layers: refactor class member vars (#10149)

* layers: refactor class member vars

* popups: rename m_WLSurface to m_wlSurface
This commit is contained in:
davc0n 2025-04-24 20:49:49 +02:00 committed by GitHub
parent be6268a7ec
commit 0e80ecc534
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 487 additions and 484 deletions

View file

@ -7,32 +7,32 @@
static const auto RULES = std::unordered_set<std::string>{"noanim", "blur", "blurpopups", "dimaround"};
static const auto RULES_PREFIX = std::unordered_set<std::string>{"ignorealpha", "ignorezero", "xray", "animation", "order"};
CLayerRule::CLayerRule(const std::string& rule_, const std::string& ns_) : targetNamespace(ns_), rule(rule_) {
const bool VALID = RULES.contains(rule) || std::any_of(RULES_PREFIX.begin(), RULES_PREFIX.end(), [&rule_](const auto& prefix) { return rule_.starts_with(prefix); });
CLayerRule::CLayerRule(const std::string& rule_, const std::string& ns_) : m_targetNamespace(ns_), m_rule(rule_) {
const bool VALID = RULES.contains(m_rule) || std::any_of(RULES_PREFIX.begin(), RULES_PREFIX.end(), [&rule_](const auto& prefix) { return rule_.starts_with(prefix); });
if (!VALID)
return;
if (rule == "noanim")
ruleType = RULE_NOANIM;
else if (rule == "blur")
ruleType = RULE_BLUR;
else if (rule == "blurpopups")
ruleType = RULE_BLURPOPUPS;
else if (rule == "dimaround")
ruleType = RULE_DIMAROUND;
else if (rule.starts_with("ignorealpha"))
ruleType = RULE_IGNOREALPHA;
else if (rule.starts_with("ignorezero"))
ruleType = RULE_IGNOREZERO;
else if (rule.starts_with("xray"))
ruleType = RULE_XRAY;
else if (rule.starts_with("animation"))
ruleType = RULE_ANIMATION;
else if (rule.starts_with("order"))
ruleType = RULE_ORDER;
if (m_rule == "noanim")
m_ruleType = RULE_NOANIM;
else if (m_rule == "blur")
m_ruleType = RULE_BLUR;
else if (m_rule == "blurpopups")
m_ruleType = RULE_BLURPOPUPS;
else if (m_rule == "dimaround")
m_ruleType = RULE_DIMAROUND;
else if (m_rule.starts_with("ignorealpha"))
m_ruleType = RULE_IGNOREALPHA;
else if (m_rule.starts_with("ignorezero"))
m_ruleType = RULE_IGNOREZERO;
else if (m_rule.starts_with("xray"))
m_ruleType = RULE_XRAY;
else if (m_rule.starts_with("animation"))
m_ruleType = RULE_ANIMATION;
else if (m_rule.starts_with("order"))
m_ruleType = RULE_ORDER;
else {
Debug::log(ERR, "CLayerRule: didn't match a rule that was found valid?!");
ruleType = RULE_INVALID;
m_ruleType = RULE_INVALID;
}
}

View file

@ -22,10 +22,10 @@ class CLayerRule {
RULE_ZUMBA,
};
eRuleType ruleType = RULE_INVALID;
eRuleType m_ruleType = RULE_INVALID;
const std::string targetNamespace;
const std::string rule;
const std::string m_targetNamespace;
const std::string m_rule;
CRuleRegexContainer targetNamespaceRegex;
CRuleRegexContainer m_targetNamespaceRegex;
};

View file

@ -17,7 +17,7 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
auto pMonitor = resource->monitor.empty() ? g_pCompositor->m_lastMonitor.lock() : g_pCompositor->getMonitorFromName(resource->monitor);
pLS->surface->assign(resource->surface.lock(), pLS);
pLS->m_surface->assign(resource->surface.lock(), pLS);
if (!pMonitor) {
Debug::log(ERR, "New LS has no monitor??");
@ -27,54 +27,54 @@ PHLLS CLayerSurface::create(SP<CLayerShellResource> resource) {
if (pMonitor->pMirrorOf)
pMonitor = g_pCompositor->m_monitors.front();
pLS->self = pLS;
pLS->m_self = pLS;
pLS->szNamespace = resource->layerNamespace;
pLS->m_namespace = resource->layerNamespace;
pLS->layer = resource->current.layer;
pLS->popupHead = CPopup::create(pLS);
pLS->monitor = pMonitor;
pLS->m_layer = resource->current.layer;
pLS->m_popupHead = CPopup::create(pLS);
pLS->m_monitor = pMonitor;
pMonitor->m_aLayerSurfaceLayers[resource->current.layer].emplace_back(pLS);
pLS->forceBlur = g_pConfigManager->shouldBlurLS(pLS->szNamespace);
pLS->m_forceBlur = g_pConfigManager->shouldBlurLS(pLS->m_namespace);
g_pAnimationManager->createAnimation(0.f, pLS->alpha, g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->createAnimation(Vector2D(0, 0), pLS->realPosition, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->createAnimation(Vector2D(0, 0), pLS->realSize, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->createAnimation(0.f, pLS->m_alpha, g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->createAnimation(Vector2D(0, 0), pLS->m_realPosition, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
g_pAnimationManager->createAnimation(Vector2D(0, 0), pLS->m_realSize, g_pConfigManager->getAnimationPropertyConfig("layersIn"), pLS, AVARDAMAGE_ENTIRE);
pLS->registerCallbacks();
pLS->alpha->setValueAndWarp(0.f);
pLS->m_alpha->setValueAndWarp(0.f);
Debug::log(LOG, "LayerSurface {:x} (namespace {} layer {}) created on monitor {}", (uintptr_t)resource.get(), resource->layerNamespace, (int)pLS->layer, pMonitor->szName);
Debug::log(LOG, "LayerSurface {:x} (namespace {} layer {}) created on monitor {}", (uintptr_t)resource.get(), resource->layerNamespace, (int)pLS->m_layer, pMonitor->szName);
return pLS;
}
void CLayerSurface::registerCallbacks() {
alpha->setUpdateCallback([this](auto) {
if (dimAround)
g_pHyprRenderer->damageMonitor(monitor.lock());
m_alpha->setUpdateCallback([this](auto) {
if (m_dimAround)
g_pHyprRenderer->damageMonitor(m_monitor.lock());
});
}
CLayerSurface::CLayerSurface(SP<CLayerShellResource> resource_) : layerSurface(resource_) {
listeners.commit = layerSurface->events.commit.registerListener([this](std::any d) { onCommit(); });
listeners.map = layerSurface->events.map.registerListener([this](std::any d) { onMap(); });
listeners.unmap = layerSurface->events.unmap.registerListener([this](std::any d) { onUnmap(); });
listeners.destroy = layerSurface->events.destroy.registerListener([this](std::any d) { onDestroy(); });
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(); });
surface = CWLSurface::create();
m_surface = CWLSurface::create();
}
CLayerSurface::~CLayerSurface() {
if (!g_pHyprOpenGL)
return;
if (surface)
surface->unassign();
if (m_surface)
m_surface->unassign();
g_pHyprRenderer->makeEGLCurrent();
std::erase_if(g_pHyprOpenGL->m_mLayerFramebuffers, [&](const auto& other) { return other.first.expired() || other.first.lock() == self.lock(); });
std::erase_if(g_pHyprOpenGL->m_mLayerFramebuffers, [&](const auto& other) { return other.first.expired() || other.first.lock() == m_self.lock(); });
for (auto const& mon : g_pCompositor->m_realMonitors) {
for (auto& lsl : mon->m_aLayerSurfaceLayers) {
@ -84,29 +84,29 @@ CLayerSurface::~CLayerSurface() {
}
void CLayerSurface::onDestroy() {
Debug::log(LOG, "LayerSurface {:x} destroyed", (uintptr_t)layerSurface.get());
Debug::log(LOG, "LayerSurface {:x} destroyed", (uintptr_t)m_layerSurface.get());
const auto PMONITOR = monitor.lock();
const auto PMONITOR = m_monitor.lock();
if (!PMONITOR)
Debug::log(WARN, "Layersurface destroyed on an invalid monitor (removed?)");
if (!fadingOut) {
if (mapped) {
if (!m_fadingOut) {
if (m_mapped) {
Debug::log(LOG, "Forcing an unmap of a LS that did a straight destroy!");
onUnmap();
} else {
Debug::log(LOG, "Removing LayerSurface that wasn't mapped.");
if (alpha)
alpha->setValueAndWarp(0.f);
fadingOut = true;
g_pCompositor->addToFadingOutSafe(self.lock());
if (m_alpha)
m_alpha->setValueAndWarp(0.f);
m_fadingOut = true;
g_pCompositor->addToFadingOutSafe(m_self.lock());
}
}
popupHead.reset();
m_popupHead.reset();
noProcess = true;
m_noProcess = true;
// rearrange to fix the reserved areas
if (PMONITOR) {
@ -114,35 +114,35 @@ void CLayerSurface::onDestroy() {
PMONITOR->scheduledRecalc = true;
// and damage
CBox geomFixed = {geometry.x + PMONITOR->vecPosition.x, geometry.y + PMONITOR->vecPosition.y, geometry.width, geometry.height};
CBox geomFixed = {m_geometry.x + PMONITOR->vecPosition.x, m_geometry.y + PMONITOR->vecPosition.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
}
readyToDelete = true;
layerSurface.reset();
if (surface)
surface->unassign();
m_readyToDelete = true;
m_layerSurface.reset();
if (m_surface)
m_surface->unassign();
listeners.unmap.reset();
listeners.destroy.reset();
listeners.map.reset();
listeners.commit.reset();
m_listeners.unmap.reset();
m_listeners.destroy.reset();
m_listeners.map.reset();
m_listeners.commit.reset();
}
void CLayerSurface::onMap() {
Debug::log(LOG, "LayerSurface {:x} mapped", (uintptr_t)layerSurface.get());
Debug::log(LOG, "LayerSurface {:x} mapped", (uintptr_t)m_layerSurface.get());
mapped = true;
interactivity = layerSurface->current.interactivity;
m_mapped = true;
m_interactivity = m_layerSurface->current.interactivity;
layerSurface->surface->map();
m_layerSurface->surface->map();
// this layer might be re-mapped.
fadingOut = false;
g_pCompositor->removeFromFadingOutSafe(self.lock());
m_fadingOut = false;
g_pCompositor->removeFromFadingOutSafe(m_self.lock());
// fix if it changed its mon
const auto PMONITOR = monitor.lock();
const auto PMONITOR = m_monitor.lock();
if (!PMONITOR)
return;
@ -153,15 +153,15 @@ void CLayerSurface::onMap() {
g_pHyprRenderer->arrangeLayersForMonitor(PMONITOR->ID);
surface->resource()->enter(PMONITOR->self.lock());
m_surface->resource()->enter(PMONITOR->self.lock());
const bool ISEXCLUSIVE = layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
const bool ISEXCLUSIVE = m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
if (ISEXCLUSIVE)
g_pInputManager->m_dExclusiveLSes.push_back(self);
g_pInputManager->m_dExclusiveLSes.push_back(m_self);
const bool GRABSFOCUS = ISEXCLUSIVE ||
(layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
(m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE &&
// don't focus if constrained
(g_pSeatManager->mouse.expired() || !g_pInputManager->isConstrained()));
@ -169,69 +169,69 @@ void CLayerSurface::onMap() {
// TODO: use the new superb really very cool grab
g_pSeatManager->setGrab(nullptr);
g_pInputManager->releaseAllMouseButtons();
g_pCompositor->focusSurface(surface->resource());
g_pCompositor->focusSurface(m_surface->resource());
const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(geometry.x + PMONITOR->vecPosition.x, geometry.y + PMONITOR->vecPosition.y);
g_pSeatManager->setPointerFocus(surface->resource(), LOCAL);
const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_geometry.x + PMONITOR->vecPosition.x, m_geometry.y + PMONITOR->vecPosition.y);
g_pSeatManager->setPointerFocus(m_surface->resource(), LOCAL);
g_pInputManager->m_bEmptyFocusCursorSet = false;
}
position = Vector2D(geometry.x, geometry.y);
m_position = Vector2D(m_geometry.x, m_geometry.y);
CBox geomFixed = {geometry.x + PMONITOR->vecPosition.x, geometry.y + PMONITOR->vecPosition.y, geometry.width, geometry.height};
CBox geomFixed = {m_geometry.x + PMONITOR->vecPosition.x, m_geometry.y + PMONITOR->vecPosition.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
const bool FULLSCREEN = PMONITOR->activeWorkspace && PMONITOR->activeWorkspace->m_bHasFullscreenWindow && PMONITOR->activeWorkspace->m_efFullscreenMode == FSMODE_FULLSCREEN;
startAnimation(!(layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && FULLSCREEN && !GRABSFOCUS));
readyToDelete = false;
fadingOut = false;
startAnimation(!(m_layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && FULLSCREEN && !GRABSFOCUS));
m_readyToDelete = false;
m_fadingOut = false;
g_pEventManager->postEvent(SHyprIPCEvent{"openlayer", szNamespace});
EMIT_HOOK_EVENT("openLayer", self.lock());
g_pEventManager->postEvent(SHyprIPCEvent{"openlayer", m_namespace});
EMIT_HOOK_EVENT("openLayer", m_self.lock());
g_pCompositor->setPreferredScaleForSurface(surface->resource(), PMONITOR->scale);
g_pCompositor->setPreferredTransformForSurface(surface->resource(), PMONITOR->transform);
g_pCompositor->setPreferredScaleForSurface(m_surface->resource(), PMONITOR->scale);
g_pCompositor->setPreferredTransformForSurface(m_surface->resource(), PMONITOR->transform);
}
void CLayerSurface::onUnmap() {
Debug::log(LOG, "LayerSurface {:x} unmapped", (uintptr_t)layerSurface.get());
Debug::log(LOG, "LayerSurface {:x} unmapped", (uintptr_t)m_layerSurface.get());
g_pEventManager->postEvent(SHyprIPCEvent{"closelayer", layerSurface->layerNamespace});
EMIT_HOOK_EVENT("closeLayer", self.lock());
g_pEventManager->postEvent(SHyprIPCEvent{"closelayer", m_layerSurface->layerNamespace});
EMIT_HOOK_EVENT("closeLayer", m_self.lock());
std::erase_if(g_pInputManager->m_dExclusiveLSes, [this](const auto& other) { return !other.lock() || other.lock() == self.lock(); });
std::erase_if(g_pInputManager->m_dExclusiveLSes, [this](const auto& other) { return !other.lock() || other.lock() == m_self.lock(); });
if (!monitor || g_pCompositor->m_unsafeState) {
if (!m_monitor || g_pCompositor->m_unsafeState) {
Debug::log(WARN, "Layersurface unmapping on invalid monitor (removed?) ignoring.");
g_pCompositor->addToFadingOutSafe(self.lock());
g_pCompositor->addToFadingOutSafe(m_self.lock());
mapped = false;
if (layerSurface && layerSurface->surface)
layerSurface->surface->unmap();
m_mapped = false;
if (m_layerSurface && m_layerSurface->surface)
m_layerSurface->surface->unmap();
startAnimation(false);
return;
}
// end any pending animations so that snapshot has right dimensions
realPosition->warp();
realSize->warp();
m_realPosition->warp();
m_realSize->warp();
// make a snapshot and start fade
g_pHyprRenderer->makeLayerSnapshot(self.lock());
g_pHyprRenderer->makeLayerSnapshot(m_self.lock());
startAnimation(false);
mapped = false;
if (layerSurface && layerSurface->surface)
layerSurface->surface->unmap();
m_mapped = false;
if (m_layerSurface && m_layerSurface->surface)
m_layerSurface->surface->unmap();
g_pCompositor->addToFadingOutSafe(self.lock());
g_pCompositor->addToFadingOutSafe(m_self.lock());
const auto PMONITOR = monitor.lock();
const auto PMONITOR = m_monitor.lock();
const bool WASLASTFOCUS = g_pSeatManager->state.keyboardFocus == surface->resource() || g_pSeatManager->state.pointerFocus == surface->resource();
const bool WASLASTFOCUS = g_pSeatManager->state.keyboardFocus == m_surface->resource() || g_pSeatManager->state.pointerFocus == m_surface->resource();
if (!PMONITOR)
return;
@ -241,14 +241,14 @@ void CLayerSurface::onUnmap() {
if (WASLASTFOCUS || (g_pCompositor->m_lastFocus && g_pCompositor->m_lastFocus->hlSurface && !g_pCompositor->m_lastFocus->hlSurface->keyboardFocusable())) {
if (!g_pInputManager->refocusLastWindow(PMONITOR))
g_pInputManager->refocus();
} else if (g_pCompositor->m_lastFocus && g_pCompositor->m_lastFocus != surface->resource())
} else if (g_pCompositor->m_lastFocus && g_pCompositor->m_lastFocus != m_surface->resource())
g_pSeatManager->setKeyboardFocus(g_pCompositor->m_lastFocus.lock());
CBox geomFixed = {geometry.x + PMONITOR->vecPosition.x, geometry.y + PMONITOR->vecPosition.y, geometry.width, geometry.height};
CBox geomFixed = {m_geometry.x + PMONITOR->vecPosition.x, m_geometry.y + PMONITOR->vecPosition.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
geomFixed = {geometry.x + (int)PMONITOR->vecPosition.x, geometry.y + (int)PMONITOR->vecPosition.y, (int)layerSurface->surface->current.size.x,
(int)layerSurface->surface->current.size.y};
geomFixed = {m_geometry.x + (int)PMONITOR->vecPosition.x, m_geometry.y + (int)PMONITOR->vecPosition.y, (int)m_layerSurface->surface->current.size.x,
(int)m_layerSurface->surface->current.size.y};
g_pHyprRenderer->damageBox(geomFixed);
g_pInputManager->simulateMouseMovement();
@ -257,47 +257,47 @@ void CLayerSurface::onUnmap() {
}
void CLayerSurface::onCommit() {
if (!layerSurface)
if (!m_layerSurface)
return;
if (!mapped) {
if (!m_mapped) {
// we're re-mapping if this is the case
if (layerSurface->surface && !layerSurface->surface->current.texture) {
fadingOut = false;
geometry = {};
if (m_layerSurface->surface && !m_layerSurface->surface->current.texture) {
m_fadingOut = false;
m_geometry = {};
g_pHyprRenderer->arrangeLayersForMonitor(monitorID());
}
return;
}
const auto PMONITOR = monitor.lock();
const auto PMONITOR = m_monitor.lock();
if (!PMONITOR)
return;
if (layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)
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
CBox geomFixed = {geometry.x, geometry.y, geometry.width, geometry.height};
CBox geomFixed = {m_geometry.x, m_geometry.y, m_geometry.width, m_geometry.height};
g_pHyprRenderer->damageBox(geomFixed);
if (layerSurface->current.committed != 0) {
if (layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_LAYER) {
if (m_layerSurface->current.committed != 0) {
if (m_layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_LAYER) {
for (auto it = PMONITOR->m_aLayerSurfaceLayers[layer].begin(); it != PMONITOR->m_aLayerSurfaceLayers[layer].end(); it++) {
if (*it == self) {
if (layerSurface->current.layer == layer)
for (auto it = PMONITOR->m_aLayerSurfaceLayers[m_layer].begin(); it != PMONITOR->m_aLayerSurfaceLayers[m_layer].end(); it++) {
if (*it == m_self) {
if (m_layerSurface->current.layer == m_layer)
break;
PMONITOR->m_aLayerSurfaceLayers[layerSurface->current.layer].emplace_back(*it);
PMONITOR->m_aLayerSurfaceLayers[layer].erase(it);
PMONITOR->m_aLayerSurfaceLayers[m_layerSurface->current.layer].emplace_back(*it);
PMONITOR->m_aLayerSurfaceLayers[m_layer].erase(it);
break;
}
}
layer = layerSurface->current.layer;
m_layer = m_layerSurface->current.layer;
if (layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)
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
}
@ -305,136 +305,136 @@ void CLayerSurface::onCommit() {
PMONITOR->scheduledRecalc = true;
} else {
position = Vector2D(geometry.x, geometry.y);
m_position = Vector2D(m_geometry.x, m_geometry.y);
// update geom if it changed
if (layerSurface->surface->current.scale == 1 && PMONITOR->scale != 1.f && layerSurface->surface->current.viewport.hasDestination) {
if (m_layerSurface->surface->current.scale == 1 && PMONITOR->scale != 1.f && m_layerSurface->surface->current.viewport.hasDestination) {
// fractional scaling. Dirty hack.
geometry = {geometry.pos(), layerSurface->surface->current.viewport.destination};
m_geometry = {m_geometry.pos(), m_layerSurface->surface->current.viewport.destination};
} else {
// this is because some apps like e.g. rofi-lbonn can't fucking use the protocol correctly.
geometry = {geometry.pos(), layerSurface->surface->current.size};
m_geometry = {m_geometry.pos(), m_layerSurface->surface->current.size};
}
}
if (realPosition->goal() != geometry.pos()) {
if (realPosition->isBeingAnimated())
*realPosition = geometry.pos();
if (m_realPosition->goal() != m_geometry.pos()) {
if (m_realPosition->isBeingAnimated())
*m_realPosition = m_geometry.pos();
else
realPosition->setValueAndWarp(geometry.pos());
m_realPosition->setValueAndWarp(m_geometry.pos());
}
if (realSize->goal() != geometry.size()) {
if (realSize->isBeingAnimated())
*realSize = geometry.size();
if (m_realSize->goal() != m_geometry.size()) {
if (m_realSize->isBeingAnimated())
*m_realSize = m_geometry.size();
else
realSize->setValueAndWarp(geometry.size());
m_realSize->setValueAndWarp(m_geometry.size());
}
if (mapped && (layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_INTERACTIVITY)) {
if (m_mapped && (m_layerSurface->current.committed & CLayerShellResource::eCommittedState::STATE_INTERACTIVITY)) {
bool WASLASTFOCUS = false;
layerSurface->surface->breadthfirst(
m_layerSurface->surface->breadthfirst(
[&WASLASTFOCUS](SP<CWLSurfaceResource> surf, const Vector2D& offset, void* data) { WASLASTFOCUS = WASLASTFOCUS || g_pSeatManager->state.keyboardFocus == surf; },
nullptr);
if (!WASLASTFOCUS && popupHead) {
popupHead->breadthfirst(
if (!WASLASTFOCUS && m_popupHead) {
m_popupHead->breadthfirst(
[&WASLASTFOCUS](WP<CPopup> popup, void* data) {
WASLASTFOCUS = WASLASTFOCUS || (popup->m_pWLSurface && g_pSeatManager->state.keyboardFocus == popup->m_pWLSurface->resource());
WASLASTFOCUS = WASLASTFOCUS || (popup->m_wlSurface && g_pSeatManager->state.keyboardFocus == popup->m_wlSurface->resource());
},
nullptr);
}
const bool WASEXCLUSIVE = interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
const bool ISEXCLUSIVE = layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_EXCLUSIVE;
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;
if (!WASEXCLUSIVE && ISEXCLUSIVE)
g_pInputManager->m_dExclusiveLSes.push_back(self);
g_pInputManager->m_dExclusiveLSes.push_back(m_self);
else if (WASEXCLUSIVE && !ISEXCLUSIVE)
std::erase_if(g_pInputManager->m_dExclusiveLSes, [this](const auto& other) { return !other.lock() || other.lock() == self.lock(); });
std::erase_if(g_pInputManager->m_dExclusiveLSes, [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 && layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) {
if (WASLASTFOCUS && m_layerSurface->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(monitor.lock());
} else if (WASLASTFOCUS && WASEXCLUSIVE && layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
g_pInputManager->refocusLastWindow(m_monitor.lock());
} else if (WASLASTFOCUS && WASEXCLUSIVE && m_layerSurface->current.interactivity == ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_ON_DEMAND) {
g_pInputManager->simulateMouseMovement();
} else if (!WASEXCLUSIVE && ISEXCLUSIVE) {
// if now exclusive and not previously
g_pSeatManager->setGrab(nullptr);
g_pInputManager->releaseAllMouseButtons();
g_pCompositor->focusSurface(surface->resource());
g_pCompositor->focusSurface(m_surface->resource());
const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(geometry.x + PMONITOR->vecPosition.x, geometry.y + PMONITOR->vecPosition.y);
g_pSeatManager->setPointerFocus(surface->resource(), LOCAL);
const auto LOCAL = g_pInputManager->getMouseCoordsInternal() - Vector2D(m_geometry.x + PMONITOR->vecPosition.x, m_geometry.y + PMONITOR->vecPosition.y);
g_pSeatManager->setPointerFocus(m_surface->resource(), LOCAL);
g_pInputManager->m_bEmptyFocusCursorSet = false;
}
}
interactivity = layerSurface->current.interactivity;
m_interactivity = m_layerSurface->current.interactivity;
g_pHyprRenderer->damageSurface(surface->resource(), position.x, position.y);
g_pHyprRenderer->damageSurface(m_surface->resource(), m_position.x, m_position.y);
g_pCompositor->setPreferredScaleForSurface(surface->resource(), PMONITOR->scale);
g_pCompositor->setPreferredTransformForSurface(surface->resource(), PMONITOR->transform);
g_pCompositor->setPreferredScaleForSurface(m_surface->resource(), PMONITOR->scale);
g_pCompositor->setPreferredTransformForSurface(m_surface->resource(), PMONITOR->transform);
}
void CLayerSurface::applyRules() {
noAnimations = false;
forceBlur = false;
ignoreAlpha = false;
ignoreAlphaValue = 0.f;
dimAround = false;
xray = -1;
animationStyle.reset();
m_noAnimations = false;
m_forceBlur = false;
m_ignoreAlpha = false;
m_ignoreAlphaValue = 0.f;
m_dimAround = false;
m_xray = -1;
m_animationStyle.reset();
for (auto const& rule : g_pConfigManager->getMatchingRules(self.lock())) {
switch (rule->ruleType) {
for (auto const& rule : g_pConfigManager->getMatchingRules(m_self.lock())) {
switch (rule->m_ruleType) {
case CLayerRule::RULE_NOANIM: {
noAnimations = true;
m_noAnimations = true;
break;
}
case CLayerRule::RULE_BLUR: {
forceBlur = true;
m_forceBlur = true;
break;
}
case CLayerRule::RULE_BLURPOPUPS: {
forceBlurPopups = true;
m_forceBlurPopups = true;
break;
}
case CLayerRule::RULE_IGNOREALPHA:
case CLayerRule::RULE_IGNOREZERO: {
const auto FIRST_SPACE_POS = rule->rule.find_first_of(' ');
const auto FIRST_SPACE_POS = rule->m_rule.find_first_of(' ');
std::string alphaValue = "";
if (FIRST_SPACE_POS != std::string::npos)
alphaValue = rule->rule.substr(FIRST_SPACE_POS + 1);
alphaValue = rule->m_rule.substr(FIRST_SPACE_POS + 1);
try {
ignoreAlpha = true;
m_ignoreAlpha = true;
if (!alphaValue.empty())
ignoreAlphaValue = std::stof(alphaValue);
m_ignoreAlphaValue = std::stof(alphaValue);
} catch (...) { Debug::log(ERR, "Invalid value passed to ignoreAlpha"); }
break;
}
case CLayerRule::RULE_DIMAROUND: {
dimAround = true;
m_dimAround = true;
break;
}
case CLayerRule::RULE_XRAY: {
CVarList vars{rule->rule, 0, ' '};
CVarList vars{rule->m_rule, 0, ' '};
try {
xray = configStringToInt(vars[1]).value_or(false);
m_xray = configStringToInt(vars[1]).value_or(false);
} catch (...) {}
break;
}
case CLayerRule::RULE_ANIMATION: {
CVarList vars{rule->rule, 2, 's'};
animationStyle = vars[1];
CVarList vars{rule->m_rule, 2, 's'};
m_animationStyle = vars[1];
break;
}
case CLayerRule::RULE_ORDER: {
CVarList vars{rule->rule, 2, 's'};
CVarList vars{rule->m_rule, 2, 's'};
try {
order = std::stoi(vars[1]);
m_order = std::stoi(vars[1]);
} catch (...) { Debug::log(ERR, "Invalid value passed to order"); }
break;
}
@ -445,19 +445,19 @@ void CLayerSurface::applyRules() {
void CLayerSurface::startAnimation(bool in, bool instant) {
if (in) {
realPosition->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
realSize->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
alpha->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"));
m_realPosition->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
m_realSize->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersIn"));
m_alpha->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersIn"));
} else {
realPosition->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
realSize->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
alpha->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersOut"));
m_realPosition->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
m_realSize->setConfig(g_pConfigManager->getAnimationPropertyConfig("layersOut"));
m_alpha->setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeLayersOut"));
}
const auto ANIMSTYLE = animationStyle.value_or(realPosition->getStyle());
const auto ANIMSTYLE = m_animationStyle.value_or(m_realPosition->getStyle());
if (ANIMSTYLE.starts_with("slide")) {
// get closest edge
const auto MIDDLE = geometry.middle();
const auto MIDDLE = m_geometry.middle();
const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE);
@ -495,38 +495,38 @@ void CLayerSurface::startAnimation(bool in, bool instant) {
}
}
realSize->setValueAndWarp(geometry.size());
alpha->setValueAndWarp(in ? 0.f : 1.f);
*alpha = in ? 1.f : 0.f;
m_realSize->setValueAndWarp(m_geometry.size());
m_alpha->setValueAndWarp(in ? 0.f : 1.f);
*m_alpha = in ? 1.f : 0.f;
Vector2D prePos;
switch (leader) {
case 0:
// TOP
prePos = {geometry.x, PMONITOR->vecPosition.y - geometry.h};
prePos = {m_geometry.x, PMONITOR->vecPosition.y - m_geometry.h};
break;
case 1:
// BOTTOM
prePos = {geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y};
prePos = {m_geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y};
break;
case 2:
// LEFT
prePos = {PMONITOR->vecPosition.x - geometry.w, geometry.y};
prePos = {PMONITOR->vecPosition.x - m_geometry.w, m_geometry.y};
break;
case 3:
// RIGHT
prePos = {PMONITOR->vecPosition.x + PMONITOR->vecSize.x, geometry.y};
prePos = {PMONITOR->vecPosition.x + PMONITOR->vecSize.x, m_geometry.y};
break;
default: UNREACHABLE();
}
if (in) {
realPosition->setValueAndWarp(prePos);
*realPosition = geometry.pos();
m_realPosition->setValueAndWarp(prePos);
*m_realPosition = m_geometry.pos();
} else {
realPosition->setValueAndWarp(geometry.pos());
*realPosition = prePos;
m_realPosition->setValueAndWarp(m_geometry.pos());
*m_realPosition = prePos;
}
} else if (ANIMSTYLE.starts_with("popin")) {
@ -542,62 +542,62 @@ void CLayerSurface::startAnimation(bool in, bool instant) {
minPerc *= 0.01;
const auto GOALSIZE = (geometry.size() * minPerc).clamp({5, 5});
const auto GOALPOS = geometry.pos() + (geometry.size() - GOALSIZE) / 2.f;
const auto GOALSIZE = (m_geometry.size() * minPerc).clamp({5, 5});
const auto GOALPOS = m_geometry.pos() + (m_geometry.size() - GOALSIZE) / 2.f;
alpha->setValueAndWarp(in ? 0.f : 1.f);
*alpha = in ? 1.f : 0.f;
m_alpha->setValueAndWarp(in ? 0.f : 1.f);
*m_alpha = in ? 1.f : 0.f;
if (in) {
realSize->setValueAndWarp(GOALSIZE);
realPosition->setValueAndWarp(GOALPOS);
*realSize = geometry.size();
*realPosition = geometry.pos();
m_realSize->setValueAndWarp(GOALSIZE);
m_realPosition->setValueAndWarp(GOALPOS);
*m_realSize = m_geometry.size();
*m_realPosition = m_geometry.pos();
} else {
realSize->setValueAndWarp(geometry.size());
realPosition->setValueAndWarp(geometry.pos());
*realSize = GOALSIZE;
*realPosition = GOALPOS;
m_realSize->setValueAndWarp(m_geometry.size());
m_realPosition->setValueAndWarp(m_geometry.pos());
*m_realSize = GOALSIZE;
*m_realPosition = GOALPOS;
}
} else {
// fade
realPosition->setValueAndWarp(geometry.pos());
realSize->setValueAndWarp(geometry.size());
*alpha = in ? 1.f : 0.f;
m_realPosition->setValueAndWarp(m_geometry.pos());
m_realSize->setValueAndWarp(m_geometry.size());
*m_alpha = in ? 1.f : 0.f;
}
if (!in)
fadingOut = true;
m_fadingOut = true;
}
bool CLayerSurface::isFadedOut() {
if (!fadingOut)
if (!m_fadingOut)
return false;
return !realPosition->isBeingAnimated() && !realSize->isBeingAnimated() && !alpha->isBeingAnimated();
return !m_realPosition->isBeingAnimated() && !m_realSize->isBeingAnimated() && !m_alpha->isBeingAnimated();
}
int CLayerSurface::popupsCount() {
if (!layerSurface || !mapped || fadingOut)
if (!m_layerSurface || !m_mapped || m_fadingOut)
return 0;
int no = -1; // we have one dummy
popupHead->breadthfirst([](WP<CPopup> p, void* data) { *(int*)data += 1; }, &no);
m_popupHead->breadthfirst([](WP<CPopup> p, void* data) { *(int*)data += 1; }, &no);
return no;
}
MONITORID CLayerSurface::monitorID() {
return monitor ? monitor->ID : MONITOR_INVALID;
return m_monitor ? m_monitor->ID : MONITOR_INVALID;
}
pid_t CLayerSurface::getPID() {
pid_t PID = -1;
if (!layerSurface || !layerSurface->surface || !layerSurface->surface->getResource() || !layerSurface->surface->getResource()->resource() ||
!layerSurface->surface->getResource()->resource()->client)
if (!m_layerSurface || !m_layerSurface->surface || !m_layerSurface->surface->getResource() || !m_layerSurface->surface->getResource()->resource() ||
!m_layerSurface->surface->getResource()->resource()->client)
return -1;
wl_client_get_credentials(layerSurface->surface->getResource()->resource()->client, &PID, nullptr, nullptr);
wl_client_get_credentials(m_layerSurface->surface->getResource()->resource()->client, &PID, nullptr, nullptr);
return PID;
}

View file

@ -22,44 +22,43 @@ class CLayerSurface {
bool isFadedOut();
int popupsCount();
PHLANIMVAR<Vector2D> realPosition;
PHLANIMVAR<Vector2D> realSize;
PHLANIMVAR<float> alpha;
PHLANIMVAR<Vector2D> m_realPosition;
PHLANIMVAR<Vector2D> m_realSize;
PHLANIMVAR<float> m_alpha;
WP<CLayerShellResource> layerSurface;
wl_list link;
WP<CLayerShellResource> m_layerSurface;
// the header providing the enum type cannot be imported here
int interactivity = 0;
int m_interactivity = 0;
SP<CWLSurface> surface;
SP<CWLSurface> m_surface;
bool mapped = false;
uint32_t layer = 0;
bool m_mapped = false;
uint32_t m_layer = 0;
PHLMONITORREF monitor;
PHLMONITORREF m_monitor;
bool fadingOut = false;
bool readyToDelete = false;
bool noProcess = false;
bool noAnimations = false;
bool m_fadingOut = false;
bool m_readyToDelete = false;
bool m_noProcess = false;
bool m_noAnimations = false;
bool forceBlur = false;
bool forceBlurPopups = false;
int64_t xray = -1;
bool ignoreAlpha = false;
float ignoreAlphaValue = 0.f;
bool dimAround = false;
int64_t order = 0;
bool m_forceBlur = false;
bool m_forceBlurPopups = false;
int64_t m_xray = -1;
bool m_ignoreAlpha = false;
float m_ignoreAlphaValue = 0.f;
bool m_dimAround = false;
int64_t m_order = 0;
std::optional<std::string> animationStyle;
std::optional<std::string> m_animationStyle;
PHLLSREF self;
PHLLSREF m_self;
CBox geometry = {0, 0, 0, 0};
Vector2D position;
std::string szNamespace = "";
UP<CPopup> popupHead;
CBox m_geometry = {0, 0, 0, 0};
Vector2D m_position;
std::string m_namespace = "";
UP<CPopup> m_popupHead;
pid_t getPID();
@ -75,12 +74,12 @@ class CLayerSurface {
CHyprSignalListener map;
CHyprSignalListener unmap;
CHyprSignalListener commit;
} listeners;
} m_listeners;
void registerCallbacks();
// For the list lookup
bool operator==(const CLayerSurface& rhs) const {
return layerSurface == rhs.layerSurface && monitor == rhs.monitor;
return m_layerSurface == rhs.m_layerSurface && m_monitor == rhs.m_monitor;
}
};

View file

@ -13,32 +13,32 @@
#include <ranges>
UP<CPopup> CPopup::create(PHLWINDOW pOwner) {
auto popup = UP<CPopup>(new CPopup());
popup->m_pWindowOwner = pOwner;
popup->m_pSelf = popup;
auto popup = UP<CPopup>(new CPopup());
popup->m_windowOwner = pOwner;
popup->m_self = popup;
popup->initAllSignals();
return popup;
}
UP<CPopup> CPopup::create(PHLLS pOwner) {
auto popup = UP<CPopup>(new CPopup());
popup->m_pLayerOwner = pOwner;
popup->m_pSelf = popup;
auto popup = UP<CPopup>(new CPopup());
popup->m_layerOwner = pOwner;
popup->m_self = popup;
popup->initAllSignals();
return popup;
}
UP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) {
auto popup = UP<CPopup>(new CPopup());
popup->m_pResource = resource;
popup->m_pWindowOwner = pOwner->m_pWindowOwner;
popup->m_pLayerOwner = pOwner->m_pLayerOwner;
popup->m_pParent = pOwner;
popup->m_pSelf = popup;
popup->m_pWLSurface = CWLSurface::create();
popup->m_pWLSurface->assign(resource->surface->surface.lock(), popup.get());
auto popup = UP<CPopup>(new CPopup());
popup->m_resource = resource;
popup->m_windowOwner = pOwner->m_windowOwner;
popup->m_layerOwner = pOwner->m_layerOwner;
popup->m_parent = pOwner;
popup->m_self = popup;
popup->m_wlSurface = CWLSurface::create();
popup->m_wlSurface->assign(resource->surface->surface.lock(), popup.get());
popup->m_vLastSize = resource->surface->current.geometry.size();
popup->m_lastSize = resource->surface->current.geometry.size();
popup->reposition();
popup->initAllSignals();
@ -46,104 +46,106 @@ UP<CPopup> CPopup::create(SP<CXDGPopupResource> resource, WP<CPopup> pOwner) {
}
CPopup::~CPopup() {
if (m_pWLSurface)
m_pWLSurface->unassign();
if (m_wlSurface)
m_wlSurface->unassign();
}
void CPopup::initAllSignals() {
if (!m_pResource) {
if (!m_pWindowOwner.expired())
listeners.newPopup = m_pWindowOwner->m_pXDGSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
else if (!m_pLayerOwner.expired())
listeners.newPopup = m_pLayerOwner->layerSurface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
if (!m_resource) {
if (!m_windowOwner.expired())
m_listeners.newPopup =
m_windowOwner->m_pXDGSurface->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)); });
else
ASSERT(false);
return;
}
listeners.reposition = m_pResource->events.reposition.registerListener([this](std::any d) { this->onReposition(); });
listeners.map = m_pResource->surface->events.map.registerListener([this](std::any d) { this->onMap(); });
listeners.unmap = m_pResource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); });
listeners.dismissed = m_pResource->events.dismissed.registerListener([this](std::any d) { this->onUnmap(); });
listeners.destroy = m_pResource->surface->events.destroy.registerListener([this](std::any d) { this->onDestroy(); });
listeners.commit = m_pResource->surface->events.commit.registerListener([this](std::any d) { this->onCommit(); });
listeners.newPopup = m_pResource->surface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
m_listeners.reposition = m_resource->events.reposition.registerListener([this](std::any d) { this->onReposition(); });
m_listeners.map = m_resource->surface->events.map.registerListener([this](std::any d) { this->onMap(); });
m_listeners.unmap = m_resource->surface->events.unmap.registerListener([this](std::any d) { this->onUnmap(); });
m_listeners.dismissed = m_resource->events.dismissed.registerListener([this](std::any d) { this->onUnmap(); });
m_listeners.destroy = m_resource->surface->events.destroy.registerListener([this](std::any d) { this->onDestroy(); });
m_listeners.commit = m_resource->surface->events.commit.registerListener([this](std::any d) { this->onCommit(); });
m_listeners.newPopup = m_resource->surface->events.newPopup.registerListener([this](std::any d) { this->onNewPopup(std::any_cast<SP<CXDGPopupResource>>(d)); });
}
void CPopup::onNewPopup(SP<CXDGPopupResource> popup) {
const auto& POPUP = m_vChildren.emplace_back(CPopup::create(popup, m_pSelf));
POPUP->m_pSelf = POPUP;
const auto& POPUP = m_children.emplace_back(CPopup::create(popup, m_self));
POPUP->m_self = POPUP;
Debug::log(LOG, "New popup at {:x}", (uintptr_t)POPUP);
}
void CPopup::onDestroy() {
m_bInert = true;
m_inert = true;
if (!m_pParent)
if (!m_parent)
return; // head node
std::erase_if(m_pParent->m_vChildren, [this](const auto& other) { return other.get() == this; });
std::erase_if(m_parent->m_children, [this](const auto& other) { return other.get() == this; });
}
void CPopup::onMap() {
if (m_bMapped)
if (m_mapped)
return;
m_bMapped = true;
m_vLastSize = m_pResource->surface->surface->current.size;
m_mapped = true;
m_lastSize = m_resource->surface->surface->current.size;
const auto COORDS = coordsGlobal();
const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS);
CBox box = m_pWLSurface->resource()->extends();
CBox box = m_wlSurface->resource()->extends();
box.translate(COORDS).expand(4);
g_pHyprRenderer->damageBox(box);
m_vLastPos = coordsRelativeToParent();
m_lastPos = coordsRelativeToParent();
g_pInputManager->simulateMouseMovement();
m_pSubsurfaceHead = CSubsurface::create(m_pSelf);
m_subsurfaceHead = CSubsurface::create(m_self);
//unconstrain();
sendScale();
m_pResource->surface->surface->enter(PMONITOR->self.lock());
m_resource->surface->surface->enter(PMONITOR->self.lock());
if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
}
void CPopup::onUnmap() {
if (!m_bMapped)
if (!m_mapped)
return;
if (!m_pResource || !m_pResource->surface) {
if (!m_resource || !m_resource->surface) {
Debug::log(ERR, "CPopup: orphaned (no surface/resource) and unmaps??");
onDestroy();
return;
}
m_bMapped = false;
m_mapped = false;
m_vLastSize = m_pResource->surface->surface->current.size;
m_lastSize = m_resource->surface->surface->current.size;
const auto COORDS = coordsGlobal();
CBox box = m_pWLSurface->resource()->extends();
CBox box = m_wlSurface->resource()->extends();
box.translate(COORDS).expand(4);
g_pHyprRenderer->damageBox(box);
m_pSubsurfaceHead.reset();
m_subsurfaceHead.reset();
if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
// damage all children
breadthfirst(
[](WP<CPopup> p, void* data) {
if (!p->m_pResource)
if (!p->m_resource)
return;
auto box = CBox{p->coordsGlobal(), p->size()};
@ -159,59 +161,59 @@ void CPopup::onUnmap() {
}
void CPopup::onCommit(bool ignoreSiblings) {
if (!m_pResource || !m_pResource->surface) {
if (!m_resource || !m_resource->surface) {
Debug::log(ERR, "CPopup: orphaned (no surface/resource) and commits??");
onDestroy();
return;
}
if (m_pResource->surface->initialCommit) {
m_pResource->surface->scheduleConfigure();
if (m_resource->surface->initialCommit) {
m_resource->surface->scheduleConfigure();
return;
}
if (!m_pWindowOwner.expired() && (!m_pWindowOwner->m_bIsMapped || !m_pWindowOwner->m_pWorkspace->m_bVisible)) {
m_vLastSize = m_pResource->surface->surface->current.size;
if (!m_windowOwner.expired() && (!m_windowOwner->m_bIsMapped || !m_windowOwner->m_pWorkspace->m_bVisible)) {
m_lastSize = m_resource->surface->surface->current.size;
static auto PLOGDAMAGE = CConfigValue<Hyprlang::INT>("debug:log_damage");
if (*PLOGDAMAGE)
Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_pWindowOwner.lock());
Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_windowOwner.lock());
return;
}
if (!m_pResource->surface->mapped)
if (!m_resource->surface->mapped)
return;
const auto COORDS = coordsGlobal();
const auto COORDSLOCAL = coordsRelativeToParent();
if (m_vLastSize != m_pResource->surface->surface->current.size || m_bRequestedReposition || m_vLastPos != COORDSLOCAL) {
CBox box = {localToGlobal(m_vLastPos), m_vLastSize};
if (m_lastSize != m_resource->surface->surface->current.size || m_requestedReposition || m_lastPos != COORDSLOCAL) {
CBox box = {localToGlobal(m_lastPos), m_lastSize};
g_pHyprRenderer->damageBox(box);
m_vLastSize = m_pResource->surface->surface->current.size;
box = {COORDS, m_vLastSize};
m_lastSize = m_resource->surface->surface->current.size;
box = {COORDS, m_lastSize};
g_pHyprRenderer->damageBox(box);
m_vLastPos = COORDSLOCAL;
m_lastPos = COORDSLOCAL;
}
if (!ignoreSiblings && m_pSubsurfaceHead)
m_pSubsurfaceHead->recheckDamageForSubsurfaces();
if (!ignoreSiblings && m_subsurfaceHead)
m_subsurfaceHead->recheckDamageForSubsurfaces();
g_pHyprRenderer->damageSurface(m_pWLSurface->resource(), COORDS.x, COORDS.y);
g_pHyprRenderer->damageSurface(m_wlSurface->resource(), COORDS.x, COORDS.y);
m_bRequestedReposition = false;
m_requestedReposition = false;
if (!m_pLayerOwner.expired() && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer));
if (!m_layerOwner.expired() && m_layerOwner->m_layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP)
g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_layerOwner->m_layer));
}
void CPopup::onReposition() {
Debug::log(LOG, "Popup {:x} requests reposition", (uintptr_t)this);
m_bRequestedReposition = true;
m_requestedReposition = true;
m_vLastPos = coordsRelativeToParent();
m_lastPos = coordsRelativeToParent();
reposition();
}
@ -224,31 +226,31 @@ void CPopup::reposition() {
return;
CBox box = {PMONITOR->vecPosition.x, PMONITOR->vecPosition.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y};
m_pResource->applyPositioning(box, COORDS);
m_resource->applyPositioning(box, COORDS);
}
SP<CWLSurface> CPopup::getT1Owner() {
if (m_pWindowOwner)
return m_pWindowOwner->m_pWLSurface;
if (m_windowOwner)
return m_windowOwner->m_pWLSurface;
else
return m_pLayerOwner->surface;
return m_layerOwner->m_surface;
}
Vector2D CPopup::coordsRelativeToParent() {
Vector2D offset;
if (!m_pResource)
if (!m_resource)
return {};
WP<CPopup> current = m_pSelf;
offset -= current->m_pResource->surface->current.geometry.pos();
WP<CPopup> current = m_self;
offset -= current->m_resource->surface->current.geometry.pos();
while (current->m_pParent && current->m_pResource) {
while (current->m_parent && current->m_resource) {
offset += current->m_pWLSurface->resource()->current.offset;
offset += current->m_pResource->geometry.pos();
offset += current->m_wlSurface->resource()->current.offset;
offset += current->m_resource->geometry.pos();
current = current->m_pParent;
current = current->m_parent;
}
return offset;
@ -263,30 +265,30 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) {
}
Vector2D CPopup::t1ParentCoords() {
if (!m_pWindowOwner.expired())
return m_pWindowOwner->m_vRealPosition->value();
if (!m_pLayerOwner.expired())
return m_pLayerOwner->realPosition->value();
if (!m_windowOwner.expired())
return m_windowOwner->m_vRealPosition->value();
if (!m_layerOwner.expired())
return m_layerOwner->m_realPosition->value();
ASSERT(false);
return {};
}
void CPopup::recheckTree() {
WP<CPopup> curr = m_pSelf;
while (curr->m_pParent) {
curr = curr->m_pParent;
WP<CPopup> curr = m_self;
while (curr->m_parent) {
curr = curr->m_parent;
}
curr->recheckChildrenRecursive();
}
void CPopup::recheckChildrenRecursive() {
if (m_bInert || !m_pWLSurface)
if (m_inert || !m_wlSurface)
return;
std::vector<WP<CPopup>> cpy;
std::ranges::for_each(m_vChildren, [&cpy](const auto& el) { cpy.emplace_back(el); });
std::ranges::for_each(m_children, [&cpy](const auto& el) { cpy.emplace_back(el); });
for (auto const& c : cpy) {
c->onCommit(true);
c->recheckChildrenRecursive();
@ -294,25 +296,25 @@ void CPopup::recheckChildrenRecursive() {
}
Vector2D CPopup::size() {
return m_vLastSize;
return m_lastSize;
}
void CPopup::sendScale() {
if (!m_pWindowOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_pWLSurface->resource(), m_pWindowOwner->m_pWLSurface->m_fLastScale);
else if (!m_pLayerOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_pWLSurface->resource(), m_pLayerOwner->surface->m_fLastScale);
if (!m_windowOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_windowOwner->m_pWLSurface->m_fLastScale);
else if (!m_layerOwner.expired())
g_pCompositor->setPreferredScaleForSurface(m_wlSurface->resource(), m_layerOwner->m_surface->m_fLastScale);
else
UNREACHABLE();
}
bool CPopup::visible() {
if (!m_pWindowOwner.expired())
return g_pHyprRenderer->shouldRenderWindow(m_pWindowOwner.lock());
if (!m_pLayerOwner.expired())
if (!m_windowOwner.expired())
return g_pHyprRenderer->shouldRenderWindow(m_windowOwner.lock());
if (!m_layerOwner.expired())
return true;
if (m_pParent)
return m_pParent->visible();
if (m_parent)
return m_parent->visible();
return false;
}
@ -326,8 +328,8 @@ void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(W
nodes2.reserve(nodes.size() * 2);
for (auto const& n : nodes) {
for (auto const& c : n->m_vChildren) {
nodes2.push_back(c->m_pSelf);
for (auto const& c : n->m_children) {
nodes2.push_back(c->m_self);
}
}
@ -337,7 +339,7 @@ void CPopup::bfHelper(std::vector<WP<CPopup>> const& nodes, std::function<void(W
void CPopup::breadthfirst(std::function<void(WP<CPopup>, void*)> fn, void* data) {
std::vector<WP<CPopup>> popups;
popups.push_back(m_pSelf);
popups.push_back(m_self);
bfHelper(popups, fn, data);
}
@ -346,14 +348,14 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
breadthfirst([&popups](WP<CPopup> popup, void* data) { popups.push_back(popup); }, &popups);
for (auto const& p : popups | std::views::reverse) {
if (!p->m_pResource || !p->m_bMapped)
if (!p->m_resource || !p->m_mapped)
continue;
if (!allowsInput) {
const bool HASSURFACE = p->m_pResource && p->m_pResource->surface;
const bool HASSURFACE = p->m_resource && p->m_resource->surface;
Vector2D offset = HASSURFACE ? p->m_pResource->surface->current.geometry.pos() : Vector2D{};
Vector2D size = HASSURFACE ? p->m_pResource->surface->current.geometry.size() : p->size();
Vector2D offset = HASSURFACE ? p->m_resource->surface->current.geometry.pos() : Vector2D{};
Vector2D size = HASSURFACE ? p->m_resource->surface->current.geometry.size() : p->size();
if (size == Vector2D{})
size = p->size();
@ -362,7 +364,7 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
if (BOX.containsPoint(globalCoords))
return p;
} else {
const auto REGION = CRegion{p->m_pWLSurface->resource()->current.input}.intersect(CBox{{}, p->m_pWLSurface->resource()->current.size}).translate(p->coordsGlobal());
const auto REGION = CRegion{p->m_wlSurface->resource()->current.input}.intersect(CBox{{}, p->m_wlSurface->resource()->current.size}).translate(p->coordsGlobal());
if (REGION.containsPoint(globalCoords))
return p;
}
@ -372,5 +374,5 @@ WP<CPopup> CPopup::at(const Vector2D& globalCoords, bool allowsInput) {
}
bool CPopup::inert() const {
return m_bInert;
return m_inert;
}

View file

@ -41,32 +41,32 @@ class CPopup {
WP<CPopup> at(const Vector2D& globalCoords, bool allowsInput = false);
//
SP<CWLSurface> m_pWLSurface;
WP<CPopup> m_pSelf;
bool m_bMapped = false;
SP<CWLSurface> m_wlSurface;
WP<CPopup> m_self;
bool m_mapped = false;
private:
CPopup() = default;
// T1 owners, each popup has to have one of these
PHLWINDOWREF m_pWindowOwner;
PHLLSREF m_pLayerOwner;
PHLWINDOWREF m_windowOwner;
PHLLSREF m_layerOwner;
// T2 owners
WP<CPopup> m_pParent;
WP<CPopup> m_parent;
WP<CXDGPopupResource> m_pResource;
WP<CXDGPopupResource> m_resource;
Vector2D m_vLastSize = {};
Vector2D m_vLastPos = {};
Vector2D m_lastSize = {};
Vector2D m_lastPos = {};
bool m_bRequestedReposition = false;
bool m_requestedReposition = false;
bool m_bInert = false;
bool m_inert = false;
//
std::vector<UP<CPopup>> m_vChildren;
UP<CSubsurface> m_pSubsurfaceHead;
std::vector<UP<CPopup>> m_children;
UP<CSubsurface> m_subsurfaceHead;
struct {
CHyprSignalListener newPopup;
@ -76,7 +76,7 @@ class CPopup {
CHyprSignalListener commit;
CHyprSignalListener dismissed;
CHyprSignalListener reposition;
} listeners;
} m_listeners;
void initAllSignals();
void reposition();

View file

@ -22,7 +22,7 @@ UP<CSubsurface> CSubsurface::create(WP<CPopup> pOwner) {
subsurface->m_pPopupParent = pOwner;
subsurface->m_pSelf = subsurface;
subsurface->initSignals();
subsurface->initExistingSubsurfaces(pOwner->m_pWLSurface->resource());
subsurface->initExistingSubsurfaces(pOwner->m_wlSurface->resource());
return subsurface;
}
@ -63,7 +63,7 @@ void CSubsurface::initSignals() {
listeners.newSubsurface = m_pWindowParent->m_pWLSurface->resource()->events.newSubsurface.registerListener(
[this](std::any d) { onNewSubsurface(std::any_cast<SP<CWLSubsurfaceResource>>(d)); });
else if (m_pPopupParent)
listeners.newSubsurface = m_pPopupParent->m_pWLSurface->resource()->events.newSubsurface.registerListener(
listeners.newSubsurface = m_pPopupParent->m_wlSurface->resource()->events.newSubsurface.registerListener(
[this](std::any d) { onNewSubsurface(std::any_cast<SP<CWLSubsurfaceResource>>(d)); });
else
ASSERT(false);
@ -107,7 +107,7 @@ void CSubsurface::onCommit() {
g_pHyprRenderer->damageSurface(m_pWLSurface->resource(), COORDS.x, COORDS.y);
if (m_pPopupParent && !m_pPopupParent->inert() && m_pPopupParent->m_pWLSurface)
if (m_pPopupParent && !m_pPopupParent->inert() && m_pPopupParent->m_wlSurface)
m_pPopupParent->recheckTree();
if (!m_pWindowParent.expired()) // I hate you firefox why are you doing this
m_pWindowParent->m_pPopupHead->recheckTree();

View file

@ -190,7 +190,7 @@ std::optional<CBox> CWLSurface::getSurfaceBoxGlobal() const {
if (!m_pWindowOwner.expired())
return m_pWindowOwner->getWindowMainSurfaceBox();
if (!m_pLayerOwner.expired())
return m_pLayerOwner->geometry;
return m_pLayerOwner->m_geometry;
if (m_pPopupOwner)
return CBox{m_pPopupOwner->coordsGlobal(), m_pPopupOwner->size()};
if (m_pSubsurfaceOwner)
@ -228,7 +228,7 @@ SP<CWLSurface> CWLSurface::fromResource(SP<CWLSurfaceResource> pSurface) {
bool CWLSurface::keyboardFocusable() const {
if (m_pWindowOwner || m_pPopupOwner || m_pSubsurfaceOwner)
return true;
if (m_pLayerOwner && m_pLayerOwner->layerSurface)
return m_pLayerOwner->layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
if (m_pLayerOwner && m_pLayerOwner->m_layerSurface)
return m_pLayerOwner->m_layerSurface->current.interactivity != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE;
return false;
}

View file

@ -162,7 +162,7 @@ SBoxExtents CWindow::getFullWindowExtents() {
// TODO: this could be better, perhaps make a getFullWindowRegion?
m_pPopupHead->breadthfirst(
[](WP<CPopup> popup, void* data) {
if (!popup->m_pWLSurface || !popup->m_pWLSurface->resource())
if (!popup->m_wlSurface || !popup->m_wlSurface->resource())
return;
CBox* pSurfaceExtents = (CBox*)data;
@ -870,7 +870,7 @@ bool CWindow::hasPopupAt(const Vector2D& pos) {
auto popup = m_pPopupHead->at(pos);
return popup && popup->m_pWLSurface->resource();
return popup && popup->m_wlSurface->resource();
}
void CWindow::applyGroupRules() {