protocols: refactor class member vars (a-m) (#10265)

This commit is contained in:
davc0n 2025-05-04 00:13:29 +02:00 committed by GitHub
parent 46ac115bd1
commit adbae0f74d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
58 changed files with 1566 additions and 1561 deletions

View File

@ -1268,7 +1268,7 @@ void CCompositor::focusSurface(SP<CWLSurfaceResource> pSurface, PHLWINDOW pWindo
SP<CWLSurfaceResource> CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, PHLMONITOR monitor, Vector2D* sCoords, PHLLS* ppLayerSurfaceFound) {
for (auto const& lsl : monitor->m_layerSurfaceLayers | std::views::reverse) {
for (auto const& ls : lsl | std::views::reverse) {
if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->mapped) || ls->m_alpha->value() == 0.f)
if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->m_mapped) || ls->m_alpha->value() == 0.f)
continue;
auto SURFACEAT = ls->m_popupHead->at(pos, true);
@ -1288,11 +1288,11 @@ SP<CWLSurfaceResource> CCompositor::vectorToLayerSurface(const Vector2D& pos, st
bool aboveLockscreen) {
for (auto const& ls : *layerSurfaces | std::views::reverse) {
if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->surface->m_mapped) || ls->m_alpha->value() == 0.f ||
if (!ls->m_mapped || ls->m_fadingOut || !ls->m_layerSurface || (ls->m_layerSurface && !ls->m_layerSurface->m_surface->m_mapped) || ls->m_alpha->value() == 0.f ||
(aboveLockscreen && (!ls->m_aboveLockscreen || !ls->m_aboveLockscreenInteractable)))
continue;
auto [surf, local] = ls->m_layerSurface->surface->at(pos - ls->m_geometry.pos(), true);
auto [surf, local] = ls->m_layerSurface->m_surface->at(pos - ls->m_geometry.pos(), true);
if (surf) {
if (surf->m_current.input.empty())
@ -2554,13 +2554,13 @@ PHLLS CCompositor::getLayerSurfaceFromSurface(SP<CWLSurfaceResource> pSurface) {
std::pair<SP<CWLSurfaceResource>, bool> result = {pSurface, false};
for (auto const& ls : m_layers) {
if (ls->m_layerSurface && ls->m_layerSurface->surface == pSurface)
if (ls->m_layerSurface && ls->m_layerSurface->m_surface == pSurface)
return ls;
if (!ls->m_layerSurface || !ls->m_mapped)
continue;
ls->m_layerSurface->surface->breadthfirst(
ls->m_layerSurface->m_surface->breadthfirst(
[&result](SP<CWLSurfaceResource> surf, const Vector2D& offset, void* data) {
if (surf == result.first) {
result.second = true;

View File

@ -1536,15 +1536,15 @@ std::vector<SP<CLayerRule>> CConfigManager::getMatchingRules(PHLLS pLS) {
if (lr->m_targetNamespace.starts_with("address:0x")) {
if (std::format("address:0x{:x}", (uintptr_t)pLS.get()) != lr->m_targetNamespace)
continue;
} else if (!lr->m_targetNamespaceRegex.passes(pLS->m_layerSurface->layerNamespace))
} else if (!lr->m_targetNamespaceRegex.passes(pLS->m_layerSurface->m_layerNamespace))
continue;
// hit
returns.emplace_back(lr);
}
if (shouldBlurLS(pLS->m_layerSurface->layerNamespace))
returns.emplace_back(makeShared<CLayerRule>(pLS->m_layerSurface->layerNamespace, "blur"));
if (shouldBlurLS(pLS->m_layerSurface->m_layerNamespace))
returns.emplace_back(makeShared<CLayerRule>(pLS->m_layerSurface->m_layerNamespace, "blur"));
return returns;
}

View File

@ -15,9 +15,9 @@
PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
PHLLS pLS = SP<CLayerSurface>(new CLayerSurface(resource));
auto pMonitor = resource->monitor.empty() ? g_pCompositor->m_lastMonitor.lock() : g_pCompositor->getMonitorFromName(resource->monitor);
auto pMonitor = resource->m_monitor.empty() ? g_pCompositor->m_lastMonitor.lock() : g_pCompositor->getMonitorFromName(resource->m_monitor);
pLS->m_surface->assign(resource->surface.lock(), pLS);
pLS->m_surface->assign(resource->m_surface.lock(), pLS);
if (!pMonitor) {
Debug::log(ERR, "New LS has no monitor??");
@ -29,12 +29,12 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
pLS->m_self = pLS;
pLS->m_namespace = resource->layerNamespace;
pLS->m_namespace = resource->m_layerNamespace;
pLS->m_layer = resource->current.layer;
pLS->m_layer = resource->m_current.layer;
pLS->m_popupHead = CPopup::create(pLS);
pLS->m_monitor = pMonitor;
pMonitor->m_layerSurfaceLayers[resource->current.layer].emplace_back(pLS);
pMonitor->m_layerSurfaceLayers[resource->m_current.layer].emplace_back(pLS);
pLS->m_forceBlur = g_pConfigManager->shouldBlurLS(pLS->m_namespace);
@ -46,7 +46,7 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
pLS->m_alpha->setValueAndWarp(0.f);
Debug::log(LOG, "LayerSurface {:x} (namespace {} layer {}) created on monitor {}", (uintptr_t)resource.get(), resource->layerNamespace, (int)pLS->m_layer, pMonitor->m_name);
Debug::log(LOG, "LayerSurface {:x} (namespace {} layer {}) created on monitor {}", (uintptr_t)resource.get(), resource->m_layerNamespace, (int)pLS->m_layer, pMonitor->m_name);
return pLS;
}
@ -59,10 +59,10 @@ void CLayerSurface::registerCallbacks() {
}
CLayerSurface::CLayerSurface(SP<CLayerShellResource> resource_) : m_layerSurface(resource_) {
m_listeners.commit = m_layerSurface->events.commit.registerListener([this](std::any d) { onCommit(); });
m_listeners.map = m_layerSurface->events.map.registerListener([this](std::any d) { onMap(); });
m_listeners.unmap = m_layerSurface->events.unmap.registerListener([this](std::any d) { onUnmap(); });
m_listeners.destroy = m_layerSurface->events.destroy.registerListener([this](std::any d) { onDestroy(); });
m_listeners.commit = m_layerSurface->m_events.commit.registerListener([this](std::any d) { onCommit(); });
m_listeners.map = m_layerSurface->m_events.map.registerListener([this](std::any d) { onMap(); });
m_listeners.unmap = m_layerSurface->m_events.unmap.registerListener([this](std::any d) { onUnmap(); });
m_listeners.destroy = m_layerSurface->m_events.destroy.registerListener([this](std::any d) { onDestroy(); });
m_surface = CWLSurface::create();
}
@ -133,9 +133,9 @@ void CLayerSurface::onMap() {
Debug::log(LOG, "LayerSurface {:x} mapped", (uintptr_t)m_layerSurface.get());
m_mapped = true;
m_interactivity = m_layerSurface->current.interactivity;
m_interactivity = m_layerSurface->m_current.interactivity;
m_layerSurface->surface->map();
m_layerSurface->m_surface->map();
// this layer might be re-mapped.
m_fadingOut = false;
@ -155,13 +155,13 @@ void CLayerSurface::onMap() {
m_surface->resource()->enter(PMONITOR->m_self.lock());
const bool ISEXCLUSIVE = m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
const bool ISEXCLUSIVE = m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
if (ISEXCLUSIVE)
g_pInputManager->m_exclusiveLSes.push_back(m_self);
const bool GRABSFOCUS = ISEXCLUSIVE ||
(m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
(m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
// don't focus if constrained
(g_pSeatManager->m_mouse.expired() || !g_pInputManager->isConstrained()));
@ -196,7 +196,7 @@ void CLayerSurface::onMap() {
void CLayerSurface::onUnmap() {
Debug::log(LOG, "LayerSurface {:x} unmapped", (uintptr_t)m_layerSurface.get());
g_pEventManager->postEvent(SHyprIPCEvent{"closelayer", m_layerSurface->layerNamespace});
g_pEventManager->postEvent(SHyprIPCEvent{"closelayer", m_layerSurface->m_layerNamespace});
EMIT_HOOK_EVENT("closeLayer", m_self.lock());
std::erase_if(g_pInputManager->m_exclusiveLSes, [this](const auto& other) { return !other || other == m_self; });
@ -207,8 +207,8 @@ void CLayerSurface::onUnmap() {
g_pCompositor->addToFadingOutSafe(m_self.lock());
m_mapped = false;
if (m_layerSurface && m_layerSurface->surface)
m_layerSurface->surface->unmap();
if (m_layerSurface && m_layerSurface->m_surface)
m_layerSurface->m_surface->unmap();
startAnimation(false);
return;
@ -224,8 +224,8 @@ void CLayerSurface::onUnmap() {
startAnimation(false);
m_mapped = false;
if (m_layerSurface && m_layerSurface->surface)
m_layerSurface->surface->unmap();
if (m_layerSurface && m_layerSurface->m_surface)
m_layerSurface->m_surface->unmap();
g_pCompositor->addToFadingOutSafe(m_self.lock());
@ -247,8 +247,8 @@ void CLayerSurface::onUnmap() {
CBox geomFixed = {m_geometry.x + PMONITOR->m_position.x, m_geometry.y + PMONITOR->m_position.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
geomFixed = {m_geometry.x + (int)PMONITOR->m_position.x, m_geometry.y + (int)PMONITOR->m_position.y, (int)m_layerSurface->surface->m_current.size.x,
(int)m_layerSurface->surface->m_current.size.y};
geomFixed = {m_geometry.x + (int)PMONITOR->m_position.x, m_geometry.y + (int)PMONITOR->m_position.y, (int)m_layerSurface->m_surface->m_current.size.x,
(int)m_layerSurface->m_surface->m_current.size.y};
g_pHyprRenderer->damageBox(geomFixed);
g_pInputManager->simulateMouseMovement();
@ -262,7 +262,7 @@ void CLayerSurface::onCommit() {
if (!m_mapped) {
// we're re-mapping if this is the case
if (m_layerSurface->surface && !m_layerSurface->surface->m_current.texture) {
if (m_layerSurface->m_surface && !m_layerSurface->m_surface->m_current.texture) {
m_fadingOut = false;
m_geometry = {};
g_pHyprRenderer->arrangeLayersForMonitor(monitorID());
@ -282,20 +282,20 @@ void CLayerSurface::onCommit() {
CBox geomFixed = {m_geometry.x, m_geometry.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
if (m_layerSurface->current.committed != 0) {
if (m_layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_LAYER) {
if (m_layerSurface->m_current.committed != 0) {
if (m_layerSurface->m_current.committed & CLayerShellResource::eCommittedState::STATE_LAYER) {
for (auto it = PMONITOR->m_layerSurfaceLayers[m_layer].begin(); it != PMONITOR->m_layerSurfaceLayers[m_layer].end(); it++) {
if (*it == m_self) {
if (m_layerSurface->current.layer == m_layer)
if (m_layerSurface->m_current.layer == m_layer)
break;
PMONITOR->m_layerSurfaceLayers[m_layerSurface->current.layer].emplace_back(*it);
PMONITOR->m_layerSurfaceLayers[m_layerSurface->m_current.layer].emplace_back(*it);
PMONITOR->m_layerSurfaceLayers[m_layer].erase(it);
break;
}
}
m_layer = m_layerSurface->current.layer;
m_layer = m_layerSurface->m_current.layer;
if (m_layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || m_layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)
g_pHyprOpenGL->markBlurDirtyForMonitor(PMONITOR); // so that blur is recalc'd
@ -308,12 +308,12 @@ void CLayerSurface::onCommit() {
m_position = Vector2D(m_geometry.x, m_geometry.y);
// update geom if it changed
if (m_layerSurface->surface->m_current.scale == 1 && PMONITOR->m_scale != 1.f && m_layerSurface->surface->m_current.viewport.hasDestination) {
if (m_layerSurface->m_surface->m_current.scale == 1 && PMONITOR->m_scale != 1.f && m_layerSurface->m_surface->m_current.viewport.hasDestination) {
// fractional scaling. Dirty hack.
m_geometry = {m_geometry.pos(), m_layerSurface->surface->m_current.viewport.destination};
m_geometry = {m_geometry.pos(), m_layerSurface->m_surface->m_current.viewport.destination};
} else {
// this is because some apps like e.g. rofi-lbonn can't fucking use the protocol correctly.
m_geometry = {m_geometry.pos(), m_layerSurface->surface->m_current.size};
m_geometry = {m_geometry.pos(), m_layerSurface->m_surface->m_current.size};
}
}
@ -330,9 +330,9 @@ void CLayerSurface::onCommit() {
m_realSize->setValueAndWarp(m_geometry.size());
}
if (m_mapped && (m_layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_INTERACTIVITY)) {
if (m_mapped && (m_layerSurface->m_current.committed & CLayerShellResource::eCommittedState::STATE_INTERACTIVITY)) {
bool WASLASTFOCUS = false;
m_layerSurface->surface->breadthfirst(
m_layerSurface->m_surface->breadthfirst(
[&WASLASTFOCUS](SP<CWLSurfaceResource> surf, const Vector2D& offset, void* data) { WASLASTFOCUS = WASLASTFOCUS || g_pSeatManager->m_state.keyboardFocus == surf; },
nullptr);
if (!WASLASTFOCUS && m_popupHead) {
@ -343,7 +343,7 @@ void CLayerSurface::onCommit() {
nullptr);
}
const bool WASEXCLUSIVE = m_interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
const bool ISEXCLUSIVE = m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
const bool ISEXCLUSIVE = m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
if (!WASEXCLUSIVE && ISEXCLUSIVE)
g_pInputManager->m_exclusiveLSes.push_back(m_self);
@ -351,12 +351,12 @@ void CLayerSurface::onCommit() {
std::erase_if(g_pInputManager->m_exclusiveLSes, [this](const auto& other) { return !other.lock() || other.lock() == m_self.lock(); });
// if the surface was focused and interactive but now isn't, refocus
if (WASLASTFOCUS && m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) {
if (WASLASTFOCUS && m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) {
// moveMouseUnified won't focus non interactive layers but it won't unfocus them either,
// so unfocus the surface here.
g_pCompositor->focusSurface(nullptr);
g_pInputManager->refocusLastWindow(m_monitor.lock());
} else if (WASLASTFOCUS && WASEXCLUSIVE && m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
} else if (WASLASTFOCUS && WASEXCLUSIVE && m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
g_pInputManager->simulateMouseMovement();
} else if (!WASEXCLUSIVE && ISEXCLUSIVE) {
// if now exclusive and not previously
@ -370,7 +370,7 @@ void CLayerSurface::onCommit() {
}
}
m_interactivity = m_layerSurface->current.interactivity;
m_interactivity = m_layerSurface->m_current.interactivity;
g_pHyprRenderer->damageSurface(m_surface->resource(), m_position.x, m_position.y);
@ -600,11 +600,11 @@ MONITORID CLayerSurface::monitorID() {
pid_t CLayerSurface::getPID() {
pid_t PID = -1;
if (!m_layerSurface || !m_layerSurface->surface || !m_layerSurface->surface->getResource() || !m_layerSurface->surface->getResource()->resource() ||
!m_layerSurface->surface->getResource()->resource()->client)
if (!m_layerSurface || !m_layerSurface->m_surface || !m_layerSurface->m_surface->getResource() || !m_layerSurface->m_surface->getResource()->resource() ||
!m_layerSurface->m_surface->getResource()->resource()->client)
return -1;
wl_client_get_credentials(m_layerSurface->surface->getResource()->resource()->client, &PID, nullptr, nullptr);
wl_client_get_credentials(m_layerSurface->m_surface->getResource()->resource()->client, &PID, nullptr, nullptr);
return PID;
}

View File

@ -57,7 +57,7 @@ void CPopup::initAllSignals() {
m_listeners.newPopup = m_windowOwner->m_xdgSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
else if (!m_layerOwner.expired())
m_listeners.newPopup =
m_layerOwner->m_layerSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
m_layerOwner->m_layerSurface->m_events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
else
ASSERT(false);

View File

@ -230,6 +230,6 @@ bool CWLSurface::keyboardFocusable() const {
if (m_windowOwner || m_popupOwner || m_subsurfaceOwner)
return true;
if (m_layerOwner && m_layerOwner->m_layerSurface)
return m_layerOwner->m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
return m_layerOwner->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
return false;
}

View File

@ -1775,7 +1775,7 @@ NContentType::eContentType CWindow::getContentType() {
if (!m_wlSurface || !m_wlSurface->resource() || !m_wlSurface->resource()->m_contentType.valid())
return CONTENT_TYPE_NONE;
return m_wlSurface->resource()->m_contentType->value;
return m_wlSurface->resource()->m_contentType->m_value;
}
void CWindow::setContentType(NContentType::eContentType contentType) {
@ -1784,7 +1784,7 @@ void CWindow::setContentType(NContentType::eContentType contentType) {
// else disallow content type change if proto is used?
Debug::log(INFO, "ContentType for window {}", (int)contentType);
m_wlSurface->resource()->m_contentType->value = contentType;
m_wlSurface->resource()->m_contentType->m_value = contentType;
}
void CWindow::deactivateGroupMembers() {

View File

@ -593,7 +593,7 @@ void Events::listener_mapWindow(void* owner, void* data) {
// check LS focus grab
const auto PFORCEFOCUS = g_pCompositor->getForceFocus();
const auto PLSFROMFOCUS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_lastFocus.lock());
if (PLSFROMFOCUS && PLSFROMFOCUS->m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE)
if (PLSFROMFOCUS && PLSFROMFOCUS->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE)
PWINDOW->m_noInitialFocus = true;
if (PWINDOW->m_workspace->m_hasFullscreenWindow && !requestedInternalFSMode.has_value() && !requestedClientFSMode.has_value() && !PWINDOW->m_isFloating) {

View File

@ -8,14 +8,14 @@ void CInputManager::newIdleInhibitor(std::any inhibitor) {
const auto PINHIBIT = m_idleInhibitors.emplace_back(makeUnique<SIdleInhibitor>()).get();
PINHIBIT->inhibitor = std::any_cast<SP<CIdleInhibitor>>(inhibitor);
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->surface.get());
Debug::log(LOG, "New idle inhibitor registered for surface {:x}", (uintptr_t)PINHIBIT->inhibitor->m_surface.get());
PINHIBIT->inhibitor->listeners.destroy = PINHIBIT->inhibitor->resource->events.destroy.registerListener([this, PINHIBIT](std::any data) {
PINHIBIT->inhibitor->m_listeners.destroy = PINHIBIT->inhibitor->m_resource->m_events.destroy.registerListener([this, PINHIBIT](std::any data) {
std::erase_if(m_idleInhibitors, [PINHIBIT](const auto& other) { return other.get() == PINHIBIT; });
recheckIdleInhibitorStatus();
});
auto WLSurface = CWLSurface::fromResource(PINHIBIT->inhibitor->surface.lock());
auto WLSurface = CWLSurface::fromResource(PINHIBIT->inhibitor->m_surface.lock());
if (!WLSurface) {
Debug::log(LOG, "Inhibitor has no HL Surface attached to it, likely meaning it's a non-desktop element. Assuming it's visible.");
@ -38,7 +38,7 @@ void CInputManager::recheckIdleInhibitorStatus() {
return;
}
auto WLSurface = CWLSurface::fromResource(ii->inhibitor->surface.lock());
auto WLSurface = CWLSurface::fromResource(ii->inhibitor->m_surface.lock());
if (!WLSurface)
continue;
@ -80,7 +80,7 @@ bool CInputManager::isWindowInhibiting(const PHLWINDOW& w, bool onlyHl) {
bool isInhibiting = false;
w->m_wlSurface->resource()->breadthfirst(
[&ii](SP<CWLSurfaceResource> surf, const Vector2D& pos, void* data) {
if (ii->inhibitor->surface != surf)
if (ii->inhibitor->m_surface != surf)
return;
auto WLSurface = CWLSurface::fromResource(surf);

View File

@ -42,7 +42,7 @@
#include <aquamarine/input/Input.hpp>
CInputManager::CInputManager() {
m_listeners.setCursorShape = PROTO::cursorShape->events.setShape.registerListener([this](std::any data) {
m_listeners.setCursorShape = PROTO::cursorShape->m_events.setShape.registerListener([this](std::any data) {
if (!cursorImageUnlocked())
return;
@ -65,7 +65,7 @@ CInputManager::CInputManager() {
g_pHyprRenderer->setCursorFromName(m_cursorSurfaceInfo.name);
});
m_listeners.newIdleInhibitor = PROTO::idleInhibit->events.newIdleInhibitor.registerListener([this](std::any data) { this->newIdleInhibitor(data); });
m_listeners.newIdleInhibitor = PROTO::idleInhibit->m_events.newIdleInhibitor.registerListener([this](std::any data) { this->newIdleInhibitor(data); });
m_listeners.newVirtualKeyboard = PROTO::virtualKeyboard->events.newKeyboard.registerListener([this](std::any data) {
this->newVirtualKeyboard(std::any_cast<SP<CVirtualKeyboardV1Resource>>(data));
updateCapabilities();
@ -504,7 +504,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {
if (!refocus && g_pCompositor->m_lastFocus) {
const auto PLS = g_pCompositor->getLayerSurfaceFromSurface(g_pCompositor->m_lastFocus.lock());
if (PLS && PLS->m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)
if (PLS && PLS->m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)
allowKeyboardRefocus = false;
}
@ -589,8 +589,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus, bool mouse) {
unsetCursorImage();
}
if (pFoundLayerSurface && (pFoundLayerSurface->m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) && FOLLOWMOUSE != 3 &&
(allowKeyboardRefocus || pFoundLayerSurface->m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)) {
if (pFoundLayerSurface && (pFoundLayerSurface->m_layerSurface->m_current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) && FOLLOWMOUSE != 3 &&
(allowKeyboardRefocus || pFoundLayerSurface->m_layerSurface->m_current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE)) {
g_pCompositor->focusSurface(foundSurface);
}

View File

@ -8,10 +8,10 @@
#include "../../render/Renderer.hpp"
CInputPopup::CInputPopup(SP<CInputMethodPopupV2> popup_) : m_popup(popup_) {
m_listeners.commit = popup_->events.commit.registerListener([this](std::any d) { onCommit(); });
m_listeners.map = popup_->events.map.registerListener([this](std::any d) { onMap(); });
m_listeners.unmap = popup_->events.unmap.registerListener([this](std::any d) { onUnmap(); });
m_listeners.destroy = popup_->events.destroy.registerListener([this](std::any d) { onDestroy(); });
m_listeners.commit = popup_->m_events.commit.registerListener([this](std::any d) { onCommit(); });
m_listeners.map = popup_->m_events.map.registerListener([this](std::any d) { onMap(); });
m_listeners.unmap = popup_->m_events.unmap.registerListener([this](std::any d) { onUnmap(); });
m_listeners.destroy = popup_->m_events.destroy.registerListener([this](std::any d) { onDestroy(); });
m_surface = CWLSurface::create();
m_surface->assign(popup_->surface());
}
@ -77,7 +77,7 @@ void CInputPopup::damageSurface() {
}
void CInputPopup::updateBox() {
if (!m_popup->mapped)
if (!m_popup->m_mapped)
return;
const auto OWNER = queryOwner();

View File

@ -13,7 +13,7 @@ CInputMethodRelay::CInputMethodRelay() {
m_listeners.newTIV3 = PROTO::textInputV3->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(std::any_cast<WP<CTextInputV3>>(ti)); });
m_listeners.newTIV1 = PROTO::textInputV1->events.newTextInput.registerListener([this](std::any ti) { onNewTextInput(std::any_cast<WP<CTextInputV1>>(ti)); });
m_listeners.newIME = PROTO::ime->events.newIME.registerListener([this](std::any ime) { onNewIME(std::any_cast<SP<CInputMethodV2>>(ime)); });
m_listeners.newIME = PROTO::ime->m_events.newIME.registerListener([this](std::any ime) { onNewIME(std::any_cast<SP<CInputMethodV2>>(ime)); });
}
void CInputMethodRelay::onNewIME(SP<CInputMethodV2> pIME) {
@ -27,7 +27,7 @@ void CInputMethodRelay::onNewIME(SP<CInputMethodV2> pIME) {
m_inputMethod = pIME;
m_listeners.commitIME = pIME->events.onCommit.registerListener([this](std::any d) {
m_listeners.commitIME = pIME->m_events.onCommit.registerListener([this](std::any d) {
const auto PTI = getFocusedTextInput();
if (!PTI) {
@ -38,7 +38,7 @@ void CInputMethodRelay::onNewIME(SP<CInputMethodV2> pIME) {
PTI->updateIMEState(m_inputMethod.lock());
});
m_listeners.destroyIME = pIME->events.destroy.registerListener([this](std::any d) {
m_listeners.destroyIME = pIME->m_events.destroy.registerListener([this](std::any d) {
const auto PTI = getFocusedTextInput();
Debug::log(LOG, "IME Destroy");
@ -49,7 +49,7 @@ void CInputMethodRelay::onNewIME(SP<CInputMethodV2> pIME) {
m_inputMethod.reset();
});
m_listeners.newPopup = pIME->events.newPopup.registerListener([this](std::any d) {
m_listeners.newPopup = pIME->m_events.newPopup.registerListener([this](std::any d) {
m_inputMethodPopups.emplace_back(makeUnique<CInputPopup>(std::any_cast<SP<CInputMethodPopupV2>>(d)));
Debug::log(LOG, "New input popup");

View File

@ -266,38 +266,38 @@ void CTextInput::updateIMEState(SP<CInputMethodV2> ime) {
if (isV3()) {
const auto INPUT = m_v3Input.lock();
if (ime->current.preeditString.committed)
INPUT->preeditString(ime->current.preeditString.string, ime->current.preeditString.begin, ime->current.preeditString.end);
if (ime->m_current.preeditString.committed)
INPUT->preeditString(ime->m_current.preeditString.string, ime->m_current.preeditString.begin, ime->m_current.preeditString.end);
if (ime->current.committedString.committed)
INPUT->commitString(ime->current.committedString.string);
if (ime->m_current.committedString.committed)
INPUT->commitString(ime->m_current.committedString.string);
if (ime->current.deleteSurrounding.committed)
INPUT->deleteSurroundingText(ime->current.deleteSurrounding.before, ime->current.deleteSurrounding.after);
if (ime->m_current.deleteSurrounding.committed)
INPUT->deleteSurroundingText(ime->m_current.deleteSurrounding.before, ime->m_current.deleteSurrounding.after);
INPUT->sendDone();
} else {
const auto INPUT = m_v1Input.lock();
if (ime->current.preeditString.committed) {
INPUT->preeditCursor(ime->current.preeditString.begin);
INPUT->preeditStyling(0, std::string(ime->current.preeditString.string).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
INPUT->preeditString(m_v1Input->serial, ime->current.preeditString.string.c_str(), "");
if (ime->m_current.preeditString.committed) {
INPUT->preeditCursor(ime->m_current.preeditString.begin);
INPUT->preeditStyling(0, std::string(ime->m_current.preeditString.string).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
INPUT->preeditString(m_v1Input->serial, ime->m_current.preeditString.string.c_str(), "");
} else {
INPUT->preeditCursor(0);
INPUT->preeditStyling(0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT);
INPUT->preeditString(m_v1Input->serial, "", "");
}
if (ime->current.committedString.committed)
INPUT->commitString(m_v1Input->serial, ime->current.committedString.string.c_str());
if (ime->m_current.committedString.committed)
INPUT->commitString(m_v1Input->serial, ime->m_current.committedString.string.c_str());
if (ime->current.deleteSurrounding.committed) {
INPUT->deleteSurroundingText(std::string(ime->current.preeditString.string).length() - ime->current.deleteSurrounding.before,
ime->current.deleteSurrounding.after + ime->current.deleteSurrounding.before);
if (ime->m_current.deleteSurrounding.committed) {
INPUT->deleteSurroundingText(std::string(ime->m_current.preeditString.string).length() - ime->m_current.deleteSurrounding.before,
ime->m_current.deleteSurrounding.after + ime->m_current.deleteSurrounding.before);
if (ime->current.preeditString.committed)
INPUT->commitString(m_v1Input->serial, ime->current.preeditString.string.c_str());
if (ime->m_current.preeditString.committed)
INPUT->commitString(m_v1Input->serial, ime->m_current.preeditString.string.c_str());
}
}
}

View File

@ -4,58 +4,58 @@
#include "alpha-modifier-v1.hpp"
#include "core/Compositor.hpp"
CAlphaModifier::CAlphaModifier(SP<CWpAlphaModifierSurfaceV1> resource, SP<CWLSurfaceResource> surface) : m_pSurface(surface) {
CAlphaModifier::CAlphaModifier(SP<CWpAlphaModifierSurfaceV1> resource, SP<CWLSurfaceResource> surface) : m_surface(surface) {
setResource(std::move(resource));
}
bool CAlphaModifier::good() {
return m_pResource->resource();
return m_resource->resource();
}
void CAlphaModifier::setResource(SP<CWpAlphaModifierSurfaceV1> resource) {
m_pResource = std::move(resource);
m_resource = std::move(resource);
if UNLIKELY (!m_pResource->resource())
if UNLIKELY (!m_resource->resource())
return;
m_pResource->setDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); });
m_pResource->setOnDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); });
m_resource->setDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); });
m_resource->setOnDestroy([this](CWpAlphaModifierSurfaceV1* resource) { destroy(); });
m_pResource->setSetMultiplier([this](CWpAlphaModifierSurfaceV1* resource, uint32_t alpha) {
if (!m_pSurface) {
m_pResource->error(WP_ALPHA_MODIFIER_SURFACE_V1_ERROR_NO_SURFACE, "set_multiplier called for destroyed wl_surface");
m_resource->setSetMultiplier([this](CWpAlphaModifierSurfaceV1* resource, uint32_t alpha) {
if (!m_surface) {
m_resource->error(WP_ALPHA_MODIFIER_SURFACE_V1_ERROR_NO_SURFACE, "set_multiplier called for destroyed wl_surface");
return;
}
m_fAlpha = alpha / (float)UINT32_MAX;
m_alpha = alpha / (float)UINT32_MAX;
});
listeners.surfaceCommitted = m_pSurface->m_events.commit.registerListener([this](std::any data) {
auto surface = CWLSurface::fromResource(m_pSurface.lock());
m_listeners.surfaceCommitted = m_surface->m_events.commit.registerListener([this](std::any data) {
auto surface = CWLSurface::fromResource(m_surface.lock());
if (surface && surface->m_alphaModifier != m_fAlpha) {
surface->m_alphaModifier = m_fAlpha;
if (surface && surface->m_alphaModifier != m_alpha) {
surface->m_alphaModifier = m_alpha;
auto box = surface->getSurfaceBoxGlobal();
if (box.has_value())
g_pHyprRenderer->damageBox(*box);
if (!m_pResource)
if (!m_resource)
PROTO::alphaModifier->destroyAlphaModifier(this);
}
});
listeners.surfaceDestroyed = m_pSurface->m_events.destroy.registerListener([this](std::any data) {
if (!m_pResource)
m_listeners.surfaceDestroyed = m_surface->m_events.destroy.registerListener([this](std::any data) {
if (!m_resource)
PROTO::alphaModifier->destroyAlphaModifier(this);
});
}
void CAlphaModifier::destroy() {
m_pResource.reset();
m_fAlpha = 1.F;
m_resource.reset();
m_alpha = 1.F;
if (!m_pSurface)
if (!m_surface)
PROTO::alphaModifier->destroyAlphaModifier(this);
}
@ -64,7 +64,7 @@ CAlphaModifierProtocol::CAlphaModifierProtocol(const wl_interface* iface, const
}
void CAlphaModifierProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CWpAlphaModifierV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CWpAlphaModifierV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CWpAlphaModifierV1* manager) { destroyManager(manager); });
RESOURCE->setDestroy([this](CWpAlphaModifierV1* manager) { destroyManager(manager); });
@ -72,19 +72,19 @@ void CAlphaModifierProtocol::bindManager(wl_client* client, void* data, uint32_t
}
void CAlphaModifierProtocol::destroyManager(CWpAlphaModifierV1* manager) {
std::erase_if(m_vManagers, [&](const auto& p) { return p.get() == manager; });
std::erase_if(m_managers, [&](const auto& p) { return p.get() == manager; });
}
void CAlphaModifierProtocol::destroyAlphaModifier(CAlphaModifier* modifier) {
std::erase_if(m_mAlphaModifiers, [&](const auto& entry) { return entry.second.get() == modifier; });
std::erase_if(m_alphaModifiers, [&](const auto& entry) { return entry.second.get() == modifier; });
}
void CAlphaModifierProtocol::getSurface(CWpAlphaModifierV1* manager, uint32_t id, SP<CWLSurfaceResource> surface) {
CAlphaModifier* alphaModifier = nullptr;
auto iter = std::find_if(m_mAlphaModifiers.begin(), m_mAlphaModifiers.end(), [&](const auto& entry) { return entry.second->m_pSurface == surface; });
auto iter = std::find_if(m_alphaModifiers.begin(), m_alphaModifiers.end(), [&](const auto& entry) { return entry.second->m_surface == surface; });
if (iter != m_mAlphaModifiers.end()) {
if (iter->second->m_pResource) {
if (iter != m_alphaModifiers.end()) {
if (iter->second->m_resource) {
LOGM(ERR, "AlphaModifier already present for surface {:x}", (uintptr_t)surface.get());
manager->error(WP_ALPHA_MODIFIER_V1_ERROR_ALREADY_CONSTRUCTED, "AlphaModifier already present");
return;
@ -93,12 +93,12 @@ void CAlphaModifierProtocol::getSurface(CWpAlphaModifierV1* manager, uint32_t id
alphaModifier = iter->second.get();
}
} else {
alphaModifier = m_mAlphaModifiers.emplace(surface, makeUnique<CAlphaModifier>(makeShared<CWpAlphaModifierSurfaceV1>(manager->client(), manager->version(), id), surface))
alphaModifier = m_alphaModifiers.emplace(surface, makeUnique<CAlphaModifier>(makeShared<CWpAlphaModifierSurfaceV1>(manager->client(), manager->version(), id), surface))
.first->second.get();
}
if UNLIKELY (!alphaModifier->good()) {
manager->noMemory();
m_mAlphaModifiers.erase(surface);
m_alphaModifiers.erase(surface);
}
}

View File

@ -17,16 +17,16 @@ class CAlphaModifier {
void setResource(SP<CWpAlphaModifierSurfaceV1> resource);
private:
SP<CWpAlphaModifierSurfaceV1> m_pResource;
WP<CWLSurfaceResource> m_pSurface;
float m_fAlpha = 1.0;
SP<CWpAlphaModifierSurfaceV1> m_resource;
WP<CWLSurfaceResource> m_surface;
float m_alpha = 1.0;
void destroy();
struct {
CHyprSignalListener surfaceCommitted;
CHyprSignalListener surfaceDestroyed;
} listeners;
} m_listeners;
friend class CAlphaModifierProtocol;
};
@ -43,8 +43,8 @@ class CAlphaModifierProtocol : public IWaylandProtocol {
void getSurface(CWpAlphaModifierV1* manager, uint32_t id, SP<CWLSurfaceResource> surface);
//
std::vector<UP<CWpAlphaModifierV1>> m_vManagers;
std::unordered_map<WP<CWLSurfaceResource>, UP<CAlphaModifier>> m_mAlphaModifiers;
std::vector<UP<CWpAlphaModifierV1>> m_managers;
std::unordered_map<WP<CWLSurfaceResource>, UP<CAlphaModifier>> m_alphaModifiers;
friend class CAlphaModifier;
};

View File

@ -8,16 +8,16 @@
#include "../helpers/Monitor.hpp"
#include "../helpers/MiscFunctions.hpp"
CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_) : resource(resource_) {
CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlManagerV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
resource->setOnDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
m_resource->setDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
m_resource->setOnDestroy([this](CHyprlandCtmControlManagerV1* pMgr) { PROTO::ctm->destroyResource(this); });
resource->setSetCtmForOutput([this](CHyprlandCtmControlManagerV1* r, wl_resource* output, wl_fixed_t mat0, wl_fixed_t mat1, wl_fixed_t mat2, wl_fixed_t mat3, wl_fixed_t mat4,
wl_fixed_t mat5, wl_fixed_t mat6, wl_fixed_t mat7, wl_fixed_t mat8) {
if (blocked)
m_resource->setSetCtmForOutput([this](CHyprlandCtmControlManagerV1* r, wl_resource* output, wl_fixed_t mat0, wl_fixed_t mat1, wl_fixed_t mat2, wl_fixed_t mat3, wl_fixed_t mat4,
wl_fixed_t mat5, wl_fixed_t mat6, wl_fixed_t mat7, wl_fixed_t mat8) {
if (m_blocked)
return;
const auto OUTPUTRESOURCE = CWLOutputResource::fromResource(output);
@ -35,42 +35,42 @@ CHyprlandCTMControlResource::CHyprlandCTMControlResource(SP<CHyprlandCtmControlM
for (auto& el : MAT) {
if (el < 0.F) {
resource->error(HYPRLAND_CTM_CONTROL_MANAGER_V1_ERROR_INVALID_MATRIX, "a matrix component was < 0");
m_resource->error(HYPRLAND_CTM_CONTROL_MANAGER_V1_ERROR_INVALID_MATRIX, "a matrix component was < 0");
return;
}
}
ctms[PMONITOR->m_name] = MAT;
m_ctms[PMONITOR->m_name] = MAT;
LOGM(LOG, "CTM set for output {}: {}", PMONITOR->m_name, ctms.at(PMONITOR->m_name).toString());
LOGM(LOG, "CTM set for output {}: {}", PMONITOR->m_name, m_ctms.at(PMONITOR->m_name).toString());
});
resource->setCommit([this](CHyprlandCtmControlManagerV1* r) {
if (blocked)
m_resource->setCommit([this](CHyprlandCtmControlManagerV1* r) {
if (m_blocked)
return;
LOGM(LOG, "Committing ctms to outputs");
for (auto& m : g_pCompositor->m_monitors) {
if (!ctms.contains(m->m_name)) {
if (!m_ctms.contains(m->m_name)) {
PROTO::ctm->setCTM(m, Mat3x3::identity());
continue;
}
PROTO::ctm->setCTM(m, ctms.at(m->m_name));
PROTO::ctm->setCTM(m, m_ctms.at(m->m_name));
}
});
}
void CHyprlandCTMControlResource::block() {
blocked = true;
m_blocked = true;
if (resource->version() >= 2)
resource->sendBlocked();
if (m_resource->version() >= 2)
m_resource->sendBlocked();
}
CHyprlandCTMControlResource::~CHyprlandCTMControlResource() {
if (blocked)
if (m_blocked)
return;
for (auto& m : g_pCompositor->m_monitors) {
@ -79,7 +79,7 @@ CHyprlandCTMControlResource::~CHyprlandCTMControlResource() {
}
bool CHyprlandCTMControlResource::good() {
return resource->resource();
return m_resource->resource();
}
CHyprlandCTMControlProtocol::CHyprlandCTMControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -87,24 +87,24 @@ CHyprlandCTMControlProtocol::CHyprlandCTMControlProtocol(const wl_interface* ifa
}
void CHyprlandCTMControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CHyprlandCTMControlResource>(makeShared<CHyprlandCtmControlManagerV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CHyprlandCTMControlResource>(makeShared<CHyprlandCtmControlManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
if (m_pManager)
if (m_manager)
RESOURCE->block();
else
m_pManager = RESOURCE;
m_manager = RESOURCE;
LOGM(LOG, "New CTM Manager at 0x{:x}", (uintptr_t)RESOURCE.get());
}
void CHyprlandCTMControlProtocol::destroyResource(CHyprlandCTMControlResource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == res; });
}
bool CHyprlandCTMControlProtocol::isCTMAnimationEnabled() {
@ -129,12 +129,12 @@ void CHyprlandCTMControlProtocol::setCTM(PHLMONITOR monitor, const Mat3x3& ctm)
return;
}
std::erase_if(m_mCTMDatas, [](const auto& el) { return !el.first; });
std::erase_if(m_ctmDatas, [](const auto& el) { return !el.first; });
if (!m_mCTMDatas.contains(monitor))
m_mCTMDatas[monitor] = makeUnique<SCTMData>();
if (!m_ctmDatas.contains(monitor))
m_ctmDatas[monitor] = makeUnique<SCTMData>();
auto& data = m_mCTMDatas.at(monitor);
auto& data = m_ctmDatas.at(monitor);
data->ctmFrom = data->ctmTo;
data->ctmTo = ctm;
@ -145,9 +145,9 @@ void CHyprlandCTMControlProtocol::setCTM(PHLMONITOR monitor, const Mat3x3& ctm)
monitor->setCTM(data->ctmFrom);
data->progress->setUpdateCallback([monitor = PHLMONITORREF{monitor}, this](auto) {
if (!monitor || !m_mCTMDatas.contains(monitor))
if (!monitor || !m_ctmDatas.contains(monitor))
return;
auto& data = m_mCTMDatas.at(monitor);
auto& data = m_ctmDatas.at(monitor);
const auto from = data->ctmFrom.getMatrix();
const auto to = data->ctmTo.getMatrix();
const auto PROGRESS = data->progress->getPercent();
@ -163,12 +163,12 @@ void CHyprlandCTMControlProtocol::setCTM(PHLMONITOR monitor, const Mat3x3& ctm)
});
data->progress->setCallbackOnEnd([monitor = PHLMONITORREF{monitor}, this](auto) {
if (!monitor || !m_mCTMDatas.contains(monitor)) {
if (!monitor || !m_ctmDatas.contains(monitor)) {
if (monitor)
monitor->setCTM(Mat3x3::identity());
return;
}
auto& data = m_mCTMDatas.at(monitor);
auto& data = m_ctmDatas.at(monitor);
monitor->setCTM(data->ctmTo);
});
}

View File

@ -19,10 +19,10 @@ class CHyprlandCTMControlResource {
void block();
private:
SP<CHyprlandCtmControlManagerV1> resource;
SP<CHyprlandCtmControlManagerV1> m_resource;
std::unordered_map<std::string, Mat3x3> ctms;
bool blocked = false;
std::unordered_map<std::string, Mat3x3> m_ctms;
bool m_blocked = false;
};
class CHyprlandCTMControlProtocol : public IWaylandProtocol {
@ -38,8 +38,8 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol {
bool isCTMAnimationEnabled();
//
std::vector<SP<CHyprlandCTMControlResource>> m_vManagers;
WP<CHyprlandCTMControlResource> m_pManager;
std::vector<SP<CHyprlandCTMControlResource>> m_managers;
WP<CHyprlandCTMControlResource> m_manager;
//
struct SCTMData {
@ -47,7 +47,7 @@ class CHyprlandCTMControlProtocol : public IWaylandProtocol {
Mat3x3 ctmFrom = Mat3x3::identity(), ctmTo = Mat3x3::identity();
PHLANIMVAR<float> progress;
};
std::map<PHLMONITORREF, UP<SCTMData>> m_mCTMDatas;
std::map<PHLMONITORREF, UP<SCTMData>> m_ctmDatas;
friend class CHyprlandCTMControlResource;
};

View File

@ -82,15 +82,15 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
}
const auto RESOURCE =
PROTO::colorManagement->m_vOutputs.emplace_back(makeShared<CColorManagementOutput>(makeShared<CWpColorManagementOutputV1>(r->client(), r->version(), id), PMONITOR));
PROTO::colorManagement->m_outputs.emplace_back(makeShared<CColorManagementOutput>(makeShared<CWpColorManagementOutputV1>(r->client(), r->version(), id), PMONITOR));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vOutputs.pop_back();
PROTO::colorManagement->m_outputs.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
m_resource->setGetSurface([](CWpColorManagerV1* r, uint32_t id, wl_resource* surface) {
LOGM(TRACE, "Get surface for id={}, surface={}", id, (uintptr_t)surface);
@ -108,14 +108,14 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
}
const auto RESOURCE =
PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared<CColorManagementSurface>(makeShared<CWpColorManagementSurfaceV1>(r->client(), r->version(), id), SURF));
PROTO::colorManagement->m_surfaces.emplace_back(makeShared<CColorManagementSurface>(makeShared<CWpColorManagementSurfaceV1>(r->client(), r->version(), id), SURF));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vSurfaces.pop_back();
PROTO::colorManagement->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
SURF->m_colorManagement = RESOURCE;
});
@ -129,16 +129,16 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
return;
}
const auto RESOURCE = PROTO::colorManagement->m_vFeedbackSurfaces.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_feedbackSurfaces.emplace_back(
makeShared<CColorManagementFeedbackSurface>(makeShared<CWpColorManagementSurfaceFeedbackV1>(r->client(), r->version(), id), SURF));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vFeedbackSurfaces.pop_back();
PROTO::colorManagement->m_feedbackSurfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
m_resource->setCreateIccCreator([](CWpColorManagerV1* r, uint32_t id) {
LOGM(WARN, "New ICC creator for id={} (unsupported)", id);
@ -148,29 +148,29 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
}
const auto RESOURCE =
PROTO::colorManagement->m_vIccCreators.emplace_back(makeShared<CColorManagementIccCreator>(makeShared<CWpImageDescriptionCreatorIccV1>(r->client(), r->version(), id)));
PROTO::colorManagement->m_iccCreators.emplace_back(makeShared<CColorManagementIccCreator>(makeShared<CWpImageDescriptionCreatorIccV1>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vIccCreators.pop_back();
PROTO::colorManagement->m_iccCreators.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
m_resource->setCreateParametricCreator([](CWpColorManagerV1* r, uint32_t id) {
LOGM(TRACE, "New parametric creator for id={}", id);
const auto RESOURCE = PROTO::colorManagement->m_vParametricCreators.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_parametricCreators.emplace_back(
makeShared<CColorManagementParametricCreator>(makeShared<CWpImageDescriptionCreatorParamsV1>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vParametricCreators.pop_back();
PROTO::colorManagement->m_parametricCreators.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
m_resource->setCreateWindowsScrgb([](CWpColorManagerV1* r, uint32_t id) {
LOGM(WARN, "New Windows scRGB description id={} (unsupported)", id);
@ -179,23 +179,23 @@ CColorManager::CColorManager(SP<CWpColorManagerV1> resource) : m_resource(resour
return;
}
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), false));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->settings.windowsScRGB = true;
RESOURCE->settings.primariesNamed = NColorManagement::CM_PRIMARIES_SRGB;
RESOURCE->settings.primariesNameSet = true;
RESOURCE->settings.primaries = NColorPrimaries::BT709;
RESOURCE->settings.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_EXT_LINEAR;
RESOURCE->settings.luminances.reference = 203;
RESOURCE->resource()->sendReady(RESOURCE->settings.updateId());
RESOURCE->m_self = RESOURCE;
RESOURCE->m_settings.windowsScRGB = true;
RESOURCE->m_settings.primariesNamed = NColorManagement::CM_PRIMARIES_SRGB;
RESOURCE->m_settings.primariesNameSet = true;
RESOURCE->m_settings.primaries = NColorPrimaries::BT709;
RESOURCE->m_settings.transferFunction = NColorManagement::CM_TRANSFER_FUNCTION_EXT_LINEAR;
RESOURCE->m_settings.luminances.reference = 203;
RESOURCE->resource()->sendReady(RESOURCE->m_settings.updateId());
});
m_resource->setOnDestroy([this](CWpColorManagerV1* r) { PROTO::colorManagement->destroyResource(this); });
@ -211,7 +211,7 @@ CColorManagementOutput::CColorManagementOutput(SP<CWpColorManagementOutputV1> re
if UNLIKELY (!good())
return;
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setDestroy([this](CWpColorManagementOutputV1* r) { PROTO::colorManagement->destroyResource(this); });
m_resource->setOnDestroy([this](CWpColorManagementOutputV1* r) { PROTO::colorManagement->destroyResource(this); });
@ -219,24 +219,24 @@ CColorManagementOutput::CColorManagementOutput(SP<CWpColorManagementOutputV1> re
m_resource->setGetImageDescription([this](CWpColorManagementOutputV1* r, uint32_t id) {
LOGM(TRACE, "Get image description for output={}, id={}", (uintptr_t)r, id);
if (imageDescription.valid())
PROTO::colorManagement->destroyResource(imageDescription.get());
if (m_imageDescription.valid())
PROTO::colorManagement->destroyResource(m_imageDescription.get());
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), true));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
if (!m_monitor.valid())
RESOURCE->m_resource->sendFailed(WP_IMAGE_DESCRIPTION_V1_CAUSE_NO_OUTPUT, "No output");
else {
RESOURCE->settings = m_monitor->m_imageDescription;
RESOURCE->m_resource->sendReady(RESOURCE->settings.updateId());
RESOURCE->m_settings = m_monitor->m_imageDescription;
RESOURCE->m_resource->sendReady(RESOURCE->m_settings.updateId());
}
});
}
@ -246,25 +246,25 @@ bool CColorManagementOutput::good() {
}
wl_client* CColorManagementOutput::client() {
return pClient;
return m_client;
}
CColorManagementSurface::CColorManagementSurface(SP<CWLSurfaceResource> surface_) : surface(surface_) {
CColorManagementSurface::CColorManagementSurface(SP<CWLSurfaceResource> surface_) : m_surface(surface_) {
// only for frog cm untill wayland cm is adopted
}
CColorManagementSurface::CColorManagementSurface(SP<CWpColorManagementSurfaceV1> resource, SP<CWLSurfaceResource> surface_) : surface(surface_), m_resource(resource) {
CColorManagementSurface::CColorManagementSurface(SP<CWpColorManagementSurfaceV1> resource, SP<CWLSurfaceResource> surface_) : m_surface(surface_), m_resource(resource) {
if UNLIKELY (!good())
return;
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setDestroy([this](CWpColorManagementSurfaceV1* r) {
LOGM(TRACE, "Destroy xx cm surface {}", (uintptr_t)surface);
LOGM(TRACE, "Destroy xx cm surface {}", (uintptr_t)m_surface);
PROTO::colorManagement->destroyResource(this);
});
m_resource->setOnDestroy([this](CWpColorManagementSurfaceV1* r) {
LOGM(TRACE, "Destroy xx cm surface {}", (uintptr_t)surface);
LOGM(TRACE, "Destroy xx cm surface {}", (uintptr_t)m_surface);
PROTO::colorManagement->destroyResource(this);
});
@ -281,15 +281,15 @@ CColorManagementSurface::CColorManagementSurface(SP<CWpColorManagementSurfaceV1>
return;
}
const auto imageDescription = std::find_if(PROTO::colorManagement->m_vImageDescriptions.begin(), PROTO::colorManagement->m_vImageDescriptions.end(),
const auto imageDescription = std::find_if(PROTO::colorManagement->m_imageDescriptions.begin(), PROTO::colorManagement->m_imageDescriptions.end(),
[&](const auto& other) { return other->resource()->resource() == image_description; });
if (imageDescription == PROTO::colorManagement->m_vImageDescriptions.end()) {
if (imageDescription == PROTO::colorManagement->m_imageDescriptions.end()) {
r->error(WP_COLOR_MANAGEMENT_SURFACE_V1_ERROR_IMAGE_DESCRIPTION, "Image description not found");
return;
}
setHasImageDescription(true);
m_imageDescription = imageDescription->get()->settings;
m_imageDescription = imageDescription->get()->m_settings;
});
m_resource->setUnsetImageDescription([this](CWpColorManagementSurfaceV1* r) {
LOGM(TRACE, "Unset image description for surface={}", (uintptr_t)r);
@ -303,7 +303,7 @@ bool CColorManagementSurface::good() {
}
wl_client* CColorManagementSurface::client() {
return pClient;
return m_client;
}
const SImageDescription& CColorManagementSurface::imageDescription() {
@ -340,20 +340,20 @@ bool CColorManagementSurface::needsHdrMetadataUpdate() {
}
CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorManagementSurfaceFeedbackV1> resource, SP<CWLSurfaceResource> surface_) :
surface(surface_), m_resource(resource) {
m_surface(surface_), m_resource(resource) {
if UNLIKELY (!good())
return;
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setDestroy([this](CWpColorManagementSurfaceFeedbackV1* r) {
LOGM(TRACE, "Destroy xx cm feedback surface {}", (uintptr_t)surface);
LOGM(TRACE, "Destroy xx cm feedback surface {}", (uintptr_t)m_surface);
if (m_currentPreferred.valid())
PROTO::colorManagement->destroyResource(m_currentPreferred.get());
PROTO::colorManagement->destroyResource(this);
});
m_resource->setOnDestroy([this](CWpColorManagementSurfaceFeedbackV1* r) {
LOGM(TRACE, "Destroy xx cm feedback surface {}", (uintptr_t)surface);
LOGM(TRACE, "Destroy xx cm feedback surface {}", (uintptr_t)m_surface);
if (m_currentPreferred.valid())
PROTO::colorManagement->destroyResource(m_currentPreferred.get());
PROTO::colorManagement->destroyResource(this);
@ -365,20 +365,20 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana
if (m_currentPreferred.valid())
PROTO::colorManagement->destroyResource(m_currentPreferred.get());
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), true));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
m_currentPreferred = RESOURCE;
m_currentPreferred->settings = g_pCompositor->getPreferredImageDescription();
RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId());
m_currentPreferred->m_settings = g_pCompositor->getPreferredImageDescription();
RESOURCE->resource()->sendReady(m_currentPreferred->m_settings.updateId());
});
m_resource->setGetPreferredParametric([this](CWpColorManagementSurfaceFeedbackV1* r, uint32_t id) {
@ -392,26 +392,26 @@ CColorManagementFeedbackSurface::CColorManagementFeedbackSurface(SP<CWpColorMana
if (m_currentPreferred.valid())
PROTO::colorManagement->destroyResource(m_currentPreferred.get());
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), true));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
m_currentPreferred = RESOURCE;
m_currentPreferred->settings = g_pCompositor->getPreferredImageDescription();
if (!PROTO::colorManagement->m_debug && m_currentPreferred->settings.icc.fd) {
m_currentPreferred->m_settings = g_pCompositor->getPreferredImageDescription();
if (!PROTO::colorManagement->m_debug && m_currentPreferred->m_settings.icc.fd) {
LOGM(ERR, "FIXME: parse icc profile");
r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "ICC profiles are not supported");
return;
}
RESOURCE->resource()->sendReady(m_currentPreferred->settings.updateId());
RESOURCE->resource()->sendReady(m_currentPreferred->m_settings.updateId());
});
}
@ -420,14 +420,14 @@ bool CColorManagementFeedbackSurface::good() {
}
wl_client* CColorManagementFeedbackSurface::client() {
return pClient;
return m_client;
}
CColorManagementIccCreator::CColorManagementIccCreator(SP<CWpImageDescriptionCreatorIccV1> resource) : m_resource(resource) {
if UNLIKELY (!good())
return;
//
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setOnDestroy([this](CWpImageDescriptionCreatorIccV1* r) { PROTO::colorManagement->destroyResource(this); });
@ -435,39 +435,39 @@ CColorManagementIccCreator::CColorManagementIccCreator(SP<CWpImageDescriptionCre
LOGM(TRACE, "Create image description from icc for id {}", id);
// FIXME actually check completeness
if (settings.icc.fd < 0 || !settings.icc.length) {
if (m_settings.icc.fd < 0 || !m_settings.icc.length) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET, "Missing required settings");
return;
}
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), false));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
LOGM(ERR, "FIXME: Parse icc file {}({},{}) for id {}", settings.icc.fd, settings.icc.offset, settings.icc.length, id);
LOGM(ERR, "FIXME: Parse icc file {}({},{}) for id {}", m_settings.icc.fd, m_settings.icc.offset, m_settings.icc.length, id);
// FIXME actually check support
if (settings.icc.fd < 0 || !settings.icc.length) {
if (m_settings.icc.fd < 0 || !m_settings.icc.length) {
RESOURCE->resource()->sendFailed(WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED, "unsupported");
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->settings = settings;
RESOURCE->resource()->sendReady(settings.updateId());
RESOURCE->m_self = RESOURCE;
RESOURCE->m_settings = m_settings;
RESOURCE->resource()->sendReady(m_settings.updateId());
PROTO::colorManagement->destroyResource(this);
});
m_resource->setSetIccFile([this](CWpImageDescriptionCreatorIccV1* r, int fd, uint32_t offset, uint32_t length) {
settings.icc.fd = fd;
settings.icc.offset = offset;
settings.icc.length = length;
m_settings.icc.fd = fd;
m_settings.icc.offset = offset;
m_settings.icc.length = length;
});
}
@ -476,14 +476,14 @@ bool CColorManagementIccCreator::good() {
}
wl_client* CColorManagementIccCreator::client() {
return pClient;
return m_client;
}
CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImageDescriptionCreatorParamsV1> resource) : m_resource(resource) {
if UNLIKELY (!good())
return;
//
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setOnDestroy([this](CWpImageDescriptionCreatorParamsV1* r) { PROTO::colorManagement->destroyResource(this); });
@ -491,35 +491,35 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
LOGM(TRACE, "Create image description from params for id {}", id);
// FIXME actually check completeness
if (!valuesSet) {
if (!m_valuesSet) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INCOMPLETE_SET, "Missing required settings");
return;
}
const auto RESOURCE = PROTO::colorManagement->m_vImageDescriptions.emplace_back(
const auto RESOURCE = PROTO::colorManagement->m_imageDescriptions.emplace_back(
makeShared<CColorManagementImageDescription>(makeShared<CWpImageDescriptionV1>(r->client(), r->version(), id), false));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::colorManagement->m_vImageDescriptions.pop_back();
PROTO::colorManagement->m_imageDescriptions.pop_back();
return;
}
// FIXME actually check support
if (!valuesSet) {
if (!m_valuesSet) {
RESOURCE->resource()->sendFailed(WP_IMAGE_DESCRIPTION_V1_CAUSE_UNSUPPORTED, "unsupported");
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->settings = settings;
RESOURCE->resource()->sendReady(settings.updateId());
RESOURCE->m_self = RESOURCE;
RESOURCE->m_settings = m_settings;
RESOURCE->resource()->sendReady(m_settings.updateId());
PROTO::colorManagement->destroyResource(this);
});
m_resource->setSetTfNamed([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t tf) {
LOGM(TRACE, "Set image description transfer function to {}", tf);
if (valuesSet & PC_TF) {
if (m_valuesSet & PC_TF) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Transfer function already set");
return;
}
@ -534,12 +534,12 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
default: r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF, "Unsupported transfer function"); return;
}
settings.transferFunction = convertTransferFunction((wpColorManagerV1TransferFunction)tf);
valuesSet |= PC_TF;
m_settings.transferFunction = convertTransferFunction((wpColorManagerV1TransferFunction)tf);
m_valuesSet |= PC_TF;
});
m_resource->setSetTfPower([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t eexp) {
LOGM(TRACE, "Set image description tf power to {}", eexp);
if (valuesSet & PC_TF_POWER) {
if (m_valuesSet & PC_TF_POWER) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Transfer function power already set");
return;
}
@ -547,16 +547,16 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "TF power is not supported");
return;
}
settings.transferFunctionPower = eexp / 10000.0f;
if (settings.transferFunctionPower < 1.0 || settings.transferFunctionPower > 10.0) {
m_settings.transferFunctionPower = eexp / 10000.0f;
if (m_settings.transferFunctionPower < 1.0 || m_settings.transferFunctionPower > 10.0) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_TF, "Power should be between 1.0 and 10.0");
return;
}
valuesSet |= PC_TF_POWER;
m_valuesSet |= PC_TF_POWER;
});
m_resource->setSetPrimariesNamed([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t primaries) {
LOGM(TRACE, "Set image description primaries by name {}", primaries);
if (valuesSet & PC_PRIMARIES) {
if (m_valuesSet & PC_PRIMARIES) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Primaries already set");
return;
}
@ -578,15 +578,15 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
}
}
settings.primariesNameSet = true;
settings.primariesNamed = convertPrimaries((wpColorManagerV1Primaries)primaries);
settings.primaries = getPrimaries(settings.primariesNamed);
valuesSet |= PC_PRIMARIES;
m_settings.primariesNameSet = true;
m_settings.primariesNamed = convertPrimaries((wpColorManagerV1Primaries)primaries);
m_settings.primaries = getPrimaries(m_settings.primariesNamed);
m_valuesSet |= PC_PRIMARIES;
});
m_resource->setSetPrimaries(
[this](CWpImageDescriptionCreatorParamsV1* r, int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) {
LOGM(TRACE, "Set image description primaries by values r:{},{} g:{},{} b:{},{} w:{},{}", r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y);
if (valuesSet & PC_PRIMARIES) {
if (m_valuesSet & PC_PRIMARIES) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Primaries already set");
return;
}
@ -594,17 +594,17 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "Custom primaries aren't supported");
return;
}
settings.primariesNameSet = false;
settings.primaries = SPCPRimaries{.red = {.x = r_x / 1000000.0f, .y = r_y / 1000000.0f},
.green = {.x = g_x / 1000000.0f, .y = g_y / 1000000.0f},
.blue = {.x = b_x / 1000000.0f, .y = b_y / 1000000.0f},
.white = {.x = w_x / 1000000.0f, .y = w_y / 1000000.0f}};
valuesSet |= PC_PRIMARIES;
m_settings.primariesNameSet = false;
m_settings.primaries = SPCPRimaries{.red = {.x = r_x / 1000000.0f, .y = r_y / 1000000.0f},
.green = {.x = g_x / 1000000.0f, .y = g_y / 1000000.0f},
.blue = {.x = b_x / 1000000.0f, .y = b_y / 1000000.0f},
.white = {.x = w_x / 1000000.0f, .y = w_y / 1000000.0f}};
m_valuesSet |= PC_PRIMARIES;
});
m_resource->setSetLuminances([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t min_lum, uint32_t max_lum, uint32_t reference_lum) {
auto min = min_lum / 10000.0f;
LOGM(TRACE, "Set image description luminances to {} - {} ({})", min, max_lum, reference_lum);
if (valuesSet & PC_LUMINANCES) {
if (m_valuesSet & PC_LUMINANCES) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Luminances already set");
return;
}
@ -612,13 +612,13 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_INVALID_LUMINANCE, "Invalid luminances");
return;
}
settings.luminances = SImageDescription::SPCLuminances{.min = min, .max = max_lum, .reference = reference_lum};
valuesSet |= PC_LUMINANCES;
m_settings.luminances = SImageDescription::SPCLuminances{.min = min, .max = max_lum, .reference = reference_lum};
m_valuesSet |= PC_LUMINANCES;
});
m_resource->setSetMasteringDisplayPrimaries(
[this](CWpImageDescriptionCreatorParamsV1* r, int32_t r_x, int32_t r_y, int32_t g_x, int32_t g_y, int32_t b_x, int32_t b_y, int32_t w_x, int32_t w_y) {
LOGM(TRACE, "Set image description mastering primaries by values r:{},{} g:{},{} b:{},{} w:{},{}", r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y);
if (valuesSet & PC_MASTERING_PRIMARIES) {
if (m_valuesSet & PC_MASTERING_PRIMARIES) {
r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Mastering primaries already set");
return;
}
@ -626,11 +626,11 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "Mastering primaries are not supported");
return;
}
settings.masteringPrimaries = SPCPRimaries{.red = {.x = r_x / 1000000.0f, .y = r_y / 1000000.0f},
.green = {.x = g_x / 1000000.0f, .y = g_y / 1000000.0f},
.blue = {.x = b_x / 1000000.0f, .y = b_y / 1000000.0f},
.white = {.x = w_x / 1000000.0f, .y = w_y / 1000000.0f}};
valuesSet |= PC_MASTERING_PRIMARIES;
m_settings.masteringPrimaries = SPCPRimaries{.red = {.x = r_x / 1000000.0f, .y = r_y / 1000000.0f},
.green = {.x = g_x / 1000000.0f, .y = g_y / 1000000.0f},
.blue = {.x = b_x / 1000000.0f, .y = b_y / 1000000.0f},
.white = {.x = w_x / 1000000.0f, .y = w_y / 1000000.0f}};
m_valuesSet |= PC_MASTERING_PRIMARIES;
// FIXME:
// If a compositor additionally supports target color volume exceeding the primary color volume, it must advertise wp_color_manager_v1.feature.extended_target_volume.
@ -652,8 +652,8 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
r->error(WP_COLOR_MANAGER_V1_ERROR_UNSUPPORTED_FEATURE, "Mastering luminances are not supported");
return;
}
settings.masteringLuminances = SImageDescription::SPCMasteringLuminances{.min = min, .max = max_lum};
valuesSet |= PC_MASTERING_LUMINANCES;
m_settings.masteringLuminances = SImageDescription::SPCMasteringLuminances{.min = min, .max = max_lum};
m_valuesSet |= PC_MASTERING_LUMINANCES;
});
m_resource->setSetMaxCll([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t max_cll) {
LOGM(TRACE, "Set image description max content light level to {}", max_cll);
@ -661,8 +661,8 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
// r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Max CLL already set");
// return;
// }
settings.maxCLL = max_cll;
valuesSet |= PC_CLL;
m_settings.maxCLL = max_cll;
m_valuesSet |= PC_CLL;
});
m_resource->setSetMaxFall([this](CWpImageDescriptionCreatorParamsV1* r, uint32_t max_fall) {
LOGM(TRACE, "Set image description max frame-average light level to {}", max_fall);
@ -670,8 +670,8 @@ CColorManagementParametricCreator::CColorManagementParametricCreator(SP<CWpImage
// r->error(WP_IMAGE_DESCRIPTION_CREATOR_PARAMS_V1_ERROR_ALREADY_SET, "Max FALL already set");
// return;
// }
settings.maxFALL = max_fall;
valuesSet |= PC_FALL;
m_settings.maxFALL = max_fall;
m_valuesSet |= PC_FALL;
});
}
@ -680,7 +680,7 @@ bool CColorManagementParametricCreator::good() {
}
wl_client* CColorManagementParametricCreator::client() {
return pClient;
return m_client;
}
CColorManagementImageDescription::CColorManagementImageDescription(SP<CWpImageDescriptionV1> resource, bool allowGetInformation) :
@ -688,7 +688,7 @@ CColorManagementImageDescription::CColorManagementImageDescription(SP<CWpImageDe
if UNLIKELY (!good())
return;
pClient = m_resource->client();
m_client = m_resource->client();
m_resource->setDestroy([this](CWpImageDescriptionV1* r) { PROTO::colorManagement->destroyResource(this); });
m_resource->setOnDestroy([this](CWpImageDescriptionV1* r) { PROTO::colorManagement->destroyResource(this); });
@ -700,7 +700,7 @@ CColorManagementImageDescription::CColorManagementImageDescription(SP<CWpImageDe
return;
}
auto RESOURCE = makeShared<CColorManagementImageDescriptionInfo>(makeShared<CWpImageDescriptionInfoV1>(r->client(), r->version(), id), settings);
auto RESOURCE = makeShared<CColorManagementImageDescriptionInfo>(makeShared<CWpImageDescriptionInfoV1>(r->client(), r->version(), id), m_settings);
if UNLIKELY (!RESOURCE->good())
r->noMemory();
@ -715,7 +715,7 @@ bool CColorManagementImageDescription::good() {
}
wl_client* CColorManagementImageDescription::client() {
return pClient;
return m_client;
}
SP<CWpImageDescriptionV1> CColorManagementImageDescription::resource() {
@ -723,33 +723,34 @@ SP<CWpImageDescriptionV1> CColorManagementImageDescription::resource() {
}
CColorManagementImageDescriptionInfo::CColorManagementImageDescriptionInfo(SP<CWpImageDescriptionInfoV1> resource, const SImageDescription& settings_) :
m_resource(resource), settings(settings_) {
m_resource(resource), m_settings(settings_) {
if UNLIKELY (!good())
return;
pClient = m_resource->client();
m_client = m_resource->client();
const auto toProto = [](float value) { return int32_t(std::round(value * 10000)); };
if (settings.icc.fd >= 0)
m_resource->sendIccFile(settings.icc.fd, settings.icc.length);
if (m_settings.icc.fd >= 0)
m_resource->sendIccFile(m_settings.icc.fd, m_settings.icc.length);
// send preferred client paramateres
m_resource->sendPrimaries(toProto(settings.primaries.red.x), toProto(settings.primaries.red.y), toProto(settings.primaries.green.x), toProto(settings.primaries.green.y),
toProto(settings.primaries.blue.x), toProto(settings.primaries.blue.y), toProto(settings.primaries.white.x), toProto(settings.primaries.white.y));
if (settings.primariesNameSet)
m_resource->sendPrimariesNamed(settings.primariesNamed);
m_resource->sendTfPower(std::round(settings.transferFunctionPower * 10000));
m_resource->sendTfNamed(settings.transferFunction);
m_resource->sendLuminances(std::round(settings.luminances.min * 10000), settings.luminances.max, settings.luminances.reference);
m_resource->sendPrimaries(toProto(m_settings.primaries.red.x), toProto(m_settings.primaries.red.y), toProto(m_settings.primaries.green.x),
toProto(m_settings.primaries.green.y), toProto(m_settings.primaries.blue.x), toProto(m_settings.primaries.blue.y),
toProto(m_settings.primaries.white.x), toProto(m_settings.primaries.white.y));
if (m_settings.primariesNameSet)
m_resource->sendPrimariesNamed(m_settings.primariesNamed);
m_resource->sendTfPower(std::round(m_settings.transferFunctionPower * 10000));
m_resource->sendTfNamed(m_settings.transferFunction);
m_resource->sendLuminances(std::round(m_settings.luminances.min * 10000), m_settings.luminances.max, m_settings.luminances.reference);
// send expexted display paramateres
m_resource->sendTargetPrimaries(toProto(settings.masteringPrimaries.red.x), toProto(settings.masteringPrimaries.red.y), toProto(settings.masteringPrimaries.green.x),
toProto(settings.masteringPrimaries.green.y), toProto(settings.masteringPrimaries.blue.x), toProto(settings.masteringPrimaries.blue.y),
toProto(settings.masteringPrimaries.white.x), toProto(settings.masteringPrimaries.white.y));
m_resource->sendTargetLuminance(std::round(settings.masteringLuminances.min * 10000), settings.masteringLuminances.max);
m_resource->sendTargetMaxCll(settings.maxCLL);
m_resource->sendTargetMaxFall(settings.maxFALL);
m_resource->sendTargetPrimaries(toProto(m_settings.masteringPrimaries.red.x), toProto(m_settings.masteringPrimaries.red.y), toProto(m_settings.masteringPrimaries.green.x),
toProto(m_settings.masteringPrimaries.green.y), toProto(m_settings.masteringPrimaries.blue.x), toProto(m_settings.masteringPrimaries.blue.y),
toProto(m_settings.masteringPrimaries.white.x), toProto(m_settings.masteringPrimaries.white.y));
m_resource->sendTargetLuminance(std::round(m_settings.masteringLuminances.min * 10000), m_settings.masteringLuminances.max);
m_resource->sendTargetMaxCll(m_settings.maxCLL);
m_resource->sendTargetMaxFall(m_settings.maxFALL);
m_resource->sendDone();
}
@ -759,7 +760,7 @@ bool CColorManagementImageDescriptionInfo::good() {
}
wl_client* CColorManagementImageDescriptionInfo::client() {
return pClient;
return m_client;
}
CColorManagementProtocol::CColorManagementProtocol(const wl_interface* iface, const int& ver, const std::string& name, bool debug) :
@ -768,11 +769,11 @@ CColorManagementProtocol::CColorManagementProtocol(const wl_interface* iface, co
}
void CColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CColorManager>(makeShared<CWpColorManagerV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CColorManager>(makeShared<CWpColorManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
@ -780,42 +781,42 @@ void CColorManagementProtocol::bindManager(wl_client* client, void* data, uint32
}
void CColorManagementProtocol::onImagePreferredChanged(uint32_t preferredId) {
for (auto const& feedback : m_vFeedbackSurfaces) {
for (auto const& feedback : m_feedbackSurfaces) {
feedback->m_resource->sendPreferredChanged(preferredId);
}
}
void CColorManagementProtocol::onMonitorImageDescriptionChanged(WP<CMonitor> monitor) {
for (auto const& output : m_vOutputs) {
for (auto const& output : m_outputs) {
if (output->m_monitor == monitor)
output->m_resource->sendImageDescriptionChanged();
}
}
void CColorManagementProtocol::destroyResource(CColorManager* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementOutput* resource) {
std::erase_if(m_vOutputs, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_outputs, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementSurface* resource) {
std::erase_if(m_vSurfaces, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_surfaces, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementFeedbackSurface* resource) {
std::erase_if(m_vFeedbackSurfaces, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_feedbackSurfaces, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementIccCreator* resource) {
std::erase_if(m_vIccCreators, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_iccCreators, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementParametricCreator* resource) {
std::erase_if(m_vParametricCreators, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_parametricCreators, [&](const auto& other) { return other.get() == resource; });
}
void CColorManagementProtocol::destroyResource(CColorManagementImageDescription* resource) {
std::erase_if(m_vImageDescriptions, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_imageDescriptions, [&](const auto& other) { return other.get() == resource; });
}

View File

@ -31,12 +31,12 @@ class CColorManagementOutput {
bool good();
wl_client* client();
WP<CColorManagementOutput> self;
WP<CColorManagementImageDescription> imageDescription;
WP<CColorManagementOutput> m_self;
WP<CColorManagementImageDescription> m_imageDescription;
private:
SP<CWpColorManagementOutputV1> m_resource;
wl_client* pClient = nullptr;
wl_client* m_client = nullptr;
WP<CMonitor> m_monitor;
friend class CColorManagementProtocol;
@ -51,8 +51,8 @@ class CColorManagementSurface {
bool good();
wl_client* client();
WP<CColorManagementSurface> self;
WP<CWLSurfaceResource> surface;
WP<CColorManagementSurface> m_self;
WP<CWLSurfaceResource> m_surface;
const NColorManagement::SImageDescription& imageDescription();
bool hasImageDescription();
@ -63,7 +63,7 @@ class CColorManagementSurface {
private:
SP<CWpColorManagementSurfaceV1> m_resource;
wl_client* pClient = nullptr;
wl_client* m_client = nullptr;
NColorManagement::SImageDescription m_imageDescription;
NColorManagement::SImageDescription m_lastImageDescription;
bool m_hasImageDescription = false;
@ -81,12 +81,12 @@ class CColorManagementFeedbackSurface {
bool good();
wl_client* client();
WP<CColorManagementFeedbackSurface> self;
WP<CWLSurfaceResource> surface;
WP<CColorManagementFeedbackSurface> m_self;
WP<CWLSurfaceResource> m_surface;
private:
SP<CWpColorManagementSurfaceFeedbackV1> m_resource;
wl_client* pClient = nullptr;
wl_client* m_client = nullptr;
WP<CColorManagementImageDescription> m_currentPreferred;
@ -100,13 +100,13 @@ class CColorManagementIccCreator {
bool good();
wl_client* client();
WP<CColorManagementIccCreator> self;
WP<CColorManagementIccCreator> m_self;
NColorManagement::SImageDescription settings;
NColorManagement::SImageDescription m_settings;
private:
SP<CWpImageDescriptionCreatorIccV1> m_resource;
wl_client* pClient = nullptr;
wl_client* m_client = nullptr;
};
class CColorManagementParametricCreator {
@ -116,9 +116,9 @@ class CColorManagementParametricCreator {
bool good();
wl_client* client();
WP<CColorManagementParametricCreator> self;
WP<CColorManagementParametricCreator> m_self;
NColorManagement::SImageDescription settings;
NColorManagement::SImageDescription m_settings;
private:
enum eValuesSet : uint32_t { // NOLINT
@ -133,8 +133,8 @@ class CColorManagementParametricCreator {
};
SP<CWpImageDescriptionCreatorParamsV1> m_resource;
wl_client* pClient = nullptr;
uint32_t valuesSet = 0; // enum eValuesSet
wl_client* m_client = nullptr;
uint32_t m_valuesSet = 0; // enum eValuesSet
};
class CColorManagementImageDescription {
@ -145,13 +145,13 @@ class CColorManagementImageDescription {
wl_client* client();
SP<CWpImageDescriptionV1> resource();
WP<CColorManagementImageDescription> self;
WP<CColorManagementImageDescription> m_self;
NColorManagement::SImageDescription settings;
NColorManagement::SImageDescription m_settings;
private:
SP<CWpImageDescriptionV1> m_resource;
wl_client* pClient = nullptr;
wl_client* m_client = nullptr;
bool m_allowGetInformation = false;
friend class CColorManagementOutput;
@ -166,8 +166,8 @@ class CColorManagementImageDescriptionInfo {
private:
SP<CWpImageDescriptionInfoV1> m_resource;
wl_client* pClient = nullptr;
NColorManagement::SImageDescription settings;
wl_client* m_client = nullptr;
NColorManagement::SImageDescription m_settings;
};
class CColorManagementProtocol : public IWaylandProtocol {
@ -188,13 +188,13 @@ class CColorManagementProtocol : public IWaylandProtocol {
void destroyResource(CColorManagementParametricCreator* resource);
void destroyResource(CColorManagementImageDescription* resource);
std::vector<SP<CColorManager>> m_vManagers;
std::vector<SP<CColorManagementOutput>> m_vOutputs;
std::vector<SP<CColorManagementSurface>> m_vSurfaces;
std::vector<SP<CColorManagementFeedbackSurface>> m_vFeedbackSurfaces;
std::vector<SP<CColorManagementIccCreator>> m_vIccCreators;
std::vector<SP<CColorManagementParametricCreator>> m_vParametricCreators;
std::vector<SP<CColorManagementImageDescription>> m_vImageDescriptions;
std::vector<SP<CColorManager>> m_managers;
std::vector<SP<CColorManagementOutput>> m_outputs;
std::vector<SP<CColorManagementSurface>> m_surfaces;
std::vector<SP<CColorManagementFeedbackSurface>> m_feedbackSurfaces;
std::vector<SP<CColorManagementIccCreator>> m_iccCreators;
std::vector<SP<CColorManagementParametricCreator>> m_parametricCreators;
std::vector<SP<CColorManagementImageDescription>> m_imageDescriptions;
bool m_debug = false;
friend class CColorManager;

View File

@ -24,14 +24,14 @@ CContentTypeManager::CContentTypeManager(SP<CWpContentTypeManagerV1> resource) :
return;
}
const auto RESOURCE = PROTO::contentType->m_vContentTypes.emplace_back(makeShared<CContentType>(makeShared<CWpContentTypeV1>(r->client(), r->version(), id)));
const auto RESOURCE = PROTO::contentType->m_contentTypes.emplace_back(makeShared<CContentType>(makeShared<CWpContentTypeV1>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::contentType->m_vContentTypes.pop_back();
PROTO::contentType->m_contentTypes.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
SURF->m_contentType = RESOURCE;
});
@ -42,19 +42,19 @@ bool CContentTypeManager::good() {
}
CContentType::CContentType(WP<CWLSurfaceResource> surface) {
destroy = surface->m_events.destroy.registerListener([this](std::any d) { PROTO::contentType->destroyResource(this); });
m_destroy = surface->m_events.destroy.registerListener([this](std::any d) { PROTO::contentType->destroyResource(this); });
}
CContentType::CContentType(SP<CWpContentTypeV1> resource) : m_resource(resource) {
if UNLIKELY (!good())
return;
m_pClient = resource->client();
m_client = resource->client();
resource->setDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
resource->setOnDestroy([this](CWpContentTypeV1* r) { PROTO::contentType->destroyResource(this); });
resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { value = NContentType::fromWP(type); });
resource->setSetContentType([this](CWpContentTypeV1* r, wpContentTypeV1Type type) { m_value = NContentType::fromWP(type); });
}
bool CContentType::good() {
@ -62,7 +62,7 @@ bool CContentType::good() {
}
wl_client* CContentType::client() {
return m_pClient;
return m_client;
}
CContentTypeProtocol::CContentTypeProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -70,11 +70,11 @@ CContentTypeProtocol::CContentTypeProtocol(const wl_interface* iface, const int&
}
void CContentTypeProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CContentTypeManager>(makeShared<CWpContentTypeManagerV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CContentTypeManager>(makeShared<CWpContentTypeManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
@ -83,13 +83,13 @@ SP<CContentType> CContentTypeProtocol::getContentType(WP<CWLSurfaceResource> sur
if (surface->m_contentType.valid())
return surface->m_contentType.lock();
return m_vContentTypes.emplace_back(makeShared<CContentType>(surface));
return m_contentTypes.emplace_back(makeShared<CContentType>(surface));
}
void CContentTypeProtocol::destroyResource(CContentTypeManager* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CContentTypeProtocol::destroyResource(CContentType* resource) {
std::erase_if(m_vContentTypes, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_contentTypes, [&](const auto& other) { return other.get() == resource; });
}

View File

@ -22,15 +22,15 @@ class CContentType {
bool good();
wl_client* client();
NContentType::eContentType value = NContentType::CONTENT_TYPE_NONE;
NContentType::eContentType m_value = NContentType::CONTENT_TYPE_NONE;
WP<CContentType> self;
WP<CContentType> m_self;
private:
SP<CWpContentTypeV1> m_resource;
wl_client* m_pClient = nullptr;
wl_client* m_client = nullptr;
CHyprSignalListener destroy;
CHyprSignalListener m_destroy;
friend class CContentTypeProtocol;
};
@ -47,8 +47,8 @@ class CContentTypeProtocol : public IWaylandProtocol {
void destroyResource(CContentTypeManager* resource);
void destroyResource(CContentType* resource);
std::vector<SP<CContentTypeManager>> m_vManagers;
std::vector<SP<CContentType>> m_vContentTypes;
std::vector<SP<CContentTypeManager>> m_managers;
std::vector<SP<CContentType>> m_contentTypes;
friend class CContentTypeManager;
friend class CContentType;

View File

@ -7,15 +7,15 @@ CCursorShapeProtocol::CCursorShapeProtocol(const wl_interface* iface, const int&
}
void CCursorShapeProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [res](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [res](const auto& other) { return other->resource() == res; });
}
void CCursorShapeProtocol::onDeviceResourceDestroy(wl_resource* res) {
std::erase_if(m_vDevices, [res](const auto& other) { return other->resource() == res; });
std::erase_if(m_devices, [res](const auto& other) { return other->resource() == res; });
}
void CCursorShapeProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CWpCursorShapeManagerV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CWpCursorShapeManagerV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CWpCursorShapeManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CWpCursorShapeManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -33,7 +33,7 @@ void CCursorShapeProtocol::onGetTabletToolV2(CWpCursorShapeManagerV1* pMgr, uint
void CCursorShapeProtocol::createCursorShapeDevice(CWpCursorShapeManagerV1* pMgr, uint32_t id, wl_resource* resource) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vDevices.emplace_back(makeShared<CWpCursorShapeDeviceV1>(CLIENT, pMgr->version(), id));
const auto RESOURCE = m_devices.emplace_back(makeShared<CWpCursorShapeDeviceV1>(CLIENT, pMgr->version(), id));
RESOURCE->setOnDestroy([this](CWpCursorShapeDeviceV1* p) { this->onDeviceResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CWpCursorShapeDeviceV1* p) { this->onDeviceResourceDestroy(p->resource()); });
@ -51,5 +51,5 @@ void CCursorShapeProtocol::onSetShape(CWpCursorShapeDeviceV1* pMgr, uint32_t ser
event.shape = shape;
event.shapeName = CURSOR_SHAPE_NAMES.at(shape);
events.setShape.emit(event);
m_events.setShape.emit(event);
}

View File

@ -19,7 +19,7 @@ class CCursorShapeProtocol : public IWaylandProtocol {
struct {
CSignal setShape;
} events;
} m_events;
private:
void onManagerResourceDestroy(wl_resource* res);
@ -32,8 +32,8 @@ class CCursorShapeProtocol : public IWaylandProtocol {
void createCursorShapeDevice(CWpCursorShapeManagerV1* pMgr, uint32_t id, wl_resource* resource);
//
std::vector<SP<CWpCursorShapeDeviceV1>> m_vDevices;
std::vector<UP<CWpCursorShapeManagerV1>> m_vManagers;
std::vector<SP<CWpCursorShapeDeviceV1>> m_devices;
std::vector<UP<CWpCursorShapeManagerV1>> m_managers;
};
namespace PROTO {

View File

@ -6,20 +6,20 @@
#include <fcntl.h>
using namespace Hyprutils::OS;
CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRequestResource> request) : resource(resource_) {
CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRequestResource> request) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); });
resource->setDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setOnDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setDestroy([this](CWpDrmLeaseV1* r) { PROTO::lease->destroyResource(this); });
parent = request->parent;
requested = request->requested;
m_parent = request->m_parent;
m_requested = request->m_requested;
for (auto const& m : requested) {
if (!m->monitor || m->monitor->m_isBeingLeased) {
LOGM(ERR, "Rejecting lease: no monitor or monitor is being leased for {}", (m->monitor ? m->monitor->m_name : "null"));
resource->sendFinished();
for (auto const& m : m_requested) {
if (!m->m_monitor || m->m_monitor->m_isBeingLeased) {
LOGM(ERR, "Rejecting lease: no monitor or monitor is being leased for {}", (m->m_monitor ? m->m_monitor->m_name : "null"));
m_resource->sendFinished();
return;
}
}
@ -28,97 +28,97 @@ CDRMLeaseResource::CDRMLeaseResource(SP<CWpDrmLeaseV1> resource_, SP<CDRMLeaseRe
LOGM(LOG, "Leasing outputs: {}", [this]() {
std::string roll;
for (auto const& o : requested) {
roll += std::format("{} ", o->monitor->m_name);
for (auto const& o : m_requested) {
roll += std::format("{} ", o->m_monitor->m_name);
}
return roll;
}());
std::vector<SP<Aquamarine::IOutput>> outputs;
// reserve to avoid reallocations
outputs.reserve(requested.size());
outputs.reserve(m_requested.size());
for (auto const& m : requested) {
outputs.emplace_back(m->monitor->m_output);
for (auto const& m : m_requested) {
outputs.emplace_back(m->m_monitor->m_output);
}
auto aqlease = Aquamarine::CDRMLease::create(outputs);
if (!aqlease) {
LOGM(ERR, "Rejecting lease: backend failed to alloc a lease");
resource->sendFinished();
m_resource->sendFinished();
return;
}
lease = aqlease;
m_lease = aqlease;
for (auto const& m : requested) {
m->monitor->m_isBeingLeased = true;
for (auto const& m : m_requested) {
m->m_monitor->m_isBeingLeased = true;
}
listeners.destroyLease = lease->events.destroy.registerListener([this](std::any d) {
for (auto const& m : requested) {
if (m && m->monitor)
m->monitor->m_isBeingLeased = false;
m_listeners.destroyLease = m_lease->events.destroy.registerListener([this](std::any d) {
for (auto const& m : m_requested) {
if (m && m->m_monitor)
m->m_monitor->m_isBeingLeased = false;
}
resource->sendFinished();
LOGM(LOG, "Revoking lease for fd {}", lease->leaseFD);
m_resource->sendFinished();
LOGM(LOG, "Revoking lease for fd {}", m_lease->leaseFD);
});
LOGM(LOG, "Granting lease, sending fd {}", lease->leaseFD);
LOGM(LOG, "Granting lease, sending fd {}", m_lease->leaseFD);
resource->sendLeaseFd(lease->leaseFD);
m_resource->sendLeaseFd(m_lease->leaseFD);
close(lease->leaseFD);
close(m_lease->leaseFD);
}
bool CDRMLeaseResource::good() {
return resource->resource();
return m_resource->resource();
}
CDRMLeaseResource::~CDRMLeaseResource() {
// destroy in this order to ensure listener gets called
lease.reset();
listeners.destroyLease.reset();
m_lease.reset();
m_listeners.destroyLease.reset();
}
CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> resource_) : resource(resource_) {
CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseRequestV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setOnDestroy([this](CWpDrmLeaseRequestV1* r) { PROTO::lease->destroyResource(this); });
resource->setRequestConnector([this](CWpDrmLeaseRequestV1* r, wl_resource* conn) {
m_resource->setRequestConnector([this](CWpDrmLeaseRequestV1* r, wl_resource* conn) {
if (!conn) {
resource->error(-1, "Null connector");
m_resource->error(-1, "Null connector");
return;
}
auto CONNECTOR = CDRMLeaseConnectorResource::fromResource(conn);
if (std::find(requested.begin(), requested.end(), CONNECTOR) != requested.end()) {
resource->error(WP_DRM_LEASE_REQUEST_V1_ERROR_DUPLICATE_CONNECTOR, "Connector already requested");
if (std::find(m_requested.begin(), m_requested.end(), CONNECTOR) != m_requested.end()) {
m_resource->error(WP_DRM_LEASE_REQUEST_V1_ERROR_DUPLICATE_CONNECTOR, "Connector already requested");
return;
}
// TODO: when (if) we add multi, make sure this is from the correct device.
requested.emplace_back(CONNECTOR);
m_requested.emplace_back(CONNECTOR);
});
resource->setSubmit([this](CWpDrmLeaseRequestV1* r, uint32_t id) {
if (requested.empty()) {
resource->error(WP_DRM_LEASE_REQUEST_V1_ERROR_EMPTY_LEASE, "No connectors added");
m_resource->setSubmit([this](CWpDrmLeaseRequestV1* r, uint32_t id) {
if (m_requested.empty()) {
m_resource->error(WP_DRM_LEASE_REQUEST_V1_ERROR_EMPTY_LEASE, "No connectors added");
return;
}
auto RESOURCE = makeShared<CDRMLeaseResource>(makeShared<CWpDrmLeaseV1>(resource->client(), resource->version(), id), self.lock());
auto RESOURCE = makeShared<CDRMLeaseResource>(makeShared<CWpDrmLeaseV1>(m_resource->client(), m_resource->version(), id), m_self.lock());
if UNLIKELY (!RESOURCE) {
resource->noMemory();
m_resource->noMemory();
return;
}
PROTO::lease->m_vLeases.emplace_back(RESOURCE);
PROTO::lease->m_leases.emplace_back(RESOURCE);
// per protcol, after submit, this is dead.
PROTO::lease->destroyResource(this);
@ -126,111 +126,111 @@ CDRMLeaseRequestResource::CDRMLeaseRequestResource(SP<CWpDrmLeaseRequestV1> reso
}
bool CDRMLeaseRequestResource::good() {
return resource->resource();
return m_resource->resource();
}
SP<CDRMLeaseConnectorResource> CDRMLeaseConnectorResource::fromResource(wl_resource* res) {
auto data = (CDRMLeaseConnectorResource*)(((CWpDrmLeaseConnectorV1*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, PHLMONITOR monitor_) : monitor(monitor_), resource(resource_) {
CDRMLeaseConnectorResource::CDRMLeaseConnectorResource(SP<CWpDrmLeaseConnectorV1> resource_, PHLMONITOR monitor_) : m_monitor(monitor_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); });
resource->setDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setOnDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setDestroy([this](CWpDrmLeaseConnectorV1* r) { PROTO::lease->destroyResource(this); });
resource->setData(this);
m_resource->setData(this);
listeners.destroyMonitor = monitor->m_events.destroy.registerListener([this](std::any d) {
resource->sendWithdrawn();
dead = true;
m_listeners.destroyMonitor = m_monitor->m_events.destroy.registerListener([this](std::any d) {
m_resource->sendWithdrawn();
m_dead = true;
});
}
bool CDRMLeaseConnectorResource::good() {
return resource->resource();
return m_resource->resource();
}
void CDRMLeaseConnectorResource::sendData() {
resource->sendName(monitor->m_name.c_str());
resource->sendDescription(monitor->m_description.c_str());
m_resource->sendName(m_monitor->m_name.c_str());
m_resource->sendDescription(m_monitor->m_description.c_str());
auto AQDRMOutput = (Aquamarine::CDRMOutput*)monitor->m_output.get();
resource->sendConnectorId(AQDRMOutput->getConnectorID());
auto AQDRMOutput = (Aquamarine::CDRMOutput*)m_monitor->m_output.get();
m_resource->sendConnectorId(AQDRMOutput->getConnectorID());
resource->sendDone();
m_resource->sendDone();
}
CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resource_) : resource(resource_) {
CDRMLeaseDeviceResource::CDRMLeaseDeviceResource(SP<CWpDrmLeaseDeviceV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); });
resource->setRelease([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setOnDestroy([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); });
m_resource->setRelease([this](CWpDrmLeaseDeviceV1* r) { PROTO::lease->destroyResource(this); });
resource->setCreateLeaseRequest([this](CWpDrmLeaseDeviceV1* r, uint32_t id) {
auto RESOURCE = makeShared<CDRMLeaseRequestResource>(makeShared<CWpDrmLeaseRequestV1>(resource->client(), resource->version(), id));
m_resource->setCreateLeaseRequest([this](CWpDrmLeaseDeviceV1* r, uint32_t id) {
auto RESOURCE = makeShared<CDRMLeaseRequestResource>(makeShared<CWpDrmLeaseRequestV1>(m_resource->client(), m_resource->version(), id));
if UNLIKELY (!RESOURCE) {
resource->noMemory();
m_resource->noMemory();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
PROTO::lease->m_vRequests.emplace_back(RESOURCE);
PROTO::lease->m_requests.emplace_back(RESOURCE);
LOGM(LOG, "New lease request {}", id);
RESOURCE->parent = self;
RESOURCE->m_parent = m_self;
});
CFileDescriptor fd{((Aquamarine::CDRMBackend*)PROTO::lease->primaryDevice->backend.get())->getNonMasterFD()};
CFileDescriptor fd{((Aquamarine::CDRMBackend*)PROTO::lease->m_primaryDevice->m_backend.get())->getNonMasterFD()};
if (!fd.isValid()) {
LOGM(ERR, "Failed to dup fd in lease");
return;
}
LOGM(LOG, "Sending DRMFD {} to new lease device", fd.get());
resource->sendDrmFd(fd.get());
m_resource->sendDrmFd(fd.get());
for (auto const& m : PROTO::lease->primaryDevice->offeredOutputs) {
for (auto const& m : PROTO::lease->m_primaryDevice->m_offeredOutputs) {
if (m)
sendConnector(m.lock());
}
resource->sendDone();
m_resource->sendDone();
}
bool CDRMLeaseDeviceResource::good() {
return resource->resource();
return m_resource->resource();
}
void CDRMLeaseDeviceResource::sendConnector(PHLMONITOR monitor) {
if (std::find_if(connectorsSent.begin(), connectorsSent.end(), [monitor](const auto& e) { return e && !e->dead && e->monitor == monitor; }) != connectorsSent.end())
if (std::find_if(m_connectorsSent.begin(), m_connectorsSent.end(), [monitor](const auto& e) { return e && !e->m_dead && e->m_monitor == monitor; }) != m_connectorsSent.end())
return;
auto RESOURCE = makeShared<CDRMLeaseConnectorResource>(makeShared<CWpDrmLeaseConnectorV1>(resource->client(), resource->version(), 0), monitor);
auto RESOURCE = makeShared<CDRMLeaseConnectorResource>(makeShared<CWpDrmLeaseConnectorV1>(m_resource->client(), m_resource->version(), 0), monitor);
if UNLIKELY (!RESOURCE) {
resource->noMemory();
m_resource->noMemory();
return;
}
RESOURCE->parent = self;
RESOURCE->self = RESOURCE;
RESOURCE->m_parent = m_self;
RESOURCE->m_self = RESOURCE;
LOGM(LOG, "Sending new connector {}", monitor->m_name);
connectorsSent.emplace_back(RESOURCE);
PROTO::lease->m_vConnectors.emplace_back(RESOURCE);
m_connectorsSent.emplace_back(RESOURCE);
PROTO::lease->m_connectors.emplace_back(RESOURCE);
resource->sendConnector(RESOURCE->resource.get());
m_resource->sendConnector(RESOURCE->m_resource.get());
RESOURCE->sendData();
}
CDRMLeaseDevice::CDRMLeaseDevice(SP<Aquamarine::CDRMBackend> drmBackend) : backend(drmBackend) {
CDRMLeaseDevice::CDRMLeaseDevice(SP<Aquamarine::CDRMBackend> drmBackend) : m_backend(drmBackend) {
auto drm = (Aquamarine::CDRMBackend*)drmBackend.get();
CFileDescriptor fd{drm->getNonMasterFD()};
@ -240,8 +240,8 @@ CDRMLeaseDevice::CDRMLeaseDevice(SP<Aquamarine::CDRMBackend> drmBackend) : backe
return;
}
success = true;
name = drm->gpuName;
m_success = true;
m_name = drm->gpuName;
}
CDRMLeaseProtocol::CDRMLeaseProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -251,64 +251,64 @@ CDRMLeaseProtocol::CDRMLeaseProtocol(const wl_interface* iface, const int& ver,
auto drm = ((Aquamarine::CDRMBackend*)b.get())->self.lock();
primaryDevice = makeShared<CDRMLeaseDevice>(drm);
m_primaryDevice = makeShared<CDRMLeaseDevice>(drm);
if (primaryDevice->success)
if (m_primaryDevice->m_success)
break;
}
if (!primaryDevice || !primaryDevice->success)
if (!m_primaryDevice || !m_primaryDevice->m_success)
g_pEventLoopManager->doLater([]() { PROTO::lease.reset(); });
}
void CDRMLeaseProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CDRMLeaseDeviceResource>(makeShared<CWpDrmLeaseDeviceV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CDRMLeaseDeviceResource>(makeShared<CWpDrmLeaseDeviceV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
}
void CDRMLeaseProtocol::destroyResource(CDRMLeaseDeviceResource* resource) {
std::erase_if(m_vManagers, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_managers, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMLeaseProtocol::destroyResource(CDRMLeaseConnectorResource* resource) {
for (const auto& m : m_vManagers) {
std::erase_if(m->connectorsSent, [resource](const auto& e) { return e.expired() || e->dead || e.get() == resource; });
for (const auto& m : m_managers) {
std::erase_if(m->m_connectorsSent, [resource](const auto& e) { return e.expired() || e->m_dead || e.get() == resource; });
}
std::erase_if(m_vConnectors, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_connectors, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMLeaseProtocol::destroyResource(CDRMLeaseRequestResource* resource) {
std::erase_if(m_vRequests, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_requests, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMLeaseProtocol::destroyResource(CDRMLeaseResource* resource) {
std::erase_if(m_vLeases, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_leases, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMLeaseProtocol::offer(PHLMONITOR monitor) {
std::erase_if(primaryDevice->offeredOutputs, [](const auto& e) { return e.expired(); });
if (std::find(primaryDevice->offeredOutputs.begin(), primaryDevice->offeredOutputs.end(), monitor) != primaryDevice->offeredOutputs.end())
std::erase_if(m_primaryDevice->m_offeredOutputs, [](const auto& e) { return e.expired(); });
if (std::find(m_primaryDevice->m_offeredOutputs.begin(), m_primaryDevice->m_offeredOutputs.end(), monitor) != m_primaryDevice->m_offeredOutputs.end())
return;
if (monitor->m_output->getBackend()->type() != Aquamarine::AQ_BACKEND_DRM)
return;
if (monitor->m_output->getBackend() != primaryDevice->backend) {
if (monitor->m_output->getBackend() != m_primaryDevice->m_backend) {
LOGM(ERR, "Monitor {} cannot be leased: primaryDevice lease is for a different device", monitor->m_name);
return;
}
primaryDevice->offeredOutputs.emplace_back(monitor);
m_primaryDevice->m_offeredOutputs.emplace_back(monitor);
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->sendConnector(monitor);
m->resource->sendDone();
m->m_resource->sendDone();
}
}

View File

@ -26,18 +26,16 @@ class CDRMLeaseResource {
bool good();
WP<CDRMLeaseDeviceResource> parent;
std::vector<WP<CDRMLeaseConnectorResource>> requested;
SP<Aquamarine::CDRMLease> lease;
int leaseFD = -1;
WP<CDRMLeaseDeviceResource> m_parent;
std::vector<WP<CDRMLeaseConnectorResource>> m_requested;
SP<Aquamarine::CDRMLease> m_lease;
struct {
CHyprSignalListener destroyLease;
} listeners;
} m_listeners;
private:
SP<CWpDrmLeaseV1> resource;
SP<CWpDrmLeaseV1> m_resource;
};
class CDRMLeaseRequestResource {
@ -46,12 +44,12 @@ class CDRMLeaseRequestResource {
bool good();
WP<CDRMLeaseDeviceResource> parent;
WP<CDRMLeaseRequestResource> self;
std::vector<WP<CDRMLeaseConnectorResource>> requested;
WP<CDRMLeaseDeviceResource> m_parent;
WP<CDRMLeaseRequestResource> m_self;
std::vector<WP<CDRMLeaseConnectorResource>> m_requested;
private:
SP<CWpDrmLeaseRequestV1> resource;
SP<CWpDrmLeaseRequestV1> m_resource;
};
class CDRMLeaseConnectorResource {
@ -62,17 +60,17 @@ class CDRMLeaseConnectorResource {
bool good();
void sendData();
WP<CDRMLeaseConnectorResource> self;
WP<CDRMLeaseDeviceResource> parent;
PHLMONITORREF monitor;
bool dead = false;
WP<CDRMLeaseConnectorResource> m_self;
WP<CDRMLeaseDeviceResource> m_parent;
PHLMONITORREF m_monitor;
bool m_dead = false;
private:
SP<CWpDrmLeaseConnectorV1> resource;
SP<CWpDrmLeaseConnectorV1> m_resource;
struct {
CHyprSignalListener destroyMonitor;
} listeners;
} m_listeners;
friend class CDRMLeaseDeviceResource;
};
@ -84,12 +82,12 @@ class CDRMLeaseDeviceResource {
bool good();
void sendConnector(PHLMONITOR monitor);
std::vector<WP<CDRMLeaseConnectorResource>> connectorsSent;
std::vector<WP<CDRMLeaseConnectorResource>> m_connectorsSent;
WP<CDRMLeaseDeviceResource> self;
WP<CDRMLeaseDeviceResource> m_self;
private:
SP<CWpDrmLeaseDeviceV1> resource;
SP<CWpDrmLeaseDeviceV1> m_resource;
friend class CDRMLeaseProtocol;
};
@ -98,11 +96,11 @@ class CDRMLeaseDevice {
public:
CDRMLeaseDevice(SP<Aquamarine::CDRMBackend> drmBackend);
std::string name = "";
bool success = false;
SP<Aquamarine::CDRMBackend> backend;
std::string m_name = "";
bool m_success = false;
SP<Aquamarine::CDRMBackend> m_backend;
std::vector<PHLMONITORREF> offeredOutputs;
std::vector<PHLMONITORREF> m_offeredOutputs;
};
class CDRMLeaseProtocol : public IWaylandProtocol {
@ -120,12 +118,12 @@ class CDRMLeaseProtocol : public IWaylandProtocol {
void destroyResource(CDRMLeaseResource* resource);
//
std::vector<SP<CDRMLeaseDeviceResource>> m_vManagers;
std::vector<SP<CDRMLeaseConnectorResource>> m_vConnectors;
std::vector<SP<CDRMLeaseRequestResource>> m_vRequests;
std::vector<SP<CDRMLeaseResource>> m_vLeases;
std::vector<SP<CDRMLeaseDeviceResource>> m_managers;
std::vector<SP<CDRMLeaseConnectorResource>> m_connectors;
std::vector<SP<CDRMLeaseRequestResource>> m_requests;
std::vector<SP<CDRMLeaseResource>> m_leases;
SP<CDRMLeaseDevice> primaryDevice;
SP<CDRMLeaseDevice> m_primaryDevice;
friend class CDRMLeaseDeviceResource;
friend class CDRMLeaseConnectorResource;

View File

@ -45,95 +45,96 @@ void CDRMSyncPointState::signal() {
}
CDRMSyncobjSurfaceResource::CDRMSyncobjSurfaceResource(UP<CWpLinuxDrmSyncobjSurfaceV1>&& resource_, SP<CWLSurfaceResource> surface_) :
surface(surface_), resource(std::move(resource_)) {
m_surface(surface_), m_resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
resource->setOnDestroy([this](CWpLinuxDrmSyncobjSurfaceV1* r) { PROTO::sync->destroyResource(this); });
resource->setDestroy([this](CWpLinuxDrmSyncobjSurfaceV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setOnDestroy([this](CWpLinuxDrmSyncobjSurfaceV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setDestroy([this](CWpLinuxDrmSyncobjSurfaceV1* r) { PROTO::sync->destroyResource(this); });
resource->setSetAcquirePoint([this](CWpLinuxDrmSyncobjSurfaceV1* r, wl_resource* timeline_, uint32_t hi, uint32_t lo) {
if (!surface) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_SURFACE, "Surface is gone");
m_resource->setSetAcquirePoint([this](CWpLinuxDrmSyncobjSurfaceV1* r, wl_resource* timeline_, uint32_t hi, uint32_t lo) {
if (!m_surface) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_SURFACE, "Surface is gone");
return;
}
auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
pendingAcquire = {timeline->timeline, ((uint64_t)hi << 32) | (uint64_t)lo};
auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
m_pendingAcquire = {timeline->m_timeline, ((uint64_t)hi << 32) | (uint64_t)lo};
});
resource->setSetReleasePoint([this](CWpLinuxDrmSyncobjSurfaceV1* r, wl_resource* timeline_, uint32_t hi, uint32_t lo) {
if (!surface) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_SURFACE, "Surface is gone");
m_resource->setSetReleasePoint([this](CWpLinuxDrmSyncobjSurfaceV1* r, wl_resource* timeline_, uint32_t hi, uint32_t lo) {
if (!m_surface) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_SURFACE, "Surface is gone");
return;
}
auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
pendingRelease = {timeline->timeline, ((uint64_t)hi << 32) | (uint64_t)lo};
auto timeline = CDRMSyncobjTimelineResource::fromResource(timeline_);
m_pendingRelease = {timeline->m_timeline, ((uint64_t)hi << 32) | (uint64_t)lo};
});
listeners.surfacePrecommit = surface->m_events.precommit.registerListener([this](std::any d) {
if (!surface->m_pending.updated.buffer || !surface->m_pending.buffer) {
if (pendingAcquire.timeline() || pendingRelease.timeline()) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_BUFFER, "Missing buffer");
surface->m_pending.rejected = true;
m_listeners.surfacePrecommit = m_surface->m_events.precommit.registerListener([this](std::any d) {
if (!m_surface->m_pending.updated.buffer || !m_surface->m_pending.buffer) {
if (m_pendingAcquire.timeline() || m_pendingRelease.timeline()) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_BUFFER, "Missing buffer");
m_surface->m_pending.rejected = true;
}
return;
}
if (!pendingAcquire.timeline()) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_ACQUIRE_POINT, "Missing acquire timeline");
surface->m_pending.rejected = true;
if (!m_pendingAcquire.timeline()) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_ACQUIRE_POINT, "Missing acquire timeline");
m_surface->m_pending.rejected = true;
return;
}
if (!pendingRelease.timeline()) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_RELEASE_POINT, "Missing release timeline");
surface->m_pending.rejected = true;
if (!m_pendingRelease.timeline()) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_NO_RELEASE_POINT, "Missing release timeline");
m_surface->m_pending.rejected = true;
return;
}
if (pendingAcquire.timeline() == pendingRelease.timeline() && pendingAcquire.point() >= pendingRelease.point()) {
resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_CONFLICTING_POINTS, "Acquire and release points are on the same timeline, and acquire >= release");
surface->m_pending.rejected = true;
if (m_pendingAcquire.timeline() == m_pendingRelease.timeline() && m_pendingAcquire.point() >= m_pendingRelease.point()) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_SURFACE_V1_ERROR_CONFLICTING_POINTS, "Acquire and release points are on the same timeline, and acquire >= release");
m_surface->m_pending.rejected = true;
return;
}
surface->m_pending.updated.acquire = true;
surface->m_pending.acquire = pendingAcquire;
pendingAcquire = {};
m_surface->m_pending.updated.acquire = true;
m_surface->m_pending.acquire = m_pendingAcquire;
m_pendingAcquire = {};
surface->m_pending.buffer->addReleasePoint(pendingRelease);
pendingRelease = {};
m_surface->m_pending.buffer->addReleasePoint(m_pendingRelease);
m_pendingRelease = {};
});
}
bool CDRMSyncobjSurfaceResource::good() {
return resource->resource();
return m_resource->resource();
}
CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(UP<CWpLinuxDrmSyncobjTimelineV1>&& resource_, CFileDescriptor&& fd_) : fd(std::move(fd_)), resource(std::move(resource_)) {
CDRMSyncobjTimelineResource::CDRMSyncobjTimelineResource(UP<CWpLinuxDrmSyncobjTimelineV1>&& resource_, CFileDescriptor&& fd_) :
m_fd(std::move(fd_)), m_resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
resource->setOnDestroy([this](CWpLinuxDrmSyncobjTimelineV1* r) { PROTO::sync->destroyResource(this); });
resource->setDestroy([this](CWpLinuxDrmSyncobjTimelineV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setOnDestroy([this](CWpLinuxDrmSyncobjTimelineV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setDestroy([this](CWpLinuxDrmSyncobjTimelineV1* r) { PROTO::sync->destroyResource(this); });
timeline = CSyncTimeline::create(PROTO::sync->drmFD, std::move(fd));
m_timeline = CSyncTimeline::create(PROTO::sync->m_drmFD, std::move(m_fd));
if (!timeline) {
resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_INVALID_TIMELINE, "Timeline failed importing");
if (!m_timeline) {
m_resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_INVALID_TIMELINE, "Timeline failed importing");
return;
}
}
WP<CDRMSyncobjTimelineResource> CDRMSyncobjTimelineResource::fromResource(wl_resource* res) {
for (const auto& r : PROTO::sync->m_vTimelines) {
if (r && r->resource && r->resource->resource() == res)
for (const auto& r : PROTO::sync->m_timelines) {
if (r && r->m_resource && r->m_resource->resource() == res)
return r;
}
@ -141,38 +142,38 @@ WP<CDRMSyncobjTimelineResource> CDRMSyncobjTimelineResource::fromResource(wl_res
}
bool CDRMSyncobjTimelineResource::good() {
return resource->resource();
return m_resource->resource();
}
CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjManagerV1>&& resource_) : resource(std::move(resource_)) {
CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjManagerV1>&& resource_) : m_resource(std::move(resource_)) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
resource->setDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setOnDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
m_resource->setDestroy([this](CWpLinuxDrmSyncobjManagerV1* r) { PROTO::sync->destroyResource(this); });
resource->setGetSurface([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, wl_resource* surf) {
m_resource->setGetSurface([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, wl_resource* surf) {
if UNLIKELY (!surf) {
resource->error(-1, "Invalid surface");
m_resource->error(-1, "Invalid surface");
return;
}
auto SURF = CWLSurfaceResource::fromResource(surf);
if UNLIKELY (!SURF) {
resource->error(-1, "Invalid surface (2)");
m_resource->error(-1, "Invalid surface (2)");
return;
}
if UNLIKELY (SURF->m_syncobj) {
resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_SURFACE_EXISTS, "Surface already has a syncobj attached");
m_resource->error(WP_LINUX_DRM_SYNCOBJ_MANAGER_V1_ERROR_SURFACE_EXISTS, "Surface already has a syncobj attached");
return;
}
const auto& RESOURCE = PROTO::sync->m_vSurfaces.emplace_back(
makeUnique<CDRMSyncobjSurfaceResource>(makeUnique<CWpLinuxDrmSyncobjSurfaceV1>(resource->client(), resource->version(), id), SURF));
const auto& RESOURCE = PROTO::sync->m_surfaces.emplace_back(
makeUnique<CDRMSyncobjSurfaceResource>(makeUnique<CWpLinuxDrmSyncobjSurfaceV1>(m_resource->client(), m_resource->version(), id), SURF));
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::sync->m_vSurfaces.pop_back();
m_resource->noMemory();
PROTO::sync->m_surfaces.pop_back();
return;
}
@ -181,12 +182,12 @@ CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjMana
LOGM(LOG, "New linux_syncobj at {:x} for surface {:x}", (uintptr_t)RESOURCE.get(), (uintptr_t)SURF.get());
});
resource->setImportTimeline([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, int32_t fd) {
const auto& RESOURCE = PROTO::sync->m_vTimelines.emplace_back(
makeUnique<CDRMSyncobjTimelineResource>(makeUnique<CWpLinuxDrmSyncobjTimelineV1>(resource->client(), resource->version(), id), CFileDescriptor{fd}));
m_resource->setImportTimeline([this](CWpLinuxDrmSyncobjManagerV1* r, uint32_t id, int32_t fd) {
const auto& RESOURCE = PROTO::sync->m_timelines.emplace_back(
makeUnique<CDRMSyncobjTimelineResource>(makeUnique<CWpLinuxDrmSyncobjTimelineV1>(m_resource->client(), m_resource->version(), id), CFileDescriptor{fd}));
if UNLIKELY (!RESOURCE->good()) {
resource->noMemory();
PROTO::sync->m_vTimelines.pop_back();
m_resource->noMemory();
PROTO::sync->m_timelines.pop_back();
return;
}
@ -195,29 +196,30 @@ CDRMSyncobjManagerResource::CDRMSyncobjManagerResource(UP<CWpLinuxDrmSyncobjMana
}
bool CDRMSyncobjManagerResource::good() {
return resource->resource();
return m_resource->resource();
}
CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name), drmFD(g_pCompositor->m_drmFD) {}
CDRMSyncobjProtocol::CDRMSyncobjProtocol(const wl_interface* iface, const int& ver, const std::string& name) :
IWaylandProtocol(iface, ver, name), m_drmFD(g_pCompositor->m_drmFD) {}
void CDRMSyncobjProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto& RESOURCE = m_vManagers.emplace_back(makeUnique<CDRMSyncobjManagerResource>(makeUnique<CWpLinuxDrmSyncobjManagerV1>(client, ver, id)));
const auto& RESOURCE = m_managers.emplace_back(makeUnique<CDRMSyncobjManagerResource>(makeUnique<CWpLinuxDrmSyncobjManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CDRMSyncobjProtocol::destroyResource(CDRMSyncobjManagerResource* resource) {
std::erase_if(m_vManagers, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_managers, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMSyncobjProtocol::destroyResource(CDRMSyncobjTimelineResource* resource) {
std::erase_if(m_vTimelines, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_timelines, [resource](const auto& e) { return e.get() == resource; });
}
void CDRMSyncobjProtocol::destroyResource(CDRMSyncobjSurfaceResource* resource) {
std::erase_if(m_vSurfaces, [resource](const auto& e) { return e.get() == resource; });
std::erase_if(m_surfaces, [resource](const auto& e) { return e.get() == resource; });
}

View File

@ -43,15 +43,15 @@ class CDRMSyncobjSurfaceResource {
bool good();
private:
WP<CWLSurfaceResource> surface;
UP<CWpLinuxDrmSyncobjSurfaceV1> resource;
WP<CWLSurfaceResource> m_surface;
UP<CWpLinuxDrmSyncobjSurfaceV1> m_resource;
CDRMSyncPointState pendingAcquire;
CDRMSyncPointState pendingRelease;
CDRMSyncPointState m_pendingAcquire;
CDRMSyncPointState m_pendingRelease;
struct {
CHyprSignalListener surfacePrecommit;
} listeners;
} m_listeners;
};
class CDRMSyncobjTimelineResource {
@ -62,11 +62,11 @@ class CDRMSyncobjTimelineResource {
bool good();
Hyprutils::OS::CFileDescriptor fd;
SP<CSyncTimeline> timeline;
Hyprutils::OS::CFileDescriptor m_fd;
SP<CSyncTimeline> m_timeline;
private:
UP<CWpLinuxDrmSyncobjTimelineV1> resource;
UP<CWpLinuxDrmSyncobjTimelineV1> m_resource;
};
class CDRMSyncobjManagerResource {
@ -77,7 +77,7 @@ class CDRMSyncobjManagerResource {
bool good();
private:
UP<CWpLinuxDrmSyncobjManagerV1> resource;
UP<CWpLinuxDrmSyncobjManagerV1> m_resource;
};
class CDRMSyncobjProtocol : public IWaylandProtocol {
@ -93,12 +93,12 @@ class CDRMSyncobjProtocol : public IWaylandProtocol {
void destroyResource(CDRMSyncobjSurfaceResource* resource);
//
std::vector<UP<CDRMSyncobjManagerResource>> m_vManagers;
std::vector<UP<CDRMSyncobjTimelineResource>> m_vTimelines;
std::vector<UP<CDRMSyncobjSurfaceResource>> m_vSurfaces;
std::vector<UP<CDRMSyncobjManagerResource>> m_managers;
std::vector<UP<CDRMSyncobjTimelineResource>> m_timelines;
std::vector<UP<CDRMSyncobjSurfaceResource>> m_surfaces;
//
int drmFD = -1;
int m_drmFD = -1;
friend class CDRMSyncobjManagerResource;
friend class CDRMSyncobjTimelineResource;

View File

@ -4,60 +4,60 @@
#include "core/Seat.hpp"
using namespace Hyprutils::OS;
CWLRDataOffer::CWLRDataOffer(SP<CZwlrDataControlOfferV1> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
CWLRDataOffer::CWLRDataOffer(SP<CZwlrDataControlOfferV1> resource_, SP<IDataSource> source_) : m_source(source_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setOnDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setOnDestroy([this](CZwlrDataControlOfferV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setReceive([this](CZwlrDataControlOfferV1* r, const char* mime, int32_t fd) {
m_resource->setReceive([this](CZwlrDataControlOfferV1* r, const char* mime, int32_t fd) {
CFileDescriptor sendFd{fd};
if (!source) {
if (!m_source) {
LOGM(WARN, "Possible bug: Receive on an offer w/o a source");
return;
}
if (dead) {
if (m_dead) {
LOGM(WARN, "Possible bug: Receive on an offer that's dead");
return;
}
LOGM(LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)source.get());
LOGM(LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)m_source.get());
source->send(mime, std::move(sendFd));
m_source->send(mime, std::move(sendFd));
});
}
bool CWLRDataOffer::good() {
return resource->resource();
return m_resource->resource();
}
void CWLRDataOffer::sendData() {
if UNLIKELY (!source)
if UNLIKELY (!m_source)
return;
for (auto const& m : source->mimes()) {
resource->sendOffer(m.c_str());
for (auto const& m : m_source->mimes()) {
m_resource->sendOffer(m.c_str());
}
}
CWLRDataSource::CWLRDataSource(SP<CZwlrDataControlSourceV1> resource_, SP<CWLRDataDevice> device_) : device(device_), resource(resource_) {
CWLRDataSource::CWLRDataSource(SP<CZwlrDataControlSourceV1> resource_, SP<CWLRDataDevice> device_) : m_device(device_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setData(this);
m_resource->setData(this);
resource->setDestroy([this](CZwlrDataControlSourceV1* r) {
m_resource->setDestroy([this](CZwlrDataControlSourceV1* r) {
m_events.destroy.emit();
PROTO::dataWlr->destroyResource(this);
});
resource->setOnDestroy([this](CZwlrDataControlSourceV1* r) {
m_resource->setOnDestroy([this](CZwlrDataControlSourceV1* r) {
m_events.destroy.emit();
PROTO::dataWlr->destroyResource(this);
});
resource->setOffer([this](CZwlrDataControlSourceV1* r, const char* mime) { mimeTypes.emplace_back(mime); });
m_resource->setOffer([this](CZwlrDataControlSourceV1* r, const char* mime) { m_mimeTypes.emplace_back(mime); });
}
CWLRDataSource::~CWLRDataSource() {
@ -66,51 +66,51 @@ CWLRDataSource::~CWLRDataSource() {
SP<CWLRDataSource> CWLRDataSource::fromResource(wl_resource* res) {
auto data = (CWLRDataSource*)(((CZwlrDataControlSourceV1*)wl_resource_get_user_data(res))->data());
return data ? data->self.lock() : nullptr;
return data ? data->m_self.lock() : nullptr;
}
bool CWLRDataSource::good() {
return resource->resource();
return m_resource->resource();
}
std::vector<std::string> CWLRDataSource::mimes() {
return mimeTypes;
return m_mimeTypes;
}
void CWLRDataSource::send(const std::string& mime, CFileDescriptor fd) {
if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end()) {
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end()) {
LOGM(ERR, "Compositor/App bug: CWLRDataSource::sendAskSend with non-existent mime");
return;
}
resource->sendSend(mime.c_str(), fd.get());
m_resource->sendSend(mime.c_str(), fd.get());
}
void CWLRDataSource::accepted(const std::string& mime) {
if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end())
if (std::find(m_mimeTypes.begin(), m_mimeTypes.end(), mime) == m_mimeTypes.end())
LOGM(ERR, "Compositor/App bug: CWLRDataSource::sendAccepted with non-existent mime");
// wlr has no accepted
}
void CWLRDataSource::cancelled() {
resource->sendCancelled();
m_resource->sendCancelled();
}
void CWLRDataSource::error(uint32_t code, const std::string& msg) {
resource->error(code, msg);
m_resource->error(code, msg);
}
CWLRDataDevice::CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_) : resource(resource_) {
CWLRDataDevice::CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
pClient = resource->client();
m_client = m_resource->client();
resource->setDestroy([this](CZwlrDataControlDeviceV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setOnDestroy([this](CZwlrDataControlDeviceV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setDestroy([this](CZwlrDataControlDeviceV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setOnDestroy([this](CZwlrDataControlDeviceV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setSetSelection([](CZwlrDataControlDeviceV1* r, wl_resource* sourceR) {
m_resource->setSetSelection([](CZwlrDataControlDeviceV1* r, wl_resource* sourceR) {
auto source = sourceR ? CWLRDataSource::fromResource(sourceR) : CSharedPointer<CWLRDataSource>{};
if (!source) {
LOGM(LOG, "wlr reset selection received");
@ -127,7 +127,7 @@ CWLRDataDevice::CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_) : resourc
g_pSeatManager->setCurrentSelection(source);
});
resource->setSetPrimarySelection([](CZwlrDataControlDeviceV1* r, wl_resource* sourceR) {
m_resource->setSetPrimarySelection([](CZwlrDataControlDeviceV1* r, wl_resource* sourceR) {
auto source = sourceR ? CWLRDataSource::fromResource(sourceR) : CSharedPointer<CWLRDataSource>{};
if (!source) {
LOGM(LOG, "wlr reset primary selection received");
@ -146,11 +146,11 @@ CWLRDataDevice::CWLRDataDevice(SP<CZwlrDataControlDeviceV1> resource_) : resourc
}
bool CWLRDataDevice::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CWLRDataDevice::client() {
return pClient;
return m_client;
}
void CWLRDataDevice::sendInitialSelections() {
@ -159,40 +159,40 @@ void CWLRDataDevice::sendInitialSelections() {
}
void CWLRDataDevice::sendDataOffer(SP<CWLRDataOffer> offer) {
resource->sendDataOffer(offer->resource.get());
m_resource->sendDataOffer(offer->m_resource.get());
}
void CWLRDataDevice::sendSelection(SP<CWLRDataOffer> selection) {
resource->sendSelection(selection->resource.get());
m_resource->sendSelection(selection->m_resource.get());
}
void CWLRDataDevice::sendPrimarySelection(SP<CWLRDataOffer> selection) {
resource->sendPrimarySelection(selection->resource.get());
m_resource->sendPrimarySelection(selection->m_resource.get());
}
CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataControlManagerV1> resource_) : resource(resource_) {
CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataControlManagerV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setOnDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); });
m_resource->setOnDestroy([this](CZwlrDataControlManagerV1* r) { PROTO::dataWlr->destroyResource(this); });
resource->setGetDataDevice([this](CZwlrDataControlManagerV1* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::dataWlr->m_vDevices.emplace_back(makeShared<CWLRDataDevice>(makeShared<CZwlrDataControlDeviceV1>(r->client(), r->version(), id)));
m_resource->setGetDataDevice([this](CZwlrDataControlManagerV1* r, uint32_t id, wl_resource* seat) {
const auto RESOURCE = PROTO::dataWlr->m_devices.emplace_back(makeShared<CWLRDataDevice>(makeShared<CZwlrDataControlDeviceV1>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::dataWlr->m_vDevices.pop_back();
PROTO::dataWlr->m_devices.pop_back();
return;
}
RESOURCE->self = RESOURCE;
device = RESOURCE;
m_device = RESOURCE;
for (auto const& s : sources) {
for (auto const& s : m_sources) {
if (!s)
continue;
s->device = RESOURCE;
s->m_device = RESOURCE;
}
RESOURCE->sendInitialSelections();
@ -200,31 +200,31 @@ CWLRDataControlManagerResource::CWLRDataControlManagerResource(SP<CZwlrDataContr
LOGM(LOG, "New wlr data device bound at {:x}", (uintptr_t)RESOURCE.get());
});
resource->setCreateDataSource([this](CZwlrDataControlManagerV1* r, uint32_t id) {
std::erase_if(sources, [](const auto& e) { return e.expired(); });
m_resource->setCreateDataSource([this](CZwlrDataControlManagerV1* r, uint32_t id) {
std::erase_if(m_sources, [](const auto& e) { return e.expired(); });
const auto RESOURCE =
PROTO::dataWlr->m_vSources.emplace_back(makeShared<CWLRDataSource>(makeShared<CZwlrDataControlSourceV1>(r->client(), r->version(), id), device.lock()));
PROTO::dataWlr->m_sources.emplace_back(makeShared<CWLRDataSource>(makeShared<CZwlrDataControlSourceV1>(r->client(), r->version(), id), m_device.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::dataWlr->m_vSources.pop_back();
PROTO::dataWlr->m_sources.pop_back();
return;
}
if (!device)
if (!m_device)
LOGM(WARN, "New data source before a device was created");
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
sources.emplace_back(RESOURCE);
m_sources.emplace_back(RESOURCE);
LOGM(LOG, "New wlr data source bound at {:x}", (uintptr_t)RESOURCE.get());
});
}
bool CWLRDataControlManagerResource::good() {
return resource->resource();
return m_resource->resource();
}
CDataDeviceWLRProtocol::CDataDeviceWLRProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -232,11 +232,11 @@ CDataDeviceWLRProtocol::CDataDeviceWLRProtocol(const wl_interface* iface, const
}
void CDataDeviceWLRProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLRDataControlManagerResource>(makeShared<CZwlrDataControlManagerV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CWLRDataControlManagerResource>(makeShared<CZwlrDataControlManagerV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
@ -244,39 +244,39 @@ void CDataDeviceWLRProtocol::bindManager(wl_client* client, void* data, uint32_t
}
void CDataDeviceWLRProtocol::destroyResource(CWLRDataControlManagerResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CDataDeviceWLRProtocol::destroyResource(CWLRDataSource* resource) {
std::erase_if(m_vSources, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_sources, [&](const auto& other) { return other.get() == resource; });
}
void CDataDeviceWLRProtocol::destroyResource(CWLRDataDevice* resource) {
std::erase_if(m_vDevices, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_devices, [&](const auto& other) { return other.get() == resource; });
}
void CDataDeviceWLRProtocol::destroyResource(CWLRDataOffer* resource) {
std::erase_if(m_vOffers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_offers, [&](const auto& other) { return other.get() == resource; });
}
void CDataDeviceWLRProtocol::sendSelectionToDevice(SP<CWLRDataDevice> dev, SP<IDataSource> sel, bool primary) {
if (!sel) {
if (primary)
dev->resource->sendPrimarySelectionRaw(nullptr);
dev->m_resource->sendPrimarySelectionRaw(nullptr);
else
dev->resource->sendSelectionRaw(nullptr);
dev->m_resource->sendSelectionRaw(nullptr);
return;
}
const auto OFFER = m_vOffers.emplace_back(makeShared<CWLRDataOffer>(makeShared<CZwlrDataControlOfferV1>(dev->resource->client(), dev->resource->version(), 0), sel));
const auto OFFER = m_offers.emplace_back(makeShared<CWLRDataOffer>(makeShared<CZwlrDataControlOfferV1>(dev->m_resource->client(), dev->m_resource->version(), 0), sel));
if (!OFFER->good()) {
dev->resource->noMemory();
m_vOffers.pop_back();
dev->m_resource->noMemory();
m_offers.pop_back();
return;
}
OFFER->primary = primary;
OFFER->m_primary = primary;
LOGM(LOG, "New {}offer {:x} for data source {:x}", primary ? "primary " : " ", (uintptr_t)OFFER.get(), (uintptr_t)sel.get());
@ -289,18 +289,18 @@ void CDataDeviceWLRProtocol::sendSelectionToDevice(SP<CWLRDataDevice> dev, SP<ID
}
void CDataDeviceWLRProtocol::setSelection(SP<IDataSource> source, bool primary) {
for (auto const& o : m_vOffers) {
if (o->source && o->source->hasDnd())
for (auto const& o : m_offers) {
if (o->m_source && o->m_source->hasDnd())
continue;
if (o->primary != primary)
if (o->m_primary != primary)
continue;
o->dead = true;
o->m_dead = true;
}
if (!source) {
LOGM(LOG, "resetting {}selection", primary ? "primary " : " ");
for (auto const& d : m_vDevices) {
for (auto const& d : m_devices) {
sendSelectionToDevice(d, nullptr, primary);
}
@ -309,14 +309,14 @@ void CDataDeviceWLRProtocol::setSelection(SP<IDataSource> source, bool primary)
LOGM(LOG, "New {}selection for data source {:x}", primary ? "primary" : "", (uintptr_t)source.get());
for (auto const& d : m_vDevices) {
for (auto const& d : m_devices) {
sendSelectionToDevice(d, source, primary);
}
}
SP<CWLRDataDevice> CDataDeviceWLRProtocol::dataDeviceForClient(wl_client* c) {
auto it = std::find_if(m_vDevices.begin(), m_vDevices.end(), [c](const auto& e) { return e->client() == c; });
if (it == m_vDevices.end())
auto it = std::find_if(m_devices.begin(), m_devices.end(), [c](const auto& e) { return e->client() == c; });
if (it == m_devices.end())
return nullptr;
return *it;
}

View File

@ -19,13 +19,13 @@ class CWLRDataOffer {
bool good();
void sendData();
bool dead = false;
bool primary = false;
bool m_dead = false;
bool m_primary = false;
WP<IDataSource> source;
WP<IDataSource> m_source;
private:
SP<CZwlrDataControlOfferV1> resource;
SP<CZwlrDataControlOfferV1> m_resource;
friend class CWLRDataDevice;
};
@ -44,12 +44,12 @@ class CWLRDataSource : public IDataSource {
virtual void cancelled();
virtual void error(uint32_t code, const std::string& msg);
std::vector<std::string> mimeTypes;
WP<CWLRDataSource> self;
WP<CWLRDataDevice> device;
std::vector<std::string> m_mimeTypes;
WP<CWLRDataSource> m_self;
WP<CWLRDataDevice> m_device;
private:
SP<CZwlrDataControlSourceV1> resource;
SP<CZwlrDataControlSourceV1> m_resource;
};
class CWLRDataDevice {
@ -67,8 +67,8 @@ class CWLRDataDevice {
WP<CWLRDataDevice> self;
private:
SP<CZwlrDataControlDeviceV1> resource;
wl_client* pClient = nullptr;
SP<CZwlrDataControlDeviceV1> m_resource;
wl_client* m_client = nullptr;
friend class CDataDeviceWLRProtocol;
};
@ -79,11 +79,11 @@ class CWLRDataControlManagerResource {
bool good();
WP<CWLRDataDevice> device;
std::vector<WP<CWLRDataSource>> sources;
WP<CWLRDataDevice> m_device;
std::vector<WP<CWLRDataSource>> m_sources;
private:
SP<CZwlrDataControlManagerV1> resource;
SP<CZwlrDataControlManagerV1> m_resource;
};
class CDataDeviceWLRProtocol : public IWaylandProtocol {
@ -99,10 +99,10 @@ class CDataDeviceWLRProtocol : public IWaylandProtocol {
void destroyResource(CWLRDataOffer* resource);
//
std::vector<SP<CWLRDataControlManagerResource>> m_vManagers;
std::vector<SP<CWLRDataSource>> m_vSources;
std::vector<SP<CWLRDataDevice>> m_vDevices;
std::vector<SP<CWLRDataOffer>> m_vOffers;
std::vector<SP<CWLRDataControlManagerResource>> m_managers;
std::vector<SP<CWLRDataSource>> m_sources;
std::vector<SP<CWLRDataDevice>> m_devices;
std::vector<SP<CWLRDataOffer>> m_offers;
//
void setSelection(SP<IDataSource> source, bool primary);

View File

@ -8,23 +8,23 @@
#include <wayland-server.h>
CFocusGrabSurfaceState::CFocusGrabSurfaceState(CFocusGrab* grab, SP<CWLSurfaceResource> surface) {
listeners.destroy = surface->m_events.destroy.registerListener([=](std::any d) { grab->eraseSurface(surface); });
m_listeners.destroy = surface->m_events.destroy.registerListener([=](std::any d) { grab->eraseSurface(surface); });
}
CFocusGrab::CFocusGrab(SP<CHyprlandFocusGrabV1> resource_) : resource(resource_) {
if UNLIKELY (!resource->resource())
CFocusGrab::CFocusGrab(SP<CHyprlandFocusGrabV1> resource_) : m_resource(resource_) {
if UNLIKELY (!m_resource->resource())
return;
grab = makeShared<CSeatGrab>();
grab->m_keyboard = true;
grab->m_pointer = true;
grab->setCallback([this]() { finish(true); });
m_grab = makeShared<CSeatGrab>();
m_grab->m_keyboard = true;
m_grab->m_pointer = true;
m_grab->setCallback([this]() { finish(true); });
resource->setDestroy([this](CHyprlandFocusGrabV1* pMgr) { PROTO::focusGrab->destroyGrab(this); });
resource->setOnDestroy([this](CHyprlandFocusGrabV1* pMgr) { PROTO::focusGrab->destroyGrab(this); });
resource->setAddSurface([this](CHyprlandFocusGrabV1* pMgr, wl_resource* surface) { addSurface(CWLSurfaceResource::fromResource(surface)); });
resource->setRemoveSurface([this](CHyprlandFocusGrabV1* pMgr, wl_resource* surface) { removeSurface(CWLSurfaceResource::fromResource(surface)); });
resource->setCommit([this](CHyprlandFocusGrabV1* pMgr) { commit(); });
m_resource->setDestroy([this](CHyprlandFocusGrabV1* pMgr) { PROTO::focusGrab->destroyGrab(this); });
m_resource->setOnDestroy([this](CHyprlandFocusGrabV1* pMgr) { PROTO::focusGrab->destroyGrab(this); });
m_resource->setAddSurface([this](CHyprlandFocusGrabV1* pMgr, wl_resource* surface) { addSurface(CWLSurfaceResource::fromResource(surface)); });
m_resource->setRemoveSurface([this](CHyprlandFocusGrabV1* pMgr, wl_resource* surface) { removeSurface(CWLSurfaceResource::fromResource(surface)); });
m_resource->setCommit([this](CHyprlandFocusGrabV1* pMgr) { commit(); });
}
CFocusGrab::~CFocusGrab() {
@ -32,21 +32,21 @@ CFocusGrab::~CFocusGrab() {
}
bool CFocusGrab::good() {
return resource->resource();
return m_resource->resource();
}
bool CFocusGrab::isSurfaceComitted(SP<CWLSurfaceResource> surface) {
auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [surface](const auto& o) { return o.first == surface; });
if (iter == m_mSurfaces.end())
auto iter = std::find_if(m_surfaces.begin(), m_surfaces.end(), [surface](const auto& o) { return o.first == surface; });
if (iter == m_surfaces.end())
return false;
return iter->second->state == CFocusGrabSurfaceState::Comitted;
return iter->second->m_state == CFocusGrabSurfaceState::Comitted;
}
void CFocusGrab::start() {
if (!m_bGrabActive) {
m_bGrabActive = true;
g_pSeatManager->setGrab(grab);
if (!m_grabActive) {
m_grabActive = true;
g_pSeatManager->setGrab(m_grab);
}
// Ensure new surfaces are focused if under the mouse when comitted.
@ -55,33 +55,33 @@ void CFocusGrab::start() {
}
void CFocusGrab::finish(bool sendCleared) {
if (m_bGrabActive) {
m_bGrabActive = false;
if (m_grabActive) {
m_grabActive = false;
if (g_pSeatManager->m_seatGrab == grab)
if (g_pSeatManager->m_seatGrab == m_grab)
g_pSeatManager->setGrab(nullptr);
grab->clear();
m_mSurfaces.clear();
m_grab->clear();
m_surfaces.clear();
if (sendCleared)
resource->sendCleared();
m_resource->sendCleared();
}
}
void CFocusGrab::addSurface(SP<CWLSurfaceResource> surface) {
auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [surface](const auto& e) { return e.first == surface; });
if (iter == m_mSurfaces.end())
m_mSurfaces.emplace(surface, makeUnique<CFocusGrabSurfaceState>(this, surface));
auto iter = std::find_if(m_surfaces.begin(), m_surfaces.end(), [surface](const auto& e) { return e.first == surface; });
if (iter == m_surfaces.end())
m_surfaces.emplace(surface, makeUnique<CFocusGrabSurfaceState>(this, surface));
}
void CFocusGrab::removeSurface(SP<CWLSurfaceResource> surface) {
auto iter = m_mSurfaces.find(surface);
if (iter != m_mSurfaces.end()) {
if (iter->second->state == CFocusGrabSurfaceState::PendingAddition)
m_mSurfaces.erase(iter);
auto iter = m_surfaces.find(surface);
if (iter != m_surfaces.end()) {
if (iter->second->m_state == CFocusGrabSurfaceState::PendingAddition)
m_surfaces.erase(iter);
else
iter->second->state = CFocusGrabSurfaceState::PendingRemoval;
iter->second->m_state = CFocusGrabSurfaceState::PendingRemoval;
}
}
@ -96,8 +96,8 @@ void CFocusGrab::refocusKeyboard() {
return;
SP<CWLSurfaceResource> surface = nullptr;
for (auto const& [surf, state] : m_mSurfaces) {
if (state->state == CFocusGrabSurfaceState::Comitted) {
for (auto const& [surf, state] : m_surfaces) {
if (state->m_state == CFocusGrabSurfaceState::Comitted) {
surface = surf.lock();
break;
}
@ -112,17 +112,17 @@ void CFocusGrab::refocusKeyboard() {
void CFocusGrab::commit(bool removeOnly) {
auto surfacesChanged = false;
auto anyComitted = false;
for (auto iter = m_mSurfaces.begin(); iter != m_mSurfaces.end();) {
switch (iter->second->state) {
for (auto iter = m_surfaces.begin(); iter != m_surfaces.end();) {
switch (iter->second->m_state) {
case CFocusGrabSurfaceState::PendingRemoval:
grab->remove(iter->first.lock());
iter = m_mSurfaces.erase(iter);
m_grab->remove(iter->first.lock());
iter = m_surfaces.erase(iter);
surfacesChanged = true;
continue;
case CFocusGrabSurfaceState::PendingAddition:
if (!removeOnly) {
iter->second->state = CFocusGrabSurfaceState::Comitted;
grab->add(iter->first.lock());
iter->second->m_state = CFocusGrabSurfaceState::Comitted;
m_grab->add(iter->first.lock());
surfacesChanged = true;
anyComitted = true;
}
@ -146,7 +146,7 @@ CFocusGrabProtocol::CFocusGrabProtocol(const wl_interface* iface, const int& ver
}
void CFocusGrabProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CHyprlandFocusGrabManagerV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CHyprlandFocusGrabManagerV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CHyprlandFocusGrabManagerV1* p) { onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CHyprlandFocusGrabManagerV1* p) { onManagerResourceDestroy(p->resource()); });
@ -154,19 +154,19 @@ void CFocusGrabProtocol::bindManager(wl_client* client, void* data, uint32_t ver
}
void CFocusGrabProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CFocusGrabProtocol::destroyGrab(CFocusGrab* grab) {
std::erase_if(m_vGrabs, [&](const auto& other) { return other.get() == grab; });
std::erase_if(m_grabs, [&](const auto& other) { return other.get() == grab; });
}
void CFocusGrabProtocol::onCreateGrab(CHyprlandFocusGrabManagerV1* pMgr, uint32_t id) {
m_vGrabs.push_back(makeUnique<CFocusGrab>(makeShared<CHyprlandFocusGrabV1>(pMgr->client(), pMgr->version(), id)));
const auto RESOURCE = m_vGrabs.back().get();
m_grabs.push_back(makeUnique<CFocusGrab>(makeShared<CHyprlandFocusGrabV1>(pMgr->client(), pMgr->version(), id)));
const auto RESOURCE = m_grabs.back().get();
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vGrabs.pop_back();
m_grabs.pop_back();
}
}

View File

@ -21,12 +21,12 @@ class CFocusGrabSurfaceState {
PendingAddition,
PendingRemoval,
Comitted,
} state = PendingAddition;
} m_state = PendingAddition;
private:
struct {
CHyprSignalListener destroy;
} listeners;
} m_listeners;
};
class CFocusGrab {
@ -47,11 +47,11 @@ class CFocusGrab {
void refocusKeyboard();
void commit(bool removeOnly = false);
SP<CHyprlandFocusGrabV1> resource;
std::unordered_map<WP<CWLSurfaceResource>, UP<CFocusGrabSurfaceState>> m_mSurfaces;
SP<CSeatGrab> grab;
SP<CHyprlandFocusGrabV1> m_resource;
std::unordered_map<WP<CWLSurfaceResource>, UP<CFocusGrabSurfaceState>> m_surfaces;
SP<CSeatGrab> m_grab;
bool m_bGrabActive = false;
bool m_grabActive = false;
friend class CFocusGrabSurfaceState;
};
@ -67,8 +67,8 @@ class CFocusGrabProtocol : public IWaylandProtocol {
void destroyGrab(CFocusGrab* grab);
void onCreateGrab(CHyprlandFocusGrabManagerV1* pMgr, uint32_t id);
std::vector<UP<CHyprlandFocusGrabManagerV1>> m_vManagers;
std::vector<UP<CFocusGrab>> m_vGrabs;
std::vector<UP<CHyprlandFocusGrabManagerV1>> m_managers;
std::vector<UP<CFocusGrab>> m_grabs;
friend class CFocusGrab;
};

View File

@ -2,34 +2,34 @@
#include "../Compositor.hpp"
#include "../managers/HookSystemManager.hpp"
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
CForeignToplevelHandle::CForeignToplevelHandle(SP<CExtForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) {
if UNLIKELY (!resource_->resource())
return;
resource->setData(this);
m_resource->setData(this);
resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
resource->setDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
m_resource->setOnDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
m_resource->setDestroy([this](CExtForeignToplevelHandleV1* h) { PROTO::foreignToplevel->destroyHandle(this); });
}
bool CForeignToplevelHandle::good() {
return resource->resource();
return m_resource->resource();
}
PHLWINDOW CForeignToplevelHandle::window() {
return pWindow.lock();
return m_window.lock();
}
CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_) : resource(resource_) {
CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resource_) : m_resource(resource_) {
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
resource->setDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
m_resource->setOnDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
m_resource->setDestroy([this](CExtForeignToplevelListV1* h) { PROTO::foreignToplevel->onManagerResourceDestroy(this); });
resource->setStop([this](CExtForeignToplevelListV1* h) {
resource->sendFinished();
finished = true;
m_resource->setStop([this](CExtForeignToplevelListV1* h) {
m_resource->sendFinished();
m_finished = true;
LOGM(LOG, "CForeignToplevelList: finished");
});
@ -42,75 +42,75 @@ CForeignToplevelList::CForeignToplevelList(SP<CExtForeignToplevelListV1> resourc
}
void CForeignToplevelList::onMap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto NEWHANDLE = PROTO::foreignToplevel->m_vHandles.emplace_back(
makeShared<CForeignToplevelHandle>(makeShared<CExtForeignToplevelHandleV1>(resource->client(), resource->version(), 0), pWindow));
const auto NEWHANDLE = PROTO::foreignToplevel->m_handles.emplace_back(
makeShared<CForeignToplevelHandle>(makeShared<CExtForeignToplevelHandleV1>(m_resource->client(), m_resource->version(), 0), pWindow));
if (!NEWHANDLE->good()) {
LOGM(ERR, "Couldn't create a foreign handle");
resource->noMemory();
PROTO::foreignToplevel->m_vHandles.pop_back();
m_resource->noMemory();
PROTO::foreignToplevel->m_handles.pop_back();
return;
}
const auto IDENTIFIER = std::format("{:08x}->{:016x}", static_cast<uint32_t>((uintptr_t)this & 0xFFFFFFFF), (uintptr_t)pWindow.get());
LOGM(LOG, "Newly mapped window gets an identifier of {}", IDENTIFIER);
resource->sendToplevel(NEWHANDLE->resource.get());
NEWHANDLE->resource->sendIdentifier(IDENTIFIER.c_str());
NEWHANDLE->resource->sendAppId(pWindow->m_initialClass.c_str());
NEWHANDLE->resource->sendTitle(pWindow->m_initialTitle.c_str());
NEWHANDLE->resource->sendDone();
m_resource->sendToplevel(NEWHANDLE->m_resource.get());
NEWHANDLE->m_resource->sendIdentifier(IDENTIFIER.c_str());
NEWHANDLE->m_resource->sendAppId(pWindow->m_initialClass.c_str());
NEWHANDLE->m_resource->sendTitle(pWindow->m_initialTitle.c_str());
NEWHANDLE->m_resource->sendDone();
handles.push_back(NEWHANDLE);
m_handles.push_back(NEWHANDLE);
}
SP<CForeignToplevelHandle> CForeignToplevelList::handleForWindow(PHLWINDOW pWindow) {
std::erase_if(handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(handles.begin(), handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == handles.end() ? SP<CForeignToplevelHandle>{} : IT->lock();
std::erase_if(m_handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(m_handles.begin(), m_handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == m_handles.end() ? SP<CForeignToplevelHandle>{} : IT->lock();
}
void CForeignToplevelList::onTitle(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendTitle(pWindow->m_title.c_str());
H->resource->sendDone();
H->m_resource->sendTitle(pWindow->m_title.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelList::onClass(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendAppId(pWindow->m_class.c_str());
H->resource->sendDone();
H->m_resource->sendAppId(pWindow->m_class.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelList::onUnmap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H)
return;
H->resource->sendClosed();
H->closed = true;
H->m_resource->sendClosed();
H->m_closed = true;
}
bool CForeignToplevelList::good() {
return resource->resource();
return m_resource->resource();
}
CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -120,7 +120,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onMap(window);
}
});
@ -131,7 +131,7 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onUnmap(window);
}
});
@ -142,29 +142,29 @@ CForeignToplevelProtocol::CForeignToplevelProtocol(const wl_interface* iface, co
if (!windowValidForForeign(window))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onTitle(window);
}
});
}
void CForeignToplevelProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CForeignToplevelList>(makeShared<CExtForeignToplevelListV1>(client, ver, id))).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CForeignToplevelList>(makeShared<CExtForeignToplevelListV1>(client, ver, id))).get();
if UNLIKELY (!RESOURCE->good()) {
LOGM(ERR, "Couldn't create a foreign list");
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CForeignToplevelProtocol::onManagerResourceDestroy(CForeignToplevelList* mgr) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == mgr; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == mgr; });
}
void CForeignToplevelProtocol::destroyHandle(CForeignToplevelHandle* handle) {
std::erase_if(m_vHandles, [&](const auto& other) { return other.get() == handle; });
std::erase_if(m_handles, [&](const auto& other) { return other.get() == handle; });
}
bool CForeignToplevelProtocol::windowValidForForeign(PHLWINDOW pWindow) {

View File

@ -14,9 +14,9 @@ class CForeignToplevelHandle {
PHLWINDOW window();
private:
SP<CExtForeignToplevelHandleV1> resource;
PHLWINDOWREF pWindow;
bool closed = false;
SP<CExtForeignToplevelHandleV1> m_resource;
PHLWINDOWREF m_window;
bool m_closed = false;
friend class CForeignToplevelList;
friend class CForeignToplevelProtocol;
@ -34,12 +34,12 @@ class CForeignToplevelList {
bool good();
private:
SP<CExtForeignToplevelListV1> resource;
bool finished = false;
SP<CExtForeignToplevelListV1> m_resource;
bool m_finished = false;
SP<CForeignToplevelHandle> handleForWindow(PHLWINDOW pWindow);
std::vector<WP<CForeignToplevelHandle>> handles;
std::vector<WP<CForeignToplevelHandle>> m_handles;
};
class CForeignToplevelProtocol : public IWaylandProtocol {
@ -55,8 +55,8 @@ class CForeignToplevelProtocol : public IWaylandProtocol {
bool windowValidForForeign(PHLWINDOW pWindow);
//
std::vector<UP<CForeignToplevelList>> m_vManagers;
std::vector<SP<CForeignToplevelHandle>> m_vHandles;
std::vector<UP<CForeignToplevelList>> m_managers;
std::vector<SP<CForeignToplevelHandle>> m_handles;
friend class CForeignToplevelList;
friend class CForeignToplevelHandle;

View File

@ -6,17 +6,17 @@
#include "../managers/HookSystemManager.hpp"
#include "../managers/EventManager.hpp"
CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : resource(resource_), pWindow(pWindow_) {
CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHandleV1> resource_, PHLWINDOW pWindow_) : m_resource(resource_), m_window(pWindow_) {
if UNLIKELY (!resource_->resource())
return;
resource->setData(this);
m_resource->setData(this);
resource->setOnDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); });
resource->setDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); });
m_resource->setOnDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); });
m_resource->setDestroy([this](CZwlrForeignToplevelHandleV1* h) { PROTO::foreignToplevelWlr->destroyHandle(this); });
resource->setActivate([this](CZwlrForeignToplevelHandleV1* p, wl_resource* seat) {
const auto PWINDOW = pWindow.lock();
m_resource->setActivate([this](CZwlrForeignToplevelHandleV1* p, wl_resource* seat) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -26,8 +26,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
PWINDOW->activate(true);
});
resource->setSetFullscreen([this](CZwlrForeignToplevelHandleV1* p, wl_resource* output) {
const auto PWINDOW = pWindow.lock();
m_resource->setSetFullscreen([this](CZwlrForeignToplevelHandleV1* p, wl_resource* output) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -57,8 +57,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pHyprRenderer->damageWindow(PWINDOW);
});
resource->setUnsetFullscreen([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setUnsetFullscreen([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -69,8 +69,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_FULLSCREEN, false);
});
resource->setSetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setSetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -86,8 +86,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_MAXIMIZED, true);
});
resource->setUnsetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setUnsetMaximized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -98,8 +98,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pCompositor->changeWindowFullscreenModeClient(PWINDOW, FSMODE_MAXIMIZED, false);
});
resource->setSetMinimized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setSetMinimized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -110,8 +110,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pEventManager->postEvent(SHyprIPCEvent{.event = "minimized", .data = std::format("{:x},1", (uintptr_t)PWINDOW.get())});
});
resource->setUnsetMinimized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setUnsetMinimized([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -122,8 +122,8 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
g_pEventManager->postEvent(SHyprIPCEvent{.event = "minimized", .data = std::format("{:x},0", (uintptr_t)PWINDOW.get())});
});
resource->setClose([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = pWindow.lock();
m_resource->setClose([this](CZwlrForeignToplevelHandleV1* p) {
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW)
return;
@ -133,42 +133,42 @@ CForeignToplevelHandleWlr::CForeignToplevelHandleWlr(SP<CZwlrForeignToplevelHand
}
bool CForeignToplevelHandleWlr::good() {
return resource->resource();
return m_resource->resource();
}
PHLWINDOW CForeignToplevelHandleWlr::window() {
return pWindow.lock();
return m_window.lock();
}
wl_resource* CForeignToplevelHandleWlr::res() {
return resource->resource();
return m_resource->resource();
}
void CForeignToplevelHandleWlr::sendMonitor(PHLMONITOR pMonitor) {
if (lastMonitorID == pMonitor->m_id)
if (m_lastMonitorID == pMonitor->m_id)
return;
const auto CLIENT = resource->client();
const auto CLIENT = m_resource->client();
if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->m_name)) {
if (const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(m_lastMonitorID); PLASTMONITOR && PROTO::outputs.contains(PLASTMONITOR->m_name)) {
const auto OLDRESOURCE = PROTO::outputs.at(PLASTMONITOR->m_name)->outputResourceFrom(CLIENT);
if LIKELY (OLDRESOURCE)
resource->sendOutputLeave(OLDRESOURCE->getResource()->resource());
m_resource->sendOutputLeave(OLDRESOURCE->getResource()->resource());
}
if (PROTO::outputs.contains(pMonitor->m_name)) {
const auto NEWRESOURCE = PROTO::outputs.at(pMonitor->m_name)->outputResourceFrom(CLIENT);
if LIKELY (NEWRESOURCE)
resource->sendOutputEnter(NEWRESOURCE->getResource()->resource());
m_resource->sendOutputEnter(NEWRESOURCE->getResource()->resource());
}
lastMonitorID = pMonitor->m_id;
m_lastMonitorID = pMonitor->m_id;
}
void CForeignToplevelHandleWlr::sendState() {
const auto PWINDOW = pWindow.lock();
const auto PWINDOW = m_window.lock();
if UNLIKELY (!PWINDOW || !PWINDOW->m_workspace || !PWINDOW->m_isMapped)
return;
@ -189,20 +189,20 @@ void CForeignToplevelHandleWlr::sendState() {
*p = ZWLR_FOREIGN_TOPLEVEL_HANDLE_V1_STATE_MAXIMIZED;
}
resource->sendState(&state);
m_resource->sendState(&state);
wl_array_release(&state);
}
CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP<CZwlrForeignToplevelManagerV1> resource_) : resource(resource_) {
CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP<CZwlrForeignToplevelManagerV1> resource_) : m_resource(resource_) {
if UNLIKELY (!resource_->resource())
return;
resource->setOnDestroy([this](CZwlrForeignToplevelManagerV1* h) { PROTO::foreignToplevelWlr->onManagerResourceDestroy(this); });
m_resource->setOnDestroy([this](CZwlrForeignToplevelManagerV1* h) { PROTO::foreignToplevelWlr->onManagerResourceDestroy(this); });
resource->setStop([this](CZwlrForeignToplevelManagerV1* h) {
resource->sendFinished();
finished = true;
m_resource->setStop([this](CZwlrForeignToplevelManagerV1* h) {
m_resource->sendFinished();
m_finished = true;
LOGM(LOG, "CForeignToplevelWlrManager: finished");
PROTO::foreignToplevelWlr->onManagerResourceDestroy(this);
});
@ -214,84 +214,84 @@ CForeignToplevelWlrManager::CForeignToplevelWlrManager(SP<CZwlrForeignToplevelMa
onMap(w);
}
lastFocus = g_pCompositor->m_lastWindow;
m_lastFocus = g_pCompositor->m_lastWindow;
}
void CForeignToplevelWlrManager::onMap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto NEWHANDLE = PROTO::foreignToplevelWlr->m_vHandles.emplace_back(
makeShared<CForeignToplevelHandleWlr>(makeShared<CZwlrForeignToplevelHandleV1>(resource->client(), resource->version(), 0), pWindow));
const auto NEWHANDLE = PROTO::foreignToplevelWlr->m_handles.emplace_back(
makeShared<CForeignToplevelHandleWlr>(makeShared<CZwlrForeignToplevelHandleV1>(m_resource->client(), m_resource->version(), 0), pWindow));
if UNLIKELY (!NEWHANDLE->good()) {
LOGM(ERR, "Couldn't create a foreign handle");
resource->noMemory();
PROTO::foreignToplevelWlr->m_vHandles.pop_back();
m_resource->noMemory();
PROTO::foreignToplevelWlr->m_handles.pop_back();
return;
}
LOGM(LOG, "Newly mapped window {:016x}", (uintptr_t)pWindow.get());
resource->sendToplevel(NEWHANDLE->resource.get());
NEWHANDLE->resource->sendAppId(pWindow->m_class.c_str());
NEWHANDLE->resource->sendTitle(pWindow->m_title.c_str());
m_resource->sendToplevel(NEWHANDLE->m_resource.get());
NEWHANDLE->m_resource->sendAppId(pWindow->m_class.c_str());
NEWHANDLE->m_resource->sendTitle(pWindow->m_title.c_str());
if LIKELY (const auto PMONITOR = pWindow->m_monitor.lock(); PMONITOR)
NEWHANDLE->sendMonitor(PMONITOR);
NEWHANDLE->sendState();
NEWHANDLE->resource->sendDone();
NEWHANDLE->m_resource->sendDone();
handles.push_back(NEWHANDLE);
m_handles.push_back(NEWHANDLE);
}
SP<CForeignToplevelHandleWlr> CForeignToplevelWlrManager::handleForWindow(PHLWINDOW pWindow) {
std::erase_if(handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(handles.begin(), handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == handles.end() ? SP<CForeignToplevelHandleWlr>{} : IT->lock();
std::erase_if(m_handles, [](const auto& wp) { return wp.expired(); });
const auto IT = std::find_if(m_handles.begin(), m_handles.end(), [pWindow](const auto& h) { return h->window() == pWindow; });
return IT == m_handles.end() ? SP<CForeignToplevelHandleWlr>{} : IT->lock();
}
void CForeignToplevelWlrManager::onTitle(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendTitle(pWindow->m_title.c_str());
H->resource->sendDone();
H->m_resource->sendTitle(pWindow->m_title.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelWlrManager::onClass(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->resource->sendAppId(pWindow->m_class.c_str());
H->resource->sendDone();
H->m_resource->sendAppId(pWindow->m_class.c_str());
H->m_resource->sendDone();
}
void CForeignToplevelWlrManager::onUnmap(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H)
return;
H->resource->sendClosed();
H->resource->sendDone();
H->closed = true;
H->m_resource->sendClosed();
H->m_resource->sendDone();
H->m_closed = true;
}
void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
const auto PMONITOR = pWindow->m_monitor.lock();
@ -300,42 +300,42 @@ void CForeignToplevelWlrManager::onMoveMonitor(PHLWINDOW pWindow) {
return;
H->sendMonitor(PMONITOR);
H->resource->sendDone();
H->m_resource->sendDone();
}
void CForeignToplevelWlrManager::onFullscreen(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->sendState();
H->resource->sendDone();
H->m_resource->sendDone();
}
void CForeignToplevelWlrManager::onNewFocus(PHLWINDOW pWindow) {
if UNLIKELY (finished)
if UNLIKELY (m_finished)
return;
if LIKELY (const auto HOLD = handleForWindow(lastFocus.lock()); HOLD) {
if LIKELY (const auto HOLD = handleForWindow(m_lastFocus.lock()); HOLD) {
HOLD->sendState();
HOLD->resource->sendDone();
HOLD->m_resource->sendDone();
}
lastFocus = pWindow;
m_lastFocus = pWindow;
const auto H = handleForWindow(pWindow);
if UNLIKELY (!H || H->closed)
if UNLIKELY (!H || H->m_closed)
return;
H->sendState();
H->resource->sendDone();
H->m_resource->sendDone();
}
bool CForeignToplevelWlrManager::good() {
return resource->resource();
return m_resource->resource();
}
CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -345,7 +345,7 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
if (!windowValidForForeign(PWINDOW))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onMap(PWINDOW);
}
});
@ -356,7 +356,7 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
if (!windowValidForForeign(PWINDOW))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onUnmap(PWINDOW);
}
});
@ -367,7 +367,7 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
if (!windowValidForForeign(PWINDOW))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onTitle(PWINDOW);
}
});
@ -378,14 +378,14 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
if (PWINDOW && !windowValidForForeign(PWINDOW))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onNewFocus(PWINDOW);
}
});
static auto P4 = g_pHookSystem->hookDynamic("moveWindow", [this](void* self, SCallbackInfo& info, std::any data) {
const auto PWINDOW = std::any_cast<PHLWINDOW>(std::any_cast<std::vector<std::any>>(data).at(0));
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onMoveMonitor(PWINDOW);
}
});
@ -396,29 +396,29 @@ CForeignToplevelWlrProtocol::CForeignToplevelWlrProtocol(const wl_interface* ifa
if (!windowValidForForeign(PWINDOW))
return;
for (auto const& m : m_vManagers) {
for (auto const& m : m_managers) {
m->onFullscreen(PWINDOW);
}
});
}
void CForeignToplevelWlrProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CForeignToplevelWlrManager>(makeShared<CZwlrForeignToplevelManagerV1>(client, ver, id))).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CForeignToplevelWlrManager>(makeShared<CZwlrForeignToplevelManagerV1>(client, ver, id))).get();
if UNLIKELY (!RESOURCE->good()) {
LOGM(ERR, "Couldn't create a foreign list");
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CForeignToplevelWlrProtocol::onManagerResourceDestroy(CForeignToplevelWlrManager* mgr) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == mgr; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == mgr; });
}
void CForeignToplevelWlrProtocol::destroyHandle(CForeignToplevelHandleWlr* handle) {
std::erase_if(m_vHandles, [&](const auto& other) { return other.get() == handle; });
std::erase_if(m_handles, [&](const auto& other) { return other.get() == handle; });
}
PHLWINDOW CForeignToplevelWlrProtocol::windowFromHandleResource(wl_resource* res) {

View File

@ -16,10 +16,10 @@ class CForeignToplevelHandleWlr {
wl_resource* res();
private:
SP<CZwlrForeignToplevelHandleV1> resource;
PHLWINDOWREF pWindow;
bool closed = false;
MONITORID lastMonitorID = MONITOR_INVALID;
SP<CZwlrForeignToplevelHandleV1> m_resource;
PHLWINDOWREF m_window;
bool m_closed = false;
MONITORID m_lastMonitorID = MONITOR_INVALID;
void sendMonitor(PHLMONITOR pMonitor);
void sendState();
@ -42,13 +42,13 @@ class CForeignToplevelWlrManager {
bool good();
private:
SP<CZwlrForeignToplevelManagerV1> resource;
bool finished = false;
PHLWINDOWREF lastFocus; // READ-ONLY
SP<CZwlrForeignToplevelManagerV1> m_resource;
bool m_finished = false;
PHLWINDOWREF m_lastFocus; // READ-ONLY
SP<CForeignToplevelHandleWlr> handleForWindow(PHLWINDOW pWindow);
std::vector<WP<CForeignToplevelHandleWlr>> handles;
std::vector<WP<CForeignToplevelHandleWlr>> m_handles;
};
class CForeignToplevelWlrProtocol : public IWaylandProtocol {
@ -65,8 +65,8 @@ class CForeignToplevelWlrProtocol : public IWaylandProtocol {
bool windowValidForForeign(PHLWINDOW pWindow);
//
std::vector<UP<CForeignToplevelWlrManager>> m_vManagers;
std::vector<SP<CForeignToplevelHandleWlr>> m_vHandles;
std::vector<UP<CForeignToplevelWlrManager>> m_managers;
std::vector<SP<CForeignToplevelHandleWlr>> m_handles;
friend class CForeignToplevelWlrManager;
friend class CForeignToplevelHandleWlr;

View File

@ -7,7 +7,7 @@ CFractionalScaleProtocol::CFractionalScaleProtocol(const wl_interface* iface, co
}
void CFractionalScaleProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CWpFractionalScaleManagerV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CWpFractionalScaleManagerV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CWpFractionalScaleManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CWpFractionalScaleManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -16,15 +16,15 @@ void CFractionalScaleProtocol::bindManager(wl_client* client, void* data, uint32
}
void CFractionalScaleProtocol::removeAddon(CFractionalScaleAddon* addon) {
m_mAddons.erase(addon->surf());
m_addons.erase(addon->surf());
}
void CFractionalScaleProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [res](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [res](const auto& other) { return other->resource() == res; });
}
void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface) {
for (auto const& [k, v] : m_mAddons) {
for (auto const& [k, v] : m_addons) {
if (k == surface) {
LOGM(ERR, "Surface {:x} already has a fractionalScale addon", (uintptr_t)surface.get());
pMgr->error(WP_FRACTIONAL_SCALE_MANAGER_V1_ERROR_FRACTIONAL_SCALE_EXISTS, "Fractional scale already exists");
@ -33,10 +33,10 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1*
}
const auto PADDON =
m_mAddons.emplace(surface, makeUnique<CFractionalScaleAddon>(makeShared<CWpFractionalScaleV1>(pMgr->client(), pMgr->version(), id), surface)).first->second.get();
m_addons.emplace(surface, makeUnique<CFractionalScaleAddon>(makeShared<CWpFractionalScaleV1>(pMgr->client(), pMgr->version(), id), surface)).first->second.get();
if UNLIKELY (!PADDON->good()) {
m_mAddons.erase(surface);
m_addons.erase(surface);
pMgr->noMemory();
return;
}
@ -44,20 +44,20 @@ void CFractionalScaleProtocol::onGetFractionalScale(CWpFractionalScaleManagerV1*
PADDON->m_resource->setOnDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
PADDON->m_resource->setDestroy([this, PADDON](CWpFractionalScaleV1* self) { this->removeAddon(PADDON); });
if (std::ranges::find_if(m_mSurfaceScales, [surface](const auto& e) { return e.first == surface; }) == m_mSurfaceScales.end())
m_mSurfaceScales.emplace(surface, 1.F);
if (std::ranges::find_if(m_surfaceScales, [surface](const auto& e) { return e.first == surface; }) == m_surfaceScales.end())
m_surfaceScales.emplace(surface, 1.F);
if (surface->m_mapped)
PADDON->setScale(m_mSurfaceScales.at(surface));
PADDON->setScale(m_surfaceScales.at(surface));
// clean old
std::erase_if(m_mSurfaceScales, [](const auto& e) { return e.first.expired(); });
std::erase_if(m_surfaceScales, [](const auto& e) { return e.first.expired(); });
}
void CFractionalScaleProtocol::sendScale(SP<CWLSurfaceResource> surf, const float& scale) {
m_mSurfaceScales[surf] = scale;
if (m_mAddons.contains(surf))
m_mAddons[surf]->setScale(scale);
m_surfaceScales[surf] = scale;
if (m_addons.contains(surf))
m_addons[surf]->setScale(scale);
}
CFractionalScaleAddon::CFractionalScaleAddon(SP<CWpFractionalScaleV1> resource_, SP<CWLSurfaceResource> surf_) : m_resource(resource_), m_surface(surf_) {

View File

@ -49,9 +49,9 @@ class CFractionalScaleProtocol : public IWaylandProtocol {
//
std::unordered_map<WP<CWLSurfaceResource>, float> m_mSurfaceScales;
std::unordered_map<WP<CWLSurfaceResource>, UP<CFractionalScaleAddon>> m_mAddons;
std::vector<UP<CWpFractionalScaleManagerV1>> m_vManagers;
std::unordered_map<WP<CWLSurfaceResource>, float> m_surfaceScales;
std::unordered_map<WP<CWLSurfaceResource>, UP<CFractionalScaleAddon>> m_addons;
std::vector<UP<CWpFractionalScaleManagerV1>> m_managers;
friend class CFractionalScaleAddon;
};

View File

@ -22,14 +22,14 @@ static wpColorManagerV1Primaries getWPPrimaries(frogColorManagedSurfacePrimaries
return (wpColorManagerV1Primaries)(primaries + 1);
}
CFrogColorManager::CFrogColorManager(SP<CFrogColorManagementFactoryV1> resource_) : resource(resource_) {
CFrogColorManager::CFrogColorManager(SP<CFrogColorManagementFactoryV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setDestroy([](CFrogColorManagementFactoryV1* r) { LOGM(TRACE, "Destroy frog_color_management at {:x} (generated default)", (uintptr_t)r); });
resource->setOnDestroy([this](CFrogColorManagementFactoryV1* r) { PROTO::frogColorManagement->destroyResource(this); });
m_resource->setDestroy([](CFrogColorManagementFactoryV1* r) { LOGM(TRACE, "Destroy frog_color_management at {:x} (generated default)", (uintptr_t)r); });
m_resource->setOnDestroy([this](CFrogColorManagementFactoryV1* r) { PROTO::frogColorManagement->destroyResource(this); });
resource->setGetColorManagedSurface([](CFrogColorManagementFactoryV1* r, wl_resource* surface, uint32_t id) {
m_resource->setGetColorManagedSurface([](CFrogColorManagementFactoryV1* r, wl_resource* surface, uint32_t id) {
LOGM(TRACE, "Get surface for id={}, surface={}", id, (uintptr_t)surface);
auto SURF = CWLSurfaceResource::fromResource(surface);
@ -39,70 +39,70 @@ CFrogColorManager::CFrogColorManager(SP<CFrogColorManagementFactoryV1> resource_
return;
}
const auto RESOURCE = PROTO::frogColorManagement->m_vSurfaces.emplace_back(
makeShared<CFrogColorManagementSurface>(makeShared<CFrogColorManagedSurface>(r->client(), r->version(), id), SURF));
const auto RESOURCE =
PROTO::frogColorManagement->m_surfaces.emplace_back(makeShared<CFrogColorManagementSurface>(makeShared<CFrogColorManagedSurface>(r->client(), r->version(), id), SURF));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::frogColorManagement->m_vSurfaces.pop_back();
PROTO::frogColorManagement->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
});
}
bool CFrogColorManager::good() {
return resource->resource();
return m_resource->resource();
}
CFrogColorManagementSurface::CFrogColorManagementSurface(SP<CFrogColorManagedSurface> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
CFrogColorManagementSurface::CFrogColorManagementSurface(SP<CFrogColorManagedSurface> resource_, SP<CWLSurfaceResource> surface_) : m_surface(surface_), m_resource(resource_) {
if UNLIKELY (!good())
return;
pClient = resource->client();
m_client = m_resource->client();
if (!surface->m_colorManagement.valid()) {
const auto RESOURCE = PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared<CColorManagementSurface>(surface_));
if (!m_surface->m_colorManagement.valid()) {
const auto RESOURCE = PROTO::colorManagement->m_surfaces.emplace_back(makeShared<CColorManagementSurface>(surface_));
if UNLIKELY (!RESOURCE) {
resource->noMemory();
PROTO::colorManagement->m_vSurfaces.pop_back();
m_resource->noMemory();
PROTO::colorManagement->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
surface->m_colorManagement = RESOURCE;
m_surface->m_colorManagement = RESOURCE;
resource->setOnDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm and xx cm for surface {}", (uintptr_t)surface);
if (surface.valid())
PROTO::colorManagement->destroyResource(surface->m_colorManagement.get());
m_resource->setOnDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm and xx cm for surface {}", (uintptr_t)m_surface);
if (m_surface.valid())
PROTO::colorManagement->destroyResource(m_surface->m_colorManagement.get());
PROTO::frogColorManagement->destroyResource(this);
});
} else
resource->setOnDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm surface {}", (uintptr_t)surface);
m_resource->setOnDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm surface {}", (uintptr_t)m_surface);
PROTO::frogColorManagement->destroyResource(this);
});
resource->setDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm surface {}", (uintptr_t)surface);
m_resource->setDestroy([this](CFrogColorManagedSurface* r) {
LOGM(TRACE, "Destroy frog cm surface {}", (uintptr_t)m_surface);
PROTO::frogColorManagement->destroyResource(this);
});
resource->setSetKnownTransferFunction([this](CFrogColorManagedSurface* r, frogColorManagedSurfaceTransferFunction tf) {
LOGM(TRACE, "Set frog cm transfer function {} for {}", (uint32_t)tf, surface->id());
m_resource->setSetKnownTransferFunction([this](CFrogColorManagedSurface* r, frogColorManagedSurfaceTransferFunction tf) {
LOGM(TRACE, "Set frog cm transfer function {} for {}", (uint32_t)tf, m_surface->id());
switch (tf) {
case FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_ST2084_PQ:
surface->m_colorManagement->m_imageDescription.transferFunction =
m_surface->m_colorManagement->m_imageDescription.transferFunction =
convertTransferFunction(getWPTransferFunction(FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_ST2084_PQ));
break;
;
case FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_GAMMA_22:
if (pqIntentSent) {
if (m_pqIntentSent) {
LOGM(TRACE,
"FIXME: assuming broken enum value 2 (FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_GAMMA_22) referring to eotf value 2 (TRANSFER_FUNCTION_ST2084_PQ)");
surface->m_colorManagement->m_imageDescription.transferFunction =
m_surface->m_colorManagement->m_imageDescription.transferFunction =
convertTransferFunction(getWPTransferFunction(FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_ST2084_PQ));
break;
};
@ -110,49 +110,49 @@ CFrogColorManagementSurface::CFrogColorManagementSurface(SP<CFrogColorManagedSur
case FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_UNDEFINED:
case FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_SCRGB_LINEAR: LOGM(TRACE, "FIXME: add tf support for {}", (uint32_t)tf); [[fallthrough]];
case FROG_COLOR_MANAGED_SURFACE_TRANSFER_FUNCTION_SRGB:
surface->m_colorManagement->m_imageDescription.transferFunction = convertTransferFunction(getWPTransferFunction(tf));
m_surface->m_colorManagement->m_imageDescription.transferFunction = convertTransferFunction(getWPTransferFunction(tf));
surface->m_colorManagement->setHasImageDescription(true);
m_surface->m_colorManagement->setHasImageDescription(true);
}
});
resource->setSetKnownContainerColorVolume([this](CFrogColorManagedSurface* r, frogColorManagedSurfacePrimaries primariesName) {
m_resource->setSetKnownContainerColorVolume([this](CFrogColorManagedSurface* r, frogColorManagedSurfacePrimaries primariesName) {
LOGM(TRACE, "Set frog cm primaries {}", (uint32_t)primariesName);
switch (primariesName) {
case FROG_COLOR_MANAGED_SURFACE_PRIMARIES_UNDEFINED:
case FROG_COLOR_MANAGED_SURFACE_PRIMARIES_REC709: surface->m_colorManagement->m_imageDescription.primaries = NColorPrimaries::BT709; break;
case FROG_COLOR_MANAGED_SURFACE_PRIMARIES_REC2020: surface->m_colorManagement->m_imageDescription.primaries = NColorPrimaries::BT2020; break;
case FROG_COLOR_MANAGED_SURFACE_PRIMARIES_REC709: m_surface->m_colorManagement->m_imageDescription.primaries = NColorPrimaries::BT709; break;
case FROG_COLOR_MANAGED_SURFACE_PRIMARIES_REC2020: m_surface->m_colorManagement->m_imageDescription.primaries = NColorPrimaries::BT2020; break;
}
surface->m_colorManagement->m_imageDescription.primariesNamed = convertPrimaries(getWPPrimaries(primariesName));
m_surface->m_colorManagement->m_imageDescription.primariesNamed = convertPrimaries(getWPPrimaries(primariesName));
surface->m_colorManagement->setHasImageDescription(true);
m_surface->m_colorManagement->setHasImageDescription(true);
});
resource->setSetRenderIntent([this](CFrogColorManagedSurface* r, frogColorManagedSurfaceRenderIntent intent) {
m_resource->setSetRenderIntent([this](CFrogColorManagedSurface* r, frogColorManagedSurfaceRenderIntent intent) {
LOGM(TRACE, "Set frog cm intent {}", (uint32_t)intent);
pqIntentSent = intent == FROG_COLOR_MANAGED_SURFACE_RENDER_INTENT_PERCEPTUAL;
surface->m_colorManagement->setHasImageDescription(true);
m_pqIntentSent = intent == FROG_COLOR_MANAGED_SURFACE_RENDER_INTENT_PERCEPTUAL;
m_surface->m_colorManagement->setHasImageDescription(true);
});
resource->setSetHdrMetadata([this](CFrogColorManagedSurface* r, uint32_t r_x, uint32_t r_y, uint32_t g_x, uint32_t g_y, uint32_t b_x, uint32_t b_y, uint32_t w_x, uint32_t w_y,
uint32_t max_lum, uint32_t min_lum, uint32_t cll, uint32_t fall) {
m_resource->setSetHdrMetadata([this](CFrogColorManagedSurface* r, uint32_t r_x, uint32_t r_y, uint32_t g_x, uint32_t g_y, uint32_t b_x, uint32_t b_y, uint32_t w_x,
uint32_t w_y, uint32_t max_lum, uint32_t min_lum, uint32_t cll, uint32_t fall) {
LOGM(TRACE, "Set frog primaries r:{},{} g:{},{} b:{},{} w:{},{} luminances {} - {} cll {} fall {}", r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y, min_lum, max_lum, cll, fall);
surface->m_colorManagement->m_imageDescription.masteringPrimaries = SPCPRimaries{.red = {.x = r_x / 50000.0f, .y = r_y / 50000.0f},
.green = {.x = g_x / 50000.0f, .y = g_y / 50000.0f},
.blue = {.x = b_x / 50000.0f, .y = b_y / 50000.0f},
.white = {.x = w_x / 50000.0f, .y = w_y / 50000.0f}};
surface->m_colorManagement->m_imageDescription.masteringLuminances.min = min_lum / 10000.0f;
surface->m_colorManagement->m_imageDescription.masteringLuminances.max = max_lum;
surface->m_colorManagement->m_imageDescription.maxCLL = cll;
surface->m_colorManagement->m_imageDescription.maxFALL = fall;
m_surface->m_colorManagement->m_imageDescription.masteringPrimaries = SPCPRimaries{.red = {.x = r_x / 50000.0f, .y = r_y / 50000.0f},
.green = {.x = g_x / 50000.0f, .y = g_y / 50000.0f},
.blue = {.x = b_x / 50000.0f, .y = b_y / 50000.0f},
.white = {.x = w_x / 50000.0f, .y = w_y / 50000.0f}};
m_surface->m_colorManagement->m_imageDescription.masteringLuminances.min = min_lum / 10000.0f;
m_surface->m_colorManagement->m_imageDescription.masteringLuminances.max = max_lum;
m_surface->m_colorManagement->m_imageDescription.maxCLL = cll;
m_surface->m_colorManagement->m_imageDescription.maxFALL = fall;
surface->m_colorManagement->setHasImageDescription(true);
m_surface->m_colorManagement->setHasImageDescription(true);
});
}
bool CFrogColorManagementSurface::good() {
return resource->resource();
return m_resource->resource();
}
wl_client* CFrogColorManagementSurface::client() {
return pClient;
return m_client;
}
CFrogColorManagementProtocol::CFrogColorManagementProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -160,11 +160,11 @@ CFrogColorManagementProtocol::CFrogColorManagementProtocol(const wl_interface* i
}
void CFrogColorManagementProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CFrogColorManager>(makeShared<CFrogColorManagementFactoryV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CFrogColorManager>(makeShared<CFrogColorManagementFactoryV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
@ -172,9 +172,9 @@ void CFrogColorManagementProtocol::bindManager(wl_client* client, void* data, ui
}
void CFrogColorManagementProtocol::destroyResource(CFrogColorManager* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CFrogColorManagementProtocol::destroyResource(CFrogColorManagementSurface* resource) {
std::erase_if(m_vSurfaces, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_surfaces, [&](const auto& other) { return other.get() == resource; });
}

View File

@ -12,7 +12,7 @@ class CFrogColorManager {
bool good();
private:
SP<CFrogColorManagementFactoryV1> resource;
SP<CFrogColorManagementFactoryV1> m_resource;
};
class CFrogColorManagementSurface {
@ -22,14 +22,14 @@ class CFrogColorManagementSurface {
bool good();
wl_client* client();
WP<CFrogColorManagementSurface> self;
WP<CWLSurfaceResource> surface;
WP<CFrogColorManagementSurface> m_self;
WP<CWLSurfaceResource> m_surface;
bool pqIntentSent = false;
bool m_pqIntentSent = false;
private:
SP<CFrogColorManagedSurface> resource;
wl_client* pClient = nullptr;
SP<CFrogColorManagedSurface> m_resource;
wl_client* m_client = nullptr;
};
class CFrogColorManagementProtocol : public IWaylandProtocol {
@ -42,8 +42,8 @@ class CFrogColorManagementProtocol : public IWaylandProtocol {
void destroyResource(CFrogColorManager* resource);
void destroyResource(CFrogColorManagementSurface* resource);
std::vector<SP<CFrogColorManager>> m_vManagers;
std::vector<SP<CFrogColorManagementSurface>> m_vSurfaces;
std::vector<SP<CFrogColorManager>> m_managers;
std::vector<SP<CFrogColorManagementSurface>> m_surfaces;
friend class CFrogColorManager;
friend class CFrogColorManagementSurface;

View File

@ -6,7 +6,7 @@
#include "../render/Renderer.hpp"
using namespace Hyprutils::OS;
CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output) : resource(resource_) {
CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* output) : m_resource(resource_) {
if UNLIKELY (!resource_->resource())
return;
@ -14,144 +14,144 @@ CGammaControl::CGammaControl(SP<CZwlrGammaControlV1> resource_, wl_resource* out
if UNLIKELY (!OUTPUTRES) {
LOGM(ERR, "No output in CGammaControl");
resource->sendFailed();
m_resource->sendFailed();
return;
}
pMonitor = OUTPUTRES->m_monitor;
m_monitor = OUTPUTRES->m_monitor;
if UNLIKELY (!pMonitor || !pMonitor->m_output) {
if UNLIKELY (!m_monitor || !m_monitor->m_output) {
LOGM(ERR, "No CMonitor");
resource->sendFailed();
m_resource->sendFailed();
return;
}
for (auto const& g : PROTO::gamma->m_vGammaControllers) {
if UNLIKELY (g->pMonitor == pMonitor) {
resource->sendFailed();
for (auto const& g : PROTO::gamma->m_gammaControllers) {
if UNLIKELY (g->m_monitor == m_monitor) {
m_resource->sendFailed();
return;
}
}
gammaSize = pMonitor->m_output->getGammaSize();
m_gammaSize = m_monitor->m_output->getGammaSize();
if UNLIKELY (gammaSize <= 0) {
LOGM(ERR, "Output {} doesn't support gamma", pMonitor->m_name);
resource->sendFailed();
if UNLIKELY (m_gammaSize <= 0) {
LOGM(ERR, "Output {} doesn't support gamma", m_monitor->m_name);
m_resource->sendFailed();
return;
}
gammaTable.resize(gammaSize * 3);
m_gammaTable.resize(m_gammaSize * 3);
resource->setDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); });
resource->setOnDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); });
m_resource->setDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); });
m_resource->setOnDestroy([this](CZwlrGammaControlV1* gamma) { PROTO::gamma->destroyGammaControl(this); });
resource->setSetGamma([this](CZwlrGammaControlV1* gamma, int32_t fd) {
m_resource->setSetGamma([this](CZwlrGammaControlV1* gamma, int32_t fd) {
CFileDescriptor gammaFd{fd};
if UNLIKELY (!pMonitor) {
if UNLIKELY (!m_monitor) {
LOGM(ERR, "setGamma for a dead monitor");
resource->sendFailed();
m_resource->sendFailed();
return;
}
LOGM(LOG, "setGamma for {}", pMonitor->m_name);
LOGM(LOG, "setGamma for {}", m_monitor->m_name);
// TODO: make CFileDescriptor getflags use F_GETFL
int fdFlags = fcntl(gammaFd.get(), F_GETFL, 0);
if UNLIKELY (fdFlags < 0) {
LOGM(ERR, "Failed to get fd flags");
resource->sendFailed();
m_resource->sendFailed();
return;
}
// TODO: make CFileDescriptor setflags use F_SETFL
if UNLIKELY (fcntl(gammaFd.get(), F_SETFL, fdFlags | O_NONBLOCK) < 0) {
LOGM(ERR, "Failed to set fd flags");
resource->sendFailed();
m_resource->sendFailed();
return;
}
ssize_t readBytes = pread(gammaFd.get(), gammaTable.data(), gammaTable.size() * sizeof(uint16_t), 0);
if (readBytes < 0 || (size_t)readBytes != gammaTable.size() * sizeof(uint16_t)) {
ssize_t readBytes = pread(gammaFd.get(), m_gammaTable.data(), m_gammaTable.size() * sizeof(uint16_t), 0);
if (readBytes < 0 || (size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t)) {
LOGM(ERR, "Failed to read bytes");
if ((size_t)readBytes != gammaTable.size() * sizeof(uint16_t)) {
if ((size_t)readBytes != m_gammaTable.size() * sizeof(uint16_t)) {
gamma->error(ZWLR_GAMMA_CONTROL_V1_ERROR_INVALID_GAMMA, "Gamma ramps size mismatch");
return;
}
resource->sendFailed();
m_resource->sendFailed();
return;
}
gammaTableSet = true;
m_gammaTableSet = true;
// translate the table to AQ format
std::vector<uint16_t> red, green, blue;
red.resize(gammaTable.size() / 3);
green.resize(gammaTable.size() / 3);
blue.resize(gammaTable.size() / 3);
for (size_t i = 0; i < gammaTable.size() / 3; ++i) {
red.at(i) = gammaTable.at(i);
green.at(i) = gammaTable.at(gammaTable.size() / 3 + i);
blue.at(i) = gammaTable.at((gammaTable.size() / 3) * 2 + i);
red.resize(m_gammaTable.size() / 3);
green.resize(m_gammaTable.size() / 3);
blue.resize(m_gammaTable.size() / 3);
for (size_t i = 0; i < m_gammaTable.size() / 3; ++i) {
red.at(i) = m_gammaTable.at(i);
green.at(i) = m_gammaTable.at(m_gammaTable.size() / 3 + i);
blue.at(i) = m_gammaTable.at((m_gammaTable.size() / 3) * 2 + i);
}
for (size_t i = 0; i < gammaTable.size() / 3; ++i) {
gammaTable.at(i * 3) = red.at(i);
gammaTable.at(i * 3 + 1) = green.at(i);
gammaTable.at(i * 3 + 2) = blue.at(i);
for (size_t i = 0; i < m_gammaTable.size() / 3; ++i) {
m_gammaTable.at(i * 3) = red.at(i);
m_gammaTable.at(i * 3 + 1) = green.at(i);
m_gammaTable.at(i * 3 + 2) = blue.at(i);
}
applyToMonitor();
});
resource->sendGammaSize(gammaSize);
m_resource->sendGammaSize(m_gammaSize);
listeners.monitorDestroy = pMonitor->m_events.destroy.registerListener([this](std::any) { this->onMonitorDestroy(); });
listeners.monitorDisconnect = pMonitor->m_events.disconnect.registerListener([this](std::any) { this->onMonitorDestroy(); });
m_listeners.monitorDestroy = m_monitor->m_events.destroy.registerListener([this](std::any) { this->onMonitorDestroy(); });
m_listeners.monitorDisconnect = m_monitor->m_events.disconnect.registerListener([this](std::any) { this->onMonitorDestroy(); });
}
CGammaControl::~CGammaControl() {
if (!gammaTableSet || !pMonitor || !pMonitor->m_output)
if (!m_gammaTableSet || !m_monitor || !m_monitor->m_output)
return;
// reset the LUT if the client dies for whatever reason and doesn't unset the gamma
pMonitor->m_output->state->setGammaLut({});
m_monitor->m_output->state->setGammaLut({});
}
bool CGammaControl::good() {
return resource->resource();
return m_resource->resource();
}
void CGammaControl::applyToMonitor() {
if UNLIKELY (!pMonitor || !pMonitor->m_output)
if UNLIKELY (!m_monitor || !m_monitor->m_output)
return; // ??
LOGM(LOG, "setting to monitor {}", pMonitor->m_name);
LOGM(LOG, "setting to monitor {}", m_monitor->m_name);
if (!gammaTableSet) {
pMonitor->m_output->state->setGammaLut({});
if (!m_gammaTableSet) {
m_monitor->m_output->state->setGammaLut({});
return;
}
pMonitor->m_output->state->setGammaLut(gammaTable);
m_monitor->m_output->state->setGammaLut(m_gammaTable);
if (!pMonitor->m_state.test()) {
LOGM(LOG, "setting to monitor {} failed", pMonitor->m_name);
pMonitor->m_output->state->setGammaLut({});
if (!m_monitor->m_state.test()) {
LOGM(LOG, "setting to monitor {} failed", m_monitor->m_name);
m_monitor->m_output->state->setGammaLut({});
}
g_pHyprRenderer->damageMonitor(pMonitor.lock());
g_pHyprRenderer->damageMonitor(m_monitor.lock());
}
PHLMONITOR CGammaControl::getMonitor() {
return pMonitor ? pMonitor.lock() : nullptr;
return m_monitor ? m_monitor.lock() : nullptr;
}
void CGammaControl::onMonitorDestroy() {
LOGM(LOG, "Destroying gamma control for {}", pMonitor->m_name);
resource->sendFailed();
LOGM(LOG, "Destroying gamma control for {}", m_monitor->m_name);
m_resource->sendFailed();
}
CGammaControlProtocol::CGammaControlProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -159,7 +159,7 @@ CGammaControlProtocol::CGammaControlProtocol(const wl_interface* iface, const in
}
void CGammaControlProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwlrGammaControlManagerV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwlrGammaControlManagerV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CZwlrGammaControlManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CZwlrGammaControlManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -167,26 +167,26 @@ void CGammaControlProtocol::bindManager(wl_client* client, void* data, uint32_t
}
void CGammaControlProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CGammaControlProtocol::destroyGammaControl(CGammaControl* gamma) {
std::erase_if(m_vGammaControllers, [&](const auto& other) { return other.get() == gamma; });
std::erase_if(m_gammaControllers, [&](const auto& other) { return other.get() == gamma; });
}
void CGammaControlProtocol::onGetGammaControl(CZwlrGammaControlManagerV1* pMgr, uint32_t id, wl_resource* output) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vGammaControllers.emplace_back(makeUnique<CGammaControl>(makeShared<CZwlrGammaControlV1>(CLIENT, pMgr->version(), id), output)).get();
const auto RESOURCE = m_gammaControllers.emplace_back(makeUnique<CGammaControl>(makeShared<CZwlrGammaControlV1>(CLIENT, pMgr->version(), id), output)).get();
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vGammaControllers.pop_back();
m_gammaControllers.pop_back();
return;
}
}
void CGammaControlProtocol::applyGammaToState(PHLMONITOR pMonitor) {
for (auto const& g : m_vGammaControllers) {
for (auto const& g : m_gammaControllers) {
if (g->getMonitor() != pMonitor)
continue;

View File

@ -18,18 +18,18 @@ class CGammaControl {
PHLMONITOR getMonitor();
private:
SP<CZwlrGammaControlV1> resource;
PHLMONITORREF pMonitor;
size_t gammaSize = 0;
bool gammaTableSet = false;
std::vector<uint16_t> gammaTable; // [r,g,b]+
SP<CZwlrGammaControlV1> m_resource;
PHLMONITORREF m_monitor;
size_t m_gammaSize = 0;
bool m_gammaTableSet = false;
std::vector<uint16_t> m_gammaTable; // [r,g,b]+
void onMonitorDestroy();
struct {
CHyprSignalListener monitorDisconnect;
CHyprSignalListener monitorDestroy;
} listeners;
} m_listeners;
};
class CGammaControlProtocol : public IWaylandProtocol {
@ -46,8 +46,8 @@ class CGammaControlProtocol : public IWaylandProtocol {
void onGetGammaControl(CZwlrGammaControlManagerV1* pMgr, uint32_t id, wl_resource* output);
//
std::vector<UP<CZwlrGammaControlManagerV1>> m_vManagers;
std::vector<UP<CGammaControl>> m_vGammaControllers;
std::vector<UP<CZwlrGammaControlManagerV1>> m_managers;
std::vector<UP<CGammaControl>> m_gammaControllers;
friend class CGammaControl;
};

View File

@ -1,21 +1,21 @@
#include "GlobalShortcuts.hpp"
#include "../helpers/time/Time.hpp"
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : resource(resource_) {
CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
resource->setDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
m_resource->setOnDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
m_resource->setDestroy([this](CHyprlandGlobalShortcutsManagerV1* pMgr) { PROTO::globalShortcuts->destroyResource(this); });
resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description) {
m_resource->setRegisterShortcut([this](CHyprlandGlobalShortcutsManagerV1* pMgr, uint32_t shortcut, const char* id, const char* app_id, const char* description,
const char* trigger_description) {
if UNLIKELY (PROTO::globalShortcuts->isTaken(id, app_id)) {
resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
m_resource->error(HYPRLAND_GLOBAL_SHORTCUTS_MANAGER_V1_ERROR_ALREADY_TAKEN, "Combination is taken");
return;
}
const auto PSHORTCUT = shortcuts.emplace_back(makeShared<SShortcut>(makeShared<CHyprlandGlobalShortcutV1>(resource->client(), resource->version(), shortcut)));
const auto PSHORTCUT = m_shortcuts.emplace_back(makeShared<SShortcut>(makeShared<CHyprlandGlobalShortcutV1>(m_resource->client(), m_resource->version(), shortcut)));
PSHORTCUT->id = id;
PSHORTCUT->description = description;
PSHORTCUT->appid = app_id;
@ -23,16 +23,16 @@ CShortcutClient::CShortcutClient(SP<CHyprlandGlobalShortcutsManagerV1> resource_
if UNLIKELY (!PSHORTCUT->resource->resource()) {
PSHORTCUT->resource->noMemory();
shortcuts.pop_back();
m_shortcuts.pop_back();
return;
}
PSHORTCUT->resource->setDestroy([this](CHyprlandGlobalShortcutV1* pMgr) { std::erase_if(shortcuts, [&](const auto& other) { return other->resource.get() == pMgr; }); });
PSHORTCUT->resource->setDestroy([this](CHyprlandGlobalShortcutV1* pMgr) { std::erase_if(m_shortcuts, [&](const auto& other) { return other->resource.get() == pMgr; }); });
});
}
bool CShortcutClient::good() {
return resource->resource();
return m_resource->resource();
}
CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -40,22 +40,22 @@ CGlobalShortcutsProtocol::CGlobalShortcutsProtocol(const wl_interface* iface, co
}
void CGlobalShortcutsProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESROUCE = m_vClients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
const auto RESROUCE = m_clients.emplace_back(makeShared<CShortcutClient>(makeShared<CHyprlandGlobalShortcutsManagerV1>(client, ver, id)));
if UNLIKELY (!RESROUCE->good()) {
wl_client_post_no_memory(client);
m_vClients.pop_back();
m_clients.pop_back();
return;
}
}
void CGlobalShortcutsProtocol::destroyResource(CShortcutClient* client) {
std::erase_if(m_vClients, [&](const auto& other) { return other.get() == client; });
std::erase_if(m_clients, [&](const auto& other) { return other.get() == client; });
}
bool CGlobalShortcutsProtocol::isTaken(std::string appid, std::string trigger) {
for (auto const& c : m_vClients) {
for (auto const& sh : c->shortcuts) {
for (auto const& c : m_clients) {
for (auto const& sh : c->m_shortcuts) {
if (sh->appid == appid && sh->id == trigger) {
return true;
}
@ -66,8 +66,8 @@ bool CGlobalShortcutsProtocol::isTaken(std::string appid, std::string trigger) {
}
void CGlobalShortcutsProtocol::sendGlobalShortcutEvent(std::string appid, std::string trigger, bool pressed) {
for (auto const& c : m_vClients) {
for (auto const& sh : c->shortcuts) {
for (auto const& c : m_clients) {
for (auto const& sh : c->m_shortcuts) {
if (sh->appid == appid && sh->id == trigger) {
const auto [sec, nsec] = Time::secNsec(Time::steadyNow());
uint32_t tvSecHi = (sizeof(sec) > 4) ? sec >> 32 : 0;
@ -87,15 +87,15 @@ std::vector<SShortcut> CGlobalShortcutsProtocol::getAllShortcuts() {
// and potential reallocation is more costly then the added precompute overhead of looping
// and finding the total size.
size_t totalShortcuts = 0;
for (const auto& c : m_vClients) {
totalShortcuts += c->shortcuts.size();
for (const auto& c : m_clients) {
totalShortcuts += c->m_shortcuts.size();
}
// reserve number of elements to avoid reallocations
copy.reserve(totalShortcuts);
for (const auto& c : m_vClients) {
for (const auto& sh : c->shortcuts) {
for (const auto& c : m_clients) {
for (const auto& sh : c->m_shortcuts) {
copy.push_back(*sh);
}
}

View File

@ -17,8 +17,8 @@ class CShortcutClient {
bool good();
private:
SP<CHyprlandGlobalShortcutsManagerV1> resource;
std::vector<SP<SShortcut>> shortcuts;
SP<CHyprlandGlobalShortcutsManagerV1> m_resource;
std::vector<SP<SShortcut>> m_shortcuts;
friend class CGlobalShortcutsProtocol;
};
@ -35,7 +35,7 @@ class CGlobalShortcutsProtocol : IWaylandProtocol {
std::vector<SShortcut> getAllShortcuts();
private:
std::vector<SP<CShortcutClient>> m_vClients;
std::vector<SP<CShortcutClient>> m_clients;
};
namespace PROTO {

View File

@ -6,83 +6,83 @@
#include <hyprutils/math/Region.hpp>
#include <wayland-server.h>
CHyprlandSurface::CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface) : m_pSurface(surface) {
CHyprlandSurface::CHyprlandSurface(SP<CHyprlandSurfaceV1> resource, SP<CWLSurfaceResource> surface) : m_surface(surface) {
setResource(std::move(resource));
}
bool CHyprlandSurface::good() const {
return m_pResource->resource();
return m_resource->resource();
}
void CHyprlandSurface::setResource(SP<CHyprlandSurfaceV1> resource) {
m_pResource = std::move(resource);
m_resource = std::move(resource);
if UNLIKELY (!m_pResource->resource())
if UNLIKELY (!m_resource->resource())
return;
m_pResource->setDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_pResource->setOnDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_resource->setDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_resource->setOnDestroy([this](CHyprlandSurfaceV1* resource) { destroy(); });
m_pResource->setSetOpacity([this](CHyprlandSurfaceV1* resource, uint32_t opacity) {
if UNLIKELY (!m_pSurface) {
m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE, "set_opacity called for destroyed wl_surface");
m_resource->setSetOpacity([this](CHyprlandSurfaceV1* resource, uint32_t opacity) {
if UNLIKELY (!m_surface) {
m_resource->error(HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE, "set_opacity called for destroyed wl_surface");
return;
}
auto fOpacity = wl_fixed_to_double(opacity);
if UNLIKELY (fOpacity < 0.0 || fOpacity > 1.0) {
m_pResource->error(HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE, "set_opacity called with an opacity value larger than 1.0 or smaller than 0.0.");
m_resource->error(HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE, "set_opacity called with an opacity value larger than 1.0 or smaller than 0.0.");
return;
}
m_fOpacity = fOpacity;
m_opacity = fOpacity;
});
m_pResource->setSetVisibleRegion([this](CHyprlandSurfaceV1* resource, wl_resource* region) {
m_resource->setSetVisibleRegion([this](CHyprlandSurfaceV1* resource, wl_resource* region) {
if (!region) {
if (!m_visibleRegion.empty())
m_bVisibleRegionChanged = true;
m_visibleRegionChanged = true;
m_visibleRegion.clear();
return;
}
m_bVisibleRegionChanged = true;
m_visibleRegion = CWLRegionResource::fromResource(region)->m_region;
m_visibleRegionChanged = true;
m_visibleRegion = CWLRegionResource::fromResource(region)->m_region;
});
listeners.surfaceCommitted = m_pSurface->m_events.commit.registerListener([this](std::any data) {
auto surface = CWLSurface::fromResource(m_pSurface.lock());
m_listeners.surfaceCommitted = m_surface->m_events.commit.registerListener([this](std::any data) {
auto surface = CWLSurface::fromResource(m_surface.lock());
if (surface && (surface->m_overallOpacity != m_fOpacity || m_bVisibleRegionChanged)) {
surface->m_overallOpacity = m_fOpacity;
if (surface && (surface->m_overallOpacity != m_opacity || m_visibleRegionChanged)) {
surface->m_overallOpacity = m_opacity;
surface->m_visibleRegion = m_visibleRegion;
auto box = surface->getSurfaceBoxGlobal();
if (box.has_value())
g_pHyprRenderer->damageBox(*box);
if (!m_pResource)
if (!m_resource)
PROTO::hyprlandSurface->destroySurface(this);
}
});
listeners.surfaceDestroyed = m_pSurface->m_events.destroy.registerListener([this](std::any data) {
if (!m_pResource)
m_listeners.surfaceDestroyed = m_surface->m_events.destroy.registerListener([this](std::any data) {
if (!m_resource)
PROTO::hyprlandSurface->destroySurface(this);
});
}
void CHyprlandSurface::destroy() {
m_pResource.reset();
m_fOpacity = 1.F;
m_resource.reset();
m_opacity = 1.F;
if (!m_visibleRegion.empty())
m_bVisibleRegionChanged = true;
m_visibleRegionChanged = true;
m_visibleRegion.clear();
if (!m_pSurface)
if (!m_surface)
PROTO::hyprlandSurface->destroySurface(this);
}
@ -91,7 +91,7 @@ CHyprlandSurfaceProtocol::CHyprlandSurfaceProtocol(const wl_interface* iface, co
}
void CHyprlandSurfaceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
auto manager = m_vManagers.emplace_back(makeUnique<CHyprlandSurfaceManagerV1>(client, ver, id)).get();
auto manager = m_managers.emplace_back(makeUnique<CHyprlandSurfaceManagerV1>(client, ver, id)).get();
manager->setOnDestroy([this](CHyprlandSurfaceManagerV1* manager) { destroyManager(manager); });
manager->setDestroy([this](CHyprlandSurfaceManagerV1* manager) { destroyManager(manager); });
@ -100,19 +100,19 @@ void CHyprlandSurfaceProtocol::bindManager(wl_client* client, void* data, uint32
}
void CHyprlandSurfaceProtocol::destroyManager(CHyprlandSurfaceManagerV1* manager) {
std::erase_if(m_vManagers, [&](const auto& p) { return p.get() == manager; });
std::erase_if(m_managers, [&](const auto& p) { return p.get() == manager; });
}
void CHyprlandSurfaceProtocol::destroySurface(CHyprlandSurface* surface) {
std::erase_if(m_mSurfaces, [&](const auto& entry) { return entry.second.get() == surface; });
std::erase_if(m_surfaces, [&](const auto& entry) { return entry.second.get() == surface; });
}
void CHyprlandSurfaceProtocol::getSurface(CHyprlandSurfaceManagerV1* manager, uint32_t id, SP<CWLSurfaceResource> surface) {
CHyprlandSurface* hyprlandSurface = nullptr;
auto iter = std::find_if(m_mSurfaces.begin(), m_mSurfaces.end(), [&](const auto& entry) { return entry.second->m_pSurface == surface; });
auto iter = std::find_if(m_surfaces.begin(), m_surfaces.end(), [&](const auto& entry) { return entry.second->m_surface == surface; });
if (iter != m_mSurfaces.end()) {
if (iter->second->m_pResource) {
if (iter != m_surfaces.end()) {
if (iter->second->m_resource) {
LOGM(ERR, "HyprlandSurface already present for surface {:x}", (uintptr_t)surface.get());
manager->error(HYPRLAND_SURFACE_MANAGER_V1_ERROR_ALREADY_CONSTRUCTED, "HyprlandSurface already present");
return;
@ -122,11 +122,11 @@ void CHyprlandSurfaceProtocol::getSurface(CHyprlandSurfaceManagerV1* manager, ui
}
} else {
hyprlandSurface =
m_mSurfaces.emplace(surface, makeUnique<CHyprlandSurface>(makeShared<CHyprlandSurfaceV1>(manager->client(), manager->version(), id), surface)).first->second.get();
m_surfaces.emplace(surface, makeUnique<CHyprlandSurface>(makeShared<CHyprlandSurfaceV1>(manager->client(), manager->version(), id), surface)).first->second.get();
}
if UNLIKELY (!hyprlandSurface->good()) {
manager->noMemory();
m_mSurfaces.erase(surface);
m_surfaces.erase(surface);
}
}

View File

@ -18,10 +18,10 @@ class CHyprlandSurface {
void setResource(SP<CHyprlandSurfaceV1> resource);
private:
SP<CHyprlandSurfaceV1> m_pResource;
WP<CWLSurfaceResource> m_pSurface;
float m_fOpacity = 1.0;
bool m_bVisibleRegionChanged = false;
SP<CHyprlandSurfaceV1> m_resource;
WP<CWLSurfaceResource> m_surface;
float m_opacity = 1.0;
bool m_visibleRegionChanged = false;
CRegion m_visibleRegion;
void destroy();
@ -29,7 +29,7 @@ class CHyprlandSurface {
struct {
CHyprSignalListener surfaceCommitted;
CHyprSignalListener surfaceDestroyed;
} listeners;
} m_listeners;
friend class CHyprlandSurfaceProtocol;
};
@ -45,8 +45,8 @@ class CHyprlandSurfaceProtocol : public IWaylandProtocol {
void destroySurface(CHyprlandSurface* surface);
void getSurface(CHyprlandSurfaceManagerV1* manager, uint32_t id, SP<CWLSurfaceResource> surface);
std::vector<UP<CHyprlandSurfaceManagerV1>> m_vManagers;
std::unordered_map<WP<CWLSurfaceResource>, UP<CHyprlandSurface>> m_mSurfaces;
std::vector<UP<CHyprlandSurfaceManagerV1>> m_managers;
std::unordered_map<WP<CWLSurfaceResource>, UP<CHyprlandSurface>> m_surfaces;
friend class CHyprlandSurface;
};

View File

@ -1,25 +1,25 @@
#include "IdleInhibit.hpp"
#include "core/Compositor.hpp"
CIdleInhibitor::CIdleInhibitor(SP<CIdleInhibitorResource> resource_, SP<CWLSurfaceResource> surf_) : resource(resource_), surface(surf_) {
CIdleInhibitor::CIdleInhibitor(SP<CIdleInhibitorResource> resource_, SP<CWLSurfaceResource> surf_) : m_resource(resource_), m_surface(surf_) {
;
}
CIdleInhibitorResource::CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, SP<CWLSurfaceResource> surface_) : resource(resource_), surface(surface_) {
listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) {
surface.reset();
listeners.destroySurface.reset();
destroySent = true;
events.destroy.emit();
CIdleInhibitorResource::CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, SP<CWLSurfaceResource> surface_) : m_resource(resource_), m_surface(surface_) {
m_listeners.destroySurface = m_surface->m_events.destroy.registerListener([this](std::any d) {
m_surface.reset();
m_listeners.destroySurface.reset();
m_destroySent = true;
m_events.destroy.emit();
});
resource->setOnDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
resource->setDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
m_resource->setOnDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
m_resource->setDestroy([this](CZwpIdleInhibitorV1* p) { PROTO::idleInhibit->removeInhibitor(this); });
}
CIdleInhibitorResource::~CIdleInhibitorResource() {
if (!destroySent)
events.destroy.emit();
if (!m_destroySent)
m_events.destroy.emit();
}
CIdleInhibitProtocol::CIdleInhibitProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -27,11 +27,11 @@ CIdleInhibitProtocol::CIdleInhibitProtocol(const wl_interface* iface, const int&
}
void CIdleInhibitProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [res](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [res](const auto& other) { return other->resource() == res; });
}
void CIdleInhibitProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwpIdleInhibitManagerV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwpIdleInhibitManagerV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CZwpIdleInhibitManagerV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CZwpIdleInhibitManagerV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -40,13 +40,13 @@ void CIdleInhibitProtocol::bindManager(wl_client* client, void* data, uint32_t v
}
void CIdleInhibitProtocol::removeInhibitor(CIdleInhibitorResource* resource) {
std::erase_if(m_vInhibitors, [resource](const auto& el) { return el.get() == resource; });
std::erase_if(m_inhibitors, [resource](const auto& el) { return el.get() == resource; });
}
void CIdleInhibitProtocol::onCreateInhibitor(CZwpIdleInhibitManagerV1* pMgr, uint32_t id, SP<CWLSurfaceResource> surface) {
const auto CLIENT = pMgr->client();
const auto RESOURCE = m_vInhibitors.emplace_back(makeShared<CIdleInhibitorResource>(makeShared<CZwpIdleInhibitorV1>(CLIENT, pMgr->version(), id), surface));
const auto RESOURCE = m_inhibitors.emplace_back(makeShared<CIdleInhibitorResource>(makeShared<CZwpIdleInhibitorV1>(CLIENT, pMgr->version(), id), surface));
RESOURCE->inhibitor = makeShared<CIdleInhibitor>(RESOURCE, surface);
events.newIdleInhibitor.emit(RESOURCE->inhibitor);
RESOURCE->m_inhibitor = makeShared<CIdleInhibitor>(RESOURCE, surface);
m_events.newIdleInhibitor.emit(RESOURCE->m_inhibitor);
}

View File

@ -14,10 +14,10 @@ class CIdleInhibitor {
struct {
CHyprSignalListener destroy;
} listeners;
} m_listeners;
WP<CIdleInhibitorResource> resource;
WP<CWLSurfaceResource> surface;
WP<CIdleInhibitorResource> m_resource;
WP<CWLSurfaceResource> m_surface;
};
class CIdleInhibitorResource {
@ -25,20 +25,20 @@ class CIdleInhibitorResource {
CIdleInhibitorResource(SP<CZwpIdleInhibitorV1> resource_, SP<CWLSurfaceResource> surface_);
~CIdleInhibitorResource();
SP<CIdleInhibitor> inhibitor;
SP<CIdleInhibitor> m_inhibitor;
struct {
CSignal destroy;
} events;
} m_events;
private:
SP<CZwpIdleInhibitorV1> resource;
WP<CWLSurfaceResource> surface;
bool destroySent = false;
SP<CZwpIdleInhibitorV1> m_resource;
WP<CWLSurfaceResource> m_surface;
bool m_destroySent = false;
struct {
CHyprSignalListener destroySurface;
} listeners;
} m_listeners;
};
class CIdleInhibitProtocol : public IWaylandProtocol {
@ -49,7 +49,7 @@ class CIdleInhibitProtocol : public IWaylandProtocol {
struct {
CSignal newIdleInhibitor; // data: SP<CIdleInhibitor>
} events;
} m_events;
private:
void onManagerResourceDestroy(wl_resource* res);
@ -58,8 +58,8 @@ class CIdleInhibitProtocol : public IWaylandProtocol {
void removeInhibitor(CIdleInhibitorResource*);
//
std::vector<UP<CZwpIdleInhibitManagerV1>> m_vManagers;
std::vector<SP<CIdleInhibitorResource>> m_vInhibitors;
std::vector<UP<CZwpIdleInhibitManagerV1>> m_managers;
std::vector<SP<CIdleInhibitorResource>> m_inhibitors;
friend class CIdleInhibitorResource;
};

View File

@ -11,15 +11,15 @@ static int onTimer(SP<CEventLoopTimer> self, void* data) {
}
CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_, uint32_t timeoutMs_, bool obeyInhibitors_) :
resource(resource_), timeoutMs(timeoutMs_), obeyInhibitors(obeyInhibitors_) {
m_resource(resource_), m_timeoutMs(timeoutMs_), m_obeyInhibitors(obeyInhibitors_) {
if UNLIKELY (!resource_->resource())
return;
resource->setDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
resource->setOnDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
m_resource->setDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
m_resource->setOnDestroy([this](CExtIdleNotificationV1* r) { PROTO::idle->destroyNotification(this); });
timer = makeShared<CEventLoopTimer>(std::nullopt, onTimer, this);
g_pEventLoopManager->addTimer(timer);
m_timer = makeShared<CEventLoopTimer>(std::nullopt, onTimer, this);
g_pEventLoopManager->addTimer(m_timer);
updateTimer();
@ -27,36 +27,36 @@ CExtIdleNotification::CExtIdleNotification(SP<CExtIdleNotificationV1> resource_,
}
CExtIdleNotification::~CExtIdleNotification() {
g_pEventLoopManager->removeTimer(timer);
timer.reset();
g_pEventLoopManager->removeTimer(m_timer);
m_timer.reset();
}
bool CExtIdleNotification::good() {
return resource->resource();
return m_resource->resource();
}
void CExtIdleNotification::updateTimer() {
if (PROTO::idle->isInhibited && obeyInhibitors)
timer->updateTimeout(std::nullopt);
if (PROTO::idle->isInhibited && m_obeyInhibitors)
m_timer->updateTimeout(std::nullopt);
else
timer->updateTimeout(std::chrono::milliseconds(timeoutMs));
m_timer->updateTimeout(std::chrono::milliseconds(m_timeoutMs));
}
void CExtIdleNotification::onTimerFired() {
resource->sendIdled();
idled = true;
m_resource->sendIdled();
m_idled = true;
}
void CExtIdleNotification::onActivity() {
if (idled)
resource->sendResumed();
if (m_idled)
m_resource->sendResumed();
idled = false;
m_idled = false;
updateTimer();
}
bool CExtIdleNotification::inhibitorsAreObeyed() const {
return obeyInhibitors;
return m_obeyInhibitors;
}
CIdleNotifyProtocol::CIdleNotifyProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -64,7 +64,7 @@ CIdleNotifyProtocol::CIdleNotifyProtocol(const wl_interface* iface, const int& v
}
void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CExtIdleNotifierV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CExtIdleNotifierV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CExtIdleNotifierV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CExtIdleNotifierV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -75,34 +75,34 @@ void CIdleNotifyProtocol::bindManager(wl_client* client, void* data, uint32_t ve
}
void CIdleNotifyProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CIdleNotifyProtocol::destroyNotification(CExtIdleNotification* notif) {
std::erase_if(m_vNotifications, [&](const auto& other) { return other.get() == notif; });
std::erase_if(m_notifications, [&](const auto& other) { return other.get() == notif; });
}
void CIdleNotifyProtocol::onGetNotification(CExtIdleNotifierV1* pMgr, uint32_t id, uint32_t timeout, wl_resource* seat, bool obeyInhibitors) {
const auto CLIENT = pMgr->client();
const auto RESOURCE =
m_vNotifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout, obeyInhibitors)).get();
m_notifications.emplace_back(makeShared<CExtIdleNotification>(makeShared<CExtIdleNotificationV1>(CLIENT, pMgr->version(), id), timeout, obeyInhibitors)).get();
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vNotifications.pop_back();
m_notifications.pop_back();
return;
}
}
void CIdleNotifyProtocol::onActivity() {
for (auto const& n : m_vNotifications) {
for (auto const& n : m_notifications) {
n->onActivity();
}
}
void CIdleNotifyProtocol::setInhibit(bool inhibited) {
isInhibited = inhibited;
for (auto const& n : m_vNotifications) {
for (auto const& n : m_notifications) {
if (n->inhibitorsAreObeyed())
n->onActivity();
}

View File

@ -19,12 +19,12 @@ class CExtIdleNotification {
bool inhibitorsAreObeyed() const;
private:
SP<CExtIdleNotificationV1> resource;
uint32_t timeoutMs = 0;
SP<CEventLoopTimer> timer;
SP<CExtIdleNotificationV1> m_resource;
uint32_t m_timeoutMs = 0;
SP<CEventLoopTimer> m_timer;
bool idled = false;
bool obeyInhibitors = false;
bool m_idled = false;
bool m_obeyInhibitors = false;
void updateTimer();
};
@ -46,8 +46,8 @@ class CIdleNotifyProtocol : public IWaylandProtocol {
bool isInhibited = false;
//
std::vector<UP<CExtIdleNotifierV1>> m_vManagers;
std::vector<SP<CExtIdleNotification>> m_vNotifications;
std::vector<UP<CExtIdleNotifierV1>> m_managers;
std::vector<SP<CExtIdleNotification>> m_notifications;
friend class CExtIdleNotification;
};

View File

@ -6,12 +6,12 @@
#include "core/Compositor.hpp"
#include <cstring>
CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : resource(resource_), owner(owner_) {
if UNLIKELY (!resource->resource())
CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboardGrabV2> resource_, SP<CInputMethodV2> owner_) : m_resource(resource_), m_owner(owner_) {
if UNLIKELY (!m_resource->resource())
return;
resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); });
resource->setOnDestroy([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); });
m_resource->setRelease([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); });
m_resource->setOnDestroy([this](CZwpInputMethodKeyboardGrabV2* r) { PROTO::ime->destroyResource(this); });
if (!g_pSeatManager->m_keyboard) {
LOGM(ERR, "IME called but no active keyboard???");
@ -22,16 +22,16 @@ CInputMethodKeyboardGrabV2::CInputMethodKeyboardGrabV2(SP<CZwpInputMethodKeyboar
}
CInputMethodKeyboardGrabV2::~CInputMethodKeyboardGrabV2() {
if (!owner.expired())
std::erase_if(owner->grabs, [](const auto& g) { return g.expired(); });
if (!m_owner.expired())
std::erase_if(m_owner->m_grabs, [](const auto& g) { return g.expired(); });
}
void CInputMethodKeyboardGrabV2::sendKeyboardData(SP<IKeyboard> keyboard) {
if (keyboard == pLastKeyboard)
if (keyboard == m_lastKeyboard)
return;
pLastKeyboard = keyboard;
m_lastKeyboard = keyboard;
auto keymapFD = allocateSHMFile(keyboard->m_xkbKeymapString.length() + 1);
if UNLIKELY (!keymapFD.isValid()) {
@ -48,95 +48,96 @@ void CInputMethodKeyboardGrabV2::sendKeyboardData(SP<IKeyboard> keyboard) {
memcpy(data, keyboard->m_xkbKeymapString.c_str(), keyboard->m_xkbKeymapString.length());
munmap(data, keyboard->m_xkbKeymapString.length() + 1);
resource->sendKeymap(WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymapFD.get(), keyboard->m_xkbKeymapString.length() + 1);
m_resource->sendKeymap(WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, keymapFD.get(), keyboard->m_xkbKeymapString.length() + 1);
sendMods(keyboard->m_modifiersState.depressed, keyboard->m_modifiersState.latched, keyboard->m_modifiersState.locked, keyboard->m_modifiersState.group);
resource->sendRepeatInfo(keyboard->m_repeatRate, keyboard->m_repeatDelay);
m_resource->sendRepeatInfo(keyboard->m_repeatRate, keyboard->m_repeatDelay);
}
void CInputMethodKeyboardGrabV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state) {
const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(resource->client()));
const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(m_resource->client()));
resource->sendKey(SERIAL, time, key, (uint32_t)state);
m_resource->sendKey(SERIAL, time, key, (uint32_t)state);
}
void CInputMethodKeyboardGrabV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) {
const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(resource->client()));
const auto SERIAL = g_pSeatManager->nextSerial(g_pSeatManager->seatResourceForClient(m_resource->client()));
resource->sendModifiers(SERIAL, depressed, latched, locked, group);
m_resource->sendModifiers(SERIAL, depressed, latched, locked, group);
}
bool CInputMethodKeyboardGrabV2::good() {
return resource->resource();
return m_resource->resource();
}
SP<CInputMethodV2> CInputMethodKeyboardGrabV2::getOwner() {
return owner.lock();
return m_owner.lock();
}
wl_client* CInputMethodKeyboardGrabV2::client() {
return resource->resource() ? resource->client() : nullptr;
return m_resource->resource() ? m_resource->client() : nullptr;
}
CInputMethodPopupV2::CInputMethodPopupV2(SP<CZwpInputPopupSurfaceV2> resource_, SP<CInputMethodV2> owner_, SP<CWLSurfaceResource> surface) : resource(resource_), owner(owner_) {
if UNLIKELY (!resource->resource())
CInputMethodPopupV2::CInputMethodPopupV2(SP<CZwpInputPopupSurfaceV2> resource_, SP<CInputMethodV2> owner_, SP<CWLSurfaceResource> surface) :
m_resource(resource_), m_owner(owner_) {
if UNLIKELY (!m_resource->resource())
return;
resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); });
resource->setOnDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); });
m_resource->setDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); });
m_resource->setOnDestroy([this](CZwpInputPopupSurfaceV2* r) { PROTO::ime->destroyResource(this); });
pSurface = surface;
m_surface = surface;
listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) {
if (mapped)
events.unmap.emit();
m_listeners.destroySurface = surface->m_events.destroy.registerListener([this](std::any d) {
if (m_mapped)
m_events.unmap.emit();
listeners.destroySurface.reset();
listeners.commitSurface.reset();
m_listeners.destroySurface.reset();
m_listeners.commitSurface.reset();
if (g_pCompositor->m_lastFocus == pSurface)
if (g_pCompositor->m_lastFocus == m_surface)
g_pCompositor->m_lastFocus.reset();
pSurface.reset();
m_surface.reset();
});
listeners.commitSurface = surface->m_events.commit.registerListener([this](std::any d) {
if (pSurface->m_current.texture && !mapped) {
mapped = true;
pSurface->map();
events.map.emit();
m_listeners.commitSurface = surface->m_events.commit.registerListener([this](std::any d) {
if (m_surface->m_current.texture && !m_mapped) {
m_mapped = true;
m_surface->map();
m_events.map.emit();
return;
}
if (!pSurface->m_current.texture && mapped) {
mapped = false;
pSurface->unmap();
events.unmap.emit();
if (!m_surface->m_current.texture && m_mapped) {
m_mapped = false;
m_surface->unmap();
m_events.unmap.emit();
return;
}
events.commit.emit();
m_events.commit.emit();
});
}
CInputMethodPopupV2::~CInputMethodPopupV2() {
if (!owner.expired())
std::erase_if(owner->popups, [](const auto& p) { return p.expired(); });
if (!m_owner.expired())
std::erase_if(m_owner->m_popups, [](const auto& p) { return p.expired(); });
events.destroy.emit();
m_events.destroy.emit();
}
bool CInputMethodPopupV2::good() {
return resource->resource();
return m_resource->resource();
}
void CInputMethodPopupV2::sendInputRectangle(const CBox& box) {
resource->sendTextInputRectangle(box.x, box.y, box.w, box.h);
m_resource->sendTextInputRectangle(box.x, box.y, box.w, box.h);
}
SP<CWLSurfaceResource> CInputMethodPopupV2::surface() {
return pSurface.lock();
return m_surface.lock();
}
void CInputMethodV2::SState::reset() {
@ -145,127 +146,127 @@ void CInputMethodV2::SState::reset() {
preeditString.committed = false;
}
CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : resource(resource_) {
if UNLIKELY (!resource->resource())
CInputMethodV2::CInputMethodV2(SP<CZwpInputMethodV2> resource_) : m_resource(resource_) {
if UNLIKELY (!m_resource->resource())
return;
resource->setDestroy([this](CZwpInputMethodV2* r) {
events.destroy.emit();
m_resource->setDestroy([this](CZwpInputMethodV2* r) {
m_events.destroy.emit();
PROTO::ime->destroyResource(this);
});
resource->setOnDestroy([this](CZwpInputMethodV2* r) {
events.destroy.emit();
m_resource->setOnDestroy([this](CZwpInputMethodV2* r) {
m_events.destroy.emit();
PROTO::ime->destroyResource(this);
});
resource->setCommitString([this](CZwpInputMethodV2* r, const char* str) {
pending.committedString.string = str;
pending.committedString.committed = true;
m_resource->setCommitString([this](CZwpInputMethodV2* r, const char* str) {
m_pending.committedString.string = str;
m_pending.committedString.committed = true;
});
resource->setDeleteSurroundingText([this](CZwpInputMethodV2* r, uint32_t before, uint32_t after) {
pending.deleteSurrounding.before = before;
pending.deleteSurrounding.after = after;
pending.deleteSurrounding.committed = true;
m_resource->setDeleteSurroundingText([this](CZwpInputMethodV2* r, uint32_t before, uint32_t after) {
m_pending.deleteSurrounding.before = before;
m_pending.deleteSurrounding.after = after;
m_pending.deleteSurrounding.committed = true;
});
resource->setSetPreeditString([this](CZwpInputMethodV2* r, const char* str, int32_t begin, int32_t end) {
pending.preeditString.string = str;
pending.preeditString.begin = begin;
pending.preeditString.end = end;
pending.preeditString.committed = true;
m_resource->setSetPreeditString([this](CZwpInputMethodV2* r, const char* str, int32_t begin, int32_t end) {
m_pending.preeditString.string = str;
m_pending.preeditString.begin = begin;
m_pending.preeditString.end = end;
m_pending.preeditString.committed = true;
});
resource->setCommit([this](CZwpInputMethodV2* r, uint32_t serial) {
current = pending;
pending.reset();
events.onCommit.emit();
m_resource->setCommit([this](CZwpInputMethodV2* r, uint32_t serial) {
m_current = m_pending;
m_pending.reset();
m_events.onCommit.emit();
});
resource->setGetInputPopupSurface([this](CZwpInputMethodV2* r, uint32_t id, wl_resource* surface) {
const auto RESOURCE = PROTO::ime->m_vPopups.emplace_back(
makeShared<CInputMethodPopupV2>(makeShared<CZwpInputPopupSurfaceV2>(r->client(), r->version(), id), self.lock(), CWLSurfaceResource::fromResource(surface)));
m_resource->setGetInputPopupSurface([this](CZwpInputMethodV2* r, uint32_t id, wl_resource* surface) {
const auto RESOURCE = PROTO::ime->m_popups.emplace_back(
makeShared<CInputMethodPopupV2>(makeShared<CZwpInputPopupSurfaceV2>(r->client(), r->version(), id), m_self.lock(), CWLSurfaceResource::fromResource(surface)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::ime->m_vPopups.pop_back();
PROTO::ime->m_popups.pop_back();
return;
}
LOGM(LOG, "New IME Popup with resource id {}", id);
popups.emplace_back(RESOURCE);
m_popups.emplace_back(RESOURCE);
events.newPopup.emit(RESOURCE);
m_events.newPopup.emit(RESOURCE);
});
resource->setGrabKeyboard([this](CZwpInputMethodV2* r, uint32_t id) {
m_resource->setGrabKeyboard([this](CZwpInputMethodV2* r, uint32_t id) {
const auto RESOURCE =
PROTO::ime->m_vGrabs.emplace_back(makeShared<CInputMethodKeyboardGrabV2>(makeShared<CZwpInputMethodKeyboardGrabV2>(r->client(), r->version(), id), self.lock()));
PROTO::ime->m_grabs.emplace_back(makeShared<CInputMethodKeyboardGrabV2>(makeShared<CZwpInputMethodKeyboardGrabV2>(r->client(), r->version(), id), m_self.lock()));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::ime->m_vGrabs.pop_back();
PROTO::ime->m_grabs.pop_back();
return;
}
LOGM(LOG, "New IME Grab with resource id {}", id);
grabs.emplace_back(RESOURCE);
m_grabs.emplace_back(RESOURCE);
});
}
CInputMethodV2::~CInputMethodV2() {
events.destroy.emit();
m_events.destroy.emit();
}
bool CInputMethodV2::good() {
return resource->resource();
return m_resource->resource();
}
void CInputMethodV2::activate() {
if (active)
if (m_active)
return;
resource->sendActivate();
active = true;
m_resource->sendActivate();
m_active = true;
}
void CInputMethodV2::deactivate() {
if (!active)
if (!m_active)
return;
resource->sendDeactivate();
active = false;
m_resource->sendDeactivate();
m_active = false;
}
void CInputMethodV2::surroundingText(const std::string& text, uint32_t cursor, uint32_t anchor) {
resource->sendSurroundingText(text.c_str(), cursor, anchor);
m_resource->sendSurroundingText(text.c_str(), cursor, anchor);
}
void CInputMethodV2::textChangeCause(zwpTextInputV3ChangeCause changeCause) {
resource->sendTextChangeCause((uint32_t)changeCause);
m_resource->sendTextChangeCause((uint32_t)changeCause);
}
void CInputMethodV2::textContentType(zwpTextInputV3ContentHint hint, zwpTextInputV3ContentPurpose purpose) {
resource->sendContentType((uint32_t)hint, (uint32_t)purpose);
m_resource->sendContentType((uint32_t)hint, (uint32_t)purpose);
}
void CInputMethodV2::done() {
resource->sendDone();
m_resource->sendDone();
}
void CInputMethodV2::unavailable() {
resource->sendUnavailable();
m_resource->sendUnavailable();
}
bool CInputMethodV2::hasGrab() {
return !grabs.empty();
return !m_grabs.empty();
}
wl_client* CInputMethodV2::grabClient() {
if (grabs.empty())
if (m_grabs.empty())
return nullptr;
for (auto const& gw : grabs) {
for (auto const& gw : m_grabs) {
auto g = gw.lock();
if (!g)
@ -278,19 +279,19 @@ wl_client* CInputMethodV2::grabClient() {
}
void CInputMethodV2::sendInputRectangle(const CBox& box) {
inputRectangle = box;
for (auto const& wp : popups) {
m_inputRectangle = box;
for (auto const& wp : m_popups) {
auto p = wp.lock();
if (!p)
continue;
p->sendInputRectangle(inputRectangle);
p->sendInputRectangle(m_inputRectangle);
}
}
void CInputMethodV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state state) {
for (auto const& gw : grabs) {
for (auto const& gw : m_grabs) {
auto g = gw.lock();
if (!g)
@ -301,7 +302,7 @@ void CInputMethodV2::sendKey(uint32_t time, uint32_t key, wl_keyboard_key_state
}
void CInputMethodV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t locked, uint32_t group) {
for (auto const& gw : grabs) {
for (auto const& gw : m_grabs) {
auto g = gw.lock();
if (!g)
@ -312,7 +313,7 @@ void CInputMethodV2::sendMods(uint32_t depressed, uint32_t latched, uint32_t loc
}
void CInputMethodV2::setKeyboard(SP<IKeyboard> keyboard) {
for (auto const& gw : grabs) {
for (auto const& gw : m_grabs) {
auto g = gw.lock();
if (!g)
@ -323,7 +324,7 @@ void CInputMethodV2::setKeyboard(SP<IKeyboard> keyboard) {
}
wl_client* CInputMethodV2::client() {
return resource->client();
return m_resource->client();
}
CInputMethodV2Protocol::CInputMethodV2Protocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -331,7 +332,7 @@ CInputMethodV2Protocol::CInputMethodV2Protocol(const wl_interface* iface, const
}
void CInputMethodV2Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwpInputMethodManagerV2>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwpInputMethodManagerV2>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CZwpInputMethodManagerV2* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CZwpInputMethodManagerV2* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -339,33 +340,33 @@ void CInputMethodV2Protocol::bindManager(wl_client* client, void* data, uint32_t
}
void CInputMethodV2Protocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CInputMethodV2Protocol::destroyResource(CInputMethodPopupV2* popup) {
std::erase_if(m_vPopups, [&](const auto& other) { return other.get() == popup; });
std::erase_if(m_popups, [&](const auto& other) { return other.get() == popup; });
}
void CInputMethodV2Protocol::destroyResource(CInputMethodKeyboardGrabV2* grab) {
std::erase_if(m_vGrabs, [&](const auto& other) { return other.get() == grab; });
std::erase_if(m_grabs, [&](const auto& other) { return other.get() == grab; });
}
void CInputMethodV2Protocol::destroyResource(CInputMethodV2* ime) {
std::erase_if(m_vIMEs, [&](const auto& other) { return other.get() == ime; });
std::erase_if(m_imes, [&](const auto& other) { return other.get() == ime; });
}
void CInputMethodV2Protocol::onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id) {
const auto RESOURCE = m_vIMEs.emplace_back(makeShared<CInputMethodV2>(makeShared<CZwpInputMethodV2>(mgr->client(), mgr->version(), id)));
const auto RESOURCE = m_imes.emplace_back(makeShared<CInputMethodV2>(makeShared<CZwpInputMethodV2>(mgr->client(), mgr->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
mgr->noMemory();
m_vIMEs.pop_back();
m_imes.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
LOGM(LOG, "New IME with resource id {}", id);
events.newIME.emit(RESOURCE);
m_events.newIME.emit(RESOURCE);
}

View File

@ -21,7 +21,7 @@ class CInputMethodV2 {
CSignal onCommit;
CSignal destroy;
CSignal newPopup;
} events;
} m_events;
struct SState {
void reset();
@ -43,7 +43,8 @@ class CInputMethodV2 {
} deleteSurrounding;
};
SState pending, current;
SState m_pending;
SState m_current;
bool good();
void activate();
@ -64,15 +65,15 @@ class CInputMethodV2 {
wl_client* grabClient();
private:
SP<CZwpInputMethodV2> resource;
std::vector<WP<CInputMethodKeyboardGrabV2>> grabs;
std::vector<WP<CInputMethodPopupV2>> popups;
SP<CZwpInputMethodV2> m_resource;
std::vector<WP<CInputMethodKeyboardGrabV2>> m_grabs;
std::vector<WP<CInputMethodPopupV2>> m_popups;
WP<CInputMethodV2> self;
WP<CInputMethodV2> m_self;
bool active = false;
bool m_active = false;
CBox inputRectangle;
CBox m_inputRectangle;
friend class CInputMethodPopupV2;
friend class CInputMethodKeyboardGrabV2;
@ -93,10 +94,10 @@ class CInputMethodKeyboardGrabV2 {
void sendKeyboardData(SP<IKeyboard> keyboard);
private:
SP<CZwpInputMethodKeyboardGrabV2> resource;
WP<CInputMethodV2> owner;
SP<CZwpInputMethodKeyboardGrabV2> m_resource;
WP<CInputMethodV2> m_owner;
WP<IKeyboard> pLastKeyboard;
WP<IKeyboard> m_lastKeyboard;
};
class CInputMethodPopupV2 {
@ -113,19 +114,19 @@ class CInputMethodPopupV2 {
CSignal unmap;
CSignal commit;
CSignal destroy;
} events;
} m_events;
bool mapped = false;
bool m_mapped = false;
private:
SP<CZwpInputPopupSurfaceV2> resource;
WP<CInputMethodV2> owner;
WP<CWLSurfaceResource> pSurface;
SP<CZwpInputPopupSurfaceV2> m_resource;
WP<CInputMethodV2> m_owner;
WP<CWLSurfaceResource> m_surface;
struct {
CHyprSignalListener destroySurface;
CHyprSignalListener commitSurface;
} listeners;
} m_listeners;
};
class CInputMethodV2Protocol : public IWaylandProtocol {
@ -136,7 +137,7 @@ class CInputMethodV2Protocol : public IWaylandProtocol {
struct {
CSignal newIME; // SP<CInputMethodV2>
} events;
} m_events;
private:
void onManagerResourceDestroy(wl_resource* res);
@ -147,10 +148,10 @@ class CInputMethodV2Protocol : public IWaylandProtocol {
void onGetIME(CZwpInputMethodManagerV2* mgr, wl_resource* seat, uint32_t id);
//
std::vector<UP<CZwpInputMethodManagerV2>> m_vManagers;
std::vector<SP<CInputMethodV2>> m_vIMEs;
std::vector<SP<CInputMethodKeyboardGrabV2>> m_vGrabs;
std::vector<SP<CInputMethodPopupV2>> m_vPopups;
std::vector<UP<CZwpInputMethodManagerV2>> m_managers;
std::vector<SP<CInputMethodV2>> m_imes;
std::vector<SP<CInputMethodKeyboardGrabV2>> m_grabs;
std::vector<SP<CInputMethodPopupV2>> m_popups;
friend class CInputMethodPopupV2;
friend class CInputMethodKeyboardGrabV2;

View File

@ -17,107 +17,107 @@ void CLayerShellResource::SState::reset() {
}
CLayerShellResource::CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, PHLMONITOR pMonitor,
zwlrLayerShellV1Layer layer) : layerNamespace(namespace_), surface(surf_), resource(resource_) {
zwlrLayerShellV1Layer layer) : m_layerNamespace(namespace_), m_surface(surf_), m_resource(resource_) {
if UNLIKELY (!good())
return;
current.layer = layer;
monitor = pMonitor ? pMonitor->m_name : "";
m_current.layer = layer;
m_monitor = pMonitor ? pMonitor->m_name : "";
resource->setDestroy([this](CZwlrLayerSurfaceV1* r) {
events.destroy.emit();
m_resource->setDestroy([this](CZwlrLayerSurfaceV1* r) {
m_events.destroy.emit();
PROTO::layerShell->destroyResource(this);
});
resource->setOnDestroy([this](CZwlrLayerSurfaceV1* r) {
events.destroy.emit();
m_resource->setOnDestroy([this](CZwlrLayerSurfaceV1* r) {
m_events.destroy.emit();
PROTO::layerShell->destroyResource(this);
});
listeners.destroySurface = surf_->m_events.destroy.registerListener([this](std::any d) {
events.destroy.emit();
m_listeners.destroySurface = surf_->m_events.destroy.registerListener([this](std::any d) {
m_events.destroy.emit();
PROTO::layerShell->destroyResource(this);
});
listeners.unmapSurface = surf_->m_events.unmap.registerListener([this](std::any d) { events.unmap.emit(); });
m_listeners.unmapSurface = surf_->m_events.unmap.registerListener([this](std::any d) { m_events.unmap.emit(); });
listeners.commitSurface = surf_->m_events.commit.registerListener([this](std::any d) {
current = pending;
pending.committed = 0;
m_listeners.commitSurface = surf_->m_events.commit.registerListener([this](std::any d) {
m_current = m_pending;
m_pending.committed = 0;
bool attachedBuffer = surface->m_current.texture;
bool attachedBuffer = m_surface->m_current.texture;
if (attachedBuffer && !configured) {
surface->error(-1, "layerSurface was not configured, but a buffer was attached");
if (attachedBuffer && !m_configured) {
m_surface->error(-1, "layerSurface was not configured, but a buffer was attached");
return;
}
constexpr uint32_t horiz = ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT;
constexpr uint32_t vert = ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM;
if (current.desiredSize.x <= 0 && (current.anchor & horiz) != horiz) {
surface->error(-1, "x == 0 but anchor doesn't have left and right");
if (m_current.desiredSize.x <= 0 && (m_current.anchor & horiz) != horiz) {
m_surface->error(-1, "x == 0 but anchor doesn't have left and right");
return;
}
if (current.desiredSize.y <= 0 && (current.anchor & vert) != vert) {
surface->error(-1, "y == 0 but anchor doesn't have top and bottom");
if (m_current.desiredSize.y <= 0 && (m_current.anchor & vert) != vert) {
m_surface->error(-1, "y == 0 but anchor doesn't have top and bottom");
return;
}
if (attachedBuffer && !mapped) {
mapped = true;
surface->map();
events.map.emit();
if (attachedBuffer && !m_mapped) {
m_mapped = true;
m_surface->map();
m_events.map.emit();
return;
}
if (!attachedBuffer && mapped) {
mapped = false;
events.unmap.emit();
surface->unmap();
configured = false;
if (!attachedBuffer && m_mapped) {
m_mapped = false;
m_events.unmap.emit();
m_surface->unmap();
m_configured = false;
return;
}
events.commit.emit();
m_events.commit.emit();
});
resource->setSetSize([this](CZwlrLayerSurfaceV1* r, uint32_t x, uint32_t y) {
pending.committed |= STATE_SIZE;
pending.desiredSize = {(int)x, (int)y};
m_resource->setSetSize([this](CZwlrLayerSurfaceV1* r, uint32_t x, uint32_t y) {
m_pending.committed |= STATE_SIZE;
m_pending.desiredSize = {(int)x, (int)y};
});
resource->setSetAnchor([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
m_resource->setSetAnchor([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
if (anchor > (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_ANCHOR, "Invalid anchor");
return;
}
pending.committed |= STATE_ANCHOR;
pending.anchor = anchor;
m_pending.committed |= STATE_ANCHOR;
m_pending.anchor = anchor;
});
resource->setSetExclusiveZone([this](CZwlrLayerSurfaceV1* r, int32_t zone) {
pending.committed |= STATE_EXCLUSIVE;
pending.exclusive = zone;
m_resource->setSetExclusiveZone([this](CZwlrLayerSurfaceV1* r, int32_t zone) {
m_pending.committed |= STATE_EXCLUSIVE;
m_pending.exclusive = zone;
});
resource->setSetMargin([this](CZwlrLayerSurfaceV1* r, int32_t top, int32_t right, int32_t bottom, int32_t left) {
pending.committed |= STATE_MARGIN;
pending.margin = {left, right, top, bottom};
m_resource->setSetMargin([this](CZwlrLayerSurfaceV1* r, int32_t top, int32_t right, int32_t bottom, int32_t left) {
m_pending.committed |= STATE_MARGIN;
m_pending.margin = {left, right, top, bottom};
});
resource->setSetKeyboardInteractivity([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1KeyboardInteractivity kbi) {
m_resource->setSetKeyboardInteractivity([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1KeyboardInteractivity kbi) {
if (kbi > ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_KEYBOARD_INTERACTIVITY, "Invalid keyboard interactivity");
return;
}
pending.committed |= STATE_INTERACTIVITY;
pending.interactivity = kbi;
m_pending.committed |= STATE_INTERACTIVITY;
m_pending.interactivity = kbi;
});
resource->setGetPopup([this](CZwlrLayerSurfaceV1* r, wl_resource* popup_) {
m_resource->setGetPopup([this](CZwlrLayerSurfaceV1* r, wl_resource* popup_) {
auto popup = CXDGPopupResource::fromResource(popup_);
if (popup->taken) {
@ -126,74 +126,74 @@ CLayerShellResource::CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<C
}
popup->taken = true;
events.newPopup.emit(popup);
m_events.newPopup.emit(popup);
});
resource->setAckConfigure([this](CZwlrLayerSurfaceV1* r, uint32_t serial) {
auto serialFound = std::find_if(serials.begin(), serials.end(), [serial](const auto& e) { return e.first == serial; });
m_resource->setAckConfigure([this](CZwlrLayerSurfaceV1* r, uint32_t serial) {
auto serialFound = std::find_if(m_serials.begin(), m_serials.end(), [serial](const auto& e) { return e.first == serial; });
if (serialFound == serials.end()) {
if (serialFound == m_serials.end()) {
r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE, "Serial invalid in ack_configure");
return;
}
configured = true;
size = serialFound->second;
m_configured = true;
m_size = serialFound->second;
serials.erase(serialFound);
m_serials.erase(serialFound);
});
resource->setSetLayer([this](CZwlrLayerSurfaceV1* r, uint32_t layer) {
m_resource->setSetLayer([this](CZwlrLayerSurfaceV1* r, uint32_t layer) {
if (layer > ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY) {
r->error(ZWLR_LAYER_SHELL_V1_ERROR_INVALID_LAYER, "Invalid layer");
return;
}
pending.committed |= STATE_LAYER;
pending.layer = (zwlrLayerShellV1Layer)layer;
m_pending.committed |= STATE_LAYER;
m_pending.layer = (zwlrLayerShellV1Layer)layer;
});
resource->setSetExclusiveEdge([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
m_resource->setSetExclusiveEdge([this](CZwlrLayerSurfaceV1* r, zwlrLayerSurfaceV1Anchor anchor) {
if (anchor > (ZWLR_LAYER_SURFACE_V1_ANCHOR_TOP | ZWLR_LAYER_SURFACE_V1_ANCHOR_BOTTOM | ZWLR_LAYER_SURFACE_V1_ANCHOR_LEFT | ZWLR_LAYER_SURFACE_V1_ANCHOR_RIGHT)) {
r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Invalid exclusive edge");
return;
}
if (anchor && (!pending.anchor || !(pending.anchor & anchor))) {
if (anchor && (!m_pending.anchor || !(m_pending.anchor & anchor))) {
r->error(ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_EXCLUSIVE_EDGE, "Exclusive edge doesn't align with anchor");
return;
}
pending.committed |= STATE_EDGE;
pending.exclusiveEdge = anchor;
m_pending.committed |= STATE_EDGE;
m_pending.exclusiveEdge = anchor;
});
}
CLayerShellResource::~CLayerShellResource() {
events.destroy.emit();
if (surface)
surface->resetRole();
m_events.destroy.emit();
if (m_surface)
m_surface->resetRole();
}
bool CLayerShellResource::good() {
return resource->resource();
return m_resource->resource();
}
void CLayerShellResource::sendClosed() {
if (closed)
if (m_closed)
return;
closed = true;
resource->sendClosed();
m_closed = true;
m_resource->sendClosed();
}
void CLayerShellResource::configure(const Vector2D& size_) {
size = size_;
m_size = size_;
auto serial = wl_display_next_serial(g_pCompositor->m_wlDisplay);
serials.push_back({serial, size_});
m_serials.push_back({serial, size_});
resource->sendConfigure(serial, size_.x, size_.y);
m_resource->sendConfigure(serial, size_.x, size_.y);
}
CLayerShellProtocol::CLayerShellProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -201,7 +201,7 @@ CLayerShellProtocol::CLayerShellProtocol(const wl_interface* iface, const int& v
}
void CLayerShellProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeUnique<CZwlrLayerShellV1>(client, ver, id)).get();
const auto RESOURCE = m_managers.emplace_back(makeUnique<CZwlrLayerShellV1>(client, ver, id)).get();
RESOURCE->setOnDestroy([this](CZwlrLayerShellV1* p) { this->onManagerResourceDestroy(p->resource()); });
RESOURCE->setDestroy([this](CZwlrLayerShellV1* pMgr) { this->onManagerResourceDestroy(pMgr->resource()); });
@ -211,11 +211,11 @@ void CLayerShellProtocol::bindManager(wl_client* client, void* data, uint32_t ve
}
void CLayerShellProtocol::onManagerResourceDestroy(wl_resource* res) {
std::erase_if(m_vManagers, [&](const auto& other) { return other->resource() == res; });
std::erase_if(m_managers, [&](const auto& other) { return other->resource() == res; });
}
void CLayerShellProtocol::destroyResource(CLayerShellResource* surf) {
std::erase_if(m_vLayers, [&](const auto& other) { return other.get() == surf; });
std::erase_if(m_layers, [&](const auto& other) { return other.get() == surf; });
}
void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* output, zwlrLayerShellV1Layer layer, std::string namespace_) {
@ -238,11 +238,11 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id
return;
}
const auto RESOURCE = m_vLayers.emplace_back(makeShared<CLayerShellResource>(makeShared<CZwlrLayerSurfaceV1>(CLIENT, pMgr->version(), id), SURF, namespace_, PMONITOR, layer));
const auto RESOURCE = m_layers.emplace_back(makeShared<CLayerShellResource>(makeShared<CZwlrLayerSurfaceV1>(CLIENT, pMgr->version(), id), SURF, namespace_, PMONITOR, layer));
if UNLIKELY (!RESOURCE->good()) {
pMgr->noMemory();
m_vLayers.pop_back();
m_layers.pop_back();
return;
}
@ -252,6 +252,6 @@ void CLayerShellProtocol::onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id
LOGM(LOG, "New wlr_layer_surface {:x}", (uintptr_t)RESOURCE.get());
}
CLayerShellRole::CLayerShellRole(SP<CLayerShellResource> ls) : layerSurface(ls) {
CLayerShellRole::CLayerShellRole(SP<CLayerShellResource> ls) : m_layerSurface(ls) {
;
}

View File

@ -21,8 +21,9 @@ class CLayerShellRole : public ISurfaceRole {
return SURFACE_ROLE_LAYER_SHELL;
}
WP<CLayerShellResource> layerSurface;
WP<CLayerShellResource> m_layerSurface;
};
class CLayerShellResource {
public:
CLayerShellResource(SP<CZwlrLayerSurfaceV1> resource_, SP<CWLSurfaceResource> surf_, std::string namespace_, PHLMONITOR pMonitor, zwlrLayerShellV1Layer layer);
@ -48,7 +49,7 @@ class CLayerShellResource {
CSignal map;
CSignal unmap;
CSignal newPopup; // wlr_xdg_popup*
} events;
} m_events;
struct SState {
uint32_t anchor = 0;
@ -64,27 +65,27 @@ class CLayerShellResource {
} margin;
void reset();
} current, pending;
} m_current, m_pending;
Vector2D size;
std::string layerNamespace;
std::string monitor = "";
WP<CWLSurfaceResource> surface;
bool mapped = false;
bool configured = false;
Vector2D m_size;
std::string m_layerNamespace;
std::string m_monitor = "";
WP<CWLSurfaceResource> m_surface;
bool m_mapped = false;
bool m_configured = false;
private:
SP<CZwlrLayerSurfaceV1> resource;
SP<CZwlrLayerSurfaceV1> m_resource;
struct {
CHyprSignalListener commitSurface;
CHyprSignalListener destroySurface;
CHyprSignalListener unmapSurface;
} listeners;
} m_listeners;
bool closed = false;
bool m_closed = false;
std::vector<std::pair<uint32_t, Vector2D>> serials;
std::vector<std::pair<uint32_t, Vector2D>> m_serials;
};
class CLayerShellProtocol : public IWaylandProtocol {
@ -99,8 +100,8 @@ class CLayerShellProtocol : public IWaylandProtocol {
void onGetLayerSurface(CZwlrLayerShellV1* pMgr, uint32_t id, wl_resource* surface, wl_resource* output, zwlrLayerShellV1Layer layer, std::string namespace_);
//
std::vector<UP<CZwlrLayerShellV1>> m_vManagers;
std::vector<SP<CLayerShellResource>> m_vLayers;
std::vector<UP<CZwlrLayerShellV1>> m_managers;
std::vector<SP<CLayerShellResource>> m_layers;
friend class CLayerShellResource;
};

View File

@ -24,7 +24,7 @@ static std::optional<dev_t> devIDFromFD(int fd) {
}
CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tranches_) :
rendererTranche(_rendererTranche), monitorTranches(tranches_) {
m_rendererTranche(_rendererTranche), m_monitorTranches(tranches_) {
std::vector<SDMABUFFormatTableEntry> formatsVec;
std::set<std::pair<uint32_t, uint64_t>> formats;
@ -32,14 +32,14 @@ CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vec
// insert formats into vec if they got inserted into set, meaning they're unique
size_t i = 0;
rendererTranche.indicies.clear();
for (auto const& fmt : rendererTranche.formats) {
m_rendererTranche.indicies.clear();
for (auto const& fmt : m_rendererTranche.formats) {
for (auto const& mod : fmt.modifiers) {
auto format = std::make_pair<>(fmt.drmFormat, mod);
auto [_, inserted] = formats.insert(format);
if (inserted) {
// if it was inserted into set, then its unique and will have a new index in vec
rendererTranche.indicies.push_back(i++);
m_rendererTranche.indicies.push_back(i++);
formatsVec.push_back(SDMABUFFormatTableEntry{
.fmt = fmt.drmFormat,
.modifier = mod,
@ -48,12 +48,12 @@ CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vec
// if it wasn't inserted then find its index in vec
auto it =
std::find_if(formatsVec.begin(), formatsVec.end(), [fmt, mod](const SDMABUFFormatTableEntry& oth) { return oth.fmt == fmt.drmFormat && oth.modifier == mod; });
rendererTranche.indicies.push_back(it - formatsVec.begin());
m_rendererTranche.indicies.push_back(it - formatsVec.begin());
}
}
}
for (auto& [monitor, tranche] : monitorTranches) {
for (auto& [monitor, tranche] : m_monitorTranches) {
tranche.indicies.clear();
for (auto const& fmt : tranche.formats) {
for (auto const& mod : fmt.modifiers) {
@ -77,12 +77,12 @@ CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vec
}
}
tableSize = formatsVec.size() * sizeof(SDMABUFFormatTableEntry);
m_tableSize = formatsVec.size() * sizeof(SDMABUFFormatTableEntry);
CFileDescriptor fds[2];
allocateSHMFilePair(tableSize, fds[0], fds[1]);
allocateSHMFilePair(m_tableSize, fds[0], fds[1]);
auto arr = (SDMABUFFormatTableEntry*)mmap(nullptr, tableSize, PROT_READ | PROT_WRITE, MAP_SHARED, fds[0].get(), 0);
auto arr = (SDMABUFFormatTableEntry*)mmap(nullptr, m_tableSize, PROT_READ | PROT_WRITE, MAP_SHARED, fds[0].get(), 0);
if (arr == MAP_FAILED) {
LOGM(ERR, "mmap failed");
@ -91,50 +91,50 @@ CDMABUFFormatTable::CDMABUFFormatTable(SDMABUFTranche _rendererTranche, std::vec
std::copy(formatsVec.begin(), formatsVec.end(), arr);
munmap(arr, tableSize);
munmap(arr, m_tableSize);
tableFD = std::move(fds[1]);
m_tableFD = std::move(fds[1]);
}
CLinuxDMABuffer::CLinuxDMABuffer(uint32_t id, wl_client* client, Aquamarine::SDMABUFAttrs attrs) {
buffer = makeShared<CDMABuffer>(id, client, attrs);
m_buffer = makeShared<CDMABuffer>(id, client, attrs);
buffer->m_resource->m_buffer = buffer;
m_buffer->m_resource->m_buffer = m_buffer;
listeners.bufferResourceDestroy = buffer->events.destroy.registerListener([this](std::any d) {
listeners.bufferResourceDestroy.reset();
m_listeners.bufferResourceDestroy = m_buffer->events.destroy.registerListener([this](std::any d) {
m_listeners.bufferResourceDestroy.reset();
PROTO::linuxDma->destroyResource(this);
});
if (!buffer->m_success)
if (!m_buffer->m_success)
LOGM(ERR, "Possibly compositor bug: buffer failed to create");
}
CLinuxDMABuffer::~CLinuxDMABuffer() {
if (buffer && buffer->m_resource)
buffer->m_resource->sendRelease();
if (m_buffer && m_buffer->m_resource)
m_buffer->m_resource->sendRelease();
buffer.reset();
listeners.bufferResourceDestroy.reset();
m_buffer.reset();
m_listeners.bufferResourceDestroy.reset();
}
bool CLinuxDMABuffer::good() {
return buffer && buffer->good();
return m_buffer && m_buffer->good();
}
CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(SP<CZwpLinuxBufferParamsV1> resource_) : resource(resource_) {
CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(SP<CZwpLinuxBufferParamsV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
resource->setDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setOnDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setDestroy([this](CZwpLinuxBufferParamsV1* r) { PROTO::linuxDma->destroyResource(this); });
attrs = makeShared<Aquamarine::SDMABUFAttrs>();
m_attrs = makeShared<Aquamarine::SDMABUFAttrs>();
attrs->success = true;
m_attrs->success = true;
resource->setAdd([this](CZwpLinuxBufferParamsV1* r, int32_t fd, uint32_t plane, uint32_t offset, uint32_t stride, uint32_t modHi, uint32_t modLo) {
if (used) {
m_resource->setAdd([this](CZwpLinuxBufferParamsV1* r, int32_t fd, uint32_t plane, uint32_t offset, uint32_t stride, uint32_t modHi, uint32_t modLo) {
if (m_used) {
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
return;
}
@ -144,19 +144,19 @@ CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(SP<CZwpLinuxBufferParamsV
return;
}
if (attrs->fds.at(plane) != -1) {
if (m_attrs->fds.at(plane) != -1) {
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_PLANE_IDX, "plane used");
return;
}
attrs->fds[plane] = fd;
attrs->strides[plane] = stride;
attrs->offsets[plane] = offset;
attrs->modifier = ((uint64_t)modHi << 32) | modLo;
m_attrs->fds[plane] = fd;
m_attrs->strides[plane] = stride;
m_attrs->offsets[plane] = offset;
m_attrs->modifier = ((uint64_t)modHi << 32) | modLo;
});
resource->setCreate([this](CZwpLinuxBufferParamsV1* r, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
if (used) {
m_resource->setCreate([this](CZwpLinuxBufferParamsV1* r, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
if (m_used) {
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
return;
}
@ -167,15 +167,15 @@ CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(SP<CZwpLinuxBufferParamsV
return;
}
attrs->size = {w, h};
attrs->format = fmt;
attrs->planes = 4 - std::count(attrs->fds.begin(), attrs->fds.end(), -1);
m_attrs->size = {w, h};
m_attrs->format = fmt;
m_attrs->planes = 4 - std::count(m_attrs->fds.begin(), m_attrs->fds.end(), -1);
create(0);
});
resource->setCreateImmed([this](CZwpLinuxBufferParamsV1* r, uint32_t id, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
if (used) {
m_resource->setCreateImmed([this](CZwpLinuxBufferParamsV1* r, uint32_t id, int32_t w, int32_t h, uint32_t fmt, zwpLinuxBufferParamsV1Flags flags) {
if (m_used) {
r->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_ALREADY_USED, "Already used");
return;
}
@ -186,20 +186,20 @@ CLinuxDMABUFParamsResource::CLinuxDMABUFParamsResource(SP<CZwpLinuxBufferParamsV
return;
}
attrs->size = {w, h};
attrs->format = fmt;
attrs->planes = 4 - std::count(attrs->fds.begin(), attrs->fds.end(), -1);
m_attrs->size = {w, h};
m_attrs->format = fmt;
m_attrs->planes = 4 - std::count(m_attrs->fds.begin(), m_attrs->fds.end(), -1);
create(id);
});
}
bool CLinuxDMABUFParamsResource::good() {
return resource->resource();
return m_resource->resource();
}
void CLinuxDMABUFParamsResource::create(uint32_t id) {
used = true;
m_used = true;
if UNLIKELY (!verify()) {
LOGM(ERR, "Failed creating a dmabuf: verify() said no");
@ -208,42 +208,42 @@ void CLinuxDMABUFParamsResource::create(uint32_t id) {
if UNLIKELY (!commence()) {
LOGM(ERR, "Failed creating a dmabuf: commence() said no");
resource->sendFailed();
m_resource->sendFailed();
return;
}
LOGM(LOG, "Creating a dmabuf, with id {}: size {}, fmt {}, planes {}", id, attrs->size, NFormatUtils::drmFormatName(attrs->format), attrs->planes);
for (int i = 0; i < attrs->planes; ++i) {
LOGM(LOG, " | plane {}: mod {} fd {} stride {} offset {}", i, attrs->modifier, attrs->fds[i], attrs->strides[i], attrs->offsets[i]);
LOGM(LOG, "Creating a dmabuf, with id {}: size {}, fmt {}, planes {}", id, m_attrs->size, NFormatUtils::drmFormatName(m_attrs->format), m_attrs->planes);
for (int i = 0; i < m_attrs->planes; ++i) {
LOGM(LOG, " | plane {}: mod {} fd {} stride {} offset {}", i, m_attrs->modifier, m_attrs->fds[i], m_attrs->strides[i], m_attrs->offsets[i]);
}
auto buf = PROTO::linuxDma->m_vBuffers.emplace_back(makeShared<CLinuxDMABuffer>(id, resource->client(), *attrs));
auto buf = PROTO::linuxDma->m_buffers.emplace_back(makeShared<CLinuxDMABuffer>(id, m_resource->client(), *m_attrs));
if UNLIKELY (!buf->good() || !buf->buffer->m_success) {
resource->sendFailed();
PROTO::linuxDma->m_vBuffers.pop_back();
if UNLIKELY (!buf->good() || !buf->m_buffer->m_success) {
m_resource->sendFailed();
PROTO::linuxDma->m_buffers.pop_back();
return;
}
if (!id)
resource->sendCreated(PROTO::linuxDma->m_vBuffers.back()->buffer->m_resource->getResource());
m_resource->sendCreated(PROTO::linuxDma->m_buffers.back()->m_buffer->m_resource->getResource());
createdBuffer = buf;
m_createdBuffer = buf;
}
bool CLinuxDMABUFParamsResource::commence() {
if (!PROTO::linuxDma->mainDeviceFD.isValid())
if (!PROTO::linuxDma->m_mainDeviceFD.isValid())
return true;
for (int i = 0; i < attrs->planes; i++) {
for (int i = 0; i < m_attrs->planes; i++) {
uint32_t handle = 0;
if (drmPrimeFDToHandle(PROTO::linuxDma->mainDeviceFD.get(), attrs->fds.at(i), &handle)) {
if (drmPrimeFDToHandle(PROTO::linuxDma->m_mainDeviceFD.get(), m_attrs->fds.at(i), &handle)) {
LOGM(ERR, "Failed to import dmabuf fd");
return false;
}
if (drmCloseBufferHandle(PROTO::linuxDma->mainDeviceFD.get(), handle)) {
if (drmCloseBufferHandle(PROTO::linuxDma->m_mainDeviceFD.get(), handle)) {
LOGM(ERR, "Failed to close dmabuf handle");
return false;
}
@ -253,20 +253,20 @@ bool CLinuxDMABUFParamsResource::commence() {
}
bool CLinuxDMABUFParamsResource::verify() {
if UNLIKELY (attrs->planes <= 0) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added");
if UNLIKELY (m_attrs->planes <= 0) {
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No planes added");
return false;
}
if UNLIKELY (attrs->fds.at(0) < 0) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0");
if UNLIKELY (m_attrs->fds.at(0) < 0) {
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INCOMPLETE, "No plane 0");
return false;
}
bool empty = false;
for (auto const& plane : attrs->fds) {
for (auto const& plane : m_attrs->fds) {
if (empty && plane != -1) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, "Gap in planes");
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT, "Gap in planes");
return false;
}
@ -276,16 +276,16 @@ bool CLinuxDMABUFParamsResource::verify() {
}
}
if UNLIKELY (attrs->size.x < 1 || attrs->size.y < 1) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1");
if UNLIKELY (m_attrs->size.x < 1 || m_attrs->size.y < 1) {
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_DIMENSIONS, "x/y < 1");
return false;
}
for (size_t i = 0; i < (size_t)attrs->planes; ++i) {
if ((uint64_t)attrs->offsets.at(i) + (uint64_t)attrs->strides.at(i) * attrs->size.y > UINT32_MAX) {
resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
std::format("size overflow on plane {}: offset {} + stride {} * height {} = {}, overflows UINT32_MAX", i, (uint64_t)attrs->offsets.at(i),
(uint64_t)attrs->strides.at(i), attrs->size.y, (uint64_t)attrs->offsets.at(i) + (uint64_t)attrs->strides.at(i)));
for (size_t i = 0; i < (size_t)m_attrs->planes; ++i) {
if ((uint64_t)m_attrs->offsets.at(i) + (uint64_t)m_attrs->strides.at(i) * m_attrs->size.y > UINT32_MAX) {
m_resource->error(ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_OUT_OF_BOUNDS,
std::format("size overflow on plane {}: offset {} + stride {} * height {} = {}, overflows UINT32_MAX", i, (uint64_t)m_attrs->offsets.at(i),
(uint64_t)m_attrs->strides.at(i), m_attrs->size.y, (uint64_t)m_attrs->offsets.at(i) + (uint64_t)m_attrs->strides.at(i)));
return false;
}
}
@ -293,20 +293,20 @@ bool CLinuxDMABUFParamsResource::verify() {
return true;
}
CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(SP<CZwpLinuxDmabufFeedbackV1> resource_, SP<CWLSurfaceResource> surface_) : surface(surface_), resource(resource_) {
CLinuxDMABUFFeedbackResource::CLinuxDMABUFFeedbackResource(SP<CZwpLinuxDmabufFeedbackV1> resource_, SP<CWLSurfaceResource> surface_) : m_surface(surface_), m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
resource->setDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setOnDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setDestroy([this](CZwpLinuxDmabufFeedbackV1* r) { PROTO::linuxDma->destroyResource(this); });
auto& formatTable = PROTO::linuxDma->formatTable;
resource->sendFormatTable(formatTable->tableFD.get(), formatTable->tableSize);
auto& formatTable = PROTO::linuxDma->m_formatTable;
m_resource->sendFormatTable(formatTable->m_tableFD.get(), formatTable->m_tableSize);
sendDefaultFeedback();
}
bool CLinuxDMABUFFeedbackResource::good() {
return resource->resource();
return m_resource->resource();
}
void CLinuxDMABUFFeedbackResource::sendTranche(SDMABUFTranche& tranche) {
@ -314,95 +314,95 @@ void CLinuxDMABUFFeedbackResource::sendTranche(SDMABUFTranche& tranche) {
.size = sizeof(tranche.device),
.data = (void*)&tranche.device,
};
resource->sendTrancheTargetDevice(&deviceArr);
m_resource->sendTrancheTargetDevice(&deviceArr);
resource->sendTrancheFlags((zwpLinuxDmabufFeedbackV1TrancheFlags)tranche.flags);
m_resource->sendTrancheFlags((zwpLinuxDmabufFeedbackV1TrancheFlags)tranche.flags);
wl_array indices = {
.size = tranche.indicies.size() * sizeof(tranche.indicies.at(0)),
.data = tranche.indicies.data(),
};
resource->sendTrancheFormats(&indices);
resource->sendTrancheDone();
m_resource->sendTrancheFormats(&indices);
m_resource->sendTrancheDone();
}
// default tranche is based on renderer (egl)
void CLinuxDMABUFFeedbackResource::sendDefaultFeedback() {
auto mainDevice = PROTO::linuxDma->mainDevice;
auto& formatTable = PROTO::linuxDma->formatTable;
auto mainDevice = PROTO::linuxDma->m_mainDevice;
auto& formatTable = PROTO::linuxDma->m_formatTable;
struct wl_array deviceArr = {
.size = sizeof(mainDevice),
.data = (void*)&mainDevice,
};
resource->sendMainDevice(&deviceArr);
m_resource->sendMainDevice(&deviceArr);
sendTranche(formatTable->rendererTranche);
sendTranche(formatTable->m_rendererTranche);
resource->sendDone();
m_resource->sendDone();
lastFeedbackWasScanout = false;
m_lastFeedbackWasScanout = false;
}
CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : resource(resource_) {
CLinuxDMABUFResource::CLinuxDMABUFResource(SP<CZwpLinuxDmabufV1> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
resource->setDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setOnDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
m_resource->setDestroy([this](CZwpLinuxDmabufV1* r) { PROTO::linuxDma->destroyResource(this); });
resource->setGetDefaultFeedback([](CZwpLinuxDmabufV1* r, uint32_t id) {
m_resource->setGetDefaultFeedback([](CZwpLinuxDmabufV1* r, uint32_t id) {
const auto RESOURCE =
PROTO::linuxDma->m_vFeedbacks.emplace_back(makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), nullptr));
PROTO::linuxDma->m_feedbacks.emplace_back(makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), nullptr));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vFeedbacks.pop_back();
PROTO::linuxDma->m_feedbacks.pop_back();
return;
}
});
resource->setGetSurfaceFeedback([](CZwpLinuxDmabufV1* r, uint32_t id, wl_resource* surf) {
const auto RESOURCE = PROTO::linuxDma->m_vFeedbacks.emplace_back(
m_resource->setGetSurfaceFeedback([](CZwpLinuxDmabufV1* r, uint32_t id, wl_resource* surf) {
const auto RESOURCE = PROTO::linuxDma->m_feedbacks.emplace_back(
makeShared<CLinuxDMABUFFeedbackResource>(makeShared<CZwpLinuxDmabufFeedbackV1>(r->client(), r->version(), id), CWLSurfaceResource::fromResource(surf)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vFeedbacks.pop_back();
PROTO::linuxDma->m_feedbacks.pop_back();
return;
}
});
resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) {
const auto RESOURCE = PROTO::linuxDma->m_vParams.emplace_back(makeShared<CLinuxDMABUFParamsResource>(makeShared<CZwpLinuxBufferParamsV1>(r->client(), r->version(), id)));
m_resource->setCreateParams([](CZwpLinuxDmabufV1* r, uint32_t id) {
const auto RESOURCE = PROTO::linuxDma->m_params.emplace_back(makeShared<CLinuxDMABUFParamsResource>(makeShared<CZwpLinuxBufferParamsV1>(r->client(), r->version(), id)));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::linuxDma->m_vParams.pop_back();
PROTO::linuxDma->m_params.pop_back();
return;
}
});
if (resource->version() < 4)
if (m_resource->version() < 4)
sendMods();
}
bool CLinuxDMABUFResource::good() {
return resource->resource();
return m_resource->resource();
}
void CLinuxDMABUFResource::sendMods() {
for (auto const& fmt : PROTO::linuxDma->formatTable->rendererTranche.formats) {
for (auto const& fmt : PROTO::linuxDma->m_formatTable->m_rendererTranche.formats) {
for (auto const& mod : fmt.modifiers) {
if (resource->version() < 3) {
if (m_resource->version() < 3) {
if (mod == DRM_FORMAT_MOD_INVALID || mod == DRM_FORMAT_MOD_LINEAR)
resource->sendFormat(fmt.drmFormat);
m_resource->sendFormat(fmt.drmFormat);
continue;
}
// TODO: https://gitlab.freedesktop.org/xorg/xserver/-/issues/1166
resource->sendModifier(fmt.drmFormat, mod >> 32, mod & 0xFFFFFFFF);
m_resource->sendModifier(fmt.drmFormat, mod >> 32, mod & 0xFFFFFFFF);
}
}
}
@ -418,10 +418,10 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
return;
}
mainDevice = *dev;
m_mainDevice = *dev;
SDMABUFTranche eglTranche = {
.device = mainDevice,
.device = m_mainDevice,
.flags = 0, // renderer isnt for ds so dont set flag.
.formats = g_pHyprOpenGL->getDRMFormats(),
};
@ -434,7 +434,7 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
for (auto const& mon : g_pCompositor->m_monitors) {
auto tranche = SDMABUFTranche{
.device = mainDevice,
.device = m_mainDevice,
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
.formats = mon->m_output->getRenderFormats(),
};
@ -444,25 +444,25 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
static auto monitorAdded = g_pHookSystem->hookDynamic("monitorAdded", [this](void* self, SCallbackInfo& info, std::any param) {
auto pMonitor = std::any_cast<PHLMONITOR>(param);
auto tranche = SDMABUFTranche{
.device = mainDevice,
.device = m_mainDevice,
.flags = ZWP_LINUX_DMABUF_FEEDBACK_V1_TRANCHE_FLAGS_SCANOUT,
.formats = pMonitor->m_output->getRenderFormats(),
};
formatTable->monitorTranches.emplace_back(std::make_pair<>(pMonitor, tranche));
m_formatTable->m_monitorTranches.emplace_back(std::make_pair<>(pMonitor, tranche));
resetFormatTable();
});
static auto monitorRemoved = g_pHookSystem->hookDynamic("monitorRemoved", [this](void* self, SCallbackInfo& info, std::any param) {
auto pMonitor = std::any_cast<PHLMONITOR>(param);
std::erase_if(formatTable->monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
std::erase_if(m_formatTable->m_monitorTranches, [pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
resetFormatTable();
});
}
formatTable = makeUnique<CDMABUFFormatTable>(eglTranche, tches);
m_formatTable = makeUnique<CDMABUFFormatTable>(eglTranche, tches);
drmDevice* device = nullptr;
if (drmGetDeviceFromDevId(mainDevice, 0, &device) != 0) {
if (drmGetDeviceFromDevId(m_mainDevice, 0, &device) != 0) {
LOGM(ERR, "failed to get drm dev, disabling linux dmabuf");
removeGlobal();
return;
@ -470,9 +470,9 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
if (device->available_nodes & (1 << DRM_NODE_RENDER)) {
const char* name = device->nodes[DRM_NODE_RENDER];
mainDeviceFD = CFileDescriptor{open(name, O_RDWR | O_CLOEXEC)};
m_mainDeviceFD = CFileDescriptor{open(name, O_RDWR | O_CLOEXEC)};
drmFreeDevice(&device);
if (!mainDeviceFD.isValid()) {
if (!m_mainDeviceFD.isValid()) {
LOGM(ERR, "failed to open drm dev, disabling linux dmabuf");
removeGlobal();
return;
@ -485,19 +485,19 @@ CLinuxDMABufV1Protocol::CLinuxDMABufV1Protocol(const wl_interface* iface, const
}
void CLinuxDMABufV1Protocol::resetFormatTable() {
if (!formatTable)
if (!m_formatTable)
return;
LOGM(LOG, "Resetting format table");
// this might be a big copy
auto newFormatTable = makeUnique<CDMABUFFormatTable>(formatTable->rendererTranche, formatTable->monitorTranches);
auto newFormatTable = makeUnique<CDMABUFFormatTable>(m_formatTable->m_rendererTranche, m_formatTable->m_monitorTranches);
for (auto const& feedback : m_vFeedbacks) {
feedback->resource->sendFormatTable(newFormatTable->tableFD.get(), newFormatTable->tableSize);
if (feedback->lastFeedbackWasScanout) {
for (auto const& feedback : m_feedbacks) {
feedback->m_resource->sendFormatTable(newFormatTable->m_tableFD.get(), newFormatTable->m_tableSize);
if (feedback->m_lastFeedbackWasScanout) {
PHLMONITOR mon;
auto HLSurface = CWLSurface::fromResource(feedback->surface);
auto HLSurface = CWLSurface::fromResource(feedback->m_surface);
if (auto w = HLSurface->getWindow(); w)
if (auto m = w->m_monitor.lock(); m)
mon = m->m_self.lock();
@ -507,46 +507,46 @@ void CLinuxDMABufV1Protocol::resetFormatTable() {
return;
}
updateScanoutTranche(feedback->surface, mon);
updateScanoutTranche(feedback->m_surface, mon);
} else {
feedback->sendDefaultFeedback();
}
}
// delete old table after we sent new one
formatTable = std::move(newFormatTable);
m_formatTable = std::move(newFormatTable);
}
void CLinuxDMABufV1Protocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CLinuxDMABUFResource>(makeShared<CZwpLinuxDmabufV1>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CLinuxDMABUFResource>(makeShared<CZwpLinuxDmabufV1>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFFeedbackResource* resource) {
std::erase_if(m_vFeedbacks, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_feedbacks, [&](const auto& other) { return other.get() == resource; });
}
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABUFParamsResource* resource) {
std::erase_if(m_vParams, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_params, [&](const auto& other) { return other.get() == resource; });
}
void CLinuxDMABufV1Protocol::destroyResource(CLinuxDMABuffer* resource) {
std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_buffers, [&](const auto& other) { return other.get() == resource; });
}
void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface, PHLMONITOR pMonitor) {
SP<CLinuxDMABUFFeedbackResource> feedbackResource;
for (auto const& f : m_vFeedbacks) {
if (f->surface != surface)
for (auto const& f : m_feedbacks) {
if (f->m_surface != surface)
continue;
feedbackResource = f;
@ -564,10 +564,10 @@ void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface
return;
}
const auto& monitorTranchePair = std::find_if(formatTable->monitorTranches.begin(), formatTable->monitorTranches.end(),
const auto& monitorTranchePair = std::find_if(m_formatTable->m_monitorTranches.begin(), m_formatTable->m_monitorTranches.end(),
[pMonitor](std::pair<PHLMONITORREF, SDMABUFTranche> pair) { return pair.first == pMonitor; });
if (monitorTranchePair == formatTable->monitorTranches.end()) {
if (monitorTranchePair == m_formatTable->m_monitorTranches.end()) {
LOGM(LOG, "updateScanoutTranche: monitor has no tranche");
return;
}
@ -577,17 +577,17 @@ void CLinuxDMABufV1Protocol::updateScanoutTranche(SP<CWLSurfaceResource> surface
LOGM(LOG, "updateScanoutTranche: sending a scanout tranche");
struct wl_array deviceArr = {
.size = sizeof(mainDevice),
.data = (void*)&mainDevice,
.size = sizeof(m_mainDevice),
.data = (void*)&m_mainDevice,
};
feedbackResource->resource->sendMainDevice(&deviceArr);
feedbackResource->m_resource->sendMainDevice(&deviceArr);
// prioritize scnaout tranche but have renderer fallback tranche
// also yes formats can be duped here because different tranche flags (ds and no ds)
feedbackResource->sendTranche(monitorTranche);
feedbackResource->sendTranche(formatTable->rendererTranche);
feedbackResource->sendTranche(m_formatTable->m_rendererTranche);
feedbackResource->resource->sendDone();
feedbackResource->m_resource->sendDone();
feedbackResource->lastFeedbackWasScanout = true;
feedbackResource->m_lastFeedbackWasScanout = true;
}

View File

@ -22,11 +22,11 @@ class CLinuxDMABuffer {
bool good();
private:
SP<CDMABuffer> buffer;
SP<CDMABuffer> m_buffer;
struct {
CHyprSignalListener bufferResourceDestroy;
} listeners;
} m_listeners;
friend class CLinuxDMABUFParamsResource;
};
@ -51,10 +51,10 @@ class CDMABUFFormatTable {
CDMABUFFormatTable(SDMABUFTranche rendererTranche, std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> tranches);
~CDMABUFFormatTable() = default;
Hyprutils::OS::CFileDescriptor tableFD;
size_t tableSize = 0;
SDMABUFTranche rendererTranche;
std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> monitorTranches;
Hyprutils::OS::CFileDescriptor m_tableFD;
size_t m_tableSize = 0;
SDMABUFTranche m_rendererTranche;
std::vector<std::pair<PHLMONITORREF, SDMABUFTranche>> m_monitorTranches;
};
class CLinuxDMABUFParamsResource {
@ -65,12 +65,12 @@ class CLinuxDMABUFParamsResource {
bool good();
void create(uint32_t id); // 0 means not immed
SP<Aquamarine::SDMABUFAttrs> attrs;
WP<CLinuxDMABuffer> createdBuffer;
bool used = false;
SP<Aquamarine::SDMABUFAttrs> m_attrs;
WP<CLinuxDMABuffer> m_createdBuffer;
bool m_used = false;
private:
SP<CZwpLinuxBufferParamsV1> resource;
SP<CZwpLinuxBufferParamsV1> m_resource;
bool verify();
bool commence();
@ -85,11 +85,11 @@ class CLinuxDMABUFFeedbackResource {
void sendDefaultFeedback();
void sendTranche(SDMABUFTranche& tranche);
SP<CWLSurfaceResource> surface; // optional, for surface feedbacks
SP<CWLSurfaceResource> m_surface; // optional, for surface feedbacks
private:
SP<CZwpLinuxDmabufFeedbackV1> resource;
bool lastFeedbackWasScanout = false;
SP<CZwpLinuxDmabufFeedbackV1> m_resource;
bool m_lastFeedbackWasScanout = false;
friend class CLinuxDMABufV1Protocol;
};
@ -103,7 +103,7 @@ class CLinuxDMABUFResource {
void sendMods();
private:
SP<CZwpLinuxDmabufV1> resource;
SP<CZwpLinuxDmabufV1> m_resource;
};
class CLinuxDMABufV1Protocol : public IWaylandProtocol {
@ -123,14 +123,14 @@ class CLinuxDMABufV1Protocol : public IWaylandProtocol {
void resetFormatTable();
//
std::vector<SP<CLinuxDMABUFResource>> m_vManagers;
std::vector<SP<CLinuxDMABUFFeedbackResource>> m_vFeedbacks;
std::vector<SP<CLinuxDMABUFParamsResource>> m_vParams;
std::vector<SP<CLinuxDMABuffer>> m_vBuffers;
std::vector<SP<CLinuxDMABUFResource>> m_managers;
std::vector<SP<CLinuxDMABUFFeedbackResource>> m_feedbacks;
std::vector<SP<CLinuxDMABUFParamsResource>> m_params;
std::vector<SP<CLinuxDMABuffer>> m_buffers;
UP<CDMABUFFormatTable> formatTable;
dev_t mainDevice;
Hyprutils::OS::CFileDescriptor mainDeviceFD;
UP<CDMABUFFormatTable> m_formatTable;
dev_t m_mainDevice;
Hyprutils::OS::CFileDescriptor m_mainDeviceFD;
friend class CLinuxDMABUFResource;
friend class CLinuxDMABUFFeedbackResource;

View File

@ -11,47 +11,48 @@ CMesaDRMBufferResource::CMesaDRMBufferResource(uint32_t id, wl_client* client, A
LOGM(LOG, " | plane {}: mod {} fd {} stride {} offset {}", i, attrs_.modifier, attrs_.fds[i], attrs_.strides[i], attrs_.offsets[i]);
}
buffer = makeShared<CDMABuffer>(id, client, attrs_);
buffer->m_resource->m_buffer = buffer;
m_buffer = makeShared<CDMABuffer>(id, client, attrs_);
m_buffer->m_resource->m_buffer = m_buffer;
listeners.bufferResourceDestroy = buffer->events.destroy.registerListener([this](std::any d) {
listeners.bufferResourceDestroy.reset();
m_listeners.bufferResourceDestroy = m_buffer->events.destroy.registerListener([this](std::any d) {
m_listeners.bufferResourceDestroy.reset();
PROTO::mesaDRM->destroyResource(this);
});
if (!buffer->m_success)
if (!m_buffer->m_success)
LOGM(ERR, "Possibly compositor bug: buffer failed to create");
}
CMesaDRMBufferResource::~CMesaDRMBufferResource() {
if (buffer && buffer->m_resource)
buffer->m_resource->sendRelease();
buffer.reset();
listeners.bufferResourceDestroy.reset();
if (m_buffer && m_buffer->m_resource)
m_buffer->m_resource->sendRelease();
m_buffer.reset();
m_listeners.bufferResourceDestroy.reset();
}
bool CMesaDRMBufferResource::good() {
return buffer && buffer->good();
return m_buffer && m_buffer->good();
}
CMesaDRMResource::CMesaDRMResource(SP<CWlDrm> resource_) : resource(resource_) {
CMesaDRMResource::CMesaDRMResource(SP<CWlDrm> resource_) : m_resource(resource_) {
if UNLIKELY (!good())
return;
resource->setOnDestroy([this](CWlDrm* r) { PROTO::mesaDRM->destroyResource(this); });
m_resource->setOnDestroy([this](CWlDrm* r) { PROTO::mesaDRM->destroyResource(this); });
resource->setAuthenticate([this](CWlDrm* r, uint32_t token) {
m_resource->setAuthenticate([this](CWlDrm* r, uint32_t token) {
// we don't need this
resource->sendAuthenticated();
m_resource->sendAuthenticated();
});
resource->setCreateBuffer([](CWlDrm* r, uint32_t, uint32_t, int32_t, int32_t, uint32_t, uint32_t) { r->error(WL_DRM_ERROR_INVALID_NAME, "Not supported, use prime instead"); });
m_resource->setCreateBuffer(
[](CWlDrm* r, uint32_t, uint32_t, int32_t, int32_t, uint32_t, uint32_t) { r->error(WL_DRM_ERROR_INVALID_NAME, "Not supported, use prime instead"); });
resource->setCreatePlanarBuffer([](CWlDrm* r, uint32_t, uint32_t, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t) {
m_resource->setCreatePlanarBuffer([](CWlDrm* r, uint32_t, uint32_t, int32_t, int32_t, uint32_t, int32_t, int32_t, int32_t, int32_t, int32_t, int32_t) {
r->error(WL_DRM_ERROR_INVALID_NAME, "Not supported, use prime instead");
});
resource->setCreatePrimeBuffer(
m_resource->setCreatePrimeBuffer(
[this](CWlDrm* r, uint32_t id, int32_t nameFd, int32_t w, int32_t h, uint32_t fmt, int32_t off0, int32_t str0, int32_t off1, int32_t str1, int32_t off2, int32_t str2) {
if (off0 < 0 || w <= 0 || h <= 0) {
r->error(WL_DRM_ERROR_INVALID_FORMAT, "Invalid w, h, or offset");
@ -85,29 +86,29 @@ CMesaDRMResource::CMesaDRMResource(SP<CWlDrm> resource_) : resource(resource_) {
attrs.fds[0] = nameFd;
attrs.format = fmt;
const auto RESOURCE = PROTO::mesaDRM->m_vBuffers.emplace_back(makeShared<CMesaDRMBufferResource>(id, resource->client(), attrs));
const auto RESOURCE = PROTO::mesaDRM->m_buffers.emplace_back(makeShared<CMesaDRMBufferResource>(id, m_resource->client(), attrs));
if UNLIKELY (!RESOURCE->good()) {
r->noMemory();
PROTO::mesaDRM->m_vBuffers.pop_back();
PROTO::mesaDRM->m_buffers.pop_back();
return;
}
// append instance so that buffer knows its owner
RESOURCE->buffer->m_resource->m_buffer = RESOURCE->buffer;
RESOURCE->m_buffer->m_resource->m_buffer = RESOURCE->m_buffer;
});
resource->sendDevice(PROTO::mesaDRM->nodeName.c_str());
resource->sendCapabilities(WL_DRM_CAPABILITY_PRIME);
m_resource->sendDevice(PROTO::mesaDRM->m_nodeName.c_str());
m_resource->sendCapabilities(WL_DRM_CAPABILITY_PRIME);
auto fmts = g_pHyprOpenGL->getDRMFormats();
for (auto const& fmt : fmts) {
resource->sendFormat(fmt.drmFormat);
m_resource->sendFormat(fmt.drmFormat);
}
}
bool CMesaDRMResource::good() {
return resource->resource();
return m_resource->resource();
}
CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
@ -120,7 +121,7 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co
}
if (dev->available_nodes & (1 << DRM_NODE_RENDER)) {
nodeName = dev->nodes[DRM_NODE_RENDER];
m_nodeName = dev->nodes[DRM_NODE_RENDER];
} else {
ASSERT(dev->available_nodes & (1 << DRM_NODE_PRIMARY));
@ -132,25 +133,25 @@ CMesaDRMProtocol::CMesaDRMProtocol(const wl_interface* iface, const int& ver, co
}
LOGM(WARN, "No DRM render node, falling back to primary {}", dev->nodes[DRM_NODE_PRIMARY]);
nodeName = dev->nodes[DRM_NODE_PRIMARY];
m_nodeName = dev->nodes[DRM_NODE_PRIMARY];
}
drmFreeDevice(&dev);
}
void CMesaDRMProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
const auto RESOURCE = m_vManagers.emplace_back(makeShared<CMesaDRMResource>(makeShared<CWlDrm>(client, ver, id)));
const auto RESOURCE = m_managers.emplace_back(makeShared<CMesaDRMResource>(makeShared<CWlDrm>(client, ver, id)));
if UNLIKELY (!RESOURCE->good()) {
wl_client_post_no_memory(client);
m_vManagers.pop_back();
m_managers.pop_back();
return;
}
}
void CMesaDRMProtocol::destroyResource(CMesaDRMResource* resource) {
std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_managers, [&](const auto& other) { return other.get() == resource; });
}
void CMesaDRMProtocol::destroyResource(CMesaDRMBufferResource* resource) {
std::erase_if(m_vBuffers, [&](const auto& other) { return other.get() == resource; });
std::erase_if(m_buffers, [&](const auto& other) { return other.get() == resource; });
}

View File

@ -15,11 +15,11 @@ class CMesaDRMBufferResource {
bool good();
private:
SP<CDMABuffer> buffer;
SP<CDMABuffer> m_buffer;
struct {
CHyprSignalListener bufferResourceDestroy;
} listeners;
} m_listeners;
friend class CMesaDRMResource;
};
@ -31,7 +31,7 @@ class CMesaDRMResource {
bool good();
private:
SP<CWlDrm> resource;
SP<CWlDrm> m_resource;
};
class CMesaDRMProtocol : public IWaylandProtocol {
@ -45,10 +45,10 @@ class CMesaDRMProtocol : public IWaylandProtocol {
void destroyResource(CMesaDRMBufferResource* resource);
//
std::vector<SP<CMesaDRMResource>> m_vManagers;
std::vector<SP<CMesaDRMBufferResource>> m_vBuffers;
std::vector<SP<CMesaDRMResource>> m_managers;
std::vector<SP<CMesaDRMBufferResource>> m_buffers;
std::string nodeName = "";
std::string m_nodeName = "";
friend class CMesaDRMResource;
friend class CMesaDRMBufferResource;

View File

@ -196,14 +196,14 @@ CXXColorManagementSurface::CXXColorManagementSurface(SP<CXxColorManagementSurfac
pClient = resource->client();
if (!surface->m_colorManagement.valid()) {
const auto RESOURCE = PROTO::colorManagement->m_vSurfaces.emplace_back(makeShared<CColorManagementSurface>(surface_));
const auto RESOURCE = PROTO::colorManagement->m_surfaces.emplace_back(makeShared<CColorManagementSurface>(surface_));
if UNLIKELY (!RESOURCE) {
resource->noMemory();
PROTO::colorManagement->m_vSurfaces.pop_back();
PROTO::colorManagement->m_surfaces.pop_back();
return;
}
RESOURCE->self = RESOURCE;
RESOURCE->m_self = RESOURCE;
surface->m_colorManagement = RESOURCE;

View File

@ -1686,7 +1686,7 @@ void CHyprRenderer::arrangeLayerArray(PHLMONITOR pMonitor, const std::vector<PHL
continue;
const auto PLAYER = ls->m_layerSurface;
const auto PSTATE = &PLAYER->current;
const auto PSTATE = &PLAYER->m_current;
if (exclusiveZone != (PSTATE->exclusive > 0))
continue;