From c198d744b77f272c2fc187eb6d431580a99ab6c3 Mon Sep 17 00:00:00 2001 From: JManch <61563764+JManch@users.noreply.github.com> Date: Wed, 28 Feb 2024 00:52:45 +0000 Subject: [PATCH 0001/2897] keybinds: unconstrain mouse on focusmonitor and cyclenext (#4863) --- src/managers/KeybindManager.cpp | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 481b8987..58425757 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -234,6 +234,7 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); const auto PNEWMAINWORKSPACE = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace); + g_pInputManager->unconstrainMouse(); g_pCompositor->setActiveMonitor(monitor); PNEWMAINWORKSPACE->rememberPrevWorkspace(PWORKSPACE); @@ -257,6 +258,9 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) { if (PWINDOWTOCHANGETO == PLASTWINDOW || !PWINDOWTOCHANGETO) return; + // remove constraints + g_pInputManager->unconstrainMouse(); + if (PLASTWINDOW && PLASTWINDOW->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && PLASTWINDOW->m_bIsFullscreen) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PLASTWINDOW->m_iWorkspaceID); const auto FSMODE = PWORKSPACE->m_efFullscreenMode; @@ -1121,9 +1125,6 @@ void CKeybindManager::moveFocusTo(std::string args) { return; } - // remove constraints - g_pInputManager->unconstrainMouse(); - const auto PWINDOWTOCHANGETO = **PFULLCYCLE && PLASTWINDOW->m_bIsFullscreen ? (arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) : g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); @@ -1158,9 +1159,6 @@ void CKeybindManager::focusUrgentOrLast(std::string args) { if (!PWINDOWURGENT && !PWINDOWPREV) return; - // remove constraints - g_pInputManager->unconstrainMouse(); - switchToWindow(PWINDOWURGENT ? PWINDOWURGENT : PWINDOWPREV); } @@ -1171,9 +1169,6 @@ void CKeybindManager::focusCurrentOrLast(std::string args) { if (!PWINDOWPREV) return; - // remove constraints - g_pInputManager->unconstrainMouse(); - switchToWindow(PWINDOWPREV); } From f4f3aa2e505ca1b22688fb4a32f31c4bfb851dd0 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 28 Feb 2024 11:45:43 +0000 Subject: [PATCH 0002/2897] layout: add size prediction for initial xdg commits fixes #4022 --- src/events/Windows.cpp | 4 ++- src/layout/DwindleLayout.cpp | 66 +++++++++++++++++++++++++++++++----- src/layout/DwindleLayout.hpp | 1 + src/layout/IHyprLayout.cpp | 4 +++ src/layout/IHyprLayout.hpp | 6 ++++ src/layout/MasterLayout.cpp | 27 +++++++++++++++ src/layout/MasterLayout.hpp | 1 + 7 files changed, 100 insertions(+), 9 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 81c5c800..d6241fa4 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -806,7 +806,9 @@ void Events::listener_commitWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; if (!PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xdg->initial_commit) { - wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, 0, 0); + const auto PREDSIZE = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); + Debug::log(LOG, "Layout predicts size {} for {}", PREDSIZE, PWINDOW); + wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, PREDSIZE.x, PREDSIZE.y); return; } diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 0f4a5f87..2bb6e4c3 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -127,7 +127,13 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for const auto PWINDOW = pNode->pWindow; // get specific gaps and rules for this workspace, // if user specified them in config - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)); + const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID)); + + if (!g_pCompositor->windowExists(PWINDOW)) { + Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); + onWindowRemovedTiling(PWINDOW); + return; + } if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks) return; @@ -143,13 +149,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); - if (!g_pCompositor->windowExists(PWINDOW) || !PWINDOW->m_bIsMapped) { - Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); - onWindowRemovedTiling(PWINDOW); - return; - } - - CBox nodeBox = pNode->box; + CBox nodeBox = pNode->box; nodeBox.round(); PWINDOW->m_vSize = nodeBox.size(); @@ -1093,3 +1093,53 @@ void CHyprDwindleLayout::onEnable() { void CHyprDwindleLayout::onDisable() { m_lDwindleNodesData.clear(); } + +Vector2D CHyprDwindleLayout::predictSizeForNewWindow() { + if (!g_pCompositor->m_pLastMonitor) + return {}; + + // get window candidate + CWindow* candidate = g_pCompositor->m_pLastWindow; + + if (!candidate) + candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + + // create a fake node + SDwindleNodeData node; + + if (!candidate) + return g_pCompositor->m_pLastMonitor->vecSize; + else { + const auto PNODE = getNodeFromWindow(candidate); + + if (!PNODE) + return {}; + + node = *PNODE; + node.pWindow = nullptr; + + CBox box = PNODE->box; + + static auto* const PSMARTSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_split"); + static auto* const PPRESERVESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:preserve_split"); + static auto* const PFLMULT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier"); + + bool splitTop = false; + + if (**PPRESERVESPLIT == 0 && **PSMARTSPLIT == 0) + splitTop = box.h * **PFLMULT > box.w; + + const auto SPLITSIDE = !splitTop; + + if (SPLITSIDE) + node.box = {{}, {box.w / 2.0, box.h}}; + else + node.box = {{}, {box.w, box.h / 2.0}}; + + // TODO: make this better and more accurate + + return node.box.size(); + } + + return {}; +} diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index f5501b28..fc73540a 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -59,6 +59,7 @@ class CHyprDwindleLayout : public IHyprLayout { virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); + virtual Vector2D predictSizeForNewWindow(); virtual void onEnable(); virtual void onDisable(); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 49e20435..16474056 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -593,4 +593,8 @@ void IHyprLayout::requestFocusForWindow(CWindow* pWindow) { g_pCompositor->focusWindow(pWindow); } +Vector2D IHyprLayout::predictSizeForNewWindow() { + return Vector2D{}; +} + IHyprLayout::~IHyprLayout() {} diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index 5c74078e..ffe004bc 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -181,6 +181,12 @@ class IHyprLayout { */ virtual void requestFocusForWindow(CWindow*); + /* + Called to predict the size of a newly opened window to send it a configure. + Return 0,0 if unpredictable + */ + virtual Vector2D predictSizeForNewWindow(); + private: Vector2D m_vBeginDragXY; Vector2D m_vLastDragXY; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 6a3cd492..1a488b0d 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -1459,6 +1459,33 @@ void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) { applyNodeDataToWindow(PNODE); } +Vector2D CHyprMasterLayout::predictSizeForNewWindow() { + static auto* const PNEWISMASTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_is_master"); + + if (!g_pCompositor->m_pLastMonitor) + return {}; + + const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + + if (NODES <= 0) + return g_pCompositor->m_pLastMonitor->vecSize; + + const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + if (!MASTER) // wtf + return {}; + + if (*PNEWISMASTER) { + return MASTER->size; + } else { + const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + + // TODO: make this better + return {g_pCompositor->m_pLastMonitor->vecSize.x - MASTER->size.x, g_pCompositor->m_pLastMonitor->vecSize.y / (SLAVES + 1)}; + } + + return {}; +} + void CHyprMasterLayout::onEnable() { for (auto& w : g_pCompositor->m_vWindows) { if (w->m_bIsFloating || !w->m_bIsMapped || w->isHidden()) diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index e316556a..d48aefdc 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -65,6 +65,7 @@ class CHyprMasterLayout : public IHyprLayout { virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); + virtual Vector2D predictSizeForNewWindow(); virtual void onEnable(); virtual void onDisable(); From 4bc669f9331bb66ab30bd705d09f1239bc3e83ed Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 15:00:34 +0000 Subject: [PATCH 0003/2897] layers: add fully featured animations Adds configs and layerrules to handle them alas fixes #981 I have cooked --- src/Compositor.cpp | 2 +- src/config/ConfigManager.cpp | 5 +- src/events/Layers.cpp | 18 +---- src/helpers/WLClasses.cpp | 123 +++++++++++++++++++++++++++++- src/helpers/WLClasses.hpp | 37 +++++---- src/managers/AnimationManager.cpp | 23 +++++- src/render/OpenGL.cpp | 15 +++- src/render/OpenGL.hpp | 2 +- src/render/Renderer.cpp | 14 +++- 9 files changed, 197 insertions(+), 42 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f0d7ca0f..48ac0e1c 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1480,7 +1480,7 @@ void CCompositor::cleanupFadingOut(const int& monid) { if (ls->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || ls->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) g_pHyprOpenGL->markBlurDirtyForMonitor(getMonitorFromID(monid)); - if (ls->fadingOut && ls->readyToDelete && !ls->alpha.isBeingAnimated()) { + if (ls->fadingOut && ls->readyToDelete && ls->isFadedOut()) { for (auto& m : m_vMonitors) { for (auto& lsl : m->m_aLayerSurfaceLayers) { if (!lsl.empty() && std::find_if(lsl.begin(), lsl.end(), [&](std::unique_ptr& other) { return other.get() == ls; }) != lsl.end()) { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 5cb18e0f..151347ad 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -617,6 +617,7 @@ void CConfigManager::setDefaultAnimationVars() { if (isFirstLaunch) { INITANIMCFG("global"); INITANIMCFG("windows"); + INITANIMCFG("layers"); INITANIMCFG("fade"); INITANIMCFG("border"); INITANIMCFG("borderangle"); @@ -644,6 +645,7 @@ void CConfigManager::setDefaultAnimationVars() { animationConfig["global"] = {false, "default", "", 8.f, 1, &animationConfig["general"], nullptr}; CREATEANIMCFG("windows", "global"); + CREATEANIMCFG("layers", "global"); CREATEANIMCFG("fade", "global"); CREATEANIMCFG("border", "global"); CREATEANIMCFG("borderangle", "global"); @@ -658,6 +660,7 @@ void CConfigManager::setDefaultAnimationVars() { CREATEANIMCFG("fadeSwitch", "fade"); CREATEANIMCFG("fadeShadow", "fade"); CREATEANIMCFG("fadeDim", "fade"); + CREATEANIMCFG("fadeLayers", "fade"); CREATEANIMCFG("specialWorkspace", "workspaces"); } @@ -1840,7 +1843,7 @@ bool windowRuleValid(const std::string& RULE) { } bool layerRuleValid(const std::string& RULE) { - return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray"); + return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray") || RULE.starts_with("animation"); } std::optional CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 9ef9b025..1b76c536 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -113,9 +113,6 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { layersurface->keyboardExclusive = layersurface->layerSurface->current.keyboard_interactive; layersurface->surface = layersurface->layerSurface->surface; - // anim - layersurface->alpha.setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeIn")); - // fix if it changed its mon const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layersurface->layerSurface->output); @@ -166,8 +163,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { const auto WORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); const bool FULLSCREEN = WORKSPACE->m_bHasFullscreenWindow && WORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL; - layersurface->alpha.setValue(0); - layersurface->alpha = ((layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && FULLSCREEN && !GRABSFOCUS) ? 0.f : 1.f); + layersurface->startAnimation(!(layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && FULLSCREEN && !GRABSFOCUS)); layersurface->readyToDelete = false; layersurface->fadingOut = false; @@ -198,23 +194,17 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { layersurface->mapped = false; - layersurface->fadingOut = true; - - layersurface->alpha.setValueAndWarp(0.f); + layersurface->startAnimation(false); return; } - // anim - layersurface->alpha.setConfig(g_pConfigManager->getAnimationPropertyConfig("fadeOut")); - // make a snapshot and start fade g_pHyprOpenGL->makeLayerSnapshot(layersurface); - layersurface->alpha = 0.f; + + layersurface->startAnimation(false); layersurface->mapped = false; - layersurface->fadingOut = true; - g_pCompositor->addToFadingOutSafe(layersurface); const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layersurface->layerSurface->output); diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 960145b9..3abcf0a5 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -3,9 +3,17 @@ #include "../Compositor.hpp" SLayerSurface::SLayerSurface() { - alpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_ENTIRE); - alpha.m_pLayer = this; + alpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeLayers"), nullptr, AVARDAMAGE_ENTIRE); + realPosition.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); + realSize.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); + alpha.m_pLayer = this; + realPosition.m_pLayer = this; + realSize.m_pLayer = this; alpha.registerVar(); + realPosition.registerVar(); + realSize.registerVar(); + + alpha.setValueAndWarp(0.f); } SLayerSurface::~SLayerSurface() { @@ -22,6 +30,7 @@ void SLayerSurface::applyRules() { ignoreAlpha = false; ignoreAlphaValue = 0.f; xray = -1; + animationStyle.reset(); for (auto& rule : g_pConfigManager->getMatchingRules(this)) { if (rule.rule == "noanim") @@ -44,10 +53,120 @@ void SLayerSurface::applyRules() { try { xray = configStringToInt(vars[1]); } catch (...) {} + } else if (rule.rule.starts_with("animation")) { + CVarList vars{rule.rule, 0, 's'}; + animationStyle = vars[1]; } } } +void SLayerSurface::startAnimation(bool in, bool instant) { + const auto ANIMSTYLE = animationStyle.value_or(realPosition.m_pConfig->pValues->internalStyle); + + if (ANIMSTYLE == "slide") { + // get closest edge + const auto MIDDLE = geometry.middle(); + + const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE); + + const std::array edgePoints = { + PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x / 2, 0}, + PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x / 2, PMONITOR->vecSize.y}, + PMONITOR->vecPosition + Vector2D{0, PMONITOR->vecSize.y}, + PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x, PMONITOR->vecSize.y / 2}, + }; + + float closest = std::numeric_limits::max(); + size_t leader = 0; + for (size_t i = 0; i < 4; ++i) { + float dist = MIDDLE.distance(edgePoints[i]); + if (dist < closest) { + leader = i; + closest = dist; + } + } + + realSize.setValueAndWarp(geometry.size()); + alpha.setValueAndWarp(1.f); + + Vector2D prePos; + + switch (leader) { + case 0: + // TOP + prePos = {geometry.x, PMONITOR->vecPosition.y - geometry.h}; + break; + case 1: + // BOTTOM + prePos = {geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecPosition.y}; + break; + case 2: + // LEFT + prePos = {PMONITOR->vecPosition.x - geometry.w, geometry.y}; + break; + case 3: + // RIGHT + prePos = {PMONITOR->vecPosition.x + PMONITOR->vecSize.x, geometry.y}; + break; + default: UNREACHABLE(); + } + + if (in) { + realPosition.setValueAndWarp(prePos); + realPosition = geometry.pos(); + } else { + realPosition.setValueAndWarp(geometry.pos()); + realPosition = prePos; + } + + } else if (ANIMSTYLE.starts_with("popin")) { + float minPerc = 0.f; + if (ANIMSTYLE.find("%") != std::string::npos) { + try { + auto percstr = ANIMSTYLE.substr(ANIMSTYLE.find_last_of(' ')); + minPerc = std::stoi(percstr.substr(0, percstr.length() - 1)); + } catch (std::exception& e) { + ; // oops + } + } + + minPerc *= 0.01; + + const auto GOALSIZE = (geometry.size() * minPerc).clamp({5, 5}); + const auto GOALPOS = geometry.pos() + (geometry.size() - GOALSIZE) / 2.f; + + alpha.setValueAndWarp(in ? 0.f : 1.f); + alpha = in ? 1.f : 0.f; + + if (in) { + realSize.setValueAndWarp(GOALSIZE); + realPosition.setValueAndWarp(GOALPOS); + realSize = geometry.size(); + realPosition = geometry.pos(); + } else { + realSize.setValueAndWarp(geometry.size()); + realPosition.setValueAndWarp(geometry.pos()); + realSize = GOALSIZE; + realPosition = GOALPOS; + } + } else { + // fade + realPosition.setValueAndWarp(geometry.pos()); + realSize.setValueAndWarp(geometry.size()); + alpha = in ? 1.f : 0.f; + } + + if (!in) + fadingOut = true; +} + +bool SLayerSurface::isFadedOut() { + if (!fadingOut) + return false; + + return !realPosition.isBeingAnimated() && !realSize.isBeingAnimated() && !alpha.isBeingAnimated(); +} + CRegion SConstraint::getLogicCoordsRegion() { CRegion result; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 6cc9b5d5..b62a6489 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -19,6 +19,11 @@ struct SLayerSurface { ~SLayerSurface(); void applyRules(); + void startAnimation(bool in, bool instant = false); + bool isFadedOut(); + + CAnimatedVariable realPosition; + CAnimatedVariable realSize; wlr_layer_surface_v1* layerSurface; wl_list link; @@ -34,26 +39,28 @@ struct SLayerSurface { DYNLISTENER(commitLayerSurface); DYNLISTENER(newPopup); - CBox geometry = {0, 0, 0, 0}; - Vector2D position; - zwlr_layer_shell_v1_layer layer; + CBox geometry = {0, 0, 0, 0}; + Vector2D position; + zwlr_layer_shell_v1_layer layer; - bool mapped = false; + bool mapped = false; - int monitorID = -1; + int monitorID = -1; - std::string szNamespace = ""; + std::string szNamespace = ""; - CAnimatedVariable alpha; - bool fadingOut = false; - bool readyToDelete = false; - bool noProcess = false; - bool noAnimations = false; + CAnimatedVariable alpha; + bool fadingOut = false; + bool readyToDelete = false; + bool noProcess = false; + bool noAnimations = false; - bool forceBlur = false; - int xray = -1; - bool ignoreAlpha = false; - float ignoreAlphaValue = 0.f; + bool forceBlur = false; + int xray = -1; + bool ignoreAlpha = false; + float ignoreAlphaValue = 0.f; + + std::optional animationStyle; // For the list lookup bool operator==(const SLayerSurface& rhs) const { diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 23584827..859e3b03 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -101,7 +101,7 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(w.get()); } } else if (PLAYER) { - WLRBOXPREV = PLAYER->geometry; + WLRBOXPREV = CBox{PLAYER->realPosition.vec(), PLAYER->realSize.vec()}; PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f); if (!PMONITOR) continue; @@ -513,6 +513,27 @@ std::string CAnimationManager::styleValidInConfigVar(const std::string& config, if (style == "loop" || style == "once") return ""; return "unknown style"; + } else if (config.starts_with("layers")) { + if (style == "fade" || style == "" || style == "slide") + return ""; + else if (style.starts_with("popin")) { + // try parsing + float minPerc = 0.f; + if (style.find("%") != std::string::npos) { + try { + auto percstr = style.substr(style.find_last_of(' ')); + minPerc = std::stoi(percstr.substr(0, percstr.length() - 1)); + } catch (std::exception& e) { return "invalid minperc"; } + + return ""; + } + + minPerc; // fix warning + + return ""; + } + return ""; + return "unknown style"; } else { return "animation has no styles"; } diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 1a53ec39..90e92e25 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1812,13 +1812,22 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) { const auto PMONITOR = g_pCompositor->getMonitorFromID(PLAYER->monitorID); - CBox monbox = {0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; + CBox layerBox; + // some mafs to figure out the correct box + // the originalClosedPos is relative to the monitor's pos + Vector2D scaleXY = Vector2D((PMONITOR->scale * PLAYER->realSize.vec().x / (PLAYER->geometry.w * PMONITOR->scale)), + (PMONITOR->scale * PLAYER->realSize.vec().y / (PLAYER->geometry.h * PMONITOR->scale))); - CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; + layerBox.width = PMONITOR->vecTransformedSize.x * scaleXY.x; + layerBox.height = PMONITOR->vecTransformedSize.y * scaleXY.y; + layerBox.x = ((PLAYER->realPosition.vec().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - (((PLAYER->geometry.x - PMONITOR->vecPosition.x) * PMONITOR->scale) * scaleXY.x); + layerBox.y = ((PLAYER->realPosition.vec().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - (((PLAYER->geometry.y - PMONITOR->vecPosition.y) * PMONITOR->scale) * scaleXY.y); + + CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; m_bEndFrame = true; - renderTextureInternalWithDamage(it->second.m_cTex, &monbox, PLAYER->alpha.fl(), &fakeDamage, 0); + renderTextureInternalWithDamage(it->second.m_cTex, &layerBox, PLAYER->alpha.fl(), &fakeDamage, 0); m_bEndFrame = false; } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 1e43333b..f6dff805 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -112,7 +112,7 @@ struct SCurrentRenderData { Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1); Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1); - CBox clipBox = {}; + CBox clipBox = {}; // scaled coordinates uint32_t discardMode = DISCARD_OPAQUE; float discardOpacity = 0.f; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 1c3aaab0..68803a4a 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -606,15 +606,20 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times TRACY_GPU_ZONE("RenderLayer"); - SRenderData renderdata = {pMonitor, time, pLayer->geometry.x, pLayer->geometry.y}; + const auto REALPOS = pLayer->realPosition.vec(); + const auto REALSIZ = pLayer->realSize.vec(); + + SRenderData renderdata = {pMonitor, time, REALPOS.x, REALPOS.y}; renderdata.fadeAlpha = pLayer->alpha.fl(); renderdata.blur = pLayer->forceBlur; renderdata.surface = pLayer->layerSurface->surface; renderdata.decorate = false; - renderdata.w = pLayer->geometry.width; - renderdata.h = pLayer->geometry.height; + renderdata.w = REALSIZ.x; + renderdata.h = REALSIZ.y; renderdata.blockBlurOptimization = pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM || pLayer->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND; + g_pHyprOpenGL->m_RenderData.clipBox = CBox{0, 0, pMonitor->vecSize.x, pMonitor->vecSize.y}.scale(pMonitor->scale); + g_pHyprOpenGL->m_pCurrentLayer = pLayer; if (pLayer->ignoreAlpha) { @@ -629,7 +634,8 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times renderdata.popup = true; wlr_layer_surface_v1_for_each_popup_surface(pLayer->layerSurface, renderSurface, &renderdata); - g_pHyprOpenGL->m_pCurrentLayer = nullptr; + g_pHyprOpenGL->m_pCurrentLayer = nullptr; + g_pHyprOpenGL->m_RenderData.clipBox = {}; } void CHyprRenderer::renderIMEPopup(SIMEPopup* pPopup, CMonitor* pMonitor, timespec* time) { From 29cdd7de1f8d99462915540569fbe54f10f609f4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 15:59:45 +0000 Subject: [PATCH 0004/2897] layers: minor fixes for new animations --- src/events/Layers.cpp | 13 +++++++++++++ src/helpers/WLClasses.cpp | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 1b76c536..5e9de8b4 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -325,6 +325,19 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { } } + if (layersurface->realPosition.goalv() != layersurface->geometry.pos()) { + if (layersurface->realPosition.isBeingAnimated()) + layersurface->realPosition = layersurface->geometry.pos(); + else + layersurface->realPosition.setValueAndWarp(layersurface->geometry.pos()); + } + if (layersurface->realSize.goalv() != layersurface->geometry.size()) { + if (layersurface->realSize.isBeingAnimated()) + layersurface->realSize = layersurface->geometry.size(); + else + layersurface->realSize.setValueAndWarp(layersurface->geometry.size()); + } + if (layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) // don't focus if constrained && !layersurface->keyboardExclusive && layersurface->mapped) { diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 3abcf0a5..43bba7c5 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -54,7 +54,7 @@ void SLayerSurface::applyRules() { xray = configStringToInt(vars[1]); } catch (...) {} } else if (rule.rule.starts_with("animation")) { - CVarList vars{rule.rule, 0, 's'}; + CVarList vars{rule.rule, 2, 's'}; animationStyle = vars[1]; } } From 51b1b17fcbb6c13667710a6bebac1003a5231bd2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 17:53:17 +0000 Subject: [PATCH 0005/2897] subsurfaceTree: assign surfaces to a CWLSurface fixes #4872 --- src/helpers/SubsurfaceTree.cpp | 1 + src/helpers/SubsurfaceTree.hpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/helpers/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp index b4ea6d85..9f53e8ad 100644 --- a/src/helpers/SubsurfaceTree.cpp +++ b/src/helpers/SubsurfaceTree.cpp @@ -145,6 +145,7 @@ void Events::listener_newSubsurfaceNode(void* owner, void* data) { const auto PSUBSURFACE = (wlr_subsurface*)data; const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.emplace_back(); + PNEWSUBSURFACE->surface.assign(PSUBSURFACE->surface); Debug::log(LOG, "Added a new subsurface {:x}", (uintptr_t)PSUBSURFACE); diff --git a/src/helpers/SubsurfaceTree.hpp b/src/helpers/SubsurfaceTree.hpp index 7a8b8fb8..811c8f66 100644 --- a/src/helpers/SubsurfaceTree.hpp +++ b/src/helpers/SubsurfaceTree.hpp @@ -36,6 +36,7 @@ struct SSurfaceTreeNode { struct SSubsurface { wlr_subsurface* pSubsurface = nullptr; + CWLSurface surface; SSurfaceTreeNode* pParent = nullptr; SSurfaceTreeNode* pChild = nullptr; From a31433c21511df93e59b1e5b167723a0d2ee2c52 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 18:00:02 +0000 Subject: [PATCH 0006/2897] renderer: damage whole ring on failed commit fixes #4770 --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 68803a4a..4ffdecb4 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1264,7 +1264,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (UNLOCK_SC) wlr_output_lock_software_cursors(pMonitor->output, false); - damageMonitor(pMonitor); + wlr_damage_ring_add_whole(&pMonitor->damage); return; } From 097f561e41e5660333492c1f188199e837742efe Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 19:42:04 +0000 Subject: [PATCH 0007/2897] surfacetree: Revert "subsurfaceTree: assign surfaces to a CWLSurface" This reverts commit 51b1b17fcbb6c13667710a6bebac1003a5231bd2. Crash issues, fixes #4874 --- src/helpers/SubsurfaceTree.cpp | 1 - src/helpers/SubsurfaceTree.hpp | 1 - 2 files changed, 2 deletions(-) diff --git a/src/helpers/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp index 9f53e8ad..b4ea6d85 100644 --- a/src/helpers/SubsurfaceTree.cpp +++ b/src/helpers/SubsurfaceTree.cpp @@ -145,7 +145,6 @@ void Events::listener_newSubsurfaceNode(void* owner, void* data) { const auto PSUBSURFACE = (wlr_subsurface*)data; const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.emplace_back(); - PNEWSUBSURFACE->surface.assign(PSUBSURFACE->surface); Debug::log(LOG, "Added a new subsurface {:x}", (uintptr_t)PSUBSURFACE); diff --git a/src/helpers/SubsurfaceTree.hpp b/src/helpers/SubsurfaceTree.hpp index 811c8f66..7a8b8fb8 100644 --- a/src/helpers/SubsurfaceTree.hpp +++ b/src/helpers/SubsurfaceTree.hpp @@ -36,7 +36,6 @@ struct SSurfaceTreeNode { struct SSubsurface { wlr_subsurface* pSubsurface = nullptr; - CWLSurface surface; SSurfaceTreeNode* pParent = nullptr; SSurfaceTreeNode* pChild = nullptr; From 1e7eb3a5a5419f97b61a3403880b161c85dd7b17 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 28 Feb 2024 23:14:50 +0000 Subject: [PATCH 0008/2897] xdg: check for floating conditions before sending tiled size hint ref #4871 --- src/config/ConfigManager.cpp | 2 +- src/events/Windows.cpp | 23 ++++++++++++++++++++--- src/managers/XWaylandManager.cpp | 16 ++++++++-------- src/managers/XWaylandManager.hpp | 2 +- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 151347ad..716882cf 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -946,7 +946,7 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) { } std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) { - if (!g_pCompositor->windowValidMapped(pWindow)) + if (!g_pCompositor->windowExists(pWindow)) return std::vector(); std::vector returns; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index d6241fa4..6ea0bb0c 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -806,9 +806,26 @@ void Events::listener_commitWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; if (!PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xdg->initial_commit) { - const auto PREDSIZE = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); - Debug::log(LOG, "Layout predicts size {} for {}", PREDSIZE, PWINDOW); - wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, PREDSIZE.x, PREDSIZE.y); + Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); + + if (g_pXWaylandManager->shouldBeFloated(PWINDOW, true)) + predSize = {}; + + Vector2D maxSize = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->pending.max_width, PWINDOW->m_uSurface.xdg->toplevel->pending.max_height}; + + if ((maxSize.x > 0 && maxSize.x < predSize.x) || (maxSize.y > 0 && maxSize.y < predSize.y)) + predSize = {}; + + for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW)) { + if (r.szRule == "float") { + predSize = {}; + break; + } + } + + Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW); + + wlr_xdg_toplevel_set_size(PWINDOW->m_uSurface.xdg->toplevel, predSize.x, predSize.y); return; } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index b46004e6..a7e869cb 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -98,11 +98,11 @@ void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { } std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { - if (!pWindow->m_bIsMapped) - return ""; - try { if (pWindow->m_bIsX11) { + if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + return ""; + if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->title) { return std::string(pWindow->m_uSurface.xwayland->title); } @@ -119,11 +119,11 @@ std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { } std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { - if (!pWindow->m_bIsMapped) - return ""; - try { if (pWindow->m_bIsX11) { + if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + return ""; + if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->_class) { return std::string(pWindow->m_uSurface.xwayland->_class); } @@ -198,7 +198,7 @@ wlr_surface* CHyprXWaylandManager::surfaceAt(CWindow* pWindow, const Vector2D& c return wlr_xdg_surface_surface_at(pWindow->m_uSurface.xdg, client.x, client.y, &surface.x, &surface.y); } -bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) { +bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow, bool pending) { if (pWindow->m_bIsX11) { for (size_t i = 0; i < pWindow->m_uSurface.xwayland->window_type_len; i++) if (pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"] || @@ -243,7 +243,7 @@ bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow) { if (SIZEHINTS && (pWindow->m_uSurface.xwayland->parent || ((SIZEHINTS->min_width == SIZEHINTS->max_width) && (SIZEHINTS->min_height == SIZEHINTS->max_height)))) return true; } else { - const auto PSTATE = &pWindow->m_uSurface.xdg->toplevel->current; + const auto PSTATE = pending ? &pWindow->m_uSurface.xdg->toplevel->pending : &pWindow->m_uSurface.xdg->toplevel->current; if ((PSTATE->min_width != 0 && PSTATE->min_height != 0 && (PSTATE->min_width == PSTATE->max_width || PSTATE->min_height == PSTATE->max_height)) || pWindow->m_uSurface.xdg->toplevel->parent) diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index e41313e0..9fa9f46e 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -23,7 +23,7 @@ class CHyprXWaylandManager { void setWindowStyleTiled(CWindow*, uint32_t); void setWindowFullscreen(CWindow*, bool); wlr_surface* surfaceAt(CWindow*, const Vector2D&, Vector2D&); - bool shouldBeFloated(CWindow*); + bool shouldBeFloated(CWindow*, bool pending = false); void moveXWaylandWindow(CWindow*, const Vector2D&); void checkBorders(CWindow*); Vector2D getMaxSizeForWindow(CWindow*); From b1c0f1cc018d13ac1e5ebccaade5528ec757bd74 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Thu, 29 Feb 2024 00:03:28 +0000 Subject: [PATCH 0009/2897] subsurface: Rewrite the subsurface tree (#4877) --- src/Compositor.hpp | 1 - src/Window.cpp | 4 + src/Window.hpp | 7 +- src/events/Events.hpp | 8 - src/events/Popups.cpp | 16 +- src/events/Windows.cpp | 17 +- src/helpers/Subsurface.cpp | 238 +++++++++++++++++++++++++ src/helpers/Subsurface.hpp | 51 ++++++ src/helpers/SubsurfaceTree.cpp | 312 --------------------------------- src/helpers/SubsurfaceTree.hpp | 60 ------- src/helpers/WLClasses.hpp | 12 +- 11 files changed, 312 insertions(+), 414 deletions(-) create mode 100644 src/helpers/Subsurface.cpp create mode 100644 src/helpers/Subsurface.hpp delete mode 100644 src/helpers/SubsurfaceTree.cpp delete mode 100644 src/helpers/SubsurfaceTree.hpp diff --git a/src/Compositor.hpp b/src/Compositor.hpp index c08a5931..491aee71 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -95,7 +95,6 @@ class CCompositor { std::vector> m_vWindows; std::vector> m_vXDGPopups; std::vector> m_vWorkspaces; - std::vector> m_vSubsurfaces; std::vector m_vWindowsFadingOut; std::vector m_vSurfacesFadingOut; diff --git a/src/Window.cpp b/src/Window.cpp index ece5b658..f1484cb0 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -471,6 +471,8 @@ void CWindow::onUnmap() { PMONITOR->solitaryClient = nullptr; g_pCompositor->updateWorkspaceWindows(m_iWorkspaceID); + + m_pSubsurfaceHead.reset(); } void CWindow::onMap() { @@ -516,6 +518,8 @@ void CWindow::onMap() { m_bTearingHint = ctrl->pWlrHint->current; break; } + + m_pSubsurfaceHead = std::make_unique(this); } void CWindow::onBorderAngleAnimEnd(void* ptr) { diff --git a/src/Window.hpp b/src/Window.hpp index f8ba4180..2d7bc986 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -1,7 +1,7 @@ #pragma once #include "defines.hpp" -#include "helpers/SubsurfaceTree.hpp" +#include "helpers/Subsurface.hpp" #include "helpers/AnimatedVariable.hpp" #include "render/decorations/IHyprWindowDecoration.hpp" #include @@ -276,9 +276,10 @@ class CWindow { bool m_bWantsInitialFullscreen = false; // bitfield eSuppressEvents - uint64_t m_eSuppressedEvents = SUPPRESS_NONE; + uint64_t m_eSuppressedEvents = SUPPRESS_NONE; - SSurfaceTreeNode* m_pSurfaceTree = nullptr; + // for the subsurface tree + std::unique_ptr m_pSubsurfaceHead; // Animated border CGradientValueData m_cRealBorderColor = {0}; diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 8b737f32..980142a0 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -22,14 +22,6 @@ namespace Events { DYNLISTENFUNC(unmapLayerSurface); DYNLISTENFUNC(commitLayerSurface); - // Subsurfaces - DYNLISTENFUNC(newSubsurfaceNode); - DYNLISTENFUNC(destroySubsurfaceNode); - DYNLISTENFUNC(mapSubsurface); - DYNLISTENFUNC(unmapSubsurface); - DYNLISTENFUNC(destroySubsurface); - DYNLISTENFUNC(commitSubsurface); - // Popups DYNLISTENFUNC(newPopup); // LayerSurface diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp index 41707b6a..ca1787f5 100644 --- a/src/events/Popups.cpp +++ b/src/events/Popups.cpp @@ -154,7 +154,7 @@ void Events::listener_mapPopupXDG(void* owner, void* data) { else if (PPOPUP->parentLS) PPOPUP->parentLS->popupSurfaces.emplace_back(PPOPUP->popup->base->surface); - PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP, PPOPUP->parentWindow); + //PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP, PPOPUP->parentWindow); int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); @@ -170,7 +170,7 @@ void Events::listener_mapPopupXDG(void* owner, void* data) { g_pCompositor->setPreferredTransformForSurface(PPOPUP->popup->base->surface, PPOPUP->monitor->transform); } - Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode {:x}", (uintptr_t)PPOPUP->pSurfaceTree); + // Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode {:x}", (uintptr_t)PPOPUP->pSurfaceTree); } void Events::listener_repositionPopupXDG(void* owner, void* data) { @@ -204,7 +204,7 @@ void Events::listener_unmapPopupXDG(void* owner, void* data) { if (PPOPUP->popup->base->surface == g_pCompositor->m_pLastFocus) g_pInputManager->releaseAllMouseButtons(); - SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); + // SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); int lx = 0, ly = 0; addPopupGlobalCoords(PPOPUP, &lx, &ly); @@ -220,7 +220,7 @@ void Events::listener_unmapPopupXDG(void* owner, void* data) { else if (PPOPUP->parentLS) std::erase(PPOPUP->parentLS->popupSurfaces, PPOPUP->popup->base->surface); - PPOPUP->pSurfaceTree = nullptr; + // PPOPUP->pSurfaceTree = nullptr; g_pInputManager->simulateMouseMovement(); // to focus and return back to an appropriate surface } @@ -260,10 +260,10 @@ void Events::listener_destroyPopupXDG(void* owner, void* data) { Debug::log(LOG, "Destroyed popup XDG {:x}", (uintptr_t)PPOPUP); - if (PPOPUP->pSurfaceTree) { - SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); - PPOPUP->pSurfaceTree = nullptr; - } + // if (PPOPUP->pSurfaceTree) { + // SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); + // PPOPUP->pSurfaceTree = nullptr; + // } std::erase_if(g_pCompositor->m_vXDGPopups, [&](std::unique_ptr& el) { return el.get() == PPOPUP; }); } diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 6ea0bb0c..162415b4 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -486,8 +486,6 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_fDimPercent.setValueAndWarp(0); } - Debug::log(LOG, "Window got assigned a surfaceTreeNode {:x}", (uintptr_t)PWINDOW->m_pSurfaceTree); - if (!PWINDOW->m_bIsX11) { PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_newPopupXDG.initCallback(&PWINDOW->m_uSurface.xdg->events.new_popup, &Events::listener_newPopupXDG, PWINDOW, "XDG Window Late"); @@ -538,8 +536,6 @@ void Events::listener_mapWindow(void* owner, void* data) { // recheck idle inhibitors g_pInputManager->recheckIdleInhibitorStatus(); - PWINDOW->m_pSurfaceTree = SubsurfaceTree::createTreeRoot(PWINDOW->m_pWLSurface.wlr(), addViewCoords, PWINDOW, PWINDOW); - PWINDOW->updateToplevel(); if (workspaceSilent) { @@ -757,11 +753,6 @@ void Events::listener_unmapWindow(void* owner, void* data) { Debug::log(LOG, "Unmapped was not focused, ignoring a refocus."); } - Debug::log(LOG, "Destroying the SubSurface tree of unmapped window {}", PWINDOW); - SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree); - - PWINDOW->m_pSurfaceTree = nullptr; - PWINDOW->m_bFadingOut = true; g_pCompositor->addToFadingOutSafe(PWINDOW); @@ -842,6 +833,8 @@ void Events::listener_commitWindow(void* owner, void* data) { g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y, PWINDOW->m_bIsX11 ? 1.0 / PWINDOW->m_fX11SurfaceScaledBy : 1.0); + PWINDOW->m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + if (PWINDOW->m_bIsX11 || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) return; @@ -895,12 +888,6 @@ void Events::listener_destroyWindow(void* owner, void* data) { g_pLayoutManager->getCurrentLayout()->onWindowRemoved(PWINDOW); - if (PWINDOW->m_pSurfaceTree) { - Debug::log(LOG, "Destroying Subsurface tree of {} in destroyWindow", PWINDOW); - SubsurfaceTree::destroySurfaceTree(PWINDOW->m_pSurfaceTree); - PWINDOW->m_pSurfaceTree = nullptr; - } - PWINDOW->m_bReadyToDelete = true; if (!PWINDOW->m_bFadingOut) { diff --git a/src/helpers/Subsurface.cpp b/src/helpers/Subsurface.cpp new file mode 100644 index 00000000..0923e9cc --- /dev/null +++ b/src/helpers/Subsurface.cpp @@ -0,0 +1,238 @@ +#include "Subsurface.hpp" +#include "../events/Events.hpp" +#include "../Compositor.hpp" + +static void onNewSubsurface(void* owner, void* data); + +CSubsurface::CSubsurface(CWindow* pOwner) : m_pWindowParent(pOwner) { + initSignals(); + + wlr_subsurface* wlrSubsurface; + wl_list_for_each(wlrSubsurface, &pOwner->m_pWLSurface.wlr()->current.subsurfaces_below, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } + wl_list_for_each(wlrSubsurface, &pOwner->m_pWLSurface.wlr()->current.subsurfaces_above, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } +} + +CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) { + m_sWLSurface.assign(pSubsurface->surface); + initSignals(); + initExistingSubsurfaces(); +} + +CSubsurface::~CSubsurface() { + hyprListener_newSubsurface.removeCallback(); + + if (!m_pSubsurface) + return; + + hyprListener_commitSubsurface.removeCallback(); + hyprListener_destroySubsurface.removeCallback(); + + const auto COORDS = coordsGlobal(); + + CBox box = {COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); +} + +static void onNewSubsurface(void* owner, void* data) { + const auto PSUBSURFACE = (CSubsurface*)owner; + PSUBSURFACE->onNewSubsurface((wlr_subsurface*)data); +} + +static void onDestroySubsurface(void* owner, void* data) { + const auto PSUBSURFACE = (CSubsurface*)owner; + PSUBSURFACE->onDestroy(); +} + +static void onCommitSubsurface(void* owner, void* data) { + const auto PSUBSURFACE = (CSubsurface*)owner; + PSUBSURFACE->onCommit(); +} + +static void onMapSubsurface(void* owner, void* data) { + const auto PSUBSURFACE = (CSubsurface*)owner; + PSUBSURFACE->onMap(); +} + +static void onUnmapSubsurface(void* owner, void* data) { + const auto PSUBSURFACE = (CSubsurface*)owner; + PSUBSURFACE->onUnmap(); +} + +void CSubsurface::initSignals() { + if (m_pSubsurface) { + hyprListener_commitSubsurface.initCallback(&m_pSubsurface->surface->events.commit, &onCommitSubsurface, this, "CSubsurface"); + hyprListener_destroySubsurface.initCallback(&m_pSubsurface->events.destroy, &onDestroySubsurface, this, "CSubsurface"); + hyprListener_newSubsurface.initCallback(&m_pSubsurface->surface->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface"); + hyprListener_mapSubsurface.initCallback(&m_pSubsurface->surface->events.map, &onMapSubsurface, this, "CSubsurface"); + hyprListener_newSubsurface.initCallback(&m_pSubsurface->surface->events.unmap, &onUnmapSubsurface, this, "CSubsurface"); + } else { + if (m_pWindowParent) + hyprListener_newSubsurface.initCallback(&m_pWindowParent->m_pWLSurface.wlr()->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface"); + else + RASSERT(false, "CSubsurface::initSignals empty subsurface"); + } +} + +void CSubsurface::checkSiblingDamage() { + if (!m_pParent) + return; // ?????????? + + const double SCALE = m_pWindowParent && m_pWindowParent->m_bIsX11 ? 1.0 / m_pWindowParent->m_fX11SurfaceScaledBy : 1.0; + + for (auto& n : m_pParent->m_vChildren) { + if (n.get() == this) + continue; + + const auto COORDS = n->coordsGlobal(); + g_pHyprRenderer->damageSurface(n->m_sWLSurface.wlr(), COORDS.x, COORDS.y, SCALE); + } +} + +void CSubsurface::recheckDamageForSubsurfaces() { + const double SCALE = m_pWindowParent && m_pWindowParent->m_bIsX11 ? 1.0 / m_pWindowParent->m_fX11SurfaceScaledBy : 1.0; + + for (auto& n : m_vChildren) { + const auto COORDS = n->coordsGlobal(); + g_pHyprRenderer->damageSurface(n->m_sWLSurface.wlr(), COORDS.x, COORDS.y, SCALE); + } +} + +void CSubsurface::onCommit() { + // no damaging if it's not visible + if (!g_pHyprRenderer->shouldRenderWindow(m_pWindowParent)) { + m_vLastSize = Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; + + static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); + if (**PLOGDAMAGE) + Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_pWindowParent); + return; + } + + const auto COORDS = coordsGlobal(); + + const double SCALE = m_pWindowParent && m_pWindowParent->m_bIsX11 ? 1.0 / m_pWindowParent->m_fX11SurfaceScaledBy : 1.0; + + g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y, SCALE); + + // I do not think this is correct, but it solves a lot of issues with some apps (e.g. firefox) + checkSiblingDamage(); + + if (m_vLastSize != Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}) { + CBox box{COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + m_vLastSize = Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; + box = {COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + } + + if (m_pWindowParent) { + if (m_pWindowParent->m_bIsX11) + m_pWindowParent->m_vReportedSize = m_pWindowParent->m_vPendingReportedSize; // apply pending size. We pinged, the window ponged. + + // tearing: if solitary, redraw it. This still might be a single surface window + const auto PMONITOR = g_pCompositor->getMonitorFromID(m_pWindowParent->m_iMonitorID); + if (PMONITOR && PMONITOR->solitaryClient == m_pWindowParent && m_pWindowParent->canBeTorn() && PMONITOR->tearingState.canTear && + m_sWLSurface.wlr()->current.committed & WLR_SURFACE_STATE_BUFFER) { + CRegion damageBox{&m_sWLSurface.wlr()->buffer_damage}; + + if (!damageBox.empty()) { + if (PMONITOR->tearingState.busy) { + PMONITOR->tearingState.frameScheduledWhileBusy = true; + } else { + PMONITOR->tearingState.nextRenderTorn = true; + g_pHyprRenderer->renderMonitor(PMONITOR); + } + } + } + } +} + +void CSubsurface::onDestroy() { + // destroy children + m_vChildren.clear(); + + if (!m_pSubsurface) + return; // dummy node, nothing to do, it's the parent dying + + // kill ourselves + std::erase_if(m_pParent->m_vChildren, [this](const auto& other) { return other.get() == this; }); +} + +void CSubsurface::onNewSubsurface(wlr_subsurface* pSubsurface) { + CSubsurface* PSUBSURFACE = nullptr; + + if (m_pWindowParent) + PSUBSURFACE = m_vChildren.emplace_back(std::make_unique(pSubsurface, m_pWindowParent)).get(); + PSUBSURFACE->m_pParent = this; + + ASSERT(PSUBSURFACE); +} + +void CSubsurface::onMap() { + m_vLastSize = {m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; + + const auto COORDS = coordsGlobal(); + CBox box{COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + + if (m_pWindowParent) + m_pWindowParent->updateSurfaceScaleTransformDetails(); +} + +void CSubsurface::onUnmap() { + const auto COORDS = coordsGlobal(); + CBox box{COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + + if (m_sWLSurface.wlr() == g_pCompositor->m_pLastFocus) + g_pInputManager->releaseAllMouseButtons(); + + if (m_pWindowParent) + m_pWindowParent->updateSurfaceScaleTransformDetails(); + + g_pInputManager->simulateMouseMovement(); + + // TODO: should this remove children? Currently it won't, only on .destroy +} + +Vector2D CSubsurface::coordsRelativeToParent() { + Vector2D offset; + + CSubsurface* current = this; + + while (current->m_pParent) { + + offset += {current->m_sWLSurface.wlr()->current.dx, current->m_sWLSurface.wlr()->current.dy}; + offset += {current->m_pSubsurface->current.x, current->m_pSubsurface->current.y}; + + current = current->m_pParent; + } + + return offset; +} + +Vector2D CSubsurface::coordsGlobal() { + Vector2D coords = coordsRelativeToParent(); + + if (m_pWindowParent) + coords += m_pWindowParent->m_vRealPosition.vec(); + + return coords; +} + +void CSubsurface::initExistingSubsurfaces() { + if (m_pWindowParent) + return; + + wlr_subsurface* wlrSubsurface; + wl_list_for_each(wlrSubsurface, &m_sWLSurface.wlr()->current.subsurfaces_below, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } + wl_list_for_each(wlrSubsurface, &m_sWLSurface.wlr()->current.subsurfaces_above, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } +} \ No newline at end of file diff --git a/src/helpers/Subsurface.hpp b/src/helpers/Subsurface.hpp new file mode 100644 index 00000000..a8f028af --- /dev/null +++ b/src/helpers/Subsurface.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "../defines.hpp" +#include +#include "WLSurface.hpp" + +class CWindow; + +class CSubsurface { + public: + // root dummy nodes + CSubsurface(CWindow* pOwner); + + // real nodes + CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner); + + ~CSubsurface(); + + Vector2D coordsRelativeToParent(); + Vector2D coordsGlobal(); + + void onCommit(); + void onDestroy(); + void onNewSubsurface(wlr_subsurface* pSubsurface); + void onMap(); + void onUnmap(); + + void recheckDamageForSubsurfaces(); + + private: + DYNLISTENER(destroySubsurface); + DYNLISTENER(commitSubsurface); + DYNLISTENER(newSubsurface); + DYNLISTENER(mapSubsurface); + DYNLISTENER(unmapSubsurface); + + wlr_subsurface* m_pSubsurface = nullptr; + CWLSurface m_sWLSurface; + Vector2D m_vLastSize = {}; + + // if nullptr, means it's a dummy node + CSubsurface* m_pParent = nullptr; + + CWindow* m_pWindowParent = nullptr; + + std::vector> m_vChildren; + + void initSignals(); + void initExistingSubsurfaces(); + void checkSiblingDamage(); +}; \ No newline at end of file diff --git a/src/helpers/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp deleted file mode 100644 index b4ea6d85..00000000 --- a/src/helpers/SubsurfaceTree.cpp +++ /dev/null @@ -1,312 +0,0 @@ -#include "SubsurfaceTree.hpp" -#include "../events/Events.hpp" -#include "../Compositor.hpp" - -void addSurfaceGlobalOffset(SSurfaceTreeNode* node, int* lx, int* ly) { - if (!node->pSurface || !node->pSurface->exists()) - return; - - *lx += node->pSurface->wlr()->current.dx; - *ly += node->pSurface->wlr()->current.dy; - - if (node->offsetfn) { - // This is the root node - RASSERT(!node->pSubsurface, "Node had no subsurface!"); - node->offsetfn(node->globalOffsetData, lx, ly); - } else { - RASSERT(node->pSubsurface, "Node had no subsurface!"); - - *lx += node->pSubsurface->pSubsurface->current.x; - *ly += node->pSubsurface->pSubsurface->current.y; - - addSurfaceGlobalOffset(node->pParent, lx, ly); - } -} - -SSurfaceTreeNode* createTree(wlr_surface* pSurface, CWindow* pWindow) { - const auto PNODE = &SubsurfaceTree::surfaceTreeNodes.emplace_back(); - - if (pSurface->data) - PNODE->pSurface = (CWLSurface*)pSurface->data; - else { - PNODE->pInternalSurface = pSurface; - PNODE->pSurface = &PNODE->pInternalSurface; - } - - PNODE->pWindowOwner = pWindow; - - PNODE->hyprListener_newSubsurface.initCallback(&pSurface->events.new_subsurface, &Events::listener_newSubsurfaceNode, PNODE, "SurfaceTreeNode"); - PNODE->hyprListener_commit.initCallback(&pSurface->events.commit, &Events::listener_commitSubsurface, PNODE, "SurfaceTreeNode"); - PNODE->hyprListener_destroy.initCallback(&pSurface->events.destroy, &Events::listener_destroySubsurfaceNode, PNODE, "SurfaceTreeNode"); - - wlr_subsurface* wlrSubsurface; - wl_list_for_each(wlrSubsurface, &pSurface->current.subsurfaces_below, current.link) { - Events::listener_newSubsurfaceNode(PNODE, wlrSubsurface); - } - wl_list_for_each(wlrSubsurface, &pSurface->current.subsurfaces_above, current.link) { - Events::listener_newSubsurfaceNode(PNODE, wlrSubsurface); - } - - return PNODE; -} - -SSurfaceTreeNode* createSubsurfaceNode(SSurfaceTreeNode* pParent, SSubsurface* pSubsurface, wlr_surface* surface, CWindow* pWindow) { - const auto PNODE = createTree(surface, pWindow); - PNODE->pParent = pParent; - PNODE->pSubsurface = pSubsurface; - - Debug::log(LOG, "Creating a subsurface Node! {}", pWindow); - - return PNODE; -} - -SSurfaceTreeNode* SubsurfaceTree::createTreeRoot(wlr_surface* pSurface, applyGlobalOffsetFn fn, void* data, CWindow* pWindow) { - const auto PNODE = createTree(pSurface, pWindow); - - Debug::log(LOG, "Creating a surfaceTree Root! {}", pWindow); - - PNODE->offsetfn = fn; - PNODE->globalOffsetData = data; - - return PNODE; -} - -void destroySubsurface(SSubsurface* pSubsurface); - -void SubsurfaceTree::destroySurfaceTree(SSurfaceTreeNode* pNode) { - bool exists = false; - for (auto& n : surfaceTreeNodes) { - if (&n == pNode) { - exists = true; - break; - } - } - - if (!exists) { - Debug::log(ERR, "Tried to remove a SurfaceTreeNode that doesn't exist?? (Node {:x})", (uintptr_t)pNode); - return; - } - - for (auto& c : pNode->childSubsurfaces) - destroySubsurface(&c); - - pNode->childSubsurfaces.clear(); - - pNode->hyprListener_commit.removeCallback(); - pNode->hyprListener_destroy.removeCallback(); - pNode->hyprListener_newSubsurface.removeCallback(); - - // damage - if (pNode->pSurface && pNode->pSurface->exists()) { - CBox extents = {}; - wlr_surface_get_extends(pNode->pSurface->wlr(), extents.pWlr()); - extents.applyFromWlr(); - - int lx = 0, ly = 0; - addSurfaceGlobalOffset(pNode, &lx, &ly); - - extents.x += lx; - extents.y += ly; - - g_pHyprRenderer->damageBox(&extents); - } - - // remove references to this node - for (auto& tn : surfaceTreeNodes) { - for (auto& cs : tn.childSubsurfaces) { - if (cs.pChild == pNode) - cs.pChild = nullptr; - } - } - - surfaceTreeNodes.remove(*pNode); - - Debug::log(LOG, "SurfaceTree Node removed"); -} - -void destroySubsurface(SSubsurface* pSubsurface) { - if (pSubsurface->pChild) { - SubsurfaceTree::destroySurfaceTree(pSubsurface->pChild); - pSubsurface->pChild = nullptr; - } - - pSubsurface->hyprListener_destroy.removeCallback(); - pSubsurface->hyprListener_map.removeCallback(); - pSubsurface->hyprListener_unmap.removeCallback(); -} - -// -// Subsurface listeners -// - -void Events::listener_newSubsurfaceNode(void* owner, void* data) { - SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner; - - const auto PSUBSURFACE = (wlr_subsurface*)data; - - const auto PNEWSUBSURFACE = &pNode->childSubsurfaces.emplace_back(); - - Debug::log(LOG, "Added a new subsurface {:x}", (uintptr_t)PSUBSURFACE); - - PNEWSUBSURFACE->pSubsurface = PSUBSURFACE; - PNEWSUBSURFACE->pParent = pNode; - - PNEWSUBSURFACE->hyprListener_map.initCallback(&PSUBSURFACE->surface->events.map, &Events::listener_mapSubsurface, PNEWSUBSURFACE, "Subsurface"); - PNEWSUBSURFACE->hyprListener_unmap.initCallback(&PSUBSURFACE->surface->events.unmap, &Events::listener_unmapSubsurface, PNEWSUBSURFACE, "Subsurface"); - PNEWSUBSURFACE->hyprListener_destroy.initCallback(&PSUBSURFACE->events.destroy, &Events::listener_destroySubsurface, PNEWSUBSURFACE, "Subsurface"); - - PNEWSUBSURFACE->pWindowOwner = pNode->pWindowOwner; - - if (PSUBSURFACE->surface->mapped) - listener_mapSubsurface(PNEWSUBSURFACE, nullptr); - - wlr_subsurface* existingWlrSubsurface; - wl_list_for_each(existingWlrSubsurface, &PSUBSURFACE->surface->current.subsurfaces_below, current.link) { - listener_newSubsurfaceNode(pNode, existingWlrSubsurface); - } - wl_list_for_each(existingWlrSubsurface, &PSUBSURFACE->surface->current.subsurfaces_above, current.link) { - listener_newSubsurfaceNode(pNode, existingWlrSubsurface); - } -} - -void Events::listener_mapSubsurface(void* owner, void* data) { - SSubsurface* subsurface = (SSubsurface*)owner; - - if (subsurface->pChild) - return; - - Debug::log(LOG, "Subsurface {:x} mapped", (uintptr_t)subsurface->pSubsurface); - - subsurface->pChild = createSubsurfaceNode(subsurface->pParent, subsurface, subsurface->pSubsurface->surface, subsurface->pWindowOwner); - - if (subsurface->pWindowOwner) - subsurface->pWindowOwner->updateSurfaceScaleTransformDetails(); -} - -void Events::listener_unmapSubsurface(void* owner, void* data) { - SSubsurface* subsurface = (SSubsurface*)owner; - - Debug::log(LOG, "Subsurface {:x} unmapped", (uintptr_t)subsurface); - - if (subsurface->pSubsurface->surface == g_pCompositor->m_pLastFocus) - g_pInputManager->releaseAllMouseButtons(); - - if (subsurface->pChild) { - const auto PNODE = subsurface->pChild; - - const auto IT = - std::find_if(SubsurfaceTree::surfaceTreeNodes.begin(), SubsurfaceTree::surfaceTreeNodes.end(), [&](const SSurfaceTreeNode& other) { return &other == PNODE; }); - - if (IT != SubsurfaceTree::surfaceTreeNodes.end()) { - if (PNODE->pSurface && PNODE->pSurface->exists()) { - int lx = 0, ly = 0; - addSurfaceGlobalOffset(PNODE, &lx, &ly); - - CBox extents = {lx, ly, 0, 0}; - - extents.width = PNODE->pSurface->wlr()->current.width; - extents.height = PNODE->pSurface->wlr()->current.height; - - g_pHyprRenderer->damageBox(&extents); - } - - // SubsurfaceTree::destroySurfaceTree(subsurface->pChild); - // subsurface->pChild = nullptr; - } - } - - g_pInputManager->simulateMouseMovement(); // to focus and return back to an appropriate surface -} - -void Events::listener_commitSubsurface(void* owner, void* data) { - SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner; - - // no damaging if it's not visible - if (!g_pHyprRenderer->shouldRenderWindow(pNode->pWindowOwner)) { - pNode->lastSize = pNode->pSurface->exists() ? Vector2D{pNode->pSurface->wlr()->current.width, pNode->pSurface->wlr()->current.height} : Vector2D{}; - - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); - if (**PLOGDAMAGE) - Debug::log(LOG, "Refusing to commit damage from {} because it's invisible.", pNode->pWindowOwner); - return; - } - - int lx = 0, ly = 0; - - addSurfaceGlobalOffset(pNode, &lx, &ly); - - const double SCALE = pNode->pWindowOwner && pNode->pWindowOwner->m_bIsX11 ? 1.0 / pNode->pWindowOwner->m_fX11SurfaceScaledBy : 1.0; - - // I do not think this is correct, but it solves a lot of issues with some apps (e.g. firefox) - // What this does is that basically, if the pNode is a child of some other node, on commit, - // it will also damage (check & damage if needed) all its siblings. - if (pNode->pParent) - for (auto& cs : pNode->pParent->childSubsurfaces) { - const auto NODECOORDS = pNode->pSubsurface ? Vector2D(pNode->pSubsurface->pSubsurface->current.x, pNode->pSubsurface->pSubsurface->current.y) : Vector2D(); - - if (&cs != pNode->pSubsurface && cs.pSubsurface) { - g_pHyprRenderer->damageSurface(cs.pSubsurface->surface, lx - NODECOORDS.x + cs.pSubsurface->current.x, ly - NODECOORDS.y + cs.pSubsurface->current.y, SCALE); - } - } - - if (pNode->pSurface && pNode->pSurface->exists()) { - g_pHyprRenderer->damageSurface(pNode->pSurface->wlr(), lx, ly, SCALE); - - if (pNode->lastSize != Vector2D{pNode->pSurface->wlr()->current.width, pNode->pSurface->wlr()->current.height} && pNode->pWindowOwner) - g_pHyprRenderer->damageWindow(pNode->pWindowOwner); - } - - if (pNode->pWindowOwner) { - if (pNode->pWindowOwner->m_bIsX11) - pNode->pWindowOwner->m_vReportedSize = pNode->pWindowOwner->m_vPendingReportedSize; // apply pending size. We pinged, the window ponged. - - // tearing: if solitary, redraw it. This still might be a single surface window - const auto PMONITOR = g_pCompositor->getMonitorFromID(pNode->pWindowOwner->m_iMonitorID); - if (PMONITOR && PMONITOR->solitaryClient == pNode->pWindowOwner && pNode->pWindowOwner->canBeTorn() && PMONITOR->tearingState.canTear && - pNode->pSurface->wlr()->current.committed & WLR_SURFACE_STATE_BUFFER) { - CRegion damageBox{&pNode->pSurface->wlr()->buffer_damage}; - - if (!damageBox.empty()) { - if (PMONITOR->tearingState.busy) { - PMONITOR->tearingState.frameScheduledWhileBusy = true; - } else { - PMONITOR->tearingState.nextRenderTorn = true; - g_pHyprRenderer->renderMonitor(PMONITOR); - } - } - } - } - - pNode->lastSize = pNode->pSurface->exists() ? Vector2D{pNode->pSurface->wlr()->current.width, pNode->pSurface->wlr()->current.height} : Vector2D{}; -} - -void Events::listener_destroySubsurface(void* owner, void* data) { - SSubsurface* subsurface = (SSubsurface*)owner; - - if (subsurface->pChild) { - SubsurfaceTree::destroySurfaceTree(subsurface->pChild); - } - - Debug::log(LOG, "Subsurface {:x} destroyed", (uintptr_t)subsurface); - - subsurface->hyprListener_destroy.removeCallback(); - subsurface->hyprListener_map.removeCallback(); - subsurface->hyprListener_unmap.removeCallback(); - - subsurface->pParent->childSubsurfaces.remove(*subsurface); -} - -void Events::listener_destroySubsurfaceNode(void* owner, void* data) { - SSurfaceTreeNode* pNode = (SSurfaceTreeNode*)owner; - - Debug::log(LOG, "Subsurface Node {:x} destroyed", (uintptr_t)pNode); - - for (auto& c : pNode->childSubsurfaces) - destroySubsurface(&c); - - pNode->hyprListener_commit.removeCallback(); - pNode->hyprListener_newSubsurface.removeCallback(); - pNode->hyprListener_destroy.removeCallback(); - - SubsurfaceTree::surfaceTreeNodes.remove(*pNode); -} diff --git a/src/helpers/SubsurfaceTree.hpp b/src/helpers/SubsurfaceTree.hpp deleted file mode 100644 index 7a8b8fb8..00000000 --- a/src/helpers/SubsurfaceTree.hpp +++ /dev/null @@ -1,60 +0,0 @@ -#pragma once - -#include "../defines.hpp" -#include -#include "WLSurface.hpp" - -struct SSubsurface; -class CWindow; - -typedef void (*applyGlobalOffsetFn)(void*, int*, int*); - -struct SSurfaceTreeNode { - CWLSurface* pSurface = nullptr; // actual surface - CWLSurface pInternalSurface; // not present for head nodes to not dupe wlr_surface ownership - - DYNLISTENER(newSubsurface); - DYNLISTENER(commit); - DYNLISTENER(destroy); - - SSurfaceTreeNode* pParent = nullptr; - SSubsurface* pSubsurface = nullptr; - - std::list childSubsurfaces; - - applyGlobalOffsetFn offsetfn; - void* globalOffsetData; - CWindow* pWindowOwner = nullptr; - - Vector2D lastSize; - - // - bool operator==(const SSurfaceTreeNode& rhs) const { - return pSurface == rhs.pSurface; - } -}; - -struct SSubsurface { - wlr_subsurface* pSubsurface = nullptr; - - SSurfaceTreeNode* pParent = nullptr; - SSurfaceTreeNode* pChild = nullptr; - - DYNLISTENER(map); - DYNLISTENER(unmap); - DYNLISTENER(destroy); - - CWindow* pWindowOwner = nullptr; - - // - bool operator==(const SSubsurface& rhs) const { - return pSubsurface == rhs.pSubsurface; - } -}; - -namespace SubsurfaceTree { - SSurfaceTreeNode* createTreeRoot(wlr_surface*, applyGlobalOffsetFn, void*, CWindow* pWindow = nullptr); - void destroySurfaceTree(SSurfaceTreeNode*); - - inline std::list surfaceTreeNodes; -}; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index b62a6489..c1110eaa 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -4,7 +4,7 @@ #include "../defines.hpp" #include "wlr-layer-shell-unstable-v1-protocol.h" #include "../Window.hpp" -#include "SubsurfaceTree.hpp" +#include "Subsurface.hpp" #include "AnimatedVariable.hpp" #include "WLSurface.hpp" #include "Region.hpp" @@ -213,13 +213,11 @@ struct SXDGPopup { DYNLISTENER(commitPopupXDG); DYNLISTENER(repositionPopupXDG); - double lx; - double ly; + double lx; + double ly; - Vector2D lastPos = {}; - bool repositionRequested = false; - - SSurfaceTreeNode* pSurfaceTree = nullptr; + Vector2D lastPos = {}; + bool repositionRequested = false; // For the list lookup bool operator==(const SXDGPopup& rhs) const { From 4bff762d9733ba7334cd37b995cf51552cc80be0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 01:21:15 +0000 Subject: [PATCH 0010/2897] xwaylandmgr: don't read xwayland surface from unmapped xwayland --- src/managers/XWaylandManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index a7e869cb..1704ee99 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -100,7 +100,7 @@ void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { try { if (pWindow->m_bIsX11) { - if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + if (!pWindow->m_bIsMapped) return ""; if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->title) { @@ -121,7 +121,7 @@ std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { try { if (pWindow->m_bIsX11) { - if (!pWindow->m_bIsMapped && pWindow->m_iX11Type != 1) + if (!pWindow->m_bIsMapped) return ""; if (pWindow->m_uSurface.xwayland && pWindow->m_uSurface.xwayland->_class) { From b39dcfa497f84486569bf862092dfcfadbfd8747 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 13:03:38 +0000 Subject: [PATCH 0011/2897] refactor: move a few things to desktop/ --- src/Compositor.hpp | 2 +- src/Window.hpp | 4 ++-- src/{helpers => desktop}/Subsurface.cpp | 0 src/{helpers => desktop}/Subsurface.hpp | 2 ++ src/{helpers => desktop}/WLSurface.cpp | 0 src/{helpers => desktop}/WLSurface.hpp | 2 +- src/{helpers => desktop}/Workspace.cpp | 0 src/{helpers => desktop}/Workspace.hpp | 2 +- src/helpers/WLClasses.hpp | 4 ++-- src/render/Renderer.hpp | 2 +- 10 files changed, 10 insertions(+), 8 deletions(-) rename src/{helpers => desktop}/Subsurface.cpp (100%) rename src/{helpers => desktop}/Subsurface.hpp (98%) rename src/{helpers => desktop}/WLSurface.cpp (100%) rename src/{helpers => desktop}/WLSurface.hpp (98%) rename src/{helpers => desktop}/Workspace.cpp (100%) rename src/{helpers => desktop}/Workspace.hpp (97%) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 491aee71..92573669 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -21,7 +21,7 @@ #include "debug/HyprDebugOverlay.hpp" #include "debug/HyprNotificationOverlay.hpp" #include "helpers/Monitor.hpp" -#include "helpers/Workspace.hpp" +#include "desktop/Workspace.hpp" #include "Window.hpp" #include "render/Renderer.hpp" #include "render/OpenGL.hpp" diff --git a/src/Window.hpp b/src/Window.hpp index 2d7bc986..476cb1c5 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -1,13 +1,13 @@ #pragma once #include "defines.hpp" -#include "helpers/Subsurface.hpp" +#include "desktop/Subsurface.hpp" #include "helpers/AnimatedVariable.hpp" #include "render/decorations/IHyprWindowDecoration.hpp" #include #include "config/ConfigDataValues.hpp" #include "helpers/Vector2D.hpp" -#include "helpers/WLSurface.hpp" +#include "desktop/WLSurface.hpp" #include "macros.hpp" #include "managers/XWaylandManager.hpp" diff --git a/src/helpers/Subsurface.cpp b/src/desktop/Subsurface.cpp similarity index 100% rename from src/helpers/Subsurface.cpp rename to src/desktop/Subsurface.cpp diff --git a/src/helpers/Subsurface.hpp b/src/desktop/Subsurface.hpp similarity index 98% rename from src/helpers/Subsurface.hpp rename to src/desktop/Subsurface.hpp index a8f028af..22692192 100644 --- a/src/helpers/Subsurface.hpp +++ b/src/desktop/Subsurface.hpp @@ -5,6 +5,7 @@ #include "WLSurface.hpp" class CWindow; +struct SXDGPopup; class CSubsurface { public: @@ -28,6 +29,7 @@ class CSubsurface { void recheckDamageForSubsurfaces(); private: + DYNLISTENER(destroySubsurface); DYNLISTENER(commitSubsurface); DYNLISTENER(newSubsurface); diff --git a/src/helpers/WLSurface.cpp b/src/desktop/WLSurface.cpp similarity index 100% rename from src/helpers/WLSurface.cpp rename to src/desktop/WLSurface.cpp diff --git a/src/helpers/WLSurface.hpp b/src/desktop/WLSurface.hpp similarity index 98% rename from src/helpers/WLSurface.hpp rename to src/desktop/WLSurface.hpp index eab4ac48..15debd56 100644 --- a/src/helpers/WLSurface.hpp +++ b/src/desktop/WLSurface.hpp @@ -1,7 +1,7 @@ #pragma once #include "../defines.hpp" -#include "Region.hpp" +#include "../helpers/Region.hpp" class CWindow; diff --git a/src/helpers/Workspace.cpp b/src/desktop/Workspace.cpp similarity index 100% rename from src/helpers/Workspace.cpp rename to src/desktop/Workspace.cpp diff --git a/src/helpers/Workspace.hpp b/src/desktop/Workspace.hpp similarity index 97% rename from src/helpers/Workspace.hpp rename to src/desktop/Workspace.hpp index a0bbb815..d4915769 100644 --- a/src/helpers/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -1,6 +1,6 @@ #pragma once -#include "AnimatedVariable.hpp" +#include "../helpers/AnimatedVariable.hpp" #include #include "../defines.hpp" diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index c1110eaa..e536c3d2 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -4,9 +4,9 @@ #include "../defines.hpp" #include "wlr-layer-shell-unstable-v1-protocol.h" #include "../Window.hpp" -#include "Subsurface.hpp" +#include "../desktop/Subsurface.hpp" #include "AnimatedVariable.hpp" -#include "WLSurface.hpp" +#include "../desktop/WLSurface.hpp" #include "Region.hpp" struct SLayerRule { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 5eafb639..53cace82 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -3,7 +3,6 @@ #include "../defines.hpp" #include #include "../helpers/Monitor.hpp" -#include "../helpers/Workspace.hpp" #include "../Window.hpp" #include "OpenGL.hpp" #include "Renderbuffer.hpp" @@ -11,6 +10,7 @@ #include "../helpers/Region.hpp" struct SMonitorRule; +class CWorkspace; // TODO: add fuller damage tracking for updating only parts of a window enum DAMAGETRACKINGMODES { From 2e111c8cf97d391c25fc6263660271fab605ece1 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 14:26:02 +0000 Subject: [PATCH 0012/2897] xdg: rewrite entire popup implementation --- src/Compositor.cpp | 9 -- src/Compositor.hpp | 2 - src/Window.cpp | 8 ++ src/Window.hpp | 5 +- src/desktop/Popup.cpp | 225 +++++++++++++++++++++++++++++++ src/desktop/Popup.hpp | 69 ++++++++++ src/desktop/Subsurface.cpp | 51 ++++--- src/desktop/Subsurface.hpp | 8 +- src/events/Events.hpp | 11 -- src/events/Layers.cpp | 6 +- src/events/Popups.cpp | 269 ------------------------------------- src/events/Windows.cpp | 7 +- src/helpers/WLClasses.hpp | 32 +---- 13 files changed, 358 insertions(+), 344 deletions(-) create mode 100644 src/desktop/Popup.cpp create mode 100644 src/desktop/Popup.hpp delete mode 100644 src/events/Popups.cpp diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 48ac0e1c..150dbfaa 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1120,15 +1120,6 @@ bool CCompositor::windowValidMapped(CWindow* pWindow) { return true; } -CWindow* CCompositor::getWindowForPopup(wlr_xdg_popup* popup) { - for (auto& p : m_vXDGPopups) { - if (p->popup == popup) - return p->parentWindow; - } - - return nullptr; -} - wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) { for (auto& ls : *layerSurfaces | std::views::reverse) { diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 92573669..e9edae04 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -93,7 +93,6 @@ class CCompositor { std::vector> m_vMonitors; std::vector> m_vRealMonitors; // for all monitors, even those turned off std::vector> m_vWindows; - std::vector> m_vXDGPopups; std::vector> m_vWorkspaces; std::vector m_vWindowsFadingOut; std::vector m_vSurfacesFadingOut; @@ -142,7 +141,6 @@ class CCompositor { Vector2D vectorToSurfaceLocal(const Vector2D&, CWindow*, wlr_surface*); CMonitor* getMonitorFromOutput(wlr_output*); CMonitor* getRealMonitorFromOutput(wlr_output*); - CWindow* getWindowForPopup(wlr_xdg_popup*); CWindow* getWindowFromSurface(wlr_surface*); CWindow* getWindowFromHandle(uint32_t); CWindow* getWindowFromZWLRHandle(wl_resource*); diff --git a/src/Window.cpp b/src/Window.cpp index f1484cb0..6742be60 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -472,7 +472,11 @@ void CWindow::onUnmap() { g_pCompositor->updateWorkspaceWindows(m_iWorkspaceID); + if (m_bIsX11) + return; + m_pSubsurfaceHead.reset(); + m_pPopupHead.reset(); } void CWindow::onMap() { @@ -519,7 +523,11 @@ void CWindow::onMap() { break; } + if (m_bIsX11) + return; + m_pSubsurfaceHead = std::make_unique(this); + m_pPopupHead = std::make_unique(this); } void CWindow::onBorderAngleAnimEnd(void* ptr) { diff --git a/src/Window.hpp b/src/Window.hpp index 476cb1c5..f4809d11 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -8,6 +8,7 @@ #include "config/ConfigDataValues.hpp" #include "helpers/Vector2D.hpp" #include "desktop/WLSurface.hpp" +#include "desktop/Popup.hpp" #include "macros.hpp" #include "managers/XWaylandManager.hpp" @@ -193,7 +194,6 @@ class CWindow { DYNLISTENER(setTitleWindow); DYNLISTENER(setGeometryX11U); DYNLISTENER(fullscreenWindow); - DYNLISTENER(newPopupXDG); DYNLISTENER(requestMove); DYNLISTENER(requestMinimize); DYNLISTENER(requestMaximize); @@ -278,8 +278,9 @@ class CWindow { // bitfield eSuppressEvents uint64_t m_eSuppressedEvents = SUPPRESS_NONE; - // for the subsurface tree + // desktop components std::unique_ptr m_pSubsurfaceHead; + std::unique_ptr m_pPopupHead; // Animated border CGradientValueData m_cRealBorderColor = {0}; diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp new file mode 100644 index 00000000..a4b63826 --- /dev/null +++ b/src/desktop/Popup.cpp @@ -0,0 +1,225 @@ +#include "Popup.hpp" + +CPopup::CPopup(CWindow* pOwner) : m_pWindowOwner(pOwner) { + initAllSignals(); +} + +CPopup::CPopup(SLayerSurface* pOwner) : m_pLayerOwner(pOwner) { + initAllSignals(); +} + +CPopup::CPopup(wlr_xdg_popup* popup, CPopup* pOwner) : m_pParent(pOwner), m_pWLR(popup) { + m_pWLR->base->data = this; + m_sWLSurface.assign(popup->base->surface); + + m_pLayerOwner = pOwner->m_pLayerOwner; + m_pWindowOwner = pOwner->m_pWindowOwner; + + m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + unconstrain(); + + initAllSignals(); +} + +CPopup::~CPopup() { + m_sWLSurface.unassign(); + if (m_pWLR) + m_pWLR->base->data = nullptr; + + hyprListener_commitPopup.removeCallback(); + hyprListener_repositionPopup.removeCallback(); + hyprListener_mapPopup.removeCallback(); + hyprListener_unmapPopup.removeCallback(); + hyprListener_newPopup.removeCallback(); + hyprListener_destroyPopup.removeCallback(); +} + +static void onNewPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onNewPopup((wlr_xdg_popup*)data); +} + +static void onMapPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onMap(); +} + +static void onDestroyPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onDestroy(); +} + +static void onUnmapPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onUnmap(); +} + +static void onCommitPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onCommit(); +} + +static void onRepositionPopup(void* owner, void* data) { + const auto POPUP = (CPopup*)owner; + POPUP->onReposition(); +} + +void CPopup::initAllSignals() { + + if (!m_pWLR) { + if (m_pWindowOwner) + hyprListener_newPopup.initCallback(&m_pWindowOwner->m_uSurface.xdg->events.new_popup, ::onNewPopup, this, "CPopup Head"); + else if (m_pLayerOwner) + hyprListener_newPopup.initCallback(&m_pLayerOwner->layerSurface->events.new_popup, ::onNewPopup, this, "CPopup Head"); + else + ASSERT(false); + + return; + } + + hyprListener_repositionPopup.initCallback(&m_pWLR->events.reposition, ::onRepositionPopup, this, "CPopup"); + hyprListener_destroyPopup.initCallback(&m_pWLR->events.destroy, ::onDestroyPopup, this, "CPopup"); + hyprListener_mapPopup.initCallback(&m_sWLSurface.wlr()->events.map, ::onMapPopup, this, "CPopup"); + hyprListener_unmapPopup.initCallback(&m_sWLSurface.wlr()->events.unmap, ::onUnmapPopup, this, "CPopup"); + hyprListener_commitPopup.initCallback(&m_sWLSurface.wlr()->events.commit, ::onCommitPopup, this, "CPopup"); + hyprListener_newPopup.initCallback(&m_pWLR->base->events.new_popup, ::onNewPopup, this, "CPopup"); +} + +void CPopup::onNewPopup(wlr_xdg_popup* popup) { + const auto POPUP = m_vChildren.emplace_back(std::make_unique(popup, this)).get(); + Debug::log(LOG, "New popup at wlr {:x} and hl {:x}", (uintptr_t)popup, (uintptr_t)POPUP); +} + +void CPopup::onDestroy() { + m_bInert = true; + + if (!m_pParent) + return; // head node + + std::erase_if(m_pParent->m_vChildren, [this](const auto& other) { return other.get() == this; }); +} + +void CPopup::onMap() { + m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + const auto COORDS = coordsGlobal(); + + CBox box = {COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + + m_vLastPos = coordsRelativeToParent(); + + g_pInputManager->simulateMouseMovement(); + + m_pSubsurfaceHead = std::make_unique(this); + + unconstrain(); +} + +void CPopup::onUnmap() { + m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + const auto COORDS = coordsGlobal(); + + CBox box = {COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + + m_pSubsurfaceHead.reset(); + + g_pInputManager->simulateMouseMovement(); +} + +void CPopup::onCommit() { + if (m_pWLR->base->initial_commit) { + wlr_xdg_surface_schedule_configure(m_pWLR->base); + return; + } + + const auto COORDS = coordsGlobal(); + const auto COORDSLOCAL = coordsRelativeToParent(); + + if (m_vLastSize != Vector2D{m_pWLR->current.geometry.width, m_pWLR->current.geometry.height} || m_bRequestedReposition || m_vLastPos != COORDSLOCAL) { + CBox box = {localToGlobal(m_vLastPos), m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + box = {COORDS, m_vLastSize}; + g_pHyprRenderer->damageBox(&box); + + m_vLastPos = COORDSLOCAL; + } + + m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + + g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y); + + m_bRequestedReposition = false; +} + +void CPopup::onReposition() { + Debug::log(LOG, "Popup {:x} requests reposition", (uintptr_t)this); + + m_bRequestedReposition = true; + + m_vLastPos = coordsRelativeToParent(); + + unconstrain(); +} + +void CPopup::unconstrain() { + const auto COORDS = t1ParentCoords(); + const auto PMONITOR = g_pCompositor->getMonitorFromVector(COORDS); + + if (!PMONITOR) + return; + + CBox box = {PMONITOR->vecPosition.x - COORDS.x, PMONITOR->vecPosition.y - COORDS.y, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; + wlr_xdg_popup_unconstrain_from_box(m_pWLR, box.pWlr()); +} + +Vector2D CPopup::coordsRelativeToParent() { + Vector2D offset; + + CPopup* current = this; + + while (current->m_pParent) { + + offset += {current->m_sWLSurface.wlr()->current.dx, current->m_sWLSurface.wlr()->current.dy}; + offset += {current->m_pWLR->current.geometry.x, current->m_pWLR->current.geometry.y}; + + current = current->m_pParent; + } + + return offset; +} + +Vector2D CPopup::coordsGlobal() { + return localToGlobal(coordsRelativeToParent()); +} + +Vector2D CPopup::localToGlobal(const Vector2D& rel) { + return t1ParentCoords() + rel; +} + +Vector2D CPopup::t1ParentCoords() { + if (m_pWindowOwner) + return m_pWindowOwner->m_vRealPosition.vec(); + if (m_pLayerOwner) + return m_pLayerOwner->realPosition.vec(); + + ASSERT(false); + return {}; +} + +void CPopup::recheckTree() { + CPopup* curr = this; + while (curr->m_pParent) { + curr = curr->m_pParent; + } + + curr->recheckChildrenRecursive(); +} + +void CPopup::recheckChildrenRecursive() { + for (auto& c : m_vChildren) { + c->onCommit(); + c->recheckChildrenRecursive(); + } +} \ No newline at end of file diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp new file mode 100644 index 00000000..8279f7ed --- /dev/null +++ b/src/desktop/Popup.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include "Subsurface.hpp" + +struct SLayerSurface; + +class CPopup { + public: + // dummy head nodes + CPopup(CWindow* pOwner); + CPopup(SLayerSurface* pOwner); + + // real nodes + CPopup(wlr_xdg_popup* popup, CPopup* pOwner); + + ~CPopup(); + + Vector2D coordsRelativeToParent(); + Vector2D coordsGlobal(); + + void onNewPopup(wlr_xdg_popup* popup); + void onDestroy(); + void onMap(); + void onUnmap(); + void onCommit(); + void onReposition(); + + void recheckTree(); + + CWLSurface m_sWLSurface; + + private: + // T1 owners, each popup has to have one of these + CWindow* m_pWindowOwner = nullptr; + SLayerSurface* m_pLayerOwner = nullptr; + + // T2 owners + CPopup* m_pParent = nullptr; + + wlr_xdg_popup* m_pWLR = nullptr; + + Vector2D m_vLastSize = {}; + Vector2D m_vLastPos = {}; + + bool m_bRequestedReposition = false; + + bool m_bInert = false; + + // + std::vector> m_vChildren; + std::unique_ptr m_pSubsurfaceHead; + + // signals + DYNLISTENER(newPopup); + DYNLISTENER(destroyPopup); + DYNLISTENER(mapPopup); + DYNLISTENER(unmapPopup); + DYNLISTENER(commitPopup); + DYNLISTENER(repositionPopup); + + void initAllSignals(); + void unconstrain(); + void recheckChildrenRecursive(); + + Vector2D localToGlobal(const Vector2D& rel); + Vector2D t1ParentCoords(); +}; \ No newline at end of file diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index 0923e9cc..dde8d532 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -16,12 +16,30 @@ CSubsurface::CSubsurface(CWindow* pOwner) : m_pWindowParent(pOwner) { } } +CSubsurface::CSubsurface(CPopup* pOwner) : m_pPopupParent(pOwner) { + initSignals(); + + wlr_subsurface* wlrSubsurface; + wl_list_for_each(wlrSubsurface, &pOwner->m_sWLSurface.wlr()->current.subsurfaces_below, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } + wl_list_for_each(wlrSubsurface, &pOwner->m_sWLSurface.wlr()->current.subsurfaces_above, current.link) { + ::onNewSubsurface(this, wlrSubsurface); + } +} + CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) { m_sWLSurface.assign(pSubsurface->surface); initSignals(); initExistingSubsurfaces(); } +CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CPopup* pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { + m_sWLSurface.assign(pSubsurface->surface); + initSignals(); + initExistingSubsurfaces(); +} + CSubsurface::~CSubsurface() { hyprListener_newSubsurface.removeCallback(); @@ -30,11 +48,6 @@ CSubsurface::~CSubsurface() { hyprListener_commitSubsurface.removeCallback(); hyprListener_destroySubsurface.removeCallback(); - - const auto COORDS = coordsGlobal(); - - CBox box = {COORDS, m_vLastSize}; - g_pHyprRenderer->damageBox(&box); } static void onNewSubsurface(void* owner, void* data) { @@ -68,10 +81,12 @@ void CSubsurface::initSignals() { hyprListener_destroySubsurface.initCallback(&m_pSubsurface->events.destroy, &onDestroySubsurface, this, "CSubsurface"); hyprListener_newSubsurface.initCallback(&m_pSubsurface->surface->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface"); hyprListener_mapSubsurface.initCallback(&m_pSubsurface->surface->events.map, &onMapSubsurface, this, "CSubsurface"); - hyprListener_newSubsurface.initCallback(&m_pSubsurface->surface->events.unmap, &onUnmapSubsurface, this, "CSubsurface"); + hyprListener_unmapSubsurface.initCallback(&m_pSubsurface->surface->events.unmap, &onUnmapSubsurface, this, "CSubsurface"); } else { if (m_pWindowParent) - hyprListener_newSubsurface.initCallback(&m_pWindowParent->m_pWLSurface.wlr()->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface"); + hyprListener_newSubsurface.initCallback(&m_pWindowParent->m_pWLSurface.wlr()->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface Head"); + else if (m_pPopupParent) + hyprListener_newSubsurface.initCallback(&m_pPopupParent->m_sWLSurface.wlr()->events.new_subsurface, &::onNewSubsurface, this, "CSubsurface Head"); else RASSERT(false, "CSubsurface::initSignals empty subsurface"); } @@ -93,11 +108,9 @@ void CSubsurface::checkSiblingDamage() { } void CSubsurface::recheckDamageForSubsurfaces() { - const double SCALE = m_pWindowParent && m_pWindowParent->m_bIsX11 ? 1.0 / m_pWindowParent->m_fX11SurfaceScaledBy : 1.0; - for (auto& n : m_vChildren) { const auto COORDS = n->coordsGlobal(); - g_pHyprRenderer->damageSurface(n->m_sWLSurface.wlr(), COORDS.x, COORDS.y, SCALE); + g_pHyprRenderer->damageSurface(n->m_sWLSurface.wlr(), COORDS.x, COORDS.y); } } @@ -112,11 +125,14 @@ void CSubsurface::onCommit() { return; } - const auto COORDS = coordsGlobal(); + const auto COORDS = coordsGlobal(); - const double SCALE = m_pWindowParent && m_pWindowParent->m_bIsX11 ? 1.0 / m_pWindowParent->m_fX11SurfaceScaledBy : 1.0; + g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y); - g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y, SCALE); + if (m_pPopupParent) + m_pPopupParent->recheckTree(); + if (m_pWindowParent) // I hate you firefox why are you doing this + m_pWindowParent->m_pPopupHead->recheckTree(); // I do not think this is correct, but it solves a lot of issues with some apps (e.g. firefox) checkSiblingDamage(); @@ -130,9 +146,6 @@ void CSubsurface::onCommit() { } if (m_pWindowParent) { - if (m_pWindowParent->m_bIsX11) - m_pWindowParent->m_vReportedSize = m_pWindowParent->m_vPendingReportedSize; // apply pending size. We pinged, the window ponged. - // tearing: if solitary, redraw it. This still might be a single surface window const auto PMONITOR = g_pCompositor->getMonitorFromID(m_pWindowParent->m_iMonitorID); if (PMONITOR && PMONITOR->solitaryClient == m_pWindowParent && m_pWindowParent->canBeTorn() && PMONITOR->tearingState.canTear && @@ -155,6 +168,8 @@ void CSubsurface::onDestroy() { // destroy children m_vChildren.clear(); + m_bInert = true; + if (!m_pSubsurface) return; // dummy node, nothing to do, it's the parent dying @@ -167,6 +182,8 @@ void CSubsurface::onNewSubsurface(wlr_subsurface* pSubsurface) { if (m_pWindowParent) PSUBSURFACE = m_vChildren.emplace_back(std::make_unique(pSubsurface, m_pWindowParent)).get(); + else if (m_pPopupParent) + PSUBSURFACE = m_vChildren.emplace_back(std::make_unique(pSubsurface, m_pPopupParent)).get(); PSUBSURFACE->m_pParent = this; ASSERT(PSUBSURFACE); @@ -220,6 +237,8 @@ Vector2D CSubsurface::coordsGlobal() { if (m_pWindowParent) coords += m_pWindowParent->m_vRealPosition.vec(); + else if (m_pPopupParent) + coords += m_pPopupParent->coordsGlobal(); return coords; } diff --git a/src/desktop/Subsurface.hpp b/src/desktop/Subsurface.hpp index 22692192..a8babd70 100644 --- a/src/desktop/Subsurface.hpp +++ b/src/desktop/Subsurface.hpp @@ -5,15 +5,17 @@ #include "WLSurface.hpp" class CWindow; -struct SXDGPopup; +class CPopup; class CSubsurface { public: // root dummy nodes CSubsurface(CWindow* pOwner); + CSubsurface(CPopup* pOwner); // real nodes CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner); + CSubsurface(wlr_subsurface* pSubsurface, CPopup* pOwner); ~CSubsurface(); @@ -29,7 +31,6 @@ class CSubsurface { void recheckDamageForSubsurfaces(); private: - DYNLISTENER(destroySubsurface); DYNLISTENER(commitSubsurface); DYNLISTENER(newSubsurface); @@ -44,9 +45,12 @@ class CSubsurface { CSubsurface* m_pParent = nullptr; CWindow* m_pWindowParent = nullptr; + CPopup* m_pPopupParent = nullptr; std::vector> m_vChildren; + bool m_bInert = false; + void initSignals(); void initExistingSubsurfaces(); void checkSiblingDamage(); diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 980142a0..69faf6c1 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -22,17 +22,6 @@ namespace Events { DYNLISTENFUNC(unmapLayerSurface); DYNLISTENFUNC(commitLayerSurface); - // Popups - DYNLISTENFUNC(newPopup); // LayerSurface - - DYNLISTENFUNC(newPopupXDG); - DYNLISTENFUNC(mapPopupXDG); - DYNLISTENFUNC(unmapPopupXDG); - DYNLISTENFUNC(destroyPopupXDG); - DYNLISTENFUNC(commitPopupXDG); - DYNLISTENFUNC(newPopupFromPopupXDG); - DYNLISTENFUNC(repositionPopupXDG); - // Surface XDG (window) LISTENER(newXDGToplevel); LISTENER(activateXDG); diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 5e9de8b4..7dbcc7b1 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -46,7 +46,6 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { layerSurface->hyprListener_destroyLayerSurface.initCallback(&WLRLAYERSURFACE->events.destroy, &Events::listener_destroyLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_mapLayerSurface.initCallback(&WLRLAYERSURFACE->surface->events.map, &Events::listener_mapLayerSurface, layerSurface, "layerSurface"); layerSurface->hyprListener_unmapLayerSurface.initCallback(&WLRLAYERSURFACE->surface->events.unmap, &Events::listener_unmapLayerSurface, layerSurface, "layerSurface"); - layerSurface->hyprListener_newPopup.initCallback(&WLRLAYERSURFACE->events.new_popup, &Events::listener_newPopup, layerSurface, "layerSurface"); layerSurface->layerSurface = WLRLAYERSURFACE; layerSurface->layer = WLRLAYERSURFACE->current.layer; @@ -87,7 +86,6 @@ void Events::listener_destroyLayerSurface(void* owner, void* data) { layersurface->hyprListener_destroyLayerSurface.removeCallback(); layersurface->hyprListener_mapLayerSurface.removeCallback(); layersurface->hyprListener_unmapLayerSurface.removeCallback(); - layersurface->hyprListener_newPopup.removeCallback(); // rearrange to fix the reserved areas if (PMONITOR) { @@ -113,6 +111,8 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { layersurface->keyboardExclusive = layersurface->layerSurface->current.keyboard_interactive; layersurface->surface = layersurface->layerSurface->surface; + layersurface->popupHead = std::make_unique(layersurface); + // fix if it changed its mon const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layersurface->layerSurface->output); @@ -184,6 +184,8 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { std::erase(g_pInputManager->m_dExclusiveLSes, layersurface); + layersurface->popupHead.reset(); + if (!g_pInputManager->m_dExclusiveLSes.empty()) g_pCompositor->focusSurface(g_pInputManager->m_dExclusiveLSes[0]->layerSurface->surface); diff --git a/src/events/Popups.cpp b/src/events/Popups.cpp deleted file mode 100644 index ca1787f5..00000000 --- a/src/events/Popups.cpp +++ /dev/null @@ -1,269 +0,0 @@ -#include "Events.hpp" - -#include "../Compositor.hpp" -#include "../helpers/WLClasses.hpp" -#include "../managers/input/InputManager.hpp" -#include "../render/Renderer.hpp" - -// --------------------------------------------- // -// _____ ____ _____ _ _ _____ _____ // -// | __ \ / __ \| __ \| | | | __ \ / ____| // -// | |__) | | | | |__) | | | | |__) | (___ // -// | ___/| | | | ___/| | | | ___/ \___ \ // -// | | | |__| | | | |__| | | ____) | // -// |_| \____/|_| \____/|_| |_____/ // -// // -// --------------------------------------------- // - -void addPopupGlobalCoords(void* pPopup, int* x, int* y) { - SXDGPopup* const PPOPUP = (SXDGPopup*)pPopup; - - auto curPopup = PPOPUP; - - int px = 0; - int py = 0; - - while (true) { - px += curPopup->popup->current.geometry.x; - py += curPopup->popup->current.geometry.y; - - if (curPopup == PPOPUP && PPOPUP->parentWindow) { - px -= curPopup->popup->base->current.geometry.x; - py -= curPopup->popup->base->current.geometry.y; - } - - if (curPopup->popup && !curPopup->parentPopup && !curPopup->parentWindow) { - const auto EXTENTSSURFACE = pixman_region32_extents(&curPopup->popup->base->surface->input_region); - px -= EXTENTSSURFACE->x1; - py -= EXTENTSSURFACE->y1; - } - - if (curPopup->parentPopup) { - curPopup = curPopup->parentPopup; - } else { - break; - } - } - - px += PPOPUP->lx; - py += PPOPUP->ly; - - *x += px; - *y += py; -} - -void createNewPopup(wlr_xdg_popup* popup, SXDGPopup* pHyprPopup) { - pHyprPopup->popup = popup; - - pHyprPopup->hyprListener_destroyPopupXDG.initCallback(&popup->events.destroy, &Events::listener_destroyPopupXDG, pHyprPopup, "HyprPopup"); - pHyprPopup->hyprListener_mapPopupXDG.initCallback(&popup->base->surface->events.map, &Events::listener_mapPopupXDG, pHyprPopup, "HyprPopup"); - pHyprPopup->hyprListener_unmapPopupXDG.initCallback(&popup->base->surface->events.unmap, &Events::listener_unmapPopupXDG, pHyprPopup, "HyprPopup"); - pHyprPopup->hyprListener_newPopupFromPopupXDG.initCallback(&popup->base->events.new_popup, &Events::listener_newPopupFromPopupXDG, pHyprPopup, "HyprPopup"); - pHyprPopup->hyprListener_commitPopupXDG.initCallback(&popup->base->surface->events.commit, &Events::listener_commitPopupXDG, pHyprPopup, "HyprPopup"); - pHyprPopup->hyprListener_repositionPopupXDG.initCallback(&popup->events.reposition, &Events::listener_repositionPopupXDG, pHyprPopup, "HyprPopup"); - - const auto PMONITOR = g_pCompositor->m_pLastMonitor; - - CBox box = {PMONITOR->vecPosition.x - pHyprPopup->lx, PMONITOR->vecPosition.y - pHyprPopup->ly, PMONITOR->vecSize.x, PMONITOR->vecSize.y}; - - wlr_xdg_popup_unconstrain_from_box(popup, box.pWlr()); - - pHyprPopup->monitor = PMONITOR; - - Debug::log(LOG, "Popup: Unconstrained from lx ly: {:j5}, pHyprPopup lx ly: {:.5f} {:.5f}", PMONITOR->vecPosition, (float)pHyprPopup->lx, (float)pHyprPopup->ly); -} - -void Events::listener_newPopup(void* owner, void* data) { - SLayerSurface* layersurface = (SLayerSurface*)owner; - - ASSERT(layersurface); - - Debug::log(LOG, "New layer popup created from surface {:x}", (uintptr_t)layersurface); - - const auto WLRPOPUP = (wlr_xdg_popup*)data; - - const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); - - const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); - - PNEWPOPUP->popup = WLRPOPUP; - PNEWPOPUP->lx = layersurface->position.x; - PNEWPOPUP->ly = layersurface->position.y; - PNEWPOPUP->monitor = PMONITOR; - PNEWPOPUP->parentLS = layersurface; - createNewPopup(WLRPOPUP, PNEWPOPUP); -} - -void Events::listener_newPopupXDG(void* owner, void* data) { - CWindow* PWINDOW = (CWindow*)owner; - - ASSERT(PWINDOW); - - if (!PWINDOW->m_bIsMapped) - return; - - Debug::log(LOG, "New layer popup created from XDG window {}", PWINDOW); - - const auto WLRPOPUP = (wlr_xdg_popup*)data; - - const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - - PNEWPOPUP->popup = WLRPOPUP; - PNEWPOPUP->lx = PWINDOW->m_vRealPosition.goalv().x; - PNEWPOPUP->ly = PWINDOW->m_vRealPosition.goalv().y; - PNEWPOPUP->parentWindow = PWINDOW; - PNEWPOPUP->monitor = PMONITOR; - createNewPopup(WLRPOPUP, PNEWPOPUP); -} - -void Events::listener_newPopupFromPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - - ASSERT(PPOPUP); - - if (PPOPUP->parentWindow) - Debug::log(LOG, "New popup created from XDG Window popup {:x} -> {}", (uintptr_t)PPOPUP, PPOPUP->parentWindow); - else - Debug::log(LOG, "New popup created from Non-Window popup {:x}", (uintptr_t)PPOPUP); - - const auto WLRPOPUP = (wlr_xdg_popup*)data; - - const auto PNEWPOPUP = g_pCompositor->m_vXDGPopups.emplace_back(std::make_unique()).get(); - - PNEWPOPUP->popup = WLRPOPUP; - PNEWPOPUP->parentPopup = PPOPUP; - PNEWPOPUP->lx = PPOPUP->lx; - PNEWPOPUP->ly = PPOPUP->ly; - PNEWPOPUP->parentWindow = PPOPUP->parentWindow; - PNEWPOPUP->monitor = PPOPUP->monitor; - - createNewPopup(WLRPOPUP, PNEWPOPUP); -} - -void Events::listener_mapPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - - ASSERT(PPOPUP); - - Debug::log(LOG, "New XDG Popup mapped at {} {}", (int)PPOPUP->lx, (int)PPOPUP->ly); - - if (PPOPUP->parentWindow) - PPOPUP->parentWindow->m_lPopupSurfaces.emplace_back(PPOPUP->popup->base->surface); - else if (PPOPUP->parentLS) - PPOPUP->parentLS->popupSurfaces.emplace_back(PPOPUP->popup->base->surface); - - //PPOPUP->pSurfaceTree = SubsurfaceTree::createTreeRoot(PPOPUP->popup->base->surface, addPopupGlobalCoords, PPOPUP, PPOPUP->parentWindow); - - int lx = 0, ly = 0; - addPopupGlobalCoords(PPOPUP, &lx, &ly); - - CBox extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); - extents.applyFromWlr(); - - g_pHyprRenderer->damageBox(lx - extents.x, ly - extents.y, extents.width + 2, extents.height + 2); - - if (PPOPUP->monitor) { - g_pCompositor->setPreferredScaleForSurface(PPOPUP->popup->base->surface, PPOPUP->monitor->scale); - g_pCompositor->setPreferredTransformForSurface(PPOPUP->popup->base->surface, PPOPUP->monitor->transform); - } - - // Debug::log(LOG, "XDG Popup got assigned a surfaceTreeNode {:x}", (uintptr_t)PPOPUP->pSurfaceTree); -} - -void Events::listener_repositionPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - - Debug::log(LOG, "XDG Popup {:x} asks for a reposition", (uintptr_t)PPOPUP); - - int lx = 0, ly = 0; - addPopupGlobalCoords(PPOPUP, &lx, &ly); - - CBox extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); - extents.applyFromWlr(); - - PPOPUP->lastPos = {lx - extents.x, ly - extents.y}; - PPOPUP->repositionRequested = true; - - const auto PMONITOR = g_pCompositor->m_pLastMonitor; - - CBox box = {PMONITOR->vecPosition.x - lx + PPOPUP->popup->current.geometry.x, PMONITOR->vecPosition.y - ly + PPOPUP->popup->current.geometry.y, PMONITOR->vecSize.x, - PMONITOR->vecSize.y}; - wlr_xdg_popup_unconstrain_from_box(PPOPUP->popup, box.pWlr()); -} - -void Events::listener_unmapPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - Debug::log(LOG, "XDG Popup unmapped"); - - ASSERT(PPOPUP); - - if (PPOPUP->popup->base->surface == g_pCompositor->m_pLastFocus) - g_pInputManager->releaseAllMouseButtons(); - - // SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); - - int lx = 0, ly = 0; - addPopupGlobalCoords(PPOPUP, &lx, &ly); - - CBox extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); - extents.applyFromWlr(); - - g_pHyprRenderer->damageBox(lx - extents.x, ly - extents.y, extents.width + 2, extents.height + 2); - - if (PPOPUP->parentWindow) - std::erase(PPOPUP->parentWindow->m_lPopupSurfaces, PPOPUP->popup->base->surface); - else if (PPOPUP->parentLS) - std::erase(PPOPUP->parentLS->popupSurfaces, PPOPUP->popup->base->surface); - - // PPOPUP->pSurfaceTree = nullptr; - - g_pInputManager->simulateMouseMovement(); // to focus and return back to an appropriate surface -} - -void Events::listener_commitPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - - if (PPOPUP->popup->base->initial_commit) { - wlr_xdg_surface_schedule_configure(PPOPUP->popup->base); - return; - } - - if (g_pCompositor->windowValidMapped(PPOPUP->parentWindow)) { - PPOPUP->lx = PPOPUP->parentWindow->m_vRealPosition.vec().x; - PPOPUP->ly = PPOPUP->parentWindow->m_vRealPosition.vec().y; - } - - int lx = 0, ly = 0; - addPopupGlobalCoords(PPOPUP, &lx, &ly); - - CBox extents; - wlr_surface_get_extends(PPOPUP->popup->base->surface, extents.pWlr()); - extents.applyFromWlr(); - - if (PPOPUP->repositionRequested) - g_pHyprRenderer->damageBox(PPOPUP->lastPos.x, PPOPUP->lastPos.y, extents.width + 2, extents.height + 2); - - PPOPUP->repositionRequested = false; - - g_pHyprRenderer->damageSurface(PPOPUP->popup->base->surface, lx, ly); -} - -void Events::listener_destroyPopupXDG(void* owner, void* data) { - SXDGPopup* PPOPUP = (SXDGPopup*)owner; - - ASSERT(PPOPUP); - - Debug::log(LOG, "Destroyed popup XDG {:x}", (uintptr_t)PPOPUP); - - // if (PPOPUP->pSurfaceTree) { - // SubsurfaceTree::destroySurfaceTree(PPOPUP->pSurfaceTree); - // PPOPUP->pSurfaceTree = nullptr; - // } - - std::erase_if(g_pCompositor->m_vXDGPopups, [&](std::unique_ptr& el) { return el.get() == PPOPUP; }); -} diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 162415b4..34a34cbd 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -488,7 +488,6 @@ void Events::listener_mapWindow(void* owner, void* data) { if (!PWINDOW->m_bIsX11) { PWINDOW->hyprListener_setTitleWindow.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.set_title, &Events::listener_setTitleWindow, PWINDOW, "XDG Window Late"); - PWINDOW->hyprListener_newPopupXDG.initCallback(&PWINDOW->m_uSurface.xdg->events.new_popup, &Events::listener_newPopupXDG, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_requestMaximize.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.request_maximize, &Events::listener_requestMaximize, PWINDOW, "XDG Window Late"); PWINDOW->hyprListener_requestMinimize.initCallback(&PWINDOW->m_uSurface.xdg->toplevel->events.request_minimize, &Events::listener_requestMinimize, PWINDOW, @@ -681,7 +680,6 @@ void Events::listener_unmapWindow(void* owner, void* data) { if (!PWINDOW->m_bIsX11) { Debug::log(LOG, "Unregistered late callbacks XDG"); PWINDOW->hyprListener_setTitleWindow.removeCallback(); - PWINDOW->hyprListener_newPopupXDG.removeCallback(); PWINDOW->hyprListener_requestMaximize.removeCallback(); PWINDOW->hyprListener_requestMinimize.removeCallback(); PWINDOW->hyprListener_requestMove.removeCallback(); @@ -833,7 +831,10 @@ void Events::listener_commitWindow(void* owner, void* data) { g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y, PWINDOW->m_bIsX11 ? 1.0 / PWINDOW->m_fX11SurfaceScaledBy : 1.0); - PWINDOW->m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + if (!PWINDOW->m_bIsX11) { + PWINDOW->m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + PWINDOW->m_pPopupHead->recheckTree(); + } if (PWINDOW->m_bIsX11 || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) return; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index e536c3d2..624625af 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -5,6 +5,7 @@ #include "wlr-layer-shell-unstable-v1-protocol.h" #include "../Window.hpp" #include "../desktop/Subsurface.hpp" +#include "../desktop/Popup.hpp" #include "AnimatedVariable.hpp" #include "../desktop/WLSurface.hpp" #include "Region.hpp" @@ -31,13 +32,14 @@ struct SLayerSurface { bool keyboardExclusive = false; CWLSurface surface; - std::list popupSurfaces; + + // desktop components + std::unique_ptr popupHead; DYNLISTENER(destroyLayerSurface); DYNLISTENER(mapLayerSurface); DYNLISTENER(unmapLayerSurface); DYNLISTENER(commitLayerSurface); - DYNLISTENER(newPopup); CBox geometry = {0, 0, 0, 0}; Vector2D position; @@ -199,32 +201,6 @@ struct SConstraint { class CMonitor; -struct SXDGPopup { - CWindow* parentWindow = nullptr; - SLayerSurface* parentLS = nullptr; - SXDGPopup* parentPopup = nullptr; - wlr_xdg_popup* popup = nullptr; - CMonitor* monitor = nullptr; - - DYNLISTENER(newPopupFromPopupXDG); - DYNLISTENER(destroyPopupXDG); - DYNLISTENER(mapPopupXDG); - DYNLISTENER(unmapPopupXDG); - DYNLISTENER(commitPopupXDG); - DYNLISTENER(repositionPopupXDG); - - double lx; - double ly; - - Vector2D lastPos = {}; - bool repositionRequested = false; - - // For the list lookup - bool operator==(const SXDGPopup& rhs) const { - return popup == rhs.popup; - } -}; - struct SSeat { wlr_seat* seat = nullptr; wl_client* exclusiveClient = nullptr; From bcec082a1c20da4b69d56b0f0f98e00ecb3b5c96 Mon Sep 17 00:00:00 2001 From: Anton Samokhvalov Date: Thu, 29 Feb 2024 18:01:56 +0300 Subject: [PATCH 0013/2897] build: fix libc++/clang build (#4886) --- src/helpers/WLClasses.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 624625af..b307191c 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -391,7 +391,7 @@ struct STearingController { DYNLISTENER(set); DYNLISTENER(destroy); - bool operator==(const STearingController& other) { + bool operator==(const STearingController& other) const { return pWlrHint == other.pWlrHint; } }; @@ -401,7 +401,7 @@ struct SShortcutInhibitor { DYNLISTENER(destroy); - bool operator==(const SShortcutInhibitor& other) { + bool operator==(const SShortcutInhibitor& other) const { return pWlrInhibitor == other.pWlrInhibitor; } }; From 6916d0a6a316d602ff766abe5abffacf929b6801 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 15:07:11 +0000 Subject: [PATCH 0014/2897] surface: unify owners --- src/Window.cpp | 3 +- src/desktop/Popup.cpp | 6 ++- src/desktop/Popup.hpp | 2 + src/desktop/Subsurface.cpp | 10 +++-- src/desktop/Subsurface.hpp | 2 + src/desktop/WLSurface.cpp | 86 +++++++++++++++++++++++++++++++++----- src/desktop/WLSurface.hpp | 35 ++++++++++++---- src/render/Renderer.cpp | 8 ++-- 8 files changed, 124 insertions(+), 28 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 6742be60..df357212 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -481,8 +481,7 @@ void CWindow::onUnmap() { void CWindow::onMap() { - m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this)); - m_pWLSurface.m_pOwner = this; + m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this), this); // JIC, reset the callbacks. If any are set, we'll make sure they are cleared so we don't accidentally unset them. (In case a window got remapped) m_vRealPosition.resetAllCallbacks(); diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index a4b63826..ad0a1a25 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -10,7 +10,7 @@ CPopup::CPopup(SLayerSurface* pOwner) : m_pLayerOwner(pOwner) { CPopup::CPopup(wlr_xdg_popup* popup, CPopup* pOwner) : m_pParent(pOwner), m_pWLR(popup) { m_pWLR->base->data = this; - m_sWLSurface.assign(popup->base->surface); + m_sWLSurface.assign(popup->base->surface, this); m_pLayerOwner = pOwner->m_pLayerOwner; m_pWindowOwner = pOwner->m_pWindowOwner; @@ -222,4 +222,8 @@ void CPopup::recheckChildrenRecursive() { c->onCommit(); c->recheckChildrenRecursive(); } +} + +Vector2D CPopup::size() { + return m_vLastSize; } \ No newline at end of file diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index 8279f7ed..48dae088 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -20,6 +20,8 @@ class CPopup { Vector2D coordsRelativeToParent(); Vector2D coordsGlobal(); + Vector2D size(); + void onNewPopup(wlr_xdg_popup* popup); void onDestroy(); void onMap(); diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index dde8d532..ab43f3c3 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -29,13 +29,13 @@ CSubsurface::CSubsurface(CPopup* pOwner) : m_pPopupParent(pOwner) { } CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CWindow* pOwner) : m_pSubsurface(pSubsurface), m_pWindowParent(pOwner) { - m_sWLSurface.assign(pSubsurface->surface); + m_sWLSurface.assign(pSubsurface->surface, this); initSignals(); initExistingSubsurfaces(); } CSubsurface::CSubsurface(wlr_subsurface* pSubsurface, CPopup* pOwner) : m_pSubsurface(pSubsurface), m_pPopupParent(pOwner) { - m_sWLSurface.assign(pSubsurface->surface); + m_sWLSurface.assign(pSubsurface->surface, this); initSignals(); initExistingSubsurfaces(); } @@ -254,4 +254,8 @@ void CSubsurface::initExistingSubsurfaces() { wl_list_for_each(wlrSubsurface, &m_sWLSurface.wlr()->current.subsurfaces_above, current.link) { ::onNewSubsurface(this, wlrSubsurface); } -} \ No newline at end of file +} + +Vector2D CSubsurface::size() { + return {m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; +} diff --git a/src/desktop/Subsurface.hpp b/src/desktop/Subsurface.hpp index a8babd70..ca02a6d5 100644 --- a/src/desktop/Subsurface.hpp +++ b/src/desktop/Subsurface.hpp @@ -22,6 +22,8 @@ class CSubsurface { Vector2D coordsRelativeToParent(); Vector2D coordsGlobal(); + Vector2D size(); + void onCommit(); void onDestroy(); void onNewSubsurface(wlr_subsurface* pSubsurface); diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp index 25f11feb..6773d761 100644 --- a/src/desktop/WLSurface.cpp +++ b/src/desktop/WLSurface.cpp @@ -1,14 +1,38 @@ #include "WLSurface.hpp" #include "../Compositor.hpp" -CWLSurface::CWLSurface(wlr_surface* pSurface) { - m_pWLRSurface = pSurface; - init(); -} - void CWLSurface::assign(wlr_surface* pSurface) { m_pWLRSurface = pSurface; init(); + m_bInert = false; +} + +void CWLSurface::assign(wlr_surface* pSurface, CWindow* pOwner) { + m_pWindowOwner = pOwner; + m_pWLRSurface = pSurface; + init(); + m_bInert = false; +} + +void CWLSurface::assign(wlr_surface* pSurface, SLayerSurface* pOwner) { + m_pLayerOwner = pOwner; + m_pWLRSurface = pSurface; + init(); + m_bInert = false; +} + +void CWLSurface::assign(wlr_surface* pSurface, CSubsurface* pOwner) { + m_pSubsurfaceOwner = pOwner; + m_pWLRSurface = pSurface; + init(); + m_bInert = false; +} + +void CWLSurface::assign(wlr_surface* pSurface, CPopup* pOwner) { + m_pPopupOwner = pOwner; + m_pWLRSurface = pSurface; + init(); + m_bInert = false; } void CWLSurface::unassign() { @@ -28,20 +52,20 @@ wlr_surface* CWLSurface::wlr() const { } bool CWLSurface::small() const { - if (!m_pOwner || !exists()) + if (!m_pWindowOwner || !exists()) return false; - return m_pOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1; + return m_pWindowOwner->m_vReportedSize.x > m_pWLRSurface->current.buffer_width + 1 || m_pWindowOwner->m_vReportedSize.y > m_pWLRSurface->current.buffer_height + 1; } Vector2D CWLSurface::correctSmallVec() const { - if (!m_pOwner || !exists() || !small() || m_bFillIgnoreSmall) + if (!m_pWindowOwner || !exists() || !small() || m_bFillIgnoreSmall) return {}; const auto SIZE = getViewporterCorrectedSize(); - return Vector2D{(m_pOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * - (m_pOwner->m_vRealSize.vec() / m_pOwner->m_vReportedSize); + return Vector2D{(m_pWindowOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pWindowOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * + (m_pWindowOwner->m_vRealSize.vec() / m_pWindowOwner->m_vReportedSize); } Vector2D CWLSurface::getViewporterCorrectedSize() const { @@ -81,7 +105,11 @@ void CWLSurface::destroy() { hyprListener_destroy.removeCallback(); m_pWLRSurface->data = nullptr; - m_pOwner = nullptr; + m_pWindowOwner = nullptr; + m_pLayerOwner = nullptr; + m_pPopupOwner = nullptr; + m_pSubsurfaceOwner = nullptr; + m_bInert = true; if (g_pCompositor && g_pCompositor->m_pLastFocus == m_pWLRSurface) g_pCompositor->m_pLastFocus = nullptr; @@ -107,4 +135,40 @@ void CWLSurface::init() { &m_pWLRSurface->events.destroy, [&](void* owner, void* data) { destroy(); }, this, "CWLSurface"); Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this); +} + +CWindow* CWLSurface::getWindow() { + return m_pWindowOwner; +} + +SLayerSurface* CWLSurface::getLayer() { + return m_pLayerOwner; +} + +CPopup* CWLSurface::getPopup() { + return m_pPopupOwner; +} + +CSubsurface* CWLSurface::getSubsurface() { + return m_pSubsurfaceOwner; +} + +bool CWLSurface::desktopComponent() { + return m_pLayerOwner || m_pWindowOwner || m_pSubsurfaceOwner || m_pPopupOwner; +} + +std::optional CWLSurface::getSurfaceBoxGlobal() { + if (!desktopComponent()) + return {}; + + if (m_pWindowOwner) + return m_pWindowOwner->getWindowMainSurfaceBox(); + if (m_pLayerOwner) + return m_pLayerOwner->geometry; + if (m_pPopupOwner) + return CBox{m_pPopupOwner->coordsGlobal(), m_pPopupOwner->size()}; + if (m_pSubsurfaceOwner) + return CBox{m_pSubsurfaceOwner->coordsGlobal(), m_pSubsurfaceOwner->size()}; + + return {}; } \ No newline at end of file diff --git a/src/desktop/WLSurface.hpp b/src/desktop/WLSurface.hpp index 15debd56..3e04b4b2 100644 --- a/src/desktop/WLSurface.hpp +++ b/src/desktop/WLSurface.hpp @@ -4,14 +4,21 @@ #include "../helpers/Region.hpp" class CWindow; +struct SLayerSurface; +class CSubsurface; +class CPopup; class CWLSurface { public: CWLSurface() = default; - CWLSurface(wlr_surface* pSurface); ~CWLSurface(); + // anonymous surfaces are non-desktop components, e.g. a cursor surface or a DnD void assign(wlr_surface* pSurface); + void assign(wlr_surface* pSurface, CWindow* pOwner); + void assign(wlr_surface* pSurface, SLayerSurface* pOwner); + void assign(wlr_surface* pSurface, CSubsurface* pOwner); + void assign(wlr_surface* pSurface, CPopup* pOwner); void unassign(); CWLSurface(const CWLSurface&) = delete; @@ -26,12 +33,18 @@ class CWLSurface { Vector2D getViewporterCorrectedSize() const; CRegion logicalDamage() const; + // getters for owners. + CWindow* getWindow(); + SLayerSurface* getLayer(); + CPopup* getPopup(); + CSubsurface* getSubsurface(); + + // desktop components misc utils + std::optional getSurfaceBoxGlobal(); + // allow stretching. Useful for plugins. bool m_bFillIgnoreSmall = false; - // if present, means this is a base surface of a window. Cleaned on unassign() - CWindow* m_pOwner = nullptr; - // track surface data and avoid dupes float m_fLastScale = 0; int m_iLastScale = 0; @@ -63,10 +76,18 @@ class CWLSurface { } private: - wlr_surface* m_pWLRSurface = nullptr; + bool m_bInert = true; - void destroy(); - void init(); + wlr_surface* m_pWLRSurface = nullptr; + + CWindow* m_pWindowOwner = nullptr; + SLayerSurface* m_pLayerOwner = nullptr; + CPopup* m_pPopupOwner = nullptr; + CSubsurface* m_pSubsurfaceOwner = nullptr; + + void destroy(); + void init(); + bool desktopComponent(); DYNLISTENER(destroy); }; \ No newline at end of file diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 4ffdecb4..fd1c3434 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -70,7 +70,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) // however, if surface buffer w / h < box, we need to adjust them auto* const PSURFACE = CWLSurface::surfaceFromWlr(surface); - if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees m_pOwner */) { + if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees m_pWindowOwner */) { const auto CORRECT = PSURFACE->correctSmallVec(); const auto SIZE = PSURFACE->getViewporterCorrectedSize(); @@ -78,8 +78,8 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) windowBox.x += CORRECT.x; windowBox.y += CORRECT.y; - windowBox.width = SIZE.x * (PSURFACE->m_pOwner->m_vRealSize.vec().x / PSURFACE->m_pOwner->m_vReportedSize.x); - windowBox.height = SIZE.y * (PSURFACE->m_pOwner->m_vRealSize.vec().y / PSURFACE->m_pOwner->m_vReportedSize.y); + windowBox.width = SIZE.x * (PSURFACE->getWindow()->m_vRealSize.vec().x / PSURFACE->getWindow()->m_vReportedSize.x); + windowBox.height = SIZE.y * (PSURFACE->getWindow()->m_vRealSize.vec().y / PSURFACE->getWindow()->m_vReportedSize.y); } else { windowBox.width = SIZE.x; windowBox.height = SIZE.y; @@ -1590,7 +1590,7 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou return; auto* const PSURFACE = CWLSurface::surfaceFromWlr(pSurface); - if (PSURFACE && PSURFACE->m_pOwner && PSURFACE->small()) { + if (PSURFACE && PSURFACE->small()) { const auto CORRECTION = PSURFACE->correctSmallVec(); x += CORRECTION.x; y += CORRECTION.y; From fbba8757cb1fbc79cc4b7744826a5a4cfca9264a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 16:15:48 +0000 Subject: [PATCH 0015/2897] window: remove unused list --- src/Window.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Window.hpp b/src/Window.hpp index f4809d11..620ae06d 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -209,8 +209,7 @@ class CWindow { DYNLISTENER(ackConfigure); // DYNLISTENER(newSubsurfaceWindow); - CWLSurface m_pWLSurface; - std::list m_lPopupSurfaces; + CWLSurface m_pWLSurface; union { wlr_xdg_surface* xdg; From 1698d336f2511ee7c93d0a520c7ba3491c831e8d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 17:23:44 +0000 Subject: [PATCH 0016/2897] core: fix crashes on access of deleted wlr_ surface ref fixes #4893 --- src/events/Windows.cpp | 2 ++ src/managers/XWaylandManager.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 34a34cbd..1c1521c9 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -891,6 +891,8 @@ void Events::listener_destroyWindow(void* owner, void* data) { PWINDOW->m_bReadyToDelete = true; + PWINDOW->m_uSurface.xdg = nullptr; + if (!PWINDOW->m_bFadingOut) { Debug::log(LOG, "Unmapped {} removed instantly", PWINDOW); g_pCompositor->removeWindowFromVectorSafe(PWINDOW); // most likely X11 unmanaged or sumn diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 1704ee99..2dcb3bcc 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -107,6 +107,9 @@ std::string CHyprXWaylandManager::getTitle(CWindow* pWindow) { return std::string(pWindow->m_uSurface.xwayland->title); } } else if (pWindow->m_uSurface.xdg) { + if (pWindow->m_bFadingOut || !pWindow->m_uSurface.xdg) + return ""; + if (pWindow->m_uSurface.xdg->toplevel && pWindow->m_uSurface.xdg->toplevel->title) { return std::string(pWindow->m_uSurface.xdg->toplevel->title); } @@ -128,6 +131,9 @@ std::string CHyprXWaylandManager::getAppIDClass(CWindow* pWindow) { return std::string(pWindow->m_uSurface.xwayland->_class); } } else if (pWindow->m_uSurface.xdg) { + if (pWindow->m_bFadingOut || !pWindow->m_uSurface.xdg) + return ""; + if (pWindow->m_uSurface.xdg->toplevel && pWindow->m_uSurface.xdg->toplevel->app_id) { return std::string(pWindow->m_uSurface.xdg->toplevel->app_id); } From e63b4b18aafbe285dc3b26a0e94f0e2f80fff3b3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 19:04:40 +0000 Subject: [PATCH 0017/2897] renderer: force a few render frames on init anim end fixes #4875 --- src/render/Renderer.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index fd1c3434..d356cd90 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1123,6 +1123,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { g_pHyprOpenGL->m_RenderData.mouseZoomFactor = zoomInFactorFirstLaunch; g_pHyprOpenGL->m_RenderData.mouseZoomUseMouse = false; g_pHyprOpenGL->m_RenderData.useNearestNeighbor = false; + pMonitor->forceFullFrames = 10; } CRegion damage, finalDamage; From f801d15947e151a8129ff82c99abb208e4767322 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 21:33:39 +0000 Subject: [PATCH 0018/2897] configmgr: fix compile on 32-bit archs fixes #4895 --- src/config/ConfigManager.cpp | 314 +++++++++++++++++------------------ 1 file changed, 157 insertions(+), 157 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 716882cf..2fd5aa28 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -302,140 +302,140 @@ CConfigManager::CConfigManager() { m_pConfig = std::make_unique(configPaths.begin()->c_str(), Hyprlang::SConfigOptions{.throwAllErrors = true, .allowMissingConfig = true}); m_pConfig->addConfigValue("general:sensitivity", {1.0f}); - m_pConfig->addConfigValue("general:apply_sens_to_raw", {0L}); - m_pConfig->addConfigValue("general:border_size", {1L}); - m_pConfig->addConfigValue("general:no_border_on_floating", {0L}); - m_pConfig->addConfigValue("general:border_part_of_window", {1L}); + m_pConfig->addConfigValue("general:apply_sens_to_raw", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:border_size", Hyprlang::INT{1}); + m_pConfig->addConfigValue("general:no_border_on_floating", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:border_part_of_window", Hyprlang::INT{1}); m_pConfig->addConfigValue("general:gaps_in", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "5"}); m_pConfig->addConfigValue("general:gaps_out", Hyprlang::CConfigCustomValueType{configHandleGapSet, configHandleGapDestroy, "20"}); - m_pConfig->addConfigValue("general:gaps_workspaces", {0L}); - m_pConfig->addConfigValue("general:cursor_inactive_timeout", {0L}); - m_pConfig->addConfigValue("general:no_cursor_warps", {0L}); - m_pConfig->addConfigValue("general:no_focus_fallback", {0L}); - m_pConfig->addConfigValue("general:resize_on_border", {0L}); - m_pConfig->addConfigValue("general:extend_border_grab_area", {15L}); - m_pConfig->addConfigValue("general:hover_icon_on_border", {1L}); + m_pConfig->addConfigValue("general:gaps_workspaces", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:cursor_inactive_timeout", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:no_cursor_warps", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:no_focus_fallback", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:resize_on_border", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:extend_border_grab_area", Hyprlang::INT{15}); + m_pConfig->addConfigValue("general:hover_icon_on_border", Hyprlang::INT{1}); m_pConfig->addConfigValue("general:layout", {"dwindle"}); - m_pConfig->addConfigValue("general:allow_tearing", {0L}); + m_pConfig->addConfigValue("general:allow_tearing", Hyprlang::INT{0}); - m_pConfig->addConfigValue("misc:disable_hyprland_logo", {0L}); - m_pConfig->addConfigValue("misc:disable_splash_rendering", {0L}); - m_pConfig->addConfigValue("misc:col.splash", {0x55ffffffL}); + m_pConfig->addConfigValue("misc:disable_hyprland_logo", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:disable_splash_rendering", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:col.splash", Hyprlang::INT{0x55ffffff}); m_pConfig->addConfigValue("misc:splash_font_family", {"Sans"}); - m_pConfig->addConfigValue("misc:force_default_wallpaper", {-1L}); - m_pConfig->addConfigValue("misc:vfr", {1L}); - m_pConfig->addConfigValue("misc:vrr", {0L}); - m_pConfig->addConfigValue("misc:mouse_move_enables_dpms", {0L}); - m_pConfig->addConfigValue("misc:key_press_enables_dpms", {0L}); - m_pConfig->addConfigValue("misc:always_follow_on_dnd", {1L}); - m_pConfig->addConfigValue("misc:layers_hog_keyboard_focus", {1L}); - m_pConfig->addConfigValue("misc:animate_manual_resizes", {0L}); - m_pConfig->addConfigValue("misc:animate_mouse_windowdragging", {0L}); - m_pConfig->addConfigValue("misc:disable_autoreload", {0L}); - m_pConfig->addConfigValue("misc:enable_swallow", {0L}); + m_pConfig->addConfigValue("misc:force_default_wallpaper", Hyprlang::INT{-1}); + m_pConfig->addConfigValue("misc:vfr", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:vrr", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:mouse_move_enables_dpms", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:key_press_enables_dpms", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:always_follow_on_dnd", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:layers_hog_keyboard_focus", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:animate_manual_resizes", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:animate_mouse_windowdragging", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:disable_autoreload", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:enable_swallow", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:swallow_regex", {STRVAL_EMPTY}); m_pConfig->addConfigValue("misc:swallow_exception_regex", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("misc:focus_on_activate", {0L}); - m_pConfig->addConfigValue("misc:no_direct_scanout", {1L}); - m_pConfig->addConfigValue("misc:hide_cursor_on_touch", {1L}); - m_pConfig->addConfigValue("misc:mouse_move_focuses_monitor", {1L}); - m_pConfig->addConfigValue("misc:render_ahead_of_time", {0L}); - m_pConfig->addConfigValue("misc:render_ahead_safezone", {1L}); + m_pConfig->addConfigValue("misc:focus_on_activate", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:no_direct_scanout", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:hide_cursor_on_touch", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:mouse_move_focuses_monitor", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:render_ahead_of_time", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:render_ahead_safezone", Hyprlang::INT{1}); m_pConfig->addConfigValue("misc:cursor_zoom_factor", {1.f}); - m_pConfig->addConfigValue("misc:cursor_zoom_rigid", {0L}); - m_pConfig->addConfigValue("misc:allow_session_lock_restore", {0L}); - m_pConfig->addConfigValue("misc:close_special_on_empty", {1L}); - m_pConfig->addConfigValue("misc:background_color", {0xff111111L}); - m_pConfig->addConfigValue("misc:new_window_takes_over_fullscreen", {0L}); + m_pConfig->addConfigValue("misc:cursor_zoom_rigid", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:allow_session_lock_restore", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:close_special_on_empty", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:background_color", Hyprlang::INT{0xff111111}); + m_pConfig->addConfigValue("misc:new_window_takes_over_fullscreen", Hyprlang::INT{0}); - m_pConfig->addConfigValue("group:insert_after_current", {1L}); - m_pConfig->addConfigValue("group:focus_removed_window", {1L}); - m_pConfig->addConfigValue("group:groupbar:enabled", {1L}); + m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); + m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); + m_pConfig->addConfigValue("group:groupbar:enabled", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:groupbar:font_family", {"Sans"}); - m_pConfig->addConfigValue("group:groupbar:font_size", {8L}); - m_pConfig->addConfigValue("group:groupbar:gradients", {1L}); - m_pConfig->addConfigValue("group:groupbar:height", {14L}); - m_pConfig->addConfigValue("group:groupbar:priority", {3L}); - m_pConfig->addConfigValue("group:groupbar:render_titles", {1L}); - m_pConfig->addConfigValue("group:groupbar:scrolling", {1L}); - m_pConfig->addConfigValue("group:groupbar:text_color", {0xffffffffL}); + m_pConfig->addConfigValue("group:groupbar:font_size", Hyprlang::INT{8}); + m_pConfig->addConfigValue("group:groupbar:gradients", Hyprlang::INT{1}); + m_pConfig->addConfigValue("group:groupbar:height", Hyprlang::INT{14}); + m_pConfig->addConfigValue("group:groupbar:priority", Hyprlang::INT{3}); + m_pConfig->addConfigValue("group:groupbar:render_titles", Hyprlang::INT{1}); + m_pConfig->addConfigValue("group:groupbar:scrolling", Hyprlang::INT{1}); + m_pConfig->addConfigValue("group:groupbar:text_color", Hyprlang::INT{0xffffffff}); - m_pConfig->addConfigValue("debug:int", {0L}); - m_pConfig->addConfigValue("debug:log_damage", {0L}); - m_pConfig->addConfigValue("debug:overlay", {0L}); - m_pConfig->addConfigValue("debug:damage_blink", {0L}); - m_pConfig->addConfigValue("debug:disable_logs", {1L}); - m_pConfig->addConfigValue("debug:disable_time", {1L}); - m_pConfig->addConfigValue("debug:enable_stdout_logs", {0L}); + m_pConfig->addConfigValue("debug:int", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:log_damage", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:overlay", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:damage_blink", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:disable_logs", Hyprlang::INT{1}); + m_pConfig->addConfigValue("debug:disable_time", Hyprlang::INT{1}); + m_pConfig->addConfigValue("debug:enable_stdout_logs", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:damage_tracking", {(Hyprlang::INT)DAMAGE_TRACKING_FULL}); - m_pConfig->addConfigValue("debug:manual_crash", {0L}); - m_pConfig->addConfigValue("debug:suppress_errors", {0L}); - m_pConfig->addConfigValue("debug:watchdog_timeout", {5L}); - m_pConfig->addConfigValue("debug:disable_scale_checks", {0L}); + m_pConfig->addConfigValue("debug:manual_crash", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:suppress_errors", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:watchdog_timeout", Hyprlang::INT{5}); + m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0}); - m_pConfig->addConfigValue("decoration:rounding", {0L}); - m_pConfig->addConfigValue("decoration:blur:enabled", {1L}); - m_pConfig->addConfigValue("decoration:blur:size", {8L}); - m_pConfig->addConfigValue("decoration:blur:passes", {1L}); - m_pConfig->addConfigValue("decoration:blur:ignore_opacity", {0L}); - m_pConfig->addConfigValue("decoration:blur:new_optimizations", {1L}); - m_pConfig->addConfigValue("decoration:blur:xray", {0L}); + m_pConfig->addConfigValue("decoration:rounding", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:blur:enabled", Hyprlang::INT{1}); + m_pConfig->addConfigValue("decoration:blur:size", Hyprlang::INT{8}); + m_pConfig->addConfigValue("decoration:blur:passes", Hyprlang::INT{1}); + m_pConfig->addConfigValue("decoration:blur:ignore_opacity", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:blur:new_optimizations", Hyprlang::INT{1}); + m_pConfig->addConfigValue("decoration:blur:xray", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:contrast", {0.8916F}); m_pConfig->addConfigValue("decoration:blur:brightness", {1.0F}); m_pConfig->addConfigValue("decoration:blur:vibrancy", {0.1696F}); m_pConfig->addConfigValue("decoration:blur:vibrancy_darkness", {0.0F}); m_pConfig->addConfigValue("decoration:blur:noise", {0.0117F}); - m_pConfig->addConfigValue("decoration:blur:special", {0L}); - m_pConfig->addConfigValue("decoration:blur:popups", {0L}); + m_pConfig->addConfigValue("decoration:blur:special", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:blur:popups", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:blur:popups_ignorealpha", {0.2F}); m_pConfig->addConfigValue("decoration:active_opacity", {1.F}); m_pConfig->addConfigValue("decoration:inactive_opacity", {1.F}); m_pConfig->addConfigValue("decoration:fullscreen_opacity", {1.F}); - m_pConfig->addConfigValue("decoration:no_blur_on_oversized", {0L}); - m_pConfig->addConfigValue("decoration:drop_shadow", {1L}); - m_pConfig->addConfigValue("decoration:shadow_range", {4L}); - m_pConfig->addConfigValue("decoration:shadow_render_power", {3L}); - m_pConfig->addConfigValue("decoration:shadow_ignore_window", {1L}); + m_pConfig->addConfigValue("decoration:no_blur_on_oversized", Hyprlang::INT{0}); + m_pConfig->addConfigValue("decoration:drop_shadow", Hyprlang::INT{1}); + m_pConfig->addConfigValue("decoration:shadow_range", Hyprlang::INT{4}); + m_pConfig->addConfigValue("decoration:shadow_render_power", Hyprlang::INT{3}); + m_pConfig->addConfigValue("decoration:shadow_ignore_window", Hyprlang::INT{1}); m_pConfig->addConfigValue("decoration:shadow_offset", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("decoration:shadow_scale", {1.f}); - m_pConfig->addConfigValue("decoration:col.shadow", {0xee1a1a1aL}); + m_pConfig->addConfigValue("decoration:col.shadow", Hyprlang::INT{0xee1a1a1a}); m_pConfig->addConfigValue("decoration:col.shadow_inactive", {(Hyprlang::INT)INT_MAX}); - m_pConfig->addConfigValue("decoration:dim_inactive", {0L}); + m_pConfig->addConfigValue("decoration:dim_inactive", Hyprlang::INT{0}); m_pConfig->addConfigValue("decoration:dim_strength", {0.5f}); m_pConfig->addConfigValue("decoration:dim_special", {0.2f}); m_pConfig->addConfigValue("decoration:dim_around", {0.4f}); m_pConfig->addConfigValue("decoration:screen_shader", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("dwindle:pseudotile", {0L}); - m_pConfig->addConfigValue("dwindle:force_split", {0L}); - m_pConfig->addConfigValue("dwindle:permanent_direction_override", {0L}); - m_pConfig->addConfigValue("dwindle:preserve_split", {0L}); + m_pConfig->addConfigValue("dwindle:pseudotile", Hyprlang::INT{0}); + m_pConfig->addConfigValue("dwindle:force_split", Hyprlang::INT{0}); + m_pConfig->addConfigValue("dwindle:permanent_direction_override", Hyprlang::INT{0}); + m_pConfig->addConfigValue("dwindle:preserve_split", Hyprlang::INT{0}); m_pConfig->addConfigValue("dwindle:special_scale_factor", {1.f}); m_pConfig->addConfigValue("dwindle:split_width_multiplier", {1.0f}); - m_pConfig->addConfigValue("dwindle:no_gaps_when_only", {0L}); - m_pConfig->addConfigValue("dwindle:use_active_for_splits", {1L}); + m_pConfig->addConfigValue("dwindle:no_gaps_when_only", Hyprlang::INT{0}); + m_pConfig->addConfigValue("dwindle:use_active_for_splits", Hyprlang::INT{1}); m_pConfig->addConfigValue("dwindle:default_split_ratio", {1.f}); - m_pConfig->addConfigValue("dwindle:smart_split", {0L}); - m_pConfig->addConfigValue("dwindle:smart_resizing", {1L}); + m_pConfig->addConfigValue("dwindle:smart_split", Hyprlang::INT{0}); + m_pConfig->addConfigValue("dwindle:smart_resizing", Hyprlang::INT{1}); m_pConfig->addConfigValue("master:special_scale_factor", {1.f}); m_pConfig->addConfigValue("master:mfact", {0.55f}); - m_pConfig->addConfigValue("master:new_is_master", {1L}); - m_pConfig->addConfigValue("master:always_center_master", {0L}); - m_pConfig->addConfigValue("master:new_on_top", {0L}); - m_pConfig->addConfigValue("master:no_gaps_when_only", {0L}); + m_pConfig->addConfigValue("master:new_is_master", Hyprlang::INT{1}); + m_pConfig->addConfigValue("master:always_center_master", Hyprlang::INT{0}); + m_pConfig->addConfigValue("master:new_on_top", Hyprlang::INT{0}); + m_pConfig->addConfigValue("master:no_gaps_when_only", Hyprlang::INT{0}); m_pConfig->addConfigValue("master:orientation", {"left"}); - m_pConfig->addConfigValue("master:inherit_fullscreen", {1L}); - m_pConfig->addConfigValue("master:allow_small_split", {0L}); - m_pConfig->addConfigValue("master:smart_resizing", {1L}); - m_pConfig->addConfigValue("master:drop_at_cursor", {1L}); + m_pConfig->addConfigValue("master:inherit_fullscreen", Hyprlang::INT{1}); + m_pConfig->addConfigValue("master:allow_small_split", Hyprlang::INT{0}); + m_pConfig->addConfigValue("master:smart_resizing", Hyprlang::INT{1}); + m_pConfig->addConfigValue("master:drop_at_cursor", Hyprlang::INT{1}); - m_pConfig->addConfigValue("animations:enabled", {1L}); - m_pConfig->addConfigValue("animations:first_launch_animation", {1L}); + m_pConfig->addConfigValue("animations:enabled", Hyprlang::INT{1}); + m_pConfig->addConfigValue("animations:first_launch_animation", Hyprlang::INT{1}); - m_pConfig->addConfigValue("input:follow_mouse", {1L}); - m_pConfig->addConfigValue("input:mouse_refocus", {1L}); - m_pConfig->addConfigValue("input:special_fallthrough", {0L}); + m_pConfig->addConfigValue("input:follow_mouse", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:mouse_refocus", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:special_fallthrough", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:sensitivity", {0.f}); m_pConfig->addConfigValue("input:accel_profile", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:kb_file", {STRVAL_EMPTY}); @@ -444,65 +444,65 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("input:kb_options", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:kb_rules", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:kb_model", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("input:repeat_rate", {25L}); - m_pConfig->addConfigValue("input:repeat_delay", {600L}); - m_pConfig->addConfigValue("input:natural_scroll", {0L}); - m_pConfig->addConfigValue("input:numlock_by_default", {0L}); - m_pConfig->addConfigValue("input:resolve_binds_by_sym", {0L}); - m_pConfig->addConfigValue("input:force_no_accel", {0L}); - m_pConfig->addConfigValue("input:float_switch_override_focus", {1L}); - m_pConfig->addConfigValue("input:left_handed", {0L}); + m_pConfig->addConfigValue("input:repeat_rate", Hyprlang::INT{25}); + m_pConfig->addConfigValue("input:repeat_delay", Hyprlang::INT{600}); + m_pConfig->addConfigValue("input:natural_scroll", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:numlock_by_default", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:resolve_binds_by_sym", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:force_no_accel", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:float_switch_override_focus", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:left_handed", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:scroll_method", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("input:scroll_button", {0L}); - m_pConfig->addConfigValue("input:scroll_button_lock", {0L}); + m_pConfig->addConfigValue("input:scroll_button", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:scroll_button_lock", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:scroll_points", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("input:touchpad:natural_scroll", {0L}); - m_pConfig->addConfigValue("input:touchpad:disable_while_typing", {1L}); - m_pConfig->addConfigValue("input:touchpad:clickfinger_behavior", {0L}); + m_pConfig->addConfigValue("input:touchpad:natural_scroll", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:touchpad:disable_while_typing", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:touchpad:clickfinger_behavior", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:touchpad:tap_button_map", {STRVAL_EMPTY}); - m_pConfig->addConfigValue("input:touchpad:middle_button_emulation", {0L}); - m_pConfig->addConfigValue("input:touchpad:tap-to-click", {1L}); - m_pConfig->addConfigValue("input:touchpad:tap-and-drag", {1L}); - m_pConfig->addConfigValue("input:touchpad:drag_lock", {0L}); + m_pConfig->addConfigValue("input:touchpad:middle_button_emulation", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:touchpad:tap-to-click", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:touchpad:tap-and-drag", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:touchpad:drag_lock", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:touchpad:scroll_factor", {1.f}); - m_pConfig->addConfigValue("input:touchdevice:transform", {0L}); + m_pConfig->addConfigValue("input:touchdevice:transform", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:touchdevice:output", {"[[Auto]]"}); - m_pConfig->addConfigValue("input:touchdevice:enabled", {1L}); - m_pConfig->addConfigValue("input:tablet:transform", {0L}); + m_pConfig->addConfigValue("input:touchdevice:enabled", Hyprlang::INT{1}); + m_pConfig->addConfigValue("input:tablet:transform", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:tablet:output", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:tablet:region_position", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("input:tablet:region_size", Hyprlang::VEC2{0, 0}); - m_pConfig->addConfigValue("input:tablet:relative_input", {0L}); + m_pConfig->addConfigValue("input:tablet:relative_input", Hyprlang::INT{0}); - m_pConfig->addConfigValue("binds:pass_mouse_when_bound", {0L}); - m_pConfig->addConfigValue("binds:scroll_event_delay", {300L}); - m_pConfig->addConfigValue("binds:workspace_back_and_forth", {0L}); - m_pConfig->addConfigValue("binds:allow_workspace_cycles", {0L}); - m_pConfig->addConfigValue("binds:workspace_center_on", {1L}); - m_pConfig->addConfigValue("binds:focus_preferred_method", {0L}); - m_pConfig->addConfigValue("binds:ignore_group_lock", {0L}); - m_pConfig->addConfigValue("binds:movefocus_cycles_fullscreen", {1L}); + m_pConfig->addConfigValue("binds:pass_mouse_when_bound", Hyprlang::INT{0}); + m_pConfig->addConfigValue("binds:scroll_event_delay", Hyprlang::INT{300}); + m_pConfig->addConfigValue("binds:workspace_back_and_forth", Hyprlang::INT{0}); + m_pConfig->addConfigValue("binds:allow_workspace_cycles", Hyprlang::INT{0}); + m_pConfig->addConfigValue("binds:workspace_center_on", Hyprlang::INT{1}); + m_pConfig->addConfigValue("binds:focus_preferred_method", Hyprlang::INT{0}); + m_pConfig->addConfigValue("binds:ignore_group_lock", Hyprlang::INT{0}); + m_pConfig->addConfigValue("binds:movefocus_cycles_fullscreen", Hyprlang::INT{1}); - m_pConfig->addConfigValue("gestures:workspace_swipe", {0L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_fingers", {3L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_distance", {300L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_invert", {1L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_min_speed_to_force", {30L}); + m_pConfig->addConfigValue("gestures:workspace_swipe", Hyprlang::INT{0}); + m_pConfig->addConfigValue("gestures:workspace_swipe_fingers", Hyprlang::INT{3}); + m_pConfig->addConfigValue("gestures:workspace_swipe_distance", Hyprlang::INT{300}); + m_pConfig->addConfigValue("gestures:workspace_swipe_invert", Hyprlang::INT{1}); + m_pConfig->addConfigValue("gestures:workspace_swipe_min_speed_to_force", Hyprlang::INT{30}); m_pConfig->addConfigValue("gestures:workspace_swipe_cancel_ratio", {0.5f}); - m_pConfig->addConfigValue("gestures:workspace_swipe_create_new", {1L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_direction_lock", {1L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_direction_lock_threshold", {10L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_forever", {0L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_numbered", {0L}); - m_pConfig->addConfigValue("gestures:workspace_swipe_use_r", {0L}); + m_pConfig->addConfigValue("gestures:workspace_swipe_create_new", Hyprlang::INT{1}); + m_pConfig->addConfigValue("gestures:workspace_swipe_direction_lock", Hyprlang::INT{1}); + m_pConfig->addConfigValue("gestures:workspace_swipe_direction_lock_threshold", Hyprlang::INT{10}); + m_pConfig->addConfigValue("gestures:workspace_swipe_forever", Hyprlang::INT{0}); + m_pConfig->addConfigValue("gestures:workspace_swipe_numbered", Hyprlang::INT{0}); + m_pConfig->addConfigValue("gestures:workspace_swipe_use_r", Hyprlang::INT{0}); - m_pConfig->addConfigValue("xwayland:use_nearest_neighbor", {1L}); - m_pConfig->addConfigValue("xwayland:force_zero_scaling", {0L}); + m_pConfig->addConfigValue("xwayland:use_nearest_neighbor", Hyprlang::INT{1}); + m_pConfig->addConfigValue("xwayland:force_zero_scaling", Hyprlang::INT{0}); - m_pConfig->addConfigValue("opengl:nvidia_anti_flicker", {1L}); - m_pConfig->addConfigValue("opengl:force_introspection", {2L}); + m_pConfig->addConfigValue("opengl:nvidia_anti_flicker", Hyprlang::INT{1}); + m_pConfig->addConfigValue("opengl:force_introspection", Hyprlang::INT{2}); - m_pConfig->addConfigValue("autogenerated", {0L}); + m_pConfig->addConfigValue("autogenerated", Hyprlang::INT{0}); m_pConfig->addConfigValue("general:col.active_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffffffff"}); m_pConfig->addConfigValue("general:col.inactive_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xff444444"}); @@ -529,29 +529,29 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "kb_options", {STRVAL_EMPTY}); m_pConfig->addSpecialConfigValue("device", "kb_rules", {STRVAL_EMPTY}); m_pConfig->addSpecialConfigValue("device", "kb_model", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "repeat_rate", {25L}); - m_pConfig->addSpecialConfigValue("device", "repeat_delay", {600L}); - m_pConfig->addSpecialConfigValue("device", "natural_scroll", {0L}); + m_pConfig->addSpecialConfigValue("device", "repeat_rate", Hyprlang::INT{25}); + m_pConfig->addSpecialConfigValue("device", "repeat_delay", Hyprlang::INT{600}); + m_pConfig->addSpecialConfigValue("device", "natural_scroll", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "tap_button_map", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "numlock_by_default", {0L}); - m_pConfig->addSpecialConfigValue("device", "resolve_binds_by_sym", {0L}); - m_pConfig->addSpecialConfigValue("device", "disable_while_typing", {1L}); - m_pConfig->addSpecialConfigValue("device", "clickfinger_behavior", {0L}); - m_pConfig->addSpecialConfigValue("device", "middle_button_emulation", {0L}); - m_pConfig->addSpecialConfigValue("device", "tap-to-click", {1L}); - m_pConfig->addSpecialConfigValue("device", "tap-and-drag", {1L}); - m_pConfig->addSpecialConfigValue("device", "drag_lock", {0L}); - m_pConfig->addSpecialConfigValue("device", "left_handed", {0L}); + m_pConfig->addSpecialConfigValue("device", "numlock_by_default", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "resolve_binds_by_sym", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "disable_while_typing", Hyprlang::INT{1}); + m_pConfig->addSpecialConfigValue("device", "clickfinger_behavior", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "middle_button_emulation", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "tap-to-click", Hyprlang::INT{1}); + m_pConfig->addSpecialConfigValue("device", "tap-and-drag", Hyprlang::INT{1}); + m_pConfig->addSpecialConfigValue("device", "drag_lock", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "left_handed", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "scroll_method", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "scroll_button", {0L}); - m_pConfig->addSpecialConfigValue("device", "scroll_button_lock", {0L}); + m_pConfig->addSpecialConfigValue("device", "scroll_button", Hyprlang::INT{0}); + m_pConfig->addSpecialConfigValue("device", "scroll_button_lock", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "scroll_points", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "transform", {0L}); + m_pConfig->addSpecialConfigValue("device", "transform", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "enabled", {1L}); // only for mice, touchpads, and touchdevices + m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets m_pConfig->addSpecialConfigValue("device", "region_size", Hyprlang::VEC2{0, 0}); // only for tablets - m_pConfig->addSpecialConfigValue("device", "relative_input", {0L}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets // keywords m_pConfig->registerHandler(&::handleRawExec, "exec", {false}); From f590505daf90dfb4059289a906863b59663e70a6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 29 Feb 2024 21:51:50 +0000 Subject: [PATCH 0019/2897] popup: minor fixes to xdg geometries fixes #4900 --- src/desktop/Popup.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index ad0a1a25..7c6eb1c9 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -100,10 +100,12 @@ void CPopup::onDestroy() { } void CPopup::onMap() { - m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + m_vLastSize = {m_pWLR->base->current.geometry.width, m_pWLR->base->current.geometry.height}; const auto COORDS = coordsGlobal(); - CBox box = {COORDS, m_vLastSize}; + CBox box; + wlr_surface_get_extends(m_sWLSurface.wlr(), box.pWlr()); + box.applyFromWlr().translate(COORDS); g_pHyprRenderer->damageBox(&box); m_vLastPos = coordsRelativeToParent(); @@ -116,10 +118,12 @@ void CPopup::onMap() { } void CPopup::onUnmap() { - m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + m_vLastSize = {m_pWLR->base->current.geometry.width, m_pWLR->base->current.geometry.height}; const auto COORDS = coordsGlobal(); - CBox box = {COORDS, m_vLastSize}; + CBox box; + wlr_surface_get_extends(m_sWLSurface.wlr(), box.pWlr()); + box.applyFromWlr().translate(COORDS); g_pHyprRenderer->damageBox(&box); m_pSubsurfaceHead.reset(); @@ -136,10 +140,10 @@ void CPopup::onCommit() { const auto COORDS = coordsGlobal(); const auto COORDSLOCAL = coordsRelativeToParent(); - if (m_vLastSize != Vector2D{m_pWLR->current.geometry.width, m_pWLR->current.geometry.height} || m_bRequestedReposition || m_vLastPos != COORDSLOCAL) { + if (m_vLastSize != Vector2D{m_pWLR->base->current.geometry.width, m_pWLR->base->current.geometry.height} || m_bRequestedReposition || m_vLastPos != COORDSLOCAL) { CBox box = {localToGlobal(m_vLastPos), m_vLastSize}; g_pHyprRenderer->damageBox(&box); - m_vLastSize = {m_pWLR->current.geometry.width, m_pWLR->current.geometry.height}; + m_vLastSize = {m_pWLR->base->current.geometry.width, m_pWLR->base->current.geometry.height}; box = {COORDS, m_vLastSize}; g_pHyprRenderer->damageBox(&box); @@ -179,6 +183,8 @@ Vector2D CPopup::coordsRelativeToParent() { CPopup* current = this; + offset -= {m_pWLR->base->current.geometry.x, m_pWLR->base->current.geometry.y}; + while (current->m_pParent) { offset += {current->m_sWLSurface.wlr()->current.dx, current->m_sWLSurface.wlr()->current.dy}; From 4937352761525de4b034e5f0152261ff5e7552f3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 1 Mar 2024 14:14:28 +0000 Subject: [PATCH 0020/2897] makefile: add asan --- Makefile | 21 +++++++++++++++++++++ scripts/hyprlandStaticAsan.diff | 21 +++++++++++++++++++++ scripts/waylandStatic.diff | 23 +++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 scripts/hyprlandStaticAsan.diff create mode 100644 scripts/waylandStatic.diff diff --git a/Makefile b/Makefile index 9c5e94d5..c893a16a 100644 --- a/Makefile +++ b/Makefile @@ -106,3 +106,24 @@ man: --variable=section:1 \ --from rst \ --to man > ./docs/hyprctl.1 + +asan: + @echo -en "!!WARNING!!\nOnly run this in the TTY.\n" + @pidof Hyprland > /dev/null && echo -ne "Refusing to run with Hyprland running.\n" || echo "" + @pidof Hyprland > /dev/null && exit 1 || echo "" + + rm -rf ./wayland + git reset --hard + + git clone --recursive https://gitlab.freedesktop.org/wayland/wayland + cd wayland && patch -p1 < ../scripts/waylandStatic.diff && meson setup build --buildtype=debug -Db_sanitize=address -Ddocumentation=false && ninja -C build && cd .. + cp ./wayland/build/src/libwayland-server.a . + @echo "Wayland done" + + patch -p1 < ./scripts/hyprlandStaticAsan.diff + cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Debug -DWITH_ASAN:STRING=True -DUSE_TRACY:STRING=False -DUSE_TRACY_GPU:STRING=False -S . -B ./build -G Ninja + cmake --build ./build --config Debug --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + @echo "Hyprland done" + + ASAN_OPTIONS="detect_odr_violation=0,log_path=asan.log" HYPRLAND_NO_CRASHREPORTER=1 ./build/Hyprland + diff --git a/scripts/hyprlandStaticAsan.diff b/scripts/hyprlandStaticAsan.diff new file mode 100644 index 00000000..5499f793 --- /dev/null +++ b/scripts/hyprlandStaticAsan.diff @@ -0,0 +1,21 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index 857e21de..122d6a78 100755 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -101,7 +101,7 @@ message(STATUS "Checking deps...") + find_package(Threads REQUIRED) + find_package(PkgConfig REQUIRED) + find_package(OpenGL REQUIRED) +-pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2) # we do not check for wlroots, as we provide it ourselves ++pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 libffi) # we do not check for wlroots, as we provide it ourselves + + file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") + +@@ -121,6 +121,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) + message(STATUS "Enabling ASan") + + target_link_libraries(Hyprland asan) ++ target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/libwayland-server.a) + target_compile_options(Hyprland PUBLIC -fsanitize=address) + endif() + \ No newline at end of file diff --git a/scripts/waylandStatic.diff b/scripts/waylandStatic.diff new file mode 100644 index 00000000..04aeda23 --- /dev/null +++ b/scripts/waylandStatic.diff @@ -0,0 +1,23 @@ +diff --git a/src/meson.build b/src/meson.build +index 5d04334..6645eec 100644 +--- a/src/meson.build ++++ b/src/meson.build +@@ -170,7 +170,7 @@ if get_option('libraries') + error('We probably need to bump the SONAME of libwayland-server and -client') + endif + +- wayland_server = library( ++ wayland_server = static_library( + 'wayland-server', + sources: [ + wayland_server_protocol_core_h, +@@ -180,9 +180,6 @@ if get_option('libraries') + 'wayland-shm.c', + 'event-loop.c' + ], +- # To avoid an unnecessary SONAME bump, wayland 1.x.y produces +- # libwayland-server.so.0.x.y. +- version: '.'.join(['0', wayland_version[1], wayland_version[2]]), + dependencies: [ + epoll_dep, + ffi_dep, From 555afea73c87f8e2bb374d1112431bb3a6f451dd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 1 Mar 2024 14:16:56 +0000 Subject: [PATCH 0021/2897] makefile: add config to make asan --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index c893a16a..c29f20a0 100644 --- a/Makefile +++ b/Makefile @@ -125,5 +125,5 @@ asan: cmake --build ./build --config Debug --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` @echo "Hyprland done" - ASAN_OPTIONS="detect_odr_violation=0,log_path=asan.log" HYPRLAND_NO_CRASHREPORTER=1 ./build/Hyprland + ASAN_OPTIONS="detect_odr_violation=0,log_path=asan.log" HYPRLAND_NO_CRASHREPORTER=1 ./build/Hyprland -c ~/.config/hypr/hyprland.conf From 6e3a494d1ddbdcffaee39d78e7d66d00a4cd350d Mon Sep 17 00:00:00 2001 From: Brett Alcox Date: Fri, 1 Mar 2024 14:07:36 -0600 Subject: [PATCH 0022/2897] core: add additional headers for Popup.cpp and InputMethodRelay.hpp (#4909) --- src/desktop/Popup.cpp | 3 ++- src/managers/input/InputMethodRelay.hpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 7c6eb1c9..0ba7f210 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -1,4 +1,5 @@ #include "Popup.hpp" +#include "../Compositor.hpp" CPopup::CPopup(CWindow* pOwner) : m_pWindowOwner(pOwner) { initAllSignals(); @@ -232,4 +233,4 @@ void CPopup::recheckChildrenRecursive() { Vector2D CPopup::size() { return m_vLastSize; -} \ No newline at end of file +} diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index 83332285..9f9e95f6 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -1,5 +1,6 @@ #pragma once +#include #include "../../defines.hpp" #include "../../helpers/WLClasses.hpp" @@ -50,4 +51,4 @@ class CInputMethodRelay { friend class CHyprRenderer; friend class CInputManager; friend class CTextInputV1ProtocolManager; -}; \ No newline at end of file +}; From f115ba94d2ec6e093c94f425535b027bc570185e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 1 Mar 2024 23:04:29 +0000 Subject: [PATCH 0023/2897] xwayland: set scaledBy for unmanaged windows in map --- src/events/Windows.cpp | 9 ++++++++- src/render/Renderer.cpp | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 1c1521c9..d4717f8b 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -652,6 +652,9 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_vReportedSize = PWINDOW->m_vPendingReportedSize; g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); + + if (PMONITOR && PWINDOW->m_iX11Type == 2) + PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; } void Events::listener_unmapWindow(void* owner, void* data) { @@ -1057,6 +1060,8 @@ void Events::listener_configureX11(void* owner, void* data) { wlr_xwayland_surface_configure(PWINDOW->m_uSurface.xwayland, E->x, E->y, E->width, E->height); PWINDOW->m_vPendingReportedSize = {E->width, E->height}; PWINDOW->m_vReportedSize = {E->width, E->height}; + if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) + PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; return; } @@ -1081,8 +1086,10 @@ void Events::listener_configureX11(void* owner, void* data) { static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); if (**PXWLFORCESCALEZERO) { - if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) + if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) { PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goalv() / PMONITOR->scale); + PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; + } } PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index d356cd90..ca75c3b5 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -470,7 +470,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* } else if (WINBB.x + WINBB.width > PWSMON->vecPosition.x + PWSMON->vecSize.x) { offset.x = (WINBB.x + WINBB.width - PWSMON->vecPosition.x - PWSMON->vecSize.x) * PROGRESS; } - } else if (PWORKSPACE->m_vRenderOffset.vec().y) { + } else if (PWORKSPACE->m_vRenderOffset.vec().y != 0) { const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); const auto PROGRESS = PWORKSPACE->m_vRenderOffset.vec().y / PWSMON->vecSize.y; const auto WINBB = pWindow->getFullWindowBoundingBox(); From b2c34404777ea0850f90f4c38f64484f03599d14 Mon Sep 17 00:00:00 2001 From: GartoxFR Date: Sat, 2 Mar 2024 01:35:17 +0100 Subject: [PATCH 0024/2897] animations: Refactor AnimatedVariable (#4911) * animation: Refactor AnimatedVariable This commit decomposes the AnimatedVariable class into a base class with the common attribute to all variable types and a templated derived type containing strongly typed info on the type being animated. Access to the typed version is perfomed using the visitor pattern. A utility is provided to build a visitor on the fly using lambdas. Adding a new type to be animated should just be a matter of adding the typed in the list defined by the ANIMABLE_TYPES macro The size of the commit is justified by the API change in the AnimatedVariable class. No more vec(), fl() or col() method but a unified value() method. * animation: Remove visitor pattern * animation: Fix coding style * animation: Fix coding style --- src/Compositor.cpp | 33 +- src/Window.cpp | 58 ++-- src/Window.hpp | 20 +- src/debug/HyprCtl.cpp | 8 +- src/desktop/Popup.cpp | 4 +- src/desktop/Subsurface.cpp | 2 +- src/desktop/WLSurface.cpp | 4 +- src/desktop/Workspace.cpp | 4 +- src/desktop/Workspace.hpp | 6 +- src/events/Layers.cpp | 4 +- src/events/Windows.cpp | 80 ++--- src/helpers/AnimatedVariable.cpp | 54 +-- src/helpers/AnimatedVariable.hpp | 315 ++++++++---------- src/helpers/Monitor.cpp | 4 +- src/helpers/WLClasses.cpp | 20 +- src/helpers/WLClasses.hpp | 20 +- src/hyprerror/HyprError.cpp | 4 +- src/hyprerror/HyprError.hpp | 20 +- src/layout/DwindleLayout.cpp | 16 +- src/layout/IHyprLayout.cpp | 47 +-- src/layout/MasterLayout.cpp | 14 +- src/managers/AnimationManager.cpp | 115 +++---- src/managers/AnimationManager.hpp | 6 +- src/managers/KeybindManager.cpp | 52 +-- src/managers/XWaylandManager.cpp | 6 +- src/managers/input/InputManager.cpp | 16 +- src/managers/input/InputMethodRelay.cpp | 6 +- src/managers/input/Swipe.cpp | 6 +- src/managers/input/Tablets.cpp | 2 +- src/managers/input/Touch.cpp | 4 +- src/protocols/ToplevelExport.cpp | 8 +- src/render/OpenGL.cpp | 30 +- src/render/Renderer.cpp | 64 ++-- .../decorations/CHyprBorderDecoration.cpp | 8 +- .../decorations/CHyprDropShadowDecoration.cpp | 14 +- .../decorations/CHyprGroupBarDecoration.cpp | 2 +- .../decorations/DecorationPositioner.cpp | 4 +- 37 files changed, 491 insertions(+), 589 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 150dbfaa..ee38764a 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -843,7 +843,8 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW wlr_xdg_surface_get_geometry(pWindow->m_uSurface.xdg, geom.pWlr()); geom.applyFromWlr(); - const auto PFOUND = wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.vec().x + geom.x, pos.y - pWindow->m_vRealPosition.vec().y + geom.y, &subx, &suby); + const auto PFOUND = + wlr_xdg_surface_surface_at(PSURFACE, pos.x - pWindow->m_vRealPosition.value().x + geom.x, pos.y - pWindow->m_vRealPosition.value().y + geom.y, &subx, &suby); if (PFOUND) { sl.x = subx; @@ -851,8 +852,8 @@ wlr_surface* CCompositor::vectorWindowToSurface(const Vector2D& pos, CWindow* pW return PFOUND; } - sl.x = pos.x - pWindow->m_vRealPosition.vec().x; - sl.y = pos.y - pWindow->m_vRealPosition.vec().y; + sl.x = pos.x - pWindow->m_vRealPosition.value().x; + sl.y = pos.y - pWindow->m_vRealPosition.value().y; sl.x += geom.x; sl.y += geom.y; @@ -865,7 +866,7 @@ Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, CWindow* pWindow return {}; if (pWindow->m_bIsX11) - return vec - pWindow->m_vRealPosition.goalv(); + return vec - pWindow->m_vRealPosition.goal(); const auto PSURFACE = pWindow->m_uSurface.xdg; @@ -887,9 +888,9 @@ Vector2D CCompositor::vectorToSurfaceLocal(const Vector2D& vec, CWindow* pWindow geom.applyFromWlr(); if (std::get<1>(iterData) == -1337 && std::get<2>(iterData) == -1337) - return vec - pWindow->m_vRealPosition.goalv(); + return vec - pWindow->m_vRealPosition.goal(); - return vec - pWindow->m_vRealPosition.goalv() - Vector2D{std::get<1>(iterData), std::get<2>(iterData)} + Vector2D{geom.x, geom.y}; + return vec - pWindow->m_vRealPosition.goal() - Vector2D{std::get<1>(iterData), std::get<2>(iterData)} + Vector2D{geom.x, geom.y}; } CMonitor* CCompositor::getMonitorFromOutput(wlr_output* out) { @@ -1123,7 +1124,7 @@ bool CCompositor::windowValidMapped(CWindow* pWindow) { wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) { for (auto& ls : *layerSurfaces | std::views::reverse) { - if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->surface->mapped) || ls->alpha.fl() == 0.f) + if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->surface->mapped) || ls->alpha.value() == 0.f) continue; auto SURFACEAT = wlr_layer_surface_v1_surface_at(ls->layerSurface, pos.x - ls->geometry.x, pos.y - ls->geometry.y, &sCoords->x, &sCoords->y); @@ -1241,7 +1242,7 @@ void CCompositor::sanityCheckWorkspaces() { if (!isWorkspaceVisible(WORKSPACE->m_iID)) { if (WORKSPACE->m_bIsSpecialWorkspace) { - if (WORKSPACE->m_fAlpha.fl() > 0.f /* don't abruptly end the fadeout */) { + if (WORKSPACE->m_fAlpha.value() > 0.f /* don't abruptly end the fadeout */) { ++it; continue; } @@ -1422,7 +1423,7 @@ void CCompositor::cleanupFadingOut(const int& monid) { bool valid = windowExists(w); - if (!valid || !w->m_bFadingOut || w->m_fAlpha.fl() == 0.f) { + if (!valid || !w->m_bFadingOut || w->m_fAlpha.value() == 0.f) { if (valid && !w->m_bReadyToDelete) continue; @@ -2014,7 +2015,7 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // additionally, move floating and fs windows manually if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.vec() - pMonitorA->vecPosition + pMonitorB->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.value() - pMonitorA->vecPosition + pMonitorB->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitorB->vecPosition; @@ -2039,7 +2040,7 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // additionally, move floating and fs windows manually if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.vec() - pMonitorB->vecPosition + pMonitorA->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.value() - pMonitorB->vecPosition + pMonitorA->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitorA->vecPosition; @@ -2206,14 +2207,14 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni if (w->m_bIsMapped && !w->isHidden()) { if (POLDMON) { if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.vec() - POLDMON->vecPosition + pMonitor->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.value() - POLDMON->vecPosition + pMonitor->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitor->vecPosition; w->m_vRealSize = pMonitor->vecSize; } } else { - w->m_vRealPosition = Vector2D{(int)w->m_vRealPosition.goalv().x % (int)pMonitor->vecSize.x, (int)w->m_vRealPosition.goalv().y % (int)pMonitor->vecSize.y}; + w->m_vRealPosition = Vector2D{(int)w->m_vRealPosition.goal().x % (int)pMonitor->vecSize.x, (int)w->m_vRealPosition.goal().y % (int)pMonitor->vecSize.y}; } } @@ -2330,7 +2331,7 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode } updateFullscreenFadeOnWorkspace(PWORKSPACE); - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv(), true); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal(), true); forceReportSizesToWindowsOnWorkspace(pWindow->m_iWorkspaceID); @@ -2569,7 +2570,7 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) { for (auto& w : m_vWindows) { if (w->m_iWorkspaceID == wid && w->m_bIsMapped && !w->isHidden()) { - g_pXWaylandManager->setWindowSize(w.get(), w->m_vRealSize.vec(), true); + g_pXWaylandManager->setWindowSize(w.get(), w->m_vRealSize.value(), true); } } } @@ -2670,7 +2671,7 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks g_pLayoutManager->getCurrentLayout()->onWindowCreatedTiling(pWindow); } else { const auto PWINDOWMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto POSTOMON = pWindow->m_vRealPosition.goalv() - PWINDOWMONITOR->vecPosition; + const auto POSTOMON = pWindow->m_vRealPosition.goal() - PWINDOWMONITOR->vecPosition; const auto PWORKSPACEMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); diff --git a/src/Window.cpp b/src/Window.cpp index df357212..997aa3f4 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -5,14 +5,14 @@ #include "render/decorations/CHyprBorderDecoration.hpp" CWindow::CWindow() { - m_vRealPosition.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_vRealSize.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_fBorderFadeAnimationProgress.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("border"), (void*)this, AVARDAMAGE_BORDER); - m_fBorderAngleAnimationProgress.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("borderangle"), (void*)this, AVARDAMAGE_BORDER); - m_fAlpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_fActiveInactiveAlpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"), (void*)this, AVARDAMAGE_ENTIRE); - m_cRealShadowColor.create(AVARTYPE_COLOR, g_pConfigManager->getAnimationPropertyConfig("fadeShadow"), (void*)this, AVARDAMAGE_SHADOW); - m_fDimPercent.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeDim"), (void*)this, AVARDAMAGE_ENTIRE); + m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); + m_vRealSize.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); + m_fBorderFadeAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("border"), (void*)this, AVARDAMAGE_BORDER); + m_fBorderAngleAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("borderangle"), (void*)this, AVARDAMAGE_BORDER); + m_fAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeIn"), (void*)this, AVARDAMAGE_ENTIRE); + m_fActiveInactiveAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"), (void*)this, AVARDAMAGE_ENTIRE); + m_cRealShadowColor.create(g_pConfigManager->getAnimationPropertyConfig("fadeShadow"), (void*)this, AVARDAMAGE_SHADOW); + m_fDimPercent.create(g_pConfigManager->getAnimationPropertyConfig("fadeDim"), (void*)this, AVARDAMAGE_ENTIRE); addWindowDeco(std::make_unique(this)); addWindowDeco(std::make_unique(this)); @@ -39,8 +39,8 @@ SWindowDecorationExtents CWindow::getFullWindowExtents() { if (m_sAdditionalConfigData.dimAround) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); - return {{m_vRealPosition.vec().x - PMONITOR->vecPosition.x, m_vRealPosition.vec().y - PMONITOR->vecPosition.y}, - {PMONITOR->vecSize.x - (m_vRealPosition.vec().x - PMONITOR->vecPosition.x), PMONITOR->vecSize.y - (m_vRealPosition.vec().y - PMONITOR->vecPosition.y)}}; + return {{m_vRealPosition.value().x - PMONITOR->vecPosition.x, m_vRealPosition.value().y - PMONITOR->vecPosition.y}, + {PMONITOR->vecSize.x - (m_vRealPosition.value().x - PMONITOR->vecPosition.x), PMONITOR->vecSize.y - (m_vRealPosition.value().y - PMONITOR->vecPosition.y)}}; } SWindowDecorationExtents maxExtents = {{BORDERSIZE + 2, BORDERSIZE + 2}, {BORDERSIZE + 2, BORDERSIZE + 2}}; @@ -101,8 +101,8 @@ CBox CWindow::getFullWindowBoundingBox() { auto maxExtents = getFullWindowExtents(); - CBox finalBox = {m_vRealPosition.vec().x - maxExtents.topLeft.x, m_vRealPosition.vec().y - maxExtents.topLeft.y, - m_vRealSize.vec().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.vec().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; + CBox finalBox = {m_vRealPosition.value().x - maxExtents.topLeft.x, m_vRealPosition.value().y - maxExtents.topLeft.y, + m_vRealSize.value().x + maxExtents.topLeft.x + maxExtents.bottomRight.x, m_vRealSize.value().y + maxExtents.topLeft.y + maxExtents.bottomRight.y}; return finalBox; } @@ -154,14 +154,14 @@ CBox CWindow::getWindowBoxUnified(uint64_t properties) { if (properties & FULL_EXTENTS) EXTENTS.addExtents(g_pDecorationPositioner->getWindowDecorationExtents(this, false)); - CBox box = {m_vRealPosition.vec().x, m_vRealPosition.vec().y, m_vRealSize.vec().x, m_vRealSize.vec().y}; + CBox box = {m_vRealPosition.value().x, m_vRealPosition.value().y, m_vRealSize.value().x, m_vRealSize.value().y}; box.addExtents(EXTENTS); return box; } CBox CWindow::getWindowMainSurfaceBox() { - return {m_vRealPosition.vec().x, m_vRealPosition.vec().y, m_vRealSize.vec().x, m_vRealSize.vec().y}; + return {m_vRealPosition.value().x, m_vRealPosition.value().y, m_vRealSize.value().x, m_vRealSize.value().y}; } SWindowDecorationExtents CWindow::getFullWindowReservedArea() { @@ -392,7 +392,7 @@ void CWindow::moveToWorkspace(int workspaceID) { } // update xwayland coords - g_pXWaylandManager->setWindowSize(this, m_vRealSize.vec()); + g_pXWaylandManager->setWindowSize(this, m_vRealSize.value()); if (g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE) == 0 && **PCLOSEONLASTSPECIAL) { const auto PWS = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); @@ -433,7 +433,7 @@ void CWindow::removeDecorationByType(eDecorationType type) { } void unregisterVar(void* ptr) { - ((CAnimatedVariable*)ptr)->unregister(); + ((CBaseAnimatedVariable*)ptr)->unregister(); } void CWindow::onUnmap() { @@ -530,7 +530,7 @@ void CWindow::onMap() { } void CWindow::onBorderAngleAnimEnd(void* ptr) { - const auto PANIMVAR = (CAnimatedVariable*)ptr; + const auto PANIMVAR = (CAnimatedVariable*)ptr; const std::string STYLE = PANIMVAR->getConfig()->pValues->internalStyle; @@ -727,10 +727,10 @@ bool CWindow::isInCurvedCorner(double x, double y) { return false; // (x0, y0), (x0, y1), ... are the center point of rounding at each corner - double x0 = m_vRealPosition.vec().x + ROUNDING; - double y0 = m_vRealPosition.vec().y + ROUNDING; - double x1 = m_vRealPosition.vec().x + m_vRealSize.vec().x - ROUNDING; - double y1 = m_vRealPosition.vec().y + m_vRealSize.vec().y - ROUNDING; + double x0 = m_vRealPosition.value().x + ROUNDING; + double y0 = m_vRealPosition.value().y + ROUNDING; + double x1 = m_vRealPosition.value().x + m_vRealSize.value().x - ROUNDING; + double y1 = m_vRealPosition.value().y + m_vRealSize.value().y - ROUNDING; if (x < x0 && y < y0) { return Vector2D{x0, y0}.distance(Vector2D{x, y}) > (double)ROUNDING; @@ -763,7 +763,7 @@ bool CWindow::hasPopupAt(const Vector2D& pos) { return false; wlr_surface* resultSurf = nullptr; - Vector2D origin = m_vRealPosition.vec(); + Vector2D origin = m_vRealPosition.value(); SExtensionFindingData data = {origin, pos, &resultSurf}; wlr_xdg_surface_for_each_popup_surface(m_uSurface.xdg, findExtensionForVector2D, &data); @@ -902,8 +902,8 @@ void CWindow::setGroupCurrent(CWindow* pWindow) { const bool FULLSCREEN = PCURRENT->m_bIsFullscreen; const auto WORKSPACE = g_pCompositor->getWorkspaceByID(PCURRENT->m_iWorkspaceID); - const auto PWINDOWSIZE = PCURRENT->m_vRealSize.goalv(); - const auto PWINDOWPOS = PCURRENT->m_vRealPosition.goalv(); + const auto PWINDOWSIZE = PCURRENT->m_vRealSize.goal(); + const auto PWINDOWPOS = PCURRENT->m_vRealPosition.goal(); const auto CURRENTISFOCUS = PCURRENT == g_pCompositor->m_pLastWindow; @@ -997,19 +997,19 @@ void CWindow::updateGroupOutputs() { curr->m_iMonitorID = m_iMonitorID; curr->moveToWorkspace(m_iWorkspaceID); - curr->m_vRealPosition = m_vRealPosition.goalv(); - curr->m_vRealSize = m_vRealSize.goalv(); + curr->m_vRealPosition = m_vRealPosition.goal(); + curr->m_vRealSize = m_vRealSize.goal(); curr = curr->m_sGroupData.pNextWindow; } } Vector2D CWindow::middle() { - return m_vRealPosition.goalv() + m_vRealSize.goalv() / 2.f; + return m_vRealPosition.goal() + m_vRealSize.goal() / 2.f; } bool CWindow::opaque() { - if (m_fAlpha.fl() != 1.f || m_fActiveInactiveAlpha.fl() != 1.f) + if (m_fAlpha.value() != 1.f || m_fActiveInactiveAlpha.value() != 1.f) return false; const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); @@ -1017,7 +1017,7 @@ bool CWindow::opaque() { if (m_pWLSurface.small() && !m_pWLSurface.m_bFillIgnoreSmall) return false; - if (PWORKSPACE->m_fAlpha.fl() != 1.f) + if (PWORKSPACE->m_fAlpha.value() != 1.f) return false; if (m_bIsX11) diff --git a/src/Window.hpp b/src/Window.hpp index 620ae06d..aeb674d1 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -221,8 +221,8 @@ class CWindow { Vector2D m_vSize = Vector2D(0, 0); // this is the real position and size used to draw the thing - CAnimatedVariable m_vRealPosition; - CAnimatedVariable m_vRealSize; + CAnimatedVariable m_vRealPosition; + CAnimatedVariable m_vRealSize; // for not spamming the protocols Vector2D m_vReportedPosition; @@ -282,13 +282,13 @@ class CWindow { std::unique_ptr m_pPopupHead; // Animated border - CGradientValueData m_cRealBorderColor = {0}; - CGradientValueData m_cRealBorderColorPrevious = {0}; - CAnimatedVariable m_fBorderFadeAnimationProgress; - CAnimatedVariable m_fBorderAngleAnimationProgress; + CGradientValueData m_cRealBorderColor = {0}; + CGradientValueData m_cRealBorderColorPrevious = {0}; + CAnimatedVariable m_fBorderFadeAnimationProgress; + CAnimatedVariable m_fBorderAngleAnimationProgress; // Fade in-out - CAnimatedVariable m_fAlpha; + CAnimatedVariable m_fAlpha; bool m_bFadingOut = false; bool m_bReadyToDelete = false; Vector2D m_vOriginalClosedPos; // these will be used for calculations later on in @@ -322,13 +322,13 @@ class CWindow { std::vector> m_vTransformers; // for alpha - CAnimatedVariable m_fActiveInactiveAlpha; + CAnimatedVariable m_fActiveInactiveAlpha; // animated shadow color - CAnimatedVariable m_cRealShadowColor; + CAnimatedVariable m_cRealShadowColor; // animated tint - CAnimatedVariable m_fDimPercent; + CAnimatedVariable m_fDimPercent; // swallowing CWindow* m_pSwallowed = nullptr; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 8f29ae72..b3fb0af3 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -171,8 +171,8 @@ static std::string getWindowData(CWindow* w, eHyprCtlOutputFormat format) { "swallowing": "0x{:x}", "focusHistoryID": {} }},)#", - (uintptr_t)w, (w->m_bIsMapped ? "true" : "false"), (w->isHidden() ? "true" : "false"), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y, - (int)w->m_vRealSize.goalv().x, (int)w->m_vRealSize.goalv().y, w->m_iWorkspaceID, + (uintptr_t)w, (w->m_bIsMapped ? "true" : "false"), (w->isHidden() ? "true" : "false"), (int)w->m_vRealPosition.goal().x, (int)w->m_vRealPosition.goal().y, + (int)w->m_vRealSize.goal().x, (int)w->m_vRealSize.goal().y, w->m_iWorkspaceID, escapeJSONStrings(w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))), @@ -187,8 +187,8 @@ static std::string getWindowData(CWindow* w, eHyprCtlOutputFormat format) { "{}\n\tinitialClass: {}\n\tinitialTitle: {}\n\tpid: " "{}\n\txwayland: {}\n\tpinned: " "{}\n\tfullscreen: {}\n\tfullscreenmode: {}\n\tfakefullscreen: {}\n\tgrouped: {}\n\tswallowing: {:x}\n\tfocusHistoryID: {}\n\n", - (uintptr_t)w, w->m_szTitle, (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goalv().x, (int)w->m_vRealPosition.goalv().y, - (int)w->m_vRealSize.goalv().x, (int)w->m_vRealSize.goalv().y, w->m_iWorkspaceID, + (uintptr_t)w, w->m_szTitle, (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goal().x, (int)w->m_vRealPosition.goal().y, (int)w->m_vRealSize.goal().x, + (int)w->m_vRealSize.goal().y, w->m_iWorkspaceID, (w->m_iWorkspaceID == -1 ? "" : g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName : std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))), diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 0ba7f210..92f0e312 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -207,9 +207,9 @@ Vector2D CPopup::localToGlobal(const Vector2D& rel) { Vector2D CPopup::t1ParentCoords() { if (m_pWindowOwner) - return m_pWindowOwner->m_vRealPosition.vec(); + return m_pWindowOwner->m_vRealPosition.value(); if (m_pLayerOwner) - return m_pLayerOwner->realPosition.vec(); + return m_pLayerOwner->realPosition.value(); ASSERT(false); return {}; diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index ab43f3c3..74ae7748 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -236,7 +236,7 @@ Vector2D CSubsurface::coordsGlobal() { Vector2D coords = coordsRelativeToParent(); if (m_pWindowParent) - coords += m_pWindowParent->m_vRealPosition.vec(); + coords += m_pWindowParent->m_vRealPosition.value(); else if (m_pPopupParent) coords += m_pPopupParent->coordsGlobal(); diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp index 6773d761..9ec121bb 100644 --- a/src/desktop/WLSurface.cpp +++ b/src/desktop/WLSurface.cpp @@ -65,7 +65,7 @@ Vector2D CWLSurface::correctSmallVec() const { const auto SIZE = getViewporterCorrectedSize(); return Vector2D{(m_pWindowOwner->m_vReportedSize.x - SIZE.x) / 2, (m_pWindowOwner->m_vReportedSize.y - SIZE.y) / 2}.clamp({}, {INFINITY, INFINITY}) * - (m_pWindowOwner->m_vRealSize.vec() / m_pWindowOwner->m_vReportedSize); + (m_pWindowOwner->m_vRealSize.value() / m_pWindowOwner->m_vReportedSize); } Vector2D CWLSurface::getViewporterCorrectedSize() const { @@ -171,4 +171,4 @@ std::optional CWLSurface::getSurfaceBoxGlobal() { return CBox{m_pSubsurfaceOwner->coordsGlobal(), m_pSubsurfaceOwner->size()}; return {}; -} \ No newline at end of file +} diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index ad8ae4ad..e2ba1d5a 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -14,8 +14,8 @@ CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { m_bIsSpecialWorkspace = special; m_vRenderOffset.m_pWorkspace = this; - m_vRenderOffset.create(AVARTYPE_VECTOR, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), - nullptr, AVARDAMAGE_ENTIRE); + m_vRenderOffset.create(special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), nullptr, + AVARDAMAGE_ENTIRE); m_fAlpha.m_pWorkspace = this; m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), nullptr, AVARDAMAGE_ENTIRE); diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index d4915769..aea842e0 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -35,9 +35,9 @@ class CWorkspace { wl_array m_wlrCoordinateArr; // for animations - CAnimatedVariable m_vRenderOffset; - CAnimatedVariable m_fAlpha; - bool m_bForceRendering = false; + CAnimatedVariable m_vRenderOffset; + CAnimatedVariable m_fAlpha; + bool m_bForceRendering = false; // "scratchpad" bool m_bIsSpecialWorkspace = false; diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 7dbcc7b1..2d94f1ed 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -327,13 +327,13 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { } } - if (layersurface->realPosition.goalv() != layersurface->geometry.pos()) { + if (layersurface->realPosition.goal() != layersurface->geometry.pos()) { if (layersurface->realPosition.isBeingAnimated()) layersurface->realPosition = layersurface->geometry.pos(); else layersurface->realPosition.setValueAndWarp(layersurface->geometry.pos()); } - if (layersurface->realSize.goalv() != layersurface->geometry.size()) { + if (layersurface->realSize.goal() != layersurface->geometry.size()) { if (layersurface->realSize.isBeingAnimated()) layersurface->realSize = layersurface->geometry.size(); else diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index d4717f8b..83aa36d7 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -17,8 +17,8 @@ void addViewCoords(void* pWindow, int* x, int* y) { const auto PWINDOW = (CWindow*)pWindow; - *x += PWINDOW->m_vRealPosition.goalv().x; - *y += PWINDOW->m_vRealPosition.goalv().y; + *x += PWINDOW->m_vRealPosition.goal().x; + *y += PWINDOW->m_vRealPosition.goal().y; if (!PWINDOW->m_bIsX11 && PWINDOW->m_bIsMapped) { wlr_box geom; @@ -30,9 +30,9 @@ void addViewCoords(void* pWindow, int* x, int* y) { } void setAnimToMove(void* data) { - auto* const PANIMCFG = g_pConfigManager->getAnimationPropertyConfig("windowsMove"); + auto* const PANIMCFG = g_pConfigManager->getAnimationPropertyConfig("windowsMove"); - CAnimatedVariable* animvar = (CAnimatedVariable*)data; + CBaseAnimatedVariable* animvar = (CBaseAnimatedVariable*)data; animvar->setConfig(PANIMCFG); } @@ -323,7 +323,7 @@ void Events::listener_mapWindow(void* owner, void* data) { Debug::log(LOG, "Rule size, applying to {}", PWINDOW); PWINDOW->m_vRealSize = Vector2D(SIZEX, SIZEY); - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); PWINDOW->setHidden(false); } catch (...) { Debug::log(LOG, "Rule size failed, rule: {} -> {}", r.szRule, r.szValue); } @@ -334,10 +334,10 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); const auto SIZE = - Vector2D(std::max((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goalv().x), std::max((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goalv().y)); + Vector2D(std::max((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goal().x), std::max((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goal().y)); PWINDOW->m_vRealSize = SIZE; - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); PWINDOW->setHidden(false); } catch (...) { Debug::log(LOG, "Rule minsize failed, rule: {} -> {}", r.szRule, r.szValue); } @@ -348,10 +348,10 @@ void Events::listener_mapWindow(void* owner, void* data) { const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); const auto SIZE = - Vector2D(std::min((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goalv().x), std::min((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goalv().y)); + Vector2D(std::min((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goal().x), std::min((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goal().y)); PWINDOW->m_vRealSize = SIZE; - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); PWINDOW->setHidden(false); } catch (...) { Debug::log(LOG, "Rule maxsize failed, rule: {} -> {}", r.szRule, r.szValue); } @@ -390,7 +390,7 @@ void Events::listener_mapWindow(void* owner, void* data) { posX = g_pInputManager->getMouseCoordsInternal().x - PMONITOR->vecPosition.x; } else { posX = g_pInputManager->getMouseCoordsInternal().x - PMONITOR->vecPosition.x + - (!POSXSTR.contains('%') ? std::stoi(POSXSTR) : std::stof(POSXSTR.substr(0, POSXSTR.length() - 1)) * 0.01 * PWINDOW->m_vRealSize.goalv().x); + (!POSXSTR.contains('%') ? std::stoi(POSXSTR) : std::stof(POSXSTR.substr(0, POSXSTR.length() - 1)) * 0.01 * PWINDOW->m_vRealSize.goal().x); } } @@ -409,7 +409,7 @@ void Events::listener_mapWindow(void* owner, void* data) { posY = g_pInputManager->getMouseCoordsInternal().y - PMONITOR->vecPosition.y; } else { posY = g_pInputManager->getMouseCoordsInternal().y - PMONITOR->vecPosition.y + - (!POSYSTR.contains('%') ? std::stoi(POSYSTR) : std::stof(POSYSTR.substr(0, POSYSTR.length() - 1)) * 0.01 * PWINDOW->m_vRealSize.goalv().y); + (!POSYSTR.contains('%') ? std::stoi(POSYSTR) : std::stof(POSYSTR.substr(0, POSYSTR.length() - 1)) * 0.01 * PWINDOW->m_vRealSize.goal().y); } } @@ -417,10 +417,10 @@ void Events::listener_mapWindow(void* owner, void* data) { int borderSize = PWINDOW->getRealBorderSize(); posX = std::clamp(posX, (int)(PMONITOR->vecReservedTopLeft.x + borderSize), - (int)(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goalv().x - borderSize)); + (int)(PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PWINDOW->m_vRealSize.goal().x - borderSize)); posY = std::clamp(posY, (int)(PMONITOR->vecReservedTopLeft.y + borderSize), - (int)(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goalv().y - borderSize)); + (int)(PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PWINDOW->m_vRealSize.goal().y - borderSize)); } Debug::log(LOG, "Rule move, applying to {}", PWINDOW); @@ -435,20 +435,20 @@ void Events::listener_mapWindow(void* owner, void* data) { if (ARGS[1] == "1") RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f; - PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET; + PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.value() / 2.f + RESERVEDOFFSET; } } // set the pseudo size to the GOAL of our current size // because the windows are animated on RealSize - PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goalv(); + PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goal(); g_pCompositor->changeWindowZOrder(PWINDOW, true); } else { g_pLayoutManager->getCurrentLayout()->onWindowCreated(PWINDOW); // Set the pseudo size here too so that it doesnt end up being 0x0 - PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goalv() - Vector2D(10, 10); + PWINDOW->m_vPseudoSize = PWINDOW->m_vRealSize.goal() - Vector2D(10, 10); } const auto PFOCUSEDWINDOWPREV = g_pCompositor->m_pLastWindow; @@ -617,7 +617,7 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->m_bFirstMap = false; - Debug::log(LOG, "Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j}", PMONITOR->szName, PWINDOW->m_vRealPosition.goalv(), PWINDOW->m_vRealSize.goalv()); + Debug::log(LOG, "Map request dispatched, monitor {}, window pos: {:5j}, window size: {:5j}", PMONITOR->szName, PWINDOW->m_vRealPosition.goal(), PWINDOW->m_vRealSize.goal()); auto workspaceID = requestedWorkspace != "" ? requestedWorkspace : PWORKSPACE->m_szName; g_pEventManager->postEvent(SHyprIPCEvent{"openwindow", std::format("{:x},{},{},{}", PWINDOW, workspaceID, g_pXWaylandManager->getAppIDClass(PWINDOW), PWINDOW->m_szTitle)}); @@ -670,8 +670,8 @@ void Events::listener_unmapWindow(void* owner, void* data) { const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); if (PMONITOR) { - PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.vec() - PMONITOR->vecPosition; - PWINDOW->m_vOriginalClosedSize = PWINDOW->m_vRealSize.vec(); + PWINDOW->m_vOriginalClosedPos = PWINDOW->m_vRealPosition.value() - PMONITOR->vecPosition; + PWINDOW->m_vOriginalClosedSize = PWINDOW->m_vRealSize.value(); PWINDOW->m_eOriginalClosedExtents = PWINDOW->getFullWindowExtents(); } @@ -760,8 +760,8 @@ void Events::listener_unmapWindow(void* owner, void* data) { g_pHyprRenderer->damageMonitor(g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)); - if (!PWINDOW->m_bX11DoesntWantBorders) // don't animate out if they weren't animated in. - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.vec() + Vector2D(0.01f, 0.01f); // it has to be animated, otherwise onWindowPostCreateClose will ignore it + if (!PWINDOW->m_bX11DoesntWantBorders) // don't animate out if they weren't animated in. + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.value() + Vector2D(0.01f, 0.01f); // it has to be animated, otherwise onWindowPostCreateClose will ignore it // anims g_pAnimationManager->onWindowPostCreateClose(PWINDOW, true); @@ -831,7 +831,7 @@ void Events::listener_commitWindow(void* owner, void* data) { PWINDOW->m_pPendingSizeAck.reset(); } - g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goalv().x, PWINDOW->m_vRealPosition.goalv().y, + g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goal().x, PWINDOW->m_vRealPosition.goal().y, PWINDOW->m_bIsX11 ? 1.0 / PWINDOW->m_fX11SurfaceScaledBy : 1.0); if (!PWINDOW->m_bIsX11) { @@ -848,7 +848,7 @@ void Events::listener_commitWindow(void* owner, void* data) { if (MAXSIZE < Vector2D{1, 1}) return; - const auto REALSIZE = PWINDOW->m_vRealSize.goalv(); + const auto REALSIZE = PWINDOW->m_vRealSize.goal(); Vector2D newSize = REALSIZE; if (MAXSIZE.x < newSize.x) @@ -862,7 +862,7 @@ void Events::listener_commitWindow(void* owner, void* data) { const Vector2D DELTA = REALSIZE - newSize; - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goalv() + DELTA / 2.0; + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + DELTA / 2.0; PWINDOW->m_vRealSize = newSize; g_pXWaylandManager->setWindowSize(PWINDOW, newSize, true); g_pHyprRenderer->damageWindow(PWINDOW); @@ -1068,7 +1068,7 @@ void Events::listener_configureX11(void* owner, void* data) { g_pHyprRenderer->damageWindow(PWINDOW); if (!PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen || g_pInputManager->currentlyDraggedWindow == PWINDOW) { - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv(), true); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal(), true); g_pInputManager->refocus(); g_pHyprRenderer->damageWindow(PWINDOW); return; @@ -1087,13 +1087,13 @@ void Events::listener_configureX11(void* owner, void* data) { static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); if (**PXWLFORCESCALEZERO) { if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) { - PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goalv() / PMONITOR->scale); + PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goal() / PMONITOR->scale); PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; } } - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.vec(); - PWINDOW->m_vSize = PWINDOW->m_vRealSize.vec(); + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.value(); + PWINDOW->m_vSize = PWINDOW->m_vRealSize.value(); wlr_xwayland_surface_configure(PWINDOW->m_uSurface.xwayland, E->x, E->y, E->width, E->height); @@ -1105,7 +1105,7 @@ void Events::listener_configureX11(void* owner, void* data) { if (!g_pCompositor->isWorkspaceVisible(PWINDOW->m_iWorkspaceID)) return; // further things are only for visible windows - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f)->activeWorkspace; + PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; g_pCompositor->changeWindowZOrder(PWINDOW, true); @@ -1123,8 +1123,8 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { if (!PWINDOW->m_bIsMapped) return; - const auto POS = PWINDOW->m_vRealPosition.goalv(); - const auto SIZ = PWINDOW->m_vRealSize.goalv(); + const auto POS = PWINDOW->m_vRealPosition.goal(); + const auto SIZ = PWINDOW->m_vRealSize.goal(); if (PWINDOW->m_uSurface.xwayland->width > 1 && PWINDOW->m_uSurface.xwayland->height > 1) PWINDOW->setHidden(false); @@ -1132,7 +1132,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { PWINDOW->setHidden(true); if (PWINDOW->m_bIsFullscreen || !PWINDOW->m_bIsFloating) { - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv(), true); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal(), true); g_pHyprRenderer->damageWindow(PWINDOW); return; } @@ -1154,23 +1154,23 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { if (**PXWLFORCESCALEZERO) { if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) { - const Vector2D DELTA = PWINDOW->m_vRealSize.goalv() - PWINDOW->m_vRealSize.goalv() / PMONITOR->scale; - PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goalv() / PMONITOR->scale); - PWINDOW->m_vRealPosition.setValueAndWarp(PWINDOW->m_vRealPosition.goalv() + DELTA / 2.0); + const Vector2D DELTA = PWINDOW->m_vRealSize.goal() - PWINDOW->m_vRealSize.goal() / PMONITOR->scale; + PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goal() / PMONITOR->scale); + PWINDOW->m_vRealPosition.setValueAndWarp(PWINDOW->m_vRealPosition.goal() + DELTA / 2.0); } } - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goalv(); - PWINDOW->m_vSize = PWINDOW->m_vRealSize.goalv(); + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goal(); + PWINDOW->m_vSize = PWINDOW->m_vRealSize.goal(); - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.vec() + PWINDOW->m_vRealSize.vec() / 2.f)->activeWorkspace; + PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; g_pCompositor->changeWindowZOrder(PWINDOW, true); PWINDOW->updateWindowDecos(); g_pHyprRenderer->damageWindow(PWINDOW); - PWINDOW->m_vReportedPosition = PWINDOW->m_vRealPosition.goalv(); - PWINDOW->m_vPendingReportedSize = PWINDOW->m_vRealSize.goalv(); + PWINDOW->m_vReportedPosition = PWINDOW->m_vRealPosition.goal(); + PWINDOW->m_vPendingReportedSize = PWINDOW->m_vRealSize.goal(); } } diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp index 740e604f..3a891e37 100644 --- a/src/helpers/AnimatedVariable.cpp +++ b/src/helpers/AnimatedVariable.cpp @@ -2,12 +2,11 @@ #include "../managers/AnimationManager.hpp" #include "../config/ConfigManager.hpp" -CAnimatedVariable::CAnimatedVariable() { +CBaseAnimatedVariable::CBaseAnimatedVariable(ANIMATEDVARTYPE type) : m_Type(type) { ; // dummy var } -void CAnimatedVariable::create(ANIMATEDVARTYPE type, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { - m_eVarType = type; +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { m_eDamagePolicy = policy; m_pConfig = pAnimConfig; m_pWindow = pWindow; @@ -15,42 +14,11 @@ void CAnimatedVariable::create(ANIMATEDVARTYPE type, SAnimationPropertyConfig* p m_bDummy = false; } -void CAnimatedVariable::create(ANIMATEDVARTYPE type, std::any val, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { - create(type, pAnimConfig, pWindow, policy); - - try { - switch (type) { - case AVARTYPE_FLOAT: { - const auto V = std::any_cast(val); - m_fValue = V; - m_fGoal = V; - break; - } - case AVARTYPE_VECTOR: { - const auto V = std::any_cast(val); - m_vValue = V; - m_vGoal = V; - break; - } - case AVARTYPE_COLOR: { - const auto V = std::any_cast(val); - m_cValue = V; - m_cGoal = V; - break; - } - default: ASSERT(false); break; - } - } catch (std::exception& e) { - Debug::log(ERR, "CAnimatedVariable create error: {}", e.what()); - RASSERT(false, "CAnimatedVariable create error: {}", e.what()); - } -} - -CAnimatedVariable::~CAnimatedVariable() { +CBaseAnimatedVariable::~CBaseAnimatedVariable() { unregister(); } -void CAnimatedVariable::unregister() { +void CBaseAnimatedVariable::unregister() { if (!g_pAnimationManager) return; std::erase_if(g_pAnimationManager->m_vAnimatedVariables, [&](const auto& other) { return other == this; }); @@ -58,23 +26,23 @@ void CAnimatedVariable::unregister() { disconnectFromActive(); } -void CAnimatedVariable::registerVar() { +void CBaseAnimatedVariable::registerVar() { if (!m_bIsRegistered) g_pAnimationManager->m_vAnimatedVariables.push_back(this); m_bIsRegistered = true; } -int CAnimatedVariable::getDurationLeftMs() { +int CBaseAnimatedVariable::getDurationLeftMs() { return std::max( (int)(m_pConfig->pValues->internalSpeed * 100) - (int)std::chrono::duration_cast(std::chrono::system_clock::now() - animationBegin).count(), 0); } -float CAnimatedVariable::getPercent() { +float CBaseAnimatedVariable::getPercent() { const auto DURATIONPASSED = std::chrono::duration_cast(std::chrono::system_clock::now() - animationBegin).count(); return std::clamp((DURATIONPASSED / 100.f) / m_pConfig->pValues->internalSpeed, 0.f, 1.f); } -float CAnimatedVariable::getCurveValue() { +float CBaseAnimatedVariable::getCurveValue() { if (!m_bIsBeingAnimated) return 1.f; @@ -86,7 +54,7 @@ float CAnimatedVariable::getCurveValue() { return g_pAnimationManager->getBezier(m_pConfig->pValues->internalBezier)->getYForPoint(SPENT); } -void CAnimatedVariable::connectToActive() { +void CBaseAnimatedVariable::connectToActive() { g_pAnimationManager->scheduleTick(); // otherwise the animation manager will never pick this up if (!m_bIsConnectedToActive) @@ -95,7 +63,7 @@ void CAnimatedVariable::connectToActive() { m_bIsConnectedToActive = true; } -void CAnimatedVariable::disconnectFromActive() { +void CBaseAnimatedVariable::disconnectFromActive() { std::erase_if(g_pAnimationManager->m_vActiveAnimatedVariables, [&](const auto& other) { return other == this; }); m_bIsConnectedToActive = false; -} \ No newline at end of file +} diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index d87273b3..6efb394b 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "Vector2D.hpp" #include "Color.hpp" #include "../macros.hpp" @@ -15,6 +16,30 @@ enum ANIMATEDVARTYPE { AVARTYPE_COLOR }; +// Utility to bind a type with its corresponding ANIMATEDVARTYPE +template +struct typeToANIMATEDVARTYPE_t { + static constexpr ANIMATEDVARTYPE value = AVARTYPE_INVALID; +}; + +template <> +struct typeToANIMATEDVARTYPE_t { + static constexpr ANIMATEDVARTYPE value = AVARTYPE_FLOAT; +}; + +template <> +struct typeToANIMATEDVARTYPE_t { + static constexpr ANIMATEDVARTYPE value = AVARTYPE_VECTOR; +}; + +template <> +struct typeToANIMATEDVARTYPE_t { + static constexpr ANIMATEDVARTYPE value = AVARTYPE_COLOR; +}; + +template +inline constexpr ANIMATEDVARTYPE typeToANIMATEDVARTYPE = typeToANIMATEDVARTYPE_t::value; + enum AVARDAMAGEPOLICY { AVARDAMAGE_NONE = -1, AVARDAMAGE_ENTIRE = 0, @@ -28,174 +53,34 @@ struct SLayerSurface; struct SAnimationPropertyConfig; class CHyprRenderer; -class CAnimatedVariable { +// Utility to define a concept as a list of possible type +template +concept OneOf = (... or std::same_as); + +// Concept to describe which type can be placed into CAnimatedVariable +// This is mainly to get better errors if we put a type that's not supported +// Otherwise template errors are ugly +template +concept Animable = OneOf; + +class CBaseAnimatedVariable { public: - CAnimatedVariable(); // dummy var + CBaseAnimatedVariable(ANIMATEDVARTYPE type); + void create(SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy); - void create(ANIMATEDVARTYPE, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY); - void create(ANIMATEDVARTYPE, std::any val, SAnimationPropertyConfig*, void* pWindow, AVARDAMAGEPOLICY); + CBaseAnimatedVariable(const CBaseAnimatedVariable&) = delete; + CBaseAnimatedVariable(CBaseAnimatedVariable&&) = delete; + CBaseAnimatedVariable& operator=(const CBaseAnimatedVariable&) = delete; + CBaseAnimatedVariable& operator=(CBaseAnimatedVariable&&) = delete; - CAnimatedVariable(const CAnimatedVariable&) = delete; - CAnimatedVariable(CAnimatedVariable&&) = delete; - CAnimatedVariable& operator=(const CAnimatedVariable&) = delete; - CAnimatedVariable& operator=(CAnimatedVariable&&) = delete; + virtual ~CBaseAnimatedVariable(); - ~CAnimatedVariable(); + void unregister(); + void registerVar(); - void unregister(); - void registerVar(); - - // gets the current vector value (real time) - const Vector2D& vec() const { - return m_vValue; - } - - // gets the current float value (real time) - const float& fl() const { - return m_fValue; - } - - // gets the current color value (real time) - const CColor& col() const { - return m_cValue; - } - - // gets the goal vector value - const Vector2D& goalv() const { - return m_vGoal; - } - - // gets the goal float value - const float& goalf() const { - return m_fGoal; - } - - // gets the goal color value - const CColor& goalc() const { - return m_cGoal; - } - - CAnimatedVariable& operator=(const Vector2D& v) { - if (v == m_vGoal) - return *this; - - m_vGoal = v; - animationBegin = std::chrono::system_clock::now(); - m_vBegun = m_vValue; - - onAnimationBegin(); - - return *this; - } - - CAnimatedVariable& operator=(const float& v) { - if (v == m_fGoal) - return *this; - - m_fGoal = v; - animationBegin = std::chrono::system_clock::now(); - m_fBegun = m_fValue; - - onAnimationBegin(); - - return *this; - } - - CAnimatedVariable& operator=(const CColor& v) { - if (v == m_cGoal) - return *this; - - m_cGoal = v; - animationBegin = std::chrono::system_clock::now(); - m_cBegun = m_cValue; - - onAnimationBegin(); - - return *this; - } - - // Sets the actual stored value, without affecting the goal, but resets the timer - void setValue(const Vector2D& v) { - if (v == m_vValue) - return; - - m_vValue = v; - animationBegin = std::chrono::system_clock::now(); - m_vBegun = m_vValue; - - onAnimationBegin(); - } - - // Sets the actual stored value, without affecting the goal, but resets the timer - void setValue(const float& v) { - if (v == m_fValue) - return; - - m_fValue = v; - animationBegin = std::chrono::system_clock::now(); - m_vBegun = m_vValue; - - onAnimationBegin(); - } - - // Sets the actual stored value, without affecting the goal, but resets the timer - void setValue(const CColor& v) { - if (v == m_cValue) - return; - - m_cValue = v; - animationBegin = std::chrono::system_clock::now(); - m_vBegun = m_vValue; - - onAnimationBegin(); - } - - // Sets the actual value and goal - void setValueAndWarp(const Vector2D& v) { - m_vGoal = v; - warp(); - } - - // Sets the actual value and goal - void setValueAndWarp(const float& v) { - m_fGoal = v; - warp(); - } - - // Sets the actual value and goal - void setValueAndWarp(const CColor& v) { - m_cGoal = v; - warp(); - } - - // checks if an animation is in progress - inline bool isBeingAnimated() { - return m_bIsBeingAnimated; - } - - void warp(bool endCallback = true) { - switch (m_eVarType) { - case AVARTYPE_FLOAT: { - m_fValue = m_fGoal; - break; - } - case AVARTYPE_VECTOR: { - m_vValue = m_vGoal; - break; - } - case AVARTYPE_COLOR: { - m_cValue = m_cGoal; - break; - } - default: UNREACHABLE(); - } - - m_bIsBeingAnimated = false; - - if (endCallback) - onAnimationEnd(); - } + virtual void warp(bool endCallback = true) = 0; + // void setConfig(SAnimationPropertyConfig* pConfig) { m_pConfig = pConfig; } @@ -212,6 +97,11 @@ class CAnimatedVariable { /* returns the current curve value */ float getCurveValue(); + // checks if an animation is in progress + inline bool isBeingAnimated() { + return m_bIsBeingAnimated; + } + /* sets a function to be ran when the animation finishes. if an animation is not running, runs instantly. if "remove" is set to true, will remove the callback when ran. */ @@ -245,20 +135,7 @@ class CAnimatedVariable { m_bRemoveEndAfterRan = false; } - private: - Vector2D m_vValue = Vector2D(0, 0); - float m_fValue = 0; - CColor m_cValue; - - Vector2D m_vGoal = Vector2D(0, 0); - float m_fGoal = 0; - CColor m_cGoal; - - Vector2D m_vBegun = Vector2D(0, 0); - float m_fBegun = 0; - CColor m_cBegun; - - // owners + protected: void* m_pWindow = nullptr; void* m_pWorkspace = nullptr; void* m_pLayer = nullptr; @@ -271,8 +148,8 @@ class CAnimatedVariable { std::chrono::system_clock::time_point animationBegin; - ANIMATEDVARTYPE m_eVarType = AVARTYPE_INVALID; AVARDAMAGEPOLICY m_eDamagePolicy = AVARDAMAGE_NONE; + ANIMATEDVARTYPE m_Type; bool m_bRemoveEndAfterRan = true; bool m_bRemoveBeginAfterRan = true; @@ -281,7 +158,9 @@ class CAnimatedVariable { std::function m_fUpdateCallback; bool m_bIsConnectedToActive = false; + void connectToActive(); + void disconnectFromActive(); // methods @@ -314,3 +193,85 @@ class CAnimatedVariable { friend struct SLayerSurface; friend class CHyprRenderer; }; + +template +class CAnimatedVariable : public CBaseAnimatedVariable { + public: + CAnimatedVariable() : CBaseAnimatedVariable(typeToANIMATEDVARTYPE) {} // dummy var + + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { + create(pAnimConfig, pWindow, policy); + m_Value = value; + } + + using CBaseAnimatedVariable::create; + + CAnimatedVariable(const CAnimatedVariable&) = delete; + CAnimatedVariable(CAnimatedVariable&&) = delete; + CAnimatedVariable& operator=(const CAnimatedVariable&) = delete; + CAnimatedVariable& operator=(CAnimatedVariable&&) = delete; + + ~CAnimatedVariable() = default; + + // gets the current vector value (real time) + const VarType& value() const { + return m_Value; + } + + // gets the goal vector value + const VarType& goal() const { + return m_Goal; + } + + CAnimatedVariable& operator=(const VarType& v) { + if (v == m_Goal) + return *this; + + m_Goal = v; + animationBegin = std::chrono::system_clock::now(); + m_Begun = m_Value; + + onAnimationBegin(); + + return *this; + } + + // Sets the actual stored value, without affecting the goal, but resets the timer + void setValue(const VarType& v) { + if (v == m_Value) + return; + + m_Value = v; + animationBegin = std::chrono::system_clock::now(); + m_Begun = m_Value; + + onAnimationBegin(); + } + + // Sets the actual value and goal + void setValueAndWarp(const VarType& v) { + m_Goal = v; + warp(); + } + + void warp(bool endCallback = true) override { + m_Value = m_Goal; + + m_bIsBeingAnimated = false; + + if (endCallback) + onAnimationEnd(); + } + + private: + VarType m_Value{}; + VarType m_Goal{}; + VarType m_Begun{}; + + // owners + + friend class CAnimationManager; + friend class CWorkspace; + friend struct SLayerSurface; + friend class CHyprRenderer; +}; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 2dd2a2d9..7f36ccd4 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -661,11 +661,11 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { if (w->m_bIsFloating && !VECINRECT(MIDDLE, vecPosition.x, vecPosition.y, vecPosition.x + vecSize.x, vecPosition.y + vecSize.y) && w->m_iX11Type != 2) { // if it's floating and the middle isnt on the current mon, move it to the center const auto PMONFROMMIDDLE = g_pCompositor->getMonitorFromVector(MIDDLE); - Vector2D pos = w->m_vRealPosition.goalv(); + Vector2D pos = w->m_vRealPosition.goal(); if (!VECINRECT(MIDDLE, PMONFROMMIDDLE->vecPosition.x, PMONFROMMIDDLE->vecPosition.y, PMONFROMMIDDLE->vecPosition.x + PMONFROMMIDDLE->vecSize.x, PMONFROMMIDDLE->vecPosition.y + PMONFROMMIDDLE->vecSize.y)) { // not on any monitor, center - pos = middle() / 2.f - w->m_vRealSize.goalv() / 2.f; + pos = middle() / 2.f - w->m_vRealSize.goal() / 2.f; } else pos = pos - PMONFROMMIDDLE->vecPosition + vecPosition; diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 43bba7c5..31db2c55 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -3,9 +3,9 @@ #include "../Compositor.hpp" SLayerSurface::SLayerSurface() { - alpha.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeLayers"), nullptr, AVARDAMAGE_ENTIRE); - realPosition.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); - realSize.create(AVARTYPE_VECTOR, g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); + alpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeLayers"), nullptr, AVARDAMAGE_ENTIRE); + realPosition.create(g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); + realSize.create(g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); alpha.m_pLayer = this; realPosition.m_pLayer = this; realSize.m_pLayer = this; @@ -181,11 +181,11 @@ CRegion SConstraint::getLogicCoordsRegion() { result.add(&constraint->region); // surface-local coords if (!PWINDOWOWNER->m_bIsX11) { - result.translate(PWINDOWOWNER->m_vRealPosition.goalv()); + result.translate(PWINDOWOWNER->m_vRealPosition.goal()); return result; } - const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goalv() : + const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goal() : g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y}); const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ? g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) : g_pCompositor->getMonitorFromVector(COORDS); @@ -210,9 +210,9 @@ Vector2D SConstraint::getLogicConstraintPos() { return {}; if (!PWINDOWOWNER->m_bIsX11) - return PWINDOWOWNER->m_vRealPosition.goalv(); + return PWINDOWOWNER->m_vRealPosition.goal(); - const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goalv() : + const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goal() : g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y}); return COORDS; @@ -228,7 +228,7 @@ Vector2D SConstraint::getLogicConstraintSize() { return {}; if (!PWINDOWOWNER->m_bIsX11) - return PWINDOWOWNER->m_vRealSize.goalv(); + return PWINDOWOWNER->m_vRealSize.goal(); const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ? g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) : @@ -237,8 +237,8 @@ Vector2D SConstraint::getLogicConstraintSize() { if (!PMONITOR) return {}; - const auto SIZE = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealSize.goalv() : + const auto SIZE = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealSize.goal() : Vector2D{PWINDOWOWNER->m_uSurface.xwayland->width, PWINDOWOWNER->m_uSurface.xwayland->height} * PMONITOR->xwaylandScale; return SIZE; -} \ No newline at end of file +} diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index b307191c..c9cb47e4 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -19,19 +19,19 @@ struct SLayerSurface { SLayerSurface(); ~SLayerSurface(); - void applyRules(); - void startAnimation(bool in, bool instant = false); - bool isFadedOut(); + void applyRules(); + void startAnimation(bool in, bool instant = false); + bool isFadedOut(); - CAnimatedVariable realPosition; - CAnimatedVariable realSize; + CAnimatedVariable realPosition; + CAnimatedVariable realSize; - wlr_layer_surface_v1* layerSurface; - wl_list link; + wlr_layer_surface_v1* layerSurface; + wl_list link; - bool keyboardExclusive = false; + bool keyboardExclusive = false; - CWLSurface surface; + CWLSurface surface; // desktop components std::unique_ptr popupHead; @@ -51,7 +51,7 @@ struct SLayerSurface { std::string szNamespace = ""; - CAnimatedVariable alpha; + CAnimatedVariable alpha; bool fadingOut = false; bool readyToDelete = false; bool noProcess = false; diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 6a91ba87..97a18e8c 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -139,7 +139,7 @@ void CHyprError::draw() { if (m_bQueuedDestroy) { if (!m_fFadeOpacity.isBeingAnimated()) { - if (m_fFadeOpacity.fl() == 0.f) { + if (m_fFadeOpacity.value() == 0.f) { m_bQueuedDestroy = false; m_tTexture.destroyTexture(); m_bIsCreated = false; @@ -164,7 +164,7 @@ void CHyprError::draw() { m_bMonitorChanged = false; - g_pHyprOpenGL->renderTexture(m_tTexture, &monbox, m_fFadeOpacity.fl(), 0); + g_pHyprOpenGL->renderTexture(m_tTexture, &monbox, m_fFadeOpacity.value(), 0); } void CHyprError::destroy() { diff --git a/src/hyprerror/HyprError.hpp b/src/hyprerror/HyprError.hpp index cee648e2..aaa8bd12 100644 --- a/src/hyprerror/HyprError.hpp +++ b/src/hyprerror/HyprError.hpp @@ -16,16 +16,16 @@ class CHyprError { void destroy(); private: - void createQueued(); - std::string m_szQueued = ""; - CColor m_cQueued; - bool m_bQueuedDestroy = false; - bool m_bIsCreated = false; - CTexture m_tTexture; - CAnimatedVariable m_fFadeOpacity; - CBox m_bDamageBox = {0, 0, 0, 0}; + void createQueued(); + std::string m_szQueued = ""; + CColor m_cQueued; + bool m_bQueuedDestroy = false; + bool m_bIsCreated = false; + CTexture m_tTexture; + CAnimatedVariable m_fFadeOpacity; + CBox m_bDamageBox = {0, 0, 0, 0}; - bool m_bMonitorChanged = false; + bool m_bMonitorChanged = false; }; -inline std::unique_ptr g_pHyprError; // This is a full-screen error. Treat it with respect, and there can only be one at a time. \ No newline at end of file +inline std::unique_ptr g_pHyprError; // This is a full-screen error. Treat it with respect, and there can only be one at a time. diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 2bb6e4c3..fda93e97 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -172,7 +172,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + RESERVED.topLeft; PWINDOW->m_vRealSize = PWINDOW->m_vSize - (RESERVED.topLeft + RESERVED.bottomRight); - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); return; } @@ -606,7 +606,7 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn const auto PNODE = getNodeFromWindow(PWINDOW); if (!PNODE) { - PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goalv() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goalv() + pixResize).y, 20.0)); + PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goal() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goal() + pixResize).y, 20.0)); PWINDOW->updateWindowDecos(); return; } @@ -625,7 +625,7 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (!m_PseudoDragFlags.started) { m_PseudoDragFlags.started = true; - const auto pseudoSize = PWINDOW->m_vRealSize.goalv(); + const auto pseudoSize = PWINDOW->m_vRealSize.goal(); const auto mouseOffset = g_pInputManager->getMouseCoordsInternal() - (PNODE->box.pos() + ((PNODE->box.size() / 2) - (pseudoSize / 2))); if (mouseOffset.x > 0 && mouseOffset.x < pseudoSize.x && mouseOffset.y > 0 && mouseOffset.y < pseudoSize.y) { @@ -805,10 +805,10 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree // save position and size if floating if (pWindow->m_bIsFloating && on) { - pWindow->m_vLastFloatingSize = pWindow->m_vRealSize.goalv(); - pWindow->m_vLastFloatingPosition = pWindow->m_vRealPosition.goalv(); - pWindow->m_vPosition = pWindow->m_vRealPosition.goalv(); - pWindow->m_vSize = pWindow->m_vRealSize.goalv(); + pWindow->m_vLastFloatingSize = pWindow->m_vRealSize.goal(); + pWindow->m_vLastFloatingPosition = pWindow->m_vRealPosition.goal(); + pWindow->m_vPosition = pWindow->m_vRealPosition.goal(); + pWindow->m_vSize = pWindow->m_vRealSize.goal(); } // otherwise, accept it. @@ -860,7 +860,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree g_pCompositor->updateWindowAnimatedDecorationValues(pWindow); - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal()); g_pCompositor->changeWindowZOrder(pWindow, true); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 16474056..106b5751 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -105,7 +105,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { } // reject any windows with size <= 5x5 - if (pWindow->m_vRealSize.goalv().x <= 5 || pWindow->m_vRealSize.goalv().y <= 5) + if (pWindow->m_vRealSize.goal().x <= 5 || pWindow->m_vRealSize.goal().y <= 5) pWindow->m_vRealSize = PMONITOR->vecSize / 2.f; if (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect) { @@ -113,11 +113,11 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { if (pWindow->m_uSurface.xwayland->x != 0 && pWindow->m_uSurface.xwayland->y != 0) pWindow->m_vRealPosition = g_pXWaylandManager->xwaylandToWaylandCoords({pWindow->m_uSurface.xwayland->x, pWindow->m_uSurface.xwayland->y}); else - pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goalv().x) / 2.f, - PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goalv().y) / 2.f); + pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goal().x) / 2.f, + PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goal().y) / 2.f); } else { - pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goalv().x) / 2.f, - PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goalv().y) / 2.f); + pWindow->m_vRealPosition = Vector2D(PMONITOR->vecPosition.x + (PMONITOR->vecSize.x - pWindow->m_vRealSize.goal().x) / 2.f, + PMONITOR->vecPosition.y + (PMONITOR->vecSize.y - pWindow->m_vRealSize.goal().y) / 2.f); } } else { // we respect the size. @@ -152,7 +152,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { } if (**PXWLFORCESCALEZERO && pWindow->m_bIsX11) - pWindow->m_vRealSize = pWindow->m_vRealSize.goalv() / PMONITOR->scale; + pWindow->m_vRealSize = pWindow->m_vRealSize.goal() / PMONITOR->scale; if (pWindow->m_bX11DoesntWantBorders || (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect)) { pWindow->m_vRealPosition.warp(); @@ -160,11 +160,11 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { } if (pWindow->m_iX11Type != 2) { - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal()); g_pCompositor->changeWindowZOrder(pWindow, true); } else { - pWindow->m_vPendingReportedSize = pWindow->m_vRealSize.goalv(); + pWindow->m_vPendingReportedSize = pWindow->m_vRealSize.goal(); pWindow->m_vReportedSize = pWindow->m_vPendingReportedSize; } } @@ -200,18 +200,18 @@ void IHyprLayout::onBeginDragWindow() { if (!DRAGGINGWINDOW->m_bIsFloating) { if (g_pInputManager->dragMode == MBIND_MOVE) { - DRAGGINGWINDOW->m_vLastFloatingSize = (DRAGGINGWINDOW->m_vRealSize.goalv() * 0.8489).clamp(Vector2D{5, 5}, Vector2D{}).floor(); + DRAGGINGWINDOW->m_vLastFloatingSize = (DRAGGINGWINDOW->m_vRealSize.goal() * 0.8489).clamp(Vector2D{5, 5}, Vector2D{}).floor(); changeWindowFloatingMode(DRAGGINGWINDOW); DRAGGINGWINDOW->m_bIsFloating = true; DRAGGINGWINDOW->m_bDraggingTiled = true; - DRAGGINGWINDOW->m_vRealPosition = g_pInputManager->getMouseCoordsInternal() - DRAGGINGWINDOW->m_vRealSize.goalv() / 2.f; + DRAGGINGWINDOW->m_vRealPosition = g_pInputManager->getMouseCoordsInternal() - DRAGGINGWINDOW->m_vRealSize.goal() / 2.f; } } m_vBeginDragXY = g_pInputManager->getMouseCoordsInternal(); - m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition.goalv(); - m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize.goalv(); + m_vBeginDragPositionXY = DRAGGINGWINDOW->m_vRealPosition.goal(); + m_vBeginDragSizeXY = DRAGGINGWINDOW->m_vRealSize.goal(); m_vLastDragXY = m_vBeginDragXY; // get the grab corner @@ -325,7 +325,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { if (g_pInputManager->dragMode == MBIND_MOVE) { - CBox wb = {m_vBeginDragPositionXY + DELTA, DRAGGINGWINDOW->m_vRealSize.goalv()}; + CBox wb = {m_vBeginDragPositionXY + DELTA, DRAGGINGWINDOW->m_vRealSize.goal()}; wb.round(); if (**PANIMATEMOUSE) @@ -333,7 +333,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { else DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(wb.pos()); - g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goal()); } else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) { if (DRAGGINGWINDOW->m_bIsFloating) { @@ -394,14 +394,14 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(wb.pos()); } - g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(DRAGGINGWINDOW, DRAGGINGWINDOW->m_vRealSize.goal()); } else { resizeActiveWindow(TICKDELTA, m_eGrabbedCorner, DRAGGINGWINDOW); } } // get middle point - Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.vec() + DRAGGINGWINDOW->m_vRealSize.vec() / 2.f; + Vector2D middle = DRAGGINGWINDOW->m_vRealPosition.value() + DRAGGINGWINDOW->m_vRealSize.value() / 2.f; // and check its monitor const auto PMONITOR = g_pCompositor->getMonitorFromVector(middle); @@ -435,18 +435,18 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { EMIT_HOOK_EVENT("changeFloatingMode", pWindow); if (!TILED) { - const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.vec() + pWindow->m_vRealSize.vec() / 2.f); + const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.value() + pWindow->m_vRealSize.value() / 2.f); pWindow->m_iMonitorID = PNEWMON->ID; pWindow->moveToWorkspace(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); pWindow->updateGroupOutputs(); // save real pos cuz the func applies the default 5,5 mid - const auto PSAVEDPOS = pWindow->m_vRealPosition.goalv(); - const auto PSAVEDSIZE = pWindow->m_vRealSize.goalv(); + const auto PSAVEDPOS = pWindow->m_vRealPosition.goal(); + const auto PSAVEDSIZE = pWindow->m_vRealSize.goal(); // if the window is pseudo, update its size if (!pWindow->m_bDraggingTiled) - pWindow->m_vPseudoSize = pWindow->m_vRealSize.goalv(); + pWindow->m_vPseudoSize = pWindow->m_vRealSize.goal(); pWindow->m_vLastFloatingSize = PSAVEDSIZE; @@ -468,10 +468,11 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { g_pCompositor->changeWindowZOrder(pWindow, true); - CBox wb = {pWindow->m_vRealPosition.goalv() + (pWindow->m_vRealSize.goalv() - pWindow->m_vLastFloatingSize) / 2.f, pWindow->m_vLastFloatingSize}; + CBox wb = {pWindow->m_vRealPosition.goal() + (pWindow->m_vRealSize.goal() - pWindow->m_vLastFloatingSize) / 2.f, pWindow->m_vLastFloatingSize}; wb.round(); - if (DELTALESSTHAN(pWindow->m_vRealSize.vec().x, pWindow->m_vLastFloatingSize.x, 10) && DELTALESSTHAN(pWindow->m_vRealSize.vec().y, pWindow->m_vLastFloatingSize.y, 10)) { + if (DELTALESSTHAN(pWindow->m_vRealSize.value().x, pWindow->m_vLastFloatingSize.x, 10) && + DELTALESSTHAN(pWindow->m_vRealSize.value().y, pWindow->m_vLastFloatingSize.y, 10)) { wb = {wb.pos() + Vector2D{10, 10}, wb.size() - Vector2D{20, 20}}; } @@ -505,7 +506,7 @@ void IHyprLayout::moveActiveWindow(const Vector2D& delta, CWindow* pWindow) { return; } - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goalv() + delta; + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + delta; g_pHyprRenderer->damageWindow(PWINDOW); } diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 1a488b0d..4008b609 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -668,7 +668,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->m_vRealPosition = PWINDOW->m_vPosition + RESERVED.topLeft; PWINDOW->m_vRealSize = PWINDOW->m_vSize - (RESERVED.topLeft + RESERVED.bottomRight); - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); return; } @@ -732,7 +732,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto PNODE = getNodeFromWindow(PWINDOW); if (!PNODE) { - PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goalv() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goalv() + pixResize).y, 20.0)); + PWINDOW->m_vRealSize = Vector2D(std::max((PWINDOW->m_vRealSize.goal() + pixResize).x, 20.0), std::max((PWINDOW->m_vRealSize.goal() + pixResize).y, 20.0)); PWINDOW->updateWindowDecos(); return; } @@ -884,10 +884,10 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen // save position and size if floating if (pWindow->m_bIsFloating && on) { - pWindow->m_vLastFloatingSize = pWindow->m_vRealSize.goalv(); - pWindow->m_vLastFloatingPosition = pWindow->m_vRealPosition.goalv(); - pWindow->m_vPosition = pWindow->m_vRealPosition.goalv(); - pWindow->m_vSize = pWindow->m_vRealSize.goalv(); + pWindow->m_vLastFloatingSize = pWindow->m_vRealSize.goal(); + pWindow->m_vLastFloatingPosition = pWindow->m_vRealPosition.goal(); + pWindow->m_vPosition = pWindow->m_vRealPosition.goal(); + pWindow->m_vSize = pWindow->m_vRealSize.goal(); } // otherwise, accept it. @@ -941,7 +941,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen g_pCompositor->updateWindowAnimatedDecorationValues(pWindow); - g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal()); g_pCompositor->changeWindowZOrder(pWindow, true); diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 859e3b03..f9d709d3 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -1,6 +1,7 @@ #include "AnimationManager.hpp" #include "../Compositor.hpp" #include "HookSystemManager.hpp" +#include "macros.hpp" int wlTick(void* data) { if (g_pAnimationManager) @@ -58,11 +59,11 @@ void CAnimationManager::tick() { if (!**PANIMENABLED) animGlobalDisabled = true; - static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); + static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); - const auto DEFAULTBEZIER = m_mBezierCurves.find("default"); + const auto DEFAULTBEZIER = m_mBezierCurves.find("default"); - std::vector animationEndedVars; + std::vector animationEndedVars; for (auto& av : m_vActiveAnimatedVariables) { @@ -101,7 +102,7 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(w.get()); } } else if (PLAYER) { - WLRBOXPREV = CBox{PLAYER->realPosition.vec(), PLAYER->realSize.vec()}; + WLRBOXPREV = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f); if (!PMONITOR) continue; @@ -113,78 +114,48 @@ void CAnimationManager::tick() { // beziers are with a switch unforto // TODO: maybe do something cleaner - switch (av->m_eVarType) { + auto updateVariable = [&](CAnimatedVariable& av) { + // for disabled anims just warp + if (av.m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { + av.warp(false); + return; + } + + if (SPENT >= 1.f || av.m_Begun == av.m_Goal) { + av.warp(false); + return; + } + + const auto DELTA = av.m_Goal - av.m_Begun; + const auto BEZIER = m_mBezierCurves.find(av.m_pConfig->pValues->internalBezier); + + if (BEZIER != m_mBezierCurves.end()) + av.m_Value = av.m_Begun + DELTA * BEZIER->second.getYForPoint(SPENT); + else + av.m_Value = av.m_Begun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + }; + + switch (av->m_Type) { case AVARTYPE_FLOAT: { - // for disabled anims just warp - if (av->m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { - av->warp(false); - break; - } - - if (SPENT >= 1.f || av->m_fBegun == av->m_fGoal) { - av->warp(false); - break; - } - - const auto DELTA = av->m_fGoal - av->m_fBegun; - const auto BEZIER = m_mBezierCurves.find(av->m_pConfig->pValues->internalBezier); - - if (BEZIER != m_mBezierCurves.end()) - av->m_fValue = av->m_fBegun + BEZIER->second.getYForPoint(SPENT) * DELTA; - else - av->m_fValue = av->m_fBegun + DEFAULTBEZIER->second.getYForPoint(SPENT) * DELTA; + auto typedAv = static_cast*>(av); + updateVariable(*typedAv); break; } case AVARTYPE_VECTOR: { - // for disabled anims just warp - if (av->m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { - av->warp(false); - break; - } - - if (SPENT >= 1.f || av->m_vBegun == av->m_vGoal) { - av->warp(false); - break; - } - - const auto DELTA = av->m_vGoal - av->m_vBegun; - const auto BEZIER = m_mBezierCurves.find(av->m_pConfig->pValues->internalBezier); - - if (BEZIER != m_mBezierCurves.end()) - av->m_vValue = av->m_vBegun + DELTA * BEZIER->second.getYForPoint(SPENT); - else - av->m_vValue = av->m_vBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + auto typedAv = static_cast*>(av); + updateVariable(*typedAv); break; } case AVARTYPE_COLOR: { - // for disabled anims just warp - if (av->m_pConfig->pValues->internalEnabled == 0 || animationsDisabled) { - av->warp(false); - break; - } - - if (SPENT >= 1.f || av->m_cBegun == av->m_cGoal) { - av->warp(false); - break; - } - - const auto DELTA = av->m_cGoal - av->m_cBegun; - const auto BEZIER = m_mBezierCurves.find(av->m_pConfig->pValues->internalBezier); - - if (BEZIER != m_mBezierCurves.end()) - av->m_cValue = av->m_cBegun + DELTA * BEZIER->second.getYForPoint(SPENT); - else - av->m_cValue = av->m_cBegun + DELTA * DEFAULTBEZIER->second.getYForPoint(SPENT); + auto typedAv = static_cast*>(av); + updateVariable(*typedAv); break; } - default: { - ; - } + default: UNREACHABLE(); } - // set size and pos if valid, but only if damage policy entire (dont if border for example) if (g_pCompositor->windowValidMapped(PWINDOW) && av->m_eDamagePolicy == AVARDAMAGE_ENTIRE && PWINDOW->m_iX11Type != 2) - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goalv()); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); // check if we did not finish animating. If so, trigger onAnimationEnd. if (!av->isBeingAnimated()) @@ -216,7 +187,7 @@ void CAnimationManager::tick() { if (w->m_bIsFloating) { auto bb = w->getFullWindowBoundingBox(); - bb.translate(PWORKSPACE->m_vRenderOffset.vec()); + bb.translate(PWORKSPACE->m_vRenderOffset.value()); g_pHyprRenderer->damageBox(&bb); } } @@ -250,7 +221,7 @@ void CAnimationManager::tick() { BORDERSIZE + ROUNDINGSIZE); // bottom // damage for new box - const CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y, PWINDOW->m_vRealSize.vec().x, PWINDOW->m_vRealSize.vec().y}; + const CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value().x, PWINDOW->m_vRealPosition.value().y, PWINDOW->m_vRealSize.value().x, PWINDOW->m_vRealSize.value().y}; g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, WLRBOXNEW.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // top g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, WLRBOXNEW.height + 2 * BORDERSIZE); // left g_pHyprRenderer->damageBox(WLRBOXNEW.x + WLRBOXNEW.width - ROUNDINGSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, @@ -323,23 +294,23 @@ bool CAnimationManager::bezierExists(const std::string& bezier) { // void CAnimationManager::animationPopin(CWindow* pWindow, bool close, float minPerc) { - const auto GOALPOS = pWindow->m_vRealPosition.goalv(); - const auto GOALSIZE = pWindow->m_vRealSize.goalv(); + const auto GOALPOS = pWindow->m_vRealPosition.goal(); + const auto GOALSIZE = pWindow->m_vRealSize.goal(); if (!close) { pWindow->m_vRealSize.setValue((GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y})); - pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_vValue / 2.f); + pWindow->m_vRealPosition.setValue(GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_Value / 2.f); } else { pWindow->m_vRealSize = (GOALSIZE * minPerc).clamp({5, 5}, {GOALSIZE.x, GOALSIZE.y}); - pWindow->m_vRealPosition = GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_vGoal / 2.f; + pWindow->m_vRealPosition = GOALPOS + GOALSIZE / 2.f - pWindow->m_vRealSize.m_Goal / 2.f; } } void CAnimationManager::animationSlide(CWindow* pWindow, std::string force, bool close) { pWindow->m_vRealSize.warp(false); // size we preserve in slide - const auto GOALPOS = pWindow->m_vRealPosition.goalv(); - const auto GOALSIZE = pWindow->m_vRealSize.goalv(); + const auto GOALPOS = pWindow->m_vRealPosition.goal(); + const auto GOALSIZE = pWindow->m_vRealSize.goal(); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index 281c61f8..ae82a60b 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -28,8 +28,8 @@ class CAnimationManager { std::unordered_map getAllBeziers(); - std::vector m_vAnimatedVariables; - std::vector m_vActiveAnimatedVariables; + std::vector m_vAnimatedVariables; + std::vector m_vActiveAnimatedVariables; wl_event_source* m_pAnimationTick; @@ -52,4 +52,4 @@ class CAnimationManager { void animationSlide(CWindow*, std::string force = "", bool close = false); }; -inline std::unique_ptr g_pAnimationManager; \ No newline at end of file +inline std::unique_ptr g_pAnimationManager; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 58425757..1ab8fa91 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -874,8 +874,8 @@ void CKeybindManager::centerWindow(std::string args) { if (args == "1") RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f; - PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goalv() / 2.f + RESERVEDOFFSET; - PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goalv(); + PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goal() / 2.f + RESERVEDOFFSET; + PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goal(); } void CKeybindManager::toggleActivePseudo(std::string args) { @@ -1222,14 +1222,14 @@ void CKeybindManager::moveActiveTo(std::string args) { switch (arg) { case 'l': vPos.x = PMONITOR->vecReservedTopLeft.x + BORDERSIZE + PMONITOR->vecPosition.x; break; - case 'r': vPos.x = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PLASTWINDOW->m_vRealSize.goalv().x - BORDERSIZE + PMONITOR->vecPosition.x; break; + case 'r': vPos.x = PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x - PLASTWINDOW->m_vRealSize.goal().x - BORDERSIZE + PMONITOR->vecPosition.x; break; case 't': case 'u': vPos.y = PMONITOR->vecReservedTopLeft.y + BORDERSIZE + PMONITOR->vecPosition.y; break; case 'b': - case 'd': vPos.y = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PLASTWINDOW->m_vRealSize.goalv().y - BORDERSIZE + PMONITOR->vecPosition.y; break; + case 'd': vPos.y = PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y - PLASTWINDOW->m_vRealSize.goal().y - BORDERSIZE + PMONITOR->vecPosition.y; break; } - PLASTWINDOW->m_vRealPosition = Vector2D(vPos.x != 0 ? vPos.x : PLASTWINDOW->m_vRealPosition.goalv().x, vPos.y != 0 ? vPos.y : PLASTWINDOW->m_vRealPosition.goalv().y); + PLASTWINDOW->m_vRealPosition = Vector2D(vPos.x != 0 ? vPos.x : PLASTWINDOW->m_vRealPosition.goal().x, vPos.y != 0 ? vPos.y : PLASTWINDOW->m_vRealPosition.goal().y); return; } @@ -1377,22 +1377,22 @@ void CKeybindManager::moveCursorToCorner(std::string arg) { switch (CORNER) { case 0: // bottom left - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, - PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.value().x, + PWINDOW->m_vRealPosition.value().y + PWINDOW->m_vRealSize.value().y); break; case 1: // bottom right - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, - PWINDOW->m_vRealPosition.vec().y + PWINDOW->m_vRealSize.vec().y); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.value().x + PWINDOW->m_vRealSize.value().x, + PWINDOW->m_vRealPosition.value().y + PWINDOW->m_vRealSize.value().y); break; case 2: // top right - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x + PWINDOW->m_vRealSize.vec().x, - PWINDOW->m_vRealPosition.vec().y); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.value().x + PWINDOW->m_vRealSize.value().x, + PWINDOW->m_vRealPosition.value().y); break; case 3: // top left - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.vec().x, PWINDOW->m_vRealPosition.vec().y); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, PWINDOW->m_vRealPosition.value().x, PWINDOW->m_vRealPosition.value().y); break; } } @@ -1457,8 +1457,8 @@ void CKeybindManager::workspaceOpt(std::string args) { continue; if (!w->m_bRequestsFloat && w->m_bIsFloating != PWORKSPACE->m_bDefaultFloating) { - const auto SAVEDPOS = w->m_vRealPosition.vec(); - const auto SAVEDSIZE = w->m_vRealSize.vec(); + const auto SAVEDPOS = w->m_vRealPosition.value(); + const auto SAVEDSIZE = w->m_vRealSize.value(); w->m_bIsFloating = PWORKSPACE->m_bDefaultFloating; g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(w); @@ -1467,8 +1467,8 @@ void CKeybindManager::workspaceOpt(std::string args) { w->m_vRealPosition.setValueAndWarp(SAVEDPOS); w->m_vRealSize.setValueAndWarp(SAVEDSIZE); g_pXWaylandManager->setWindowSize(w, SAVEDSIZE); - w->m_vRealSize = w->m_vRealSize.vec() + Vector2D(4, 4); - w->m_vRealPosition = w->m_vRealPosition.vec() - Vector2D(2, 2); + w->m_vRealSize = w->m_vRealSize.value() + Vector2D(4, 4); + w->m_vRealPosition = w->m_vRealPosition.value() - Vector2D(2, 2); } } } @@ -1651,14 +1651,14 @@ void CKeybindManager::resizeActive(std::string args) { if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen) return; - const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.goalv()); + const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealSize.goal()); if (SIZ.x < 1 || SIZ.y < 1) return; - g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goalv()); + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - g_pCompositor->m_pLastWindow->m_vRealSize.goal()); - if (g_pCompositor->m_pLastWindow->m_vRealSize.goalv().x > 1 && g_pCompositor->m_pLastWindow->m_vRealSize.goalv().y > 1) + if (g_pCompositor->m_pLastWindow->m_vRealSize.goal().x > 1 && g_pCompositor->m_pLastWindow->m_vRealSize.goal().y > 1) g_pCompositor->m_pLastWindow->setHidden(false); } @@ -1666,9 +1666,9 @@ void CKeybindManager::moveActive(std::string args) { if (!g_pCompositor->m_pLastWindow || g_pCompositor->m_pLastWindow->m_bIsFullscreen) return; - const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goalv()); + const auto POS = g_pCompositor->parseWindowVectorArgsRelative(args, g_pCompositor->m_pLastWindow->m_vRealPosition.goal()); - g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - g_pCompositor->m_pLastWindow->m_vRealPosition.goalv()); + g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - g_pCompositor->m_pLastWindow->m_vRealPosition.goal()); } void CKeybindManager::moveWindow(std::string args) { @@ -1686,9 +1686,9 @@ void CKeybindManager::moveWindow(std::string args) { if (PWINDOW->m_bIsFullscreen) return; - const auto POS = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealPosition.goalv()); + const auto POS = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealPosition.goal()); - g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PWINDOW->m_vRealPosition.goalv(), PWINDOW); + g_pLayoutManager->getCurrentLayout()->moveActiveWindow(POS - PWINDOW->m_vRealPosition.goal(), PWINDOW); } void CKeybindManager::resizeWindow(std::string args) { @@ -1706,14 +1706,14 @@ void CKeybindManager::resizeWindow(std::string args) { if (PWINDOW->m_bIsFullscreen) return; - const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealSize.goalv()); + const auto SIZ = g_pCompositor->parseWindowVectorArgsRelative(MOVECMD, PWINDOW->m_vRealSize.goal()); if (SIZ.x < 1 || SIZ.y < 1) return; - g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goalv(), CORNER_NONE, PWINDOW); + g_pLayoutManager->getCurrentLayout()->resizeActiveWindow(SIZ - PWINDOW->m_vRealSize.goal(), CORNER_NONE, PWINDOW); - if (PWINDOW->m_vRealSize.goalv().x > 1 && PWINDOW->m_vRealSize.goalv().y > 1) + if (PWINDOW->m_vRealSize.goal().x > 1 && PWINDOW->m_vRealSize.goal().y > 1) PWINDOW->setHidden(false); } diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 2dcb3bcc..f70022cf 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -55,7 +55,7 @@ void CHyprXWaylandManager::activateSurface(wlr_surface* pSurface, bool activate) void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { if (pWindow->m_bIsX11) { - setWindowSize(pWindow, pWindow->m_vRealSize.vec()); // update xwayland output pos + setWindowSize(pWindow, pWindow->m_vRealSize.value()); // update xwayland output pos if (activate) { wlr_xwayland_surface_set_minimized(pWindow->m_uSurface.xwayland, false); @@ -161,7 +161,7 @@ void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool f // calculate pos // TODO: this should be decoupled from setWindowSize IMO - Vector2D windowPos = pWindow->m_vRealPosition.vec(); + Vector2D windowPos = pWindow->m_vRealPosition.value(); if (pWindow->m_bIsX11 && PMONITOR) { windowPos = windowPos - PMONITOR->vecPosition; // normalize to monitor @@ -266,7 +266,7 @@ void CHyprXWaylandManager::moveXWaylandWindow(CWindow* pWindow, const Vector2D& if (!pWindow->m_bIsX11) return; - wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.vec().x, pWindow->m_vRealSize.vec().y); + wlr_xwayland_surface_configure(pWindow->m_uSurface.xwayland, pos.x, pos.y, pWindow->m_vRealSize.value().x, pWindow->m_vRealSize.value().y); } void CHyprXWaylandManager::checkBorders(CWindow* pWindow) { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 2c8c2d7c..5944ba87 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -66,7 +66,7 @@ void CInputManager::sendMotionEventsToFocused() { timespec now; clock_gettime(CLOCK_MONOTONIC, &now); - const auto LOCAL = getMouseCoordsInternal() - (PWINDOW ? PWINDOW->m_vRealPosition.goalv() : (PLS ? Vector2D{PLS->geometry.x, PLS->geometry.y} : Vector2D{})); + const auto LOCAL = getMouseCoordsInternal() - (PWINDOW ? PWINDOW->m_vRealPosition.goal() : (PLS ? Vector2D{PLS->geometry.x, PLS->geometry.y} : Vector2D{})); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, LOCAL.x, LOCAL.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, now.tv_sec * 1000 + now.tv_nsec / 10000000, LOCAL.x, LOCAL.y); @@ -134,7 +134,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (forcedFocus) { pFoundWindow = forcedFocus; - surfacePos = pFoundWindow->m_vRealPosition.vec(); + surfacePos = pFoundWindow->m_vRealPosition.value(); foundSurface = pFoundWindow->m_pWLSurface.wlr(); } @@ -182,7 +182,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (CONSTRAINTWINDOW->m_bIsX11) { foundSurface = CONSTRAINTWINDOW->m_pWLSurface.wlr(); - surfacePos = CONSTRAINTWINDOW->m_vRealPosition.vec(); + surfacePos = CONSTRAINTWINDOW->m_vRealPosition.value(); } else { g_pCompositor->vectorWindowToSurface(mouseCoords, CONSTRAINTWINDOW, surfaceCoords); } @@ -273,7 +273,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { surfacePos = Vector2D(-1337, -1337); } else { foundSurface = pFoundWindow->m_pWLSurface.wlr(); - surfacePos = pFoundWindow->m_vRealPosition.vec(); + surfacePos = pFoundWindow->m_vRealPosition.value(); } } @@ -302,7 +302,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorWindowToSurface(mouseCoords, pFoundWindow, surfaceCoords); } else { foundSurface = pFoundWindow->m_pWLSurface.wlr(); - surfacePos = pFoundWindow->m_vRealPosition.vec(); + surfacePos = pFoundWindow->m_vRealPosition.value(); } } } @@ -626,7 +626,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // TODO detect click on LS properly if (**PRESIZEONBORDER && !m_bLastFocusOnLS && e->state == WLR_BUTTON_PRESSED) { if (w && !w->m_bIsFullscreen) { - const CBox real = {w->m_vRealPosition.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().y}; + const CBox real = {w->m_vRealPosition.value().x, w->m_vRealPosition.value().y, w->m_vRealSize.value().x, w->m_vRealSize.value().y}; const CBox grab = {real.x - BORDER_GRAB_AREA, real.y - BORDER_GRAB_AREA, real.width + 2 * BORDER_GRAB_AREA, real.height + 2 * BORDER_GRAB_AREA}; if ((grab.containsPoint(mouseCoords) && (!real.containsPoint(mouseCoords) || w->isInCurvedCorner(mouseCoords.x, mouseCoords.y))) && !w->hasPopupAt(mouseCoords)) { @@ -1304,9 +1304,9 @@ void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* co if (const auto PWINDOW = g_pCompositor->getWindowFromSurface(constraint->surface); PWINDOW) { const auto RELATIVETO = PWINDOW->m_bIsX11 ? - (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealPosition.goalv() : + (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealPosition.goal() : g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y})) : - PWINDOW->m_vRealPosition.goalv(); + PWINDOW->m_vRealPosition.goal(); PCONSTRAINT->cursorPosOnActivate = (MOUSECOORDS - RELATIVETO) * PWINDOW->m_fX11SurfaceScaledBy; } diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index aef9bb69..fb668cc2 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -192,8 +192,8 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE); if (PWINDOW) { - parentPos = PWINDOW->m_vRealPosition.goalv(); - parentSize = PWINDOW->m_vRealSize.goalv(); + parentPos = PWINDOW->m_vRealPosition.goal(); + parentSize = PWINDOW->m_vRealSize.goal(); pMonitor = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); } } @@ -298,7 +298,7 @@ void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) { const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE); if (PWINDOW) { - parentPos = PWINDOW->m_vRealPosition.goalv(); + parentPos = PWINDOW->m_vRealPosition.goal(); } } diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 1cc1b031..f32e983a 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -79,7 +79,7 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER - const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.vec(); + const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value(); const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + **PWORKSPACEGAP; const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + **PWORKSPACEGAP; @@ -118,7 +118,7 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { pSwitchedTo = m_sActiveSwipe.pWorkspaceBegin; } else if (m_sActiveSwipe.delta < 0) { // switch to left - const auto RENDEROFFSET = PWORKSPACEL ? PWORKSPACEL->m_vRenderOffset.vec() : Vector2D(); + const auto RENDEROFFSET = PWORKSPACEL ? PWORKSPACEL->m_vRenderOffset.value() : Vector2D(); if (PWORKSPACEL) m_sActiveSwipe.pMonitor->changeWorkspace(workspaceIDLeft); @@ -144,7 +144,7 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { pSwitchedTo = PWORKSPACEL; } else { // switch to right - const auto RENDEROFFSET = PWORKSPACER ? PWORKSPACER->m_vRenderOffset.vec() : Vector2D(); + const auto RENDEROFFSET = PWORKSPACER ? PWORKSPACER->m_vRenderOffset.value() : Vector2D(); if (PWORKSPACER) m_sActiveSwipe.pMonitor->changeWorkspace(workspaceIDRight); diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 959ce432..f692620c 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -267,7 +267,7 @@ void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool moti } if (motion) { - auto local = CURSORPOS - PWINDOW->m_vRealPosition.goalv(); + auto local = CURSORPOS - PWINDOW->m_vRealPosition.goal(); if (PWINDOW->m_bIsX11) local = local * PWINDOW->m_fX11SurfaceScaledBy; diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 600df302..0b26bd30 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -34,8 +34,8 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { if (m_sTouchData.touchFocusWindow) { if (m_sTouchData.touchFocusWindow->m_bIsX11) { - local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goalv()) * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; - m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_vRealPosition.goalv(); + local = (g_pInputManager->getMouseCoordsInternal() - m_sTouchData.touchFocusWindow->m_vRealPosition.goal()) * m_sTouchData.touchFocusWindow->m_fX11SurfaceScaledBy; + m_sTouchData.touchSurfaceOrigin = m_sTouchData.touchFocusWindow->m_vRealPosition.goal(); } else { g_pCompositor->vectorWindowToSurface(g_pInputManager->getMouseCoordsInternal(), m_sTouchData.touchFocusWindow, local); m_sTouchData.touchSurfaceOrigin = g_pInputManager->getMouseCoordsInternal() - local; diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index e7ea787d..88e56954 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -212,7 +212,7 @@ void CToplevelExportProtocolManager::captureToplevel(wl_client* client, wl_resou PFRAME->dmabufFormat = DRM_FORMAT_INVALID; } - PFRAME->box = {0, 0, (int)(PFRAME->pWindow->m_vRealSize.vec().x * PMONITOR->scale), (int)(PFRAME->pWindow->m_vRealSize.vec().y * PMONITOR->scale)}; + PFRAME->box = {0, 0, (int)(PFRAME->pWindow->m_vRealSize.value().x * PMONITOR->scale), (int)(PFRAME->pWindow->m_vRealSize.value().y * PMONITOR->scale)}; int ow, oh; wlr_output_effective_resolution(PMONITOR->output, &ow, &oh); PFRAME->box.transform(PMONITOR->transform, ow, oh).round(); @@ -322,7 +322,7 @@ void CToplevelExportProtocolManager::onOutputCommit(CMonitor* pMonitor, wlr_outp if (PMONITOR != g_pCompositor->getMonitorFromID(f->pWindow->m_iMonitorID)) continue; - CBox geometry = {f->pWindow->m_vRealPosition.vec().x, f->pWindow->m_vRealPosition.vec().y, f->pWindow->m_vRealSize.vec().x, f->pWindow->m_vRealSize.vec().y}; + CBox geometry = {f->pWindow->m_vRealPosition.value().x, f->pWindow->m_vRealPosition.value().y, f->pWindow->m_vRealSize.value().x, f->pWindow->m_vRealSize.value().y}; if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr())) continue; @@ -404,7 +404,7 @@ bool CToplevelExportProtocolManager::copyFrameShm(SScreencopyFrame* frame, times g_pHyprRenderer->m_bBlockSurfaceFeedback = false; if (frame->overlayCursor) - g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.vec()); + g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.value()); const auto PFORMAT = g_pHyprOpenGL->getPixelFormatFromDRM(format); if (!PFORMAT) { @@ -450,7 +450,7 @@ bool CToplevelExportProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame, ti g_pHyprRenderer->m_bBlockSurfaceFeedback = false; if (frame->overlayCursor) - g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.vec()); + g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.value()); g_pHyprRenderer->endRender(); return true; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 90e92e25..64f582f2 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -168,7 +168,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { if (!ws->m_bIsSpecialWorkspace || ws->m_iMonitorID != pMonitor->ID) continue; - if (ws->m_fAlpha.fl() == 0) + if (ws->m_fAlpha.value() == 0) continue; return true; @@ -881,7 +881,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* if (allowDim && m_pCurrentWindow && **PDIMINACTIVE) { glUniform1i(shader->applyTint, 1); - const auto DIM = m_pCurrentWindow->m_fDimPercent.fl(); + const auto DIM = m_pCurrentWindow->m_fDimPercent.value(); glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM); } else { glUniform1i(shader->applyTint, 0); @@ -1292,7 +1292,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { const auto PSURFACE = pWindow->m_pWLSurface.wlr(); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - const float A = pWindow->m_fAlpha.fl() * pWindow->m_fActiveInactiveAlpha.fl() * PWORKSPACE->m_fAlpha.fl(); + const float A = pWindow->m_fAlpha.value() * pWindow->m_fActiveInactiveAlpha.value() * PWORKSPACE->m_fAlpha.value(); if (A >= 1.f) { if (PSURFACE->opaque) @@ -1330,7 +1330,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { if (!ls->layerSurface || ls->xray != 1) continue; - if (ls->layerSurface->surface->opaque && ls->alpha.fl() >= 1.f) + if (ls->layerSurface->surface->opaque && ls->alpha.value() >= 1.f) continue; hasWindows = true; @@ -1773,25 +1773,25 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { CBox windowBox; // some mafs to figure out the correct box // the originalClosedPos is relative to the monitor's pos - Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.vec().x / (PWINDOW->m_vOriginalClosedSize.x * PMONITOR->scale)), - (PMONITOR->scale * PWINDOW->m_vRealSize.vec().y / (PWINDOW->m_vOriginalClosedSize.y * PMONITOR->scale))); + Vector2D scaleXY = Vector2D((PMONITOR->scale * PWINDOW->m_vRealSize.value().x / (PWINDOW->m_vOriginalClosedSize.x * PMONITOR->scale)), + (PMONITOR->scale * PWINDOW->m_vRealSize.value().y / (PWINDOW->m_vOriginalClosedSize.y * PMONITOR->scale))); windowBox.width = PMONITOR->vecTransformedSize.x * scaleXY.x; windowBox.height = PMONITOR->vecTransformedSize.y * scaleXY.y; - windowBox.x = ((PWINDOW->m_vRealPosition.vec().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.x * PMONITOR->scale) * scaleXY.x); - windowBox.y = ((PWINDOW->m_vRealPosition.vec().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.y * PMONITOR->scale) * scaleXY.y); + windowBox.x = ((PWINDOW->m_vRealPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.x * PMONITOR->scale) * scaleXY.x); + windowBox.y = ((PWINDOW->m_vRealPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - ((PWINDOW->m_vOriginalClosedPos.y * PMONITOR->scale) * scaleXY.y); CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; if (**PDIMAROUND && (*pWindow)->m_sAdditionalConfigData.dimAround) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMAROUND * PWINDOW->m_fAlpha.fl())); + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMAROUND * PWINDOW->m_fAlpha.value())); g_pHyprRenderer->damageMonitor(PMONITOR); } m_bEndFrame = true; - renderTextureInternalWithDamage(it->second.m_cTex, &windowBox, PWINDOW->m_fAlpha.fl(), &fakeDamage, 0); + renderTextureInternalWithDamage(it->second.m_cTex, &windowBox, PWINDOW->m_fAlpha.value(), &fakeDamage, 0); m_bEndFrame = false; } @@ -1815,19 +1815,19 @@ void CHyprOpenGLImpl::renderSnapshot(SLayerSurface** pLayer) { CBox layerBox; // some mafs to figure out the correct box // the originalClosedPos is relative to the monitor's pos - Vector2D scaleXY = Vector2D((PMONITOR->scale * PLAYER->realSize.vec().x / (PLAYER->geometry.w * PMONITOR->scale)), - (PMONITOR->scale * PLAYER->realSize.vec().y / (PLAYER->geometry.h * PMONITOR->scale))); + Vector2D scaleXY = Vector2D((PMONITOR->scale * PLAYER->realSize.value().x / (PLAYER->geometry.w * PMONITOR->scale)), + (PMONITOR->scale * PLAYER->realSize.value().y / (PLAYER->geometry.h * PMONITOR->scale))); layerBox.width = PMONITOR->vecTransformedSize.x * scaleXY.x; layerBox.height = PMONITOR->vecTransformedSize.y * scaleXY.y; - layerBox.x = ((PLAYER->realPosition.vec().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - (((PLAYER->geometry.x - PMONITOR->vecPosition.x) * PMONITOR->scale) * scaleXY.x); - layerBox.y = ((PLAYER->realPosition.vec().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - (((PLAYER->geometry.y - PMONITOR->vecPosition.y) * PMONITOR->scale) * scaleXY.y); + layerBox.x = ((PLAYER->realPosition.value().x - PMONITOR->vecPosition.x) * PMONITOR->scale) - (((PLAYER->geometry.x - PMONITOR->vecPosition.x) * PMONITOR->scale) * scaleXY.x); + layerBox.y = ((PLAYER->realPosition.value().y - PMONITOR->vecPosition.y) * PMONITOR->scale) - (((PLAYER->geometry.y - PMONITOR->vecPosition.y) * PMONITOR->scale) * scaleXY.y); CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; m_bEndFrame = true; - renderTextureInternalWithDamage(it->second.m_cTex, &layerBox, PLAYER->alpha.fl(), &fakeDamage, 0); + renderTextureInternalWithDamage(it->second.m_cTex, &layerBox, PLAYER->alpha.value(), &fakeDamage, 0); m_bEndFrame = false; } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index ca75c3b5..fcc0a2df 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -78,8 +78,8 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) windowBox.x += CORRECT.x; windowBox.y += CORRECT.y; - windowBox.width = SIZE.x * (PSURFACE->getWindow()->m_vRealSize.vec().x / PSURFACE->getWindow()->m_vReportedSize.x); - windowBox.height = SIZE.y * (PSURFACE->getWindow()->m_vRealSize.vec().y / PSURFACE->getWindow()->m_vReportedSize.y); + windowBox.width = SIZE.x * (PSURFACE->getWindow()->m_vRealSize.value().x / PSURFACE->getWindow()->m_vReportedSize.x); + windowBox.height = SIZE.y * (PSURFACE->getWindow()->m_vRealSize.value().y / PSURFACE->getWindow()->m_vReportedSize.y); } else { windowBox.width = SIZE.x; windowBox.height = SIZE.y; @@ -90,8 +90,8 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, std::max(surface->current.width, 2), std::max(surface->current.height, 2)}; if (RDATA->pWindow && RDATA->pWindow->m_vRealSize.isBeingAnimated() && RDATA->surface && RDATA->surface != surface && RDATA->squishOversized /* subsurface */) { // adjust subsurfaces to the window - windowBox.width = (windowBox.width / RDATA->pWindow->m_vReportedSize.x) * RDATA->pWindow->m_vRealSize.vec().x; - windowBox.height = (windowBox.height / RDATA->pWindow->m_vReportedSize.y) * RDATA->pWindow->m_vRealSize.vec().y; + windowBox.width = (windowBox.width / RDATA->pWindow->m_vReportedSize.x) * RDATA->pWindow->m_vRealSize.value().x; + windowBox.height = (windowBox.height / RDATA->pWindow->m_vReportedSize.y) * RDATA->pWindow->m_vRealSize.value().y; } } @@ -192,7 +192,7 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo return true; } else { if (PWINDOWWORKSPACE->m_bHasFullscreenWindow && !pWindow->m_bIsFullscreen && !pWindow->m_bIsFloating && !pWindow->m_bCreatedOverFullscreen && - pWindow->m_fAlpha.fl() == 0) + pWindow->m_fAlpha.value() == 0) return false; } } @@ -247,7 +247,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) continue; - if (w->m_fAlpha.fl() == 0.f) + if (w->m_fAlpha.value() == 0.f) continue; if (w->m_bIsFullscreen || w->m_bIsFloating) @@ -264,7 +264,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) continue; - if (w->m_fAlpha.fl() == 0.f) + if (w->m_fAlpha.value() == 0.f) continue; if (w->m_bIsFullscreen || !w->m_bIsFloating) @@ -408,12 +408,12 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* TRACY_GPU_ZONE("RenderWindow"); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - const auto REALPOS = pWindow->m_vRealPosition.vec() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.vec()); + const auto REALPOS = pWindow->m_vRealPosition.value() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.value()); static auto* const PDIMAROUND = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_around"); static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); SRenderData renderdata = {pMonitor, time}; - CBox textureBox = {REALPOS.x, REALPOS.y, std::max(pWindow->m_vRealSize.vec().x, 5.0), std::max(pWindow->m_vRealSize.vec().y, 5.0)}; + CBox textureBox = {REALPOS.x, REALPOS.y, std::max(pWindow->m_vRealSize.value().x, 5.0), std::max(pWindow->m_vRealSize.value().y, 5.0)}; renderdata.x = textureBox.x; renderdata.y = textureBox.y; @@ -430,8 +430,8 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* renderdata.surface = pWindow->m_pWLSurface.wlr(); renderdata.dontRound = (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) || (!pWindow->m_sSpecialRenderData.rounding); - renderdata.fadeAlpha = pWindow->m_fAlpha.fl() * (pWindow->m_bPinned ? 1.f : PWORKSPACE->m_fAlpha.fl()); - renderdata.alpha = pWindow->m_fActiveInactiveAlpha.fl(); + renderdata.fadeAlpha = pWindow->m_fAlpha.value() * (pWindow->m_bPinned ? 1.f : PWORKSPACE->m_fAlpha.value()); + renderdata.alpha = pWindow->m_fActiveInactiveAlpha.value(); renderdata.decorate = decorate && !pWindow->m_bX11DoesntWantBorders && (!pWindow->m_bIsFullscreen || PWORKSPACE->m_efFullscreenMode != FULLSCREEN_FULL); renderdata.rounding = ignoreAllGeometry || renderdata.dontRound ? 0 : pWindow->rounding() * pMonitor->scale; renderdata.blur = !ignoreAllGeometry; // if it shouldn't, it will be ignored later @@ -460,9 +460,9 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (!ignorePosition && pWindow->m_bIsFloating && !pWindow->m_bPinned && !pWindow->m_bIsFullscreen) { Vector2D offset; - if (PWORKSPACE->m_vRenderOffset.vec().x != 0) { + if (PWORKSPACE->m_vRenderOffset.value().x != 0) { const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - const auto PROGRESS = PWORKSPACE->m_vRenderOffset.vec().x / PWSMON->vecSize.x; + const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().x / PWSMON->vecSize.x; const auto WINBB = pWindow->getFullWindowBoundingBox(); if (WINBB.x < PWSMON->vecPosition.x) { @@ -470,9 +470,9 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* } else if (WINBB.x + WINBB.width > PWSMON->vecPosition.x + PWSMON->vecSize.x) { offset.x = (WINBB.x + WINBB.width - PWSMON->vecPosition.x - PWSMON->vecSize.x) * PROGRESS; } - } else if (PWORKSPACE->m_vRenderOffset.vec().y != 0) { + } else if (PWORKSPACE->m_vRenderOffset.value().y != 0) { const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - const auto PROGRESS = PWORKSPACE->m_vRenderOffset.vec().y / PWSMON->vecSize.y; + const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().y / PWSMON->vecSize.y; const auto WINBB = pWindow->getFullWindowBoundingBox(); if (WINBB.y < PWSMON->vecPosition.y) { @@ -488,7 +488,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* // if window is floating and we have a slide animation, clip it to its full bb if (!ignorePosition && pWindow->m_bIsFloating && !pWindow->m_bIsFullscreen && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !pWindow->m_bPinned) { - CRegion rg = pWindow->getFullWindowBoundingBox().translate(-pMonitor->vecPosition + PWORKSPACE->m_vRenderOffset.vec()).scale(pMonitor->scale); + CRegion rg = pWindow->getFullWindowBoundingBox().translate(-pMonitor->vecPosition + PWORKSPACE->m_vRenderOffset.value()).scale(pMonitor->scale); g_pHyprOpenGL->m_RenderData.clipBox = rg.getExtents(); } @@ -606,11 +606,11 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times TRACY_GPU_ZONE("RenderLayer"); - const auto REALPOS = pLayer->realPosition.vec(); - const auto REALSIZ = pLayer->realSize.vec(); + const auto REALPOS = pLayer->realPosition.value(); + const auto REALSIZ = pLayer->realSize.value(); SRenderData renderdata = {pMonitor, time, REALPOS.x, REALPOS.y}; - renderdata.fadeAlpha = pLayer->alpha.fl(); + renderdata.fadeAlpha = pLayer->alpha.value(); renderdata.blur = pLayer->forceBlur; renderdata.surface = pLayer->layerSurface->surface; renderdata.decorate = false; @@ -698,7 +698,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* // TODO: check better with solitary after MR for tearing. const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); if (!pWorkspace->m_bHasFullscreenWindow || pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL || !PFULLWINDOW || PFULLWINDOW->m_vRealSize.isBeingAnimated() || - !PFULLWINDOW->opaque() || pWorkspace->m_vRenderOffset.vec() != Vector2D{}) { + !PFULLWINDOW->opaque() || pWorkspace->m_vRenderOffset.value() != Vector2D{}) { if (!g_pHyprOpenGL->m_RenderData.pCurrentMonData->blurFBShouldRender) setOccludedForBackLayers(g_pHyprOpenGL->m_RenderData.damage, pWorkspace); @@ -738,7 +738,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* // and then special for (auto& ws : g_pCompositor->m_vWorkspaces) { - if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.fl() > 0.f && ws->m_bIsSpecialWorkspace) { + if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { const auto SPECIALANIMPROGRS = ws->m_vRenderOffset.isBeingAnimated() ? ws->m_vRenderOffset.getCurveValue() : ws->m_fAlpha.getCurveValue(); const bool ANIMOUT = !pMonitor->specialWorkspaceID; @@ -758,7 +758,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* // special for (auto& ws : g_pCompositor->m_vWorkspaces) { - if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.fl() > 0.f && ws->m_bIsSpecialWorkspace) + if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) renderWorkspaceWindows(pMonitor, ws.get(), time); } @@ -863,7 +863,7 @@ void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurfac geom.applyFromWlr(); // ignore X and Y, adjust uv - if (geom.x != 0 || geom.y != 0 || geom.width > pWindow->m_vRealSize.vec().x || geom.height > pWindow->m_vRealSize.vec().y) { + if (geom.x != 0 || geom.y != 0 || geom.width > pWindow->m_vRealSize.value().x || geom.height > pWindow->m_vRealSize.value().y) { const auto XPERC = (double)geom.x / (double)pSurface->current.width; const auto YPERC = (double)geom.y / (double)pSurface->current.height; const auto WPERC = (double)(geom.x + geom.width) / (double)pSurface->current.width; @@ -874,7 +874,7 @@ void CHyprRenderer::calculateUVForSurface(CWindow* pWindow, wlr_surface* pSurfac uvTL = uvTL + TOADDTL; // TODO: make this passed to the func. Might break in the future. - auto maxSize = pWindow->m_vRealSize.vec(); + auto maxSize = pWindow->m_vRealSize.value(); if (pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall) maxSize = pWindow->m_pWLSurface.getViewporterCorrectedSize(); @@ -2307,8 +2307,8 @@ void CHyprRenderer::setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWo continue; const auto ROUNDING = w->rounding() * PMONITOR->scale; - const Vector2D POS = w->m_vRealPosition.vec() + Vector2D{ROUNDING, ROUNDING} - PMONITOR->vecPosition + (w->m_bPinned ? Vector2D{} : pWorkspace->m_vRenderOffset.vec()); - const Vector2D SIZE = w->m_vRealSize.vec() - Vector2D{ROUNDING * 2, ROUNDING * 2}; + const Vector2D POS = w->m_vRealPosition.value() + Vector2D{ROUNDING, ROUNDING} - PMONITOR->vecPosition + (w->m_bPinned ? Vector2D{} : pWorkspace->m_vRenderOffset.value()); + const Vector2D SIZE = w->m_vRealSize.value() - Vector2D{ROUNDING * 2, ROUNDING * 2}; CBox box = {POS.x, POS.y, SIZE.x, SIZE.y}; @@ -2333,8 +2333,8 @@ void CHyprRenderer::setOccludedForBackLayers(CRegion& region, CWorkspace* pWorks continue; const auto ROUNDING = w->rounding() * PMONITOR->scale; - const Vector2D POS = w->m_vRealPosition.vec() + Vector2D{ROUNDING, ROUNDING} - PMONITOR->vecPosition + (w->m_bPinned ? Vector2D{} : pWorkspace->m_vRenderOffset.vec()); - const Vector2D SIZE = w->m_vRealSize.vec() - Vector2D{ROUNDING * 2, ROUNDING * 2}; + const Vector2D POS = w->m_vRealPosition.value() + Vector2D{ROUNDING, ROUNDING} - PMONITOR->vecPosition + (w->m_bPinned ? Vector2D{} : pWorkspace->m_vRenderOffset.value()); + const Vector2D SIZE = w->m_vRealSize.value() - Vector2D{ROUNDING * 2, ROUNDING * 2}; CBox box = {POS.x, POS.y, SIZE.x, SIZE.y}; @@ -2351,7 +2351,7 @@ bool CHyprRenderer::canSkipBackBufferClear(CMonitor* pMonitor) { if (!ls->layerSurface) continue; - if (ls->alpha.fl() < 1.f) + if (ls->alpha.value() < 1.f) continue; if (ls->geometry.x != pMonitor->vecPosition.x || ls->geometry.y != pMonitor->vecPosition.y || ls->geometry.width != pMonitor->vecSize.x || @@ -2381,7 +2381,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace); if (!PWORKSPACE || !PWORKSPACE->m_bHasFullscreenWindow || g_pInputManager->m_sDrag.drag || g_pCompositor->m_sSeat.exclusiveClient || pMonitor->specialWorkspaceID || - PWORKSPACE->m_fAlpha.fl() != 1.f || PWORKSPACE->m_vRenderOffset.vec() != Vector2D{}) + PWORKSPACE->m_fAlpha.value() != 1.f || PWORKSPACE->m_vRenderOffset.value() != Vector2D{}) return; const auto PCANDIDATE = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); @@ -2392,7 +2392,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { if (!PCANDIDATE->opaque()) return; - if (PCANDIDATE->m_vRealSize.vec() != pMonitor->vecSize || PCANDIDATE->m_vRealPosition.vec() != pMonitor->vecPosition || PCANDIDATE->m_vRealPosition.isBeingAnimated() || + if (PCANDIDATE->m_vRealSize.value() != pMonitor->vecSize || PCANDIDATE->m_vRealPosition.value() != pMonitor->vecPosition || PCANDIDATE->m_vRealPosition.isBeingAnimated() || PCANDIDATE->m_vRealSize.isBeingAnimated()) return; @@ -2400,7 +2400,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { return; for (auto& topls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { - if (topls->alpha.fl() != 0.f) + if (topls->alpha.value() != 0.f) return; } diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 1ed6c144..93a1c34c 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -40,7 +40,7 @@ CBox CHyprBorderDecoration::assignedBoxGlobal() { if (!PWORKSPACE) return box; - const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.vec() : Vector2D(); + const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); return box.translate(WORKSPACEOFFSET); } @@ -58,10 +58,10 @@ void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& of auto grad = m_pWindow->m_cRealBorderColor; const bool ANIMATED = m_pWindow->m_fBorderFadeAnimationProgress.isBeingAnimated(); - float a1 = a * (ANIMATED ? m_pWindow->m_fBorderFadeAnimationProgress.fl() : 1.f); + float a1 = a * (ANIMATED ? m_pWindow->m_fBorderFadeAnimationProgress.value() : 1.f); if (m_pWindow->m_fBorderAngleAnimationProgress.getConfig()->pValues->internalEnabled) { - grad.m_fAngle += m_pWindow->m_fBorderAngleAnimationProgress.fl() * M_PI * 2; + grad.m_fAngle += m_pWindow->m_fBorderAngleAnimationProgress.value() * M_PI * 2; grad.m_fAngle = normalizeAngleRad(grad.m_fAngle); } @@ -71,7 +71,7 @@ void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& of g_pHyprOpenGL->renderBorder(&windowBox, grad, ROUNDING, borderSize, a1); if (ANIMATED) { - float a2 = a * (1.f - m_pWindow->m_fBorderFadeAnimationProgress.fl()); + float a2 = a * (1.f - m_pWindow->m_fBorderFadeAnimationProgress.value()); g_pHyprOpenGL->renderBorder(&windowBox, m_pWindow->m_cRealBorderColorPrevious, ROUNDING, borderSize, a2); } } diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 4448ce9d..8ea96169 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -46,8 +46,8 @@ void CHyprDropShadowDecoration::damageEntire() { } void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { - m_vLastWindowPos = m_pWindow->m_vRealPosition.vec(); - m_vLastWindowSize = m_pWindow->m_vRealSize.vec(); + m_vLastWindowPos = m_pWindow->m_vRealPosition.value(); + m_vLastWindowSize = m_pWindow->m_vRealSize.value(); m_bLastWindowBox = {m_vLastWindowPos.x, m_vLastWindowPos.y, m_vLastWindowSize.x, m_vLastWindowSize.y}; m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow); @@ -58,7 +58,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D if (!g_pCompositor->windowValidMapped(m_pWindow)) return; - if (m_pWindow->m_cRealShadowColor.col() == CColor(0, 0, 0, 0)) + if (m_pWindow->m_cRealShadowColor.value() == CColor(0, 0, 0, 0)) return; // don't draw invisible shadows if (!m_pWindow->m_sSpecialRenderData.decorate) @@ -82,7 +82,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D const auto ROUNDINGBASE = m_pWindow->rounding(); const auto ROUNDING = ROUNDINGBASE > 0 ? ROUNDINGBASE + m_pWindow->getRealBorderSize() : 0; const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); - const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.vec() : Vector2D(); + const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); // draw the shadow CBox fullBox = m_bLastWindowBoxWithDecos; @@ -147,7 +147,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0); // render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit) - g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.col().a), a); + g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.value().a), a); // render black window box ("clip") g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), ROUNDING * pMonitor->scale); @@ -155,7 +155,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D alphaSwapFB.bind(); // alpha swap just has the shadow color. It will be the "texture" to render. - g_pHyprOpenGL->renderRect(&fullBox, m_pWindow->m_cRealShadowColor.col().stripA(), 0); + g_pHyprOpenGL->renderRect(&fullBox, m_pWindow->m_cRealShadowColor.value().stripA(), 0); LASTFB->bind(); @@ -166,7 +166,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D g_pHyprOpenGL->m_RenderData.damage = saveDamage; } else { - g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, m_pWindow->m_cRealShadowColor.col(), a); + g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, m_pWindow->m_cRealShadowColor.value(), a); } if (m_seExtents != m_seReportedExtents) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 20c0240f..ee0a5ce4 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -504,6 +504,6 @@ CBox CHyprGroupBarDecoration::assignedBoxGlobal() { if (!PWORKSPACE) return box; - const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.vec() : Vector2D(); + const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); return box.translate(WORKSPACEOFFSET); } diff --git a/src/render/decorations/DecorationPositioner.cpp b/src/render/decorations/DecorationPositioner.cpp index e19c361b..145a697b 100644 --- a/src/render/decorations/DecorationPositioner.cpp +++ b/src/render/decorations/DecorationPositioner.cpp @@ -124,7 +124,7 @@ void CDecorationPositioner::onWindowUpdate(CWindow* pWindow) { datas.push_back(getDataFor(wd.get(), pWindow)); } - if (WINDOWDATA->lastWindowSize == pWindow->m_vRealSize.vec() /* position not changed */ + if (WINDOWDATA->lastWindowSize == pWindow->m_vRealSize.value() /* position not changed */ && std::all_of(m_vWindowPositioningDatas.begin(), m_vWindowPositioningDatas.end(), [pWindow](const auto& data) { return pWindow != data->pWindow || !data->needsReposition; }) /* all window datas are either not for this window or don't need a reposition */ @@ -132,7 +132,7 @@ void CDecorationPositioner::onWindowUpdate(CWindow* pWindow) { ) return; - WINDOWDATA->lastWindowSize = pWindow->m_vRealSize.vec(); + WINDOWDATA->lastWindowSize = pWindow->m_vRealSize.value(); WINDOWDATA->needsRecalc = false; const bool EPHEMERAL = pWindow->m_vRealSize.isBeingAnimated(); From 7ce781e87cf7cf789a54d37af7d78f1c11d66dbc Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 2 Mar 2024 01:46:16 +0000 Subject: [PATCH 0025/2897] keybinds: better follow xkb translation state fixes #4908 --- src/helpers/WLClasses.cpp | 64 +++++++++++++++++++++++++++++ src/helpers/WLClasses.hpp | 2 + src/managers/input/InputManager.cpp | 7 ++-- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 31db2c55..3cf170bf 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -242,3 +242,67 @@ Vector2D SConstraint::getLogicConstraintSize() { return SIZE; } + +void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { + xkb_state_unref(xkbTranslationState); + + if (keymap) { + Debug::log(LOG, "Updating keyboard {:x}'s translation state from a provided keymap", (uintptr_t)this); + xkbTranslationState = xkb_state_new(keymap); + return; + } + + const auto WLRKB = wlr_keyboard_from_input_device(keyboard); + const auto KEYMAP = WLRKB->keymap; + const auto STATE = WLRKB->xkb_state; + const auto LAYOUTSNUM = xkb_keymap_num_layouts(KEYMAP); + + const auto PCONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + + for (uint32_t i = 0; i < LAYOUTSNUM; ++i) { + if (xkb_state_layout_index_is_active(STATE, i, XKB_STATE_LAYOUT_EFFECTIVE)) { + Debug::log(LOG, "Updating keyboard {:x}'s translation state from an active index {}", (uintptr_t)this, i); + + CVarList keyboardLayouts(currentRules.layout, 0, ','); + CVarList keyboardModels(currentRules.model, 0, ','); + CVarList keyboardVariants(currentRules.variant, 0, ','); + + xkb_rule_names rules = {.rules = "", .model = "", .layout = "", .variant = "", .options = ""}; + + std::string layout, model, variant; + layout = keyboardLayouts[i % keyboardLayouts.size()]; + model = keyboardModels[i % keyboardLayouts.size()]; + variant = keyboardVariants[i % keyboardLayouts.size()]; + + rules.layout = layout.c_str(); + rules.model = model.c_str(); + rules.variant = variant.c_str(); + + const auto KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + + xkbTranslationState = xkb_state_new(KEYMAP); + + xkb_keymap_unref(KEYMAP); + xkb_context_unref(PCONTEXT); + + return; + } + } + + Debug::log(LOG, "Updating keyboard {:x}'s translation state from an unknown index", (uintptr_t)this); + + xkb_rule_names rules = { + .rules = currentRules.rules.c_str(), + .model = currentRules.model.c_str(), + .layout = currentRules.layout.c_str(), + .variant = currentRules.variant.c_str(), + .options = currentRules.options.c_str(), + }; + + const auto NEWKEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + + xkbTranslationState = xkb_state_new(NEWKEYMAP); + + xkb_keymap_unref(NEWKEYMAP); + xkb_context_unref(PCONTEXT); +} diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index c9cb47e4..b1c6c9d7 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -148,6 +148,8 @@ struct SKeyboard { int numlockOn = -1; bool resolveBindsBySym = false; + void updateXKBTranslationState(xkb_keymap* const keymap = nullptr); + // For the list lookup bool operator==(const SKeyboard& rhs) const { return keyboard == rhs.keyboard; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 5944ba87..989d863a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -908,11 +908,10 @@ void CInputManager::applyConfigToKeyboard(SKeyboard* pKeyboard) { KEYMAP = xkb_keymap_new_from_names(CONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); } - xkb_state_unref(pKeyboard->xkbTranslationState); - pKeyboard->xkbTranslationState = xkb_state_new(KEYMAP); - wlr_keyboard_set_keymap(wlr_keyboard_from_input_device(pKeyboard->keyboard), KEYMAP); + pKeyboard->updateXKBTranslationState(); + wlr_keyboard_modifiers wlrMods = {0}; if (NUMLOCKON == 1) { @@ -1246,6 +1245,8 @@ void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) { const auto LAYOUT = getActiveLayoutForKeyboard(pKeyboard); + pKeyboard->updateXKBTranslationState(); + g_pEventManager->postEvent(SHyprIPCEvent{"activelayout", pKeyboard->name + "," + LAYOUT}); EMIT_HOOK_EVENT("activeLayout", (std::vector{pKeyboard, (void*)&LAYOUT})); } From 1e311c947e4601612492d2b1aa34adb186e4fbe7 Mon Sep 17 00:00:00 2001 From: ves <28784043+vesdev@users.noreply.github.com> Date: Sat, 2 Mar 2024 17:02:33 +0200 Subject: [PATCH 0026/2897] Nix: add missing dependencies for make asan (#4919) --- flake.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flake.nix b/flake.nix index 675a6d92..be80440a 100644 --- a/flake.nix +++ b/flake.nix @@ -91,7 +91,7 @@ stdenv = pkgsFor.${system}.gcc13Stdenv; } { name = "hyprland-shell"; - nativeBuildInputs = with pkgsFor.${system}; [cmake python3]; + nativeBuildInputs = with pkgsFor.${system}; [cmake python3 expat libxml2]; buildInputs = [self.packages.${system}.wlroots-hyprland]; hardeningDisable = ["fortify"]; inputsFrom = [ From 52db21660801ef4300a8b3c5dbb5c7e244ed2d19 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 2 Mar 2024 15:20:35 +0000 Subject: [PATCH 0027/2897] events: don't switch to active workspace on workspace rule --- src/events/Windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 83aa36d7..6209b77b 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -290,7 +290,7 @@ void Events::listener_mapWindow(void* owner, void* data) { if (!workspaceSilent) { if (pWorkspace->m_bIsSpecialWorkspace) g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID)->setSpecialWorkspace(pWorkspace); - else + else if (PMONITOR->activeWorkspace != REQUESTEDWORKSPACEID) g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); PMONITOR = g_pCompositor->m_pLastMonitor; From 8811f4b69ade469285635c539f20194d717c8e17 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 2 Mar 2024 15:25:32 +0000 Subject: [PATCH 0028/2897] drag: check min size for reisze drags fixes #4920 --- src/layout/IHyprLayout.cpp | 2 +- src/managers/XWaylandManager.cpp | 15 +++++++++++++++ src/managers/XWaylandManager.hpp | 1 + 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 106b5751..46ae3807 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -337,7 +337,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { } else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) { if (DRAGGINGWINDOW->m_bIsFloating) { - Vector2D MINSIZE = Vector2D(20, 20); + Vector2D MINSIZE = g_pXWaylandManager->getMinSizeForWindow(DRAGGINGWINDOW).clamp({20, 20}); Vector2D MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW); Vector2D newSize = m_vBeginDragSizeXY; diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index f70022cf..4e01d724 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -321,6 +321,21 @@ Vector2D CHyprXWaylandManager::getMaxSizeForWindow(CWindow* pWindow) { return MAXSIZE; } +Vector2D CHyprXWaylandManager::getMinSizeForWindow(CWindow* pWindow) { + if (!g_pCompositor->windowValidMapped(pWindow)) + return Vector2D(0, 0); + + if ((pWindow->m_bIsX11 && !pWindow->m_uSurface.xwayland->size_hints) || (!pWindow->m_bIsX11 && !pWindow->m_uSurface.xdg->toplevel)) + return Vector2D(0, 0); + + auto MINSIZE = pWindow->m_bIsX11 ? Vector2D(pWindow->m_uSurface.xwayland->size_hints->min_width, pWindow->m_uSurface.xwayland->size_hints->min_height) : + Vector2D(pWindow->m_uSurface.xdg->toplevel->current.min_width, pWindow->m_uSurface.xdg->toplevel->current.min_height); + + MINSIZE = MINSIZE.clamp({1, 1}); + + return MINSIZE; +} + Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); diff --git a/src/managers/XWaylandManager.hpp b/src/managers/XWaylandManager.hpp index 9fa9f46e..c374f579 100644 --- a/src/managers/XWaylandManager.hpp +++ b/src/managers/XWaylandManager.hpp @@ -27,6 +27,7 @@ class CHyprXWaylandManager { void moveXWaylandWindow(CWindow*, const Vector2D&); void checkBorders(CWindow*); Vector2D getMaxSizeForWindow(CWindow*); + Vector2D getMinSizeForWindow(CWindow*); Vector2D xwaylandToWaylandCoords(const Vector2D&); }; From be89d6faa988f6bd33a66f02746872c649a16180 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Sat, 2 Mar 2024 19:12:31 +0100 Subject: [PATCH 0029/2897] notifs: Implement notification dimissing (#4790) --- hyprctl/main.cpp | 3 +++ src/debug/HyprCtl.cpp | 21 +++++++++++++++++++++ src/debug/HyprNotificationOverlay.cpp | 12 ++++++++++++ src/debug/HyprNotificationOverlay.hpp | 1 + 4 files changed, 37 insertions(+) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 02da5f43..e6ae15bb 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -33,6 +33,7 @@ commands: cursorpos decorations devices + dismissnotify dispatch getoption globalshortcuts @@ -388,6 +389,8 @@ int main(int argc, char** argv) { request(fullRequest, 3); else if (fullRequest.contains("/plugin")) request(fullRequest, 1); + else if (fullRequest.contains("/dismissnotify")) + request(fullRequest, 0); else if (fullRequest.contains("/notify")) request(fullRequest, 2); else if (fullRequest.contains("/output")) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index b3fb0af3..962496f7 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1430,6 +1430,26 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { return "ok"; } +std::string dispatchDismissNotify(eHyprCtlOutputFormat format, std::string request) { + CVarList vars(request, 0, ' '); + + int amount = -1; + + if (vars.size() > 1) { + const auto AMOUNT = vars[1]; + if (!isNumber(AMOUNT)) + return "invalid arg 1"; + + try { + amount = std::stoi(AMOUNT); + } catch (std::exception& e) { return "invalid arg 1"; } + } + + g_pHyprNotificationOverlay->dismissNotifications(amount); + + return "ok"; +} + CHyprCtl::CHyprCtl() { registerCommand(SHyprCtlCommand{"workspaces", true, workspacesRequest}); registerCommand(SHyprCtlCommand{"workspacerules", true, workspaceRulesRequest}); @@ -1453,6 +1473,7 @@ CHyprCtl::CHyprCtl() { registerCommand(SHyprCtlCommand{"reload", false, reloadRequest}); registerCommand(SHyprCtlCommand{"plugin", false, dispatchPlugin}); registerCommand(SHyprCtlCommand{"notify", false, dispatchNotify}); + registerCommand(SHyprCtlCommand{"dismissnotify", false, dispatchDismissNotify}); registerCommand(SHyprCtlCommand{"setprop", false, dispatchSetProp}); registerCommand(SHyprCtlCommand{"seterror", false, dispatchSeterror}); registerCommand(SHyprCtlCommand{"switchxkblayout", false, switchXKBLayoutRequest}); diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index 2968134b..98c68f1f 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -50,6 +50,18 @@ void CHyprNotificationOverlay::addNotification(const std::string& text, const CC } } +void CHyprNotificationOverlay::dismissNotifications(const int amount) { + if (amount == -1) + m_dNotifications.clear(); + else { + const int AMT = std::min(amount, static_cast(m_dNotifications.size())); + + for (int i = 0; i < AMT; ++i) { + m_dNotifications.pop_front(); + } + } +} + CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { static constexpr auto ANIM_DURATION_MS = 600.0; static constexpr auto ANIM_LAG_MS = 100.0; diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp index 7a883f15..ef81b014 100644 --- a/src/debug/HyprNotificationOverlay.hpp +++ b/src/debug/HyprNotificationOverlay.hpp @@ -41,6 +41,7 @@ class CHyprNotificationOverlay { void draw(CMonitor* pMonitor); void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE); + void dismissNotifications(const int amount); bool hasAny(); private: From d2289d8327d46e6b55c06b3c639fc138c3e02d1a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 2 Mar 2024 18:53:11 +0000 Subject: [PATCH 0030/2897] xdg: minor improvements to initial size reporting fixes #4918 --- src/Window.cpp | 5 ++--- src/config/ConfigManager.cpp | 4 ++-- src/config/ConfigManager.hpp | 2 +- src/events/Windows.cpp | 4 ++-- src/layout/DwindleLayout.cpp | 7 ++----- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 997aa3f4..335010c8 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -239,13 +239,12 @@ bool CWindow::checkInputOnDecos(const eInputType type, const Vector2D& mouseCoor pid_t CWindow::getPID() { pid_t PID = -1; if (!m_bIsX11) { - - if (!m_bIsMapped) + if (!m_uSurface.xdg) return -1; wl_client_get_credentials(wl_resource_get_client(m_uSurface.xdg->resource), &PID, nullptr, nullptr); } else { - if (!m_bIsMapped) + if (!m_uSurface.xwayland) return -1; PID = m_uSurface.xwayland->pid; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 2fd5aa28..4ae62392 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -945,7 +945,7 @@ SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) { return *IT; } -std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) { +std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic, bool shadowExec) { if (!g_pCompositor->windowExists(pWindow)) return std::vector(); @@ -1093,7 +1093,7 @@ std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool } } - if (anyExecFound) // remove exec rules to unclog searches in the future, why have the garbage here. + if (anyExecFound && !shadowExec) // remove exec rules to unclog searches in the future, why have the garbage here. execRequestedRules.erase(std::remove_if(execRequestedRules.begin(), execRequestedRules.end(), [&](const SExecRequestedRule& other) { return std::ranges::any_of(PIDs, [&](const auto& pid) { return pid == other.iPid; }); })); diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index fbc61059..2effb644 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -111,7 +111,7 @@ class CConfigManager { std::string getBoundMonitorStringForWS(const std::string&); const std::deque& getAllWorkspaceRules(); - std::vector getMatchingRules(CWindow*, bool dynamic = true); + std::vector getMatchingRules(CWindow*, bool dynamic = true, bool shadowExec = false); std::vector getMatchingRules(SLayerSurface*); std::unordered_map m_mAdditionalReservedAreas; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 6209b77b..83a37ec3 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -808,8 +808,8 @@ void Events::listener_commitWindow(void* owner, void* data) { if ((maxSize.x > 0 && maxSize.x < predSize.x) || (maxSize.y > 0 && maxSize.y < predSize.y)) predSize = {}; - for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW)) { - if (r.szRule == "float") { + for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW, true, true)) { + if (r.szRule.starts_with("float")) { predSize = {}; break; } diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index fda93e97..a08dfa9e 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -1124,12 +1124,9 @@ Vector2D CHyprDwindleLayout::predictSizeForNewWindow() { static auto* const PPRESERVESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:preserve_split"); static auto* const PFLMULT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier"); - bool splitTop = false; + bool splitTop = box.h * **PFLMULT > box.w; - if (**PPRESERVESPLIT == 0 && **PSMARTSPLIT == 0) - splitTop = box.h * **PFLMULT > box.w; - - const auto SPLITSIDE = !splitTop; + const auto SPLITSIDE = !splitTop; if (SPLITSIDE) node.box = {{}, {box.w / 2.0, box.h}}; From 328ab431655f207a5ee59737291f8e8d85fab992 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 2 Mar 2024 19:06:09 +0000 Subject: [PATCH 0031/2897] hyprpm: don't copy .so if file doesn't exist ref #4926 --- hyprpm/src/core/DataState.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index b6b34375..a7f9a7ae 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -50,7 +50,8 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) { }; for (auto& p : repo.plugins) { // copy .so to the good place - std::filesystem::copy_file(p.filename, PATH + "/" + p.name + ".so"); + if (std::filesystem::exists(p.filename)) + std::filesystem::copy_file(p.filename, PATH + "/" + p.name + ".so"); DATA.emplace(p.name, toml::table{ {"filename", p.name + ".so"}, From d72ea5f2a7fdb0d0a7bf914412327195b05199b0 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 2 Mar 2024 21:04:55 +0000 Subject: [PATCH 0032/2897] input: Rewritten pointer constraints (#4889) * rewritten constraints * send pointer enter on activate if not pointer focus * minor cleanup * simulate movement on commit * don't ignore oneshot prop * various fixes * dont send motion on confined * update pos hint on region change --- src/Compositor.cpp | 43 ++---- src/Compositor.hpp | 1 - src/desktop/Constraint.cpp | 121 +++++++++++++++++ src/desktop/Constraint.hpp | 44 ++++++ src/desktop/WLSurface.cpp | 22 +++ src/desktop/WLSurface.hpp | 18 ++- src/events/Devices.cpp | 40 +----- src/events/Events.hpp | 3 - src/events/Layers.cpp | 7 +- src/events/Windows.cpp | 7 +- src/helpers/WLClasses.cpp | 76 ----------- src/helpers/WLClasses.hpp | 37 +---- src/managers/input/InputManager.cpp | 204 ++++------------------------ src/managers/input/InputManager.hpp | 45 +++--- 14 files changed, 282 insertions(+), 386 deletions(-) create mode 100644 src/desktop/Constraint.cpp create mode 100644 src/desktop/Constraint.hpp diff --git a/src/Compositor.cpp b/src/Compositor.cpp index ee38764a..37626da9 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1040,13 +1040,6 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { if (pWindow->m_phForeignToplevel) wlr_foreign_toplevel_handle_v1_set_activated(pWindow->m_phForeignToplevel, true); - if (!pWindow->m_bIsX11) { - const auto PCONSTRAINT = wlr_pointer_constraints_v1_constraint_for_surface(m_sWLRPointerConstraints, pWindow->m_uSurface.xdg->surface, m_sSeat.seat); - - if (PCONSTRAINT) - g_pInputManager->constrainMouse(m_sSeat.mouse, PCONSTRAINT); - } - g_pInputManager->recheckIdleInhibitorStatus(); // move to front of the window history @@ -1069,6 +1062,8 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) { if (g_pSessionLockManager->isSessionLocked() && !g_pSessionLockManager->isSurfaceSessionLock(pSurface)) return; + const auto PLASTSURF = m_pLastFocus; + // Unfocus last surface if should if (m_pLastFocus && !pWindowOwner) g_pXWaylandManager->activateSurface(m_pLastFocus, false); @@ -1103,6 +1098,15 @@ void CCompositor::focusSurface(wlr_surface* pSurface, CWindow* pWindowOwner) { m_pLastFocus = pSurface; EMIT_HOOK_EVENT("keyboardFocus", pSurface); + + const auto SURF = CWLSurface::surfaceFromWlr(pSurface); + const auto OLDSURF = CWLSurface::surfaceFromWlr(PLASTSURF); + + if (OLDSURF && OLDSURF->constraint()) + OLDSURF->constraint()->deactivate(); + + if (SURF && SURF->constraint()) + SURF->constraint()->activate(); } bool CCompositor::windowValidMapped(CWindow* pWindow) { @@ -1770,31 +1774,6 @@ void checkFocusSurfaceIter(wlr_surface* pSurface, int x, int y, void* data) { pair->second = pair->second || pSurface == pair->first; } -CWindow* CCompositor::getConstraintWindow(SMouse* pMouse) { - if (!pMouse->currentConstraint) - return nullptr; - - const auto PSURFACE = pMouse->currentConstraint->surface; - - for (auto& w : m_vWindows) { - if (w->isHidden() || !w->m_bIsMapped || !w->m_pWLSurface.exists()) - continue; - - if (w->m_bIsX11) { - if (PSURFACE == w->m_pWLSurface.wlr()) - return w.get(); - } else { - std::pair check = {PSURFACE, false}; - wlr_surface_for_each_surface(w->m_uSurface.xdg->surface, checkFocusSurfaceIter, &check); - - if (check.second) - return w.get(); - } - } - - return nullptr; -} - CMonitor* CCompositor::getMonitorInDirection(const char& dir) { return this->getMonitorInDirection(m_pLastMonitor, dir); } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index e9edae04..5d75b199 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -166,7 +166,6 @@ class CCompositor { int getNextAvailableNamedWorkspace(); bool isPointOnAnyMonitor(const Vector2D&); bool isPointOnReservedArea(const Vector2D& point, const CMonitor* monitor = nullptr); - CWindow* getConstraintWindow(SMouse*); CMonitor* getMonitorInDirection(const char&); CMonitor* getMonitorInDirection(CMonitor*, const char&); void updateAllWindowsAnimatedDecorationValues(); diff --git a/src/desktop/Constraint.cpp b/src/desktop/Constraint.cpp new file mode 100644 index 00000000..ea89037f --- /dev/null +++ b/src/desktop/Constraint.cpp @@ -0,0 +1,121 @@ +#include "Constraint.hpp" +#include "WLSurface.hpp" +#include "../Compositor.hpp" + +CConstraint::CConstraint(wlr_pointer_constraint_v1* constraint, CWLSurface* owner) : m_pOwner(owner), m_pConstraint(constraint) { + initSignals(); + + m_vCursorPosOnActivate = g_pInputManager->getMouseCoordsInternal(); + + g_pInputManager->m_vConstraints.push_back(this); + + if (g_pCompositor->m_pLastFocus == m_pOwner->wlr()) + activate(); +} + +CConstraint::~CConstraint() { + std::erase(g_pInputManager->m_vConstraints, this); +} + +static void onConstraintDestroy(void* owner, void* data) { + const auto CONSTRAINT = (CConstraint*)owner; + CONSTRAINT->onDestroy(); +} + +static void onConstraintSetRegion(void* owner, void* data) { + const auto CONSTRAINT = (CConstraint*)owner; + CONSTRAINT->onSetRegion(); +} + +void CConstraint::initSignals() { + hyprListener_setConstraintRegion.initCallback(&m_pConstraint->events.set_region, ::onConstraintSetRegion, this, "CConstraint"); + hyprListener_destroyConstraint.initCallback(&m_pConstraint->events.destroy, ::onConstraintDestroy, this, "CConstraint"); +} + +void CConstraint::onDestroy() { + if (active()) + deactivate(); + + // this is us + m_pOwner->m_pConstraint.reset(); +} + +void CConstraint::onSetRegion() { + if (!m_bActive) + return; + + m_rRegion.set(&m_pConstraint->region); + m_vPositionHint = m_rRegion.closestPoint(m_vPositionHint); + g_pInputManager->simulateMouseMovement(); // to warp the cursor if anything's amiss +} + +void CConstraint::onCommit() { + if (!m_bActive) + return; + + const auto COMMITTED = m_pConstraint->current.committed; + + if (COMMITTED & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { + m_bHintSet = true; + m_vPositionHint = {m_pConstraint->current.cursor_hint.x, m_pConstraint->current.cursor_hint.y}; + g_pInputManager->simulateMouseMovement(); + } + + if (COMMITTED & WLR_POINTER_CONSTRAINT_V1_STATE_REGION) + onSetRegion(); +} + +CRegion CConstraint::logicConstraintRegion() { + CRegion rg = m_rRegion; + const auto SURFBOX = m_pOwner->getSurfaceBoxGlobal(); + const auto CONSTRAINTPOS = SURFBOX.has_value() ? SURFBOX->pos() : Vector2D{}; + rg.translate(CONSTRAINTPOS); + return rg; +} + +CWLSurface* CConstraint::owner() { + return m_pOwner; +} + +bool CConstraint::isLocked() { + return m_pConstraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED; +} + +Vector2D CConstraint::logicPositionHint() { + const auto SURFBOX = m_pOwner->getSurfaceBoxGlobal(); + const auto CONSTRAINTPOS = SURFBOX.has_value() ? SURFBOX->pos() : Vector2D{}; + + return m_bHintSet ? CONSTRAINTPOS + m_vPositionHint : m_vCursorPosOnActivate; +} + +void CConstraint::deactivate() { + if (!m_bActive) + return; + + wlr_pointer_constraint_v1_send_deactivated(m_pConstraint); + m_bActive = false; + g_pCompositor->warpCursorTo(logicPositionHint(), true); + + if (m_pConstraint->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) + m_bDead = true; +} + +void CConstraint::activate() { + if (m_bActive || m_bDead) + return; + + // TODO: hack, probably not a super duper great idea + if (g_pCompositor->m_sSeat.seat->pointer_state.focused_surface != m_pOwner->wlr()) { + const auto SURFBOX = m_pOwner->getSurfaceBoxGlobal(); + const auto LOCAL = SURFBOX.has_value() ? logicPositionHint() - SURFBOX->pos() : Vector2D{}; + wlr_seat_pointer_enter(g_pCompositor->m_sSeat.seat, m_pOwner->wlr(), LOCAL.x, LOCAL.y); + } + + g_pCompositor->warpCursorTo(logicPositionHint(), true); + wlr_pointer_constraint_v1_send_activated(m_pConstraint); + m_bActive = true; +} + +bool CConstraint::active() { + return m_bActive; +} diff --git a/src/desktop/Constraint.hpp b/src/desktop/Constraint.hpp new file mode 100644 index 00000000..34690217 --- /dev/null +++ b/src/desktop/Constraint.hpp @@ -0,0 +1,44 @@ +#pragma once + +#include "../includes.hpp" +#include "../helpers/Region.hpp" +#include "../helpers/WLListener.hpp" + +class CWLSurface; + +class CConstraint { + public: + CConstraint(wlr_pointer_constraint_v1* constraint, CWLSurface* owner); + ~CConstraint(); + + void onCommit(); + void onDestroy(); + void onSetRegion(); + CRegion logicConstraintRegion(); + bool isLocked(); + Vector2D logicPositionHint(); + + void deactivate(); + void activate(); + bool active(); + + CWLSurface* owner(); + + private: + bool m_bActive = false; + CWLSurface* m_pOwner = nullptr; + wlr_pointer_constraint_v1* m_pConstraint; + + CRegion m_rRegion; + bool m_bHintSet = false; + Vector2D m_vPositionHint = {-1, -1}; + Vector2D m_vCursorPosOnActivate = {-1, -1}; + + // for oneshot constraints that have been activated once + bool m_bDead = false; + + DYNLISTENER(destroyConstraint); + DYNLISTENER(setConstraintRegion); + + void initSignals(); +}; \ No newline at end of file diff --git a/src/desktop/WLSurface.cpp b/src/desktop/WLSurface.cpp index 9ec121bb..b102c5ce 100644 --- a/src/desktop/WLSurface.cpp +++ b/src/desktop/WLSurface.cpp @@ -103,7 +103,10 @@ void CWLSurface::destroy() { if (!m_pWLRSurface) return; + m_pConstraint.reset(); + hyprListener_destroy.removeCallback(); + hyprListener_commit.removeCallback(); m_pWLRSurface->data = nullptr; m_pWindowOwner = nullptr; m_pLayerOwner = nullptr; @@ -123,6 +126,11 @@ void CWLSurface::destroy() { Debug::log(LOG, "CWLSurface {:x} called destroy()", (uintptr_t)this); } +static void onCommit(void* owner, void* data) { + const auto SURF = (CWLSurface*)owner; + SURF->onCommit(); +} + void CWLSurface::init() { if (!m_pWLRSurface) return; @@ -133,6 +141,7 @@ void CWLSurface::init() { hyprListener_destroy.initCallback( &m_pWLRSurface->events.destroy, [&](void* owner, void* data) { destroy(); }, this, "CWLSurface"); + hyprListener_commit.initCallback(&m_pWLRSurface->events.commit, ::onCommit, this, "CWLSurface"); Debug::log(LOG, "CWLSurface {:x} called init()", (uintptr_t)this); } @@ -172,3 +181,16 @@ std::optional CWLSurface::getSurfaceBoxGlobal() { return {}; } + +void CWLSurface::appendConstraint(wlr_pointer_constraint_v1* constraint) { + m_pConstraint = std::make_unique(constraint, this); +} + +void CWLSurface::onCommit() { + if (m_pConstraint) + m_pConstraint->onCommit(); +} + +CConstraint* CWLSurface::constraint() { + return m_pConstraint.get(); +} diff --git a/src/desktop/WLSurface.hpp b/src/desktop/WLSurface.hpp index 3e04b4b2..b9306eea 100644 --- a/src/desktop/WLSurface.hpp +++ b/src/desktop/WLSurface.hpp @@ -2,6 +2,7 @@ #include "../defines.hpp" #include "../helpers/Region.hpp" +#include "Constraint.hpp" class CWindow; struct SLayerSurface; @@ -32,6 +33,7 @@ class CWLSurface { Vector2D correctSmallVec() const; // returns a corrective vector for small() surfaces Vector2D getViewporterCorrectedSize() const; CRegion logicalDamage() const; + void onCommit(); // getters for owners. CWindow* getWindow(); @@ -41,6 +43,8 @@ class CWLSurface { // desktop components misc utils std::optional getSurfaceBoxGlobal(); + void appendConstraint(wlr_pointer_constraint_v1* constraint); + CConstraint* constraint(); // allow stretching. Useful for plugins. bool m_bFillIgnoreSmall = false; @@ -72,6 +76,8 @@ class CWLSurface { } static CWLSurface* surfaceFromWlr(wlr_surface* pSurface) { + if (!pSurface) + return nullptr; return (CWLSurface*)pSurface->data; } @@ -85,9 +91,15 @@ class CWLSurface { CPopup* m_pPopupOwner = nullptr; CSubsurface* m_pSubsurfaceOwner = nullptr; - void destroy(); - void init(); - bool desktopComponent(); + // + std::unique_ptr m_pConstraint; + + void destroy(); + void init(); + bool desktopComponent(); DYNLISTENER(destroy); + DYNLISTENER(commit); + + friend class CConstraint; }; \ No newline at end of file diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 1ba6cad4..64050320 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -97,44 +97,14 @@ void Events::listener_newConstraint(wl_listener* listener, void* data) { Debug::log(LOG, "New mouse constraint at {:x}", (uintptr_t)PCONSTRAINT); - g_pInputManager->m_lConstraints.emplace_back(); - const auto CONSTRAINT = &g_pInputManager->m_lConstraints.back(); + const auto SURFACE = CWLSurface::surfaceFromWlr(PCONSTRAINT->surface); - CONSTRAINT->pMouse = g_pCompositor->m_sSeat.mouse; - CONSTRAINT->constraint = PCONSTRAINT; - - CONSTRAINT->hyprListener_destroyConstraint.initCallback(&PCONSTRAINT->events.destroy, &Events::listener_destroyConstraint, CONSTRAINT, "Constraint"); - CONSTRAINT->hyprListener_setConstraintRegion.initCallback(&PCONSTRAINT->events.set_region, &Events::listener_setConstraintRegion, CONSTRAINT, "Constraint"); - - if (g_pCompositor->m_pLastFocus == PCONSTRAINT->surface) { - g_pInputManager->constrainMouse(CONSTRAINT->pMouse, PCONSTRAINT); - - if (!CONSTRAINT->hintSet) - CONSTRAINT->positionHint = Vector2D{-1, -1}; - } -} - -void Events::listener_destroyConstraint(void* owner, void* data) { - const auto PCONSTRAINT = (SConstraint*)owner; - - if (PCONSTRAINT->pMouse->currentConstraint == PCONSTRAINT->constraint) { - PCONSTRAINT->pMouse->hyprListener_commitConstraint.removeCallback(); - - const auto PWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); - - if (PWINDOW && PCONSTRAINT->active && PCONSTRAINT->constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) - g_pInputManager->warpMouseToConstraintMiddle(PCONSTRAINT); - - PCONSTRAINT->pMouse->currentConstraint = nullptr; + if (!SURFACE) { + Debug::log(ERR, "Refusing a constraint from an unassigned wl_surface {:x}", (uintptr_t)PCONSTRAINT->surface); + return; } - Debug::log(LOG, "Unconstrained mouse from {:x}", (uintptr_t)PCONSTRAINT->constraint); - - g_pInputManager->m_lConstraints.remove(*PCONSTRAINT); -} - -void Events::listener_setConstraintRegion(void* owner, void* data) { - // no + SURFACE->appendConstraint(PCONSTRAINT); } void Events::listener_newVirtPtr(wl_listener* listener, void* data) { diff --git a/src/events/Events.hpp b/src/events/Events.hpp index 69faf6c1..a105846e 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -65,10 +65,7 @@ namespace Events { DYNLISTENFUNC(keyboardMod); DYNLISTENFUNC(keyboardDestroy); - DYNLISTENFUNC(commitConstraint); LISTENER(newConstraint); - DYNLISTENFUNC(setConstraintRegion); - DYNLISTENFUNC(destroyConstraint); // Various LISTENER(requestMouse); diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 2d94f1ed..ad65f8fb 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -144,7 +144,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { const bool GRABSFOCUS = layersurface->layerSurface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE && // don't focus if constrained - (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint); + (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()); if (GRABSFOCUS) { g_pCompositor->focusSurface(layersurface->layerSurface->surface); @@ -340,8 +340,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { layersurface->realSize.setValueAndWarp(layersurface->geometry.size()); } - if (layersurface->layerSurface->current.keyboard_interactive && - (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) // don't focus if constrained + if (layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) // don't focus if constrained && !layersurface->keyboardExclusive && layersurface->mapped) { g_pCompositor->focusSurface(layersurface->layerSurface->surface); @@ -349,7 +348,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { g_pInputManager->getMouseCoordsInternal() - Vector2D(layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, layersurface->layerSurface->surface, LOCAL.x, LOCAL.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, 0, LOCAL.x, LOCAL.y); - } else if (!layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) && + } else if (!layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) && layersurface->keyboardExclusive) { g_pInputManager->refocus(); } diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 83a37ec3..778b857e 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -476,8 +476,9 @@ void Events::listener_mapWindow(void* owner, void* data) { } if (!PWINDOW->m_sAdditionalConfigData.noFocus && !PWINDOW->m_bNoInitialFocus && - (PWINDOW->m_iX11Type != 2 || (PWINDOW->m_bIsX11 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) && !workspaceSilent && - (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW)) { + (PWINDOW->m_iX11Type != 2 || + (PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xwayland->window_type_len > 0 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) && + !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW) && !g_pInputManager->isConstrained()) { g_pCompositor->focusWindow(PWINDOW); PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(**PACTIVEALPHA); PWINDOW->m_fDimPercent.setValueAndWarp(PWINDOW->m_sAdditionalConfigData.forceNoDim ? 0.f : **PDIMSTRENGTH); @@ -645,7 +646,7 @@ void Events::listener_mapWindow(void* owner, void* data) { g_pCompositor->setPreferredScaleForSurface(PWINDOW->m_pWLSurface.wlr(), PMONITOR->scale); g_pCompositor->setPreferredTransformForSurface(PWINDOW->m_pWLSurface.wlr(), PMONITOR->transform); - if (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->constraintActive) + if (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) g_pInputManager->sendMotionEventsToFocused(); // fix some xwayland apps that don't behave nicely diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 3cf170bf..8964ba59 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -167,82 +167,6 @@ bool SLayerSurface::isFadedOut() { return !realPosition.isBeingAnimated() && !realSize.isBeingAnimated() && !alpha.isBeingAnimated(); } -CRegion SConstraint::getLogicCoordsRegion() { - CRegion result; - - if (!constraint) - return result; - - const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface); - - if (!PWINDOWOWNER) - return result; - - result.add(&constraint->region); // surface-local coords - - if (!PWINDOWOWNER->m_bIsX11) { - result.translate(PWINDOWOWNER->m_vRealPosition.goal()); - return result; - } - - const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goal() : - g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y}); - - const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ? g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) : g_pCompositor->getMonitorFromVector(COORDS); - - if (!PMONITOR) - return CRegion{}; - - result.scale(PMONITOR->xwaylandScale); - - result.translate(COORDS); - - return result; -} - -Vector2D SConstraint::getLogicConstraintPos() { - if (!constraint) - return {}; - - const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface); - - if (!PWINDOWOWNER) - return {}; - - if (!PWINDOWOWNER->m_bIsX11) - return PWINDOWOWNER->m_vRealPosition.goal(); - - const auto COORDS = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealPosition.goal() : - g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y}); - - return COORDS; -} - -Vector2D SConstraint::getLogicConstraintSize() { - if (!constraint) - return {}; - - const auto PWINDOWOWNER = g_pCompositor->getWindowFromSurface(constraint->surface); - - if (!PWINDOWOWNER) - return {}; - - if (!PWINDOWOWNER->m_bIsX11) - return PWINDOWOWNER->m_vRealSize.goal(); - - const auto PMONITOR = PWINDOWOWNER->m_bIsMapped ? - g_pCompositor->getMonitorFromID(PWINDOWOWNER->m_iMonitorID) : - g_pCompositor->getMonitorFromVector(g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOWOWNER->m_uSurface.xwayland->x, PWINDOWOWNER->m_uSurface.xwayland->y})); - - if (!PMONITOR) - return {}; - - const auto SIZE = PWINDOWOWNER->m_bIsMapped ? PWINDOWOWNER->m_vRealSize.goal() : - Vector2D{PWINDOWOWNER->m_uSurface.xwayland->width, PWINDOWOWNER->m_uSurface.xwayland->height} * PMONITOR->xwaylandScale; - - return SIZE; -} - void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { xkb_state_unref(xkbTranslationState); diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index b1c6c9d7..5fc2692a 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -157,20 +157,14 @@ struct SKeyboard { }; struct SMouse { - wlr_input_device* mouse = nullptr; + wlr_input_device* mouse = nullptr; - wlr_pointer_constraint_v1* currentConstraint = nullptr; - bool constraintActive = false; + std::string name = ""; - CRegion confinedTo; + bool virt = false; - std::string name = ""; + bool connected = false; // means connected to the cursor - bool virt = false; - - bool connected = false; // means connected to the cursor - - DYNLISTENER(commitConstraint); DYNLISTENER(destroyMouse); bool operator==(const SMouse& b) const { @@ -178,29 +172,6 @@ struct SMouse { } }; -struct SConstraint { - SMouse* pMouse = nullptr; - wlr_pointer_constraint_v1* constraint = nullptr; - - bool active = false; - - bool hintSet = false; - Vector2D positionHint = {-1, -1}; // the position hint, but will use cursorPosOnActivate if unset - Vector2D cursorPosOnActivate = {-1, -1}; - - DYNLISTENER(setConstraintRegion); - DYNLISTENER(destroyConstraint); - - CRegion getLogicCoordsRegion(); - Vector2D getLogicConstraintPos(); - Vector2D getLogicConstraintSize(); - - // - bool operator==(const SConstraint& b) const { - return constraint == b.constraint; - } -}; - class CMonitor; struct SSeat { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 989d863a..c634037c 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -4,7 +4,7 @@ #include CInputManager::~CInputManager() { - m_lConstraints.clear(); + m_vConstraints.clear(); m_lKeyboards.clear(); m_lMice.clear(); m_lTablets.clear(); @@ -56,7 +56,7 @@ void CInputManager::simulateMouseMovement() { } void CInputManager::sendMotionEventsToFocused() { - if (!g_pCompositor->m_pLastFocus) + if (!g_pCompositor->m_pLastFocus || isConstrained()) return; // todo: this sucks ass @@ -139,56 +139,27 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { } // constraints - // All constraints TODO: multiple mice? - if (g_pCompositor->m_sSeat.mouse && g_pCompositor->m_sSeat.mouse->currentConstraint && !g_pCompositor->m_sSeat.exclusiveClient && !g_pSessionLockManager->isSessionLocked()) { - // XWayland windows sometimes issue constraints weirdly. - // TODO: We probably should search their parent. wlr_xwayland_surface->parent - const auto CONSTRAINTWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); - const auto PCONSTRAINT = constraintFromWlr(g_pCompositor->m_sSeat.mouse->currentConstraint); + if (g_pCompositor->m_sSeat.mouse && isConstrained()) { + const auto SURF = CWLSurface::surfaceFromWlr(g_pCompositor->m_pLastFocus); + const auto CONSTRAINT = SURF->constraint(); - if (!CONSTRAINTWINDOW || !PCONSTRAINT) { - unconstrainMouse(); - } else { - // Native Wayland apps know how 2 constrain themselves. - // XWayland, we just have to accept them. Might cause issues, but thats XWayland for ya. - const auto CONSTRAINTPOS = PCONSTRAINT->getLogicConstraintPos(); - const auto CONSTRAINTSIZE = PCONSTRAINT->getLogicConstraintSize(); - - if (g_pCompositor->m_sSeat.mouse->currentConstraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) { - // we just snap the cursor to where it should be. - - if (PCONSTRAINT->hintSet) - wlr_cursor_warp_closest(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sSeat.mouse->mouse, CONSTRAINTPOS.x + PCONSTRAINT->positionHint.x, - CONSTRAINTPOS.y + PCONSTRAINT->positionHint.y); - - return; // don't process anything else, the cursor is locked. The surface should not receive any further events. - // these are usually FPS games. They will use the relative motion. + if (SURF && CONSTRAINT) { + if (CONSTRAINT->isLocked()) { + const auto HINT = CONSTRAINT->logicPositionHint(); + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, HINT.x, HINT.y); } else { - // we restrict the cursor to the confined region - const auto REGION = PCONSTRAINT->getLogicCoordsRegion(); + const auto RG = CONSTRAINT->logicConstraintRegion(); + const auto CLOSEST = RG.closestPoint(mouseCoords); + const auto BOX = SURF->getSurfaceBoxGlobal(); + const auto CLOSESTLOCAL = CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{}); - if (!REGION.containsPoint(mouseCoords)) { - if (g_pCompositor->m_sSeat.mouse->constraintActive) { - const auto CLOSEST = REGION.closestPoint(mouseCoords); - wlr_cursor_warp_closest(g_pCompositor->m_sWLRCursor, NULL, CLOSEST.x, CLOSEST.y); - mouseCoords = getMouseCoordsInternal(); - } - } else { - if ((!CONSTRAINTWINDOW->m_bIsX11 && PMONITOR && CONSTRAINTWINDOW->m_iWorkspaceID == PMONITOR->activeWorkspace) || (CONSTRAINTWINDOW->m_bIsX11)) { - g_pCompositor->m_sSeat.mouse->constraintActive = true; - } - } + wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, CLOSEST.x, CLOSEST.y); } - if (CONSTRAINTWINDOW->m_bIsX11) { - foundSurface = CONSTRAINTWINDOW->m_pWLSurface.wlr(); - surfacePos = CONSTRAINTWINDOW->m_vRealPosition.value(); - } else { - g_pCompositor->vectorWindowToSurface(mouseCoords, CONSTRAINTWINDOW, surfaceCoords); - } + return; - pFoundWindow = CONSTRAINTWINDOW; - } + } else + Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", (uintptr_t)SURF, (uintptr_t)CONSTRAINT); } // update stuff @@ -641,7 +612,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { if (**PFOLLOWMOUSE == 3) // don't refocus on full loose break; - if ((!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) /* No constraints */ + if ((!g_pCompositor->m_sSeat.mouse || !isConstrained()) /* No constraints */ && (w && g_pCompositor->m_pLastWindow != w) /* window should change */) { // a bit hacky // if we only pressed one button, allow us to refocus. m_lCurrentlyHeldButtons.size() > 0 will stick the focus @@ -1278,133 +1249,27 @@ void CInputManager::updateDragIcon() { } } -void CInputManager::recheckConstraint(SMouse* pMouse) { - if (!pMouse->currentConstraint) - return; - - const auto PREGION = &pMouse->currentConstraint->region; - - if (pMouse->currentConstraint->type == WLR_POINTER_CONSTRAINT_V1_CONFINED) - pMouse->confinedTo.set(PREGION); - else - pMouse->confinedTo.clear(); -} - -void CInputManager::constrainMouse(SMouse* pMouse, wlr_pointer_constraint_v1* constraint) { - - if (pMouse->currentConstraint == constraint) - return; - - const auto MOUSECOORDS = getMouseCoordsInternal(); - const auto PCONSTRAINT = constraintFromWlr(constraint); - - pMouse->hyprListener_commitConstraint.removeCallback(); - - if (pMouse->currentConstraint) - wlr_pointer_constraint_v1_send_deactivated(pMouse->currentConstraint); - - if (const auto PWINDOW = g_pCompositor->getWindowFromSurface(constraint->surface); PWINDOW) { - const auto RELATIVETO = PWINDOW->m_bIsX11 ? - (PWINDOW->m_bIsMapped ? PWINDOW->m_vRealPosition.goal() : - g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y})) : - PWINDOW->m_vRealPosition.goal(); - - PCONSTRAINT->cursorPosOnActivate = (MOUSECOORDS - RELATIVETO) * PWINDOW->m_fX11SurfaceScaledBy; - } - - if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - PCONSTRAINT->hintSet = true; - PCONSTRAINT->positionHint = {constraint->current.cursor_hint.x, constraint->current.cursor_hint.y}; - } - - if (constraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT && constraint->type == WLR_POINTER_CONSTRAINT_V1_LOCKED) - warpMouseToConstraintMiddle(PCONSTRAINT); - - pMouse->currentConstraint = constraint; - pMouse->constraintActive = true; - - if (pixman_region32_not_empty(&constraint->current.region)) - pixman_region32_intersect(&constraint->region, &constraint->surface->input_region, &constraint->current.region); - else - pixman_region32_copy(&constraint->region, &constraint->surface->input_region); - - // warp to the constraint - recheckConstraint(pMouse); - - PCONSTRAINT->active = true; - - wlr_pointer_constraint_v1_send_activated(pMouse->currentConstraint); - - pMouse->hyprListener_commitConstraint.initCallback(&pMouse->currentConstraint->surface->events.commit, &Events::listener_commitConstraint, pMouse, "Mouse constraint commit"); - - Debug::log(LOG, "Constrained mouse to {:x}", (uintptr_t)pMouse->currentConstraint); -} - -void CInputManager::warpMouseToConstraintMiddle(SConstraint* pConstraint) { - - if (!pConstraint) - return; - - const auto PWINDOW = g_pCompositor->getWindowFromSurface(pConstraint->constraint->surface); - - if (PWINDOW) { - const auto RELATIVETO = pConstraint->getLogicConstraintPos(); - const auto HINTSCALE = PWINDOW->m_fX11SurfaceScaledBy; - - auto HINT = pConstraint->hintSet ? pConstraint->positionHint : pConstraint->cursorPosOnActivate; - - if (HINT == Vector2D{-1, -1}) - HINT = pConstraint->getLogicConstraintSize() / 2.f; - - if (HINT != Vector2D{-1, -1}) { - wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, RELATIVETO.x + HINT.x / HINTSCALE, RELATIVETO.y + HINT.y / HINTSCALE); - wlr_seat_pointer_warp(pConstraint->constraint->seat, pConstraint->constraint->current.cursor_hint.x, pConstraint->constraint->current.cursor_hint.y); - } - } -} - void CInputManager::unconstrainMouse() { - if (!g_pCompositor->m_sSeat.mouse || !g_pCompositor->m_sSeat.mouse->currentConstraint) + if (!g_pCompositor->m_sSeat.mouse) return; - const auto CONSTRAINTWINDOW = g_pCompositor->getConstraintWindow(g_pCompositor->m_sSeat.mouse); + for (auto& c : m_vConstraints) { + if (!c->active()) + continue; - if (CONSTRAINTWINDOW) - g_pXWaylandManager->activateSurface(CONSTRAINTWINDOW->m_pWLSurface.wlr(), false); - - wlr_pointer_constraint_v1_send_deactivated(g_pCompositor->m_sSeat.mouse->currentConstraint); - - const auto PCONSTRAINT = constraintFromWlr(g_pCompositor->m_sSeat.mouse->currentConstraint); - if (PCONSTRAINT) - PCONSTRAINT->active = false; - - g_pCompositor->m_sSeat.mouse->constraintActive = false; - - // TODO: its better to somehow detect the workspace... - g_pCompositor->m_sSeat.mouse->currentConstraint = nullptr; - - g_pCompositor->m_sSeat.mouse->hyprListener_commitConstraint.removeCallback(); + c->deactivate(); + } } -void Events::listener_commitConstraint(void* owner, void* data) { - const auto PMOUSE = (SMouse*)owner; +bool CInputManager::isConstrained() { + for (auto& c : m_vConstraints) { + if (!c->active() || c->owner()->wlr() != g_pCompositor->m_pLastFocus) + continue; - if (PMOUSE->currentConstraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_CURSOR_HINT) { - const auto PCONSTRAINT = g_pInputManager->constraintFromWlr(PMOUSE->currentConstraint); - if (PCONSTRAINT) { // should never be null but who knows - PCONSTRAINT->positionHint = Vector2D(PMOUSE->currentConstraint->current.cursor_hint.x, PMOUSE->currentConstraint->current.cursor_hint.y); - PCONSTRAINT->hintSet = true; - } + return true; } - if (PMOUSE->currentConstraint->current.committed & WLR_POINTER_CONSTRAINT_V1_STATE_REGION) { - if (pixman_region32_not_empty(&PMOUSE->currentConstraint->current.region)) - pixman_region32_intersect(&PMOUSE->currentConstraint->region, &PMOUSE->currentConstraint->surface->input_region, &PMOUSE->currentConstraint->current.region); - else - pixman_region32_copy(&PMOUSE->currentConstraint->region, &PMOUSE->currentConstraint->surface->input_region); - - g_pInputManager->recheckConstraint(PMOUSE); - } + return false; } void CInputManager::updateCapabilities() { @@ -1670,15 +1535,6 @@ std::string CInputManager::getNameForNewDevice(std::string internalName) { return proposedNewName + (dupeno == 0 ? "" : ("-" + std::to_string(dupeno))); } -SConstraint* CInputManager::constraintFromWlr(wlr_pointer_constraint_v1* constraint) { - for (auto& c : m_lConstraints) { - if (c.constraint == constraint) - return &c; - } - - return nullptr; -} - void CInputManager::releaseAllMouseButtons() { const auto buttonsCopy = m_lCurrentlyHeldButtons; diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index e32e27f8..cef8386f 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -7,6 +7,8 @@ #include "../../helpers/Timer.hpp" #include "InputMethodRelay.hpp" +class CConstraint; + enum eClickBehaviorMode { CLICKMODE_DEFAULT = 0, CLICKMODE_KILL @@ -80,11 +82,8 @@ class CInputManager { void destroyMouse(wlr_input_device*); void destroySwitch(SSwitchDevice*); - void constrainMouse(SMouse*, wlr_pointer_constraint_v1*); - void warpMouseToConstraintMiddle(SConstraint*); - void recheckConstraint(SMouse*); void unconstrainMouse(); - SConstraint* constraintFromWlr(wlr_pointer_constraint_v1*); + bool isConstrained(); std::string getActiveLayoutForKeyboard(SKeyboard*); Vector2D getMouseCoordsInternal(); @@ -120,13 +119,12 @@ class CInputManager { bool m_bWasDraggingWindow = false; // for refocus to be forced - CWindow* m_pForcedFocus = nullptr; + CWindow* m_pForcedFocus = nullptr; - SDrag m_sDrag; + SDrag m_sDrag; - std::list m_lConstraints; - std::list m_lKeyboards; - std::list m_lMice; + std::list m_lKeyboards; + std::list m_lMice; // tablets std::list m_lTablets; @@ -145,25 +143,28 @@ class CInputManager { // Exclusive layer surfaces std::deque m_dExclusiveLSes; - void newTabletTool(wlr_input_device*); - void newTabletPad(wlr_input_device*); - void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false); - void newIdleInhibitor(wlr_idle_inhibitor_v1*); - void recheckIdleInhibitorStatus(); + // constraints + std::vector m_vConstraints; - void onSwipeBegin(wlr_pointer_swipe_begin_event*); - void onSwipeEnd(wlr_pointer_swipe_end_event*); - void onSwipeUpdate(wlr_pointer_swipe_update_event*); + void newTabletTool(wlr_input_device*); + void newTabletPad(wlr_input_device*); + void focusTablet(STablet*, wlr_tablet_tool*, bool motion = false); + void newIdleInhibitor(wlr_idle_inhibitor_v1*); + void recheckIdleInhibitorStatus(); - SSwipeGesture m_sActiveSwipe; + void onSwipeBegin(wlr_pointer_swipe_begin_event*); + void onSwipeEnd(wlr_pointer_swipe_end_event*); + void onSwipeUpdate(wlr_pointer_swipe_update_event*); - SKeyboard* m_pActiveKeyboard = nullptr; + SSwipeGesture m_sActiveSwipe; - CTimer m_tmrLastCursorMovement; + SKeyboard* m_pActiveKeyboard = nullptr; - CInputMethodRelay m_sIMERelay; + CTimer m_tmrLastCursorMovement; - void updateKeyboardsLeds(wlr_input_device* pKeyboard); + CInputMethodRelay m_sIMERelay; + + void updateKeyboardsLeds(wlr_input_device* pKeyboard); // for shared mods uint32_t accumulateModsFromAllKBs(); From 508262b7db6e8e88573a4069c88b4fb88ccff1d5 Mon Sep 17 00:00:00 2001 From: JManch <61563764+JManch@users.noreply.github.com> Date: Sat, 2 Mar 2024 22:15:07 +0000 Subject: [PATCH 0033/2897] events: update render data after workspace window rule (#4931) --- src/events/Windows.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 778b857e..b8f413f9 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -258,8 +258,6 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->applyDynamicRule(r); } - PWINDOW->updateSpecialRenderData(); - // disallow tiled pinned if (PWINDOW->m_bPinned && !PWINDOW->m_bIsFloating) PWINDOW->m_bPinned = false; @@ -299,6 +297,8 @@ void Events::listener_mapWindow(void* owner, void* data) { workspaceSilent = false; } + PWINDOW->updateSpecialRenderData(); + if (PWINDOW->m_bIsFloating) { g_pLayoutManager->getCurrentLayout()->onWindowCreatedFloating(PWINDOW); PWINDOW->m_bCreatedOverFullscreen = true; From 964f1a438df5114fd9d771f24015e95b8061e503 Mon Sep 17 00:00:00 2001 From: Tobias Zimmermann Date: Sun, 3 Mar 2024 01:17:02 +0100 Subject: [PATCH 0034/2897] keybinds: Add the 'catchall' keyword that matches all keys (#4930) * Add the 'catchall' keyword that matches all keys This keyword can be used to define arbitrary keybinds. The only special behavior that it exhibits is that it matches every key, including modifier keys. Any flags still apply normally. This commit also fixes an issue that keys bound via the code:KEYCODE format were not unbound correctly. * Disallow catchall keybinds outside of submaps A catchall keybind outside a submap would prevent essentially all key events from going through to applications and would be difficult to remove again. --- src/config/ConfigManager.cpp | 30 +++++++++++++++++++++--------- src/debug/HyprCtl.cpp | 8 +++++--- src/managers/KeybindManager.cpp | 16 +++++----------- src/managers/KeybindManager.hpp | 9 ++++++++- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 4ae62392..59de33bb 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1732,6 +1732,17 @@ std::optional CConfigManager::handleAnimation(const std::string& co return {}; } +SParsedKey parseKey(const std::string& key) { + if (isNumber(key) && std::stoi(key) > 9) + return {.keycode = std::stoi(key)}; + else if (key.starts_with("code:") && isNumber(key.substr(5))) + return {.keycode = std::stoi(key.substr(5))}; + else if (key == "catchall") + return {.catchAll = true}; + else + return {.key = key}; +} + std::optional CConfigManager::handleBind(const std::string& command, const std::string& value) { // example: // bind[fl]=SUPER,G,exec,dmenu_run @@ -1807,14 +1818,15 @@ std::optional CConfigManager::handleBind(const std::string& command } if (KEY != "") { - if (isNumber(KEY) && std::stoi(KEY) > 9) - g_pKeybindManager->addKeybind( - SKeybind{"", std::stoi(KEY), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming, transparent, ignoreMods}); - else if (KEY.starts_with("code:") && isNumber(KEY.substr(5))) - g_pKeybindManager->addKeybind( - SKeybind{"", std::stoi(KEY.substr(5)), MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming, transparent, ignoreMods}); - else - g_pKeybindManager->addKeybind(SKeybind{KEY, 0, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming, transparent, ignoreMods}); + SParsedKey parsedKey = parseKey(KEY); + + if (parsedKey.catchAll && m_szCurrentSubmap == "") { + Debug::log(ERR, "Catchall not allowed outside of submap!"); + return "Invalid catchall, catchall keybinds are only allowed in submaps."; + } + + g_pKeybindManager->addKeybind(SKeybind{parsedKey.key, parsedKey.keycode, parsedKey.catchAll, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, + nonConsuming, transparent, ignoreMods}); } return {}; @@ -1825,7 +1837,7 @@ std::optional CConfigManager::handleUnbind(const std::string& comma const auto MOD = g_pKeybindManager->stringToModMask(ARGS[0]); - const auto KEY = ARGS[1]; + const auto KEY = parseKey(ARGS[1]); g_pKeybindManager->removeKeybind(MOD, KEY); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 962496f7..a65533d2 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -718,8 +718,8 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { if (kb.nonConsuming) ret += "n"; - ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, kb.key, kb.keycode, kb.handler, - kb.arg); + ret += std::format("\n\tmodmask: {}\n\tsubmap: {}\n\tkey: {}\n\tkeycode: {}\n\tcatchall: {}\n\tdispatcher: {}\n\targ: {}\n\n", kb.modmask, kb.submap, kb.key, + kb.keycode, kb.catchAll, kb.handler, kb.arg); } } else { // json @@ -737,11 +737,13 @@ std::string bindsRequest(eHyprCtlOutputFormat format, std::string request) { "submap": "{}", "key": "{}", "keycode": {}, + "catch_all": {}, "dispatcher": "{}", "arg": "{}" }},)#", kb.locked ? "true" : "false", kb.mouse ? "true" : "false", kb.release ? "true" : "false", kb.repeat ? "true" : "false", kb.nonConsuming ? "true" : "false", - kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, escapeJSONStrings(kb.handler), escapeJSONStrings(kb.arg)); + kb.modmask, escapeJSONStrings(kb.submap), escapeJSONStrings(kb.key), kb.keycode, kb.catchAll ? "true" : "false", escapeJSONStrings(kb.handler), + escapeJSONStrings(kb.arg)); } trimTrailingComma(ret); ret += "]"; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1ab8fa91..28c72029 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -95,18 +95,9 @@ void CKeybindManager::addKeybind(SKeybind kb) { m_pActiveKeybind = nullptr; } -void CKeybindManager::removeKeybind(uint32_t mod, const std::string& key) { +void CKeybindManager::removeKeybind(uint32_t mod, const SParsedKey& key) { for (auto it = m_lKeybinds.begin(); it != m_lKeybinds.end(); ++it) { - if (isNumber(key) && std::stoi(key) > 9) { - const uint32_t KEYNUM = std::stoi(key); - - if (it->modmask == mod && it->keycode == KEYNUM) { - it = m_lKeybinds.erase(it); - - if (it == m_lKeybinds.end()) - break; - } - } else if (it->modmask == mod && it->key == key) { + if (it->modmask == mod && it->key == key.key && it->keycode == key.keycode && it->catchAll == key.catchAll) { it = m_lKeybinds.erase(it); if (it == m_lKeybinds.end()) @@ -527,6 +518,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi } else if (k.keycode != 0) { if (key.keycode != k.keycode) continue; + } else if (k.catchAll) { + if (found) + continue; } else { // oMg such performance hit!!11! // this little maneouver is gonna cost us 4µs diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index edd9ede2..561ee1ab 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -13,6 +13,7 @@ class CPluginSystem; struct SKeybind { std::string key = ""; uint32_t keycode = 0; + bool catchAll = false; uint32_t modmask = 0; std::string handler = ""; std::string arg = ""; @@ -44,6 +45,12 @@ struct SPressedKeyWithMods { bool sent = false; }; +struct SParsedKey { + std::string key = ""; + uint32_t keycode = 0; + bool catchAll = false; +}; + class CKeybindManager { public: CKeybindManager(); @@ -57,7 +64,7 @@ class CKeybindManager { void onSwitchOffEvent(const std::string&); void addKeybind(SKeybind); - void removeKeybind(uint32_t, const std::string&); + void removeKeybind(uint32_t, const SParsedKey&); uint32_t stringToModMask(std::string); uint32_t keycodeToModifier(xkb_keycode_t); void clearKeybinds(); From 1762e9c6ec0140a35e79b0f4c88cce003b05ced5 Mon Sep 17 00:00:00 2001 From: JManch <61563764+JManch@users.noreply.github.com> Date: Sun, 3 Mar 2024 00:17:40 +0000 Subject: [PATCH 0035/2897] renderer: respect forceNoBlur when rendering small surface windows (#4932) --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index fcc0a2df..e8359601 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -525,7 +525,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if ((pWindow->m_bIsX11 && **PXWLUSENN) || pWindow->m_sAdditionalConfigData.nearestNeighbor.toUnderlying()) g_pHyprOpenGL->m_RenderData.useNearestNeighbor = true; - if (pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall && renderdata.blur && **PBLUR) { + if (!pWindow->m_sAdditionalConfigData.forceNoBlur && pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall && renderdata.blur && **PBLUR) { CBox wb = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; wb.scale(pMonitor->scale).round(); g_pHyprOpenGL->renderRectWithBlur(&wb, CColor(0, 0, 0, 0), renderdata.dontRound ? 0 : renderdata.rounding - 1, renderdata.fadeAlpha, From acf0b536a643bd5c87cd6097f5c94b4041797c15 Mon Sep 17 00:00:00 2001 From: Epilepsy Gatherings <73647246+phonetic112@users.noreply.github.com> Date: Sat, 2 Mar 2024 19:18:53 -0500 Subject: [PATCH 0036/2897] xwayland: disable initial focus for xwayland dialogs (#4936) --- src/managers/XWaylandManager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 4e01d724..6f49c7f2 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -222,9 +222,7 @@ bool CHyprXWaylandManager::shouldBeFloated(CWindow* pWindow, bool pending) { pWindow->m_uSurface.xwayland->window_type[i] == HYPRATOMS["_NET_WM_WINDOW_TYPE_MENU"]) pWindow->m_bX11ShouldntFocus = true; - if (pWindow->m_uSurface.xwayland->window_type[i] != HYPRATOMS["_NET_WM_WINDOW_TYPE_DIALOG"]) - pWindow->m_bNoInitialFocus = true; - + pWindow->m_bNoInitialFocus = true; return true; } From 689fced8b92ec3d8e83f5415d62dd162eedbf082 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 3 Mar 2024 00:22:40 +0000 Subject: [PATCH 0037/2897] windowrules: fix center fixes #4934 --- src/events/Windows.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index b8f413f9..dcf0b99a 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -435,7 +435,7 @@ void Events::listener_mapWindow(void* owner, void* data) { if (ARGS[1] == "1") RESERVEDOFFSET = (PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight) / 2.f; - PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.value() / 2.f + RESERVEDOFFSET; + PWINDOW->m_vRealPosition = PMONITOR->middle() - PWINDOW->m_vRealSize.goal() / 2.f + RESERVEDOFFSET; } } From 2a08f2ba84ead47bd13aae5797d0d71b2e11b612 Mon Sep 17 00:00:00 2001 From: Julien Roy Date: Sat, 2 Mar 2024 19:31:36 -0500 Subject: [PATCH 0038/2897] opengl: fix compilation on legacy renderer (#4928) --- src/render/OpenGL.cpp | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 64f582f2..cbe58753 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -353,7 +353,11 @@ void CHyprOpenGLImpl::end() { // check for gl errors const GLenum ERR = glGetError(); +#ifdef GLES2 + if (ERR == GL_CONTEXT_LOST_KHR) /* We don't have infra to recover from this */ +#else if (ERR == GL_CONTEXT_LOST) /* We don't have infra to recover from this */ +#endif RASSERT(false, "glGetError at Opengl::end() returned GL_CONTEXT_LOST. Cannot continue until proper GPU reset handling is implemented."); } @@ -2057,9 +2061,15 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { tex.m_vSize = IMAGESIZE * scale; // copy the data to an OpenGL texture we have - const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB32F : GL_RGBA; - const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA; - const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE; + const GLint glIFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? +#ifdef GLES2 + GL_RGB32F_EXT : +#else + GL_RGB32F : +#endif + GL_RGBA; + const GLint glFormat = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_RGB : GL_RGBA; + const GLint glType = CAIROFORMAT == CAIRO_FORMAT_RGB96F ? GL_FLOAT : GL_UNSIGNED_BYTE; const auto DATA = cairo_image_surface_get_data(CAIROSURFACE); glBindTexture(GL_TEXTURE_2D, tex.m_iTexID); From cc94123fa7d45e816327b4b8c8592589313f4718 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 3 Mar 2024 02:18:00 +0000 Subject: [PATCH 0039/2897] renderer: minor fixes to transformations --- src/protocols/Screencopy.cpp | 14 ++++++++------ src/render/OpenGL.cpp | 2 +- .../decorations/CHyprDropShadowDecoration.cpp | 4 ++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index 6d0aa8bc..a0c05b22 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -484,9 +484,9 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec* } CBox monbox = CBox{0, 0, frame->pMonitor->vecTransformedSize.x, frame->pMonitor->vecTransformedSize.y}.translate({-frame->box.x, -frame->box.y}); - g_pHyprOpenGL->setMonitorTransformEnabled(false); - g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); + g_pHyprOpenGL->setMonitorTransformEnabled(false); #ifndef GLES2 glBindFramebuffer(GL_READ_FRAMEBUFFER, fb.m_iFb); @@ -535,15 +535,17 @@ bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) { if (!sourceTex) return false; - CRegion fakeDamage = {0, 0, frame->box.width, frame->box.height}; + CRegion fakeDamage = {0, 0, INT16_MAX, INT16_MAX}; if (!g_pHyprRenderer->beginRender(frame->pMonitor, fakeDamage, RENDER_MODE_TO_BUFFER, frame->buffer)) return false; - CBox monbox = CBox{0, 0, frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y}.translate({-frame->box.x, -frame->box.y}); - g_pHyprOpenGL->setMonitorTransformEnabled(false); - g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); + CBox monbox = CBox{0, 0, frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y} + .translate({-frame->box.x, -frame->box.y}) // vvvv kinda ass-backwards but that's how I designed the renderer... sigh. + .transform(wlr_output_transform_invert(frame->pMonitor->output->transform), frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y); g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); + g_pHyprOpenGL->setMonitorTransformEnabled(false); g_pHyprRenderer->endRender(); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index cbe58753..de92130c 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -2173,7 +2173,7 @@ void CHyprOpenGLImpl::bindBackOnMain() { } void CHyprOpenGLImpl::setMonitorTransformEnabled(bool enabled) { - m_bEndFrame = !enabled; + m_bEndFrame = enabled; } inline const SGLPixelFormat GLES2_FORMATS[] = { diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 8ea96169..8541e06e 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -160,9 +160,9 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D LASTFB->bind(); CBox monbox = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; - g_pHyprOpenGL->setMonitorTransformEnabled(false); - g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.m_cTex, &monbox, alphaFB); g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.m_cTex, &monbox, alphaFB); + g_pHyprOpenGL->setMonitorTransformEnabled(false); g_pHyprOpenGL->m_RenderData.damage = saveDamage; } else { From c701767038a0f968b6aa5705e06b32f554cf77bd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 3 Mar 2024 17:02:15 +0000 Subject: [PATCH 0040/2897] xkb: handle invalid keymaps in updateXKBTranslationState fixes #4941 --- src/helpers/WLClasses.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 8964ba59..c71271c8 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -195,14 +195,27 @@ void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { std::string layout, model, variant; layout = keyboardLayouts[i % keyboardLayouts.size()]; - model = keyboardModels[i % keyboardLayouts.size()]; - variant = keyboardVariants[i % keyboardLayouts.size()]; + model = keyboardModels[i % keyboardModels.size()]; + variant = keyboardVariants[i % keyboardVariants.size()]; rules.layout = layout.c_str(); rules.model = model.c_str(); rules.variant = variant.c_str(); - const auto KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + auto KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + + if (!KEYMAP) { + Debug::log(ERR, "updateXKBTranslationState: keymap failed 1, fallback without model/variant"); + rules.model = ""; + rules.variant = ""; + KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + } + + if (!KEYMAP) { + Debug::log(ERR, "updateXKBTranslationState: keymap failed 2, fallback to us"); + rules.layout = "us"; + KEYMAP = xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + } xkbTranslationState = xkb_state_new(KEYMAP); From 28272d2d7450eb7fffaee42d2d2da06171e626c2 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 3 Mar 2024 09:03:23 -0800 Subject: [PATCH 0041/2897] master: Fix animate resize (#4942) * fix master animate resize * fix some other pointers --- src/layout/MasterLayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 4008b609..230e5bcf 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -707,7 +707,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { g_pXWaylandManager->setWindowSize(PWINDOW, wb.size()); } - if (m_bForceWarps && !*PANIMATE) { + if (m_bForceWarps && !**PANIMATE) { g_pHyprRenderer->damageWindow(PWINDOW); PWINDOW->m_vRealPosition.warp(); @@ -774,7 +774,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne if (WINDOWS > 2) { if (!NONE || !PNODE->isMaster) delta *= 2; - if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && *PSMARTRESIZING)) + if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && **PSMARTRESIZING)) delta = -delta; } break; From 8ccbd272cc5f3a98280d4e050f456d25aee47ee5 Mon Sep 17 00:00:00 2001 From: JManch <61563764+JManch@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:04:39 +0000 Subject: [PATCH 0042/2897] compositor: ignore grab extend behind special workspaces (#4944) * compositor: ignore grab extend behind special workspaces * ignore the window entirely --- src/Compositor.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 37626da9..7cbe3e13 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -739,8 +739,16 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular continue; - const auto BB = w->getWindowBoxUnified(properties); - CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; + const auto BB = w->getWindowBoxUnified(properties); + const auto PWINDOWMONITOR = getMonitorFromID(w->m_iMonitorID); + + // to avoid focusing windows behind special workspaces from other monitors + if (!**PSPECIALFALLTHRU && PWINDOWMONITOR && PWINDOWMONITOR->specialWorkspaceID && w->m_iWorkspaceID != PWINDOWMONITOR->specialWorkspaceID && + BB.x >= PWINDOWMONITOR->vecPosition.x && BB.y >= PWINDOWMONITOR->vecPosition.y && + BB.x + BB.width <= PWINDOWMONITOR->vecPosition.x + PWINDOWMONITOR->vecSize.x && BB.y + BB.height <= PWINDOWMONITOR->vecPosition.y + PWINDOWMONITOR->vecSize.y) + continue; + + CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) { // OR windows should add focus to parent From 063708df26e8b930f492200e1907eb47950f50e6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 3 Mar 2024 18:39:20 +0000 Subject: [PATCH 0043/2897] config: improve config value infrastructure --- src/Compositor.cpp | 103 +++++------ src/Window.cpp | 29 +-- src/config/ConfigManager.cpp | 4 +- src/config/ConfigValue.hpp | 72 ++++++++ src/debug/HyprCtl.cpp | 6 +- src/desktop/Subsurface.cpp | 5 +- src/desktop/Workspace.cpp | 9 +- src/events/Monitors.cpp | 11 +- src/events/Windows.cpp | 53 +++--- src/helpers/Monitor.cpp | 16 +- src/helpers/Watchdog.cpp | 9 +- src/layout/DwindleLayout.cpp | 123 +++++++------ src/layout/IHyprLayout.cpp | 25 +-- src/layout/MasterLayout.cpp | 163 ++++++++--------- src/macros.hpp | 1 + src/managers/AnimationManager.cpp | 9 +- src/managers/KeybindManager.cpp | 125 ++++++------- src/managers/SessionLockManager.cpp | 5 +- src/managers/ThreadManager.cpp | 7 +- src/managers/XWaylandManager.cpp | 19 +- src/managers/input/InputManager.cpp | 91 +++++----- src/managers/input/Swipe.cpp | 111 ++++++------ src/protocols/XDGOutput.cpp | 5 +- src/render/OpenGL.cpp | 163 ++++++++--------- src/render/Renderer.cpp | 165 +++++++++--------- .../decorations/CHyprBorderDecoration.cpp | 5 +- .../decorations/CHyprDropShadowDecoration.cpp | 35 ++-- .../decorations/CHyprGroupBarDecoration.cpp | 122 ++++++------- 28 files changed, 794 insertions(+), 697 deletions(-) create mode 100644 src/config/ConfigValue.hpp diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 7cbe3e13..bb80f3ef 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1,5 +1,6 @@ #include "Compositor.hpp" #include "helpers/Splashes.hpp" +#include "config/ConfigValue.hpp" #include #include #include "debug/HyprCtl.hpp" @@ -707,12 +708,12 @@ bool CCompositor::monitorExists(CMonitor* pMonitor) { } CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t properties, CWindow* pIgnoreWindow) { - const auto PMONITOR = getMonitorFromVector(pos); - static auto* const PRESIZEONBORDER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:resize_on_border"); - static auto* const PBORDERSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:border_size"); - static auto* const PBORDERGRABEXTEND = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area"); - static auto* const PSPECIALFALLTHRU = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:special_fallthrough"); - const auto BORDER_GRAB_AREA = **PRESIZEONBORDER ? **PBORDERSIZE + **PBORDERGRABEXTEND : 0; + const auto PMONITOR = getMonitorFromVector(pos); + static auto PRESIZEONBORDER = CConfigValue("general:resize_on_border"); + static auto PBORDERSIZE = CConfigValue("general:border_size"); + static auto PBORDERGRABEXTEND = CConfigValue("general:extend_border_grab_area"); + static auto PSPECIALFALLTHRU = CConfigValue("input:special_fallthrough"); + const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; // pinned windows on top of floating regardless if (properties & ALLOW_FLOATING) { @@ -743,7 +744,7 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert const auto PWINDOWMONITOR = getMonitorFromID(w->m_iMonitorID); // to avoid focusing windows behind special workspaces from other monitors - if (!**PSPECIALFALLTHRU && PWINDOWMONITOR && PWINDOWMONITOR->specialWorkspaceID && w->m_iWorkspaceID != PWINDOWMONITOR->specialWorkspaceID && + if (!*PSPECIALFALLTHRU && PWINDOWMONITOR && PWINDOWMONITOR->specialWorkspaceID && w->m_iWorkspaceID != PWINDOWMONITOR->specialWorkspaceID && BB.x >= PWINDOWMONITOR->vecPosition.x && BB.y >= PWINDOWMONITOR->vecPosition.y && BB.x + BB.width <= PWINDOWMONITOR->vecPosition.x + PWINDOWMONITOR->vecSize.x && BB.y + BB.height <= PWINDOWMONITOR->vecPosition.y + PWINDOWMONITOR->vecSize.y) continue; @@ -822,7 +823,7 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert }; // special workspace - if (PMONITOR->specialWorkspaceID && !**PSPECIALFALLTHRU) + if (PMONITOR->specialWorkspaceID && !*PSPECIALFALLTHRU) return windowForWorkspace(true); if (PMONITOR->specialWorkspaceID) { @@ -923,8 +924,8 @@ CMonitor* CCompositor::getRealMonitorFromOutput(wlr_output* out) { void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { - static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); - static auto* const PSPECIALFALLTHROUGH = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:special_fallthrough"); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); + static auto PSPECIALFALLTHROUGH = CConfigValue("input:special_fallthrough"); if (g_pCompositor->m_sSeat.exclusiveClient) { Debug::log(LOG, "Disallowing setting focus to a window due to there being an active input inhibitor layer."); @@ -998,7 +999,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { /* If special fallthrough is enabled, this behavior will be disabled, as I have no better idea of nicely tracking which window focuses are "via keybinds" and which ones aren't. */ - if (PMONITOR->specialWorkspaceID && PMONITOR->specialWorkspaceID != pWindow->m_iWorkspaceID && !pWindow->m_bPinned && !**PSPECIALFALLTHROUGH) + if (PMONITOR->specialWorkspaceID && PMONITOR->specialWorkspaceID != pWindow->m_iWorkspaceID && !pWindow->m_bPinned && !*PSPECIALFALLTHROUGH) PMONITOR->setSpecialWorkspace(nullptr); // we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window @@ -1058,7 +1059,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { std::rotate(m_vWindowFocusHistory.begin(), HISTORYPIVOT, HISTORYPIVOT + 1); } - if (**PFOLLOWMOUSE == 0) + if (*PFOLLOWMOUSE == 0) g_pInputManager->sendMotionEventsToFocused(); } @@ -1527,9 +1528,9 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { return nullptr; // 0 -> history, 1 -> shared length - static auto* const PMETHOD = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:focus_preferred_method"); + static auto PMETHOD = CConfigValue("binds:focus_preferred_method"); - const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); if (!PMONITOR) return nullptr; // ?? @@ -1589,7 +1590,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { break; } - if (**PMETHOD == 0 /* history */) { + if (*PMETHOD == 0 /* history */) { if (intersectLength > 0) { // get idx @@ -1870,32 +1871,32 @@ void CCompositor::updateWorkspaceWindows(const int64_t& id) { void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { // optimization - static auto* const PACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:col.active_border"); - static auto* const PINACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:col.inactive_border"); - static auto* const PNOGROUPACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:col.nogroup_border_active"); - static auto* const PNOGROUPINACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:col.nogroup_border"); - static auto* const PGROUPACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:col.border_active"); - static auto* const PGROUPINACTIVECOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:col.border_inactive"); - static auto* const PGROUPACTIVELOCKEDCOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:col.border_locked_active"); - static auto* const PGROUPINACTIVELOCKEDCOL = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:col.border_locked_inactive"); - static auto* const PINACTIVEALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity"); - static auto* const PACTIVEALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:active_opacity"); - static auto* const PFULLSCREENALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:fullscreen_opacity"); - static auto* const PSHADOWCOL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:col.shadow"); - static auto* const PSHADOWCOLINACTIVE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:col.shadow_inactive"); - static auto* const PDIMSTRENGTH = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_strength"); - static auto* const PDIMENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_inactive"); + static auto PACTIVECOL = CConfigValue("general:col.active_border"); + static auto PINACTIVECOL = CConfigValue("general:col.inactive_border"); + static auto PNOGROUPACTIVECOL = CConfigValue("general:col.nogroup_border_active"); + static auto PNOGROUPINACTIVECOL = CConfigValue("general:col.nogroup_border"); + static auto PGROUPACTIVECOL = CConfigValue("group:col.border_active"); + static auto PGROUPINACTIVECOL = CConfigValue("group:col.border_inactive"); + static auto PGROUPACTIVELOCKEDCOL = CConfigValue("group:col.border_locked_active"); + static auto PGROUPINACTIVELOCKEDCOL = CConfigValue("group:col.border_locked_inactive"); + static auto PINACTIVEALPHA = CConfigValue("decoration:inactive_opacity"); + static auto PACTIVEALPHA = CConfigValue("decoration:active_opacity"); + static auto PFULLSCREENALPHA = CConfigValue("decoration:fullscreen_opacity"); + static auto PSHADOWCOL = CConfigValue("decoration:col.shadow"); + static auto PSHADOWCOLINACTIVE = CConfigValue("decoration:col.shadow_inactive"); + static auto PDIMSTRENGTH = CConfigValue("decoration:dim_strength"); + static auto PDIMENABLED = CConfigValue("decoration:dim_inactive"); - auto* const ACTIVECOL = (CGradientValueData*)(*PACTIVECOL)->getData(); - auto* const INACTIVECOL = (CGradientValueData*)(*PINACTIVECOL)->getData(); - auto* const NOGROUPACTIVECOL = (CGradientValueData*)(*PNOGROUPACTIVECOL)->getData(); - auto* const NOGROUPINACTIVECOL = (CGradientValueData*)(*PNOGROUPINACTIVECOL)->getData(); - auto* const GROUPACTIVECOL = (CGradientValueData*)(*PGROUPACTIVECOL)->getData(); - auto* const GROUPINACTIVECOL = (CGradientValueData*)(*PGROUPINACTIVECOL)->getData(); - auto* const GROUPACTIVELOCKEDCOL = (CGradientValueData*)(*PGROUPACTIVELOCKEDCOL)->getData(); - auto* const GROUPINACTIVELOCKEDCOL = (CGradientValueData*)(*PGROUPINACTIVELOCKEDCOL)->getData(); + auto* const ACTIVECOL = (CGradientValueData*)(PACTIVECOL.ptr())->getData(); + auto* const INACTIVECOL = (CGradientValueData*)(PINACTIVECOL.ptr())->getData(); + auto* const NOGROUPACTIVECOL = (CGradientValueData*)(PNOGROUPACTIVECOL.ptr())->getData(); + auto* const NOGROUPINACTIVECOL = (CGradientValueData*)(PNOGROUPINACTIVECOL.ptr())->getData(); + auto* const GROUPACTIVECOL = (CGradientValueData*)(PGROUPACTIVECOL.ptr())->getData(); + auto* const GROUPINACTIVECOL = (CGradientValueData*)(PGROUPINACTIVECOL.ptr())->getData(); + auto* const GROUPACTIVELOCKEDCOL = (CGradientValueData*)(PGROUPACTIVELOCKEDCOL.ptr())->getData(); + auto* const GROUPINACTIVELOCKEDCOL = (CGradientValueData*)(PGROUPINACTIVELOCKEDCOL.ptr())->getData(); - auto setBorderColor = [&](CGradientValueData grad) -> void { + auto setBorderColor = [&](CGradientValueData grad) -> void { if (grad == pWindow->m_cRealBorderColor) return; @@ -1931,31 +1932,31 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { // opacity const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); if (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { - pWindow->m_fActiveInactiveAlpha = **PFULLSCREENALPHA; + pWindow->m_fActiveInactiveAlpha = *PFULLSCREENALPHA; } else { if (pWindow == m_pLastWindow) pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaOverride.toUnderlying() ? pWindow->m_sSpecialRenderData.alpha.toUnderlying() : - pWindow->m_sSpecialRenderData.alpha.toUnderlying() * **PACTIVEALPHA; + pWindow->m_sSpecialRenderData.alpha.toUnderlying() * *PACTIVEALPHA; else pWindow->m_fActiveInactiveAlpha = pWindow->m_sSpecialRenderData.alphaInactive.toUnderlying() != -1 ? (pWindow->m_sSpecialRenderData.alphaInactiveOverride.toUnderlying() ? pWindow->m_sSpecialRenderData.alphaInactive.toUnderlying() : - pWindow->m_sSpecialRenderData.alphaInactive.toUnderlying() * **PINACTIVEALPHA) : - **PINACTIVEALPHA; + pWindow->m_sSpecialRenderData.alphaInactive.toUnderlying() * *PINACTIVEALPHA) : + *PINACTIVEALPHA; } // dim - if (pWindow == m_pLastWindow || pWindow->m_sAdditionalConfigData.forceNoDim || !**PDIMENABLED) { + if (pWindow == m_pLastWindow || pWindow->m_sAdditionalConfigData.forceNoDim || !*PDIMENABLED) { pWindow->m_fDimPercent = 0; } else { - pWindow->m_fDimPercent = **PDIMSTRENGTH; + pWindow->m_fDimPercent = *PDIMSTRENGTH; } // shadow if (pWindow->m_iX11Type != 2 && !pWindow->m_bX11DoesntWantBorders) { if (pWindow == m_pLastWindow) { - pWindow->m_cRealShadowColor = CColor(**PSHADOWCOL); + pWindow->m_cRealShadowColor = CColor(*PSHADOWCOL); } else { - pWindow->m_cRealShadowColor = CColor(**PSHADOWCOLINACTIVE != INT_MAX ? **PSHADOWCOLINACTIVE : **PSHADOWCOL); + pWindow->m_cRealShadowColor = CColor(*PSHADOWCOLINACTIVE != INT_MAX ? *PSHADOWCOLINACTIVE : *PSHADOWCOL); } } else { pWindow->m_cRealShadowColor.setValueAndWarp(CColor(0, 0, 0, 0)); // no shadow @@ -2441,9 +2442,9 @@ void CCompositor::warpCursorTo(const Vector2D& pos, bool force) { // warpCursorTo should only be used for warps that // should be disabled with no_cursor_warps - static auto* const PNOWARPS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_cursor_warps"); + static auto PNOWARPS = CConfigValue("general:no_cursor_warps"); - if (**PNOWARPS && !force) + if (*PNOWARPS && !force) return; if (!m_sSeat.mouse) @@ -2755,9 +2756,9 @@ void CCompositor::arrangeMonitors() { for (auto& m : m_vMonitors) { Debug::log(LOG, "arrangeMonitors: {} xwayland [{}, {:.2f}]", m->szName, maxOffset, 0.f); m->vecXWaylandPosition = {maxOffset, 0}; - maxOffset += (**PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x); + maxOffset += (*PXWLFORCESCALEZERO ? m->vecTransformedSize.x : m->vecSize.x); - if (**PXWLFORCESCALEZERO) + if (*PXWLFORCESCALEZERO) m->xwaylandScale = m->scale; else m->xwaylandScale = 1.f; diff --git a/src/Window.cpp b/src/Window.cpp index 335010c8..6444aced 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -3,6 +3,7 @@ #include "render/decorations/CHyprDropShadowDecoration.hpp" #include "render/decorations/CHyprGroupBarDecoration.hpp" #include "render/decorations/CHyprBorderDecoration.hpp" +#include "config/ConfigValue.hpp" CWindow::CWindow() { m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); @@ -370,9 +371,9 @@ void CWindow::moveToWorkspace(int workspaceID) { if (m_iWorkspaceID == workspaceID) return; - static auto* const PCLOSEONLASTSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty"); + static auto PCLOSEONLASTSPECIAL = CConfigValue("misc:close_special_on_empty"); - const int OLDWORKSPACE = m_iWorkspaceID; + const int OLDWORKSPACE = m_iWorkspaceID; m_iWorkspaceID = workspaceID; @@ -393,7 +394,7 @@ void CWindow::moveToWorkspace(int workspaceID) { // update xwayland coords g_pXWaylandManager->setWindowSize(this, m_vRealSize.value()); - if (g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE) == 0 && **PCLOSEONLASTSPECIAL) { + if (g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE) == 0 && *PCLOSEONLASTSPECIAL) { const auto PWS = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); if (PWS) { @@ -436,7 +437,7 @@ void unregisterVar(void* ptr) { } void CWindow::onUnmap() { - static auto* const PCLOSEONLASTSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty"); + static auto PCLOSEONLASTSPECIAL = CConfigValue("misc:close_special_on_empty"); if (g_pCompositor->m_pLastWindow == this) g_pCompositor->m_pLastWindow = nullptr; @@ -458,7 +459,7 @@ void CWindow::onUnmap() { hyprListener_unmapWindow.removeCallback(); - if (**PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(m_iWorkspaceID) == 0 && g_pCompositor->isWorkspaceSpecial(m_iWorkspaceID)) { + if (*PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(m_iWorkspaceID) == 0 && g_pCompositor->isWorkspaceSpecial(m_iWorkspaceID)) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); if (PMONITOR && PMONITOR->specialWorkspaceID == m_iWorkspaceID) PMONITOR->setSpecialWorkspace(nullptr); @@ -1033,21 +1034,21 @@ bool CWindow::opaque() { } float CWindow::rounding() { - static auto* const PROUNDING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:rounding"); + static auto PROUNDING = CConfigValue("decoration:rounding"); - float rounding = m_sAdditionalConfigData.rounding.toUnderlying() == -1 ? **PROUNDING : m_sAdditionalConfigData.rounding.toUnderlying(); + float rounding = m_sAdditionalConfigData.rounding.toUnderlying() == -1 ? *PROUNDING : m_sAdditionalConfigData.rounding.toUnderlying(); return m_sSpecialRenderData.rounding ? rounding : 0; } void CWindow::updateSpecialRenderData() { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); - const auto WORKSPACERULE = PWORKSPACE ? g_pConfigManager->getWorkspaceRuleFor(PWORKSPACE) : SWorkspaceRule{}; - bool border = true; + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + const auto WORKSPACERULE = PWORKSPACE ? g_pConfigManager->getWorkspaceRuleFor(PWORKSPACE) : SWorkspaceRule{}; + bool border = true; - static auto* const* PNOBORDERONFLOATING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_border_on_floating"); + static auto PNOBORDERONFLOATING = CConfigValue("general:no_border_on_floating"); - if (m_bIsFloating && **PNOBORDERONFLOATING == 1) + if (m_bIsFloating && *PNOBORDERONFLOATING == 1) border = false; m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(border); @@ -1067,9 +1068,9 @@ int CWindow::getRealBorderSize() { if (m_sSpecialRenderData.borderSize.toUnderlying() != -1) return m_sSpecialRenderData.borderSize.toUnderlying(); - static auto* const* PBORDERSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:border_size"); + static auto PBORDERSIZE = CConfigValue("general:border_size"); - return **PBORDERSIZE; + return *PBORDERSIZE; } bool CWindow::canBeTorn() { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 59de33bb..7c957510 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1231,9 +1231,9 @@ void CConfigManager::ensureMonitorStatus() { } void CConfigManager::ensureVRR(CMonitor* pMonitor) { - static auto* const PVRR = reinterpret_cast(getConfigValuePtr("misc:vrr")); + static auto PVRR = reinterpret_cast(getConfigValuePtr("misc:vrr")); - static auto ensureVRRForDisplay = [&](CMonitor* m) -> void { + static auto ensureVRRForDisplay = [&](CMonitor* m) -> void { if (!m->output || m->createdByUser) return; diff --git a/src/config/ConfigValue.hpp b/src/config/ConfigValue.hpp new file mode 100644 index 00000000..6017a7cd --- /dev/null +++ b/src/config/ConfigValue.hpp @@ -0,0 +1,72 @@ +#pragma once + +#include +#include +#include +#include "../debug/Log.hpp" +#include "../macros.hpp" + +template +class CConfigValue { + public: + CConfigValue(const std::string& val) { + const auto PVHYPRLANG = g_pConfigManager->getHyprlangConfigValuePtr(val.c_str()); + + p_ = PVHYPRLANG->getDataStaticPtr(); + +#ifdef HYPRLAND_DEBUG + // verify type + const auto ANY = PVHYPRLANG->getValue(); + const auto TYPE = std::type_index(ANY.type()); + + // exceptions + const bool STRINGEX = (typeid(T) == typeid(std::string) && TYPE == typeid(Hyprlang::STRING)); + const bool CUSTOMEX = (typeid(T) == typeid(Hyprlang::CUSTOMTYPE) && (TYPE == typeid(Hyprlang::CUSTOMTYPE*) || TYPE == typeid(void*) /* dunno why it does this? */)); + + RASSERT(typeid(T) == TYPE || STRINGEX || CUSTOMEX, "Mismatched type in CConfigValue, got {} but has {}", typeid(T).name(), TYPE.name()); +#endif + } + + T* ptr() const { + return *(T* const*)p_; + } + + T operator*() const { + return *ptr(); + } + + private: + void* const* p_ = nullptr; +}; + +template <> +inline std::string* CConfigValue::ptr() const { + RASSERT(false, "Impossible to implement ptr() of CConfigValue"); + return nullptr; +} + +template <> +inline std::string CConfigValue::operator*() const { + return std::string{*(Hyprlang::STRING*)p_}; +} + +template <> +inline Hyprlang::STRING* CConfigValue::ptr() const { + return (Hyprlang::STRING*)p_; +} + +template <> +inline Hyprlang::STRING CConfigValue::operator*() const { + return *(Hyprlang::STRING*)p_; +} + +template <> +inline Hyprlang::CUSTOMTYPE* CConfigValue::ptr() const { + return *(Hyprlang::CUSTOMTYPE* const*)p_; +} + +template <> +inline Hyprlang::CUSTOMTYPE CConfigValue::operator*() const { + RASSERT(false, "Impossible to implement operator* of CConfigValue, use ptr()"); + return *ptr(); +} \ No newline at end of file diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index a65533d2..acc399b6 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -15,6 +15,8 @@ #include #include +#include "../config/ConfigValue.hpp" + static void trimTrailingComma(std::string& str) { if (!str.empty() && str.back() == ',') str.pop_back(); @@ -879,7 +881,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { g_pInputManager->setTabletConfigs(); // update tablets } - static auto* const PLAYOUT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("general:layout"); + static auto PLAYOUT = CConfigValue("general:layout"); if (COMMAND.contains("general:layout")) g_pLayoutManager->switchToLayout(*PLAYOUT); // update layout @@ -1564,7 +1566,7 @@ std::string CHyprCtl::getReply(std::string request) { g_pInputManager->setTouchDeviceConfigs(); // update touch device cfgs g_pInputManager->setTabletConfigs(); // update tablets - static auto* const PLAYOUT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("general:layout"); + static auto PLAYOUT = CConfigValue("general:layout"); g_pLayoutManager->switchToLayout(*PLAYOUT); // update layout diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index 74ae7748..d9aa3d6d 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -1,6 +1,7 @@ #include "Subsurface.hpp" #include "../events/Events.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" static void onNewSubsurface(void* owner, void* data); @@ -119,8 +120,8 @@ void CSubsurface::onCommit() { if (!g_pHyprRenderer->shouldRenderWindow(m_pWindowParent)) { m_vLastSize = Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); - if (**PLOGDAMAGE) + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); + if (*PLOGDAMAGE) Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_pWindowParent); return; } diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index e2ba1d5a..470d23e6 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -1,5 +1,6 @@ #include "Workspace.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID); @@ -42,8 +43,8 @@ CWorkspace::~CWorkspace() { } void CWorkspace::startAnim(bool in, bool left, bool instant) { - const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; - static auto* const PWORKSPACEGAP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_workspaces"); + const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; + static auto PWORKSPACEGAP = CConfigValue("general:gaps_workspaces"); if (ANIMSTYLE.starts_with("slidefade")) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); @@ -95,7 +96,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { } else if (ANIMSTYLE == "slidevert") { // fallback is slide const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); - const auto YDISTANCE = PMONITOR->vecSize.y + **PWORKSPACEGAP; + const auto YDISTANCE = PMONITOR->vecSize.y + *PWORKSPACEGAP; m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide. @@ -108,7 +109,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { } else { // fallback is slide const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); - const auto XDISTANCE = PMONITOR->vecSize.x + **PWORKSPACEGAP; + const auto XDISTANCE = PMONITOR->vecSize.x + *PWORKSPACEGAP; m_fAlpha.setValueAndWarp(1.f); // fix a bug, if switching from fade -> slide. diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index 01ea24f8..e235096b 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -4,6 +4,7 @@ #include "../render/Renderer.hpp" #include "Events.hpp" #include "../debug/HyprCtl.hpp" +#include "../config/ConfigValue.hpp" // --------------------------------------------------------- // // __ __ ____ _ _ _____ _______ ____ _____ _____ // @@ -147,12 +148,12 @@ void Events::listener_monitorFrame(void* owner, void* data) { PMONITOR->tearingState.frameScheduledWhileBusy = false; } - static auto* const PENABLERAT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:render_ahead_of_time"); - static auto* const PRATSAFE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:render_ahead_safezone"); + static auto PENABLERAT = CConfigValue("misc:render_ahead_of_time"); + static auto PRATSAFE = CConfigValue("misc:render_ahead_safezone"); PMONITOR->lastPresentationTimer.reset(); - if (**PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) { + if (*PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) { if (!PMONITOR->RATScheduled) { // render g_pHyprRenderer->renderMonitor(PMONITOR); @@ -162,14 +163,14 @@ void Events::listener_monitorFrame(void* owner, void* data) { const auto& [avg, max, min] = g_pHyprRenderer->getRenderTimes(PMONITOR); - if (max + **PRATSAFE > 1000.0 / PMONITOR->refreshRate) + if (max + *PRATSAFE > 1000.0 / PMONITOR->refreshRate) return; const auto MSLEFT = 1000.0 / PMONITOR->refreshRate - PMONITOR->lastPresentationTimer.getMillis(); PMONITOR->RATScheduled = true; - const auto ESTRENDERTIME = std::ceil(avg + **PRATSAFE); + const auto ESTRENDERTIME = std::ceil(avg + *PRATSAFE); const auto TIMETOSLEEP = std::floor(MSLEFT - ESTRENDERTIME); if (MSLEFT < 1 || MSLEFT < ESTRENDERTIME || TIMETOSLEEP < 1) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index dcf0b99a..3517badc 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -4,6 +4,7 @@ #include "../helpers/WLClasses.hpp" #include "../managers/input/InputManager.hpp" #include "../render/Renderer.hpp" +#include "../config/ConfigValue.hpp" // ------------------------------------------------------------ // // __ _______ _ _ _____ ______ _______ // @@ -38,17 +39,17 @@ void setAnimToMove(void* data) { } void Events::listener_mapWindow(void* owner, void* data) { - CWindow* PWINDOW = (CWindow*)owner; + CWindow* PWINDOW = (CWindow*)owner; - static auto* const PINACTIVEALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity"); - static auto* const PACTIVEALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:active_opacity"); - static auto* const PDIMSTRENGTH = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_strength"); - static auto* const PSWALLOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:enable_swallow"); - static auto* const PSWALLOWREGEX = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("misc:swallow_regex"); - static auto* const PSWALLOWEXREGEX = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("misc:swallow_exception_regex"); - static auto* const PNEWTAKESOVERFS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:new_window_takes_over_fullscreen"); + static auto PINACTIVEALPHA = CConfigValue("decoration:inactive_opacity"); + static auto PACTIVEALPHA = CConfigValue("decoration:active_opacity"); + static auto PDIMSTRENGTH = CConfigValue("decoration:dim_strength"); + static auto PSWALLOW = CConfigValue("misc:enable_swallow"); + static auto PSWALLOWREGEX = CConfigValue("misc:swallow_regex"); + static auto PSWALLOWEXREGEX = CConfigValue("misc:swallow_exception_regex"); + static auto PNEWTAKESOVERFS = CConfigValue("misc:new_window_takes_over_fullscreen"); - auto PMONITOR = g_pCompositor->m_pLastMonitor; + auto PMONITOR = g_pCompositor->m_pLastMonitor; auto PWORKSPACE = PMONITOR->specialWorkspaceID ? g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID) : g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; @@ -465,9 +466,9 @@ void Events::listener_mapWindow(void* owner, void* data) { if (PLSFROMFOCUS && PLSFROMFOCUS->layerSurface->current.keyboard_interactive) PWINDOW->m_bNoInitialFocus = true; if (PWORKSPACE->m_bHasFullscreenWindow && !requestsFullscreen && !PWINDOW->m_bIsFloating) { - if (**PNEWTAKESOVERFS == 0) + if (*PNEWTAKESOVERFS == 0) PWINDOW->m_bNoInitialFocus = true; - else if (**PNEWTAKESOVERFS == 2) + else if (*PNEWTAKESOVERFS == 2) g_pCompositor->setWindowFullscreen(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), false, FULLSCREEN_INVALID); else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) requestsMaximize = true; @@ -480,10 +481,10 @@ void Events::listener_mapWindow(void* owner, void* data) { (PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xwayland->window_type_len > 0 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) && !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW) && !g_pInputManager->isConstrained()) { g_pCompositor->focusWindow(PWINDOW); - PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(**PACTIVEALPHA); - PWINDOW->m_fDimPercent.setValueAndWarp(PWINDOW->m_sAdditionalConfigData.forceNoDim ? 0.f : **PDIMSTRENGTH); + PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(*PACTIVEALPHA); + PWINDOW->m_fDimPercent.setValueAndWarp(PWINDOW->m_sAdditionalConfigData.forceNoDim ? 0.f : *PDIMSTRENGTH); } else { - PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(**PINACTIVEALPHA); + PWINDOW->m_fActiveInactiveAlpha.setValueAndWarp(*PINACTIVEALPHA); PWINDOW->m_fDimPercent.setValueAndWarp(0); } @@ -547,7 +548,7 @@ void Events::listener_mapWindow(void* owner, void* data) { } // verify swallowing - if (**PSWALLOW && std::string{*PSWALLOWREGEX} != STRVAL_EMPTY) { + if (*PSWALLOW && std::string{*PSWALLOWREGEX} != STRVAL_EMPTY) { // don't swallow ourselves std::regex rgx(*PSWALLOWREGEX); if (!std::regex_match(g_pXWaylandManager->getAppIDClass(PWINDOW), rgx)) { @@ -986,9 +987,9 @@ void Events::listener_fullscreenWindow(void* owner, void* data) { } void Events::listener_activateXDG(wl_listener* listener, void* data) { - const auto E = (wlr_xdg_activation_v1_request_activate_event*)data; + const auto E = (wlr_xdg_activation_v1_request_activate_event*)data; - static auto* const PFOCUSONACTIVATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:focus_on_activate"); + static auto PFOCUSONACTIVATE = CConfigValue("misc:focus_on_activate"); Debug::log(LOG, "Activate request for surface at {:x}", (uintptr_t)E->surface); @@ -1005,7 +1006,7 @@ void Events::listener_activateXDG(wl_listener* listener, void* data) { PWINDOW->m_bIsUrgent = true; - if (!**PFOCUSONACTIVATE || (PWINDOW->m_eSuppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY)) + if (!*PFOCUSONACTIVATE || (PWINDOW->m_eSuppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY)) return; if (PWINDOW->m_bIsFloating) @@ -1016,9 +1017,9 @@ void Events::listener_activateXDG(wl_listener* listener, void* data) { } void Events::listener_activateX11(void* owner, void* data) { - const auto PWINDOW = (CWindow*)owner; + const auto PWINDOW = (CWindow*)owner; - static auto* const PFOCUSONACTIVATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:focus_on_activate"); + static auto PFOCUSONACTIVATE = CConfigValue("misc:focus_on_activate"); Debug::log(LOG, "X11 Activate request for window {}", PWINDOW); @@ -1042,7 +1043,7 @@ void Events::listener_activateX11(void* owner, void* data) { g_pEventManager->postEvent(SHyprIPCEvent{"urgent", std::format("{:x}", (uintptr_t)PWINDOW)}); EMIT_HOOK_EVENT("urgent", PWINDOW); - if (!**PFOCUSONACTIVATE || (PWINDOW->m_eSuppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY)) + if (!*PFOCUSONACTIVATE || (PWINDOW->m_eSuppressedEvents & SUPPRESS_ACTIVATE_FOCUSONLY)) return; if (PWINDOW->m_bIsFloating) @@ -1085,8 +1086,8 @@ void Events::listener_configureX11(void* owner, void* data) { PWINDOW->m_vRealPosition.setValueAndWarp(LOGICALPOS); PWINDOW->m_vRealSize.setValueAndWarp(Vector2D(E->width, E->height)); - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); - if (**PXWLFORCESCALEZERO) { + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); + if (*PXWLFORCESCALEZERO) { if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) { PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goal() / PMONITOR->scale); PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; @@ -1138,9 +1139,9 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { return; } - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - const auto LOGICALPOS = g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y}); + const auto LOGICALPOS = g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y}); if (abs(std::floor(POS.x) - LOGICALPOS.x) > 2 || abs(std::floor(POS.y) - LOGICALPOS.y) > 2 || abs(std::floor(SIZ.x) - PWINDOW->m_uSurface.xwayland->width) > 2 || abs(std::floor(SIZ.y) - PWINDOW->m_uSurface.xwayland->height) > 2) { @@ -1153,7 +1154,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { if (abs(std::floor(SIZ.x) - PWINDOW->m_uSurface.xwayland->width) > 2 || abs(std::floor(SIZ.y) - PWINDOW->m_uSurface.xwayland->height) > 2) PWINDOW->m_vRealSize.setValueAndWarp(Vector2D(PWINDOW->m_uSurface.xwayland->width, PWINDOW->m_uSurface.xwayland->height)); - if (**PXWLFORCESCALEZERO) { + if (*PXWLFORCESCALEZERO) { if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); PMONITOR) { const Vector2D DELTA = PWINDOW->m_vRealSize.goal() - PWINDOW->m_vRealSize.goal() / PMONITOR->scale; PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goal() / PMONITOR->scale); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 7f36ccd4..12857969 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -4,6 +4,8 @@ #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" + int ratHandler(void* data) { g_pHyprRenderer->renderMonitor((CMonitor*)data); @@ -330,8 +332,8 @@ void CMonitor::onDisconnect(bool destroy) { } void CMonitor::addDamage(const pixman_region32_t* rg) { - static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor"); - if (**PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { + static auto PZOOMFACTOR = CConfigValue("misc:cursor_zoom_factor"); + if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { wlr_damage_ring_add_whole(&damage); g_pCompositor->scheduleFrameForMonitor(this); } else if (wlr_damage_ring_add(&damage, rg)) @@ -343,8 +345,8 @@ void CMonitor::addDamage(const CRegion* rg) { } void CMonitor::addDamage(const CBox* box) { - static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor"); - if (**PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { + static auto PZOOMFACTOR = CConfigValue("misc:cursor_zoom_factor"); + if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { wlr_damage_ring_add_whole(&damage); g_pCompositor->scheduleFrameForMonitor(this); } @@ -568,11 +570,11 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool } if (!noFocus && !g_pCompositor->m_pLastMonitor->specialWorkspaceID) { - static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); - CWindow* pWindow = pWorkspace->getLastFocusedWindow(); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); + CWindow* pWindow = pWorkspace->getLastFocusedWindow(); if (!pWindow) { - if (**PFOLLOWMOUSE == 1) + if (*PFOLLOWMOUSE == 1) pWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindow) diff --git a/src/helpers/Watchdog.cpp b/src/helpers/Watchdog.cpp index ce4d2707..afb8a946 100644 --- a/src/helpers/Watchdog.cpp +++ b/src/helpers/Watchdog.cpp @@ -1,6 +1,7 @@ #include "Watchdog.hpp" #include #include "config/ConfigManager.hpp" +#include "../config/ConfigValue.hpp" CWatchdog::~CWatchdog() { m_bExitThread = true; @@ -13,7 +14,7 @@ CWatchdog::CWatchdog() { m_iMainThreadPID = pthread_self(); m_pWatchdog = std::make_unique([this] { - static auto* const PTIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout"); + static auto PTIMEOUT = CConfigValue("debug:watchdog_timeout"); while (1337) { std::unique_lock lk(m_mWatchdogMutex); @@ -21,7 +22,7 @@ CWatchdog::CWatchdog() { if (!m_bWillWatch) m_cvWatchdogCondition.wait(lk, [this] { return m_bNotified; }); else { - if (m_cvWatchdogCondition.wait_for(lk, std::chrono::milliseconds((int)(**PTIMEOUT * 1000.0)), [this] { return m_bNotified; }) == false) + if (m_cvWatchdogCondition.wait_for(lk, std::chrono::milliseconds((int)(*PTIMEOUT * 1000.0)), [this] { return m_bNotified; }) == false) pthread_kill(m_iMainThreadPID, SIGUSR1); } @@ -37,9 +38,9 @@ CWatchdog::CWatchdog() { } void CWatchdog::startWatching() { - static auto* const PTIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout"); + static auto PTIMEOUT = CConfigValue("debug:watchdog_timeout"); - if (**PTIMEOUT == 0) + if (*PTIMEOUT == 0) return; m_tTriggered = std::chrono::high_resolution_clock::now(); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index a08dfa9e..56539848 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -1,15 +1,16 @@ #include "DwindleLayout.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) { if (children[0]) { - static auto* const PSMARTSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_split"); - static auto* const PPRESERVESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:preserve_split"); - static auto* const PFLMULT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier"); + static auto PSMARTSPLIT = CConfigValue("dwindle:smart_split"); + static auto PPRESERVESPLIT = CConfigValue("dwindle:preserve_split"); + static auto PFLMULT = CConfigValue("dwindle:split_width_multiplier"); - if (**PPRESERVESPLIT == 0 && **PSMARTSPLIT == 0) - splitTop = box.h * **PFLMULT > box.w; + if (*PPRESERVESPLIT == 0 && *PSMARTSPLIT == 0) + splitTop = box.h * *PFLMULT > box.w; if (verticalOverride == true) splitTop = true; @@ -140,16 +141,16 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->updateSpecialRenderData(); - static auto* const PNOGAPSWHENONLY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:no_gaps_when_only"); - static auto* const PGAPSINDATA = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:gaps_in"); - static auto* const PGAPSOUTDATA = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:gaps_out"); - auto* const PGAPSIN = (CCssGapData*)(*PGAPSINDATA)->getData(); - auto* const PGAPSOUT = (CCssGapData*)(*PGAPSOUTDATA)->getData(); + static auto PNOGAPSWHENONLY = CConfigValue("dwindle:no_gaps_when_only"); + static auto PGAPSINDATA = CConfigValue("general:gaps_in"); + static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); + auto* const PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); + auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); - auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); - auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); + auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); + auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); - CBox nodeBox = pNode->box; + CBox nodeBox = pNode->box; nodeBox.round(); PWINDOW->m_vSize = nodeBox.size(); @@ -157,10 +158,10 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID); - if (**PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && + if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { - PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(**PNOGAPSWHENONLY == 2); + PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2); PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true); PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -217,9 +218,9 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) { // if special, we adjust the coords a bit - static auto* const PSCALEFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:special_scale_factor"); + static auto PSCALEFACTOR = CConfigValue("dwindle:special_scale_factor"); - CBox wb = {calcPos + (calcSize - calcSize * **PSCALEFACTOR) / 2.f, calcSize * **PSCALEFACTOR}; + CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR}; wb.round(); // avoid rounding mess PWINDOW->m_vRealPosition = wb.pos(); @@ -253,12 +254,12 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire return; m_lDwindleNodesData.push_back(SDwindleNodeData()); - const auto PNODE = &m_lDwindleNodesData.back(); + const auto PNODE = &m_lDwindleNodesData.back(); - const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - static auto* const PUSEACTIVE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:use_active_for_splits"); - static auto* const PDEFAULTSPLIT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:default_split_ratio"); + static auto PUSEACTIVE = CConfigValue("dwindle:use_active_for_splits"); + static auto PDEFAULTSPLIT = CConfigValue("dwindle:default_split_ratio"); if (direction != DIRECTION_DEFAULT && overrideDirection == DIRECTION_DEFAULT) overrideDirection = direction; @@ -275,13 +276,13 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto MONFROMCURSOR = g_pCompositor->getMonitorFromVector(MOUSECOORDS); if (PMONITOR->ID == MONFROMCURSOR->ID && - (PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !**PUSEACTIVE) { + (PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !*PUSEACTIVE) { OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS); - } else if (**PUSEACTIVE) { + } else if (*PUSEACTIVE) { if (g_pCompositor->m_pLastWindow && !g_pCompositor->m_pLastWindow->m_bIsFloating && g_pCompositor->m_pLastWindow != pWindow && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) { OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow); @@ -343,8 +344,8 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire && pWindow->canBeGroupedInto(OPENINGON->pWindow) && !m_vOverrideFocalPoint) { // we are not moving window m_lDwindleNodesData.remove(*PNODE); - static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); - (**USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); + static auto USECURRPOS = CConfigValue("group:insert_after_current"); + (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); OPENINGON->pWindow->setGroupCurrent(pWindow); pWindow->applyGroupRules(); @@ -367,20 +368,20 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire NEWPARENT->workspaceID = OPENINGON->workspaceID; NEWPARENT->pParent = OPENINGON->pParent; NEWPARENT->isNode = true; // it is a node - NEWPARENT->splitRatio = std::clamp(**PDEFAULTSPLIT, 0.1f, 1.9f); + NEWPARENT->splitRatio = std::clamp(*PDEFAULTSPLIT, 0.1f, 1.9f); - const auto PWIDTHMULTIPLIER = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier"); + static auto PWIDTHMULTIPLIER = CConfigValue("dwindle:split_width_multiplier"); // if cursor over first child, make it first, etc - const auto SIDEBYSIDE = NEWPARENT->box.w > NEWPARENT->box.h * **PWIDTHMULTIPLIER; + const auto SIDEBYSIDE = NEWPARENT->box.w > NEWPARENT->box.h * *PWIDTHMULTIPLIER; NEWPARENT->splitTop = !SIDEBYSIDE; - static auto* const PFORCESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:force_split"); - static auto* const PERMANENTDIRECTIONOVERRIDE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:permanent_direction_override"); - static auto* const PSMARTSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_split"); + static auto PFORCESPLIT = CConfigValue("dwindle:force_split"); + static auto PERMANENTDIRECTIONOVERRIDE = CConfigValue("dwindle:permanent_direction_override"); + static auto PSMARTSPLIT = CConfigValue("dwindle:smart_split"); - bool horizontalOverride = false; - bool verticalOverride = false; + bool horizontalOverride = false; + bool verticalOverride = false; // let user select position -> top, right, bottom, left if (overrideDirection != DIRECTION_DEFAULT) { @@ -401,9 +402,9 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire } // whether or not the override persists after opening one window - if (**PERMANENTDIRECTIONOVERRIDE == 0) + if (*PERMANENTDIRECTIONOVERRIDE == 0) overrideDirection = DIRECTION_DEFAULT; - } else if (**PSMARTSPLIT == 1) { + } else if (*PSMARTSPLIT == 1) { const auto PARENT_CENTER = NEWPARENT->box.pos() + NEWPARENT->box.size() / 2; const auto PARENT_PROPORTIONS = NEWPARENT->box.h / NEWPARENT->box.w; const auto DELTA = MOUSECOORDS - PARENT_CENTER; @@ -434,11 +435,11 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire NEWPARENT->children[1] = OPENINGON; } } - } else if (**PFORCESPLIT == 0 || !pWindow->m_bFirstMap) { + } else if (*PFORCESPLIT == 0 || !pWindow->m_bFirstMap) { if ((SIDEBYSIDE && - VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / **PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) || + VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y + NEWPARENT->box.h)) || (!SIDEBYSIDE && - VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / **PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) { + VECINRECT(MOUSECOORDS, NEWPARENT->box.x, NEWPARENT->box.y / *PWIDTHMULTIPLIER, NEWPARENT->box.x + NEWPARENT->box.w, NEWPARENT->box.y + NEWPARENT->box.h / 2.f))) { // we are hovering over the first node, make PNODE first. NEWPARENT->children[1] = OPENINGON; NEWPARENT->children[0] = PNODE; @@ -448,7 +449,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire NEWPARENT->children[1] = PNODE; } } else { - if (**PFORCESPLIT == 1) { + if (*PFORCESPLIT == 1) { NEWPARENT->children[1] = OPENINGON; NEWPARENT->children[0] = PNODE; } else { @@ -467,7 +468,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire } // Update the children - if (!verticalOverride && (NEWPARENT->box.w * **PWIDTHMULTIPLIER > NEWPARENT->box.h || horizontalOverride)) { + if (!verticalOverride && (NEWPARENT->box.w * *PWIDTHMULTIPLIER > NEWPARENT->box.h || horizontalOverride)) { // split left/right -> forced OPENINGON->box = {NEWPARENT->box.pos(), Vector2D(NEWPARENT->box.w / 2.f, NEWPARENT->box.h)}; PNODE->box = {Vector2D(NEWPARENT->box.x + NEWPARENT->box.w / 2.f, NEWPARENT->box.y), Vector2D(NEWPARENT->box.w / 2.f, NEWPARENT->box.h)}; @@ -611,8 +612,8 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn return; } - const auto PANIMATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes"); - const auto PSMARTRESIZING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_resizing"); + static auto PANIMATE = CConfigValue("misc:animate_manual_resizes"); + static auto PSMARTRESIZING = CConfigValue("dwindle:smart_resizing"); // get some data about our window const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); @@ -655,7 +656,7 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn PWINDOW->m_vPseudoSize = {std::clamp(PWINDOW->m_vPseudoSize.x, 30.0, wbox.w), std::clamp(PWINDOW->m_vPseudoSize.y, 30.0, wbox.h)}; PWINDOW->m_vLastFloatingSize = PWINDOW->m_vPseudoSize; - PNODE->recalcSizePosRecursive(**PANIMATE == 0); + PNODE->recalcSizePosRecursive(*PANIMATE == 0); return; } @@ -669,7 +670,7 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (DISPLAYBOTTOM && DISPLAYTOP) allowedMovement.y = 0; - if (**PSMARTRESIZING == 1) { + if (*PSMARTRESIZING == 1) { // Identify inner and outer nodes for both directions SDwindleNodeData* PVOUTER = nullptr; SDwindleNodeData* PVINNER = nullptr; @@ -703,14 +704,14 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (PHINNER) { const auto ORIGINAL = PHINNER->box.w; - PHOUTER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PHOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0); if (PHINNER->pParent->children[0] == PHINNER) PHINNER->pParent->splitRatio = std::clamp((ORIGINAL - allowedMovement.x) / PHINNER->pParent->box.w * 2.f, 0.1, 1.9); else PHINNER->pParent->splitRatio = std::clamp(2 - (ORIGINAL + allowedMovement.x) / PHINNER->pParent->box.w * 2.f, 0.1, 1.9); - PHINNER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PHINNER->pParent->recalcSizePosRecursive(*PANIMATE == 0); } else - PHOUTER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PHOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0); } if (PVOUTER) { @@ -718,14 +719,14 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (PVINNER) { const auto ORIGINAL = PVINNER->box.h; - PVOUTER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PVOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0); if (PVINNER->pParent->children[0] == PVINNER) PVINNER->pParent->splitRatio = std::clamp((ORIGINAL - allowedMovement.y) / PVINNER->pParent->box.h * 2.f, 0.1, 1.9); else PVINNER->pParent->splitRatio = std::clamp(2 - (ORIGINAL + allowedMovement.y) / PVINNER->pParent->box.h * 2.f, 0.1, 1.9); - PVINNER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PVINNER->pParent->recalcSizePosRecursive(*PANIMATE == 0); } else - PVOUTER->pParent->recalcSizePosRecursive(**PANIMATE == 0); + PVOUTER->pParent->recalcSizePosRecursive(*PANIMATE == 0); } } else { // get the correct containers to apply splitratio to @@ -744,11 +745,11 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (PARENTSIDEBYSIDE) { allowedMovement.x *= 2.f / PPARENT->box.w; PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, 0.1, 1.9); - PPARENT->recalcSizePosRecursive(**PANIMATE == 0); + PPARENT->recalcSizePosRecursive(*PANIMATE == 0); } else { allowedMovement.y *= 2.f / PPARENT->box.h; PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, 0.1, 1.9); - PPARENT->recalcSizePosRecursive(**PANIMATE == 0); + PPARENT->recalcSizePosRecursive(*PANIMATE == 0); } return; @@ -763,11 +764,11 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn if (PARENTSIDEBYSIDE) { allowedMovement.x *= 2.f / PPARENT->box.w; PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.x, 0.1, 1.9); - PPARENT->recalcSizePosRecursive(**PANIMATE == 0); + PPARENT->recalcSizePosRecursive(*PANIMATE == 0); } else { allowedMovement.y *= 2.f / PPARENT->box.h; PPARENT->splitRatio = std::clamp(PPARENT->splitRatio + allowedMovement.y, 0.1, 1.9); - PPARENT->recalcSizePosRecursive(**PANIMATE == 0); + PPARENT->recalcSizePosRecursive(*PANIMATE == 0); } return; @@ -782,8 +783,8 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn SIDECONTAINER->splitRatio = std::clamp(SIDECONTAINER->splitRatio + allowedMovement.x, 0.1, 1.9); TOPCONTAINER->splitRatio = std::clamp(TOPCONTAINER->splitRatio + allowedMovement.y, 0.1, 1.9); - SIDECONTAINER->recalcSizePosRecursive(**PANIMATE == 0); - TOPCONTAINER->recalcSizePosRecursive(**PANIMATE == 0); + SIDECONTAINER->recalcSizePosRecursive(*PANIMATE == 0); + TOPCONTAINER->recalcSizePosRecursive(*PANIMATE == 0); } } @@ -1118,15 +1119,13 @@ Vector2D CHyprDwindleLayout::predictSizeForNewWindow() { node = *PNODE; node.pWindow = nullptr; - CBox box = PNODE->box; + CBox box = PNODE->box; - static auto* const PSMARTSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:smart_split"); - static auto* const PPRESERVESPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:preserve_split"); - static auto* const PFLMULT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier"); + static auto PFLMULT = CConfigValue("dwindle:split_width_multiplier"); - bool splitTop = box.h * **PFLMULT > box.w; + bool splitTop = box.h * *PFLMULT > box.w; - const auto SPLITSIDE = !splitTop; + const auto SPLITSIDE = !splitTop; if (SPLITSIDE) node.box = {{}, {box.w / 2.0, box.h}}; diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 46ae3807..d48f15fa 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -2,6 +2,7 @@ #include "../defines.hpp" #include "../Compositor.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp" +#include "../config/ConfigValue.hpp" void IHyprLayout::onWindowCreated(CWindow* pWindow, eDirection direction) { if (pWindow->m_bIsFloating) { @@ -87,7 +88,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { desiredGeometry.y = xy.y; } - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); if (!PMONITOR) { Debug::log(ERR, "{:m} has an invalid monitor in onWindowCreatedFloating!!!", pWindow); @@ -151,7 +152,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { } } - if (**PXWLFORCESCALEZERO && pWindow->m_bIsX11) + if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11) pWindow->m_vRealSize = pWindow->m_vRealSize.goal() / PMONITOR->scale; if (pWindow->m_bX11DoesntWantBorders || (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect)) { @@ -275,8 +276,8 @@ void IHyprLayout::onEndDragWindow() { return; if (pWindow->m_sGroupData.pNextWindow && DRAGGINGWINDOW->canBeGroupedInto(pWindow)) { - static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); - (**USECURRPOS ? pWindow : pWindow->getGroupTail())->insertWindowToGroup(DRAGGINGWINDOW); + static auto USECURRPOS = CConfigValue("group:insert_after_current"); + (*USECURRPOS ? pWindow : pWindow->getGroupTail())->insertWindowToGroup(DRAGGINGWINDOW); pWindow->setGroupCurrent(DRAGGINGWINDOW); DRAGGINGWINDOW->updateWindowDecos(); @@ -302,15 +303,15 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { return; } - static auto TIMER = std::chrono::high_resolution_clock::now(); + static auto TIMER = std::chrono::high_resolution_clock::now(); - const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID); + const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID); - const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y); - const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y); + const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y); + const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y); - static auto* const PANIMATEMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:animate_mouse_windowdragging"); - static auto* const PANIMATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes"); + static auto PANIMATEMOUSE = CConfigValue("misc:animate_mouse_windowdragging"); + static auto PANIMATE = CConfigValue("misc:animate_manual_resizes"); if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - TIMER).count() < @@ -328,7 +329,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { CBox wb = {m_vBeginDragPositionXY + DELTA, DRAGGINGWINDOW->m_vRealSize.goal()}; wb.round(); - if (**PANIMATEMOUSE) + if (*PANIMATEMOUSE) DRAGGINGWINDOW->m_vRealPosition = wb.pos(); else DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(wb.pos()); @@ -386,7 +387,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { CBox wb = {newPos, newSize}; wb.round(); - if (**PANIMATE) { + if (*PANIMATE) { DRAGGINGWINDOW->m_vRealSize = wb.size(); DRAGGINGWINDOW->m_vRealPosition = wb.pos(); } else { diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 230e5bcf..a828399a 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -3,6 +3,7 @@ #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "config/ConfigDataValues.hpp" #include +#include "../config/ConfigValue.hpp" SMasterNodeData* CHyprMasterLayout::getNodeFromWindow(CWindow* pWindow) { for (auto& nd : m_lMasterNodesData) { @@ -81,26 +82,26 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc if (pWindow->m_bIsFloating) return; - static auto* const PNEWTOP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_on_top"); + static auto PNEWTOP = CConfigValue("master:new_on_top"); - const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto PNODE = **PNEWTOP ? &m_lMasterNodesData.emplace_front() : &m_lMasterNodesData.emplace_back(); + const auto PNODE = *PNEWTOP ? &m_lMasterNodesData.emplace_front() : &m_lMasterNodesData.emplace_back(); PNODE->workspaceID = pWindow->m_iWorkspaceID; PNODE->pWindow = pWindow; - static auto* const PNEWISMASTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_is_master"); + static auto PNEWISMASTER = CConfigValue("master:new_is_master"); - const auto WINDOWSONWORKSPACE = getNodesOnWorkspace(PNODE->workspaceID); - static auto* const PMFACT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("master:mfact"); - float lastSplitPercent = **PMFACT; + const auto WINDOWSONWORKSPACE = getNodesOnWorkspace(PNODE->workspaceID); + static auto PMFACT = CConfigValue("master:mfact"); + float lastSplitPercent = *PMFACT; - auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID ? - getNodeFromWindow(g_pCompositor->m_pLastWindow) : - getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); + auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID ? + getNodeFromWindow(g_pCompositor->m_pLastWindow) : + getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); - const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); + const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); if (g_pInputManager->m_bWasDraggingWindow && OPENINGON) { if (OPENINGON->pWindow->checkInputOnDecos(INPUT_TYPE_DRAG_END, MOUSECOORDS, pWindow)) @@ -113,8 +114,8 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc m_lMasterNodesData.remove(*PNODE); - static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); - (**USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); + static auto USECURRPOS = CConfigValue("group:insert_after_current"); + (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); OPENINGON->pWindow->setGroupCurrent(pWindow); pWindow->applyGroupRules(); @@ -129,14 +130,14 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc pWindow->applyGroupRules(); - static auto* const PDROPATCURSOR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:drop_at_cursor"); - const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID); - eOrientation orientation = PWORKSPACEDATA->orientation; - const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); + static auto PDROPATCURSOR = CConfigValue("master:drop_at_cursor"); + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID); + eOrientation orientation = PWORKSPACEDATA->orientation; + const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); - bool forceDropAsMaster = false; + bool forceDropAsMaster = false; // if dragging window to move, drop it at the cursor position instead of bottom/top of stack - if (**PDROPATCURSOR && g_pInputManager->dragMode == MBIND_MOVE) { + if (*PDROPATCURSOR && g_pInputManager->dragMode == MBIND_MOVE) { if (WINDOWSONWORKSPACE > 2) { for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) { if (it->workspaceID != pWindow->m_iWorkspaceID) @@ -192,7 +193,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc } } - if ((**PNEWISMASTER && g_pInputManager->dragMode != MBIND_MOVE) || WINDOWSONWORKSPACE == 1 || (WINDOWSONWORKSPACE > 2 && !pWindow->m_bFirstMap && OPENINGON->isMaster) || + if ((*PNEWISMASTER && g_pInputManager->dragMode != MBIND_MOVE) || WINDOWSONWORKSPACE == 1 || (WINDOWSONWORKSPACE > 2 && !pWindow->m_bFirstMap && OPENINGON->isMaster) || forceDropAsMaster) { for (auto& nd : m_lMasterNodesData) { if (nd.isMaster && nd.workspaceID == PNODE->workspaceID) { @@ -238,16 +239,16 @@ void CHyprMasterLayout::onWindowRemovedTiling(CWindow* pWindow) { if (!PNODE) return; - const auto WORKSPACEID = PNODE->workspaceID; - const auto MASTERSLEFT = getMastersOnWorkspace(WORKSPACEID); - static const auto* SMALLSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:allow_small_split"); + const auto WORKSPACEID = PNODE->workspaceID; + const auto MASTERSLEFT = getMastersOnWorkspace(WORKSPACEID); + static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); pWindow->updateSpecialRenderData(); if (pWindow->m_bIsFullscreen) g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); - if (PNODE->isMaster && (MASTERSLEFT <= 1 || **SMALLSPLIT == 1)) { + if (PNODE->isMaster && (MASTERSLEFT <= 1 || *SMALLSPLIT == 1)) { // find a new master from top of the list for (auto& nd : m_lMasterNodesData) { if (!nd.isMaster && nd.workspaceID == WORKSPACEID) { @@ -337,19 +338,19 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (!PMASTERNODE) return; - eOrientation orientation = PWORKSPACEDATA->orientation; - bool centerMasterWindow = false; - static auto* const ALWAYSCENTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:always_center_master"); - static auto* const PSMARTRESIZING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:smart_resizing"); + eOrientation orientation = PWORKSPACEDATA->orientation; + bool centerMasterWindow = false; + static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); + static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); - const auto MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); - const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); - const auto STACKWINDOWS = WINDOWS - MASTERS; - const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - const auto WSPOS = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; + const auto MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); + const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); + const auto STACKWINDOWS = WINDOWS - MASTERS; + const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; + const auto WSPOS = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; if (orientation == ORIENTATION_CENTER) { - if (STACKWINDOWS >= 2 || (**ALWAYSCENTER == 1)) { + if (STACKWINDOWS >= 2 || (*ALWAYSCENTER == 1)) { centerMasterWindow = true; } else { orientation = ORIENTATION_LEFT; @@ -362,7 +363,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { float masterAccumulatedSize = 0; float slaveAccumulatedSize = 0; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { // check the total width and height so that later // if larger/smaller than screen size them down/up for (auto& nd : m_lMasterNodesData) { @@ -400,7 +401,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (WIDTH > widthLeft * 0.9f && mastersLeft > 1) WIDTH = widthLeft * 0.9f; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { nd.percSize *= WSSIZE.x / masterAccumulatedSize; WIDTH = masterAverageSize * nd.percSize; } @@ -437,7 +438,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && mastersLeft > 1) HEIGHT = heightLeft * 0.9f; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { nd.percSize *= WSSIZE.y / masterAccumulatedSize; HEIGHT = masterAverageSize * nd.percSize; } @@ -474,7 +475,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (WIDTH > widthLeft * 0.9f && slavesLeft > 1) WIDTH = widthLeft * 0.9f; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { nd.percSize *= WSSIZE.x / slaveAccumulatedSize; WIDTH = slaveAverageSize * nd.percSize; } @@ -504,7 +505,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && slavesLeft > 1) HEIGHT = heightLeft * 0.9f; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { nd.percSize *= WSSIZE.y / slaveAccumulatedSize; HEIGHT = slaveAverageSize * nd.percSize; } @@ -535,7 +536,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { const float slaveAverageHeightR = WSSIZE.y / slavesLeftR; float slaveAccumulatedHeightL = 0; float slaveAccumulatedHeightR = 0; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { for (auto& nd : m_lMasterNodesData) { if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) continue; @@ -570,7 +571,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (HEIGHT > heightLeft * 0.9f && slavesLeft > 1) HEIGHT = heightLeft * 0.9f; - if (**PSMARTRESIZING) { + if (*PSMARTRESIZING) { if (onRight) { nd.percSize *= WSSIZE.y / slaveAccumulatedHeightR; HEIGHT = slaveAverageHeightR * nd.percSize; @@ -634,15 +635,15 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->updateSpecialRenderData(); - static auto* const PNOGAPSWHENONLY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:no_gaps_when_only"); - static auto* const PANIMATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes"); - static auto* const PGAPSINDATA = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:gaps_in"); - static auto* const PGAPSOUTDATA = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("general:gaps_out"); - auto* const PGAPSIN = (CCssGapData*)(*PGAPSINDATA)->getData(); - auto* const PGAPSOUT = (CCssGapData*)(*PGAPSOUTDATA)->getData(); + static auto PNOGAPSWHENONLY = CConfigValue("master:no_gaps_when_only"); + static auto PANIMATE = CConfigValue("misc:animate_manual_resizes"); + static auto PGAPSINDATA = CConfigValue("general:gaps_in"); + static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); + auto* PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); + auto* PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); - auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); - auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); + auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); + auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); if (!g_pCompositor->windowValidMapped(PWINDOW)) { Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); @@ -652,11 +653,11 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->m_vSize = pNode->size; PWINDOW->m_vPosition = pNode->position; - if (**PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && + if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { - PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(**PNOGAPSWHENONLY == 2); + PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2); PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true); PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -688,9 +689,9 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) { - static auto* const PSCALEFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("master:special_scale_factor"); + static auto PSCALEFACTOR = CConfigValue("master:special_scale_factor"); - CBox wb = {calcPos + (calcSize - calcSize * **PSCALEFACTOR) / 2.f, calcSize * **PSCALEFACTOR}; + CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR}; wb.round(); // avoid rounding mess PWINDOW->m_vRealPosition = wb.pos(); @@ -707,7 +708,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { g_pXWaylandManager->setWindowSize(PWINDOW, wb.size()); } - if (m_bForceWarps && !**PANIMATE) { + if (m_bForceWarps && !*PANIMATE) { g_pHyprRenderer->damageWindow(PWINDOW); PWINDOW->m_vRealPosition.warp(); @@ -737,27 +738,27 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne return; } - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PMONITOR->activeWorkspace); - static auto* const ALWAYSCENTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:always_center_master"); - static auto* const PSMARTRESIZING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:smart_resizing"); + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PMONITOR->activeWorkspace); + static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); + static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); - eOrientation orientation = PWORKSPACEDATA->orientation; - bool centered = orientation == ORIENTATION_CENTER && (**ALWAYSCENTER == 1); - double delta = 0; + eOrientation orientation = PWORKSPACEDATA->orientation; + bool centered = orientation == ORIENTATION_CENTER && (*ALWAYSCENTER == 1); + double delta = 0; - const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y); - const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x); - const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y); - const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x); + const bool DISPLAYBOTTOM = STICKS(PWINDOW->m_vPosition.y + PWINDOW->m_vSize.y, PMONITOR->vecPosition.y + PMONITOR->vecSize.y - PMONITOR->vecReservedBottomRight.y); + const bool DISPLAYRIGHT = STICKS(PWINDOW->m_vPosition.x + PWINDOW->m_vSize.x, PMONITOR->vecPosition.x + PMONITOR->vecSize.x - PMONITOR->vecReservedBottomRight.x); + const bool DISPLAYTOP = STICKS(PWINDOW->m_vPosition.y, PMONITOR->vecPosition.y + PMONITOR->vecReservedTopLeft.y); + const bool DISPLAYLEFT = STICKS(PWINDOW->m_vPosition.x, PMONITOR->vecPosition.x + PMONITOR->vecReservedTopLeft.x); - const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT; - const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT; - const bool NONE = corner == CORNER_NONE; + const bool LEFT = corner == CORNER_TOPLEFT || corner == CORNER_BOTTOMLEFT; + const bool TOP = corner == CORNER_TOPLEFT || corner == CORNER_TOPRIGHT; + const bool NONE = corner == CORNER_NONE; - const auto MASTERS = getMastersOnWorkspace(PNODE->workspaceID); - const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID); - const auto STACKWINDOWS = WINDOWS - MASTERS; + const auto MASTERS = getMastersOnWorkspace(PNODE->workspaceID); + const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID); + const auto STACKWINDOWS = WINDOWS - MASTERS; if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered) return; @@ -774,7 +775,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne if (WINDOWS > 2) { if (!NONE || !PNODE->isMaster) delta *= 2; - if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && **PSMARTRESIZING)) + if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && *PSMARTRESIZING)) delta = -delta; } break; @@ -800,7 +801,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto SIZE = isStackVertical ? WSSIZE.y / nodesInSameColumn : WSSIZE.x / nodesInSameColumn; if (RESIZEDELTA != 0 && nodesInSameColumn > 1) { - if (!**PSMARTRESIZING) { + if (!*PSMARTRESIZING) { PNODE->percSize = std::clamp(PNODE->percSize + RESIZEDELTA / SIZE, 0.05, 1.95); } else { const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); @@ -1058,8 +1059,8 @@ bool CHyprMasterLayout::prepareLoseFocus(CWindow* pWindow) { //if the current window is fullscreen, make it normal again if we are about to lose focus if (pWindow->m_bIsFullscreen) { g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); - static auto* const INHERIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:inherit_fullscreen"); - return **INHERIT == 1; + static auto INHERIT = CConfigValue("master:inherit_fullscreen"); + return *INHERIT == 1; } return false; @@ -1232,13 +1233,13 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (header.pWindow->m_bIsFloating) return 0; - const auto PNODE = getNodeFromWindow(header.pWindow); + const auto PNODE = getNodeFromWindow(header.pWindow); - const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); - const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); - static const auto* SMALLSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:allow_small_split"); + const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); + const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); + static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); - if (MASTERS + 2 > WINDOWS && **SMALLSPLIT == 0) + if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) return 0; prepareLoseFocus(header.pWindow); @@ -1460,7 +1461,7 @@ void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) { } Vector2D CHyprMasterLayout::predictSizeForNewWindow() { - static auto* const PNEWISMASTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_is_master"); + static auto PNEWISMASTER = CConfigValue("master:new_is_master"); if (!g_pCompositor->m_pLastMonitor) return {}; diff --git a/src/macros.hpp b/src/macros.hpp index 19b4cbc6..02ca185d 100644 --- a/src/macros.hpp +++ b/src/macros.hpp @@ -6,6 +6,7 @@ #ifndef NDEBUG #ifdef HYPRLAND_DEBUG +#define HYPRLAND_DEBUG #define ISDEBUG true #else #define ISDEBUG false diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f9d709d3..072a377e 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -2,6 +2,7 @@ #include "../Compositor.hpp" #include "HookSystemManager.hpp" #include "macros.hpp" +#include "../config/ConfigValue.hpp" int wlTick(void* data) { if (g_pAnimationManager) @@ -52,11 +53,11 @@ void CAnimationManager::tick() { if (m_vActiveAnimatedVariables.empty()) return; - bool animGlobalDisabled = false; + bool animGlobalDisabled = false; - static auto* const PANIMENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("animations:enabled"); + static auto PANIMENABLED = CConfigValue("animations:enabled"); - if (!**PANIMENABLED) + if (!*PANIMENABLED) animGlobalDisabled = true; static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); @@ -67,7 +68,7 @@ void CAnimationManager::tick() { for (auto& av : m_vActiveAnimatedVariables) { - if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW && !**PSHADOWSENABLED) { + if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW && !*PSHADOWSENABLED) { av->warp(false); animationEndedVars.push_back(av); continue; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 28c72029..9e12750b 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2,6 +2,7 @@ #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "debug/Log.hpp" #include "helpers/VarList.hpp" +#include "../config/ConfigValue.hpp" #include @@ -155,26 +156,26 @@ void CKeybindManager::updateXKBTranslationState() { m_pXKBTranslationState = nullptr; } - static auto* const PFILEPATH = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_file"); - static auto* const PRULES = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_rules"); - static auto* const PMODEL = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_model"); - static auto* const PLAYOUT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_layout"); - static auto* const PVARIANT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_variant"); - static auto* const POPTIONS = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("input:kb_options"); + static auto PFILEPATH = CConfigValue("input:kb_file"); + static auto PRULES = CConfigValue("input:kb_rules"); + static auto PMODEL = CConfigValue("input:kb_model"); + static auto PLAYOUT = CConfigValue("input:kb_layout"); + static auto PVARIANT = CConfigValue("input:kb_variant"); + static auto POPTIONS = CConfigValue("input:kb_options"); - const std::string FILEPATH = std::string{*PFILEPATH} == STRVAL_EMPTY ? "" : *PFILEPATH; - const std::string RULES = std::string{*PRULES} == STRVAL_EMPTY ? "" : *PRULES; - const std::string MODEL = std::string{*PMODEL} == STRVAL_EMPTY ? "" : *PMODEL; - const std::string LAYOUT = std::string{*PLAYOUT} == STRVAL_EMPTY ? "" : *PLAYOUT; - const std::string VARIANT = std::string{*PVARIANT} == STRVAL_EMPTY ? "" : *PVARIANT; - const std::string OPTIONS = std::string{*POPTIONS} == STRVAL_EMPTY ? "" : *POPTIONS; + const std::string FILEPATH = std::string{*PFILEPATH} == STRVAL_EMPTY ? "" : *PFILEPATH; + const std::string RULES = std::string{*PRULES} == STRVAL_EMPTY ? "" : *PRULES; + const std::string MODEL = std::string{*PMODEL} == STRVAL_EMPTY ? "" : *PMODEL; + const std::string LAYOUT = std::string{*PLAYOUT} == STRVAL_EMPTY ? "" : *PLAYOUT; + const std::string VARIANT = std::string{*PVARIANT} == STRVAL_EMPTY ? "" : *PVARIANT; + const std::string OPTIONS = std::string{*POPTIONS} == STRVAL_EMPTY ? "" : *POPTIONS; - xkb_rule_names rules = {.rules = RULES.c_str(), .model = MODEL.c_str(), .layout = LAYOUT.c_str(), .variant = VARIANT.c_str(), .options = OPTIONS.c_str()}; - const auto PCONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS); - FILE* const KEYMAPFILE = FILEPATH == "" ? NULL : fopen(absolutePath(FILEPATH, g_pConfigManager->configCurrentPath).c_str(), "r"); + xkb_rule_names rules = {.rules = RULES.c_str(), .model = MODEL.c_str(), .layout = LAYOUT.c_str(), .variant = VARIANT.c_str(), .options = OPTIONS.c_str()}; + const auto PCONTEXT = xkb_context_new(XKB_CONTEXT_NO_FLAGS); + FILE* const KEYMAPFILE = FILEPATH == "" ? NULL : fopen(absolutePath(FILEPATH, g_pConfigManager->configCurrentPath).c_str(), "r"); - auto PKEYMAP = KEYMAPFILE ? xkb_keymap_new_from_file(PCONTEXT, KEYMAPFILE, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS) : - xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); + auto PKEYMAP = KEYMAPFILE ? xkb_keymap_new_from_file(PCONTEXT, KEYMAPFILE, XKB_KEYMAP_FORMAT_TEXT_V1, XKB_KEYMAP_COMPILE_NO_FLAGS) : + xkb_keymap_new_from_names(PCONTEXT, &rules, XKB_KEYMAP_COMPILE_NO_FLAGS); if (KEYMAPFILE) fclose(KEYMAPFILE); @@ -369,11 +370,11 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard } bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { - const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); + const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); - static auto* const PDELAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:scroll_event_delay"); + static auto PDELAY = CConfigValue("binds:scroll_event_delay"); - if (m_tScrollTimer.getMillis() < **PDELAY) { + if (m_tScrollTimer.getMillis() < *PDELAY) { m_tScrollTimer.reset(); return true; // timer hasn't passed yet! } @@ -890,11 +891,11 @@ void CKeybindManager::changeworkspace(std::string args) { // Workspace_back_and_forth being enabled means that an attempt to switch to // the current workspace will instead switch to the previous. - static auto* const PBACKANDFORTH = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth"); - static auto* const PALLOWWORKSPACECYCLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles"); - static auto* const PWORKSPACECENTERON = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:workspace_center_on"); + static auto PBACKANDFORTH = CConfigValue("binds:workspace_back_and_forth"); + static auto PALLOWWORKSPACECYCLES = CConfigValue("binds:allow_workspace_cycles"); + static auto PWORKSPACECENTERON = CConfigValue("binds:workspace_center_on"); - const auto PMONITOR = g_pCompositor->m_pLastMonitor; + const auto PMONITOR = g_pCompositor->m_pLastMonitor; if (!PMONITOR) return; @@ -927,7 +928,7 @@ void CKeybindManager::changeworkspace(std::string args) { const bool BISWORKSPACECURRENT = workspaceToChangeTo == PCURRENTWORKSPACE->m_iID; - if (BISWORKSPACECURRENT && (!(**PBACKANDFORTH || EXPLICITPREVIOUS) || PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1)) + if (BISWORKSPACECURRENT && (!(*PBACKANDFORTH || EXPLICITPREVIOUS) || PCURRENTWORKSPACE->m_sPrevWorkspace.iID == -1)) return; g_pInputManager->unconstrainMouse(); @@ -959,14 +960,14 @@ void CKeybindManager::changeworkspace(std::string args) { Vector2D middle = PMONITORWORKSPACEOWNER->middle(); if (const auto PLAST = pWorkspaceToChangeTo->getLastFocusedWindow(); PLAST) { g_pCompositor->focusWindow(PLAST); - if (**PWORKSPACECENTERON == 1) + if (*PWORKSPACECENTERON == 1) middle = PLAST->middle(); } g_pCompositor->warpCursorTo(middle); } if (BISWORKSPACECURRENT) { - if (**PALLOWWORKSPACECYCLES) + if (*PALLOWWORKSPACECYCLES) pWorkspaceToChangeTo->rememberPrevWorkspace(PCURRENTWORKSPACE); else if (!EXPLICITPREVIOUS) pWorkspaceToChangeTo->rememberPrevWorkspace(nullptr); @@ -1024,10 +1025,10 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { return; } - auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); - CMonitor* pMonitor = nullptr; - const auto POLDWS = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - static auto* const PALLOWWORKSPACECYCLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles"); + auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); + CMonitor* pMonitor = nullptr; + const auto POLDWS = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + static auto PALLOWWORKSPACECYCLES = CConfigValue("binds:allow_workspace_cycles"); g_pHyprRenderer->damageWindow(PWINDOW); @@ -1053,7 +1054,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { g_pCompositor->focusWindow(PWINDOW); g_pCompositor->warpCursorTo(PWINDOW->middle()); - if (**PALLOWWORKSPACECYCLES) + if (*PALLOWWORKSPACECYCLES) pWorkspace->rememberPrevWorkspace(POLDWS); } @@ -1105,8 +1106,8 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } void CKeybindManager::moveFocusTo(std::string args) { - static auto* const PFULLCYCLE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:movefocus_cycles_fullscreen"); - char arg = args[0]; + static auto PFULLCYCLE = CConfigValue("binds:movefocus_cycles_fullscreen"); + char arg = args[0]; if (!isDirection(args)) { Debug::log(ERR, "Cannot move focus in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); @@ -1119,7 +1120,7 @@ void CKeybindManager::moveFocusTo(std::string args) { return; } - const auto PWINDOWTOCHANGETO = **PFULLCYCLE && PLASTWINDOW->m_bIsFullscreen ? + const auto PWINDOWTOCHANGETO = *PFULLCYCLE && PLASTWINDOW->m_bIsFullscreen ? (arg == 'd' || arg == 'b' || arg == 'r' ? g_pCompositor->getNextWindowOnWorkspace(PLASTWINDOW, true) : g_pCompositor->getPrevWindowOnWorkspace(PLASTWINDOW, true)) : g_pCompositor->getWindowInDirection(PLASTWINDOW, arg); @@ -1134,8 +1135,8 @@ void CKeybindManager::moveFocusTo(std::string args) { if (tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg))) return; - static auto* const PNOFALLBACK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_focus_fallback"); - if (**PNOFALLBACK) + static auto PNOFALLBACK = CConfigValue("general:no_focus_fallback"); + if (*PNOFALLBACK) return; Debug::log(LOG, "No monitor found in direction {}, falling back to next window on current workspace", arg); @@ -1587,10 +1588,10 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { void CKeybindManager::toggleSpecialWorkspace(std::string args) { - static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); - std::string workspaceName = ""; - int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName); + std::string workspaceName = ""; + int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName); if (workspaceID == WORKSPACE_INVALID || !g_pCompositor->isWorkspaceSpecial(workspaceID)) { Debug::log(ERR, "Invalid workspace passed to special"); @@ -1598,7 +1599,7 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { } bool requestedWorkspaceIsAlreadyOpen = false; - const auto PMONITOR = **PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor; + const auto PMONITOR = *PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor; int specialOpenOnMonitor = PMONITOR->specialWorkspaceID; for (auto& m : g_pCompositor->m_vMonitors) { @@ -2133,8 +2134,8 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow); // This removes groupped property! - static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); - pWindowInDirection = **USECURRPOS ? pWindowInDirection : pWindowInDirection->getGroupTail(); + static auto USECURRPOS = CConfigValue("group:insert_after_current"); + pWindowInDirection = *USECURRPOS ? pWindowInDirection : pWindowInDirection->getGroupTail(); pWindowInDirection->insertWindowToGroup(pWindow); pWindowInDirection->setGroupCurrent(pWindow); @@ -2148,9 +2149,9 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi } void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir) { - static auto* const BFOCUSREMOVEDWINDOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:focus_removed_window"); - const auto PWINDOWPREV = pWindow->getGroupPrevious(); - eDirection direction; + static auto BFOCUSREMOVEDWINDOW = CConfigValue("group:focus_removed_window"); + const auto PWINDOWPREV = pWindow->getGroupPrevious(); + eDirection direction; switch (dir[0]) { case 't': @@ -2175,7 +2176,7 @@ void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& g_pKeybindManager->m_bGroupsLocked = GROUPSLOCKEDPREV; } - if (**BFOCUSREMOVEDWINDOW) { + if (*BFOCUSREMOVEDWINDOW) { g_pCompositor->focusWindow(pWindow); g_pCompositor->warpCursorTo(pWindow->middle()); } else { @@ -2185,11 +2186,11 @@ void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& } void CKeybindManager::moveIntoGroup(std::string args) { - char arg = args[0]; + char arg = args[0]; - static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); + static auto PIGNOREGROUPLOCK = CConfigValue("binds:ignore_group_lock"); - if (!**PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) + if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) return; if (!isDirection(args)) { @@ -2208,16 +2209,16 @@ void CKeybindManager::moveIntoGroup(std::string args) { return; // Do not move window into locked group if binds:ignore_group_lock is false - if (!**PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || (PWINDOW->m_sGroupData.pNextWindow && PWINDOW->getGroupHead()->m_sGroupData.locked))) + if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || (PWINDOW->m_sGroupData.pNextWindow && PWINDOW->getGroupHead()->m_sGroupData.locked))) return; moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); } void CKeybindManager::moveOutOfGroup(std::string args) { - static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); + static auto PIGNOREGROUPLOCK = CConfigValue("binds:ignore_group_lock"); - if (!**PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) + if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) return; CWindow* PWINDOW = nullptr; @@ -2234,9 +2235,9 @@ void CKeybindManager::moveOutOfGroup(std::string args) { } void CKeybindManager::moveWindowOrGroup(std::string args) { - char arg = args[0]; + char arg = args[0]; - static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); + static auto PIGNOREGROUPLOCK = CConfigValue("binds:ignore_group_lock"); if (!isDirection(args)) { Debug::log(ERR, "Cannot move into group in direction {}, unsupported direction. Supported: l,r,u/t,d/b", arg); @@ -2247,7 +2248,7 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { if (!PWINDOW || PWINDOW->m_bIsFullscreen) return; - if (!**PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) { + if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); return; } @@ -2260,13 +2261,13 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { // note: PWINDOWINDIR is not null implies !PWINDOW->m_bIsFloating if (PWINDOWINDIR && PWINDOWINDIR->m_sGroupData.pNextWindow) { // target is group - if (!**PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || ISWINDOWGROUPLOCKED || PWINDOW->m_sGroupData.deny)) { + if (!*PIGNOREGROUPLOCK && (PWINDOWINDIR->getGroupHead()->m_sGroupData.locked || ISWINDOWGROUPLOCKED || PWINDOW->m_sGroupData.deny)) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); g_pCompositor->warpCursorTo(PWINDOW->middle()); } else moveWindowIntoGroup(PWINDOW, PWINDOWINDIR); } else if (PWINDOWINDIR) { // target is regular window - if ((!**PIGNOREGROUPLOCK && ISWINDOWGROUPLOCKED) || !ISWINDOWGROUP || (ISWINDOWGROUPSINGLE && PWINDOW->m_eGroupRules & GROUP_SET_ALWAYS)) { + if ((!*PIGNOREGROUPLOCK && ISWINDOWGROUPLOCKED) || !ISWINDOWGROUP || (ISWINDOWGROUPSINGLE && PWINDOW->m_eGroupRules & GROUP_SET_ALWAYS)) { g_pLayoutManager->getCurrentLayout()->moveWindowTo(PWINDOW, args); g_pCompositor->warpCursorTo(PWINDOW->middle()); } else @@ -2282,14 +2283,14 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { } void CKeybindManager::setIgnoreGroupLock(std::string args) { - static auto* const BIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); + static auto PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); if (args == "toggle") - **BIGNOREGROUPLOCK = !*BIGNOREGROUPLOCK; + **PIGNOREGROUPLOCK = !**PIGNOREGROUPLOCK; else - **BIGNOREGROUPLOCK = args == "on"; + **PIGNOREGROUPLOCK = args == "on"; - g_pEventManager->postEvent(SHyprIPCEvent{"ignoregrouplock", std::to_string(**BIGNOREGROUPLOCK)}); + g_pEventManager->postEvent(SHyprIPCEvent{"ignoregrouplock", std::to_string(**PIGNOREGROUPLOCK)}); } void CKeybindManager::denyWindowFromGroup(std::string args) { diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 89c08566..82606a8a 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -1,5 +1,6 @@ #include "SessionLockManager.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" static void handleSurfaceMap(void* owner, void* data) { const auto PSURFACE = (SSessionLockSurface*)owner; @@ -44,9 +45,9 @@ static void handleSurfaceDestroy(void* owner, void* data) { void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) { - static auto* const PALLOWRELOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:allow_session_lock_restore"); + static auto PALLOWRELOCK = CConfigValue("misc:allow_session_lock_restore"); - if (m_sSessionLock.active && (!**PALLOWRELOCK || m_sSessionLock.pWlrLock)) { + if (m_sSessionLock.active && (!*PALLOWRELOCK || m_sSessionLock.pWlrLock)) { Debug::log(LOG, "Attempted to lock a locked session!"); wlr_session_lock_v1_destroy(pWlrLock); return; diff --git a/src/managers/ThreadManager.cpp b/src/managers/ThreadManager.cpp index ee58a8ce..cd892503 100644 --- a/src/managers/ThreadManager.cpp +++ b/src/managers/ThreadManager.cpp @@ -1,15 +1,16 @@ #include "ThreadManager.hpp" #include "../debug/HyprCtl.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" int slowUpdate = 0; int handleTimer(void* data) { - const auto PTM = (CThreadManager*)data; + const auto PTM = (CThreadManager*)data; - static auto* const PDISABLECFGRELOAD = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:disable_autoreload"); + static auto PDISABLECFGRELOAD = CConfigValue("misc:disable_autoreload"); - if (**PDISABLECFGRELOAD != 1) + if (*PDISABLECFGRELOAD != 1) g_pConfigManager->tick(); wl_event_source_timer_update(PTM->m_esConfigTimer, 1000); diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index 6f49c7f2..e37a08f7 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -2,6 +2,7 @@ #include "../Compositor.hpp" #include "../events/Events.hpp" #include "xdg-output-unstable-v1-protocol.h" +#include "../config/ConfigValue.hpp" #define OUTPUT_MANAGER_VERSION 3 #define OUTPUT_DONE_DEPRECATED_SINCE_VERSION 3 @@ -153,9 +154,9 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool force) { - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); size = size.clamp(Vector2D{0, 0}, Vector2D{std::numeric_limits::infinity(), std::numeric_limits::infinity()}); @@ -165,7 +166,7 @@ void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool f if (pWindow->m_bIsX11 && PMONITOR) { windowPos = windowPos - PMONITOR->vecPosition; // normalize to monitor - if (**PXWLFORCESCALEZERO) + if (*PXWLFORCESCALEZERO) windowPos = windowPos * PMONITOR->scale; // scale if applicable windowPos = windowPos + PMONITOR->vecXWaylandPosition; // move to correct position for xwayland } @@ -178,7 +179,7 @@ void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool f pWindow->m_fX11SurfaceScaledBy = 1.f; - if (**PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) { + if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11 && PMONITOR) { size = size * PMONITOR->scale; pWindow->m_fX11SurfaceScaledBy = PMONITOR->scale; } @@ -336,12 +337,12 @@ Vector2D CHyprXWaylandManager::getMinSizeForWindow(CWindow* pWindow) { Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); - CMonitor* pMonitor = nullptr; - double bestDistance = __FLT_MAX__; + CMonitor* pMonitor = nullptr; + double bestDistance = __FLT_MAX__; for (auto& m : g_pCompositor->m_vMonitors) { - const auto SIZ = **PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize; + const auto SIZ = *PXWLFORCESCALEZERO ? m->vecTransformedSize : m->vecSize; double distance = vecToRectDistanceSquared(coord, {m->vecXWaylandPosition.x, m->vecXWaylandPosition.y}, {m->vecXWaylandPosition.x + SIZ.x - 1, m->vecXWaylandPosition.y + SIZ.y - 1}); @@ -358,7 +359,7 @@ Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { // get local coords Vector2D result = coord - pMonitor->vecXWaylandPosition; // if scaled, unscale - if (**PXWLFORCESCALEZERO) + if (*PXWLFORCESCALEZERO) result = result / pMonitor->scale; // add pos result = result + pMonitor->vecPosition; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index c634037c..d8013d75 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -2,6 +2,7 @@ #include "../../Compositor.hpp" #include "wlr/types/wlr_switch.h" #include +#include "../../config/ConfigValue.hpp" CInputManager::~CInputManager() { m_vConstraints.clear(); @@ -16,20 +17,20 @@ CInputManager::~CInputManager() { } void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) { - static auto* const PSENS = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("general:sensitivity"); - static auto* const PNOACCEL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:force_no_accel"); - static auto* const PSENSTORAW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:apply_sens_to_raw"); + static auto PSENS = CConfigValue("general:sensitivity"); + static auto PNOACCEL = CConfigValue("input:force_no_accel"); + static auto PSENSTORAW = CConfigValue("general:apply_sens_to_raw"); - const auto DELTA = **PNOACCEL == 1 ? Vector2D(e->unaccel_dx, e->unaccel_dy) : Vector2D(e->delta_x, e->delta_y); + const auto DELTA = *PNOACCEL == 1 ? Vector2D(e->unaccel_dx, e->unaccel_dy) : Vector2D(e->delta_x, e->delta_y); - if (**PSENSTORAW == 1) - wlr_relative_pointer_manager_v1_send_relative_motion(g_pCompositor->m_sWLRRelPointerMgr, g_pCompositor->m_sSeat.seat, (uint64_t)e->time_msec * 1000, DELTA.x * **PSENS, - DELTA.y * **PSENS, e->unaccel_dx * **PSENS, e->unaccel_dy * **PSENS); + if (*PSENSTORAW == 1) + wlr_relative_pointer_manager_v1_send_relative_motion(g_pCompositor->m_sWLRRelPointerMgr, g_pCompositor->m_sSeat.seat, (uint64_t)e->time_msec * 1000, DELTA.x * *PSENS, + DELTA.y * *PSENS, e->unaccel_dx * *PSENS, e->unaccel_dy * *PSENS); else wlr_relative_pointer_manager_v1_send_relative_motion(g_pCompositor->m_sWLRRelPointerMgr, g_pCompositor->m_sSeat.seat, (uint64_t)e->time_msec * 1000, DELTA.x, DELTA.y, e->unaccel_dx, e->unaccel_dy); - wlr_cursor_move(g_pCompositor->m_sWLRCursor, &e->pointer->base, DELTA.x * **PSENS, DELTA.y * **PSENS); + wlr_cursor_move(g_pCompositor->m_sWLRCursor, &e->pointer->base, DELTA.x * *PSENS, DELTA.y * *PSENS); mouseMoveUnified(e->time_msec); @@ -73,17 +74,17 @@ void CInputManager::sendMotionEventsToFocused() { } void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { - static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); - static auto* const PMOUSEREFOCUS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:mouse_refocus"); - static auto* const PMOUSEDPMS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:mouse_move_enables_dpms"); - static auto* const PFOLLOWONDND = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:always_follow_on_dnd"); - static auto* const PFLOATBEHAVIOR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:float_switch_override_focus"); - static auto* const PMOUSEFOCUSMON = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:mouse_move_focuses_monitor"); - static auto* const PRESIZEONBORDER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:resize_on_border"); - static auto* const PRESIZECURSORICON = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:hover_icon_on_border"); - static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor"); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); + static auto PMOUSEREFOCUS = CConfigValue("input:mouse_refocus"); + static auto PMOUSEDPMS = CConfigValue("misc:mouse_move_enables_dpms"); + static auto PFOLLOWONDND = CConfigValue("misc:always_follow_on_dnd"); + static auto PFLOATBEHAVIOR = CConfigValue("input:float_switch_override_focus"); + static auto PMOUSEFOCUSMON = CConfigValue("misc:mouse_move_focuses_monitor"); + static auto PRESIZEONBORDER = CConfigValue("general:resize_on_border"); + static auto PRESIZECURSORICON = CConfigValue("general:hover_icon_on_border"); + static auto PZOOMFACTOR = CConfigValue("misc:cursor_zoom_factor"); - const auto FOLLOWMOUSE = **PFOLLOWONDND && m_sDrag.drag ? 1 : **PFOLLOWMOUSE; + const auto FOLLOWMOUSE = *PFOLLOWONDND && m_sDrag.drag ? 1 : *PFOLLOWMOUSE; m_pFoundSurfaceToFocus = nullptr; m_pFoundLSToFocus = nullptr; @@ -97,7 +98,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (!g_pCompositor->m_bReadyToProcess || g_pCompositor->m_bIsShuttingDown || g_pCompositor->m_bUnsafeState) return; - if (!g_pCompositor->m_bDPMSStateON && **PMOUSEDPMS) { + if (!g_pCompositor->m_bDPMSStateON && *PMOUSEDPMS) { // enable dpms g_pKeybindManager->dpms("on"); } @@ -121,7 +122,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (PMONITOR == nullptr) return; - if (**PZOOMFACTOR != 1.f) + if (*PZOOMFACTOR != 1.f) g_pHyprRenderer->damageMonitor(PMONITOR); if (!PMONITOR->solitaryClient && g_pHyprRenderer->shouldRenderCursor() && PMONITOR->output->software_cursor_locks > 0) @@ -191,7 +192,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { g_pLayoutManager->getCurrentLayout()->onMouseMove(getMouseCoordsInternal()); - if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor && (**PMOUSEFOCUSMON || refocus)) + if (PMONITOR && PMONITOR != g_pCompositor->m_pLastMonitor && (*PMOUSEFOCUSMON || refocus)) g_pCompositor->setActiveMonitor(PMONITOR); if (g_pSessionLockManager->isSessionLocked()) { @@ -291,7 +292,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (!foundSurface) { if (!m_bEmptyFocusCursorSet) { - if (**PRESIZEONBORDER && **PRESIZECURSORICON && m_eBorderIconDirection != BORDERICON_NONE) { + if (*PRESIZEONBORDER && *PRESIZECURSORICON && m_eBorderIconDirection != BORDERICON_NONE) { m_eBorderIconDirection = BORDERICON_NONE; unsetCursorImage(); } @@ -361,7 +362,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (pFoundWindow) { // change cursor icon if hovering over border - if (**PRESIZEONBORDER && **PRESIZECURSORICON) { + if (*PRESIZEONBORDER && *PRESIZECURSORICON) { if (!pFoundWindow->m_bIsFullscreen && !pFoundWindow->hasPopupAt(mouseCoords)) { setCursorIconOnBorder(pFoundWindow); } else if (m_eBorderIconDirection != BORDERICON_NONE) { @@ -371,7 +372,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (FOLLOWMOUSE != 1 && !refocus) { if (pFoundWindow != g_pCompositor->m_pLastWindow && g_pCompositor->m_pLastWindow && - ((pFoundWindow->m_bIsFloating && **PFLOATBEHAVIOR == 2) || (g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && **PFLOATBEHAVIOR != 0))) { + ((pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR == 2) || (g_pCompositor->m_pLastWindow->m_bIsFloating != pFoundWindow->m_bIsFloating && *PFLOATBEHAVIOR != 0))) { // enter if change floating style if (FOLLOWMOUSE != 3 && allowKeyboardRefocus) g_pCompositor->focusWindow(pFoundWindow, foundSurface); @@ -409,7 +410,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { m_bLastFocusOnLS = false; } else { - if (**PRESIZEONBORDER && **PRESIZECURSORICON && m_eBorderIconDirection != BORDERICON_NONE) { + if (*PRESIZEONBORDER && *PRESIZECURSORICON && m_eBorderIconDirection != BORDERICON_NONE) { m_eBorderIconDirection = BORDERICON_NONE; unsetCursorImage(); } @@ -576,15 +577,15 @@ void CInputManager::setClickMode(eClickBehaviorMode mode) { void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // notify the keybind manager - static auto* const PPASSMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:pass_mouse_when_bound"); - const auto PASS = g_pKeybindManager->onMouseEvent(e); - static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); - static auto* const PRESIZEONBORDER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:resize_on_border"); - static auto* const PBORDERSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:border_size"); - static auto* const PBORDERGRABEXTEND = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area"); - const auto BORDER_GRAB_AREA = **PRESIZEONBORDER ? **PBORDERSIZE + **PBORDERGRABEXTEND : 0; + static auto PPASSMOUSE = CConfigValue("binds:pass_mouse_when_bound"); + const auto PASS = g_pKeybindManager->onMouseEvent(e); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); + static auto PRESIZEONBORDER = CConfigValue("general:resize_on_border"); + static auto PBORDERSIZE = CConfigValue("general:border_size"); + static auto PBORDERGRABEXTEND = CConfigValue("general:extend_border_grab_area"); + const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; - if (!PASS && !**PPASSMOUSE) + if (!PASS && !*PPASSMOUSE) return; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); @@ -595,7 +596,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // clicking on border triggers resize // TODO detect click on LS properly - if (**PRESIZEONBORDER && !m_bLastFocusOnLS && e->state == WLR_BUTTON_PRESSED) { + if (*PRESIZEONBORDER && !m_bLastFocusOnLS && e->state == WLR_BUTTON_PRESSED) { if (w && !w->m_bIsFullscreen) { const CBox real = {w->m_vRealPosition.value().x, w->m_vRealPosition.value().y, w->m_vRealSize.value().x, w->m_vRealSize.value().y}; const CBox grab = {real.x - BORDER_GRAB_AREA, real.y - BORDER_GRAB_AREA, real.width + 2 * BORDER_GRAB_AREA, real.height + 2 * BORDER_GRAB_AREA}; @@ -609,7 +610,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { switch (e->state) { case WLR_BUTTON_PRESSED: - if (**PFOLLOWMOUSE == 3) // don't refocus on full loose + if (*PFOLLOWMOUSE == 3) // don't refocus on full loose break; if ((!g_pCompositor->m_sSeat.mouse || !isConstrained()) /* No constraints */ @@ -664,11 +665,11 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { } void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { - static auto* const PSCROLLFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("input:touchpad:scroll_factor"); + static auto PSCROLLFACTOR = CConfigValue("input:touchpad:scroll_factor"); - auto factor = (**PSCROLLFACTOR <= 0.f || e->source != WLR_AXIS_SOURCE_FINGER ? 1.f : **PSCROLLFACTOR); + auto factor = (*PSCROLLFACTOR <= 0.f || e->source != WLR_AXIS_SOURCE_FINGER ? 1.f : *PSCROLLFACTOR); - const auto EMAP = std::unordered_map{{"event", e}}; + const auto EMAP = std::unordered_map{{"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); bool passEvent = g_pKeybindManager->onAxisEvent(e); @@ -1159,8 +1160,8 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar const auto EMAP = std::unordered_map{{"keyboard", pKeyboard}, {"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); - static auto* const PDPMS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:key_press_enables_dpms"); - if (**PDPMS && !g_pCompositor->m_bDPMSStateON) { + static auto PDPMS = CConfigValue("misc:key_press_enables_dpms"); + if (*PDPMS && !g_pCompositor->m_bDPMSStateON) { // enable dpms g_pKeybindManager->dpms("on"); } @@ -1555,17 +1556,17 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { return; } - static auto* const PEXTENDBORDERGRAB = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area"); - const int BORDERSIZE = w->getRealBorderSize(); - const int ROUNDING = w->rounding(); + static auto PEXTENDBORDERGRAB = CConfigValue("general:extend_border_grab_area"); + const int BORDERSIZE = w->getRealBorderSize(); + const int ROUNDING = w->rounding(); // give a small leeway (10 px) for corner icon const auto CORNER = ROUNDING + BORDERSIZE + 10; const auto mouseCoords = getMouseCoordsInternal(); CBox box = w->getWindowMainSurfaceBox(); eBorderIconDirection direction = BORDERICON_NONE; - CBox boxFullGrabInput = {box.x - **PEXTENDBORDERGRAB - BORDERSIZE, box.y - **PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (**PEXTENDBORDERGRAB + BORDERSIZE), - box.height + 2 * (**PEXTENDBORDERGRAB + BORDERSIZE)}; + CBox boxFullGrabInput = {box.x - *PEXTENDBORDERGRAB - BORDERSIZE, box.y - *PEXTENDBORDERGRAB - BORDERSIZE, box.width + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE), + box.height + 2 * (*PEXTENDBORDERGRAB + BORDERSIZE)}; if (w->hasPopupAt(mouseCoords)) direction = BORDERICON_NONE; diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index f32e983a..937266af 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -1,12 +1,13 @@ #include "InputManager.hpp" #include "../../Compositor.hpp" +#include "../../config/ConfigValue.hpp" void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) { - static auto* const PSWIPE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe"); - static auto* const PSWIPEFINGERS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_fingers"); - static auto* const PSWIPENEW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new"); + static auto PSWIPE = CConfigValue("gestures:workspace_swipe"); + static auto PSWIPEFINGERS = CConfigValue("gestures:workspace_swipe_fingers"); + static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); - if (e->fingers != **PSWIPEFINGERS || **PSWIPE == 0 || g_pSessionLockManager->isSessionLocked()) + if (e->fingers != *PSWIPEFINGERS || *PSWIPE == 0 || g_pSessionLockManager->isSessionLocked()) return; int onMonitor = 0; @@ -16,7 +17,7 @@ void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) { } } - if (onMonitor < 2 && !**PSWIPENEW) + if (onMonitor < 2 && !*PSWIPENEW) return; // disallow swiping when there's 1 workspace on a monitor beginWorkspaceSwipe(); @@ -44,20 +45,20 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; // no valid swipe - static auto* const PSWIPEPERC = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_cancel_ratio"); - static auto* const PSWIPEDIST = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance"); - static auto* const PSWIPEFORC = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_min_speed_to_force"); - static auto* const PSWIPENEW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new"); - static auto* const PSWIPENUMBER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered"); - static auto* const PSWIPEUSER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r"); - static auto* const PWORKSPACEGAP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_workspaces"); - const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + static auto PSWIPEPERC = CConfigValue("gestures:workspace_swipe_cancel_ratio"); + static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); + static auto PSWIPEFORC = CConfigValue("gestures:workspace_swipe_min_speed_to_force"); + static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); + static auto PSWIPENUMBER = CConfigValue("gestures:workspace_swipe_numbered"); + static auto PSWIPEUSER = CConfigValue("gestures:workspace_swipe_use_r"); + static auto PWORKSPACEGAP = CConfigValue("general:gaps_workspaces"); + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); // commit std::string wsname = ""; - auto workspaceIDLeft = getWorkspaceIDFromString(**PSWIPENUMBER ? "-1" : (**PSWIPEUSER ? "r-1" : "m-1"), wsname); - auto workspaceIDRight = getWorkspaceIDFromString(**PSWIPENUMBER ? "+1" : (**PSWIPEUSER ? "r+1" : "m+1"), wsname); + auto workspaceIDLeft = getWorkspaceIDFromString(*PSWIPENUMBER ? "-1" : (*PSWIPEUSER ? "r-1" : "m-1"), wsname); + auto workspaceIDRight = getWorkspaceIDFromString(*PSWIPENUMBER ? "+1" : (*PSWIPEUSER ? "r+1" : "m+1"), wsname); // If we've been swiping off the right end with PSWIPENEW enabled, there is // no workspace there yet, and we need to choose an ID for a new one now. @@ -68,7 +69,7 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { // be counterintuitive to swipe rightwards onto a new workspace and end up // left of where we started. Instead, it's one more than the greatest // workspace ID that currently exists. - if (workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID && **PSWIPENEW) { + if (workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID && *PSWIPENEW) { int maxWorkspace = 0; for (const auto& ws : g_pCompositor->m_vWorkspaces) { maxWorkspace = std::max(maxWorkspace, ws->m_iID); @@ -80,12 +81,12 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value(); - const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + **PWORKSPACEGAP; - const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + **PWORKSPACEGAP; + const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP; + const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; CWorkspace* pSwitchedTo = nullptr; - if ((abs(m_sActiveSwipe.delta) < **PSWIPEDIST * **PSWIPEPERC && (**PSWIPEFORC == 0 || (**PSWIPEFORC != 0 && m_sActiveSwipe.avgSpeed < **PSWIPEFORC))) || + if ((abs(m_sActiveSwipe.delta) < *PSWIPEDIST * *PSWIPEPERC && (*PSWIPEFORC == 0 || (*PSWIPEFORC != 0 && m_sActiveSwipe.avgSpeed < *PSWIPEFORC))) || abs(m_sActiveSwipe.delta) < 2) { // revert if (abs(m_sActiveSwipe.delta) < 2) { @@ -194,40 +195,40 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; - static auto* const PSWIPEDIST = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance"); - static auto* const PSWIPEINVR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_invert"); - static auto* const PSWIPENEW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new"); - static auto* const PSWIPEDIRLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock"); - static auto* const PSWIPEDIRLOCKTHRESHOLD = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock_threshold"); - static auto* const PSWIPEFOREVER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_forever"); - static auto* const PSWIPENUMBER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered"); - static auto* const PSWIPEUSER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r"); - static auto* const PWORKSPACEGAP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_workspaces"); + static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); + static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); + static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); + static auto PSWIPEDIRLOCK = CConfigValue("gestures:workspace_swipe_direction_lock"); + static auto PSWIPEDIRLOCKTHRESHOLD = CConfigValue("gestures:workspace_swipe_direction_lock_threshold"); + static auto PSWIPEFOREVER = CConfigValue("gestures:workspace_swipe_forever"); + static auto PSWIPENUMBER = CConfigValue("gestures:workspace_swipe_numbered"); + static auto PSWIPEUSER = CConfigValue("gestures:workspace_swipe_use_r"); + static auto PWORKSPACEGAP = CConfigValue("general:gaps_workspaces"); - const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + **PWORKSPACEGAP; - const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + **PWORKSPACEGAP; - const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP; + const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); - m_sActiveSwipe.delta += VERTANIMS ? (**PSWIPEINVR ? -e->dy : e->dy) : (**PSWIPEINVR ? -e->dx : e->dx); + m_sActiveSwipe.delta += VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx); m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(e->dx)) / (m_sActiveSwipe.speedPoints + 1); m_sActiveSwipe.speedPoints++; std::string wsname = ""; - auto workspaceIDLeft = getWorkspaceIDFromString(**PSWIPENUMBER ? "-1" : (**PSWIPEUSER ? "r-1" : "m-1"), wsname); - auto workspaceIDRight = getWorkspaceIDFromString(**PSWIPENUMBER ? "+1" : (**PSWIPEUSER ? "r+1" : "m+1"), wsname); + auto workspaceIDLeft = getWorkspaceIDFromString(*PSWIPENUMBER ? "-1" : (*PSWIPEUSER ? "r-1" : "m-1"), wsname); + auto workspaceIDRight = getWorkspaceIDFromString(*PSWIPENUMBER ? "+1" : (*PSWIPEUSER ? "r+1" : "m+1"), wsname); - if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !**PSWIPENEW) { + if ((workspaceIDLeft == WORKSPACE_INVALID || workspaceIDRight == WORKSPACE_INVALID || workspaceIDLeft == m_sActiveSwipe.pWorkspaceBegin->m_iID) && !*PSWIPENEW) { m_sActiveSwipe.pWorkspaceBegin = nullptr; // invalidate the swipe return; } m_sActiveSwipe.pWorkspaceBegin->m_bForceRendering = true; - m_sActiveSwipe.delta = std::clamp(m_sActiveSwipe.delta, (double)-**PSWIPEDIST, (double)**PSWIPEDIST); + m_sActiveSwipe.delta = std::clamp(m_sActiveSwipe.delta, (double)-*PSWIPEDIST, (double)*PSWIPEDIST); - if ((m_sActiveSwipe.pWorkspaceBegin->m_iID == workspaceIDLeft && **PSWIPENEW && (m_sActiveSwipe.delta < 0)) || + if ((m_sActiveSwipe.pWorkspaceBegin->m_iID == workspaceIDLeft && *PSWIPENEW && (m_sActiveSwipe.delta < 0)) || (m_sActiveSwipe.delta > 0 && g_pCompositor->getWindowsOnWorkspace(m_sActiveSwipe.pWorkspaceBegin->m_iID) == 0 && workspaceIDRight <= m_sActiveSwipe.pWorkspaceBegin->m_iID) || (m_sActiveSwipe.delta < 0 && m_sActiveSwipe.pWorkspaceBegin->m_iID <= workspaceIDLeft)) { @@ -236,10 +237,10 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { return; } - if (**PSWIPEDIRLOCK) { + if (*PSWIPEDIRLOCK) { if (m_sActiveSwipe.initialDirection != 0 && m_sActiveSwipe.initialDirection != (m_sActiveSwipe.delta < 0 ? -1 : 1)) m_sActiveSwipe.delta = 0; - else if (m_sActiveSwipe.initialDirection == 0 && abs(m_sActiveSwipe.delta) > **PSWIPEDIRLOCKTHRESHOLD) + else if (m_sActiveSwipe.initialDirection == 0 && abs(m_sActiveSwipe.delta) > *PSWIPEDIRLOCKTHRESHOLD) m_sActiveSwipe.initialDirection = m_sActiveSwipe.delta < 0 ? -1 : 1; } @@ -247,13 +248,13 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDLeft); if (workspaceIDLeft > m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) { - if (**PSWIPENEW || **PSWIPENUMBER) { + if (*PSWIPENEW || *PSWIPENUMBER) { g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor); if (VERTANIMS) - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE)); else - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE, 0)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE, 0)); g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); return; @@ -275,11 +276,11 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { } if (VERTANIMS) { - PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE - YDISTANCE)); - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE)); + PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE - YDISTANCE)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE)); } else { - PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE - XDISTANCE, 0)); - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE, 0)); + PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE - XDISTANCE, 0)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE, 0)); } g_pCompositor->updateWorkspaceWindowDecos(workspaceIDLeft); @@ -287,13 +288,13 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(workspaceIDRight); if (workspaceIDRight < m_sActiveSwipe.pWorkspaceBegin->m_iID || !PWORKSPACE) { - if (**PSWIPENEW || **PSWIPENUMBER) { + if (*PSWIPENEW || *PSWIPENUMBER) { g_pHyprRenderer->damageMonitor(m_sActiveSwipe.pMonitor); if (VERTANIMS) - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE)); else - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE, 0)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE, 0)); g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); return; @@ -315,11 +316,11 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { } if (VERTANIMS) { - PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE + YDISTANCE)); - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / **PSWIPEDIST) * YDISTANCE)); + PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE + YDISTANCE)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(0, ((-m_sActiveSwipe.delta) / *PSWIPEDIST) * YDISTANCE)); } else { - PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE + XDISTANCE, 0)); - m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / **PSWIPEDIST) * XDISTANCE, 0)); + PWORKSPACE->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE + XDISTANCE, 0)); + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.setValueAndWarp(Vector2D(((-m_sActiveSwipe.delta) / *PSWIPEDIST) * XDISTANCE, 0)); } g_pCompositor->updateWorkspaceWindowDecos(workspaceIDRight); @@ -329,8 +330,8 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { g_pCompositor->updateWorkspaceWindowDecos(m_sActiveSwipe.pWorkspaceBegin->m_iID); - if (**PSWIPEFOREVER) { - if (abs(m_sActiveSwipe.delta) >= **PSWIPEDIST) { + if (*PSWIPEFOREVER) { + if (abs(m_sActiveSwipe.delta) >= *PSWIPEDIST) { onSwipeEnd(nullptr); beginWorkspaceSwipe(); } diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 9f6e071d..c097b551 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -1,5 +1,6 @@ #include "XDGOutput.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" #include "xdg-output-unstable-v1-protocol.h" @@ -112,7 +113,7 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(wl_client* client, wl_resource* r } void CXDGOutputProtocol::updateOutputDetails(SXDGOutput* pOutput) { - static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); + static auto PXWLFORCESCALEZERO = CConfigValue("xwayland:force_zero_scaling"); if (!pOutput->resource->good() || !pOutput->monitor) return; @@ -120,7 +121,7 @@ void CXDGOutputProtocol::updateOutputDetails(SXDGOutput* pOutput) { const auto POS = pOutput->isXWayland ? pOutput->monitor->vecXWaylandPosition : pOutput->monitor->vecPosition; zxdg_output_v1_send_logical_position(pOutput->resource->resource(), POS.x, POS.y); - if (**PXWLFORCESCALEZERO && pOutput->isXWayland) + if (*PXWLFORCESCALEZERO && pOutput->isXWayland) zxdg_output_v1_send_logical_size(pOutput->resource->resource(), pOutput->monitor->vecTransformedSize.x, pOutput->monitor->vecTransformedSize.y); else zxdg_output_v1_send_logical_size(pOutput->resource->resource(), pOutput->monitor->vecSize.x, pOutput->monitor->vecSize.y); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index de92130c..30803885 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -4,6 +4,7 @@ #include "../helpers/MiscFunctions.hpp" #include "Shaders.hpp" #include +#include "../config/ConfigValue.hpp" inline void loadGLProc(void* pProc, const char* name) { void* proc = (void*)eglGetProcAddress(name); @@ -120,10 +121,10 @@ GLuint CHyprOpenGLImpl::compileShader(const GLuint& type, std::string src, bool bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { // passes requiring introspection are the ones that need to render blur. - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); - static auto* const PXRAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:xray"); - static auto* const POPTIM = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations"); - static auto* const PBLURSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:special"); + static auto PBLUR = CConfigValue("decoration:blur:enabled"); + static auto PXRAY = CConfigValue("decoration:blur:xray"); + static auto POPTIM = CConfigValue("decoration:blur:new_optimizations"); + static auto PBLURSPECIAL = CConfigValue("decoration:blur:special"); if (m_RenderData.mouseZoomFactor != 1.0 || g_pHyprRenderer->m_bCrashingInProgress) return true; @@ -131,7 +132,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { if (!pMonitor->mirrors.empty()) return true; - if (**PBLUR == 0) + if (*PBLUR == 0) return false; if (m_RenderData.pCurrentMonData->blurFBShouldRender) @@ -141,13 +142,13 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { return false; for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { - const auto XRAYMODE = ls->xray == -1 ? **PXRAY : ls->xray; + const auto XRAYMODE = ls->xray == -1 ? *PXRAY : ls->xray; if (ls->forceBlur && !XRAYMODE) return true; } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { - const auto XRAYMODE = ls->xray == -1 ? **PXRAY : ls->xray; + const auto XRAYMODE = ls->xray == -1 ? *PXRAY : ls->xray; if (ls->forceBlur && !XRAYMODE) return true; } @@ -175,11 +176,11 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { } } - if (**PXRAY) + if (*PXRAY) return false; for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || (!w->m_bIsFloating && **POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID))) + if (!w->m_bIsMapped || w->isHidden() || (!w->m_bIsFloating && *POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID))) continue; if (!g_pHyprRenderer->shouldRenderWindow(w.get())) @@ -200,7 +201,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { void CHyprOpenGLImpl::begin(CMonitor* pMonitor, const CRegion& damage_, CFramebuffer* fb, std::optional finalDamage) { m_RenderData.pMonitor = pMonitor; - static auto* const PFORCEINTROSPECTION = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("opengl:force_introspection"); + static auto PFORCEINTROSPECTION = CConfigValue("opengl:force_introspection"); #ifndef GLES2 @@ -257,14 +258,14 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, const CRegion& damage_, CFramebu m_bFakeFrame = fb; if (m_bReloadScreenShader) { - m_bReloadScreenShader = false; - static auto* const PSHADER = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("decoration:screen_shader"); + m_bReloadScreenShader = false; + static auto PSHADER = CConfigValue("decoration:screen_shader"); applyScreenShader(*PSHADER); } const auto PRBO = g_pHyprRenderer->getCurrentRBO(); const bool FBPROPERSIZE = !fb || fb->m_vSize == pMonitor->vecPixelSize; - const bool USERFORCEDINTROSPECTION = **PFORCEINTROSPECTION == 1 ? true : (**PFORCEINTROSPECTION == 2 ? g_pHyprRenderer->isNvidia() : false); // 0 - no, 1 - yes, 2 - nvidia only + const bool USERFORCEDINTROSPECTION = *PFORCEINTROSPECTION == 1 ? true : (*PFORCEINTROSPECTION == 2 ? g_pHyprRenderer->isNvidia() : false); // 0 - no, 1 - yes, 2 - nvidia only if (USERFORCEDINTROSPECTION || m_RenderData.forceIntrospection || !FBPROPERSIZE || m_sFinalScreenShader.program > 0 || (PRBO && pMonitor->vecPixelSize != PRBO->getFB()->m_vSize) || passRequiresIntrospection(pMonitor)) { @@ -290,7 +291,7 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, const CRegion& damage_, CFramebu } void CHyprOpenGLImpl::end() { - static auto* const PZOOMRIGID = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_rigid"); + static auto PZOOMRIGID = CConfigValue("misc:cursor_zoom_rigid"); TRACY_GPU_ZONE("RenderEnd"); @@ -310,7 +311,7 @@ void CHyprOpenGLImpl::end() { (g_pInputManager->getMouseCoordsInternal() - m_RenderData.pMonitor->vecPosition) * m_RenderData.pMonitor->scale : m_RenderData.pMonitor->vecTransformedSize / 2.f; - monbox.translate(-ZOOMCENTER).scale(m_RenderData.mouseZoomFactor).translate(**PZOOMRIGID ? m_RenderData.pMonitor->vecTransformedSize / 2.0 : ZOOMCENTER); + monbox.translate(-ZOOMCENTER).scale(m_RenderData.mouseZoomFactor).translate(*PZOOMRIGID ? m_RenderData.pMonitor->vecTransformedSize / 2.0 : ZOOMCENTER); if (monbox.x > 0) monbox.x = 0; @@ -530,7 +531,7 @@ void CHyprOpenGLImpl::initShaders() { void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { - static auto* const PDT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); + static auto PDT = CConfigValue("debug:damage_tracking"); m_sFinalScreenShader.destroy(); @@ -557,7 +558,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.tex = glGetUniformLocation(m_sFinalScreenShader.program, "tex"); m_sFinalScreenShader.time = glGetUniformLocation(m_sFinalScreenShader.program, "time"); m_sFinalScreenShader.wl_output = glGetUniformLocation(m_sFinalScreenShader.program, "wl_output"); - if (m_sFinalScreenShader.time != -1 && **PDT != 0 && !g_pHyprRenderer->m_bCrashingInProgress) { + if (m_sFinalScreenShader.time != -1 && *PDT != 0 && !g_pHyprRenderer->m_bCrashingInProgress) { // The screen shader uses the "time" uniform // Since the screen shader could change every frame, damage tracking *needs* to be disabled g_pConfigManager->addParseError("Screen shader: Screen shader uses uniform 'time', which requires debug:damage_tracking to be switched off.\n" @@ -781,8 +782,8 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* CBox newBox = *pBox; m_RenderData.renderModif.applyToBox(newBox); - static auto* const PDIMINACTIVE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_inactive"); - static auto* const PDT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); + static auto PDIMINACTIVE = CConfigValue("decoration:dim_inactive"); + static auto PDT = CConfigValue("debug:damage_tracking"); // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); @@ -842,7 +843,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* #endif glUniform1i(shader->tex, 0); - if ((usingFinalShader && **PDT == 0) || CRASHING) { + if ((usingFinalShader && *PDT == 0) || CRASHING) { glUniform1f(shader->time, m_tGlobalTimer.getSeconds()); } else if (usingFinalShader && shader->time != -1) { // Don't let time be unitialised @@ -883,7 +884,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* glUniform2f(shader->fullSize, FULLSIZE.x, FULLSIZE.y); glUniform1f(shader->radius, round); - if (allowDim && m_pCurrentWindow && **PDIMINACTIVE) { + if (allowDim && m_pCurrentWindow && *PDIMINACTIVE) { glUniform1i(shader->applyTint, 1); const auto DIM = m_pCurrentWindow->m_fDimPercent.value(); glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM); @@ -1067,16 +1068,16 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix); // get the config settings - static auto* const PBLURSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:size"); - static auto* const PBLURPASSES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:passes"); - static auto* const PBLURVIBRANCY = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:vibrancy"); - static auto* const PBLURVIBRANCYDARKNESS = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:vibrancy_darkness"); + static auto PBLURSIZE = CConfigValue("decoration:blur:size"); + static auto PBLURPASSES = CConfigValue("decoration:blur:passes"); + static auto PBLURVIBRANCY = CConfigValue("decoration:blur:vibrancy"); + static auto PBLURVIBRANCYDARKNESS = CConfigValue("decoration:blur:vibrancy_darkness"); // prep damage CRegion damage{*originalDamage}; wlr_region_transform(damage.pixman(), damage.pixman(), wlr_output_transform_invert(m_RenderData.pMonitor->transform), m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y); - wlr_region_expand(damage.pixman(), damage.pixman(), **PBLURPASSES > 10 ? pow(2, 15) : std::clamp(**PBLURSIZE, (int64_t)1, (int64_t)40) * pow(2, **PBLURPASSES)); + wlr_region_expand(damage.pixman(), damage.pixman(), *PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, (int64_t)1, (int64_t)40) * pow(2, *PBLURPASSES)); // helper const auto PMIRRORFB = &m_RenderData.pCurrentMonData->mirrorFB; @@ -1087,8 +1088,8 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o // Begin with base color adjustments - global brightness and contrast // TODO: make this a part of the first pass maybe to save on a drawcall? { - static auto* const PBLURCONTRAST = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:contrast"); - static auto* const PBLURBRIGHTNESS = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:brightness"); + static auto PBLURCONTRAST = CConfigValue("decoration:blur:contrast"); + static auto PBLURBRIGHTNESS = CConfigValue("decoration:blur:brightness"); PMIRRORSWAPFB->bind(); @@ -1106,8 +1107,8 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_transpose(glMatrix, glMatrix); glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURPREPARE.proj, 1, GL_FALSE, glMatrix); #endif - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURPREPARE.contrast, **PBLURCONTRAST); - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURPREPARE.brightness, **PBLURBRIGHTNESS); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURPREPARE.contrast, *PBLURCONTRAST); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURPREPARE.brightness, *PBLURBRIGHTNESS); glUniform1i(m_RenderData.pCurrentMonData->m_shBLURPREPARE.tex, 0); glVertexAttribPointer(m_RenderData.pCurrentMonData->m_shBLURPREPARE.posAttrib, 2, GL_FLOAT, GL_FALSE, 0, fullVerts); @@ -1151,13 +1152,13 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_transpose(glMatrix, glMatrix); glUniformMatrix3fv(pShader->proj, 1, GL_FALSE, glMatrix); #endif - glUniform1f(pShader->radius, **PBLURSIZE * a); // this makes the blursize change with a + glUniform1f(pShader->radius, *PBLURSIZE * a); // this makes the blursize change with a if (pShader == &m_RenderData.pCurrentMonData->m_shBLUR1) { glUniform2f(m_RenderData.pCurrentMonData->m_shBLUR1.halfpixel, 0.5f / (m_RenderData.pMonitor->vecPixelSize.x / 2.f), 0.5f / (m_RenderData.pMonitor->vecPixelSize.y / 2.f)); - glUniform1i(m_RenderData.pCurrentMonData->m_shBLUR1.passes, **PBLURPASSES); - glUniform1f(m_RenderData.pCurrentMonData->m_shBLUR1.vibrancy, **PBLURVIBRANCY); - glUniform1f(m_RenderData.pCurrentMonData->m_shBLUR1.vibrancy_darkness, **PBLURVIBRANCYDARKNESS); + glUniform1i(m_RenderData.pCurrentMonData->m_shBLUR1.passes, *PBLURPASSES); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLUR1.vibrancy, *PBLURVIBRANCY); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLUR1.vibrancy_darkness, *PBLURVIBRANCYDARKNESS); } else glUniform2f(m_RenderData.pCurrentMonData->m_shBLUR2.halfpixel, 0.5f / (m_RenderData.pMonitor->vecPixelSize.x * 2.f), 0.5f / (m_RenderData.pMonitor->vecPixelSize.y * 2.f)); @@ -1194,20 +1195,20 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o CRegion tempDamage{damage}; // and draw - for (int i = 1; i <= **PBLURPASSES; ++i) { + for (int i = 1; i <= *PBLURPASSES; ++i) { wlr_region_scale(tempDamage.pixman(), damage.pixman(), 1.f / (1 << i)); drawPass(&m_RenderData.pCurrentMonData->m_shBLUR1, &tempDamage); // down } - for (int i = **PBLURPASSES - 1; i >= 0; --i) { + for (int i = *PBLURPASSES - 1; i >= 0; --i) { wlr_region_scale(tempDamage.pixman(), damage.pixman(), 1.f / (1 << i)); // when upsampling we make the region twice as big drawPass(&m_RenderData.pCurrentMonData->m_shBLUR2, &tempDamage); // up } // finalize the image { - static auto* const PBLURNOISE = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:noise"); - static auto* const PBLURBRIGHTNESS = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:brightness"); + static auto PBLURNOISE = CConfigValue("decoration:blur:noise"); + static auto PBLURBRIGHTNESS = CConfigValue("decoration:blur:brightness"); if (currentRenderToFB == PMIRRORFB) PMIRRORSWAPFB->bind(); @@ -1228,8 +1229,8 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_transpose(glMatrix, glMatrix); glUniformMatrix3fv(m_RenderData.pCurrentMonData->m_shBLURFINISH.proj, 1, GL_FALSE, glMatrix); #endif - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.noise, **PBLURNOISE); - glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness, **PBLURBRIGHTNESS); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.noise, *PBLURNOISE); + glUniform1f(m_RenderData.pCurrentMonData->m_shBLURFINISH.brightness, *PBLURBRIGHTNESS); glUniform1i(m_RenderData.pCurrentMonData->m_shBLURFINISH.tex, 0); @@ -1268,11 +1269,11 @@ void CHyprOpenGLImpl::markBlurDirtyForMonitor(CMonitor* pMonitor) { } void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { - static auto* const PBLURNEWOPTIMIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations"); - static auto* const PBLURXRAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:xray"); - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + static auto PBLURNEWOPTIMIZE = CConfigValue("decoration:blur:new_optimizations"); + static auto PBLURXRAY = CConfigValue("decoration:blur:xray"); + static auto PBLUR = CConfigValue("decoration:blur:enabled"); - if (!**PBLURNEWOPTIMIZE || !m_mMonitorRenderResources[pMonitor].blurFBDirty || !**PBLUR) + if (!*PBLURNEWOPTIMIZE || !m_mMonitorRenderResources[pMonitor].blurFBDirty || !*PBLUR) return; // ignore if solitary present, nothing to blur @@ -1317,7 +1318,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { bool hasWindows = false; for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == pMonitor->activeWorkspace && !w->isHidden() && w->m_bIsMapped && (!w->m_bIsFloating || **PBLURXRAY)) { + if (w->m_iWorkspaceID == pMonitor->activeWorkspace && !w->isHidden() && w->m_bIsMapped && (!w->m_bIsFloating || *PBLURXRAY)) { // check if window is valid if (!windowShouldBeBlurred(w.get())) @@ -1390,15 +1391,15 @@ void CHyprOpenGLImpl::preWindowPass() { } bool CHyprOpenGLImpl::preBlurQueued() { - static auto* const PBLURNEWOPTIMIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations"); - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + static auto PBLURNEWOPTIMIZE = CConfigValue("decoration:blur:new_optimizations"); + static auto PBLUR = CConfigValue("decoration:blur:enabled"); - return !(!m_RenderData.pCurrentMonData->blurFBDirty || !**PBLURNEWOPTIMIZE || !**PBLUR || !m_RenderData.pCurrentMonData->blurFBShouldRender); + return !(!m_RenderData.pCurrentMonData->blurFBDirty || !*PBLURNEWOPTIMIZE || !*PBLUR || !m_RenderData.pCurrentMonData->blurFBShouldRender); } bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWindow* pWindow) { - static auto* const PBLURNEWOPTIMIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations"); - static auto* const PBLURXRAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:xray"); + static auto PBLURNEWOPTIMIZE = CConfigValue("decoration:blur:new_optimizations"); + static auto PBLURXRAY = CConfigValue("decoration:blur:xray"); if (!m_RenderData.pCurrentMonData->blurFB.m_cTex.m_iTexID) return false; @@ -1409,7 +1410,7 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWind if (pLayer && pLayer->xray == 0) return false; - if ((**PBLURNEWOPTIMIZE && pWindow && !pWindow->m_bIsFloating && !g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) || **PBLURXRAY) + if ((*PBLURNEWOPTIMIZE && pWindow && !pWindow->m_bIsFloating && !g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) || *PBLURXRAY) return true; if ((pLayer && pLayer->xray == 1) || (pWindow && pWindow->m_sAdditionalConfigData.xray.toUnderlying() == 1)) @@ -1421,8 +1422,8 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWind void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, float a, wlr_surface* pSurface, int round, bool blockBlurOptimization, float blurA) { RASSERT(m_RenderData.pMonitor, "Tried to render texture with blur without begin()!"); - static auto* const PBLURENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); - static auto* const PNOBLUROVERSIZED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:no_blur_on_oversized"); + static auto PBLURENABLED = CConfigValue("decoration:blur:enabled"); + static auto PNOBLUROVERSIZED = CConfigValue("decoration:no_blur_on_oversized"); TRACY_GPU_ZONE("RenderTextureWithBlur"); @@ -1433,7 +1434,7 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo if (texDamage.empty()) return; - if (**PBLURENABLED == 0 || (**PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) || + if (*PBLURENABLED == 0 || (*PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) || (m_pCurrentWindow && (m_pCurrentWindow->m_sAdditionalConfigData.forceNoBlur || m_pCurrentWindow->m_sAdditionalConfigData.forceRGBX))) { renderTexture(tex, pBox, a, round, false, true); return; @@ -1494,11 +1495,11 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo // stencil done. Render everything. CBox MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; // render our great blurred FB - static auto* const PBLURIGNOREOPACITY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:ignore_opacity"); - m_bEndFrame = true; // fix transformed - const auto SAVEDRENDERMODIF = m_RenderData.renderModif; - m_RenderData.renderModif = {}; // fix shit - renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, **PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); + static auto PBLURIGNOREOPACITY = CConfigValue("decoration:blur:ignore_opacity"); + m_bEndFrame = true; // fix transformed + const auto SAVEDRENDERMODIF = m_RenderData.renderModif; + m_RenderData.renderModif = {}; // fix shit + renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); m_bEndFrame = false; m_RenderData.renderModif = SAVEDRENDERMODIF; @@ -1648,7 +1649,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFra // will try to copy the bg to apply blur. // this isn't entirely correct, but like, oh well. // small todo: maybe make this correct? :P - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + static auto* const PBLUR = (Hyprlang::INT* const*)(g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")); const auto BLURVAL = **PBLUR; **PBLUR = 0; @@ -1701,7 +1702,7 @@ void CHyprOpenGLImpl::makeWindowSnapshot(CWindow* pWindow) { // will try to copy the bg to apply blur. // this isn't entirely correct, but like, oh well. // small todo: maybe make this correct? :P - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + static auto* const PBLUR = (Hyprlang::INT* const*)(g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")); const auto BLURVAL = **PBLUR; **PBLUR = 0; @@ -1758,11 +1759,11 @@ void CHyprOpenGLImpl::makeLayerSnapshot(SLayerSurface* pLayer) { void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!"); - const auto PWINDOW = *pWindow; + const auto PWINDOW = *pWindow; - static auto* const PDIMAROUND = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_around"); + static auto PDIMAROUND = CConfigValue("decoration:dim_around"); - auto it = m_mWindowFramebuffers.begin(); + auto it = m_mWindowFramebuffers.begin(); for (; it != m_mWindowFramebuffers.end(); it++) { if (it->first == PWINDOW) { break; @@ -1787,9 +1788,9 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { CRegion fakeDamage{0, 0, PMONITOR->vecTransformedSize.x, PMONITOR->vecTransformedSize.y}; - if (**PDIMAROUND && (*pWindow)->m_sAdditionalConfigData.dimAround) { + if (*PDIMAROUND && (*pWindow)->m_sAdditionalConfigData.dimAround) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecPixelSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMAROUND * PWINDOW->m_fAlpha.value())); + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * PWINDOW->m_fAlpha.value())); g_pHyprRenderer->damageMonitor(PMONITOR); } @@ -1851,13 +1852,13 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const box = &newBox; - static auto* const PSHADOWPOWER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow_render_power"); + static auto PSHADOWPOWER = CConfigValue("decoration:shadow_render_power"); - const auto SHADOWPOWER = std::clamp((int)**PSHADOWPOWER, 1, 4); + const auto SHADOWPOWER = std::clamp((int)*PSHADOWPOWER, 1, 4); - const auto col = color; + const auto col = color; - float matrix[9]; + float matrix[9]; wlr_matrix_project_box(matrix, box->pWlr(), wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform), newBox.rot, m_RenderData.pMonitor->projMatrix.data()); // TODO: write own, don't use WLR here @@ -1945,16 +1946,16 @@ void CHyprOpenGLImpl::renderMirrored() { } void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const CAIROSURFACE, double offsetY, const Vector2D& size) { - static auto* const PSPLASHCOLOR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:col.splash"); + static auto PSPLASHCOLOR = CConfigValue("misc:col.splash"); - static auto* const PSPLASHFONT = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("misc:splash_font_family"); + static auto PSPLASHFONT = CConfigValue("misc:splash_font_family"); - cairo_select_font_face(CAIRO, *PSPLASHFONT, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); + cairo_select_font_face(CAIRO, (*PSPLASHFONT).c_str(), CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); const auto FONTSIZE = (int)(size.y / 76); cairo_set_font_size(CAIRO, FONTSIZE); - const auto COLOR = CColor(**PSPLASHCOLOR); + const auto COLOR = CColor(*PSPLASHCOLOR); cairo_set_source_rgba(CAIRO, COLOR.r, COLOR.g, COLOR.b, COLOR.a); @@ -1971,15 +1972,15 @@ void CHyprOpenGLImpl::renderSplash(cairo_t* const CAIRO, cairo_surface_t* const void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { RASSERT(m_RenderData.pMonitor, "Tried to createBGTex without begin()!"); - static auto* const PRENDERTEX = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo"); - static auto* const PNOSPLASH = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:disable_splash_rendering"); - static auto* const PFORCEWALLPAPER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:force_default_wallpaper"); + static auto PRENDERTEX = CConfigValue("misc:disable_hyprland_logo"); + static auto PNOSPLASH = CConfigValue("misc:disable_splash_rendering"); + static auto PFORCEWALLPAPER = CConfigValue("misc:force_default_wallpaper"); - const auto FORCEWALLPAPER = std::clamp(**PFORCEWALLPAPER, static_cast(-1L), static_cast(2L)); + const auto FORCEWALLPAPER = std::clamp(*PFORCEWALLPAPER, static_cast(-1L), static_cast(2L)); static std::string texPath = ""; - if (**PRENDERTEX) + if (*PRENDERTEX) return; // release the last tex if exists @@ -2001,7 +2002,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { texPath += std::to_string(distribution(engine)); } else - texPath += std::to_string(std::clamp(**PFORCEWALLPAPER, (int64_t)0, (int64_t)2)); + texPath += std::to_string(std::clamp(*PFORCEWALLPAPER, (int64_t)0, (int64_t)2)); texPath += ".png"; @@ -2052,7 +2053,7 @@ void CHyprOpenGLImpl::createBGTextureForMonitor(CMonitor* pMonitor) { cairo_set_source_surface(CAIRO, CAIROISURFACE, 0, 0); cairo_paint(CAIRO); - if (!**PNOSPLASH) + if (!*PNOSPLASH) renderSplash(CAIRO, CAIROSURFACE, origin.y * WPRATIO / MONRATIO * scale, IMAGESIZE); cairo_surface_flush(CAIROSURFACE); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e8359601..303491d1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -3,6 +3,7 @@ #include "linux-dmabuf-unstable-v1-protocol.h" #include "../helpers/Region.hpp" #include +#include "../config/ConfigValue.hpp" extern "C" { #include @@ -48,12 +49,12 @@ CHyprRenderer::CHyprRenderer() { } static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { - static auto* const PBLURPOPUPS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:popups"); - static auto* const PBLURPOPUPSIGNOREALPHA = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:popups_ignorealpha"); + static auto PBLURPOPUPS = CConfigValue("decoration:blur:popups"); + static auto PBLURPOPUPSIGNOREALPHA = CConfigValue("decoration:blur:popups_ignorealpha"); - const auto TEXTURE = wlr_surface_get_texture(surface); - const auto RDATA = (SRenderData*)data; - const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE; + const auto TEXTURE = wlr_surface_get_texture(surface); + const auto RDATA = (SRenderData*)data; + const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE; if (!TEXTURE) return; @@ -148,11 +149,11 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, rounding, true); } } else { - if (RDATA->blur && RDATA->popup && **PBLURPOPUPS) { + if (RDATA->blur && RDATA->popup && *PBLURPOPUPS) { - if (**PBLURPOPUPSIGNOREALPHA != 1.f) { + if (*PBLURPOPUPSIGNOREALPHA != 1.f) { g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; - g_pHyprOpenGL->m_RenderData.discardOpacity = **PBLURPOPUPSIGNOREALPHA; + g_pHyprOpenGL->m_RenderData.discardOpacity = *PBLURPOPUPSIGNOREALPHA; } g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, surface, rounding, true); @@ -407,13 +408,13 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* TRACY_GPU_ZONE("RenderWindow"); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - const auto REALPOS = pWindow->m_vRealPosition.value() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.value()); - static auto* const PDIMAROUND = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_around"); - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto REALPOS = pWindow->m_vRealPosition.value() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.value()); + static auto PDIMAROUND = CConfigValue("decoration:dim_around"); + static auto PBLUR = CConfigValue("decoration:blur:enabled"); - SRenderData renderdata = {pMonitor, time}; - CBox textureBox = {REALPOS.x, REALPOS.y, std::max(pWindow->m_vRealSize.value().x, 5.0), std::max(pWindow->m_vRealSize.value().y, 5.0)}; + SRenderData renderdata = {pMonitor, time}; + CBox textureBox = {REALPOS.x, REALPOS.y, std::max(pWindow->m_vRealSize.value().x, 5.0), std::max(pWindow->m_vRealSize.value().y, 5.0)}; renderdata.x = textureBox.x; renderdata.y = textureBox.y; @@ -452,7 +453,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (*PDIMAROUND && pWindow->m_sAdditionalConfigData.dimAround && !m_bRenderingSnapshot && mode != RENDER_PASS_POPUP) { CBox monbox = {0, 0, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.x, g_pHyprOpenGL->m_RenderData.pMonitor->vecTransformedSize.y}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); } // clip box for animated offsets @@ -521,11 +522,11 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* } } - static auto* const PXWLUSENN = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:use_nearest_neighbor"); - if ((pWindow->m_bIsX11 && **PXWLUSENN) || pWindow->m_sAdditionalConfigData.nearestNeighbor.toUnderlying()) + static auto PXWLUSENN = CConfigValue("xwayland:use_nearest_neighbor"); + if ((pWindow->m_bIsX11 && *PXWLUSENN) || pWindow->m_sAdditionalConfigData.nearestNeighbor.toUnderlying()) g_pHyprOpenGL->m_RenderData.useNearestNeighbor = true; - if (!pWindow->m_sAdditionalConfigData.forceNoBlur && pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall && renderdata.blur && **PBLUR) { + if (!pWindow->m_sAdditionalConfigData.forceNoBlur && pWindow->m_pWLSurface.small() && !pWindow->m_pWLSurface.m_bFillIgnoreSmall && renderdata.blur && *PBLUR) { CBox wb = {renderdata.x - pMonitor->vecPosition.x, renderdata.y - pMonitor->vecPosition.y, renderdata.w, renderdata.h}; wb.scale(pMonitor->scale).round(); g_pHyprOpenGL->renderRectWithBlur(&wb, CColor(0, 0, 0, 0), renderdata.dontRound ? 0 : renderdata.rounding - 1, renderdata.fadeAlpha, @@ -663,13 +664,13 @@ void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMon } void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { - static auto* const PDIMSPECIAL = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_special"); - static auto* const PBLURSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:special"); - static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); - static auto* const PRENDERTEX = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo"); - static auto* const PBACKGROUNDCOLOR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:background_color"); + static auto PDIMSPECIAL = CConfigValue("decoration:dim_special"); + static auto PBLURSPECIAL = CConfigValue("decoration:blur:special"); + static auto PBLUR = CConfigValue("decoration:blur:enabled"); + static auto PRENDERTEX = CConfigValue("misc:disable_hyprland_logo"); + static auto PBACKGROUNDCOLOR = CConfigValue("misc:background_color"); - SRenderModifData RENDERMODIFDATA; + SRenderModifData RENDERMODIFDATA; if (translate != Vector2D{0, 0}) RENDERMODIFDATA.modifs.push_back({SRenderModifData::eRenderModifType::RMOD_TYPE_TRANSLATE, translate}); if (scale != 1.f) @@ -705,8 +706,8 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* g_pHyprOpenGL->blend(false); if (!canSkipBackBufferClear(pMonitor)) { - if (**PRENDERTEX /* inverted cfg flag */) - g_pHyprOpenGL->clear(CColor(**PBACKGROUNDCOLOR)); + if (*PRENDERTEX /* inverted cfg flag */) + g_pHyprOpenGL->clear(CColor(*PBACKGROUNDCOLOR)); else g_pHyprOpenGL->clearWithTex(); // will apply the hypr "wallpaper" } @@ -742,12 +743,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* const auto SPECIALANIMPROGRS = ws->m_vRenderOffset.isBeingAnimated() ? ws->m_vRenderOffset.getCurveValue() : ws->m_fAlpha.getCurveValue(); const bool ANIMOUT = !pMonitor->specialWorkspaceID; - if (**PDIMSPECIAL != 0.f) { + if (*PDIMSPECIAL != 0.f) { CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; - g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMSPECIAL * (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS))); + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMSPECIAL * (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS))); } - if (**PBLURSPECIAL && **PBLUR) { + if (*PBLURSPECIAL && *PBLUR) { CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; g_pHyprOpenGL->renderRectWithBlur(&monbox, CColor(0, 0, 0, 0), 0, (ANIMOUT ? (1.0 - SPECIALANIMPROGRS) : SPECIALANIMPROGRS)); } @@ -949,23 +950,23 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { static std::chrono::high_resolution_clock::time_point renderStartOverlay = std::chrono::high_resolution_clock::now(); static std::chrono::high_resolution_clock::time_point endRenderOverlay = std::chrono::high_resolution_clock::now(); - static auto* const PDEBUGOVERLAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:overlay"); - static auto* const PDAMAGETRACKINGMODE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); - static auto* const PDAMAGEBLINK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_blink"); - static auto* const PNODIRECTSCANOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:no_direct_scanout"); - static auto* const PVFR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:vfr"); - static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor"); - static auto* const PANIMENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("animations:enabled"); - static auto* const PFIRSTLAUNCHANIM = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("animations:first_launch_animation"); - static auto* const PTEARINGENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:allow_tearing"); + static auto PDEBUGOVERLAY = CConfigValue("debug:overlay"); + static auto PDAMAGETRACKINGMODE = CConfigValue("debug:damage_tracking"); + static auto PDAMAGEBLINK = CConfigValue("debug:damage_blink"); + static auto PNODIRECTSCANOUT = CConfigValue("misc:no_direct_scanout"); + static auto PVFR = CConfigValue("misc:vfr"); + static auto PZOOMFACTOR = CConfigValue("misc:cursor_zoom_factor"); + static auto PANIMENABLED = CConfigValue("animations:enabled"); + static auto PFIRSTLAUNCHANIM = CConfigValue("animations:first_launch_animation"); + static auto PTEARINGENABLED = CConfigValue("general:allow_tearing"); static int damageBlinkCleanup = 0; // because double-buffered - if (!**PDAMAGEBLINK) + if (!*PDAMAGEBLINK) damageBlinkCleanup = 0; static bool firstLaunch = true; - static bool firstLaunchAnimActive = **PFIRSTLAUNCHANIM; + static bool firstLaunchAnimActive = *PFIRSTLAUNCHANIM; float zoomInFactorFirstLaunch = 1.f; @@ -975,7 +976,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } if (m_tRenderTimer.getSeconds() < 1.5f && firstLaunchAnimActive) { // TODO: make the animation system more damage-flexible so that this can be migrated to there - if (!**PANIMENABLED) { + if (!*PANIMENABLED) { zoomInFactorFirstLaunch = 1.f; firstLaunchAnimActive = false; } else { @@ -988,7 +989,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { renderStart = std::chrono::high_resolution_clock::now(); - if (**PDEBUGOVERLAY == 1) + if (*PDEBUGOVERLAY == 1) g_pDebugOverlay->frameData(pMonitor); if (pMonitor->framesToSkip > 0) { @@ -1008,7 +1009,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { // checks // if (pMonitor->ID == m_pMostHzMonitor->ID || - **PVFR == 1) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that + *PVFR == 1) { // unfortunately with VFR we don't have the guarantee mostHz is going to be updated all the time, so we have to ignore that g_pCompositor->sanityCheckWorkspaces(); g_pConfigManager->dispatchExecOnce(); // We exec-once when at least one monitor starts refreshing, meaning stuff has init'd @@ -1049,7 +1050,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (pMonitor->tearingState.nextRenderTorn) { pMonitor->tearingState.nextRenderTorn = false; - if (!**PTEARINGENABLED) { + if (!*PTEARINGENABLED) { Debug::log(WARN, "Tearing commit requested but the master switch general:allow_tearing is off, ignoring"); return; } @@ -1068,7 +1069,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { shouldTear = true; } - if (!**PNODIRECTSCANOUT && !shouldTear) { + if (!*PNODIRECTSCANOUT && !shouldTear) { if (attemptDirectScanout(pMonitor)) { return; } else if (m_pLastScanout) { @@ -1090,10 +1091,10 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { // check the damage bool hasChanged = pMonitor->output->needs_frame || pixman_region32_not_empty(&pMonitor->damage.current); - if (!hasChanged && **PDAMAGETRACKINGMODE != DAMAGE_TRACKING_NONE && pMonitor->forceFullFrames == 0 && damageBlinkCleanup == 0) + if (!hasChanged && *PDAMAGETRACKINGMODE != DAMAGE_TRACKING_NONE && pMonitor->forceFullFrames == 0 && damageBlinkCleanup == 0) return; - if (**PDAMAGETRACKINGMODE == -1) { + if (*PDAMAGETRACKINGMODE == -1) { Debug::log(CRIT, "Damage tracking mode -1 ????"); return; } @@ -1115,7 +1116,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { TRACY_GPU_ZONE("Render"); if (pMonitor == g_pCompositor->getMonitorFromCursor()) - g_pHyprOpenGL->m_RenderData.mouseZoomFactor = std::clamp(**PZOOMFACTOR, 1.f, INFINITY); + g_pHyprOpenGL->m_RenderData.mouseZoomFactor = std::clamp(*PZOOMFACTOR, 1.f, INFINITY); else g_pHyprOpenGL->m_RenderData.mouseZoomFactor = 1.f; @@ -1139,22 +1140,22 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } // if we have no tracking or full tracking, invalidate the entire monitor - if (**PDAMAGETRACKINGMODE == DAMAGE_TRACKING_NONE || **PDAMAGETRACKINGMODE == DAMAGE_TRACKING_MONITOR || pMonitor->forceFullFrames > 0 || damageBlinkCleanup > 0 || + if (*PDAMAGETRACKINGMODE == DAMAGE_TRACKING_NONE || *PDAMAGETRACKINGMODE == DAMAGE_TRACKING_MONITOR || pMonitor->forceFullFrames > 0 || damageBlinkCleanup > 0 || pMonitor->isMirror() /* why??? */) { damage = {0, 0, (int)pMonitor->vecTransformedSize.x * 10, (int)pMonitor->vecTransformedSize.y * 10}; finalDamage = damage; } else { - static auto* const PBLURENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + static auto PBLURENABLED = CConfigValue("decoration:blur:enabled"); // if we use blur we need to expand the damage for proper blurring // if framebuffer was not offloaded we're not doing introspection aka not blurring so this is redundant and dumb - if (**PBLURENABLED == 1 && g_pHyprOpenGL->m_bOffloadedFramebuffer) { + if (*PBLURENABLED == 1 && g_pHyprOpenGL->m_bOffloadedFramebuffer) { // TODO: can this be optimized? - static auto* const PBLURSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:size"); - static auto* const PBLURPASSES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:passes"); - const auto BLURRADIUS = - **PBLURPASSES > 10 ? pow(2, 15) : std::clamp(**PBLURSIZE, (int64_t)1, (int64_t)40) * pow(2, **PBLURPASSES); // is this 2^pass? I don't know but it works... I think. + static auto PBLURSIZE = CConfigValue("decoration:blur:size"); + static auto PBLURPASSES = CConfigValue("decoration:blur:passes"); + const auto BLURRADIUS = + *PBLURPASSES > 10 ? pow(2, 15) : std::clamp(*PBLURSIZE, (int64_t)1, (int64_t)40) * pow(2, *PBLURPASSES); // is this 2^pass? I don't know but it works... I think. // now, prep the damage, get the extended damage region wlr_region_expand(damage.pixman(), damage.pixman(), BLURRADIUS); // expand for proper blurring @@ -1198,17 +1199,17 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } // for drawing the debug overlay - if (pMonitor == g_pCompositor->m_vMonitors.front().get() && **PDEBUGOVERLAY == 1) { + if (pMonitor == g_pCompositor->m_vMonitors.front().get() && *PDEBUGOVERLAY == 1) { renderStartOverlay = std::chrono::high_resolution_clock::now(); g_pDebugOverlay->draw(); endRenderOverlay = std::chrono::high_resolution_clock::now(); } - if (**PDAMAGEBLINK && damageBlinkCleanup == 0) { + if (*PDAMAGEBLINK && damageBlinkCleanup == 0) { CBox monrect = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; g_pHyprOpenGL->renderRect(&monrect, CColor(1.0, 0.0, 1.0, 100.0 / 255.0), 0); damageBlinkCleanup = 1; - } else if (**PDAMAGEBLINK) { + } else if (*PDAMAGEBLINK) { damageBlinkCleanup++; if (damageBlinkCleanup > 3) damageBlinkCleanup = 0; @@ -1223,7 +1224,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (renderCursor) { TRACY_GPU_ZONE("RenderCursor"); - bool lockSoftware = pMonitor == g_pCompositor->getMonitorFromCursor() && **PZOOMFACTOR != 1.f; + bool lockSoftware = pMonitor == g_pCompositor->getMonitorFromCursor() && *PZOOMFACTOR != 1.f; if (lockSoftware) { wlr_output_lock_software_cursors(pMonitor->output, true); @@ -1245,10 +1246,10 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { const auto TRANSFORM = wlr_output_transform_invert(pMonitor->output->transform); wlr_region_transform(frameDamage.pixman(), finalDamage.pixman(), TRANSFORM, (int)pMonitor->vecTransformedSize.x, (int)pMonitor->vecTransformedSize.y); - if (**PDAMAGETRACKINGMODE == DAMAGE_TRACKING_NONE || **PDAMAGETRACKINGMODE == DAMAGE_TRACKING_MONITOR) + if (*PDAMAGETRACKINGMODE == DAMAGE_TRACKING_NONE || *PDAMAGETRACKINGMODE == DAMAGE_TRACKING_MONITOR) frameDamage.add(0, 0, (int)pMonitor->vecTransformedSize.x, (int)pMonitor->vecTransformedSize.y); - if (**PDAMAGEBLINK) + if (*PDAMAGEBLINK) frameDamage.add(damage); g_pHyprRenderer->damageMirrorsWith(pMonitor, frameDamage); @@ -1276,7 +1277,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (UNLOCK_SC) wlr_output_lock_software_cursors(pMonitor->output, false); - if (**PDAMAGEBLINK || **PVFR == 0 || pMonitor->pendingFrame) + if (*PDAMAGEBLINK || *PVFR == 0 || pMonitor->pendingFrame) g_pCompositor->scheduleFrameForMonitor(pMonitor); pMonitor->pendingFrame = false; @@ -1284,7 +1285,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { const float µs = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - renderStart).count() / 1000.f; g_pDebugOverlay->renderData(pMonitor, µs); - if (**PDEBUGOVERLAY == 1) { + if (*PDEBUGOVERLAY == 1) { if (pMonitor == g_pCompositor->m_vMonitors.front().get()) { const float µsNoOverlay = µs - std::chrono::duration_cast(endRenderOverlay - renderStartOverlay).count() / 1000.f; g_pDebugOverlay->renderDataNoOverlay(pMonitor, µsNoOverlay); @@ -1627,9 +1628,9 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou m->addDamage(&damageBoxForEach); } - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); - if (**PLOGDAMAGE) + if (*PLOGDAMAGE) Debug::log(LOG, "Damage: Surface (extents): xy: {}, {} wh: {}, {}", damageBox.pixman()->extents.x1, damageBox.pixman()->extents.y1, damageBox.pixman()->extents.x2 - damageBox.pixman()->extents.x1, damageBox.pixman()->extents.y2 - damageBox.pixman()->extents.y1); } @@ -1648,9 +1649,9 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { for (auto& wd : pWindow->m_dWindowDecorations) wd->damageEntire(); - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); - if (**PLOGDAMAGE) + if (*PLOGDAMAGE) Debug::log(LOG, "Damage: Window ({}): xy: {}, {} wh: {}, {}", pWindow->m_szTitle, damageBox.x, damageBox.y, damageBox.width, damageBox.height); } @@ -1661,9 +1662,9 @@ void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { CBox damageBox = {0, 0, INT16_MAX, INT16_MAX}; pMonitor->addDamage(&damageBox); - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); - if (**PLOGDAMAGE) + if (*PLOGDAMAGE) Debug::log(LOG, "Damage: Monitor {}", pMonitor->szName); } @@ -1680,9 +1681,9 @@ void CHyprRenderer::damageBox(CBox* pBox) { m->addDamage(&damageBox); } - static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); - if (**PLOGDAMAGE) + if (*PLOGDAMAGE) Debug::log(LOG, "Damage: Box: xy: {}, {} wh: {}, {}", pBox->x, pBox->y, pBox->width, pBox->height); } @@ -1738,7 +1739,7 @@ DAMAGETRACKINGMODES CHyprRenderer::damageTrackingModeFromStr(const std::string& bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorRule, bool force) { - static auto* const PDISABLESCALECHECKS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:disable_scale_checks"); + static auto PDISABLESCALECHECKS = CConfigValue("debug:disable_scale_checks"); Debug::log(LOG, "Applying monitor rule for {}", pMonitor->szName); @@ -2015,7 +2016,7 @@ bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorR pMonitor->vecPixelSize = pMonitor->vecSize; Vector2D logicalSize = pMonitor->vecPixelSize / pMonitor->scale; - if (!**PDISABLESCALECHECKS && (logicalSize.x != std::round(logicalSize.x) || logicalSize.y != std::round(logicalSize.y))) { + if (!*PDISABLESCALECHECKS && (logicalSize.x != std::round(logicalSize.x) || logicalSize.y != std::round(logicalSize.y))) { // invalid scale, will produce fractional pixels. // find the nearest valid. @@ -2189,13 +2190,13 @@ void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { } void CHyprRenderer::ensureCursorRenderingMode() { - static auto* const PCURSORTIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:cursor_inactive_timeout"); - static auto* const PHIDEONTOUCH = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:hide_cursor_on_touch"); + static auto PCURSORTIMEOUT = CConfigValue("general:cursor_inactive_timeout"); + static auto PHIDEONTOUCH = CConfigValue("misc:hide_cursor_on_touch"); - const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds(); + const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds(); - if (**PCURSORTIMEOUT > 0 || **PHIDEONTOUCH) { - const bool HIDE = (**PCURSORTIMEOUT > 0 && **PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && **PHIDEONTOUCH); + if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) { + const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH); if (HIDE && !m_bCursorHidden) { Debug::log(LOG, "Hiding the cursor (timeout)"); @@ -2286,7 +2287,7 @@ void CHyprRenderer::initiateManualCrash() { g_pHyprOpenGL->m_tGlobalTimer.reset(); - static auto* const PDT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); + static auto PDT = (Hyprlang::INT* const*)(g_pConfigManager->getConfigValuePtr("debug:damage_tracking")); **PDT = 0; } @@ -2514,8 +2515,8 @@ bool CHyprRenderer::beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode } void CHyprRenderer::endRender() { - const auto PMONITOR = g_pHyprOpenGL->m_RenderData.pMonitor; - static auto* const PNVIDIAANTIFLICKER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("opengl:nvidia_anti_flicker"); + const auto PMONITOR = g_pHyprOpenGL->m_RenderData.pMonitor; + static auto PNVIDIAANTIFLICKER = CConfigValue("opengl:nvidia_anti_flicker"); if (m_eRenderMode != RENDER_MODE_TO_BUFFER_READ_ONLY) g_pHyprOpenGL->end(); @@ -2528,7 +2529,7 @@ void CHyprRenderer::endRender() { if (m_eRenderMode == RENDER_MODE_FULL_FAKE) return; - if (isNvidia() && **PNVIDIAANTIFLICKER) + if (isNvidia() && *PNVIDIAANTIFLICKER) glFinish(); else glFlush(); diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 93a1c34c..ea40ee65 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -1,5 +1,6 @@ #include "CHyprBorderDecoration.hpp" #include "../../Compositor.hpp" +#include "../../config/ConfigValue.hpp" CHyprBorderDecoration::CHyprBorderDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { m_pWindow = pWindow; @@ -94,9 +95,9 @@ eDecorationLayer CHyprBorderDecoration::getDecorationLayer() { } uint64_t CHyprBorderDecoration::getDecorationFlags() { - static auto* const PPARTOFWINDOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:border_part_of_window"); + static auto PPARTOFWINDOW = CConfigValue("general:border_part_of_window"); - return **PPARTOFWINDOW && !doesntWantBorders() ? DECORATION_PART_OF_MAIN_WINDOW : 0; + return *PPARTOFWINDOW && !doesntWantBorders() ? DECORATION_PART_OF_MAIN_WINDOW : 0; } std::string CHyprBorderDecoration::getDisplayName() { diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 8541e06e..588b23a4 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -1,6 +1,7 @@ #include "CHyprDropShadowDecoration.hpp" #include "../../Compositor.hpp" +#include "../../config/ConfigValue.hpp" CHyprDropShadowDecoration::CHyprDropShadowDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { m_pWindow = pWindow; @@ -35,9 +36,9 @@ std::string CHyprDropShadowDecoration::getDisplayName() { } void CHyprDropShadowDecoration::damageEntire() { - static auto* const PSHADOWS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); + static auto PSHADOWS = CConfigValue("decoration:drop_shadow"); - if (**PSHADOWS != 1) + if (*PSHADOWS != 1) return; // disabled CBox dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, @@ -70,13 +71,13 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D if (m_pWindow->m_sAdditionalConfigData.forceNoShadow) return; - static auto* const PSHADOWS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); - static auto* const PSHADOWSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow_range"); - static auto* const PSHADOWIGNOREWINDOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow_ignore_window"); - static auto* const PSHADOWSCALE = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow_scale"); - static auto* const PSHADOWOFFSET = (Hyprlang::VEC2* const*)g_pConfigManager->getConfigValuePtr("decoration:shadow_offset"); + static auto PSHADOWS = CConfigValue("decoration:drop_shadow"); + static auto PSHADOWSIZE = CConfigValue("decoration:shadow_range"); + static auto PSHADOWIGNOREWINDOW = CConfigValue("decoration:shadow_ignore_window"); + static auto PSHADOWSCALE = CConfigValue("decoration:shadow_scale"); + static auto PSHADOWOFFSET = CConfigValue("decoration:shadow_offset"); - if (**PSHADOWS != 1) + if (*PSHADOWS != 1) return; // disabled const auto ROUNDINGBASE = m_pWindow->rounding(); @@ -87,15 +88,15 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D // draw the shadow CBox fullBox = m_bLastWindowBoxWithDecos; fullBox.translate(-pMonitor->vecPosition + WORKSPACEOFFSET); - fullBox.x -= **PSHADOWSIZE; - fullBox.y -= **PSHADOWSIZE; - fullBox.w += 2 * **PSHADOWSIZE; - fullBox.h += 2 * **PSHADOWSIZE; + fullBox.x -= *PSHADOWSIZE; + fullBox.y -= *PSHADOWSIZE; + fullBox.w += 2 * *PSHADOWSIZE; + fullBox.h += 2 * *PSHADOWSIZE; - const float SHADOWSCALE = std::clamp(**PSHADOWSCALE, 0.f, 1.f); + const float SHADOWSCALE = std::clamp(*PSHADOWSCALE, 0.f, 1.f); // scale the box in relation to the center of the box - fullBox.scaleFromCenter(SHADOWSCALE).translate(**PSHADOWOFFSET); + fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET); m_vLastWindowPos += WORKSPACEOFFSET; m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2}, @@ -116,7 +117,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D fullBox.scale(pMonitor->scale).round(); - if (**PSHADOWIGNOREWINDOW) { + if (*PSHADOWIGNOREWINDOW) { CBox windowBox = m_bLastWindowBox; CBox withDecos = m_bLastWindowBoxWithDecos; @@ -147,7 +148,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D g_pHyprOpenGL->renderRect(&fullBox, CColor(0, 0, 0, 1), 0); // render white shadow with the alpha of the shadow color (otherwise we clear with alpha later and shit it to 2 bit) - g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.value().a), a); + g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, CColor(1, 1, 1, m_pWindow->m_cRealShadowColor.value().a), a); // render black window box ("clip") g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), ROUNDING * pMonitor->scale); @@ -166,7 +167,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D g_pHyprOpenGL->m_RenderData.damage = saveDamage; } else { - g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, **PSHADOWSIZE * pMonitor->scale, m_pWindow->m_cRealShadowColor.value(), a); + g_pHyprOpenGL->renderRoundedShadow(&fullBox, ROUNDING * pMonitor->scale, *PSHADOWSIZE * pMonitor->scale, m_pWindow->m_cRealShadowColor.value(), a); } if (m_seExtents != m_seReportedExtents) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index ee0a5ce4..cd9f32be 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -1,5 +1,6 @@ #include "CHyprGroupBarDecoration.hpp" #include "../../Compositor.hpp" +#include "../../config/ConfigValue.hpp" #include #include @@ -15,31 +16,31 @@ constexpr int BAR_TEXT_PAD = 2; constexpr int BAR_HORIZONTAL_PADDING = 2; CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { - static auto* const PGRADIENTS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:enabled"); - static auto* const PENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:gradients"); - m_pWindow = pWindow; + static auto PGRADIENTS = CConfigValue("group:groupbar:enabled"); + static auto PENABLED = CConfigValue("group:groupbar:gradients"); + m_pWindow = pWindow; - if (m_tGradientActive.m_iTexID == 0 && **PENABLED && **PGRADIENTS) + if (m_tGradientActive.m_iTexID == 0 && *PENABLED && *PGRADIENTS) refreshGroupBarGradients(); } CHyprGroupBarDecoration::~CHyprGroupBarDecoration() {} SDecorationPositioningInfo CHyprGroupBarDecoration::getPositioningInfo() { - static auto* const PHEIGHT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:height"); - static auto* const PENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:enabled"); - static auto* const PRENDERTITLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles"); - static auto* const PGRADIENTS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:gradients"); - static auto* const PPRIORITY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:priority"); + static auto PHEIGHT = CConfigValue("group:groupbar:height"); + static auto PENABLED = CConfigValue("group:groupbar:enabled"); + static auto PRENDERTITLES = CConfigValue("group:groupbar:render_titles"); + static auto PGRADIENTS = CConfigValue("group:groupbar:gradients"); + static auto PPRIORITY = CConfigValue("group:groupbar:priority"); SDecorationPositioningInfo info; info.policy = DECORATION_POSITION_STICKY; info.edges = DECORATION_EDGE_TOP; - info.priority = **PPRIORITY; + info.priority = *PPRIORITY; info.reserved = true; - if (**PENABLED && m_pWindow->m_sSpecialRenderData.decorate) - info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (**PGRADIENTS || **PRENDERTITLES ? **PHEIGHT : 0) + 2}, {0, 0}}; + if (*PENABLED && m_pWindow->m_sSpecialRenderData.decorate) + info.desiredExtents = {{0, BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0) + 2}, {0, 0}}; else info.desiredExtents = {{0, 0}, {0, 0}}; @@ -87,22 +88,22 @@ void CHyprGroupBarDecoration::damageEntire() { void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) { // get how many bars we will draw - int barsToDraw = m_dwGroupMembers.size(); + int barsToDraw = m_dwGroupMembers.size(); - static auto* const PENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:enabled"); - static auto* const PRENDERTITLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles"); - static auto* const PTITLEFONTSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:font_size"); - static auto* const PHEIGHT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:height"); - static auto* const PGRADIENTS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:gradients"); + static auto PENABLED = CConfigValue("group:groupbar:enabled"); + static auto PRENDERTITLES = CConfigValue("group:groupbar:render_titles"); + static auto PTITLEFONTSIZE = CConfigValue("group:groupbar:font_size"); + static auto PHEIGHT = CConfigValue("group:groupbar:height"); + static auto PGRADIENTS = CConfigValue("group:groupbar:gradients"); - if (!**PENABLED || !m_pWindow->m_sSpecialRenderData.decorate) + if (!*PENABLED || !m_pWindow->m_sSpecialRenderData.decorate) return; const auto ASSIGNEDBOX = assignedBoxGlobal(); m_fBarWidth = (ASSIGNEDBOX.w - BAR_HORIZONTAL_PADDING * (barsToDraw - 1)) / barsToDraw; - const auto DESIREDHEIGHT = BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (**PGRADIENTS || **PRENDERTITLES ? **PHEIGHT : 0) + 2; + const auto DESIREDHEIGHT = BAR_PADDING_OUTER_VERT * 2 + BAR_INDICATOR_HEIGHT + (*PGRADIENTS || *PRENDERTITLES ? *PHEIGHT : 0) + 2; if (DESIREDHEIGHT != ASSIGNEDBOX.h) g_pDecorationPositioner->repositionDeco(this); @@ -117,20 +118,20 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& rect.scale(pMonitor->scale); - static auto* const PGROUPCOLACTIVE = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.active"); - static auto* const PGROUPCOLINACTIVE = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive"); - static auto* const PGROUPCOLACTIVELOCKED = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_active"); - static auto* const PGROUPCOLINACTIVELOCKED = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_inactive"); - auto* const GROUPCOLACTIVE = (CGradientValueData*)(*PGROUPCOLACTIVE)->getData(); - auto* const GROUPCOLINACTIVE = (CGradientValueData*)(*PGROUPCOLINACTIVE)->getData(); - auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(*PGROUPCOLACTIVELOCKED)->getData(); - auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(*PGROUPCOLINACTIVELOCKED)->getData(); + static auto PGROUPCOLACTIVE = CConfigValue("group:groupbar:col.active"); + static auto PGROUPCOLINACTIVE = CConfigValue("group:groupbar:col.inactive"); + static auto PGROUPCOLACTIVELOCKED = CConfigValue("group:groupbar:col.locked_active"); + static auto PGROUPCOLINACTIVELOCKED = CConfigValue("group:groupbar:col.locked_inactive"); + auto* const GROUPCOLACTIVE = (CGradientValueData*)(PGROUPCOLACTIVE.ptr())->getData(); + auto* const GROUPCOLINACTIVE = (CGradientValueData*)(PGROUPCOLINACTIVE.ptr())->getData(); + auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(PGROUPCOLACTIVELOCKED.ptr())->getData(); + auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(PGROUPCOLINACTIVELOCKED.ptr())->getData(); - const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked; - const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE; - const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE; + const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked; + const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE; + const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE; - CColor color = m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0]; + CColor color = m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? PCOLACTIVE->m_vColors[0] : PCOLINACTIVE->m_vColors[0]; color.a *= a; g_pHyprOpenGL->renderRect(&rect, color); @@ -145,17 +146,17 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& g_pHyprOpenGL->renderTexture(GRADIENTTEX, &rect, 1.0); } - if (**PRENDERTITLES) { + if (*PRENDERTITLES) { CTitleTex* pTitleTex = textureFromTitle(m_dwGroupMembers[i]->m_szTitle); if (!pTitleTex) pTitleTex = m_sTitleTexs.titleTexs .emplace_back(std::make_unique(m_dwGroupMembers[i], - Vector2D{m_fBarWidth * pMonitor->scale, (**PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale})) + Vector2D{m_fBarWidth * pMonitor->scale, (*PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale})) .get(); - rect.y += (ASSIGNEDBOX.h / 2.0 - (**PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) / 2.0) * pMonitor->scale; - rect.height = (**PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale; + rect.y += (ASSIGNEDBOX.h / 2.0 - (*PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) / 2.0) * pMonitor->scale; + rect.height = (*PTITLEFONTSIZE + 2 * BAR_TEXT_PAD) * pMonitor->scale; g_pHyprOpenGL->renderTexture(pTitleTex->tex, &rect, 1.f); } @@ -163,7 +164,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& xoff += BAR_HORIZONTAL_PADDING + m_fBarWidth; } - if (**PRENDERTITLES) + if (*PRENDERTITLES) invalidateTextures(); } @@ -181,17 +182,16 @@ void CHyprGroupBarDecoration::invalidateTextures() { } CTitleTex::CTitleTex(CWindow* pWindow, const Vector2D& bufferSize) { - szContent = pWindow->m_szTitle; - pWindowOwner = pWindow; - const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y); - const auto CAIRO = cairo_create(CAIROSURFACE); - const auto MONITORSCALE = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID)->scale; + szContent = pWindow->m_szTitle; + pWindowOwner = pWindow; + const auto CAIROSURFACE = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, bufferSize.x, bufferSize.y); + const auto CAIRO = cairo_create(CAIROSURFACE); - static auto* const PTITLEFONTFAMILY = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("group:groupbar:font_family"); - static auto* const PTITLEFONTSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:font_size"); - static auto* const PTEXTCOLOR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:text_color"); + static auto PTITLEFONTFAMILY = CConfigValue("group:groupbar:font_family"); + static auto PTITLEFONTSIZE = CConfigValue("group:groupbar:font_size"); + static auto PTEXTCOLOR = CConfigValue("group:groupbar:text_color"); - const CColor COLOR = CColor(**PTEXTCOLOR); + const CColor COLOR = CColor(*PTEXTCOLOR); // clear the pixmap cairo_save(CAIRO); @@ -203,8 +203,8 @@ CTitleTex::CTitleTex(CWindow* pWindow, const Vector2D& bufferSize) { PangoLayout* layout = pango_cairo_create_layout(CAIRO); pango_layout_set_text(layout, szContent.c_str(), -1); - PangoFontDescription* fontDesc = pango_font_description_from_string(*PTITLEFONTFAMILY); - pango_font_description_set_size(fontDesc, **PTITLEFONTSIZE * PANGO_SCALE); + PangoFontDescription* fontDesc = pango_font_description_from_string((*PTITLEFONTFAMILY).c_str()); + pango_font_description_set_size(fontDesc, *PTITLEFONTSIZE * PANGO_SCALE); pango_layout_set_font_description(layout, fontDesc); pango_font_description_free(fontDesc); @@ -301,17 +301,17 @@ void renderGradientTo(CTexture& tex, CGradientValueData* grad) { } void refreshGroupBarGradients() { - static auto* const PGRADIENTS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:enabled"); - static auto* const PENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:gradients"); + static auto PGRADIENTS = CConfigValue("group:groupbar:enabled"); + static auto PENABLED = CConfigValue("group:groupbar:gradients"); - static auto* const PGROUPCOLACTIVE = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.active"); - static auto* const PGROUPCOLINACTIVE = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive"); - static auto* const PGROUPCOLACTIVELOCKED = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_active"); - static auto* const PGROUPCOLINACTIVELOCKED = (Hyprlang::CUSTOMTYPE* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_inactive"); - auto* const GROUPCOLACTIVE = (CGradientValueData*)(*PGROUPCOLACTIVE)->getData(); - auto* const GROUPCOLINACTIVE = (CGradientValueData*)(*PGROUPCOLINACTIVE)->getData(); - auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(*PGROUPCOLACTIVELOCKED)->getData(); - auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(*PGROUPCOLINACTIVELOCKED)->getData(); + static auto PGROUPCOLACTIVE = CConfigValue("group:groupbar:col.active"); + static auto PGROUPCOLINACTIVE = CConfigValue("group:groupbar:col.inactive"); + static auto PGROUPCOLACTIVELOCKED = CConfigValue("group:groupbar:col.locked_active"); + static auto PGROUPCOLINACTIVELOCKED = CConfigValue("group:groupbar:col.locked_inactive"); + auto* const GROUPCOLACTIVE = (CGradientValueData*)(PGROUPCOLACTIVE.ptr())->getData(); + auto* const GROUPCOLINACTIVE = (CGradientValueData*)(PGROUPCOLINACTIVE.ptr())->getData(); + auto* const GROUPCOLACTIVELOCKED = (CGradientValueData*)(PGROUPCOLACTIVELOCKED.ptr())->getData(); + auto* const GROUPCOLINACTIVELOCKED = (CGradientValueData*)(PGROUPCOLINACTIVELOCKED.ptr())->getData(); g_pHyprRenderer->makeEGLCurrent(); @@ -322,7 +322,7 @@ void refreshGroupBarGradients() { m_tGradientLockedInactive.destroyTexture(); } - if (!**PENABLED || !**PGRADIENTS) + if (!*PENABLED || !*PGRADIENTS) return; renderGradientTo(m_tGradientActive, GROUPCOLACTIVE); @@ -460,9 +460,9 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point } bool CHyprGroupBarDecoration::onScrollOnDeco(const Vector2D& pos, wlr_pointer_axis_event* e) { - static auto* const PGROUPBARSCROLLING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:scrolling"); + static auto PGROUPBARSCROLLING = CConfigValue("group:groupbar:scrolling"); - if (!**PGROUPBARSCROLLING || !m_pWindow->m_sGroupData.pNextWindow) + if (!*PGROUPBARSCROLLING || !m_pWindow->m_sGroupData.pNextWindow) return false; if (e->delta > 0) From 9d89b7109da9b58904caf7c53a7af4b6daed1696 Mon Sep 17 00:00:00 2001 From: Isaiah Hamilton Date: Sun, 3 Mar 2024 18:00:28 -0500 Subject: [PATCH 0044/2897] config: update per device input configs link (#4951) --- src/config/defaultConfig.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 6d1d9751..33cdd0eb 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -123,7 +123,7 @@ misc { } # Example per-device config -# See https://wiki.hyprland.org/Configuring/Keywords/#executing for more +# See https://wiki.hyprland.org/Configuring/Keywords/#per-device-input-configs for more device { name = epic-mouse-v1 sensitivity = -0.5 From 12da0fc84f8b084f7b13702b811cbed7dae9854c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 4 Mar 2024 10:36:32 +0000 Subject: [PATCH 0045/2897] hyprctl: parse custom types in getoption --- src/config/ConfigDataValues.hpp | 15 +++++++++++++++ src/debug/HyprCtl.cpp | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index accc92ab..39c60a5a 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -14,6 +14,8 @@ class ICustomConfigValueData { virtual ~ICustomConfigValueData() = 0; virtual eConfigValueDataTypes getDataType() = 0; + + virtual std::string toString() = 0; }; class CGradientValueData : public ICustomConfigValueData { @@ -51,6 +53,15 @@ class CGradientValueData : public ICustomConfigValueData { return true; } + + virtual std::string toString() { + std::string result; + for (auto& c : m_vColors) { + result += std::format("{:x} ", c.getAsHex()); + } + + result += std::format("{}deg", (int)(m_fAngle * 180.0 / M_PI)); + } }; class CCssGapData : public ICustomConfigValueData { @@ -103,4 +114,8 @@ class CCssGapData : public ICustomConfigValueData { virtual eConfigValueDataTypes getDataType() { return CVD_TYPE_CSS_VALUE; } + + virtual std::string toString() { + return std::format("{} {} {} {}", top, right, bottom, left); + } }; diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index acc399b6..f2e4869a 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1225,8 +1225,8 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) return std::format("vec2: [{}, {}]\nset: {}", std::any_cast(VAL).x, std::any_cast(VAL).y, VAR->m_bSetByUser); else if (TYPE == typeid(Hyprlang::STRING)) return std::format("str: {}\nset: {}", std::any_cast(VAL), VAR->m_bSetByUser); - else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) - return std::format("custom type at: {:x}\nset: {}", (uintptr_t)std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(void*)) + return std::format("custom type: {}\nset: {}", ((ICustomConfigValueData*)std::any_cast(VAL))->toString(), VAR->m_bSetByUser); } else { if (TYPE == typeid(Hyprlang::INT)) return std::format("{{\"option\": \"{}\", \"int\": {}, \"set\": {} }}", curitem, std::any_cast(VAL), VAR->m_bSetByUser); @@ -1237,8 +1237,9 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) VAR->m_bSetByUser); else if (TYPE == typeid(Hyprlang::STRING)) return std::format("{{\"option\": \"{}\", \"str\": \"{}\", \"set\": {} }}", curitem, escapeJSONStrings(std::any_cast(VAL)), VAR->m_bSetByUser); - else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) - return std::format("{{\"option\": \"{}\", \"custom\": \"{:x}\", \"set\": {} }}", curitem, (uintptr_t)std::any_cast(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(void*)) + return std::format("{{\"option\": \"{}\", \"custom\": \"{}\", \"set\": {} }}", curitem, ((ICustomConfigValueData*)std::any_cast(VAL))->toString(), + VAR->m_bSetByUser); } return "invalid type (internal error)"; From 07c7235b7245375802c767472d62b776458c221d Mon Sep 17 00:00:00 2001 From: Tom Benham <38216488+tomben13@users.noreply.github.com> Date: Mon, 4 Mar 2024 18:05:20 +0100 Subject: [PATCH 0046/2897] keybinds: Better handling of workspace_back_and_forth (#4952) * Removed redundant boolean condition * Better handling of workspace_back_and_forth when using focusworkspaceoncurrentmonitor dispatcher * Fixed config acquisition --------- Co-authored-by: Tom Benham --- src/Compositor.cpp | 5 ++++- src/managers/KeybindManager.cpp | 35 ++++++++++++++++++++++----------- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index bb80f3ef..1f7f6182 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2042,6 +2042,9 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) pMonitorA->activeWorkspace = PWORKSPACEB->m_iID; pMonitorB->activeWorkspace = PWORKSPACEA->m_iID; + PWORKSPACEA->rememberPrevWorkspace(PWORKSPACEB); + PWORKSPACEB->rememberPrevWorkspace(PWORKSPACEA); + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorA->ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitorB->ID); @@ -2150,7 +2153,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni // fix old mon int nextWorkspaceOnMonitorID = -1; - if (!SWITCHINGISACTIVE || !POLDMON) + if (!SWITCHINGISACTIVE) nextWorkspaceOnMonitorID = pWorkspace->m_iID; else { for (auto& w : m_vWorkspaces) { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 9e12750b..47a4b119 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1546,9 +1546,9 @@ void CKeybindManager::moveWorkspaceToMonitor(std::string args) { void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { std::string workspaceName; - const int WORKSPACEID = getWorkspaceIDFromString(args, workspaceName); + int workspaceID = getWorkspaceIDFromString(args, workspaceName); - if (WORKSPACEID == WORKSPACE_INVALID) { + if (workspaceID == WORKSPACE_INVALID) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor invalid workspace!"); return; } @@ -1560,30 +1560,43 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { return; } - auto PWORKSPACE = g_pCompositor->getWorkspaceByID(WORKSPACEID); + auto pWorkspace = g_pCompositor->getWorkspaceByID(workspaceID); - if (!PWORKSPACE) { - PWORKSPACE = g_pCompositor->createNewWorkspace(WORKSPACEID, PCURRMONITOR->ID); + if (!pWorkspace) { + pWorkspace = g_pCompositor->createNewWorkspace(workspaceID, PCURRMONITOR->ID); // we can skip the moving, since it's already on the current monitor - changeworkspace(PWORKSPACE->getConfigName()); + changeworkspace(pWorkspace->getConfigName()); return; } - if (PWORKSPACE->m_iMonitorID != PCURRMONITOR->ID) { - const auto POLDMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); + static auto PBACKANDFORTH = CConfigValue("binds:workspace_back_and_forth"); + + if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspace == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) { + const int PREVWORKSPACEID = pWorkspace->m_sPrevWorkspace.iID; + const auto PREVWORKSPACENAME = pWorkspace->m_sPrevWorkspace.name; + // Workspace to focus is previous workspace + pWorkspace = g_pCompositor->getWorkspaceByID(PREVWORKSPACEID); + if (!pWorkspace) + pWorkspace = g_pCompositor->createNewWorkspace(PREVWORKSPACEID, PCURRMONITOR->ID, PREVWORKSPACENAME); + + workspaceID = pWorkspace->m_iID; + } + + if (pWorkspace->m_iMonitorID != PCURRMONITOR->ID) { + const auto POLDMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!POLDMONITOR) { // wat Debug::log(ERR, "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!"); return; } - if (POLDMONITOR->activeWorkspace == WORKSPACEID) { + if (POLDMONITOR->activeWorkspace == workspaceID) { g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR); return; } else { - g_pCompositor->moveWorkspaceToMonitor(PWORKSPACE, PCURRMONITOR, true); + g_pCompositor->moveWorkspaceToMonitor(pWorkspace, PCURRMONITOR, true); } } - changeworkspace(PWORKSPACE->getConfigName()); + changeworkspace(pWorkspace->getConfigName()); } void CKeybindManager::toggleSpecialWorkspace(std::string args) { From f3c92e75c8746901898b59abf2a1412bb16cbb54 Mon Sep 17 00:00:00 2001 From: musjj <72612857+musjj@users.noreply.github.com> Date: Tue, 5 Mar 2024 01:33:42 +0700 Subject: [PATCH 0047/2897] CI/Nix: attempt to fix broken cache (#4963) DeterminateSystems/nix-installer-action is causing hash inconsistency between CI & local build. --- .github/workflows/nix-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nix-build.yml b/.github/workflows/nix-build.yml index 2c05d5e2..bb6d90ad 100644 --- a/.github/workflows/nix-build.yml +++ b/.github/workflows/nix-build.yml @@ -19,7 +19,7 @@ jobs: with: ref: ${{ github.ref }} - - uses: DeterminateSystems/nix-installer-action@main + - uses: cachix/install-nix-action@v25 - uses: DeterminateSystems/magic-nix-cache-action@main - uses: cachix/cachix-action@v12 with: From 7a76ab01d16cdeb3bbb11449476d2b8ad84a3fda Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 4 Mar 2024 23:07:16 +0000 Subject: [PATCH 0048/2897] input: send motion to confined cursors --- src/managers/input/InputManager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index d8013d75..b988df5e 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -155,6 +155,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { const auto CLOSESTLOCAL = CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{}); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, CLOSEST.x, CLOSEST.y); + wlr_seat_pointer_send_motion(g_pCompositor->m_sSeat.seat, time, CLOSESTLOCAL.x, CLOSESTLOCAL.y); } return; From 9c48c322d49ba083ae474bc9131470d89cdce6fd Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 4 Mar 2024 15:29:45 -0800 Subject: [PATCH 0049/2897] keybinds: Allow fullscreen/maximize in special workspace (#4921) * allow fullscreen/maximize in special workspace * remove duplicate code * hide top layer * fix special fullscreen deco * edit * fix fade top layer when toggle special * remove double render --- src/Compositor.cpp | 2 +- src/helpers/Monitor.cpp | 8 ++++++++ src/layout/DwindleLayout.cpp | 7 ++++--- src/layout/MasterLayout.cpp | 4 ++-- src/managers/KeybindManager.cpp | 3 --- src/render/Renderer.cpp | 11 +++++++++-- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 1f7f6182..69643d10 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2281,7 +2281,7 @@ void CCompositor::updateFullscreenFadeOnWorkspace(CWorkspace* pWorkspace) { const auto PMONITOR = getMonitorFromID(pWorkspace->m_iMonitorID); - if (pWorkspace->m_iID == PMONITOR->activeWorkspace) { + if (pWorkspace->m_iID == PMONITOR->activeWorkspace || pWorkspace->m_iID == PMONITOR->specialWorkspaceID) { for (auto& ls : PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { if (!ls->fadingOut) ls->alpha = FULLSCREEN && pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL ? 0.f : 1.f; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 12857969..7e9bc82a 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -628,6 +628,10 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { else g_pInputManager->refocus(); + g_pCompositor->updateFullscreenFadeOnWorkspace(PWORKSPACE); + + g_pConfigManager->ensureVRR(this); + g_pCompositor->updateSuspendedStates(); return; @@ -688,6 +692,10 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { g_pHyprRenderer->damageMonitor(this); + g_pCompositor->updateFullscreenFadeOnWorkspace(pWorkspace); + + g_pConfigManager->ensureVRR(this); + g_pCompositor->updateSuspendedStates(); } diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 56539848..02a3dfbe 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -216,7 +216,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) { + if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { // if special, we adjust the coords a bit static auto PSCALEFACTOR = CConfigValue("dwindle:special_scale_factor"); @@ -792,7 +792,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree if (!g_pCompositor->windowValidMapped(pWindow)) return; - if (on == pWindow->m_bIsFullscreen || g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) + if (on == pWindow->m_bIsFullscreen) return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); @@ -854,8 +854,9 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree fakeNode.workspaceID = pWindow->m_iWorkspaceID; pWindow->m_vPosition = fakeNode.box.pos(); pWindow->m_vSize = fakeNode.box.size(); + fakeNode.ignoreFullscreenChecks = true; - applyNodeDataToWindow(&fakeNode, true); + applyNodeDataToWindow(&fakeNode); } } diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index a828399a..c7e09186 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -688,7 +688,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) { + if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { static auto PSCALEFACTOR = CConfigValue("master:special_scale_factor"); CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR}; @@ -871,7 +871,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen if (!g_pCompositor->windowValidMapped(pWindow)) return; - if (on == pWindow->m_bIsFullscreen || g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) + if (on == pWindow->m_bIsFullscreen) return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 47a4b119..d1b72e53 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -988,9 +988,6 @@ void CKeybindManager::fullscreenActive(std::string args) { if (!PWINDOW) return; - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) - return; - PWINDOW->m_bDontSendFullscreen = false; if (args == "2") PWINDOW->m_bDontSendFullscreen = true; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 303491d1..4e76a972 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -295,6 +295,9 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (!w->m_bIsFullscreen) continue; + if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + continue; + renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL); if (w->m_iWorkspaceID != pWorkspace->m_iID) @@ -759,8 +762,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* // special for (auto& ws : g_pCompositor->m_vWorkspaces) { - if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) - renderWorkspaceWindows(pMonitor, ws.get(), time); + if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { + if (ws->m_bHasFullscreenWindow) + renderWorkspaceWindowsFullscreen(pMonitor, ws.get(), time); + else + renderWorkspaceWindows(pMonitor, ws.get(), time); + } } // pinned always above From 12985fa0d8e43b1e33326dfb49be681970dfaea5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 5 Mar 2024 00:21:37 +0000 Subject: [PATCH 0050/2897] surface: fix damage tearing feedback fixes #4935 --- src/desktop/Subsurface.cpp | 18 ------------------ src/events/Windows.cpp | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index d9aa3d6d..bdf5aa35 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -145,24 +145,6 @@ void CSubsurface::onCommit() { box = {COORDS, m_vLastSize}; g_pHyprRenderer->damageBox(&box); } - - if (m_pWindowParent) { - // tearing: if solitary, redraw it. This still might be a single surface window - const auto PMONITOR = g_pCompositor->getMonitorFromID(m_pWindowParent->m_iMonitorID); - if (PMONITOR && PMONITOR->solitaryClient == m_pWindowParent && m_pWindowParent->canBeTorn() && PMONITOR->tearingState.canTear && - m_sWLSurface.wlr()->current.committed & WLR_SURFACE_STATE_BUFFER) { - CRegion damageBox{&m_sWLSurface.wlr()->buffer_damage}; - - if (!damageBox.empty()) { - if (PMONITOR->tearingState.busy) { - PMONITOR->tearingState.frameScheduledWhileBusy = true; - } else { - PMONITOR->tearingState.nextRenderTorn = true; - g_pHyprRenderer->renderMonitor(PMONITOR); - } - } - } - } } void CSubsurface::onDestroy() { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 3517badc..0bf84f10 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -841,6 +841,22 @@ void Events::listener_commitWindow(void* owner, void* data) { PWINDOW->m_pPopupHead->recheckTree(); } + // tearing: if solitary, redraw it. This still might be a single surface window + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + if (PMONITOR && PMONITOR->solitaryClient == PWINDOW && PWINDOW->canBeTorn() && PMONITOR->tearingState.canTear && + PWINDOW->m_pWLSurface.wlr()->current.committed & WLR_SURFACE_STATE_BUFFER) { + CRegion damageBox{&PWINDOW->m_pWLSurface.wlr()->buffer_damage}; + + if (!damageBox.empty()) { + if (PMONITOR->tearingState.busy) { + PMONITOR->tearingState.frameScheduledWhileBusy = true; + } else { + PMONITOR->tearingState.nextRenderTorn = true; + g_pHyprRenderer->renderMonitor(PMONITOR); + } + } + } + if (PWINDOW->m_bIsX11 || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) return; From 08152477dca873fec395d08cf30d27f961556f6e Mon Sep 17 00:00:00 2001 From: Junxuan Liao <70618504+MikeWalrus@users.noreply.github.com> Date: Tue, 5 Mar 2024 21:41:51 +0800 Subject: [PATCH 0051/2897] monitor: remove commas from short description (#4970) Since `hyprctl monitor` shows szShortDescription now, it needs to be sanitized. (See #2457) Also, monitor selectors are now compared against szShortDescription and szDescription to avoid re-striping the string. --- src/helpers/Monitor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 7e9bc82a..7b694d48 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -56,11 +56,12 @@ void CMonitor::onConnect(bool noRule) { szDescription = output->description ? output->description : ""; // remove comma character from description. This allow monitor specific rules to work on monitor with comma on their description - szDescription.erase(std::remove(szDescription.begin(), szDescription.end(), ','), szDescription.end()); + std::erase(szDescription, ','); // field is backwards-compatible with intended usage of `szDescription` but excludes the parenthesized DRM node name suffix szShortDescription = removeBeginEndSpacesTabs(std::format("{} {} {}", output->make ? output->make : "", output->model ? output->model : "", output->serial ? output->serial : "")); + std::erase(szShortDescription, ','); if (!wlr_backend_is_drm(output->backend)) createdByUser = true; // should be true. WL, X11 and Headless backends should be addable / removable @@ -363,9 +364,8 @@ bool CMonitor::matchesStaticSelector(const std::string& selector) const { if (selector.starts_with("desc:")) { // match by description const auto DESCRIPTIONSELECTOR = selector.substr(5); - const auto DESCRIPTION = removeBeginEndSpacesTabs(szDescription.substr(0, szDescription.find_first_of('('))); - return DESCRIPTIONSELECTOR == szDescription || DESCRIPTIONSELECTOR == DESCRIPTION; + return DESCRIPTIONSELECTOR == szShortDescription || DESCRIPTIONSELECTOR == szDescription; } else { // match by selector return szName == selector; From bdfa8ab856b889f92240684680cb3fdbdc41fb3d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 5 Mar 2024 13:55:33 +0000 Subject: [PATCH 0052/2897] hyprctl: print format and modes fixes #4971 --- src/debug/HyprCtl.cpp | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index f2e4869a..10302b08 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -31,6 +31,38 @@ static std::string getWorkspaceNameFromSpecialID(const int workspaceID) { return workspace->m_szName; } +static std::string formatToString(uint32_t drmFormat) { + switch (drmFormat) { + case DRM_FORMAT_XRGB2101010: return "XRGB2101010"; + case DRM_FORMAT_XBGR2101010: return "XBGR2101010"; + case DRM_FORMAT_XRGB8888: return "XRGB8888"; + case DRM_FORMAT_XBGR8888: return "XBGR8888"; + default: break; + } + + return "Invalid"; +} + +static std::string availableModesForOutput(CMonitor* pMonitor, eHyprCtlOutputFormat format) { + std::string result; + + if (!wl_list_empty(&pMonitor->output->modes)) { + wlr_output_mode* mode; + + wl_list_for_each(mode, &pMonitor->output->modes, link) { + + if (format == FORMAT_NORMAL) + result += std::format("{}x{}@{:.2f}Hz ", mode->width, mode->height, mode->refresh / 1000.0); + else + result += std::format("\"{}x{}@{:.2f}Hz\",", mode->width, mode->height, mode->refresh / 1000.0); + } + + result.pop_back(); + } + + return result; +} + std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { CVarList vars(request, 0, ' '); auto allMonitors = false; @@ -76,7 +108,9 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { "focused": {}, "dpmsStatus": {}, "vrr": {}, - "activelyTearing": {} + "activelyTearing": {}, + "currentFormat": "{}", + "availableModes": [{}] }},)#", m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szShortDescription), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, @@ -84,7 +118,7 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), - m->tearingState.activelyTearing ? "true" : "false"); + m->tearingState.activelyTearing ? "true" : "false", formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); } trimTrailingComma(result); @@ -99,13 +133,14 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { std::format("Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial " "workspace: {} ({})\n\treserved: {} " "{} {} {}\n\tscale: {:.2f}\n\ttransform: " - "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\n", + "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\tcurrentFormat: {}\n\tavailableModes: {}\n\n", m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->szShortDescription, (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), m->activeWorkspace, (m->activeWorkspace == -1 ? "" : g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName), m->specialWorkspaceID, getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, - (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing); + (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing, formatToString(m->drmFormat), + availableModesForOutput(m.get(), format)); } } From f8a081b56d09ec325ac485a0f055e541146486d3 Mon Sep 17 00:00:00 2001 From: Junxuan Liao <70618504+MikeWalrus@users.noreply.github.com> Date: Wed, 6 Mar 2024 01:56:06 +0800 Subject: [PATCH 0053/2897] layout: warp the cursor when focusing windows (#4982) Similar to the `focuswindow` dispatcher, when focusing a window with wlr-foreign-toplevel-management, the cursor should be warped. Otherwise, the focus is lost immediately after the cursor moves. --- src/layout/IHyprLayout.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index d48f15fa..2a84b024 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -593,6 +593,7 @@ void IHyprLayout::bringWindowToTop(CWindow* pWindow) { void IHyprLayout::requestFocusForWindow(CWindow* pWindow) { bringWindowToTop(pWindow); g_pCompositor->focusWindow(pWindow); + g_pCompositor->warpCursorTo(pWindow->middle()); } Vector2D IHyprLayout::predictSizeForNewWindow() { From 0ee69058c447b91bd142523676b13c5af8685ba8 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Tue, 5 Mar 2024 14:18:53 -0500 Subject: [PATCH 0054/2897] config: Add input:scroll_factor configuration (#4980) * Allow for input:scroll_factor configuration This PR will allow for a `scroll_factor` configuration within an `input` block. The purpose is to control the scroll factor of external mice. Closes #2574. * clang-format --- src/config/ConfigManager.cpp | 1 + src/managers/input/InputManager.cpp | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7c957510..08b2e3c1 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -455,6 +455,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("input:scroll_method", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:scroll_button", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:scroll_button_lock", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:scroll_factor", {1.f}); m_pConfig->addConfigValue("input:scroll_points", {STRVAL_EMPTY}); m_pConfig->addConfigValue("input:touchpad:natural_scroll", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:touchpad:disable_while_typing", Hyprlang::INT{1}); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index b988df5e..f5ae1638 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -666,9 +666,10 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { } void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { - static auto PSCROLLFACTOR = CConfigValue("input:touchpad:scroll_factor"); + static auto PINPUTSCROLLFACTOR = CConfigValue("input:scroll_factor"); + static auto PTOUCHPADSCROLLFACTOR = CConfigValue("input:touchpad:scroll_factor"); - auto factor = (*PSCROLLFACTOR <= 0.f || e->source != WLR_AXIS_SOURCE_FINGER ? 1.f : *PSCROLLFACTOR); + auto factor = (*PTOUCHPADSCROLLFACTOR <= 0.f || e->source == WLR_AXIS_SOURCE_FINGER ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR); const auto EMAP = std::unordered_map{{"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); From a4c1f4a03d7304f4b7935d4e163fd5df62a3121c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 5 Mar 2024 20:42:22 +0000 Subject: [PATCH 0055/2897] popup: send scale on map fixes #4972 --- src/desktop/Popup.cpp | 10 ++++++++++ src/desktop/Popup.hpp | 1 + 2 files changed, 11 insertions(+) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 92f0e312..29594e47 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -116,6 +116,7 @@ void CPopup::onMap() { m_pSubsurfaceHead = std::make_unique(this); unconstrain(); + sendScale(); } void CPopup::onUnmap() { @@ -234,3 +235,12 @@ void CPopup::recheckChildrenRecursive() { Vector2D CPopup::size() { return m_vLastSize; } + +void CPopup::sendScale() { + if (m_pWindowOwner) + g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pWindowOwner->m_pWLSurface.m_fLastScale); + else if (m_pLayerOwner) + g_pCompositor->setPreferredScaleForSurface(m_sWLSurface.wlr(), m_pLayerOwner->surface.m_fLastScale); + else + UNREACHABLE(); +} diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index 48dae088..0ac460d1 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -65,6 +65,7 @@ class CPopup { void initAllSignals(); void unconstrain(); void recheckChildrenRecursive(); + void sendScale(); Vector2D localToGlobal(const Vector2D& rel); Vector2D t1ParentCoords(); From 31e1287da26c7389d1c65f05fe40e647a3ad2689 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 5 Mar 2024 20:45:23 +0000 Subject: [PATCH 0056/2897] subsurface: don't update transform on unmap fixes #4969 --- src/desktop/Subsurface.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index bdf5aa35..0d76a147 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -191,9 +191,6 @@ void CSubsurface::onUnmap() { if (m_sWLSurface.wlr() == g_pCompositor->m_pLastFocus) g_pInputManager->releaseAllMouseButtons(); - if (m_pWindowParent) - m_pWindowParent->updateSurfaceScaleTransformDetails(); - g_pInputManager->simulateMouseMovement(); // TODO: should this remove children? Currently it won't, only on .destroy From 05dd204c5feddd18084a4ae5e4747579b0728a23 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 5 Mar 2024 20:46:08 +0000 Subject: [PATCH 0057/2897] window: ignore surface updates in unsafe / on invalid monitors --- src/Window.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Window.cpp b/src/Window.cpp index 6444aced..41562291 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -336,7 +336,7 @@ void sendLeaveIter(wlr_surface* pSurface, int x, int y, void* data) { } void CWindow::updateSurfaceScaleTransformDetails() { - if (!m_bIsMapped || m_bHidden) + if (!m_bIsMapped || m_bHidden || g_pCompositor->m_bUnsafeState) return; const auto PLASTMONITOR = g_pCompositor->getMonitorFromID(m_iLastSurfaceMonitorID); @@ -345,6 +345,9 @@ void CWindow::updateSurfaceScaleTransformDetails() { const auto PNEWMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); + if (!PNEWMONITOR) + return; + if (PNEWMONITOR != PLASTMONITOR) { if (PLASTMONITOR && PLASTMONITOR->m_bEnabled) wlr_surface_for_each_surface(m_pWLSurface.wlr(), sendLeaveIter, PLASTMONITOR->output); From b1e2ca04a016b1ea24344d3cfb2eb3370863eb5e Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Tue, 5 Mar 2024 17:51:34 -0500 Subject: [PATCH 0058/2897] CrashReporter: Fix compilation with musl libc (#4805) It can be assumed this doesn't function correctly: my 'configuration does not support execinfo.h', so I have no backtrace to test against --- src/debug/CrashReporter.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/debug/CrashReporter.cpp b/src/debug/CrashReporter.cpp index cf648191..a4bdc761 100644 --- a/src/debug/CrashReporter.cpp +++ b/src/debug/CrashReporter.cpp @@ -108,18 +108,23 @@ void CrashReporter::createAndSaveCrash(int sig) { std::string addrs = ""; for (size_t i = 0; i < CALLSTACK.size(); ++i) { +#ifdef __GLIBC__ // convert in memory address to VMA address Dl_info info; struct link_map* linkMap; dladdr1((void*)CALLSTACK[i].adr, &info, (void**)&linkMap, RTLD_DL_LINKMAP); size_t vmaAddr = (size_t)CALLSTACK[i].adr - linkMap->l_addr; +#else + // musl doesn't define dladdr1 + size_t vmaAddr = (size_t)CALLSTACK[i].adr; +#endif addrs += std::format("0x{:x} ", vmaAddr); } #ifdef __clang__ const auto CMD = std::format("llvm-addr2line -e {} -Cf {}", FPATH.c_str(), addrs); #else - const auto CMD = std::format("addr2line -e {} -Cf {}", FPATH.c_str(), addrs); + const auto CMD = std::format("addr2line -e {} -Cf {}", FPATH.c_str(), addrs); #endif const auto ADDR2LINE = execAndGet(CMD.c_str()); From fb87e332c59ce386a095b3e81bb1abbcc9cc3e5c Mon Sep 17 00:00:00 2001 From: bvr-yr <130279855+bvr-yr@users.noreply.github.com> Date: Wed, 6 Mar 2024 03:15:44 +0300 Subject: [PATCH 0059/2897] input: fix window move stutter by introducing additional checks for low-hz monitors (#4553) * resize-limiter: add additional check for low-hz monitors * simplify checker * add comment * rename variable --- src/layout/IHyprLayout.cpp | 30 +++++++++++++++++++++++++----- src/layout/IHyprLayout.hpp | 1 + 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 2a84b024..26a30ecf 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -173,7 +173,8 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { void IHyprLayout::onBeginDragWindow() { const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow; - m_vBeginDragSizeXY = Vector2D(); + m_iMouseMoveEventCount = 1; + m_vBeginDragSizeXY = Vector2D(); // Window will be floating. Let's check if it's valid. It should be, but I don't like crashing. if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) { @@ -248,6 +249,8 @@ void IHyprLayout::onBeginDragWindow() { void IHyprLayout::onEndDragWindow() { const auto DRAGGINGWINDOW = g_pInputManager->currentlyDraggedWindow; + m_iMouseMoveEventCount = 1; + if (!g_pCompositor->windowValidMapped(DRAGGINGWINDOW)) { if (DRAGGINGWINDOW) { g_pInputManager->unsetCursorImage(); @@ -303,7 +306,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { return; } - static auto TIMER = std::chrono::high_resolution_clock::now(); + static auto TIMER = std::chrono::high_resolution_clock::now(), MSTIMER = TIMER; const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID); @@ -313,9 +316,26 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { static auto PANIMATEMOUSE = CConfigValue("misc:animate_mouse_windowdragging"); static auto PANIMATE = CConfigValue("misc:animate_manual_resizes"); - if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || - (std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - TIMER).count() < - 1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate)) + const auto TIMERDELTA = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - TIMER).count(); + const auto MSDELTA = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - MSTIMER).count(); + const auto MSMONITOR = 1000.0 / g_pHyprRenderer->m_pMostHzMonitor->refreshRate; + static int totalMs = 0; + bool canSkipUpdate = true; + + MSTIMER = std::chrono::high_resolution_clock::now(); + + if (m_iMouseMoveEventCount == 1) + totalMs = 0; + + if (MSMONITOR > 16.0) { + totalMs += MSDELTA < MSMONITOR ? MSDELTA : std::round(totalMs * 1.0 / m_iMouseMoveEventCount); + m_iMouseMoveEventCount += 1; + + // check if time-window is enough to skip update on 60hz monitor + canSkipUpdate = std::clamp(MSMONITOR - TIMERDELTA, 0.0, MSMONITOR) > totalMs * 1.0 / m_iMouseMoveEventCount; + } + + if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || (TIMERDELTA < MSMONITOR && canSkipUpdate)) return; TIMER = std::chrono::high_resolution_clock::now(); diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index ffe004bc..d3f8dfa6 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -188,6 +188,7 @@ class IHyprLayout { virtual Vector2D predictSizeForNewWindow(); private: + int m_iMouseMoveEventCount; Vector2D m_vBeginDragXY; Vector2D m_vLastDragXY; Vector2D m_vBeginDragPositionXY; From d6f1b151b2fe85ffbb131cbdd05acefc6a357e81 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 6 Mar 2024 02:14:13 -0800 Subject: [PATCH 0060/2897] animations: fix m_Goal not being set after #4911 (#4992) --- src/helpers/AnimatedVariable.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 6efb394b..005f2832 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -202,6 +202,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable { void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { create(pAnimConfig, pWindow, policy); m_Value = value; + m_Goal = value; } using CBaseAnimatedVariable::create; From 082bf002546cfa7aaa7c5b79b03a1b6dd95454af Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 6 Mar 2024 13:01:04 +0100 Subject: [PATCH 0061/2897] hyprpm: Add support for specifying exact git revisions for plugin repo (#4983) * hyprpm(feat): support specifying exact git revs * Mention git rev argument in help * Mention git rev arg is optional * Wrap text --- hyprpm/src/core/DataState.cpp | 5 ++++- hyprpm/src/core/Plugin.hpp | 1 + hyprpm/src/core/PluginManager.cpp | 26 ++++++++++++++++++++++---- hyprpm/src/core/PluginManager.hpp | 4 ++-- hyprpm/src/main.cpp | 10 ++++++++-- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/hyprpm/src/core/DataState.cpp b/hyprpm/src/core/DataState.cpp index a7f9a7ae..61ad336f 100644 --- a/hyprpm/src/core/DataState.cpp +++ b/hyprpm/src/core/DataState.cpp @@ -45,7 +45,8 @@ void DataState::addNewPluginRepo(const SPluginRepository& repo) { {"repository", toml::table{ {"name", repo.name}, {"hash", repo.hash}, - {"url", repo.url} + {"url", repo.url}, + {"rev", repo.rev} }} }; for (auto& p : repo.plugins) { @@ -178,12 +179,14 @@ std::vector DataState::getAllRepositories() { const auto NAME = STATE["repository"]["name"].value_or(""); const auto URL = STATE["repository"]["url"].value_or(""); + const auto REV = STATE["repository"]["rev"].value_or(""); const auto HASH = STATE["repository"]["hash"].value_or(""); SPluginRepository repo; repo.hash = HASH; repo.name = NAME; repo.url = URL; + repo.rev = REV; for (const auto& [key, val] : STATE) { if (key == "repository") diff --git a/hyprpm/src/core/Plugin.hpp b/hyprpm/src/core/Plugin.hpp index a69478d1..e66031c9 100644 --- a/hyprpm/src/core/Plugin.hpp +++ b/hyprpm/src/core/Plugin.hpp @@ -12,6 +12,7 @@ struct SPlugin { struct SPluginRepository { std::string url; + std::string rev; std::string name; std::vector plugins; std::string hash; diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 4b026090..725e6a93 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -77,8 +77,7 @@ SHyprlandVersion CPluginManager::getHyprlandVersion() { return ver; } -bool CPluginManager::addNewPluginRepo(const std::string& url) { - +bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& rev) { const auto HLVER = getHyprlandVersion(); if (DataState::pluginRepoExists(url)) { @@ -134,6 +133,14 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) { return false; } + if (!rev.empty()) { + std::string ret = execAndGet("git -C /tmp/hyprpm/new reset --hard --recurse-submodules " + rev); + if (ret.compare(0, 6, "fatal:") == 0) { + std::cerr << "\n" << Colors::RED << "✖" << Colors::RESET << " Could not check out revision " << rev << ". shell returned:\n" << ret << "\n"; + return false; + } + } + progress.m_iSteps = 1; progress.printMessageAbove(std::string{Colors::GREEN} + "✔" + Colors::RESET + " cloned"); progress.m_szCurrentMessage = "Reading the manifest"; @@ -240,6 +247,7 @@ bool CPluginManager::addNewPluginRepo(const std::string& url) { repohash.pop_back(); repo.name = pManifest->m_sRepository.name.empty() ? url.substr(url.find_last_of('/') + 1) : pManifest->m_sRepository.name; repo.url = url; + repo.rev = rev; repo.hash = repohash; for (auto& p : pManifest->m_vPlugins) { repo.plugins.push_back(SPlugin{p.name, "/tmp/hyprpm/new/" + p.output, false, p.failed}); @@ -494,6 +502,16 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { return false; } + if (!repo.rev.empty()) { + progress.printMessageAbove(std::string{Colors::RESET} + " → Plugin has revision set, resetting: " + repo.rev); + + std::string ret = execAndGet("git -C /tmp/hyprpm reset --hard --recurse-submodules " + repo.rev); + if (ret.compare(0, 6, "fatal:") == 0) { + std::cout << "\n" << std::string{Colors::RED} + "✖" + Colors::RESET + " could not check out revision " + repo.rev + ": shell returned:\n" + ret; + return false; + } + } + if (!update) { // check if git has updates std::string hash = execAndGet("cd /tmp/hyprpm/update && git rev-parse HEAD"); @@ -538,8 +556,8 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { continue; } - if (!pManifest->m_sRepository.commitPins.empty()) { - // check commit pins + if (repo.rev.empty() && !pManifest->m_sRepository.commitPins.empty()) { + // check commit pins unless a revision is specified progress.printMessageAbove(std::string{Colors::RESET} + " → Manifest has " + std::to_string(pManifest->m_sRepository.commitPins.size()) + " pins, checking"); diff --git a/hyprpm/src/core/PluginManager.hpp b/hyprpm/src/core/PluginManager.hpp index dedb2d43..028e6357 100644 --- a/hyprpm/src/core/PluginManager.hpp +++ b/hyprpm/src/core/PluginManager.hpp @@ -36,7 +36,7 @@ struct SHyprlandVersion { class CPluginManager { public: - bool addNewPluginRepo(const std::string& url); + bool addNewPluginRepo(const std::string& url, const std::string& rev); bool removePluginRepo(const std::string& urlOrName); eHeadersErrors headersValid(); @@ -60,4 +60,4 @@ class CPluginManager { std::string headerError(const eHeadersErrors err); }; -inline std::unique_ptr g_pPluginManager; \ No newline at end of file +inline std::unique_ptr g_pPluginManager; diff --git a/hyprpm/src/main.cpp b/hyprpm/src/main.cpp index 37972443..e40d336d 100644 --- a/hyprpm/src/main.cpp +++ b/hyprpm/src/main.cpp @@ -11,7 +11,8 @@ const std::string HELP = R"#(┏ hyprpm, a Hyprland Plugin Manager ┃ -┣ add [url] → Install a new plugin repository from git +┣ add [url] [git rev] → Install a new plugin repository from git. Git revision +┃ is optional, when set, commit locks are ignored. ┣ remove [url/name] → Remove an installed plugin repository ┣ enable [name] → Enable a plugin ┣ disable [name] → Disable a plugin @@ -77,7 +78,12 @@ int main(int argc, char** argv, char** envp) { return 1; } - return g_pPluginManager->addNewPluginRepo(command[1]) ? 0 : 1; + std::string rev = ""; + if (command.size() >= 3) { + rev = command[2]; + } + + return g_pPluginManager->addNewPluginRepo(command[1], rev) ? 0 : 1; } else if (command[0] == "remove") { if (ARGS.size() < 2) { std::cerr << Colors::RED << "✖" << Colors::RESET << " Not enough args for remove.\n"; From 669ea8a373f6d365c16ab40a82953f2e52faa765 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 6 Mar 2024 15:26:52 +0000 Subject: [PATCH 0062/2897] ci: pack hyprpm to the release tar --- .github/workflows/ci.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 01bb43d1..42dfcf9c 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -31,6 +31,7 @@ jobs: cp ./LICENSE hyprland/ cp build/Hyprland hyprland/ cp build/hyprctl/hyprctl hyprland/ + cp build/hyprpm/hyprpm hyprland/ cp subprojects/wlroots/build/libwlroots.so.13032 hyprland/ cp build/Hyprland hyprland/ cp -r example/ hyprland/ From 8e2a62e53bf51e8b4ae719d0e46797b0a26eeb22 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 6 Mar 2024 18:14:59 +0000 Subject: [PATCH 0063/2897] events: apply monitor state on sessionActive ref #4839 --- src/events/Misc.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index 35721832..0ee95ac3 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -169,6 +169,7 @@ void Events::listener_sessionActive(wl_listener* listener, void* data) { for (auto& m : g_pCompositor->m_vMonitors) { g_pCompositor->scheduleFrameForMonitor(m.get()); + g_pHyprRenderer->applyMonitorRule(m.get(), &m->activeMonitorRule, true); } g_pConfigManager->m_bWantsMonitorReload = true; From 067df84388be41b7b2352918060c2e9d88717740 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Wed, 6 Mar 2024 22:20:26 +0100 Subject: [PATCH 0064/2897] notify: Add custom fontsize support for notifications (#4981) * Add custom fontsize support for notifications * Remove debug stuff * Use original default font size * Handle fontsize as keyword arg * Use CVarList::join instead of for loop * Use size_t for msgidx --- src/debug/HyprCtl.cpp | 24 +++++++++++++++----- src/debug/HyprNotificationOverlay.cpp | 32 +++++++++++++-------------- src/debug/HyprNotificationOverlay.hpp | 7 +++--- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 10302b08..332e3969 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1455,17 +1455,29 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { time = std::stoi(TIME); } catch (std::exception& e) { return "invalid arg 2"; } - CColor color = configStringToInt(vars[3]); + CColor color = configStringToInt(vars[3]); - std::string message = ""; + size_t msgidx = 4; + float fontsize = 13.f; + if (vars[msgidx].length() > 9 && vars[msgidx].compare(0, 10, "fontsize:")) { + const auto FONTSIZE = vars[msgidx].substr(9); - for (size_t i = 4; i < vars.size(); ++i) { - message += vars[i] + " "; + if (!isNumber(FONTSIZE, true)) + return "invalid fontsize kwarg"; + + try { + fontsize = std::stoi(FONTSIZE); + } catch (std::exception& e) { return "invalid fontsize karg"; } + + ++msgidx; } - message.pop_back(); + if (vars.size() <= msgidx) + return "not enough args"; - g_pHyprNotificationOverlay->addNotification(message, color, time, (eIcons)icon); + const auto MESSAGE = vars.join(" ", msgidx); + + g_pHyprNotificationOverlay->addNotification(MESSAGE, color, time, (eIcons)icon, fontsize); return "ok"; } diff --git a/src/debug/HyprNotificationOverlay.cpp b/src/debug/HyprNotificationOverlay.cpp index 98c68f1f..ced27814 100644 --- a/src/debug/HyprNotificationOverlay.cpp +++ b/src/debug/HyprNotificationOverlay.cpp @@ -36,14 +36,15 @@ CHyprNotificationOverlay::CHyprNotificationOverlay() { m_szIconFontName = fonts.substr(COLON + 2, LASTCHAR - (COLON + 2)); } -void CHyprNotificationOverlay::addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon) { +void CHyprNotificationOverlay::addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon, const float fontSize) { const auto PNOTIF = m_dNotifications.emplace_back(std::make_unique()).get(); PNOTIF->text = text; PNOTIF->color = color == CColor(0) ? ICONS_COLORS[icon] : color; PNOTIF->started.reset(); - PNOTIF->timeMs = timeMs; - PNOTIF->icon = icon; + PNOTIF->timeMs = timeMs; + PNOTIF->icon = icon; + PNOTIF->fontSize = fontSize; for (auto& m : g_pCompositor->m_vMonitors) { g_pCompositor->scheduleFrameForMonitor(m.get()); @@ -73,28 +74,25 @@ CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { float offsetY = 10; float maxWidth = 0; - const auto SCALE = pMonitor->scale; - const auto FONTSIZE = std::clamp((int)(13.f * ((pMonitor->vecPixelSize.x * SCALE) / 1920.f)), 8, 40); + const auto SCALE = pMonitor->scale; const auto MONSIZE = pMonitor->vecPixelSize; cairo_text_extents_t cairoExtents; int iconW = 0, iconH = 0; - PangoLayout* pangoLayout; - PangoFontDescription* pangoFD; - - pangoLayout = pango_cairo_create_layout(m_pCairo); - pangoFD = pango_font_description_from_string(("Sans " + std::to_string(FONTSIZE * ICON_SCALE)).c_str()); - pango_layout_set_font_description(pangoLayout, pangoFD); - cairo_select_font_face(m_pCairo, "Sans", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL); - cairo_set_font_size(m_pCairo, FONTSIZE); const auto PBEZIER = g_pAnimationManager->getBezier("default"); for (auto& notif : m_dNotifications) { - const auto ICONPADFORNOTIF = notif->icon == ICON_NONE ? 0 : ICON_PAD; + const auto ICONPADFORNOTIF = notif->icon == ICON_NONE ? 0 : ICON_PAD; + const auto FONTSIZE = std::clamp((int)(notif->fontSize * ((pMonitor->vecPixelSize.x * SCALE) / 1920.f)), 8, 40); + + PangoLayout* pangoLayout = pango_cairo_create_layout(m_pCairo); + PangoFontDescription* pangoFD = pango_font_description_from_string(("Sans " + std::to_string(FONTSIZE * ICON_SCALE)).c_str()); + pango_layout_set_font_description(pangoLayout, pangoFD); + cairo_set_font_size(m_pCairo, FONTSIZE); // first rect (bg, col) const float FIRSTRECTANIMP = @@ -174,10 +172,10 @@ CBox CHyprNotificationOverlay::drawNotifications(CMonitor* pMonitor) { if (maxWidth < NOTIFSIZE.x) maxWidth = NOTIFSIZE.x; - } - pango_font_description_free(pangoFD); - g_object_unref(pangoLayout); + pango_font_description_free(pangoFD); + g_object_unref(pangoLayout); + } // cleanup notifs std::erase_if(m_dNotifications, [](const auto& notif) { return notif->started.getMillis() > notif->timeMs; }); diff --git a/src/debug/HyprNotificationOverlay.hpp b/src/debug/HyprNotificationOverlay.hpp index ef81b014..5599b71b 100644 --- a/src/debug/HyprNotificationOverlay.hpp +++ b/src/debug/HyprNotificationOverlay.hpp @@ -31,8 +31,9 @@ struct SNotification { std::string text = ""; CColor color; CTimer started; - float timeMs = 0; - eIcons icon = ICON_NONE; + float timeMs = 0; + eIcons icon = ICON_NONE; + float fontSize = 13.f; }; class CHyprNotificationOverlay { @@ -40,7 +41,7 @@ class CHyprNotificationOverlay { CHyprNotificationOverlay(); void draw(CMonitor* pMonitor); - void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE); + void addNotification(const std::string& text, const CColor& color, const float timeMs, const eIcons icon = ICON_NONE, const float fontSize = 13.f); void dismissNotifications(const int amount); bool hasAny(); From 95769a3c54448e8e65b1bb0c3d4e7ff3bb9edaba Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 6 Mar 2024 21:33:50 +0000 Subject: [PATCH 0065/2897] compositor: update state after moving to workspace fixes #4987 --- src/Compositor.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 69643d10..ca722ada 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2651,9 +2651,6 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); pWindow->moveToWorkspace(pWorkspace->m_iID); - pWindow->updateToplevel(); - pWindow->updateDynamicRules(); - pWindow->uncacheWindowDecos(); if (!pWindow->m_bIsFloating) { g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); @@ -2672,6 +2669,10 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks pWindow->m_vRealPosition = POSTOMON + PWORKSPACEMONITOR->vecPosition; } + pWindow->updateToplevel(); + pWindow->updateDynamicRules(); + pWindow->uncacheWindowDecos(); + if (pWindow->m_sGroupData.pNextWindow) { CWindow* next = pWindow->m_sGroupData.pNextWindow; while (next != pWindow) { From ce072638e9d86aac15c5ff4c6dd777b2894af422 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Thu, 7 Mar 2024 10:59:24 +0200 Subject: [PATCH 0066/2897] Nix: use propagatedBuildInputs instead of wrapping This way, users that want to wrap Hyprland themselves won't have the issues of double-wrapping. --- nix/default.nix | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index 6062a215..66ea53a6 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -93,6 +93,13 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov ++ lib.optionals enableXWayland [libxcb xcbutilwm xwayland] ++ lib.optionals withSystemd [systemd]; + # avoid wrapping + propagatedBuildInputs = [ + stdenv.cc + binutils + pciutils + ]; + mesonBuildType = if debug then "debug" @@ -132,14 +139,6 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov postInstall = '' ln -s ${wlroots}/include/wlr $dev/include/hyprland/wlroots - ${lib.optionalString wrapRuntimeDeps '' - wrapProgram $out/bin/Hyprland \ - --suffix PATH : ${lib.makeBinPath [ - stdenv.cc - binutils - pciutils - ]} - ''} ''; passthru.providedSessions = ["hyprland"]; From 77161fdbef72033ea1989e4c4d386a5732bd6bf0 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Thu, 7 Mar 2024 11:03:43 +0200 Subject: [PATCH 0067/2897] flake.lock: update --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index d5e00c3b..d94efaaa 100644 --- a/flake.lock +++ b/flake.lock @@ -33,11 +33,11 @@ ] }, "locked": { - "lastModified": 1708787654, - "narHash": "sha256-7ACgM3ZuAhPqurXHUvR2nWMRcnmzGGPjLK6q4DSTelI=", + "lastModified": 1709775675, + "narHash": "sha256-G+gIMUQBtfbbrnsM/OPJzebdqKFP6typplNCE7X8Szw=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "0fce791ba2334aca183f2ed42399518947550d0d", + "rev": "f1db1a7e1faee2a5c67d03b6bd283da82eed3730", "type": "github" }, "original": { @@ -48,11 +48,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1708807242, - "narHash": "sha256-sRTRkhMD4delO/hPxxi+XwLqPn8BuUq6nnj4JqLwOu0=", + "lastModified": 1709703039, + "narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "73de017ef2d18a04ac4bfd0c02650007ccb31c2a", + "rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", "type": "github" }, "original": { @@ -122,11 +122,11 @@ ] }, "locked": { - "lastModified": 1708696469, - "narHash": "sha256-shh5wmpeYy3MmsBfkm4f76yPsBDGk6OLYRVG+ARy2F0=", + "lastModified": 1709299639, + "narHash": "sha256-jYqJM5khksLIbqSxCLUUcqEgI+O2LdlSlcMEBs39CAU=", "owner": "hyprwm", "repo": "xdg-desktop-portal-hyprland", - "rev": "1b713911c2f12b96c2574474686e4027ac4bf826", + "rev": "2d2fb547178ec025da643db57d40a971507b82fe", "type": "github" }, "original": { From bf71026b8d31edc86a97222ef0fbec4972635cac Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Thu, 7 Mar 2024 05:23:22 -0800 Subject: [PATCH 0068/2897] master: change active monitor when moving windows around (#5001) --- src/layout/MasterLayout.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index c7e09186..4cff8bed 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -977,6 +977,8 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { onWindowRemovedTiling(pWindow); pWindow->moveToWorkspace(PWINDOW2->m_iWorkspaceID); pWindow->m_iMonitorID = PWINDOW2->m_iMonitorID; + const auto pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); + g_pCompositor->setActiveMonitor(pMonitor); onWindowCreatedTiling(pWindow); } else { // if same monitor, switch windows From 6c4e2489a0a153ac2a92744ecb2985280c97fc89 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Thu, 7 Mar 2024 05:27:58 -0800 Subject: [PATCH 0069/2897] layout: Fix toggling fullscreen special workspace on different monitor (#5000) * fix toggling fullscreen special ws on different monitor * add for dwindle * fix change regular workspace when special fullscreen --- src/helpers/Monitor.cpp | 10 ++++++++++ src/layout/DwindleLayout.cpp | 21 +++++++++++++++++++++ src/layout/MasterLayout.cpp | 22 ++++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 7b694d48..06ea0fa5 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -603,6 +603,12 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool g_pConfigManager->ensureVRR(this); g_pCompositor->updateSuspendedStates(); + + if (specialWorkspaceID) { + const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(specialWorkspaceID); + if (PSPECIALWS->m_bHasFullscreenWindow) + g_pCompositor->updateFullscreenFadeOnWorkspace(PSPECIALWS); + } } void CMonitor::changeWorkspace(const int& id, bool internal, bool noMouseMove, bool noFocus) { @@ -649,6 +655,10 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { PMONITORWORKSPACEOWNER->specialWorkspaceID = 0; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITORWORKSPACEOWNER->ID); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + PMONITORWORKSPACEOWNER->szName}); + + const auto PACTIVEWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITORWORKSPACEOWNER->activeWorkspace); + g_pCompositor->updateFullscreenFadeOnWorkspace(PACTIVEWORKSPACE); + animate = false; } diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 02a3dfbe..2f66482a 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -549,6 +549,27 @@ void CHyprDwindleLayout::recalculateMonitor(const int& monid) { g_pHyprRenderer->damageMonitor(PMONITOR); if (PMONITOR->specialWorkspaceID) { + const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID); + + if (PSPECIALWS->m_bHasFullscreenWindow) { + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PSPECIALWS->m_iID); + + if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_FULL) { + PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; + PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; + } else if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + SDwindleNodeData fakeNode; + fakeNode.pWindow = PFULLWINDOW; + fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; + fakeNode.workspaceID = PSPECIALWS->m_iID; + PFULLWINDOW->m_vPosition = fakeNode.box.pos(); + PFULLWINDOW->m_vSize = fakeNode.box.size(); + fakeNode.ignoreFullscreenChecks = true; + + applyNodeDataToWindow(&fakeNode); + } + } + const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->specialWorkspaceID); if (TOPNODE && PMONITOR) { diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 4cff8bed..d266d816 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -296,6 +296,28 @@ void CHyprMasterLayout::recalculateMonitor(const int& monid) { g_pHyprRenderer->damageMonitor(PMONITOR); if (PMONITOR->specialWorkspaceID) { + const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID); + + if (PSPECIALWS->m_bHasFullscreenWindow) { + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PSPECIALWS->m_iID); + + if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_FULL) { + PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; + PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; + } else if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + SMasterNodeData fakeNode; + fakeNode.pWindow = PFULLWINDOW; + fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; + fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; + fakeNode.workspaceID = PSPECIALWS->m_iID; + PFULLWINDOW->m_vPosition = fakeNode.position; + PFULLWINDOW->m_vSize = fakeNode.size; + fakeNode.ignoreFullscreenChecks = true; + + applyNodeDataToWindow(&fakeNode); + } + } + calculateWorkspace(PMONITOR->specialWorkspaceID); } From ceecdd0fd511122b7ff4f477a606880fe6599100 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Fri, 8 Mar 2024 00:34:33 +0100 Subject: [PATCH 0070/2897] hyprctl: Fix incorrect invalid fontsize kwarg response (#5013) --- src/debug/HyprCtl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 332e3969..c6864573 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1459,7 +1459,7 @@ std::string dispatchNotify(eHyprCtlOutputFormat format, std::string request) { size_t msgidx = 4; float fontsize = 13.f; - if (vars[msgidx].length() > 9 && vars[msgidx].compare(0, 10, "fontsize:")) { + if (vars[msgidx].length() > 9 && vars[msgidx].compare(0, 9, "fontsize:") == 0) { const auto FONTSIZE = vars[msgidx].substr(9); if (!isNumber(FONTSIZE, true)) From e52d3fa8522ff83813a9006d4bf46b3057f4a4cc Mon Sep 17 00:00:00 2001 From: Epilepsy Gatherings <73647246+phonetic112@users.noreply.github.com> Date: Thu, 7 Mar 2024 21:24:44 -0500 Subject: [PATCH 0071/2897] windowrules: Make min/maxsize rules dynamic (#4775) * rebase * simplify and remove prop * Stuff - add back win prop - change minsize defaults - change request formatting for setprop * style fix * remove empty line * change defaults * redo string to vec * remove redundant parsing * change to vec * support commas * remove static rules * take out garbage * format * don't allow commas and resize on setprop * use isNumber --- src/Window.cpp | 18 +++++++++++++++ src/Window.hpp | 42 ++++++++++++++++++----------------- src/debug/HyprCtl.cpp | 23 ++++++++++++++----- src/events/Windows.cpp | 28 ----------------------- src/helpers/MiscFunctions.cpp | 26 ++++++++++++++++++++++ src/helpers/MiscFunctions.hpp | 1 + src/layout/IHyprLayout.cpp | 4 ++-- 7 files changed, 87 insertions(+), 55 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 41562291..85608f6f 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -687,6 +687,22 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { m_eIdleInhibitMode = IDLEINHIBIT_FULLSCREEN; else Debug::log(ERR, "Rule idleinhibit: unknown mode {}", IDLERULE); + } else if (r.szRule.starts_with("maxsize")) { + try { + m_sAdditionalConfigData.maxSize = configStringToVector2D(r.szRule.substr(8)); + m_vRealSize = Vector2D(std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().x, m_vRealSize.goal().x), + std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().y, m_vRealSize.goal().y)); + g_pXWaylandManager->setWindowSize(this, m_vRealSize.goal()); + setHidden(false); + } catch (std::exception& e) { Debug::log(ERR, "maxsize rule \"{}\" failed with: {}", r.szRule, e.what()); } + } else if (r.szRule.starts_with("minsize")) { + try { + m_sAdditionalConfigData.minSize = configStringToVector2D(r.szRule.substr(8)); + m_vRealSize = Vector2D(std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().x, m_vRealSize.goal().x), + std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().y, m_vRealSize.goal().y)); + g_pXWaylandManager->setWindowSize(this, m_vRealSize.goal()); + setHidden(false); + } catch (std::exception& e) { Debug::log(ERR, "minsize rule \"{}\" failed with: {}", r.szRule, e.what()); } } } @@ -701,6 +717,8 @@ void CWindow::updateDynamicRules() { m_sAdditionalConfigData.forceNoDim = false; if (!m_sAdditionalConfigData.forceOpaqueOverridden) m_sAdditionalConfigData.forceOpaque = false; + m_sAdditionalConfigData.maxSize = Vector2D(std::numeric_limits::max(), std::numeric_limits::max()); + m_sAdditionalConfigData.minSize = Vector2D(1, 1); m_sAdditionalConfigData.forceNoAnims = false; m_sAdditionalConfigData.animationStyle = std::string(""); m_sAdditionalConfigData.rounding = -1; diff --git a/src/Window.hpp b/src/Window.hpp index aeb674d1..5fcb951f 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -142,26 +142,28 @@ struct SWindowSpecialRenderData { }; struct SWindowAdditionalConfigData { - std::string animationStyle = std::string(""); - CWindowOverridableVar rounding = -1; // -1 means no - CWindowOverridableVar forceNoBlur = false; - CWindowOverridableVar forceOpaque = false; - CWindowOverridableVar forceOpaqueOverridden = false; // if true, a rule will not change the forceOpaque state. This is for the force opaque dispatcher. - CWindowOverridableVar forceAllowsInput = false; - CWindowOverridableVar forceNoAnims = false; - CWindowOverridableVar forceNoBorder = false; - CWindowOverridableVar forceNoShadow = false; - CWindowOverridableVar forceNoDim = false; - CWindowOverridableVar noFocus = false; - CWindowOverridableVar windowDanceCompat = false; - CWindowOverridableVar noMaxSize = false; - CWindowOverridableVar dimAround = false; - CWindowOverridableVar forceRGBX = false; - CWindowOverridableVar keepAspectRatio = false; - CWindowOverridableVar xray = -1; // -1 means unset, takes precedence over the renderdata one - CWindowOverridableVar borderSize = -1; // -1 means unset, takes precedence over the renderdata one - CWindowOverridableVar forceTearing = false; - CWindowOverridableVar nearestNeighbor = false; + std::string animationStyle = std::string(""); + CWindowOverridableVar rounding = -1; // -1 means no + CWindowOverridableVar forceNoBlur = false; + CWindowOverridableVar forceOpaque = false; + CWindowOverridableVar forceOpaqueOverridden = false; // if true, a rule will not change the forceOpaque state. This is for the force opaque dispatcher. + CWindowOverridableVar forceAllowsInput = false; + CWindowOverridableVar forceNoAnims = false; + CWindowOverridableVar forceNoBorder = false; + CWindowOverridableVar forceNoShadow = false; + CWindowOverridableVar forceNoDim = false; + CWindowOverridableVar noFocus = false; + CWindowOverridableVar windowDanceCompat = false; + CWindowOverridableVar noMaxSize = false; + CWindowOverridableVar maxSize = Vector2D(std::numeric_limits::max(), std::numeric_limits::max()); + CWindowOverridableVar minSize = Vector2D(1, 1); + CWindowOverridableVar dimAround = false; + CWindowOverridableVar forceRGBX = false; + CWindowOverridableVar keepAspectRatio = false; + CWindowOverridableVar xray = -1; // -1 means unset, takes precedence over the renderdata one + CWindowOverridableVar borderSize = -1; // -1 means unset, takes precedence over the renderdata one + CWindowOverridableVar forceTearing = false; + CWindowOverridableVar nearestNeighbor = false; }; struct SWindowRule { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index c6864573..594d002f 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1147,11 +1147,8 @@ std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) { bool lock = false; - if (vars.size() > 4) { - if (vars[4].starts_with("lock")) { - lock = true; - } - } + if (request.ends_with("lock")) + lock = true; try { if (PROP == "animationstyle") { @@ -1180,6 +1177,22 @@ std::string dispatchSetProp(eHyprCtlOutputFormat format, std::string request) { PWINDOW->m_sAdditionalConfigData.windowDanceCompat.forceSetIgnoreLocked(configStringToInt(VAL), lock); } else if (PROP == "nomaxsize") { PWINDOW->m_sAdditionalConfigData.noMaxSize.forceSetIgnoreLocked(configStringToInt(VAL), lock); + } else if (PROP == "maxsize") { + PWINDOW->m_sAdditionalConfigData.maxSize.forceSetIgnoreLocked(configStringToVector2D(VAL + " " + vars[4]), lock); + if (lock) { + PWINDOW->m_vRealSize = Vector2D(std::min((double)PWINDOW->m_sAdditionalConfigData.maxSize.toUnderlying().x, PWINDOW->m_vRealSize.goal().x), + std::min((double)PWINDOW->m_sAdditionalConfigData.maxSize.toUnderlying().y, PWINDOW->m_vRealSize.goal().y)); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); + PWINDOW->setHidden(false); + } + } else if (PROP == "minsize") { + PWINDOW->m_sAdditionalConfigData.minSize.forceSetIgnoreLocked(configStringToVector2D(VAL + " " + vars[4]), lock); + if (lock) { + PWINDOW->m_vRealSize = Vector2D(std::max((double)PWINDOW->m_sAdditionalConfigData.minSize.toUnderlying().x, PWINDOW->m_vRealSize.goal().x), + std::max((double)PWINDOW->m_sAdditionalConfigData.minSize.toUnderlying().y, PWINDOW->m_vRealSize.goal().y)); + g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); + PWINDOW->setHidden(false); + } } else if (PROP == "dimaround") { PWINDOW->m_sAdditionalConfigData.dimAround.forceSetIgnoreLocked(configStringToInt(VAL), lock); } else if (PROP == "alphaoverride") { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 0bf84f10..84040ad5 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -328,34 +328,6 @@ void Events::listener_mapWindow(void* owner, void* data) { PWINDOW->setHidden(false); } catch (...) { Debug::log(LOG, "Rule size failed, rule: {} -> {}", r.szRule, r.szValue); } - } else if (r.szRule.starts_with("minsize")) { - try { - const auto VALUE = r.szRule.substr(r.szRule.find(' ') + 1); - const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); - const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); - - const auto SIZE = - Vector2D(std::max((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goal().x), std::max((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goal().y)); - - PWINDOW->m_vRealSize = SIZE; - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); - - PWINDOW->setHidden(false); - } catch (...) { Debug::log(LOG, "Rule minsize failed, rule: {} -> {}", r.szRule, r.szValue); } - } else if (r.szRule.starts_with("maxsize")) { - try { - const auto VALUE = r.szRule.substr(r.szRule.find(' ') + 1); - const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); - const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); - - const auto SIZE = - Vector2D(std::min((double)std::stoll(SIZEXSTR), PWINDOW->m_vRealSize.goal().x), std::min((double)std::stoll(SIZEYSTR), PWINDOW->m_vRealSize.goal().y)); - - PWINDOW->m_vRealSize = SIZE; - g_pXWaylandManager->setWindowSize(PWINDOW, PWINDOW->m_vRealSize.goal()); - - PWINDOW->setHidden(false); - } catch (...) { Debug::log(LOG, "Rule maxsize failed, rule: {} -> {}", r.szRule, r.szValue); } } else if (r.szRule.starts_with("move")) { try { auto value = r.szRule.substr(r.szRule.find(' ') + 1); diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 2905ce2b..860d8456 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -722,6 +722,32 @@ int64_t configStringToInt(const std::string& VALUE) { return std::stoll(VALUE); } +Vector2D configStringToVector2D(const std::string& VALUE) { + std::istringstream iss(VALUE); + std::string token; + + if (!std::getline(iss, token, ' ') && !std::getline(iss, token, ',')) + throw std::invalid_argument("Invalid string format"); + + if (!isNumber(token)) + throw std::invalid_argument("Invalid x value"); + + long long x = std::stoll(token); + + if (!std::getline(iss, token)) + throw std::invalid_argument("Invalid string format"); + + if (!isNumber(token)) + throw std::invalid_argument("Invalid y value"); + + long long y = std::stoll(token); + + if (std::getline(iss, token)) + throw std::invalid_argument("Invalid string format"); + + return Vector2D(x, y); +} + double normalizeAngleRad(double ang) { if (ang > M_PI * 2) { while (ang > M_PI * 2) diff --git a/src/helpers/MiscFunctions.hpp b/src/helpers/MiscFunctions.hpp index 23fc6e5a..d8a86b95 100644 --- a/src/helpers/MiscFunctions.hpp +++ b/src/helpers/MiscFunctions.hpp @@ -28,6 +28,7 @@ void logSystemInfo(); std::string execAndGet(const char*); int64_t getPPIDof(int64_t pid); int64_t configStringToInt(const std::string&); +Vector2D configStringToVector2D(const std::string&); std::optional getPlusMinusKeywordResult(std::string in, float relative); void matrixProjection(float mat[9], int w, int h, wl_output_transform tr); double normalizeAngleRad(double ang); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 26a30ecf..7269bab7 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -358,8 +358,8 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { } else if (g_pInputManager->dragMode == MBIND_RESIZE || g_pInputManager->dragMode == MBIND_RESIZE_FORCE_RATIO || g_pInputManager->dragMode == MBIND_RESIZE_BLOCK_RATIO) { if (DRAGGINGWINDOW->m_bIsFloating) { - Vector2D MINSIZE = g_pXWaylandManager->getMinSizeForWindow(DRAGGINGWINDOW).clamp({20, 20}); - Vector2D MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW); + Vector2D MINSIZE = g_pXWaylandManager->getMinSizeForWindow(DRAGGINGWINDOW).clamp(DRAGGINGWINDOW->m_sAdditionalConfigData.minSize.toUnderlying()); + Vector2D MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(DRAGGINGWINDOW).clamp({}, DRAGGINGWINDOW->m_sAdditionalConfigData.maxSize.toUnderlying()); Vector2D newSize = m_vBeginDragSizeXY; Vector2D newPos = m_vBeginDragPositionXY; From 1290507ac418bd48490522da9bf612d271e87010 Mon Sep 17 00:00:00 2001 From: Epilepsy Gatherings <73647246+phonetic112@users.noreply.github.com> Date: Fri, 8 Mar 2024 09:54:45 -0500 Subject: [PATCH 0072/2897] windowrules: check if floating when resizing from maxsize (#5019) * check if floating * use return --- src/Window.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Window.cpp b/src/Window.cpp index 85608f6f..8bc16f1b 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -689,6 +689,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { Debug::log(ERR, "Rule idleinhibit: unknown mode {}", IDLERULE); } else if (r.szRule.starts_with("maxsize")) { try { + if (!m_bIsFloating) + return; m_sAdditionalConfigData.maxSize = configStringToVector2D(r.szRule.substr(8)); m_vRealSize = Vector2D(std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().x, m_vRealSize.goal().x), std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().y, m_vRealSize.goal().y)); @@ -697,6 +699,8 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { } catch (std::exception& e) { Debug::log(ERR, "maxsize rule \"{}\" failed with: {}", r.szRule, e.what()); } } else if (r.szRule.starts_with("minsize")) { try { + if (!m_bIsFloating) + return; m_sAdditionalConfigData.minSize = configStringToVector2D(r.szRule.substr(8)); m_vRealSize = Vector2D(std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().x, m_vRealSize.goal().x), std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().y, m_vRealSize.goal().y)); From d1c80c31c8d4bdaff37c04d0e713cb8ba71f7588 Mon Sep 17 00:00:00 2001 From: Fazzi Date: Fri, 8 Mar 2024 16:30:42 +0000 Subject: [PATCH 0073/2897] README: change dwl link to new codeberg link (#5026) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9f4aa847..70cce21d 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ easy IPC, much more QoL stuff than other wlr-based compositors and more... [Wayfire]: https://github.com/WayfireWM/wayfire [TinyWl]: https://gitlab.freedesktop.org/wlroots/wlroots/-/blob/master/tinywl/tinywl.c [Sway]: https://github.com/swaywm/sway -[DWL]: https://github.com/djpohly/dwl +[DWL]: https://codeberg.org/dwl/dwl From 4c34e4aac25309b1203b5527387c8425f8e84ca8 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 8 Mar 2024 17:10:38 +0000 Subject: [PATCH 0074/2897] windowrules: minor improvements to min/max size fixes #5017 --- src/Window.cpp | 18 +++++++++++++++--- src/Window.hpp | 2 +- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index 8bc16f1b..3d101d13 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -691,7 +691,13 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { try { if (!m_bIsFloating) return; - m_sAdditionalConfigData.maxSize = configStringToVector2D(r.szRule.substr(8)); + const auto VEC = configStringToVector2D(r.szRule.substr(8)); + if (VEC.x < 1 || VEC.y < 1) { + Debug::log(ERR, "Invalid size for maxsize"); + return; + } + + m_sAdditionalConfigData.maxSize = VEC; m_vRealSize = Vector2D(std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().x, m_vRealSize.goal().x), std::min((double)m_sAdditionalConfigData.maxSize.toUnderlying().y, m_vRealSize.goal().y)); g_pXWaylandManager->setWindowSize(this, m_vRealSize.goal()); @@ -701,7 +707,13 @@ void CWindow::applyDynamicRule(const SWindowRule& r) { try { if (!m_bIsFloating) return; - m_sAdditionalConfigData.minSize = configStringToVector2D(r.szRule.substr(8)); + const auto VEC = configStringToVector2D(r.szRule.substr(8)); + if (VEC.x < 1 || VEC.y < 1) { + Debug::log(ERR, "Invalid size for minsize"); + return; + } + + m_sAdditionalConfigData.minSize = VEC; m_vRealSize = Vector2D(std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().x, m_vRealSize.goal().x), std::max((double)m_sAdditionalConfigData.minSize.toUnderlying().y, m_vRealSize.goal().y)); g_pXWaylandManager->setWindowSize(this, m_vRealSize.goal()); @@ -722,7 +734,7 @@ void CWindow::updateDynamicRules() { if (!m_sAdditionalConfigData.forceOpaqueOverridden) m_sAdditionalConfigData.forceOpaque = false; m_sAdditionalConfigData.maxSize = Vector2D(std::numeric_limits::max(), std::numeric_limits::max()); - m_sAdditionalConfigData.minSize = Vector2D(1, 1); + m_sAdditionalConfigData.minSize = Vector2D(20, 20); m_sAdditionalConfigData.forceNoAnims = false; m_sAdditionalConfigData.animationStyle = std::string(""); m_sAdditionalConfigData.rounding = -1; diff --git a/src/Window.hpp b/src/Window.hpp index 5fcb951f..2a19cfa5 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -156,7 +156,7 @@ struct SWindowAdditionalConfigData { CWindowOverridableVar windowDanceCompat = false; CWindowOverridableVar noMaxSize = false; CWindowOverridableVar maxSize = Vector2D(std::numeric_limits::max(), std::numeric_limits::max()); - CWindowOverridableVar minSize = Vector2D(1, 1); + CWindowOverridableVar minSize = Vector2D(20, 20); CWindowOverridableVar dimAround = false; CWindowOverridableVar forceRGBX = false; CWindowOverridableVar keepAspectRatio = false; From 5920c6a6b8d059413377f0cb25f3dfb1dc8c4201 Mon Sep 17 00:00:00 2001 From: Aaron <100180619+A7R7@users.noreply.github.com> Date: Sat, 9 Mar 2024 01:39:53 +0800 Subject: [PATCH 0075/2897] socket2: Add 5 IPC event with support for workspace ID (#5022) - `moveworkspacev2`: returns workspaceID,workspaceName,monitorName - `movewindowv2`: returns windowAddress,workspaceID,workspaceName - `createWorkspacev2`: returns workspaceID,workspaceName - `destroyWorkspacev2`: returns workspaceID,workspaceName - `workspacev2`: returns workspaceID,workspaceName - Include workspaceID as a parameter in CWorkspace constructor to support `createWorkspacev2`. Resolves #4929 --- src/Compositor.cpp | 8 ++++---- src/Window.cpp | 1 + src/desktop/Workspace.cpp | 5 ++++- src/desktop/Workspace.hpp | 2 +- src/helpers/Monitor.cpp | 5 ++--- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index ca722ada..9d5f7241 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2059,8 +2059,10 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // event g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", PWORKSPACEA->m_szName + "," + pMonitorB->szName}); + g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", PWORKSPACEA->m_iID, PWORKSPACEA->m_szName, pMonitorB->szName)}); EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEA, pMonitorB})); g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", PWORKSPACEB->m_szName + "," + pMonitorA->szName}); + g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", PWORKSPACEB->m_iID, PWORKSPACEB->m_szName, pMonitorA->szName)}); EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEB, pMonitorA})); } @@ -2241,6 +2243,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni // event g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", pWorkspace->m_szName + "," + pMonitor->szName}); + g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", pWorkspace->m_iID, pWorkspace->m_szName, pMonitor->szName)}); EMIT_HOOK_EVENT("moveWorkspace", (std::vector{pWorkspace, pMonitor})); } @@ -2577,10 +2580,7 @@ CWorkspace* CCompositor::createNewWorkspace(const int& id, const int& monid, con const bool SPECIAL = id >= SPECIAL_WORKSPACE_START && id <= -2; - const auto PWORKSPACE = m_vWorkspaces.emplace_back(std::make_unique(monID, NAME, SPECIAL)).get(); - - PWORKSPACE->m_iID = id; - PWORKSPACE->m_iMonitorID = monID; + const auto PWORKSPACE = m_vWorkspaces.emplace_back(std::make_unique(id, monID, NAME, SPECIAL)).get(); PWORKSPACE->m_fAlpha.setValueAndWarp(0); diff --git a/src/Window.cpp b/src/Window.cpp index 3d101d13..c63209a0 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -386,6 +386,7 @@ void CWindow::moveToWorkspace(int workspaceID) { if (PWORKSPACE) { g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", std::format("{:x},{}", (uintptr_t)this, PWORKSPACE->m_szName)}); + g_pEventManager->postEvent(SHyprIPCEvent{"movewindowv2", std::format("{:x},{},{}", (uintptr_t)this, PWORKSPACE->m_iID, PWORKSPACE->m_szName)}); EMIT_HOOK_EVENT("moveWindow", (std::vector{this, PWORKSPACE})); } diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 470d23e6..23f76309 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -2,7 +2,7 @@ #include "../Compositor.hpp" #include "../config/ConfigValue.hpp" -CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { +CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID); if (!PMONITOR) { @@ -11,6 +11,7 @@ CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { } m_iMonitorID = monitorID; + m_iID = id; m_szName = name; m_bIsSpecialWorkspace = special; @@ -30,6 +31,7 @@ CWorkspace::CWorkspace(int monitorID, std::string name, bool special) { m_szName = RULEFORTHIS.defaultName.value(); g_pEventManager->postEvent({"createworkspace", m_szName}); + g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("createWorkspace", this); } @@ -39,6 +41,7 @@ CWorkspace::~CWorkspace() { Debug::log(LOG, "Destroying workspace ID {}", m_iID); g_pEventManager->postEvent({"destroyworkspace", m_szName}); + g_pEventManager->postEvent({"destroyworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("destroyWorkspace", this); } diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index aea842e0..15b7c0e2 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -14,7 +14,7 @@ class CWindow; class CWorkspace { public: - CWorkspace(int monitorID, std::string name, bool special = false); + CWorkspace(int id, int monitorID, std::string name, bool special = false); ~CWorkspace(); // Workspaces ID-based have IDs > 0 diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 06ea0fa5..c05c79cc 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -414,9 +414,7 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { if (newDefaultWorkspaceName == "") newDefaultWorkspaceName = std::to_string(WORKSPACEID); - PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(ID, newDefaultWorkspaceName)).get(); - - PNEWWORKSPACE->m_iID = WORKSPACEID; + PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(WORKSPACEID, ID, newDefaultWorkspaceName)).get(); } activeWorkspace = PNEWWORKSPACE->m_iID; @@ -593,6 +591,7 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); g_pEventManager->postEvent(SHyprIPCEvent{"workspace", pWorkspace->m_szName}); + g_pEventManager->postEvent(SHyprIPCEvent{"workspacev2", std::format("{},{}", pWorkspace->m_iID, pWorkspace->m_szName)}); EMIT_HOOK_EVENT("workspace", pWorkspace); } From 0a4ade01d35abb4506da77cc64ab93e0c5c34dbd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 8 Mar 2024 17:40:23 +0000 Subject: [PATCH 0076/2897] format: make ci happy --- src/helpers/MiscFunctions.cpp | 4 ++-- src/plugins/PluginAPI.cpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 860d8456..2b83832c 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -649,8 +649,8 @@ int64_t getPPIDof(int64_t pid) { return 0; #else - std::string dir = "/proc/" + std::to_string(pid) + "/status"; - FILE* infile; + std::string dir = "/proc/" + std::to_string(pid) + "/status"; + FILE* infile; infile = fopen(dir.c_str(), "r"); if (!infile) diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index b6326960..494aa640 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -296,7 +296,7 @@ APICALL std::vector HyprlandAPI::findFunctionsByName(HANDLE hand const auto FPATH = std::filesystem::canonical(exe); #elif defined(__OpenBSD__) // Neither KERN_PROC_PATHNAME nor /proc are supported - const auto FPATH = std::filesystem::canonical("/usr/local/bin/Hyprland"); + const auto FPATH = std::filesystem::canonical("/usr/local/bin/Hyprland"); #else const auto FPATH = std::filesystem::canonical("/proc/self/exe"); #endif From 717d5b3cc2b9e2f94d3ec1ba794e21bc2bb787e3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 8 Mar 2024 17:47:12 +0000 Subject: [PATCH 0077/2897] hyprctl: hide unmapped windows without -a --- hyprctl/main.cpp | 2 ++ src/debug/HyprCtl.cpp | 15 ++++++++++++--- src/debug/HyprCtl.hpp | 4 ++++ 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index e6ae15bb..4d6066b5 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -309,6 +309,8 @@ int main(int argc, char** argv) { json = true; } else if (ARGS[i] == "-r" && !fullArgs.contains("r")) { fullArgs += "r"; + } else if (ARGS[i] == "-a" && !fullArgs.contains("a")) { + fullArgs += "a"; } else if (ARGS[i] == "--batch") { fullRequest = "--batch "; } else if (ARGS[i] == "--instance" || ARGS[i] == "-i") { diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 594d002f..80b1d16c 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -242,6 +242,9 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { result += "["; for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all) + continue; + result += getWindowData(w.get(), format); } @@ -250,6 +253,9 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { result += "]"; } else { for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped && !g_pHyprCtl->m_sCurrentRequestParams.all) + continue; + result += getWindowData(w.get(), format); } } @@ -1562,8 +1568,9 @@ void CHyprCtl::unregisterCommand(const std::shared_ptr& cmd) { } std::string CHyprCtl::getReply(std::string request) { - auto format = eHyprCtlOutputFormat::FORMAT_NORMAL; - bool reloadAll = false; + auto format = eHyprCtlOutputFormat::FORMAT_NORMAL; + bool reloadAll = false; + m_sCurrentRequestParams = {}; // process flags for non-batch requests if (!request.starts_with("[[BATCH]]") && request.contains("/")) { @@ -1584,8 +1591,10 @@ std::string CHyprCtl::getReply(std::string request) { if (c == 'j') format = eHyprCtlOutputFormat::FORMAT_JSON; - if (c == 'r') + else if (c == 'r') reloadAll = true; + else if (c == 'a') + m_sCurrentRequestParams.all = true; } if (sepIndex < request.size()) diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index 339acd1b..d668fffc 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -16,6 +16,10 @@ class CHyprCtl { int m_iSocketFD = -1; + struct { + bool all = false; + } m_sCurrentRequestParams; + private: void startHyprCtlSocket(); From 024d4ddc74c9bd7945c4075c972575f20bc5b9bd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 8 Mar 2024 22:51:28 +0000 Subject: [PATCH 0078/2897] input: scale local coords in constraints fixes #5029 --- src/managers/input/InputManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index f5ae1638..97d05118 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -152,7 +152,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { const auto RG = CONSTRAINT->logicConstraintRegion(); const auto CLOSEST = RG.closestPoint(mouseCoords); const auto BOX = SURF->getSurfaceBoxGlobal(); - const auto CLOSESTLOCAL = CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{}); + const auto CLOSESTLOCAL = (CLOSEST - (BOX.has_value() ? BOX->pos() : Vector2D{})) * (SURF->getWindow() ? SURF->getWindow()->m_fX11SurfaceScaledBy : 1.0); wlr_cursor_warp(g_pCompositor->m_sWLRCursor, nullptr, CLOSEST.x, CLOSEST.y); wlr_seat_pointer_send_motion(g_pCompositor->m_sSeat.seat, time, CLOSESTLOCAL.x, CLOSESTLOCAL.y); From 3e930a568a76a810dde6bcabcf737a81850e7153 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 03:09:25 +0000 Subject: [PATCH 0079/2897] format: fix format --- src/debug/HyprCtl.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/debug/HyprCtl.hpp b/src/debug/HyprCtl.hpp index d668fffc..cad57447 100644 --- a/src/debug/HyprCtl.hpp +++ b/src/debug/HyprCtl.hpp @@ -17,7 +17,7 @@ class CHyprCtl { int m_iSocketFD = -1; struct { - bool all = false; + bool all = false; } m_sCurrentRequestParams; private: From c9ea600baa186acd3825dde306a6b3f89de09131 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 15:32:36 +0000 Subject: [PATCH 0080/2897] layer-shell: allow for popup creation before map ref https://github.com/jjsullivan5196/wvkbd/issues/65 --- src/events/Layers.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index ad65f8fb..db237690 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -51,6 +51,7 @@ void Events::listener_newLayerSurface(wl_listener* listener, void* data) { layerSurface->layer = WLRLAYERSURFACE->current.layer; WLRLAYERSURFACE->data = layerSurface; layerSurface->monitorID = PMONITOR->ID; + layerSurface->popupHead = std::make_unique(layerSurface); layerSurface->forceBlur = g_pConfigManager->shouldBlurLS(layerSurface->szNamespace); @@ -65,6 +66,8 @@ void Events::listener_destroyLayerSurface(void* owner, void* data) { const auto PMONITOR = g_pCompositor->getMonitorFromID(layersurface->monitorID); + layersurface->popupHead.reset(); + if (!g_pCompositor->getMonitorFromID(layersurface->monitorID)) Debug::log(WARN, "Layersurface destroyed on an invalid monitor (removed?)"); @@ -111,8 +114,6 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { layersurface->keyboardExclusive = layersurface->layerSurface->current.keyboard_interactive; layersurface->surface = layersurface->layerSurface->surface; - layersurface->popupHead = std::make_unique(layersurface); - // fix if it changed its mon const auto PMONITOR = g_pCompositor->getMonitorFromOutput(layersurface->layerSurface->output); @@ -184,8 +185,6 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { std::erase(g_pInputManager->m_dExclusiveLSes, layersurface); - layersurface->popupHead.reset(); - if (!g_pInputManager->m_dExclusiveLSes.empty()) g_pCompositor->focusSurface(g_pInputManager->m_dExclusiveLSes[0]->layerSurface->surface); From 300d77edd9833db42c999a91271ae23a5be69ef2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 16:08:07 +0000 Subject: [PATCH 0081/2897] keybinds: track submap at press for keypresses fixes #5037 --- src/managers/KeybindManager.cpp | 4 +++- src/managers/KeybindManager.hpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index d1b72e53..d8a4ca46 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -319,6 +319,7 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard .keycode = KEYCODE, .modmaskAtPressTime = MODS, .sent = true, + .submapAtPress = m_szCurrentSelectedSubmap, }; bool suppressEvent = false; @@ -349,7 +350,8 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard bool foundInPressedKeys = false; for (auto it = m_dPressedKeys.begin(); it != m_dPressedKeys.end();) { if (it->keycode == KEYCODE) { - suppressEvent = handleKeybinds(MODS, *it, false); + if (it->submapAtPress == m_szCurrentSelectedSubmap) + handleKeybinds(MODS, *it, false); foundInPressedKeys = true; suppressEvent = !it->sent; it = m_dPressedKeys.erase(it); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 561ee1ab..07b77398 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -43,6 +43,7 @@ struct SPressedKeyWithMods { uint32_t keycode = 0; uint32_t modmaskAtPressTime = 0; bool sent = false; + std::string submapAtPress = ""; }; struct SParsedKey { From 3f58e77e75efad11edf5a0f6fd41f57a796323aa Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 16:35:35 +0000 Subject: [PATCH 0082/2897] deps: update wlroots --- src/events/Devices.cpp | 2 +- src/managers/KeybindManager.cpp | 16 ++++++++-------- src/managers/input/InputManager.cpp | 12 ++++++------ src/managers/input/Touch.cpp | 2 +- subprojects/wlroots | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/events/Devices.cpp b/src/events/Devices.cpp index 64050320..f0d68337 100644 --- a/src/events/Devices.cpp +++ b/src/events/Devices.cpp @@ -74,7 +74,7 @@ void Events::listener_newInput(wl_listener* listener, void* data) { Debug::log(LOG, "Attached a touch device with name {}", DEVICE->name); g_pInputManager->newTouchDevice(DEVICE); break; - case WLR_INPUT_DEVICE_TABLET_TOOL: + case WLR_INPUT_DEVICE_TABLET: Debug::log(LOG, "Attached a tablet tool with name {}", DEVICE->name); g_pInputManager->newTabletTool(DEVICE); break; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index d8a4ca46..6bcc7d3d 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -384,12 +384,12 @@ bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { m_tScrollTimer.reset(); bool found = false; - if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_VERTICAL) { + if (e->source == WL_POINTER_AXIS_SOURCE_WHEEL && e->orientation == WL_POINTER_AXIS_VERTICAL_SCROLL) { if (e->delta < 0) found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_down"}, true); else found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_up"}, true); - } else if (e->source == WLR_AXIS_SOURCE_WHEEL && e->orientation == WLR_AXIS_ORIENTATION_HORIZONTAL) { + } else if (e->source == WL_POINTER_AXIS_SOURCE_WHEEL && e->orientation == WL_POINTER_AXIS_HORIZONTAL_SCROLL) { if (e->delta < 0) found = handleKeybinds(MODS, SPressedKeyWithMods{.keyName = "mouse_left"}, true); else @@ -420,7 +420,7 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) { .modmaskAtPressTime = MODS, }; - if (e->state == WLR_BUTTON_PRESSED) { + if (e->state == WL_POINTER_BUTTON_STATE_PRESSED) { m_dPressedKeys.push_back(KEY); suppressEvent = handleKeybinds(MODS, KEY, true); @@ -454,7 +454,7 @@ bool CKeybindManager::onMouseEvent(wlr_pointer_button_event* e) { } void CKeybindManager::resizeWithBorder(wlr_pointer_button_event* e) { - if (e->state == WLR_BUTTON_PRESSED) { + if (e->state == WL_POINTER_BUTTON_STATE_PRESSED) { mouse("1resizewindow"); } else { mouse("0resizewindow"); @@ -1857,20 +1857,20 @@ void CKeybindManager::pass(std::string regexp) { if (g_pKeybindManager->m_uLastCode != 0) wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastCode - 8, WLR_BUTTON_PRESSED); else - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WLR_BUTTON_PRESSED); + wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WL_POINTER_BUTTON_STATE_PRESSED); } else if (g_pKeybindManager->m_iPassPressed == 0) if (g_pKeybindManager->m_uLastCode != 0) wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastCode - 8, WLR_BUTTON_RELEASED); else - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WLR_BUTTON_RELEASED); + wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WL_POINTER_BUTTON_STATE_RELEASED); else { // dynamic call of the dispatcher if (g_pKeybindManager->m_uLastCode != 0) { wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastCode - 8, WLR_BUTTON_PRESSED); wlr_seat_keyboard_notify_key(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastCode - 8, WLR_BUTTON_RELEASED); } else { - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WLR_BUTTON_PRESSED); - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WLR_BUTTON_RELEASED); + wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WL_POINTER_BUTTON_STATE_PRESSED); + wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, g_pKeybindManager->m_uTimeLastMs, g_pKeybindManager->m_uLastMouseCode, WL_POINTER_BUTTON_STATE_RELEASED); } } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 97d05118..32a9fbae 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -439,7 +439,7 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { m_tmrLastCursorMovement.reset(); - if (e->state == WLR_BUTTON_PRESSED) { + if (e->state == WL_POINTER_BUTTON_STATE_PRESSED) { m_lCurrentlyHeldButtons.push_back(e->button); } else { if (std::find_if(m_lCurrentlyHeldButtons.begin(), m_lCurrentlyHeldButtons.end(), [&](const auto& other) { return other == e->button; }) == m_lCurrentlyHeldButtons.end()) @@ -453,7 +453,7 @@ void CInputManager::onMouseButton(wlr_pointer_button_event* e) { default: break; } - if (m_bFocusHeldByButtons && m_lCurrentlyHeldButtons.empty() && e->state == WLR_BUTTON_RELEASED) { + if (m_bFocusHeldByButtons && m_lCurrentlyHeldButtons.empty() && e->state == WL_POINTER_BUTTON_STATE_RELEASED) { if (m_bRefocusHeldByButtons) refocus(); else @@ -597,7 +597,7 @@ void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // clicking on border triggers resize // TODO detect click on LS properly - if (*PRESIZEONBORDER && !m_bLastFocusOnLS && e->state == WLR_BUTTON_PRESSED) { + if (*PRESIZEONBORDER && !m_bLastFocusOnLS && e->state == WL_POINTER_BUTTON_STATE_PRESSED) { if (w && !w->m_bIsFullscreen) { const CBox real = {w->m_vRealPosition.value().x, w->m_vRealPosition.value().y, w->m_vRealSize.value().x, w->m_vRealSize.value().y}; const CBox grab = {real.x - BORDER_GRAB_AREA, real.y - BORDER_GRAB_AREA, real.width + 2 * BORDER_GRAB_AREA, real.height + 2 * BORDER_GRAB_AREA}; @@ -669,7 +669,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { static auto PINPUTSCROLLFACTOR = CConfigValue("input:scroll_factor"); static auto PTOUCHPADSCROLLFACTOR = CConfigValue("input:touchpad:scroll_factor"); - auto factor = (*PTOUCHPADSCROLLFACTOR <= 0.f || e->source == WLR_AXIS_SOURCE_FINGER ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR); + auto factor = (*PTOUCHPADSCROLLFACTOR <= 0.f || e->source == WL_POINTER_AXIS_SOURCE_FINGER ? *PTOUCHPADSCROLLFACTOR : *PINPUTSCROLLFACTOR); const auto EMAP = std::unordered_map{{"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); @@ -690,7 +690,7 @@ void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { } wlr_seat_pointer_notify_axis(g_pCompositor->m_sSeat.seat, e->time_msec, e->orientation, factor * e->delta, std::round(factor * e->delta_discrete), e->source, - WLR_AXIS_RELATIVE_DIRECTION_IDENTICAL); + WL_POINTER_AXIS_RELATIVE_DIRECTION_IDENTICAL); } Vector2D CInputManager::getMouseCoordsInternal() { @@ -1545,7 +1545,7 @@ void CInputManager::releaseAllMouseButtons() { return; for (auto& mb : buttonsCopy) { - wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, 0, mb, WLR_BUTTON_RELEASED); + wlr_seat_pointer_notify_button(g_pCompositor->m_sSeat.seat, 0, mb, WL_POINTER_BUTTON_STATE_RELEASED); } m_lCurrentlyHeldButtons.clear(); diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 0b26bd30..3247a229 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -19,7 +19,7 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { if (m_ecbClickBehavior == CLICKMODE_KILL) { wlr_pointer_button_event e; - e.state = WLR_BUTTON_PRESSED; + e.state = WL_POINTER_BUTTON_STATE_PRESSED; g_pInputManager->processMouseDownKill(&e); return; } diff --git a/subprojects/wlroots b/subprojects/wlroots index 0cb091f1..50eae512 160000 --- a/subprojects/wlroots +++ b/subprojects/wlroots @@ -1 +1 @@ -Subproject commit 0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5 +Subproject commit 50eae512d9cecbf0b3b1898bb1f0b40fa05fe19b From fa886d8b11b5d38f9fa12debcdd1f992b258406a Mon Sep 17 00:00:00 2001 From: vaxerski Date: Sat, 9 Mar 2024 16:36:19 +0000 Subject: [PATCH 0083/2897] [gha] Nix: update wlroots --- flake.lock | 8 ++++---- flake.nix | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flake.lock b/flake.lock index d94efaaa..6d27876d 100644 --- a/flake.lock +++ b/flake.lock @@ -91,18 +91,18 @@ "flake": false, "locked": { "host": "gitlab.freedesktop.org", - "lastModified": 1708558866, - "narHash": "sha256-Mz6hCtommq7RQfcPnxLINigO4RYSNt23HeJHC6mVmWI=", + "lastModified": 1709983277, + "narHash": "sha256-wXWIJLd4F2JZeMaihWVDW/yYXCLEC8OpeNJZg9a9ly8=", "owner": "wlroots", "repo": "wlroots", - "rev": "0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5", + "rev": "50eae512d9cecbf0b3b1898bb1f0b40fa05fe19b", "type": "gitlab" }, "original": { "host": "gitlab.freedesktop.org", "owner": "wlroots", "repo": "wlroots", - "rev": "0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5", + "rev": "50eae512d9cecbf0b3b1898bb1f0b40fa05fe19b", "type": "gitlab" } }, diff --git a/flake.nix b/flake.nix index be80440a..ed52478a 100644 --- a/flake.nix +++ b/flake.nix @@ -12,7 +12,7 @@ host = "gitlab.freedesktop.org"; owner = "wlroots"; repo = "wlroots"; - rev = "0cb091f1a2d345f37d2ee445f4ffd04f7f4ec9e5"; + rev = "50eae512d9cecbf0b3b1898bb1f0b40fa05fe19b"; flake = false; }; From a01949dd286ba67f8026aeec38b44b61e20be412 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 16:39:33 +0000 Subject: [PATCH 0084/2897] deco: fix warnings --- src/render/decorations/CHyprGroupBarDecoration.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index cd9f32be..defff9ba 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -430,15 +430,15 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point if (e->button == 274) { static Vector2D pressedCursorPos; - if (e->state == WLR_BUTTON_PRESSED) + if (e->state == WL_POINTER_BUTTON_STATE_PRESSED) pressedCursorPos = pos; - else if (e->state == WLR_BUTTON_RELEASED && pressedCursorPos == pos) + else if (e->state == WL_POINTER_BUTTON_STATE_RELEASED && pressedCursorPos == pos) g_pXWaylandManager->sendCloseWindow(m_pWindow->getGroupWindowByIndex(WINDOWINDEX)); return true; } - if (e->state != WLR_BUTTON_PRESSED) + if (e->state != WL_POINTER_BUTTON_STATE_PRESSED) return true; // click on padding From e7a5db4852d654596e554b9cdeaa2694b346ee03 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:47:57 +0000 Subject: [PATCH 0085/2897] xwayland: Set xwayland's name prop (#4924) * set xwayland name * [gha] Nix: update wlroots * fix --------- Co-authored-by: vaxerski --- src/Compositor.hpp | 5 ++++- src/events/Misc.cpp | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 5d75b199..8042aaaa 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -233,4 +233,7 @@ inline std::map HYPRATOMS = {HYPRATOM("_NET_WM_WINDOW_T HYPRATOM("_NET_WM_WINDOW_TYPE_POPUP_MENU"), HYPRATOM("_NET_WM_WINDOW_TYPE_TOOLTIP"), HYPRATOM("_NET_WM_WINDOW_TYPE_NOTIFICATION"), - HYPRATOM("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE")}; + HYPRATOM("_KDE_NET_WM_WINDOW_TYPE_OVERRIDE"), + HYPRATOM("_NET_SUPPORTING_WM_CHECK"), + HYPRATOM("_NET_WM_NAME"), + HYPRATOM("UTF8_STRING")}; diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index 0ee95ac3..64f2f29d 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -63,6 +63,8 @@ void Events::listener_readyXWayland(wl_listener* listener, void* data) { } ATOM.second = reply->atom; + + free(reply); } wlr_xwayland_set_seat(g_pXWaylandManager->m_sWLRXWayland, g_pCompositor->m_sSeat.seat); @@ -73,6 +75,19 @@ void Events::listener_readyXWayland(wl_listener* listener, void* data) { XCURSOR->images[0]->height, XCURSOR->images[0]->hotspot_x, XCURSOR->images[0]->hotspot_y); } + const auto ROOT = xcb_setup_roots_iterator(xcb_get_setup(XCBCONNECTION)).data->root; + auto cookie = xcb_get_property(XCBCONNECTION, 0, ROOT, HYPRATOMS["_NET_SUPPORTING_WM_CHECK"], XCB_ATOM_ANY, 0, 2048); + auto reply = xcb_get_property_reply(XCBCONNECTION, cookie, nullptr); + + const auto XWMWINDOW = *(xcb_window_t*)xcb_get_property_value(reply); + const char* name = "Hyprland"; + + xcb_change_property(wlr_xwayland_get_xwm_connection(g_pXWaylandManager->m_sWLRXWayland), XCB_PROP_MODE_REPLACE, XWMWINDOW, HYPRATOMS["_NET_WM_NAME"], HYPRATOMS["UTF8_STRING"], + 8, // format + strlen(name), name); + + free(reply); + xcb_disconnect(XCBCONNECTION); #endif } From c3882bb83240b602277f2d22f21d71690531f62e Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Sat, 9 Mar 2024 16:52:59 +0000 Subject: [PATCH 0086/2897] internal: Support libhyprcursor (#5009) woo --------- Co-authored-by: Mihai Fufezan --- .github/actions/setup_base/action.yml | 14 +- CMakeLists.txt | 2 +- flake.lock | 72 +++++++++- flake.nix | 6 + nix/default.nix | 3 +- nix/overlays.nix | 1 + nix/patches/meson-build.patch | 5 +- src/Compositor.cpp | 17 +-- src/Compositor.hpp | 1 - src/config/ConfigManager.cpp | 1 + src/debug/HyprCtl.cpp | 12 +- src/events/Misc.cpp | 9 +- src/helpers/Monitor.cpp | 4 - src/includes.hpp | 2 +- src/managers/CursorManager.cpp | 200 ++++++++++++++++++++++++++ src/managers/CursorManager.hpp | 69 +++++++++ src/meson.build | 1 + src/render/Renderer.cpp | 3 +- 18 files changed, 379 insertions(+), 43 deletions(-) create mode 100644 src/managers/CursorManager.cpp create mode 100644 src/managers/CursorManager.hpp diff --git a/.github/actions/setup_base/action.yml b/.github/actions/setup_base/action.yml index 8a33dd55..8598b5a3 100644 --- a/.github/actions/setup_base/action.yml +++ b/.github/actions/setup_base/action.yml @@ -12,6 +12,7 @@ runs: - name: Get required pacman pkgs shell: bash run: | + sed -i -e "1i [extra-testing]\nInclude = /etc/pacman.d/mirrorlist" "/etc/pacman.conf" sed -i 's/SigLevel = Required DatabaseOptional/SigLevel = Optional TrustAll/' /etc/pacman.conf pacman --noconfirm --noprogressbar -Syyu pacman --noconfirm --noprogressbar -Sy \ @@ -51,7 +52,18 @@ runs: wayland-protocols \ xcb-util-errors \ xcb-util-renderutil \ - xcb-util-wm + xcb-util-wm \ + libzip \ + librsvg + + - name: Get hyprcursor-git + shell: bash + run: | + git clone https://github.com/hyprwm/hyprcursor --recursive + cd hyprcursor + cmake --no-warn-unused-cli -DCMAKE_BUILD_TYPE:STRING=Release -DCMAKE_INSTALL_PREFIX:PATH=/usr -S . -B ./build + cmake --build ./build --config Release --target all -j`nproc 2>/dev/null || getconf NPROCESSORS_CONF` + cmake --install build - name: Get Xorg pacman pkgs shell: bash diff --git a/CMakeLists.txt b/CMakeLists.txt index 857e21de..71766a8c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ message(STATUS "Checking deps...") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) find_package(OpenGL REQUIRED) -pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2) # we do not check for wlroots, as we provide it ourselves +pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 hyprcursor) # we do not check for wlroots, as we provide it ourselves file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") diff --git a/flake.lock b/flake.lock index 6d27876d..36a509b1 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,29 @@ { "nodes": { + "hyprcursor": { + "inputs": { + "hyprlang": "hyprlang", + "nixpkgs": [ + "nixpkgs" + ], + "systems": [ + "systems" + ] + }, + "locked": { + "lastModified": 1709942067, + "narHash": "sha256-DGU4zQDwIx6pXM6oHdA+89UU/QjqE05HiXOvigECJjI=", + "owner": "hyprwm", + "repo": "hyprcursor", + "rev": "a2233d4a2a58233457712acfd88d10a2a8a85711", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprcursor", + "type": "github" + } + }, "hyprland-protocols": { "inputs": { "nixpkgs": [ @@ -24,6 +48,28 @@ } }, "hyprlang": { + "inputs": { + "nixpkgs": [ + "hyprcursor", + "nixpkgs" + ], + "systems": "systems" + }, + "locked": { + "lastModified": 1709914708, + "narHash": "sha256-bR4o3mynoTa1Wi4ZTjbnsZ6iqVcPGriXp56bZh5UFTk=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "a685493fdbeec01ca8ccdf1f3655c044a8ce2fe2", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "hyprlang_2": { "inputs": { "nixpkgs": [ "nixpkgs" @@ -33,11 +79,11 @@ ] }, "locked": { - "lastModified": 1709775675, - "narHash": "sha256-G+gIMUQBtfbbrnsM/OPJzebdqKFP6typplNCE7X8Szw=", + "lastModified": 1709914708, + "narHash": "sha256-bR4o3mynoTa1Wi4ZTjbnsZ6iqVcPGriXp56bZh5UFTk=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "f1db1a7e1faee2a5c67d03b6bd283da82eed3730", + "rev": "a685493fdbeec01ca8ccdf1f3655c044a8ce2fe2", "type": "github" }, "original": { @@ -64,10 +110,11 @@ }, "root": { "inputs": { + "hyprcursor": "hyprcursor", "hyprland-protocols": "hyprland-protocols", - "hyprlang": "hyprlang", + "hyprlang": "hyprlang_2", "nixpkgs": "nixpkgs", - "systems": "systems", + "systems": "systems_2", "wlroots": "wlroots", "xdph": "xdph" } @@ -87,6 +134,21 @@ "type": "github" } }, + "systems_2": { + "locked": { + "lastModified": 1689347949, + "narHash": "sha256-12tWmuL2zgBgZkdoB6qXZsgJEH9LR3oUgpaQq2RbI80=", + "owner": "nix-systems", + "repo": "default-linux", + "rev": "31732fcf5e8fea42e59c2488ad31a0e651500f68", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default-linux", + "type": "github" + } + }, "wlroots": { "flake": false, "locked": { diff --git a/flake.nix b/flake.nix index ed52478a..e97ba1c9 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,12 @@ flake = false; }; + hyprcursor = { + url = "github:hyprwm/hyprcursor"; + inputs.nixpkgs.follows = "nixpkgs"; + inputs.systems.follows = "systems"; + }; + hyprland-protocols = { url = "github:hyprwm/hyprland-protocols"; inputs.nixpkgs.follows = "nixpkgs"; diff --git a/nix/default.nix b/nix/default.nix index 66ea53a6..c4650d3c 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -8,6 +8,7 @@ binutils, cairo, git, + hyprcursor, hyprland-protocols, hyprlang, jq, @@ -32,7 +33,6 @@ enableXWayland ? true, legacyRenderer ? false, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, - wrapRuntimeDeps ? true, version ? "git", commit, date, @@ -75,6 +75,7 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov [ cairo git + hyprcursor.dev hyprland-protocols hyprlang libdrm diff --git a/nix/overlays.nix b/nix/overlays.nix index 0a84d93e..c216ff53 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -21,6 +21,7 @@ in { # Packages for variations of Hyprland, dependencies included. hyprland-packages = lib.composeManyExtensions [ # Dependencies + inputs.hyprcursor.overlays.default inputs.hyprland-protocols.overlays.default inputs.hyprlang.overlays.default self.overlays.wlroots-hyprland diff --git a/nix/patches/meson-build.patch b/nix/patches/meson-build.patch index aefbf1bc..7f372107 100644 --- a/nix/patches/meson-build.patch +++ b/nix/patches/meson-build.patch @@ -37,15 +37,16 @@ diff --git a/src/meson.build b/src/meson.build index 45701f5f..3505cefe 100644 --- a/src/meson.build +++ b/src/meson.build -@@ -9,17 +9,17 @@ executable('Hyprland', src, +@@ -9,7 +9,7 @@ executable('Hyprland', src, server_protos, dependency('wayland-server'), dependency('wayland-client'), - wlroots.get_variable('wlroots'), + dependency('wlroots'), dependency('cairo'), + dependency('hyprcursor'), dependency('hyprlang', version: '>= 0.3.2'), - dependency('libdrm'), +@@ -16,12 +16,12 @@ executable('Hyprland', src, dependency('egl'), dependency('xkbcommon'), dependency('libinput'), diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 9d5f7241..5697adbf 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1,6 +1,7 @@ #include "Compositor.hpp" #include "helpers/Splashes.hpp" #include "config/ConfigValue.hpp" +#include "managers/CursorManager.hpp" #include #include #include "debug/HyprCtl.hpp" @@ -182,18 +183,6 @@ void CCompositor::initServer() { m_sWLRCursor = wlr_cursor_create(); wlr_cursor_attach_output_layout(m_sWLRCursor, m_sWLROutputLayout); - if (const auto XCURSORENV = getenv("XCURSOR_SIZE"); !XCURSORENV || std::string(XCURSORENV).empty()) - setenv("XCURSOR_SIZE", "24", true); - - const auto XCURSORENV = getenv("XCURSOR_SIZE"); - int cursorSize = 24; - try { - cursorSize = std::stoi(XCURSORENV); - } catch (std::exception& e) { Debug::log(ERR, "XCURSOR_SIZE invalid in check #2? ({})", XCURSORENV); } - - m_sWLRXCursorMgr = wlr_xcursor_manager_create(nullptr, cursorSize); - wlr_xcursor_manager_load(m_sWLRXCursorMgr, 1); - m_sSeat.seat = wlr_seat_create(m_sWLDisplay, "seat0"); m_sWLRPresentation = wlr_presentation_create(m_sWLDisplay, m_sWLRBackend); @@ -422,6 +411,7 @@ void CCompositor::cleanup() { wl_display_destroy_clients(g_pCompositor->m_sWLDisplay); g_pDecorationPositioner.reset(); + g_pCursorManager.reset(); g_pPluginSystem.reset(); g_pHyprNotificationOverlay.reset(); g_pDebugOverlay.reset(); @@ -511,6 +501,9 @@ void CCompositor::initManagers(eManagersInitStage stage) { Debug::log(LOG, "Creating the DecorationPositioner!"); g_pDecorationPositioner = std::make_unique(); + + Debug::log(LOG, "Creating the CursorManager!"); + g_pCursorManager = std::make_unique(); } break; default: UNREACHABLE(); } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 8042aaaa..b1033e89 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -57,7 +57,6 @@ class CCompositor { wlr_layer_shell_v1* m_sWLRLayerShell; wlr_xdg_shell* m_sWLRXDGShell; wlr_cursor* m_sWLRCursor; - wlr_xcursor_manager* m_sWLRXCursorMgr; wlr_virtual_keyboard_manager_v1* m_sWLRVKeyboardMgr; wlr_output_manager_v1* m_sWLROutputMgr; wlr_presentation* m_sWLRPresentation; diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 08b2e3c1..0409140a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -347,6 +347,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:close_special_on_empty", Hyprlang::INT{1}); m_pConfig->addConfigValue("misc:background_color", Hyprlang::INT{0xff111111}); m_pConfig->addConfigValue("misc:new_window_takes_over_fullscreen", Hyprlang::INT{0}); + m_pConfig->addConfigValue("misc:enable_hyprcursor", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 80b1d16c..f13843a3 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -16,6 +16,7 @@ #include #include "../config/ConfigValue.hpp" +#include "../managers/CursorManager.hpp" static void trimTrailingComma(std::string& str) { if (!str.empty() && str.back() == ',') @@ -1045,16 +1046,7 @@ std::string dispatchSetCursor(eHyprCtlOutputFormat format, std::string request) if (size <= 0) return "size not positive"; - wlr_xcursor_manager_destroy(g_pCompositor->m_sWLRXCursorMgr); - - g_pCompositor->m_sWLRXCursorMgr = wlr_xcursor_manager_create(theme.c_str(), size); - - setenv("XCURSOR_SIZE", SIZESTR.c_str(), true); - setenv("XCURSOR_THEME", theme.c_str(), true); - - for (auto& m : g_pCompositor->m_vMonitors) { - wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, m->scale); - } + g_pCursorManager->changeTheme(theme, size); return "ok"; } diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index 64f2f29d..d7e3a849 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -4,6 +4,7 @@ #include "../helpers/WLClasses.hpp" #include "../managers/input/InputManager.hpp" #include "../render/Renderer.hpp" +#include "../managers/CursorManager.hpp" // ------------------------------ // // __ __ _____ _____ _____ // @@ -69,10 +70,10 @@ void Events::listener_readyXWayland(wl_listener* listener, void* data) { wlr_xwayland_set_seat(g_pXWaylandManager->m_sWLRXWayland, g_pCompositor->m_sSeat.seat); - const auto XCURSOR = wlr_xcursor_manager_get_xcursor(g_pCompositor->m_sWLRXCursorMgr, "left_ptr", 1); - if (XCURSOR) { - wlr_xwayland_set_cursor(g_pXWaylandManager->m_sWLRXWayland, XCURSOR->images[0]->buffer, XCURSOR->images[0]->width * 4, XCURSOR->images[0]->width, - XCURSOR->images[0]->height, XCURSOR->images[0]->hotspot_x, XCURSOR->images[0]->hotspot_y); + const auto CURSOR = g_pCursorManager->dataFor("left_ptr"); + if (CURSOR.surface) { + wlr_xwayland_set_cursor(g_pXWaylandManager->m_sWLRXWayland, cairo_image_surface_get_data(CURSOR.surface), cairo_image_surface_get_stride(CURSOR.surface), CURSOR.size, + CURSOR.size, CURSOR.hotspotX, CURSOR.hotspotY); } const auto ROOT = xcb_setup_roots_iterator(xcb_get_setup(XCBCONNECTION)).data->root; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index c05c79cc..9126f936 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -164,8 +164,6 @@ void CMonitor::onConnect(bool noRule) { wlr_damage_ring_set_bounds(&damage, vecTransformedSize.x, vecTransformedSize.y); - wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale); - Debug::log(LOG, "Added new monitor with name {} at {:j0} with size {:j0}, pointer {:x}", output->name, vecPosition, vecPixelSize, (uintptr_t)output); setupDefaultWS(monitorRule); @@ -192,8 +190,6 @@ void CMonitor::onConnect(bool noRule) { if (!g_pCompositor->m_pLastMonitor) // set the last monitor if it isnt set yet g_pCompositor->setActiveMonitor(this); - wlr_xcursor_manager_load(g_pCompositor->m_sWLRXCursorMgr, scale); - g_pHyprRenderer->arrangeLayersForMonitor(ID); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); diff --git a/src/includes.hpp b/src/includes.hpp index 961729ad..6a1e5bc3 100644 --- a/src/includes.hpp +++ b/src/includes.hpp @@ -63,7 +63,6 @@ extern "C" { #include #include #include -#include #include #include #include @@ -76,6 +75,7 @@ extern "C" { #include #include #include +#include #include #include #include diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp new file mode 100644 index 00000000..ae765016 --- /dev/null +++ b/src/managers/CursorManager.cpp @@ -0,0 +1,200 @@ +#include "CursorManager.hpp" +#include "Compositor.hpp" +#include "../config/ConfigValue.hpp" + +extern "C" { +#include +#include +} + +static int cursorAnimTimer(void* data) { + g_pCursorManager->tickAnimatedCursor(); + return 1; +} + +CCursorManager::CCursorManager() { + m_pHyprcursor = std::make_unique(m_szTheme.empty() ? nullptr : m_szTheme.c_str()); + + // find default size. First, HYPRCURSOR_SIZE, then XCURSOR_SIZE, then 24 + auto SIZE = getenv("HYPRCURSOR_SIZE"); + if (SIZE) { + try { + m_iSize = std::stoi(SIZE); + } catch (...) { ; } + } + + SIZE = getenv("XCURSOR_SIZE"); + if (SIZE && m_iSize == 0) { + try { + m_iSize = std::stoi(SIZE); + } catch (...) { ; } + } + + if (m_iSize == 0) + m_iSize = 24; + + m_pWLRXCursorMgr = wlr_xcursor_manager_create(nullptr, m_iSize); + wlr_xcursor_manager_load(m_pWLRXCursorMgr, 1.0); + + m_pAnimationTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ::cursorAnimTimer, nullptr); + + updateTheme(); + + g_pHookSystem->hookDynamic("monitorLayoutChanged", [this](void* self, SCallbackInfo& info, std::any param) { this->updateTheme(); }); +} + +void CCursorManager::dropBufferRef(CCursorManager::CCursorBuffer* ref) { + std::erase_if(m_vCursorBuffers, [ref](const auto& buf) { return buf.get() == ref; }); +} + +static void cursorBufferDestroy(struct wlr_buffer* wlr_buffer) { + CCursorManager::CCursorBuffer::SCursorWlrBuffer* buffer = wl_container_of(wlr_buffer, buffer, base); + g_pCursorManager->dropBufferRef(buffer->parent); +} + +static bool cursorBufferBeginDataPtr(struct wlr_buffer* wlr_buffer, uint32_t flags, void** data, uint32_t* format, size_t* stride) { + CCursorManager::CCursorBuffer::SCursorWlrBuffer* buffer = wl_container_of(wlr_buffer, buffer, base); + + if (flags & WLR_BUFFER_DATA_PTR_ACCESS_WRITE) + return false; + + *data = cairo_image_surface_get_data(buffer->surface); + *stride = cairo_image_surface_get_stride(buffer->surface); + *format = DRM_FORMAT_ARGB8888; + return true; +} + +static void cursorBufferEndDataPtr(struct wlr_buffer* wlr_buffer) { + ; +} + +// +static const wlr_buffer_impl bufferImpl = { + .destroy = cursorBufferDestroy, + .begin_data_ptr_access = cursorBufferBeginDataPtr, + .end_data_ptr_access = cursorBufferEndDataPtr, +}; + +CCursorManager::CCursorBuffer::CCursorBuffer(cairo_surface_t* surf, const Vector2D& size_, const Vector2D& hot_) : size(size_), hotspot(hot_) { + wlrBuffer.surface = surf; + wlr_buffer_init(&wlrBuffer.base, &bufferImpl, size.x, size.y); + wlrBuffer.parent = this; +} + +CCursorManager::CCursorBuffer::~CCursorBuffer() { + ; // will be freed in .destroy +} + +wlr_buffer* CCursorManager::getCursorBuffer() { + return !m_vCursorBuffers.empty() ? &m_vCursorBuffers.back()->wlrBuffer.base : nullptr; +} + +void CCursorManager::setCursorSurface(wlr_surface* surf, const Vector2D& hotspot) { + wlr_cursor_set_surface(g_pCompositor->m_sWLRCursor, surf, hotspot.x, hotspot.y); + + m_bOurBufferConnected = false; +} + +void CCursorManager::setCursorFromName(const std::string& name) { + + static auto PUSEHYPRCURSOR = CConfigValue("misc:enable_hyprcursor"); + + if (!m_pHyprcursor->valid() || !*PUSEHYPRCURSOR) { + wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, m_pWLRXCursorMgr, name.c_str()); + return; + } + + m_sCurrentCursorShapeData = m_pHyprcursor->getShape(name.c_str(), m_sCurrentStyleInfo); + + if (m_sCurrentCursorShapeData.images.size() < 1) { + Debug::log(ERR, "BUG THIS: No cursor returned by getShape()"); + return; + } + + m_vCursorBuffers.emplace_back(std::make_unique(m_sCurrentCursorShapeData.images[0].surface, + Vector2D{m_sCurrentCursorShapeData.images[0].size, m_sCurrentCursorShapeData.images[0].size}, + Vector2D{m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY})); + + if (g_pCompositor->m_sWLRCursor) + wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY, + m_fCursorScale); + + m_bOurBufferConnected = true; + + if (m_sCurrentCursorShapeData.images.size() > 1) { + // animated + wl_event_source_timer_update(m_pAnimationTimer, m_sCurrentCursorShapeData.images[0].delay); + m_iCurrentAnimationFrame = 0; + } else { + // disarm + wl_event_source_timer_update(m_pAnimationTimer, 0); + } +} + +void CCursorManager::tickAnimatedCursor() { + if (m_sCurrentCursorShapeData.images.size() < 2 || !m_bOurBufferConnected) + return; + + m_iCurrentAnimationFrame++; + if ((size_t)m_iCurrentAnimationFrame >= m_sCurrentCursorShapeData.images.size()) + m_iCurrentAnimationFrame = 0; + + m_vCursorBuffers.emplace_back(std::make_unique( + m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].surface, + Vector2D{m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].size, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].size}, + Vector2D{m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotX, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotY})); + + if (g_pCompositor->m_sWLRCursor) + wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotX, + m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotY, m_fCursorScale); + + wl_event_source_timer_update(m_pAnimationTimer, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].delay); +} + +SCursorImageData CCursorManager::dataFor(const std::string& name) { + const auto IMAGES = m_pHyprcursor->getShape(name.c_str(), m_sCurrentStyleInfo); + + if (IMAGES.images.empty()) + return {}; + + return IMAGES.images[0]; +} + +void CCursorManager::updateTheme() { + float highestScale = 1.0; + + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->scale > highestScale) + highestScale = m->scale; + } + + if (highestScale * m_iSize == m_sCurrentStyleInfo.size) + return; + + if (m_sCurrentStyleInfo.size && m_pHyprcursor->valid()) + m_pHyprcursor->cursorSurfaceStyleDone(m_sCurrentStyleInfo); + + m_sCurrentStyleInfo.size = m_iSize * highestScale; + m_fCursorScale = highestScale; + + if (m_pHyprcursor->valid()) + m_pHyprcursor->loadThemeStyle(m_sCurrentStyleInfo); + + setCursorFromName("left_ptr"); + + for (auto& m : g_pCompositor->m_vMonitors) { + m->forceFullFrames = 5; + g_pCompositor->scheduleFrameForMonitor(m.get()); + } +} + +void CCursorManager::changeTheme(const std::string& name, const int size) { + m_pHyprcursor = std::make_unique(name.empty() ? "" : name.c_str()); + m_szTheme = name; + m_iSize = size; + + setenv("XCURSOR_SIZE", std::to_string(m_iSize).c_str(), true); + setenv("XCURSOR_THEME", name.c_str(), true); + + updateTheme(); +} diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp new file mode 100644 index 00000000..b1c49b31 --- /dev/null +++ b/src/managers/CursorManager.hpp @@ -0,0 +1,69 @@ +#pragma once + +#include +#include +#include +#include "../includes.hpp" +#include "../helpers/Vector2D.hpp" + +struct wlr_buffer; +struct wlr_xcursor_manager; + +class CCursorManager { + public: + CCursorManager(); + + wlr_buffer* getCursorBuffer(); + + void setCursorFromName(const std::string& name); + void setCursorSurface(wlr_surface* surf, const Vector2D& hotspot); + + void changeTheme(const std::string& name, const int size); + void updateTheme(); + SCursorImageData dataFor(const std::string& name); // for xwayland + + void tickAnimatedCursor(); + + class CCursorBuffer { + public: + CCursorBuffer(cairo_surface_t* surf, const Vector2D& size, const Vector2D& hotspot); + ~CCursorBuffer(); + + struct SCursorWlrBuffer { + wlr_buffer base; + cairo_surface_t* surface = nullptr; + bool dropped = false; + CCursorBuffer* parent = nullptr; + } wlrBuffer; + + private: + Vector2D size; + Vector2D hotspot; + + friend class CCursorManager; + }; + + void dropBufferRef(CCursorBuffer* ref); + + bool m_bOurBufferConnected = false; + + private: + std::vector> m_vCursorBuffers; + + std::unique_ptr m_pHyprcursor; + + std::string m_szTheme = ""; + int m_iSize = 24; + float m_fCursorScale = 1.0; + + Hyprcursor::SCursorStyleInfo m_sCurrentStyleInfo; + + wl_event_source* m_pAnimationTimer = nullptr; + int m_iCurrentAnimationFrame = 0; + Hyprcursor::SCursorShapeData m_sCurrentCursorShapeData; + + // xcursor fallback + wlr_xcursor_manager* m_pWLRXCursorMgr = nullptr; +}; + +inline std::unique_ptr g_pCursorManager; \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 2d72280c..59771fcf 100644 --- a/src/meson.build +++ b/src/meson.build @@ -11,6 +11,7 @@ executable('Hyprland', src, dependency('wayland-client'), wlroots.get_variable('wlroots'), dependency('cairo'), + dependency('hyprcursor'), dependency('hyprlang', version: '>= 0.3.2'), dependency('libdrm'), dependency('egl'), diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 4e76a972..fd3309e1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -4,6 +4,7 @@ #include "../helpers/Region.hpp" #include #include "../config/ConfigValue.hpp" +#include "../managers/CursorManager.hpp" extern "C" { #include @@ -2193,7 +2194,7 @@ void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { if (m_bCursorHidden && !force) return; - wlr_cursor_set_xcursor(g_pCompositor->m_sWLRCursor, g_pCompositor->m_sWLRXCursorMgr, name.c_str()); + g_pCursorManager->setCursorFromName(name); } void CHyprRenderer::ensureCursorRenderingMode() { From 7e41e5146d124aa1161a73c249d41ad60f1bb162 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 18:00:37 +0000 Subject: [PATCH 0087/2897] cursormgr: add fallbacks for unknown cursors --- src/managers/CursorManager.cpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index ae765016..dc62bb74 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -107,8 +107,20 @@ void CCursorManager::setCursorFromName(const std::string& name) { m_sCurrentCursorShapeData = m_pHyprcursor->getShape(name.c_str(), m_sCurrentStyleInfo); if (m_sCurrentCursorShapeData.images.size() < 1) { - Debug::log(ERR, "BUG THIS: No cursor returned by getShape()"); - return; + // fallback to a default if available + constexpr const std::array fallbackShapes = {"default", "left_ptr"}; + + for (auto& s : fallbackShapes) { + m_sCurrentCursorShapeData = m_pHyprcursor->getShape(s, m_sCurrentStyleInfo); + + if (m_sCurrentCursorShapeData.images.size() > 0) + break; + } + + if (m_sCurrentCursorShapeData.images.size() < 1) { + Debug::log(ERR, "BUG THIS: No fallback found for a cursor in setCursorFromName"); + return; + } } m_vCursorBuffers.emplace_back(std::make_unique(m_sCurrentCursorShapeData.images[0].surface, From 18a35b140681767e055bb78d268efafab8664f90 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 18:04:33 +0000 Subject: [PATCH 0088/2897] cursormgr: fix memory leak with cursor buffers --- src/managers/CursorManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index dc62bb74..ff644010 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -127,9 +127,12 @@ void CCursorManager::setCursorFromName(const std::string& name) { Vector2D{m_sCurrentCursorShapeData.images[0].size, m_sCurrentCursorShapeData.images[0].size}, Vector2D{m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY})); - if (g_pCompositor->m_sWLRCursor) + if (g_pCompositor->m_sWLRCursor) { wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY, m_fCursorScale); + if (m_vCursorBuffers.size() > 1) + wlr_buffer_drop(&m_vCursorBuffers.front()->wlrBuffer.base); + } m_bOurBufferConnected = true; From 26cd1bf949d0460b754fe3b1ae7f06bd4b2535ee Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 18:12:55 +0000 Subject: [PATCH 0089/2897] input: fix minor default cursor reset conditions --- src/events/Layers.cpp | 4 +++- src/events/Windows.cpp | 3 +++ src/managers/input/InputManager.cpp | 2 ++ src/managers/input/InputManager.hpp | 4 +++- 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index db237690..4e61baa0 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -154,6 +154,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { g_pInputManager->getMouseCoordsInternal() - Vector2D(layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, layersurface->layerSurface->surface, LOCAL.x, LOCAL.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, 0, LOCAL.x, LOCAL.y); + g_pInputManager->m_bEmptyFocusCursorSet = false; } layersurface->position = Vector2D(layersurface->geometry.x, layersurface->geometry.y); @@ -235,7 +236,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface); - if (!foundSurface) { + if (!foundSurface && g_pCompositor->m_pLastWindow) { // if there isn't any, focus the last window const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); @@ -347,6 +348,7 @@ void Events::listener_commitLayerSurface(void* owner, void* data) { g_pInputManager->getMouseCoordsInternal() - Vector2D(layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y); wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, layersurface->layerSurface->surface, LOCAL.x, LOCAL.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, 0, LOCAL.x, LOCAL.y); + g_pInputManager->m_bEmptyFocusCursorSet = false; } else if (!layersurface->layerSurface->current.keyboard_interactive && (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()) && layersurface->keyboardExclusive) { g_pInputManager->refocus(); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 84040ad5..2da54583 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -716,6 +716,9 @@ void Events::listener_unmapWindow(void* owner, void* data) { if (PWINDOWCANDIDATE != g_pCompositor->m_pLastWindow && PWINDOWCANDIDATE) g_pCompositor->focusWindow(PWINDOWCANDIDATE); + if (!PWINDOWCANDIDATE && g_pCompositor->getWindowsOnWorkspace(PWINDOW->m_iWorkspaceID) == 0) + g_pInputManager->refocus(); + g_pInputManager->sendMotionEventsToFocused(); // CWindow::onUnmap will remove this window's active status, but we can't really do it above. diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 32a9fbae..9072f27a 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -69,6 +69,8 @@ void CInputManager::sendMotionEventsToFocused() { const auto LOCAL = getMouseCoordsInternal() - (PWINDOW ? PWINDOW->m_vRealPosition.goal() : (PLS ? Vector2D{PLS->geometry.x, PLS->geometry.y} : Vector2D{})); + m_bEmptyFocusCursorSet = false; + wlr_seat_pointer_notify_enter(g_pCompositor->m_sSeat.seat, g_pCompositor->m_pLastFocus, LOCAL.x, LOCAL.y); wlr_seat_pointer_notify_motion(g_pCompositor->m_sSeat.seat, now.tv_sec * 1000 + now.tv_nsec / 10000000, LOCAL.x, LOCAL.y); } diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index cef8386f..fd3aefe5 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -191,13 +191,15 @@ class CInputManager { CWindow* m_pLastMouseFocus = nullptr; wlr_surface* m_pLastMouseSurface = nullptr; + // + bool m_bEmptyFocusCursorSet = false; + private: bool m_bCursorImageOverridden = false; eBorderIconDirection m_eBorderIconDirection = BORDERICON_NONE; // for click behavior override eClickBehaviorMode m_ecbClickBehavior = CLICKMODE_DEFAULT; - bool m_bEmptyFocusCursorSet = false; Vector2D m_vLastCursorPosFloored = Vector2D(); void processMouseDownNormal(wlr_pointer_button_event* e); From 739c5bc98c6037101e5744827dd66e696a4e9ecd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 21:54:33 +0000 Subject: [PATCH 0090/2897] cursormgr: fix invalid access to hyprcursor in xwayland init fixes #5048 --- src/events/Misc.cpp | 6 +----- src/managers/CursorManager.cpp | 16 ++++++++++++++++ src/managers/CursorManager.hpp | 2 ++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp index d7e3a849..8d0a9710 100644 --- a/src/events/Misc.cpp +++ b/src/events/Misc.cpp @@ -70,11 +70,7 @@ void Events::listener_readyXWayland(wl_listener* listener, void* data) { wlr_xwayland_set_seat(g_pXWaylandManager->m_sWLRXWayland, g_pCompositor->m_sSeat.seat); - const auto CURSOR = g_pCursorManager->dataFor("left_ptr"); - if (CURSOR.surface) { - wlr_xwayland_set_cursor(g_pXWaylandManager->m_sWLRXWayland, cairo_image_surface_get_data(CURSOR.surface), cairo_image_surface_get_stride(CURSOR.surface), CURSOR.size, - CURSOR.size, CURSOR.hotspotX, CURSOR.hotspotY); - } + g_pCursorManager->setXWaylandCursor(g_pXWaylandManager->m_sWLRXWayland); const auto ROOT = xcb_setup_roots_iterator(xcb_get_setup(XCBCONNECTION)).data->root; auto cookie = xcb_get_property(XCBCONNECTION, 0, ROOT, HYPRATOMS["_NET_SUPPORTING_WM_CHECK"], XCB_ATOM_ANY, 0, 2048); diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index ff644010..2467b593 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -167,6 +167,10 @@ void CCursorManager::tickAnimatedCursor() { } SCursorImageData CCursorManager::dataFor(const std::string& name) { + + if (!m_pHyprcursor->valid()) + return {}; + const auto IMAGES = m_pHyprcursor->getShape(name.c_str(), m_sCurrentStyleInfo); if (IMAGES.images.empty()) @@ -175,6 +179,18 @@ SCursorImageData CCursorManager::dataFor(const std::string& name) { return IMAGES.images[0]; } +void CCursorManager::setXWaylandCursor(wlr_xwayland* xwayland) { + const auto CURSOR = dataFor("left_ptr"); + if (CURSOR.surface) { + wlr_xwayland_set_cursor(xwayland, cairo_image_surface_get_data(CURSOR.surface), cairo_image_surface_get_stride(CURSOR.surface), CURSOR.size, CURSOR.size, CURSOR.hotspotX, + CURSOR.hotspotY); + } else if (const auto XCURSOR = wlr_xcursor_manager_get_xcursor(m_pWLRXCursorMgr, "left_ptr", 1); XCURSOR) { + wlr_xwayland_set_cursor(xwayland, XCURSOR->images[0]->buffer, XCURSOR->images[0]->width * 4, XCURSOR->images[0]->width, XCURSOR->images[0]->height, + XCURSOR->images[0]->hotspot_x, XCURSOR->images[0]->hotspot_y); + } else + Debug::log(ERR, "CursorManager: no valid cursor for xwayland"); +} + void CCursorManager::updateTheme() { float highestScale = 1.0; diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index b1c49b31..0e8d99bc 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -8,6 +8,7 @@ struct wlr_buffer; struct wlr_xcursor_manager; +struct wlr_xwayland; class CCursorManager { public: @@ -21,6 +22,7 @@ class CCursorManager { void changeTheme(const std::string& name, const int size); void updateTheme(); SCursorImageData dataFor(const std::string& name); // for xwayland + void setXWaylandCursor(wlr_xwayland* xwayland); void tickAnimatedCursor(); From 2ed032a7fd140ee85483a891fa63c16668019577 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 22:37:49 +0000 Subject: [PATCH 0091/2897] xwayland: fix no_xwayland compiles --- src/helpers/XWaylandStubs.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/XWaylandStubs.hpp b/src/helpers/XWaylandStubs.hpp index 89e0b41f..c21041cd 100644 --- a/src/helpers/XWaylandStubs.hpp +++ b/src/helpers/XWaylandStubs.hpp @@ -167,4 +167,6 @@ inline wlr_xwayland_surface* wlr_xwayland_surface_try_from_wlr_surface(wlr_surfa inline bool wlr_xwayland_or_surface_wants_focus(const wlr_xwayland_surface*) { return false; -} \ No newline at end of file +} + +inline void wlr_xwayland_set_cursor(wlr_xwayland* wlr_xwayland, uint8_t* pixels, uint32_t stride, uint32_t width, uint32_t height, int32_t hotspot_x, int32_t hotspot_y) {} \ No newline at end of file From b0f98a3d3e9e5f5f7f89fa4e855dbeb860e7a0c4 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 9 Mar 2024 22:39:23 +0000 Subject: [PATCH 0092/2897] compositor: reject focus to noFocus OR xwayland windows fixes #4922 --- src/Compositor.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 5697adbf..f061bf6b 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -930,6 +930,9 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { return; } + if (pWindow && pWindow->m_bIsX11 && pWindow->m_iX11Type == 2 && !wlr_xwayland_or_surface_wants_focus(pWindow->m_uSurface.xwayland)) + return; + g_pLayoutManager->getCurrentLayout()->bringWindowToTop(pWindow); if (!pWindow || !windowValidMapped(pWindow)) { From 335506d5557b91a0baf974750c353443841e691b Mon Sep 17 00:00:00 2001 From: Matt Wyatt Date: Sat, 9 Mar 2024 17:19:48 -0600 Subject: [PATCH 0093/2897] constraints: only warp cursor on deactivate if constraint is locked. (#5056) --- src/desktop/Constraint.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/desktop/Constraint.cpp b/src/desktop/Constraint.cpp index ea89037f..662f0990 100644 --- a/src/desktop/Constraint.cpp +++ b/src/desktop/Constraint.cpp @@ -94,7 +94,9 @@ void CConstraint::deactivate() { wlr_pointer_constraint_v1_send_deactivated(m_pConstraint); m_bActive = false; - g_pCompositor->warpCursorTo(logicPositionHint(), true); + + if (isLocked()) + g_pCompositor->warpCursorTo(logicPositionHint(), true); if (m_pConstraint->lifetime == ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_ONESHOT) m_bDead = true; From 0c28d4e334532e8a8edacf36bcaf4e6b973ea398 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Mar 2024 16:56:32 +0000 Subject: [PATCH 0094/2897] window: prevent vector modification segfault while iterating oops, updateWindow can modify the vec --- src/Window.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Window.cpp b/src/Window.cpp index c63209a0..4c8ff509 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -194,7 +194,14 @@ void CWindow::updateWindowDecos() { m_vDecosToRemove.clear(); + // make a copy because updateWindow can remove decos. + std::vector decos; + for (auto& wd : m_dWindowDecorations) { + decos.push_back(wd.get()); + } + + for (auto& wd : decos) { wd->updateWindow(this); } } From 981296f101cf79176a8da7a1aa64fa297b2976dc Mon Sep 17 00:00:00 2001 From: NotAShelf Date: Sun, 10 Mar 2024 22:52:54 +0300 Subject: [PATCH 0095/2897] flake: bump inputs (#5066) --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 36a509b1..341286a1 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ ] }, "locked": { - "lastModified": 1709942067, - "narHash": "sha256-DGU4zQDwIx6pXM6oHdA+89UU/QjqE05HiXOvigECJjI=", + "lastModified": 1710091028, + "narHash": "sha256-yFk2kc8J2kVh0RWlwT+PQf0bpfUNcROOcRYcyQJbpk4=", "owner": "hyprwm", "repo": "hyprcursor", - "rev": "a2233d4a2a58233457712acfd88d10a2a8a85711", + "rev": "05db7dfd7fc261e0195e54f8a6d655d4f370e70f", "type": "github" }, "original": { @@ -94,11 +94,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1709703039, - "narHash": "sha256-6hqgQ8OK6gsMu1VtcGKBxKQInRLHtzulDo9Z5jxHEFY=", + "lastModified": 1709961763, + "narHash": "sha256-6H95HGJHhEZtyYA3rIQpvamMKAGoa8Yh2rFV29QnuGw=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9df3e30ce24fd28c7b3e2de0d986769db5d6225d", + "rev": "3030f185ba6a4bf4f18b87f345f104e6a6961f34", "type": "github" }, "original": { From 0a1632a79f08ea5a2581832263354e06e9fab1f0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Mar 2024 22:27:17 +0000 Subject: [PATCH 0096/2897] dwindle: preserve fs state on switchWindows fixes #2842 --- src/Compositor.hpp | 2 +- src/layout/DwindleLayout.cpp | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index b1033e89..84667656 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -175,7 +175,7 @@ class CCompositor { void swapActiveWorkspaces(CMonitor*, CMonitor*); CMonitor* getMonitorFromString(const std::string&); bool workspaceIDOutOfBounds(const int64_t&); - void setWindowFullscreen(CWindow*, bool, eFullscreenMode); + void setWindowFullscreen(CWindow*, bool, eFullscreenMode mode = FULLSCREEN_INVALID); void updateFullscreenFadeOnWorkspace(CWorkspace*); CWindow* getX11Parent(CWindow*); void scheduleFrameForMonitor(CMonitor*); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 2f66482a..cc4bc0b3 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -963,9 +963,16 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { auto PNODE = getNodeFromWindow(pWindow); auto PNODE2 = getNodeFromWindow(pWindow2); - if (!PNODE2 || !PNODE) { + if (!PNODE2 || !PNODE) return; - } + + const bool FS1 = pWindow->m_bIsFullscreen; + const bool FS2 = pWindow2->m_bIsFullscreen; + + if (FS1) + g_pCompositor->setWindowFullscreen(pWindow, false); + if (FS2) + g_pCompositor->setWindowFullscreen(pWindow2, false); SDwindleNodeData* ACTIVE1 = nullptr; SDwindleNodeData* ACTIVE2 = nullptr; @@ -982,9 +989,8 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { // recalc the workspace getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive(); - if (PNODE2->workspaceID != PNODE->workspaceID) { + if (PNODE2->workspaceID != PNODE->workspaceID) getMasterNodeOnWorkspace(PNODE2->workspaceID)->recalcSizePosRecursive(); - } if (ACTIVE1) { ACTIVE1->box = PNODE->box; @@ -1000,6 +1006,11 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { g_pHyprRenderer->damageWindow(pWindow); g_pHyprRenderer->damageWindow(pWindow2); + + if (FS1) + g_pCompositor->setWindowFullscreen(pWindow2, true); + if (FS2) + g_pCompositor->setWindowFullscreen(pWindow, true); } void CHyprDwindleLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exact) { From 220144276b8789d05e58df3e0452314c11b64728 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 10 Mar 2024 22:31:49 +0000 Subject: [PATCH 0097/2897] layout: unfullscreen on toggle into tiled fullscreen fixes a bug where the tiled window would be on top --- src/layout/IHyprLayout.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 7269bab7..433434de 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -461,6 +461,11 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { pWindow->moveToWorkspace(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); pWindow->updateGroupOutputs(); + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); + + if (PWORKSPACE->m_bHasFullscreenWindow) + g_pCompositor->setWindowFullscreen(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), false); + // save real pos cuz the func applies the default 5,5 mid const auto PSAVEDPOS = pWindow->m_vRealPosition.goal(); const auto PSAVEDSIZE = pWindow->m_vRealSize.goal(); From 66330281ff19e84c986c5ce639b670929e5dadd6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 11 Mar 2024 01:39:00 +0000 Subject: [PATCH 0098/2897] config: report errors from sourced files --- src/config/ConfigManager.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 0409140a..618a6294 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -2243,6 +2243,8 @@ std::optional CConfigManager::handleSource(const std::string& comma return err; } + std::string errorsFromParsing; + for (size_t i = 0; i < glob_buf->gl_pathc; i++) { auto value = absolutePath(glob_buf->gl_pathv[i], configCurrentPath); @@ -2268,12 +2270,17 @@ std::optional CConfigManager::handleSource(const std::string& comma auto configCurrentPathBackup = configCurrentPath; configCurrentPath = value; - m_pConfig->parseFile(value.c_str()); + const auto THISRESULT = m_pConfig->parseFile(value.c_str()); configCurrentPath = configCurrentPathBackup; + + if (THISRESULT.error && errorsFromParsing.empty()) + errorsFromParsing += THISRESULT.getError(); } - return {}; + if (errorsFromParsing.empty()) + return {}; + return errorsFromParsing; } std::optional CConfigManager::handleEnv(const std::string& command, const std::string& value) { From 0fc9d45e4be40cb148fcee2ae6a0574ae63f29aa Mon Sep 17 00:00:00 2001 From: Lucas Reis Date: Mon, 11 Mar 2024 15:31:39 -0400 Subject: [PATCH 0099/2897] core: Fix typo and check grandchild PID in spawn() (#5070) --- src/managers/KeybindManager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 6bcc7d3d..5178e848 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -792,9 +792,9 @@ uint64_t CKeybindManager::spawnRaw(std::string args) { close(socket[1]); read(socket[0], &grandchild, sizeof(grandchild)); close(socket[0]); - // clear child and leave child to init + // clear child and leave grandchild to init waitpid(child, NULL, 0); - if (child < 0) { + if (grandchild < 0) { Debug::log(LOG, "Fail to create the second fork"); return 0; } From a065b481f32f4297596a9cd9c538794fd4669b1a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 11 Mar 2024 20:33:21 +0000 Subject: [PATCH 0100/2897] cursormgr: use XCURSOR_THEME for x themes --- src/managers/CursorManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index 2467b593..c3916e4b 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -33,7 +33,7 @@ CCursorManager::CCursorManager() { if (m_iSize == 0) m_iSize = 24; - m_pWLRXCursorMgr = wlr_xcursor_manager_create(nullptr, m_iSize); + m_pWLRXCursorMgr = wlr_xcursor_manager_create(getenv("XCURSOR_THEME"), m_iSize); wlr_xcursor_manager_load(m_pWLRXCursorMgr, 1.0); m_pAnimationTimer = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, ::cursorAnimTimer, nullptr); From f1ec0ba4670edbacfded296c849f0c2bcd64f69c Mon Sep 17 00:00:00 2001 From: Ikko Eltociear Ashimine Date: Wed, 13 Mar 2024 00:26:42 +0900 Subject: [PATCH 0101/2897] keybinds: Fix typo (#5081) minor fix --- src/managers/KeybindManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 5178e848..26326104 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -530,7 +530,7 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi const auto KBKEY = xkb_keysym_from_name(k.key.c_str(), XKB_KEYSYM_CASE_INSENSITIVE); if (KBKEY == 0) { - // Keysym failed to resolve from the key name of the the currently iterated bind. + // Keysym failed to resolve from the key name of the currently iterated bind. // This happens for names such as `switch:off:Lid Switch` as well as some keys // (such as yen and ro). // From 5da9591775cbe6b34273c292f1ba0c2ccac8f23c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 12 Mar 2024 15:37:40 +0000 Subject: [PATCH 0102/2897] config: more safety around monitor keyword ref https://github.com/hyprwm/hyprland-wiki/issues/523 --- src/config/ConfigManager.cpp | 59 ++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 618a6294..09733596 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1552,6 +1552,8 @@ std::optional CConfigManager::handleMonitor(const std::string& comm return {}; } + std::string error = ""; + if (ARGS[1].starts_with("pref")) { newrule.resolution = Vector2D(); } else if (ARGS[1].starts_with("highrr")) { @@ -1562,30 +1564,43 @@ std::optional CConfigManager::handleMonitor(const std::string& comm newrule.resolution = Vector2D(newrule.drmMode.hdisplay, newrule.drmMode.vdisplay); newrule.refreshRate = newrule.drmMode.vrefresh / 1000; } else { - newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x'))); - newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@'))); - if (ARGS[1].contains("@")) - newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1)); + if (!ARGS[1].contains("x")) { + error += "invalid resolution "; + newrule.resolution = Vector2D(); + } else { + newrule.resolution.x = stoi(ARGS[1].substr(0, ARGS[1].find_first_of('x'))); + newrule.resolution.y = stoi(ARGS[1].substr(ARGS[1].find_first_of('x') + 1, ARGS[1].find_first_of('@'))); + + if (ARGS[1].contains("@")) + newrule.refreshRate = stof(ARGS[1].substr(ARGS[1].find_first_of('@') + 1)); + } } if (ARGS[2].starts_with("auto")) { newrule.offset = Vector2D(-INT32_MAX, -INT32_MAX); } else { - newrule.offset.x = stoi(ARGS[2].substr(0, ARGS[2].find_first_of('x'))); - newrule.offset.y = stoi(ARGS[2].substr(ARGS[2].find_first_of('x') + 1)); + if (!ARGS[2].contains("x")) { + error += "invalid offset "; + newrule.offset = Vector2D(-INT32_MAX, -INT32_MAX); + } else { + newrule.offset.x = stoi(ARGS[2].substr(0, ARGS[2].find_first_of('x'))); + newrule.offset.y = stoi(ARGS[2].substr(ARGS[2].find_first_of('x') + 1)); + } } - std::string error = ""; - if (ARGS[3].starts_with("auto")) { newrule.scale = -1; } else { - newrule.scale = stof(ARGS[3]); + if (!isNumber(ARGS[3], true)) + error += "invalid scale "; + else { + newrule.scale = stof(ARGS[3]); - if (newrule.scale < 0.25f) { - error = "invalid scale"; - newrule.scale = 1; + if (newrule.scale < 0.25f) { + error += "invalid scale "; + newrule.scale = 1; + } } } @@ -1599,9 +1614,29 @@ std::optional CConfigManager::handleMonitor(const std::string& comm newrule.enable10bit = ARGS[argno + 1] == "10"; argno++; } else if (ARGS[argno] == "transform") { + if (!isNumber(ARGS[argno + 1])) { + error = "invalid transform "; + argno++; + continue; + } + + const auto NUM = std::stoi(ARGS[argno + 1]); + + if (NUM < 0 || NUM > 7) { + error = "invalid transform "; + argno++; + continue; + } + newrule.transform = (wl_output_transform)std::stoi(ARGS[argno + 1]); argno++; } else if (ARGS[argno] == "vrr") { + if (!isNumber(ARGS[argno + 1])) { + error = "invalid vrr "; + argno++; + continue; + } + newrule.vrr = std::stoi(ARGS[argno + 1]); argno++; } else if (ARGS[argno] == "workspace") { From 6c53d4d82fd81aaa8aeb8c89ece1b88455a1f2a1 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Tue, 12 Mar 2024 21:35:41 +0200 Subject: [PATCH 0103/2897] Nix: remove hyprland-unwrapped leftover --- flake.nix | 1 - nix/overlays.nix | 1 - 2 files changed, 2 deletions(-) diff --git a/flake.nix b/flake.nix index e97ba1c9..9bee5efc 100644 --- a/flake.nix +++ b/flake.nix @@ -77,7 +77,6 @@ # hyprland-packages hyprland - hyprland-unwrapped hyprland-debug hyprland-legacy-renderer # hyprland-extras diff --git a/nix/overlays.nix b/nix/overlays.nix index c216ff53..68c196d9 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -38,7 +38,6 @@ in { udis86 = final.udis86-hyprland; # explicit override until decided on breaking change of the name inherit date; }; - hyprland-unwrapped = final.hyprland.override {wrapRuntimeDeps = false;}; hyprland-debug = final.hyprland.override {debug = true;}; hyprland-legacy-renderer = final.hyprland.override {legacyRenderer = true;}; hyprland-nvidia = From 7ea555da7fff0a2457e24e06bbd34986c0755025 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Tue, 12 Mar 2024 19:09:20 -0700 Subject: [PATCH 0104/2897] master: Fix master layout window focus and scroll (#5074) * fix master switch window scrolling * fix some more dispatchers and remove some duplicate code * refactor and remove duplicate code * fix focusmonitor: https://github.com/hyprwm/Hyprland/issues/5006#issuecomment-1986977255 * change check --- src/Compositor.cpp | 5 ++ src/layout/MasterLayout.cpp | 87 +++++++++++---------------------- src/layout/MasterLayout.hpp | 4 +- src/managers/KeybindManager.cpp | 6 ++- 4 files changed, 39 insertions(+), 63 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f061bf6b..4d3fd65b 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2297,6 +2297,11 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode return; } + if (pWindow->m_bIsFullscreen == on) { + Debug::log(LOG, "Window is already in the required fullscreen state"); + return; + } + const auto PMONITOR = getMonitorFromID(pWindow->m_iMonitorID); const auto PWORKSPACE = getWorkspaceByID(pWindow->m_iWorkspaceID); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index d266d816..0a51401f 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -245,8 +245,7 @@ void CHyprMasterLayout::onWindowRemovedTiling(CWindow* pWindow) { pWindow->updateSpecialRenderData(); - if (pWindow->m_bIsFullscreen) - g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); + g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); if (PNODE->isMaster && (MASTERSLEFT <= 1 || *SMALLSPLIT == 1)) { // find a new master from top of the list @@ -1017,8 +1016,6 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { if (!PNODE2 || !PNODE) return; - const auto inheritFullscreen = prepareLoseFocus(pWindow); - if (PNODE->workspaceID != PNODE2->workspaceID) { std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID); std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); @@ -1034,8 +1031,6 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { g_pHyprRenderer->damageWindow(pWindow); g_pHyprRenderer->damageWindow(pWindow2); - - prepareNewFocus(pWindow2, inheritFullscreen); } void CHyprMasterLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exact) { @@ -1076,35 +1071,27 @@ CWindow* CHyprMasterLayout::getNextWindow(CWindow* pWindow, bool next) { return CANDIDATE == nodes.end() ? nullptr : CANDIDATE->pWindow; } -bool CHyprMasterLayout::prepareLoseFocus(CWindow* pWindow) { - if (!pWindow) - return false; - - //if the current window is fullscreen, make it normal again if we are about to lose focus - if (pWindow->m_bIsFullscreen) { - g_pCompositor->setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); - static auto INHERIT = CConfigValue("master:inherit_fullscreen"); - return *INHERIT == 1; - } - - return false; -} - -void CHyprMasterLayout::prepareNewFocus(CWindow* pWindow, bool inheritFullscreen) { - if (!pWindow) - return; - - if (inheritFullscreen) - g_pCompositor->setWindowFullscreen(pWindow, true, g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_efFullscreenMode); -} - std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::string message) { auto switchToWindow = [&](CWindow* PWINDOWTOCHANGETO) { if (!g_pCompositor->windowValidMapped(PWINDOWTOCHANGETO)) return; - g_pCompositor->focusWindow(PWINDOWTOCHANGETO); - g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->middle()); + if (header.pWindow->m_bIsFullscreen) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID); + const auto FSMODE = PWORKSPACE->m_efFullscreenMode; + static auto INHERITFULLSCREEN = CConfigValue("master:inherit_fullscreen"); + g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + if (*INHERITFULLSCREEN) + g_pCompositor->setWindowFullscreen(PWINDOWTOCHANGETO, true, FSMODE); + } else { + g_pCompositor->focusWindow(PWINDOWTOCHANGETO); + g_pCompositor->warpCursorTo(PWINDOWTOCHANGETO->middle()); + } + + g_pInputManager->m_pForcedFocus = PWINDOWTOCHANGETO; + g_pInputManager->simulateMouseMovement(); + g_pInputManager->m_pForcedFocus = nullptr; }; CVarList vars(message, 0, ' '); @@ -1138,23 +1125,19 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto NEWCHILD = PMASTER->pWindow; if (PMASTER->pWindow != PWINDOW) { - const auto NEWMASTER = PWINDOW; - const bool newFocusToChild = vars.size() >= 2 && vars[1] == "child"; - const bool inheritFullscreen = prepareLoseFocus(NEWMASTER); + const auto NEWMASTER = PWINDOW; + const bool newFocusToChild = vars.size() >= 2 && vars[1] == "child"; switchWindows(NEWMASTER, NEWCHILD); const auto NEWFOCUS = newFocusToChild ? NEWCHILD : NEWMASTER; switchToWindow(NEWFOCUS); - prepareNewFocus(NEWFOCUS, inheritFullscreen); } else { for (auto& n : m_lMasterNodesData) { if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) { - const auto NEWMASTER = n.pWindow; - const bool inheritFullscreen = prepareLoseFocus(NEWCHILD); + const auto NEWMASTER = n.pWindow; switchWindows(NEWMASTER, NEWCHILD); const bool newFocusToMaster = vars.size() >= 2 && vars[1] == "master"; const auto NEWFOCUS = newFocusToMaster ? NEWMASTER : NEWCHILD; switchToWindow(NEWFOCUS); - prepareNewFocus(NEWFOCUS, inheritFullscreen); break; } } @@ -1172,8 +1155,6 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const bool inheritFullscreen = prepareLoseFocus(PWINDOW); - const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); if (!PMASTER) @@ -1181,7 +1162,6 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (PMASTER->pWindow != PWINDOW) { switchToWindow(PMASTER->pWindow); - prepareNewFocus(PMASTER->pWindow, inheritFullscreen); } else if (vars.size() >= 2 && vars[1] == "master") { return 0; } else { @@ -1189,7 +1169,6 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri for (auto& n : m_lMasterNodesData) { if (n.workspaceID == PMASTER->workspaceID && !n.isMaster) { switchToWindow(n.pWindow); - prepareNewFocus(n.pWindow, inheritFullscreen); break; } } @@ -1202,22 +1181,16 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const bool inheritFullscreen = prepareLoseFocus(PWINDOW); - const auto PNEXTWINDOW = getNextWindow(PWINDOW, true); switchToWindow(PNEXTWINDOW); - prepareNewFocus(PNEXTWINDOW, inheritFullscreen); } else if (command == "cycleprev") { const auto PWINDOW = header.pWindow; if (!PWINDOW) return 0; - const bool inheritFullscreen = prepareLoseFocus(PWINDOW); - const auto PPREVWINDOW = getNextWindow(PWINDOW, false); switchToWindow(PPREVWINDOW); - prepareNewFocus(PPREVWINDOW, inheritFullscreen); } else if (command == "swapnext") { if (!g_pCompositor->windowValidMapped(header.pWindow)) return 0; @@ -1230,9 +1203,9 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, true); if (PWINDOWTOSWAPWITH) { - prepareLoseFocus(header.pWindow); + g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); switchWindows(header.pWindow, PWINDOWTOSWAPWITH); - g_pCompositor->focusWindow(header.pWindow); + switchToWindow(header.pWindow); } } else if (command == "swapprev") { if (!g_pCompositor->windowValidMapped(header.pWindow)) @@ -1246,9 +1219,9 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PWINDOWTOSWAPWITH = getNextWindow(header.pWindow, false); if (PWINDOWTOSWAPWITH) { - prepareLoseFocus(header.pWindow); + g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); switchWindows(header.pWindow, PWINDOWTOSWAPWITH); - g_pCompositor->focusWindow(header.pWindow); + switchToWindow(header.pWindow); } } else if (command == "addmaster") { if (!g_pCompositor->windowValidMapped(header.pWindow)) @@ -1265,7 +1238,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) return 0; - prepareLoseFocus(header.pWindow); + g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); if (!PNODE || PNODE->isMaster) { // first non-master node @@ -1297,7 +1270,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (WINDOWS < 2 || MASTERS < 2) return 0; - prepareLoseFocus(header.pWindow); + g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); if (!PNODE || !PNODE->isMaster) { // first non-master node @@ -1318,7 +1291,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - prepareLoseFocus(PWINDOW); + g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); @@ -1373,9 +1346,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri nd.isMaster = true; const auto NEWMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), nd); m_lMasterNodesData.splice(OLDMASTERIT, m_lMasterNodesData, NEWMASTERIT); - const bool inheritFullscreen = prepareLoseFocus(PWINDOW); switchToWindow(nd.pWindow); - prepareNewFocus(nd.pWindow, inheritFullscreen); OLDMASTER->isMaster = false; m_lMasterNodesData.splice(m_lMasterNodesData.end(), m_lMasterNodesData, OLDMASTERIT); break; @@ -1401,9 +1372,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri nd.isMaster = true; const auto NEWMASTERIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), nd); m_lMasterNodesData.splice(OLDMASTERIT, m_lMasterNodesData, NEWMASTERIT); - const bool inheritFullscreen = prepareLoseFocus(PWINDOW); switchToWindow(nd.pWindow); - prepareNewFocus(nd.pWindow, inheritFullscreen); OLDMASTER->isMaster = false; m_lMasterNodesData.splice(m_lMasterNodesData.begin(), m_lMasterNodesData, OLDMASTERIT); break; @@ -1430,7 +1399,7 @@ void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarLi if (!PWINDOW) return; - prepareLoseFocus(PWINDOW); + g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index d48aefdc..6f8ea120 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -87,8 +87,6 @@ class CHyprMasterLayout : public IHyprLayout { void calculateWorkspace(const int&); CWindow* getNextWindow(CWindow*, bool); int getMastersOnWorkspace(const int&); - bool prepareLoseFocus(CWindow*); - void prepareNewFocus(CWindow*, bool inherit_fullscreen); friend struct SMasterNodeData; friend struct SMasterWorkspaceData; @@ -108,4 +106,4 @@ struct std::formatter : std::formatter { std::format_to(out, ", window: {:x}", node->pWindow); return std::format_to(out, "]"); } -}; \ No newline at end of file +}; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 26326104..2125e9ba 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -227,7 +227,6 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { const auto PNEWMAINWORKSPACE = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace); g_pInputManager->unconstrainMouse(); - g_pCompositor->setActiveMonitor(monitor); PNEWMAINWORKSPACE->rememberPrevWorkspace(PWORKSPACE); const auto PNEWWORKSPACE = monitor->specialWorkspaceID != 0 ? g_pCompositor->getWorkspaceByID(monitor->specialWorkspaceID) : PNEWMAINWORKSPACE; @@ -236,10 +235,15 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { if (PNEWWINDOW) { g_pCompositor->focusWindow(PNEWWINDOW); g_pCompositor->warpCursorTo(PNEWWINDOW->middle()); + + g_pInputManager->m_pForcedFocus = PNEWWINDOW; + g_pInputManager->simulateMouseMovement(); + g_pInputManager->m_pForcedFocus = nullptr; } else { g_pCompositor->focusWindow(nullptr); g_pCompositor->warpCursorTo(monitor->middle()); } + g_pCompositor->setActiveMonitor(monitor); return true; } From c58fcfbce2c2e9f12cad7771555ce38b515a3389 Mon Sep 17 00:00:00 2001 From: djvs <2954343+djvs@users.noreply.github.com> Date: Tue, 12 Mar 2024 22:43:22 -0400 Subject: [PATCH 0105/2897] input: add general:resize_corner for manual resizing (#5090) * Resize corner config thing * clang-format --------- Co-authored-by: djvs --- src/config/ConfigManager.cpp | 1 + src/layout/IHyprLayout.cpp | 22 +++++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 09733596..89195a27 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -317,6 +317,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("general:hover_icon_on_border", Hyprlang::INT{1}); m_pConfig->addConfigValue("general:layout", {"dwindle"}); m_pConfig->addConfigValue("general:allow_tearing", Hyprlang::INT{0}); + m_pConfig->addConfigValue("general:resize_corner", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:disable_hyprland_logo", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:disable_splash_rendering", Hyprlang::INT{0}); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 433434de..d2ec1ab1 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -217,7 +217,27 @@ void IHyprLayout::onBeginDragWindow() { m_vLastDragXY = m_vBeginDragXY; // get the grab corner - if (m_vBeginDragXY.x < m_vBeginDragPositionXY.x + m_vBeginDragSizeXY.x / 2.0) { + static auto RESIZECORNER = CConfigValue("general:resize_corner"); + if (*RESIZECORNER != 0 && *RESIZECORNER <= 4) { + switch (*RESIZECORNER) { + case 1: + m_eGrabbedCorner = CORNER_TOPLEFT; + g_pInputManager->setCursorImageUntilUnset("nw-resize"); + break; + case 2: + m_eGrabbedCorner = CORNER_TOPRIGHT; + g_pInputManager->setCursorImageUntilUnset("ne-resize"); + break; + case 3: + m_eGrabbedCorner = CORNER_BOTTOMRIGHT; + g_pInputManager->setCursorImageUntilUnset("se-resize"); + break; + case 4: + m_eGrabbedCorner = CORNER_BOTTOMLEFT; + g_pInputManager->setCursorImageUntilUnset("sw-resize"); + break; + } + } else if (m_vBeginDragXY.x < m_vBeginDragPositionXY.x + m_vBeginDragSizeXY.x / 2.0) { if (m_vBeginDragXY.y < m_vBeginDragPositionXY.y + m_vBeginDragSizeXY.y / 2.0) { m_eGrabbedCorner = CORNER_TOPLEFT; g_pInputManager->setCursorImageUntilUnset("nw-resize"); From 893c55217b15cf0e5fe7eb3eb2d88183df410b9a Mon Sep 17 00:00:00 2001 From: djvs <2954343+djvs@users.noreply.github.com> Date: Tue, 12 Mar 2024 23:38:32 -0400 Subject: [PATCH 0106/2897] input: only override dragging corner on floating (#5092) Co-authored-by: djvs --- src/layout/IHyprLayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index d2ec1ab1..f992899d 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -218,7 +218,7 @@ void IHyprLayout::onBeginDragWindow() { // get the grab corner static auto RESIZECORNER = CConfigValue("general:resize_corner"); - if (*RESIZECORNER != 0 && *RESIZECORNER <= 4) { + if (*RESIZECORNER != 0 && *RESIZECORNER <= 4 && DRAGGINGWINDOW->m_bIsFloating) { switch (*RESIZECORNER) { case 1: m_eGrabbedCorner = CORNER_TOPLEFT; From 3e67ee0f5f66c74c0a0bd4f797361fd100c2e2d2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 13 Mar 2024 15:38:18 +0000 Subject: [PATCH 0107/2897] events: ignore setTitle when title didn't change --- src/events/Windows.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 2da54583..1e547efc 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -901,7 +901,12 @@ void Events::listener_setTitleWindow(void* owner, void* data) { if (!g_pCompositor->windowValidMapped(PWINDOW)) return; - PWINDOW->m_szTitle = g_pXWaylandManager->getTitle(PWINDOW); + const auto NEWTITLE = g_pXWaylandManager->getTitle(PWINDOW); + + if (NEWTITLE == PWINDOW->m_szTitle) + return; + + PWINDOW->m_szTitle = NEWTITLE; g_pEventManager->postEvent(SHyprIPCEvent{"windowtitle", std::format("{:x}", (uintptr_t)PWINDOW)}); EMIT_HOOK_EVENT("windowTitle", PWINDOW); From 164e92f8e376536fff89dac41cde654293e64522 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 14 Mar 2024 18:25:28 +0000 Subject: [PATCH 0108/2897] internal: minor fixups for fading out xwayland windows fixes #4935 --- src/Compositor.cpp | 12 ++++++++---- src/Window.cpp | 6 ++++++ src/Window.hpp | 1 + src/render/Renderer.cpp | 15 ++++++++++----- 4 files changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 4d3fd65b..eda5b5ed 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1433,11 +1433,15 @@ void CCompositor::cleanupFadingOut(const int& monid) { bool valid = windowExists(w); if (!valid || !w->m_bFadingOut || w->m_fAlpha.value() == 0.f) { - if (valid && !w->m_bReadyToDelete) - continue; + if (valid) { + w->m_bFadingOut = false; + + if (!w->m_bReadyToDelete) + continue; + + removeWindowFromVectorSafe(w); + } - w->m_bFadingOut = false; - removeWindowFromVectorSafe(w); std::erase(m_vWindowsFadingOut, w); Debug::log(LOG, "Cleanup: destroyed a window"); diff --git a/src/Window.cpp b/src/Window.cpp index 4c8ff509..06b71763 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1137,3 +1137,9 @@ void CWindow::setSuspended(bool suspend) { wlr_xdg_toplevel_set_suspended(m_uSurface.xdg->toplevel, suspend); m_bSuspended = suspend; } + +bool CWindow::visibleOnMonitor(CMonitor* pMonitor) { + CBox wbox = {m_vRealPosition.value(), m_vRealSize.value()}; + + return wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, wbox.pWlr()); +} diff --git a/src/Window.hpp b/src/Window.hpp index 2a19cfa5..cb4fc057 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -395,6 +395,7 @@ class CWindow { bool canBeTorn(); bool shouldSendFullscreenState(); void setSuspended(bool suspend); + bool visibleOnMonitor(CMonitor* pMonitor); int getRealBorderSize(); void updateSpecialRenderData(); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index fd3309e1..a9c7c11a 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -335,7 +335,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork // Non-floating main for (auto& w : g_pCompositor->m_vWindows) { - if (w->isHidden() && !w->m_bIsMapped && !w->m_bFadingOut) + if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) continue; if (w->m_bIsFloating) @@ -362,7 +362,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork // Non-floating popup for (auto& w : g_pCompositor->m_vWindows) { - if (w->isHidden() && !w->m_bIsMapped && !w->m_bFadingOut) + if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) continue; if (w->m_bIsFloating) @@ -380,7 +380,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork // floating on top for (auto& w : g_pCompositor->m_vWindows) { - if (w->isHidden() && !w->m_bIsMapped && !w->m_bFadingOut) + if (w->isHidden() || (!w->m_bIsMapped && !w->m_bFadingOut)) continue; if (!w->m_bIsFloating || w->m_bPinned) @@ -410,6 +410,9 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* return; } + if (!pWindow->m_bIsMapped) + return; + TRACY_GPU_ZONE("RenderWindow"); const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); @@ -2414,8 +2417,10 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { } for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == PCANDIDATE->m_iWorkspaceID && w->m_bIsFloating && w->m_bCreatedOverFullscreen && !w->isHidden() && (w->m_bIsMapped || w->m_bFadingOut) && - w.get() != PCANDIDATE) + if (w.get() == PCANDIDATE || (!w->m_bIsMapped && !w->m_bFadingOut) || w->isHidden()) + continue; + + if (w->m_iWorkspaceID == PCANDIDATE->m_iWorkspaceID && w->m_bIsFloating && w->m_bCreatedOverFullscreen && w->visibleOnMonitor(pMonitor)) return; } From b7b13623bac54d4f6dd9e546f18fa816ecf555b7 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 14 Mar 2024 20:21:58 +0000 Subject: [PATCH 0109/2897] subsurface/popup: expand on map/unmap to add buffering ref #5113 --- src/desktop/Popup.cpp | 4 ++-- src/desktop/Subsurface.cpp | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 29594e47..d5599c65 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -106,7 +106,7 @@ void CPopup::onMap() { CBox box; wlr_surface_get_extends(m_sWLSurface.wlr(), box.pWlr()); - box.applyFromWlr().translate(COORDS); + box.applyFromWlr().translate(COORDS).expand(4); g_pHyprRenderer->damageBox(&box); m_vLastPos = coordsRelativeToParent(); @@ -125,7 +125,7 @@ void CPopup::onUnmap() { CBox box; wlr_surface_get_extends(m_sWLSurface.wlr(), box.pWlr()); - box.applyFromWlr().translate(COORDS); + box.applyFromWlr().translate(COORDS).expand(4); g_pHyprRenderer->damageBox(&box); m_pSubsurfaceHead.reset(); diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index 0d76a147..1a3dd9f5 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -177,6 +177,7 @@ void CSubsurface::onMap() { const auto COORDS = coordsGlobal(); CBox box{COORDS, m_vLastSize}; + box.expand(4); g_pHyprRenderer->damageBox(&box); if (m_pWindowParent) @@ -186,6 +187,7 @@ void CSubsurface::onMap() { void CSubsurface::onUnmap() { const auto COORDS = coordsGlobal(); CBox box{COORDS, m_vLastSize}; + box.expand(4); g_pHyprRenderer->damageBox(&box); if (m_sWLSurface.wlr() == g_pCompositor->m_pLastFocus) From 045c3fbd854090b2b60ca025fedd3e62498ed1ec Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 14 Mar 2024 20:42:33 +0000 Subject: [PATCH 0110/2897] subsurface: fix visibility check ref #5113 --- src/desktop/Subsurface.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index 1a3dd9f5..c3538ee1 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -117,7 +117,7 @@ void CSubsurface::recheckDamageForSubsurfaces() { void CSubsurface::onCommit() { // no damaging if it's not visible - if (!g_pHyprRenderer->shouldRenderWindow(m_pWindowParent)) { + if (m_pWindowParent && !g_pHyprRenderer->shouldRenderWindow(m_pWindowParent)) { m_vLastSize = Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); From dc44bd7113b81a5c9aa61ecdc11d905a749b3e88 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 03:32:24 +0000 Subject: [PATCH 0111/2897] ci: remove codeql bullshit, useless, and only fails for no reason --- .github/workflows/security-checks.yml | 41 --------------------------- 1 file changed, 41 deletions(-) diff --git a/.github/workflows/security-checks.yml b/.github/workflows/security-checks.yml index 6a86f70e..564013cf 100644 --- a/.github/workflows/security-checks.yml +++ b/.github/workflows/security-checks.yml @@ -24,44 +24,3 @@ jobs: uses: github/codeql-action/upload-sarif@v2 with: sarif_file: ${{github.workspace}}/flawfinder_results.sarif - - codeql: - name: CodeQL - runs-on: ubuntu-latest - container: - image: archlinux - - permissions: - actions: read - contents: read - security-events: write - - strategy: - fail-fast: false - matrix: - language: [ 'cpp' ] - - steps: - - name: Checkout repository actions - uses: actions/checkout@v4 - with: - sparse-checkout: .github/actions - - - name: Initialize CodeQL - uses: github/codeql-action/init@v2 - with: - languages: ${{ matrix.language }} - - - name: Setup base - uses: ./.github/actions/setup_base - with: - INSTALL_XORG_PKGS: true - - - name: Build Hyprland - run: | - make all - - - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v2 - with: - category: "/language:${{matrix.language}}" From d00c658405fe8e805196df3694baa4dcf0ba18e5 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Fri, 15 Mar 2024 10:11:54 +0200 Subject: [PATCH 0112/2897] Nix: add wrapping back Ref: https://github.com/hyprwm/hyprland-plugins/issues/93 --- flake.nix | 1 + nix/default.nix | 17 ++++++++++------- nix/overlays.nix | 1 + 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/flake.nix b/flake.nix index 9bee5efc..e419e3e3 100644 --- a/flake.nix +++ b/flake.nix @@ -79,6 +79,7 @@ hyprland hyprland-debug hyprland-legacy-renderer + hyprland-unwrapped # hyprland-extras xdg-desktop-portal-hyprland diff --git a/nix/default.nix b/nix/default.nix index c4650d3c..a2a31818 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -33,6 +33,7 @@ enableXWayland ? true, legacyRenderer ? false, withSystemd ? lib.meta.availableOn stdenv.hostPlatform systemd, + wrapRuntimeDeps ? true, version ? "git", commit, date, @@ -94,13 +95,6 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov ++ lib.optionals enableXWayland [libxcb xcbutilwm xwayland] ++ lib.optionals withSystemd [systemd]; - # avoid wrapping - propagatedBuildInputs = [ - stdenv.cc - binutils - pciutils - ]; - mesonBuildType = if debug then "debug" @@ -140,6 +134,15 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov postInstall = '' ln -s ${wlroots}/include/wlr $dev/include/hyprland/wlroots + + ${lib.optionalString wrapRuntimeDeps '' + wrapProgram $out/bin/Hyprland \ + --suffix PATH : ${lib.makeBinPath [ + stdenv.cc + binutils + pciutils + ]} + ''} ''; passthru.providedSessions = ["hyprland"]; diff --git a/nix/overlays.nix b/nix/overlays.nix index 68c196d9..c216ff53 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -38,6 +38,7 @@ in { udis86 = final.udis86-hyprland; # explicit override until decided on breaking change of the name inherit date; }; + hyprland-unwrapped = final.hyprland.override {wrapRuntimeDeps = false;}; hyprland-debug = final.hyprland.override {debug = true;}; hyprland-legacy-renderer = final.hyprland.override {legacyRenderer = true;}; hyprland-nvidia = From 6c24cee88f50721cfd6a62e4140924ac13549d1d Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Fri, 15 Mar 2024 11:13:27 +0200 Subject: [PATCH 0113/2897] flake.lock: update --- flake.lock | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/flake.lock b/flake.lock index 341286a1..9e6464f0 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ ] }, "locked": { - "lastModified": 1710091028, - "narHash": "sha256-yFk2kc8J2kVh0RWlwT+PQf0bpfUNcROOcRYcyQJbpk4=", + "lastModified": 1710257359, + "narHash": "sha256-43re5pzE/cswFAgw92/ugsB3+d5ufDaCcLtl9ztKfBo=", "owner": "hyprwm", "repo": "hyprcursor", - "rev": "05db7dfd7fc261e0195e54f8a6d655d4f370e70f", + "rev": "1761f6cefd77f4fcd2039d930c88d6716ddc4974", "type": "github" }, "original": { @@ -94,11 +94,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1709961763, - "narHash": "sha256-6H95HGJHhEZtyYA3rIQpvamMKAGoa8Yh2rFV29QnuGw=", + "lastModified": 1710272261, + "narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "3030f185ba6a4bf4f18b87f345f104e6a6961f34", + "rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2", "type": "github" }, "original": { From bc15a8f60028539690cccdb78eed7fc9175fe792 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Fri, 15 Mar 2024 07:28:14 -0700 Subject: [PATCH 0114/2897] renderer: Allow headless mode in hyprland (#4794) * allow headless * clang-format * fix redundant logic lol --- src/Compositor.cpp | 25 +++++++++++++++++++------ src/render/Renderer.cpp | 18 +++++++++++------- 2 files changed, 30 insertions(+), 13 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index eda5b5ed..42ba9b5f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -127,13 +127,26 @@ void CCompositor::initServer() { throwError("wlr_backend_autocreate() failed!"); } - m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend); - if (m_iDRMFD < 0) { - Debug::log(CRIT, "Couldn't query the DRM FD!"); - throwError("wlr_backend_get_drm_fd() failed!"); - } + bool isHeadlessOnly = true; + wlr_multi_for_each_backend( + m_sWLRBackend, + [](wlr_backend* backend, void* isHeadlessOnly) { + if (!wlr_backend_is_headless(backend)) + *(bool*)isHeadlessOnly = false; + }, + &isHeadlessOnly); - m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD); + if (isHeadlessOnly) { + m_sWLRRenderer = wlr_renderer_autocreate(m_sWLRBackend); + } else { + m_iDRMFD = wlr_backend_get_drm_fd(m_sWLRBackend); + if (m_iDRMFD < 0) { + Debug::log(CRIT, "Couldn't query the DRM FD!"); + throwError("wlr_backend_get_drm_fd() failed!"); + } + + m_sWLRRenderer = wlr_gles2_renderer_create_with_drm_fd(m_iDRMFD); + } if (!m_sWLRRenderer) { Debug::log(CRIT, "m_sWLRRenderer was NULL! This usually means wlroots could not find a GPU or enountered some issues."); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index a9c7c11a..10f15a9d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -31,16 +31,20 @@ CHyprRenderer::CHyprRenderer() { } else { Debug::log(LOG, "m_sWLRSession is null, omitting full DRM node checks"); - const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD); + const auto DRMV = drmGetVersion(g_pCompositor->m_iDRMFD); - std::string name = std::string{DRMV->name, DRMV->name_len}; - std::transform(name.begin(), name.end(), name.begin(), tolower); + if (DRMV) { + std::string name = std::string{DRMV->name, DRMV->name_len}; + std::transform(name.begin(), name.end(), name.begin(), tolower); - if (name.contains("nvidia")) - m_bNvidia = true; + if (name.contains("nvidia")) + m_bNvidia = true; - Debug::log(LOG, "Primary DRM driver information: {} v{}.{}.{} from {} description {}", name, DRMV->version_major, DRMV->version_minor, DRMV->version_patchlevel, - std::string{DRMV->date, DRMV->date_len}, std::string{DRMV->desc, DRMV->desc_len}); + Debug::log(LOG, "Primary DRM driver information: {} v{}.{}.{} from {} description {}", name, DRMV->version_major, DRMV->version_minor, DRMV->version_patchlevel, + std::string{DRMV->date, DRMV->date_len}, std::string{DRMV->desc, DRMV->desc_len}); + } else { + Debug::log(LOG, "No primary DRM driver information found"); + } drmFreeVersion(DRMV); } From bb933dcf04ff1daafbc9681c87b87d7e907ae7bd Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 15:55:24 +0000 Subject: [PATCH 0115/2897] popup: avoid damage loops with commits fixes #5118 --- src/desktop/Popup.cpp | 7 ++++--- src/desktop/Popup.hpp | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index d5599c65..98d5881a 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -133,7 +133,7 @@ void CPopup::onUnmap() { g_pInputManager->simulateMouseMovement(); } -void CPopup::onCommit() { +void CPopup::onCommit(bool ignoreSiblings) { if (m_pWLR->base->initial_commit) { wlr_xdg_surface_schedule_configure(m_pWLR->base); return; @@ -152,7 +152,8 @@ void CPopup::onCommit() { m_vLastPos = COORDSLOCAL; } - m_pSubsurfaceHead->recheckDamageForSubsurfaces(); + if (!ignoreSiblings) + m_pSubsurfaceHead->recheckDamageForSubsurfaces(); g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y); @@ -227,7 +228,7 @@ void CPopup::recheckTree() { void CPopup::recheckChildrenRecursive() { for (auto& c : m_vChildren) { - c->onCommit(); + c->onCommit(true); c->recheckChildrenRecursive(); } } diff --git a/src/desktop/Popup.hpp b/src/desktop/Popup.hpp index 0ac460d1..5f7af085 100644 --- a/src/desktop/Popup.hpp +++ b/src/desktop/Popup.hpp @@ -26,7 +26,7 @@ class CPopup { void onDestroy(); void onMap(); void onUnmap(); - void onCommit(); + void onCommit(bool ignoreSiblings = false); void onReposition(); void recheckTree(); From a958884b5259ec5d6a2c97078b373c722ae20c39 Mon Sep 17 00:00:00 2001 From: Maximilian Seidler <78690852+PaideiaDilemma@users.noreply.github.com> Date: Fri, 15 Mar 2024 17:17:13 +0100 Subject: [PATCH 0116/2897] lock: fix red screen issues with multiple monitors (#5100) * lock: use uint64_t for iMonitorID * lock: move activateLock to onNewSessionLock * lock: add red screen fade * lock: damage when fading the red screen and delay for screencopy * lock: remove redundant scheduleFrameForMonitor --- src/managers/SessionLockManager.cpp | 22 +++++++++++++++++++--- src/managers/SessionLockManager.hpp | 10 ++++++++-- src/render/Renderer.cpp | 17 ++++++++++++----- src/render/Renderer.hpp | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 82606a8a..1e366034 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -15,8 +15,6 @@ static void handleSurfaceMap(void* owner, void* data) { if (PMONITOR) g_pHyprRenderer->damageMonitor(PMONITOR); - - g_pSessionLockManager->activateLock(); // activate lock here to prevent the red screen from flashing before that } static void handleSurfaceCommit(void* owner, void* data) { @@ -97,6 +95,8 @@ void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) { m_sSessionLock.active = false; + m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.clear(); + g_pCompositor->m_sSeat.exclusiveClient = nullptr; g_pInputManager->refocus(); @@ -126,13 +126,15 @@ void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) { pWlrLock, "wlr_session_lock_v1"); wlr_session_lock_v1_send_locked(pWlrLock); + + g_pSessionLockManager->activateLock(); } bool CSessionLockManager::isSessionLocked() { return m_sSessionLock.active; } -SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(const int& id) { +SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(uint64_t id) { for (auto& sls : m_sSessionLock.vSessionLockSurfaces) { if (sls->iMonitorID == id) { if (sls->mapped) @@ -145,6 +147,20 @@ SSessionLockSurface* CSessionLockManager::getSessionLockSurfaceForMonitor(const return nullptr; } +// We don't want the red screen to flash. +// This violates the protocol a bit, but tries to handle the missing sync between a lock surface beeing created and the red screen beeing drawn. +float CSessionLockManager::getRedScreenAlphaForMonitor(uint64_t id) { + const auto& NOMAPPEDSURFACETIMER = m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.find(id); + + if (NOMAPPEDSURFACETIMER == m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.end()) { + m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers.emplace(id, CTimer()); + m_sSessionLock.mMonitorsWithoutMappedSurfaceTimers[id].reset(); + return 0.f; + } + + return std::clamp(NOMAPPEDSURFACETIMER->second.getSeconds() - /* delay for screencopy */ 0.5f, 0.f, 1.f); +} + bool CSessionLockManager::isSurfaceSessionLock(wlr_surface* pSurface) { for (auto& sls : m_sSessionLock.vSessionLockSurfaces) { if (sls->pWlrLockSurface->surface == pSurface) diff --git a/src/managers/SessionLockManager.hpp b/src/managers/SessionLockManager.hpp index 51232867..c2c539db 100644 --- a/src/managers/SessionLockManager.hpp +++ b/src/managers/SessionLockManager.hpp @@ -1,10 +1,13 @@ #pragma once #include "../defines.hpp" +#include "../helpers/Timer.hpp" +#include +#include struct SSessionLockSurface { wlr_session_lock_surface_v1* pWlrLockSurface = nullptr; - int iMonitorID = -1; + uint64_t iMonitorID = -1; bool mapped = false; @@ -18,6 +21,7 @@ struct SSessionLock { wlr_session_lock_v1* pWlrLock = nullptr; std::vector> vSessionLockSurfaces; + std::unordered_map mMonitorsWithoutMappedSurfaceTimers; DYNLISTENER(newSurface); DYNLISTENER(unlock); @@ -30,7 +34,9 @@ class CSessionLockManager { ~CSessionLockManager() = default; void onNewSessionLock(wlr_session_lock_v1*); - SSessionLockSurface* getSessionLockSurfaceForMonitor(const int&); + SSessionLockSurface* getSessionLockSurfaceForMonitor(uint64_t); + + float getRedScreenAlphaForMonitor(uint64_t); bool isSessionLocked(); bool isSurfaceSessionLock(wlr_surface*); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 10f15a9d..815b70fb 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -815,16 +815,23 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* g_pHyprOpenGL->m_RenderData.renderModif = {}; } -void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now) { +void CHyprRenderer::renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry) { TRACY_GPU_ZONE("RenderLockscreen"); if (g_pSessionLockManager->isSessionLocked()) { - const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID); + Vector2D translate = {geometry.x, geometry.y}; + float scale = (float)geometry.width / pMonitor->vecPixelSize.x; + const auto PSLS = g_pSessionLockManager->getSessionLockSurfaceForMonitor(pMonitor->ID); if (!PSLS) { // locked with no surface, fill with red - CBox boxe = {0, 0, INT16_MAX, INT16_MAX}; - g_pHyprOpenGL->renderRect(&boxe, CColor(1.0, 0.2, 0.2, 1.0)); + const auto ALPHA = g_pSessionLockManager->getRedScreenAlphaForMonitor(pMonitor->ID); + + CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; + g_pHyprOpenGL->renderRect(&monbox, CColor(1.0, 0.2, 0.2, ALPHA)); + + if (ALPHA < 1.f) /* animate */ + damageMonitor(pMonitor); } else { renderSessionLockSurface(PSLS, pMonitor, now); } @@ -1206,7 +1213,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; renderWorkspace(pMonitor, g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace), &now, renderBox); - renderLockscreen(pMonitor, &now); + renderLockscreen(pMonitor, &now, renderBox); if (pMonitor == g_pCompositor->m_pLastMonitor) { g_pHyprNotificationOverlay->draw(pMonitor); diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 53cace82..e480b26d 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -59,7 +59,7 @@ class CHyprRenderer { void setCursorHidden(bool hide); void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false); std::tuple getRenderTimes(CMonitor* pMonitor); // avg max min - void renderLockscreen(CMonitor* pMonitor, timespec* now); + void renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry); void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace); void setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace); // TODO: merge occlusion methods bool canSkipBackBufferClear(CMonitor* pMonitor); From 72d78eff95948a3eb3260791cfdf625c0102d33a Mon Sep 17 00:00:00 2001 From: drendog <53359960+drendog@users.noreply.github.com> Date: Fri, 15 Mar 2024 19:44:17 +0100 Subject: [PATCH 0117/2897] sessionlock: refocus after destroy focused surface (#5117) * fix: refocus after destroy focused surface * refactor: minor refactor on refocus loop condition * refactor: minor refactor on condition * style: format code --- src/managers/SessionLockManager.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 1e366034..a0374b85 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -172,6 +172,17 @@ bool CSessionLockManager::isSurfaceSessionLock(wlr_surface* pSurface) { void CSessionLockManager::removeSessionLockSurface(SSessionLockSurface* pSLS) { std::erase_if(m_sSessionLock.vSessionLockSurfaces, [&](const auto& other) { return pSLS == other.get(); }); + + if (g_pCompositor->m_pLastFocus) + return; + + for (auto& sls : m_sSessionLock.vSessionLockSurfaces) { + if (!sls->mapped) + continue; + + g_pCompositor->focusSurface(sls->pWlrLockSurface->surface); + break; + } } void CSessionLockManager::activateLock() { From 38576d651a9a7edcf5d7b782a2f415c8a1f0f4e6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 19:23:45 +0000 Subject: [PATCH 0118/2897] renderer: adjust surface dimensions for oversized not-yet ackd surface sizes supersedes #5104 --- src/render/Renderer.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 815b70fb..2a0c6f7d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -75,23 +75,34 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) // however, if surface buffer w / h < box, we need to adjust them auto* const PSURFACE = CWLSurface::surfaceFromWlr(surface); + const auto PWINDOW = PSURFACE->getWindow(); - if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees m_pWindowOwner */) { + if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees PWINDOW */) { const auto CORRECT = PSURFACE->correctSmallVec(); const auto SIZE = PSURFACE->getViewporterCorrectedSize(); if (!INTERACTIVERESIZEINPROGRESS) { - windowBox.x += CORRECT.x; - windowBox.y += CORRECT.y; + windowBox.translate(CORRECT); - windowBox.width = SIZE.x * (PSURFACE->getWindow()->m_vRealSize.value().x / PSURFACE->getWindow()->m_vReportedSize.x); - windowBox.height = SIZE.y * (PSURFACE->getWindow()->m_vRealSize.value().y / PSURFACE->getWindow()->m_vReportedSize.y); + windowBox.width = SIZE.x * (PWINDOW->m_vRealSize.value().x / PWINDOW->m_vReportedSize.x); + windowBox.height = SIZE.y * (PWINDOW->m_vRealSize.value().y / PWINDOW->m_vReportedSize.y); } else { windowBox.width = SIZE.x; windowBox.height = SIZE.y; } } + if (PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize) { + Vector2D size = + Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; + Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; + + windowBox.translate(correct / 2.0); + + windowBox.w = size.x; + windowBox.h = size.y; + } + } else { // here we clamp to 2, these might be some tiny specks windowBox = {(int)outputX + RDATA->x + x, (int)outputY + RDATA->y + y, std::max(surface->current.width, 2), std::max(surface->current.height, 2)}; if (RDATA->pWindow && RDATA->pWindow->m_vRealSize.isBeingAnimated() && RDATA->surface && RDATA->surface != surface && RDATA->squishOversized /* subsurface */) { From c4f52d19792696b8b297877b9152bd86d0f4624b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 19:31:33 +0000 Subject: [PATCH 0119/2897] master: fix invalid config usage --- src/layout/MasterLayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 0a51401f..9e7f8880 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -43,9 +43,9 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { //create on the fly if it doesn't exist yet const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); PWORKSPACEDATA->workspaceID = ws; - const auto orientation = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("master:orientation"); + static auto PORIENTATION = CConfigValue("master:orientation"); const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts; - std::string orientationForWs = *orientation; + std::string orientationForWs = *PORIENTATION; if (layoutoptsForWs.contains("orientation")) orientationForWs = layoutoptsForWs.at("orientation"); From 2a2da6082e5f1501731004b755d35a8dbb605fde Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 21:29:20 +0000 Subject: [PATCH 0120/2897] renderer: fix invalid access on non-assigned surfaces fixes #5125 --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 2a0c6f7d..5c0d3d10 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -75,7 +75,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) // however, if surface buffer w / h < box, we need to adjust them auto* const PSURFACE = CWLSurface::surfaceFromWlr(surface); - const auto PWINDOW = PSURFACE->getWindow(); + const auto PWINDOW = PSURFACE ? PSURFACE->getWindow() : nullptr; if (PSURFACE && !PSURFACE->m_bFillIgnoreSmall && PSURFACE->small() /* guarantees PWINDOW */) { const auto CORRECT = PSURFACE->correctSmallVec(); From 3f5f5f5491149d16ef721454616c3dd0f96018e5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 23:58:22 +0000 Subject: [PATCH 0121/2897] splashes: add 2ya splash --- src/helpers/Splashes.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/Splashes.hpp b/src/helpers/Splashes.hpp index e7a1cb5f..4a4fd022 100644 --- a/src/helpers/Splashes.hpp +++ b/src/helpers/Splashes.hpp @@ -75,6 +75,8 @@ inline const std::vector SPLASHES = { "Join the discord server!", "Thanks ThatOneCalculator!", "The AUR packages always work, except for the times they don't.", - "Funny animation compositor woo" + "Funny animation compositor woo", + // + "2 years!" // clang-format on }; \ No newline at end of file From 19c90048d65a5660384d2fb865926a366696d6be Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 15 Mar 2024 23:58:39 +0000 Subject: [PATCH 0122/2897] props: bump ver to 0.37.0 --- props.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/props.json b/props.json index df4784ea..ca41ea51 100644 --- a/props.json +++ b/props.json @@ -1,3 +1,3 @@ { - "version": "0.36.0" + "version": "0.37.0" } \ No newline at end of file From 5e5d7e2abcd91c83058ba80ec64ec5054cae5bfa Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 16 Mar 2024 14:37:07 +0000 Subject: [PATCH 0123/2897] renderer: fix non-reported sizes window box calculations fixed #5129 --- src/render/Renderer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 5c0d3d10..309e5742 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -92,7 +92,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) } } - if (PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize) { + if (PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { Vector2D size = Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; From c942ce6dce7f01415f71e5207da69b6989d3818c Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 16 Mar 2024 07:49:34 -0700 Subject: [PATCH 0124/2897] renderer: add better multi monitor animations (#5126) --- src/helpers/Box.cpp | 18 ++++++++++++++++ src/helpers/Box.hpp | 1 + src/managers/AnimationManager.cpp | 35 ++++++++++++++++++++++++++----- src/render/Renderer.cpp | 15 ++++++++++--- 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp index 59578f23..e9e0eeeb 100644 --- a/src/helpers/Box.cpp +++ b/src/helpers/Box.cpp @@ -116,6 +116,24 @@ CBox& CBox::noNegativeSize() { return *this; } +CBox& CBox::intersection(const CBox other) { + const float newTop = std::max(y, other.y); + const float newBottom = std::min(y + h, other.y + other.h); + const float newLeft = std::max(x, other.x); + const float newRight = std::min(x + w, other.x + other.w); + y = newTop; + x = newLeft; + w = newRight - newLeft; + h = newBottom - newTop; + + if (w <= 0 || h <= 0) { + w = 0; + h = 0; + } + + return *this; +} + CBox CBox::roundInternal() { float newW = x + w - std::floor(x); float newH = y + h - std::floor(y); diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp index fd31a7b7..e38d6108 100644 --- a/src/helpers/Box.hpp +++ b/src/helpers/Box.hpp @@ -52,6 +52,7 @@ class CBox { CBox& addExtents(const SWindowDecorationExtents& e); CBox& expand(const double& value); CBox& noNegativeSize(); + CBox& intersection(const CBox other); CBox copy() const; diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 072a377e..f9dfa6fa 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -86,8 +86,13 @@ void CAnimationManager::tick() { CBox WLRBOXPREV = {0, 0, 0, 0}; if (PWINDOW) { - WLRBOXPREV = PWINDOW->getFullWindowBoundingBox(); - PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); + CBox bb = PWINDOW->getFullWindowBoundingBox(); + const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + if (PWINDOWWORKSPACE) + bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + WLRBOXPREV = bb; + + PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); if (!PMONITOR) continue; animationsDisabled = animationsDisabled || PWINDOW->m_sAdditionalConfigData.forceNoAnims; @@ -95,13 +100,27 @@ void CAnimationManager::tick() { PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); if (!PMONITOR) continue; - WLRBOXPREV = {(int)PMONITOR->vecPosition.x, (int)PMONITOR->vecPosition.y, (int)PMONITOR->vecSize.x, (int)PMONITOR->vecSize.y}; + WLRBOXPREV = {PMONITOR->vecPosition, PMONITOR->vecSize}; // TODO: just make this into a damn callback already vax... for (auto& w : g_pCompositor->m_vWindows) { if (!w->isHidden() && w->m_bIsMapped && w->m_bIsFloating) g_pHyprRenderer->damageWindow(w.get()); } + + // if a workspace window is on any monitor, damage it + for (auto& w : g_pCompositor->m_vWindows) { + for (auto& m : g_pCompositor->m_vMonitors) { + if (w->m_iWorkspaceID == PWORKSPACE->m_iID && g_pCompositor->windowValidMapped(w.get()) && g_pHyprRenderer->shouldRenderWindow(w.get(), m.get(), PWORKSPACE)) { + CBox bb = w->getFullWindowBoundingBox(); + bb.translate(PWORKSPACE->m_vRenderOffset.value()); + if (PWORKSPACE->m_bIsSpecialWorkspace) + bb.scaleFromCenter(1.1); // for some reason special ws windows getting border artifacts if you close it too quickly... + bb.intersection({m->vecPosition, m->vecSize}); + g_pHyprRenderer->damageBox(&bb); + } + } + } } else if (PLAYER) { WLRBOXPREV = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f); @@ -175,7 +194,10 @@ void CAnimationManager::tick() { if (PWINDOW) { PWINDOW->updateWindowDecos(); - g_pHyprRenderer->damageWindow(PWINDOW); + auto bb = PWINDOW->getFullWindowBoundingBox(); + const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + g_pHyprRenderer->damageBox(&bb); } else if (PWORKSPACE) { for (auto& w : g_pCompositor->m_vWindows) { if (!w->m_bIsMapped || w->isHidden()) @@ -222,7 +244,10 @@ void CAnimationManager::tick() { BORDERSIZE + ROUNDINGSIZE); // bottom // damage for new box - const CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value().x, PWINDOW->m_vRealPosition.value().y, PWINDOW->m_vRealSize.value().x, PWINDOW->m_vRealSize.value().y}; + CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value(), PWINDOW->m_vRealSize.value()}; + const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + if (PWINDOWWORKSPACE) + WLRBOXNEW.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, WLRBOXNEW.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // top g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, WLRBOXNEW.height + 2 * BORDERSIZE); // left g_pHyprRenderer->damageBox(WLRBOXNEW.x + WLRBOXNEW.width - ROUNDINGSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 309e5742..cb60cd41 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -224,6 +224,15 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo if (pMonitor->specialWorkspaceID == pWindow->m_iWorkspaceID) return true; + if (pWindow->m_vRealPosition.isBeingAnimated()) { + // render window if window and monitor intersect + // (when moving out of or through a monitor) + CBox windowBox = {pWindow->m_vRealPosition.value(), pWindow->m_vRealSize.value()}; + const CBox monitorBox = {pMonitor->vecPosition, pMonitor->vecSize}; + if (!windowBox.intersection(monitorBox).empty()) + return true; + } + return false; } @@ -363,7 +372,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork continue; // render active window after all others of this pass - if (w.get() == g_pCompositor->m_pLastWindow && w->m_iWorkspaceID == pWorkspace->m_iID) { + if (w.get() == g_pCompositor->m_pLastWindow) { lastWindow = w.get(); continue; } @@ -404,7 +413,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) continue; - if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) continue; if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID) @@ -781,7 +790,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* // special for (auto& ws : g_pCompositor->m_vWorkspaces) { - if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { + if (ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { if (ws->m_bHasFullscreenWindow) renderWorkspaceWindowsFullscreen(pMonitor, ws.get(), time); else From c5e28ebcfe00a510922779b2c568cfa52a317445 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 16 Mar 2024 14:51:44 +0000 Subject: [PATCH 0125/2897] props: bump ver 0.37.1 --- props.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/props.json b/props.json index ca41ea51..81f6a4cb 100644 --- a/props.json +++ b/props.json @@ -1,3 +1,3 @@ { - "version": "0.37.0" + "version": "0.37.1" } \ No newline at end of file From bd332a79e7669f1dc05ce7ea6b5d78028f1f02bc Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Sat, 16 Mar 2024 18:12:32 +0200 Subject: [PATCH 0126/2897] Nix: match derivation to Nixpkgs --- nix/default.nix | 72 ++++++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 34 deletions(-) diff --git a/nix/default.nix b/nix/default.nix index a2a31818..91e132b2 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -14,6 +14,7 @@ jq, libGL, libdrm, + libexecinfo, libinput, libxcb, libxkbcommon, @@ -44,7 +45,9 @@ }: assert lib.assertMsg (!nvidiaPatches) "The option `nvidiaPatches` has been removed."; assert lib.assertMsg (!enableNvidiaPatches) "The option `enableNvidiaPatches` has been removed."; -assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been removed. Please refer https://wiki.hyprland.org/Configuring/XWayland"; +assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been removed. Please refer https://wiki.hyprland.org/Configuring/XWayland"; let + wlr = wlroots.override {inherit enableXWayland;}; +in stdenv.mkDerivation { pname = "hyprland${lib.optionalString debug "-debug"}"; inherit version; @@ -57,12 +60,36 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov src = lib.cleanSource ../.; }; + patches = [ + # make meson use the provided wlroots instead of the git submodule + ./patches/meson-build.patch + ]; + + postPatch = '' + # Fix hardcoded paths to /usr installation + sed -i "s#/usr#$out#" src/render/OpenGL.cpp + + # Generate version.h + cp src/version.h.in src/version.h + substituteInPlace src/version.h \ + --replace "@HASH@" '${commit}' \ + --replace "@BRANCH@" "" \ + --replace "@MESSAGE@" "" \ + --replace "@DATE@" "${date}" \ + --replace "@TAG@" "" \ + --replace "@DIRTY@" '${ + if commit == "" + then "dirty" + else "" + }' + ''; + nativeBuildInputs = [ jq + makeWrapper meson ninja pkg-config - makeWrapper wayland-scanner ]; @@ -90,8 +117,9 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov udis86 wayland wayland-protocols - wlroots + wlr ] + ++ lib.optionals stdenv.hostPlatform.isMusl [libexecinfo] ++ lib.optionals enableXWayland [libxcb xcbutilwm xwayland] ++ lib.optionals withSystemd [systemd]; @@ -102,38 +130,14 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov mesonAutoFeatures = "disabled"; - mesonFlags = builtins.concatLists [ - (lib.optional enableXWayland "-Dxwayland=enabled") - (lib.optional legacyRenderer "-Dlegacy_renderer=enabled") - (lib.optional withSystemd "-Dsystemd=enabled") + mesonFlags = [ + (lib.mesonEnable "xwayland" enableXWayland) + (lib.mesonEnable "legacy_renderer" legacyRenderer) + (lib.mesonEnable "systemd" withSystemd) ]; - patches = [ - # make meson use the provided wlroots instead of the git submodule - ./patches/meson-build.patch - ]; - - postPatch = '' - # Fix hardcoded paths to /usr installation - sed -i "s#/usr#$out#" src/render/OpenGL.cpp - - # Generate version.h - cp src/version.h.in src/version.h - substituteInPlace src/version.h \ - --replace "@HASH@" '${commit}' \ - --replace "@BRANCH@" "" \ - --replace "@MESSAGE@" "" \ - --replace "@DATE@" "${date}" \ - --replace "@TAG@" "" \ - --replace "@DIRTY@" '${ - if commit == "" - then "dirty" - else "" - }' - ''; - postInstall = '' - ln -s ${wlroots}/include/wlr $dev/include/hyprland/wlroots + ln -s ${wlr}/include/wlr $dev/include/hyprland/wlroots ${lib.optionalString wrapRuntimeDeps '' wrapProgram $out/bin/Hyprland \ @@ -148,10 +152,10 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov passthru.providedSessions = ["hyprland"]; meta = with lib; { - homepage = "https://github.com/vaxerski/Hyprland"; + homepage = "https://github.com/hyprwm/Hyprland"; description = "A dynamic tiling Wayland compositor that doesn't sacrifice on its looks"; license = licenses.bsd3; - platforms = platforms.linux; + platforms = wlr.meta.platforms; mainProgram = "Hyprland"; }; } From e566be7847b1d32c11291edb99b169f6b64fcebb Mon Sep 17 00:00:00 2001 From: Omar <147266582+somerand0mcat@users.noreply.github.com> Date: Sat, 16 Mar 2024 18:57:45 +0200 Subject: [PATCH 0127/2897] LICENSE: Update year (#5132) Updating the license year from 2022-2023 to 2022-2024 --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 8ec509bd..a34afebb 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2022-2023, vaxerski +Copyright (c) 2022-2024, vaxerski All rights reserved. Redistribution and use in source and binary forms, with or without From 3162739e1b555ba7d7b4643bf1ea4debd31007ce Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 16 Mar 2024 17:12:24 +0000 Subject: [PATCH 0128/2897] renderer: don't translate surface box on interactive resizes with non-updated sizes closes #5135 --- src/render/Renderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index cb60cd41..16d06a96 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -97,7 +97,8 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; - windowBox.translate(correct / 2.0); + if (!INTERACTIVERESIZEINPROGRESS) + windowBox.translate(correct / 2.0); windowBox.w = size.x; windowBox.h = size.y; From 0e87a08e15c023325b64920d9e1159f38a090695 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 16 Mar 2024 17:56:09 +0000 Subject: [PATCH 0129/2897] renderer: disable surface adjustments for misaligned reported when manual resizing ref #5135 --- src/render/Renderer.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 16d06a96..58f4b31a 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -92,13 +92,12 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) } } - if (PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { + if (!INTERACTIVERESIZEINPROGRESS && PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { Vector2D size = Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; - if (!INTERACTIVERESIZEINPROGRESS) - windowBox.translate(correct / 2.0); + windowBox.translate(correct / 2.0); windowBox.w = size.x; windowBox.h = size.y; From 0387528c56c4d9faf93946cbc9426973de6ef61b Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 16 Mar 2024 17:15:12 -0700 Subject: [PATCH 0130/2897] master: fix moving fullscreen workspace and remove duplicate code (#5131) --- src/layout/DwindleLayout.cpp | 49 +++++++++------------------ src/layout/DwindleLayout.hpp | 3 +- src/layout/MasterLayout.cpp | 65 ++++++++++++------------------------ 3 files changed, 39 insertions(+), 78 deletions(-) diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index cc4bc0b3..1ce6aa82 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -541,42 +541,24 @@ void CHyprDwindleLayout::recalculateMonitor(const int& monid) { if (!PMONITOR) return; // ??? - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + g_pHyprRenderer->damageMonitor(PMONITOR); + + if (PMONITOR->specialWorkspaceID) + calculateWorkspace(PMONITOR->specialWorkspaceID); + + calculateWorkspace(PMONITOR->activeWorkspace); +} + +void CHyprDwindleLayout::calculateWorkspace(const int& ws) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); if (!PWORKSPACE) return; - g_pHyprRenderer->damageMonitor(PMONITOR); + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - if (PMONITOR->specialWorkspaceID) { - const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID); - - if (PSPECIALWS->m_bHasFullscreenWindow) { - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PSPECIALWS->m_iID); - - if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_FULL) { - PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; - PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { - SDwindleNodeData fakeNode; - fakeNode.pWindow = PFULLWINDOW; - fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - fakeNode.workspaceID = PSPECIALWS->m_iID; - PFULLWINDOW->m_vPosition = fakeNode.box.pos(); - PFULLWINDOW->m_vSize = fakeNode.box.size(); - fakeNode.ignoreFullscreenChecks = true; - - applyNodeDataToWindow(&fakeNode); - } - } - - const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->specialWorkspaceID); - - if (TOPNODE && PMONITOR) { - TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - TOPNODE->recalcSizePosRecursive(); - } - } + if (!PMONITOR) + return; if (PWORKSPACE->m_bHasFullscreenWindow) { // massive hack from the fullscreen func @@ -597,12 +579,13 @@ void CHyprDwindleLayout::recalculateMonitor(const int& monid) { applyNodeDataToWindow(&fakeNode); } + // if has fullscreen, don't calculate the rest return; } - const auto TOPNODE = getMasterNodeOnWorkspace(PMONITOR->activeWorkspace); + const auto TOPNODE = getMasterNodeOnWorkspace(ws); - if (TOPNODE && PMONITOR) { + if (TOPNODE) { TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; TOPNODE->recalcSizePosRecursive(); } diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index fc73540a..5ca90fcd 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -78,6 +78,7 @@ class CHyprDwindleLayout : public IHyprLayout { int getNodesOnWorkspace(const int&); void applyNodeDataToWindow(SDwindleNodeData*, bool force = false); + void calculateWorkspace(const int& ws); SDwindleNodeData* getNodeFromWindow(CWindow*); SDwindleNodeData* getFirstNodeOnWorkspace(const int&); SDwindleNodeData* getClosestNodeOnWorkspace(const int&, const Vector2D&); @@ -103,4 +104,4 @@ struct std::formatter : std::formatter { std::format_to(out, ", window: {:x}", node->pWindow); return std::format_to(out, "]"); } -}; \ No newline at end of file +}; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 9e7f8880..7919d50f 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -287,38 +287,24 @@ void CHyprMasterLayout::recalculateMonitor(const int& monid) { if (!PMONITOR) return; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + g_pHyprRenderer->damageMonitor(PMONITOR); + + if (PMONITOR->specialWorkspaceID) + calculateWorkspace(PMONITOR->specialWorkspaceID); + + calculateWorkspace(PMONITOR->activeWorkspace); +} + +void CHyprMasterLayout::calculateWorkspace(const int& ws) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); if (!PWORKSPACE) return; - g_pHyprRenderer->damageMonitor(PMONITOR); + const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - if (PMONITOR->specialWorkspaceID) { - const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID); - - if (PSPECIALWS->m_bHasFullscreenWindow) { - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PSPECIALWS->m_iID); - - if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_FULL) { - PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; - PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PSPECIALWS->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { - SMasterNodeData fakeNode; - fakeNode.pWindow = PFULLWINDOW; - fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; - fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = PSPECIALWS->m_iID; - PFULLWINDOW->m_vPosition = fakeNode.position; - PFULLWINDOW->m_vSize = fakeNode.size; - fakeNode.ignoreFullscreenChecks = true; - - applyNodeDataToWindow(&fakeNode); - } - } - - calculateWorkspace(PMONITOR->specialWorkspaceID); - } + if (!PMONITOR) + return; if (PWORKSPACE->m_bHasFullscreenWindow) { // massive hack from the fullscreen func @@ -329,31 +315,22 @@ void CHyprMasterLayout::recalculateMonitor(const int& monid) { PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; } else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { SMasterNodeData fakeNode; - fakeNode.pWindow = PFULLWINDOW; - fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; - fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = PWORKSPACE->m_iID; - PFULLWINDOW->m_vPosition = fakeNode.position; - PFULLWINDOW->m_vSize = fakeNode.size; + fakeNode.pWindow = PFULLWINDOW; + fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; + fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; + fakeNode.workspaceID = PWORKSPACE->m_iID; + PFULLWINDOW->m_vPosition = fakeNode.position; + PFULLWINDOW->m_vSize = fakeNode.size; + fakeNode.ignoreFullscreenChecks = true; applyNodeDataToWindow(&fakeNode); } + // if has fullscreen, don't calculate the rest return; } - // calc the WS - calculateWorkspace(PWORKSPACE->m_iID); -} - -void CHyprMasterLayout::calculateWorkspace(const int& ws) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); - - if (!PWORKSPACE) - return; - const auto PWORKSPACEDATA = getMasterWorkspaceData(ws); - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); const auto PMASTERNODE = getMasterNodeOnWorkspace(PWORKSPACE->m_iID); if (!PMASTERNODE) From e68c07d8096ee5f83e29508c8762279ab80a924b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Mar 2024 01:05:26 +0000 Subject: [PATCH 0131/2897] renderer: don't render window on other mons during anim in fixes #5139 --- src/Window.cpp | 1 + src/Window.hpp | 1 + src/events/Windows.cpp | 3 +++ src/helpers/AnimatedVariable.hpp | 5 +++++ src/render/Renderer.cpp | 4 ++++ 5 files changed, 14 insertions(+) diff --git a/src/Window.cpp b/src/Window.cpp index 06b71763..c6c958ba 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -524,6 +524,7 @@ void CWindow::onMap() { "CWindow"); m_vReportedSize = m_vPendingReportedSize; + m_bAnimatingIn = true; for (const auto& ctrl : g_pHyprRenderer->m_vTearingControllers) { if (ctrl->pWlrHint->surface != m_pWLSurface.wlr()) diff --git a/src/Window.hpp b/src/Window.hpp index cb4fc057..11bd86c8 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -296,6 +296,7 @@ class CWindow { Vector2D m_vOriginalClosedPos; // these will be used for calculations later on in Vector2D m_vOriginalClosedSize; // drawing the closing animations SWindowDecorationExtents m_eOriginalClosedExtents; + bool m_bAnimatingIn = false; // For pinned (sticky) windows bool m_bPinned = false; diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 1e547efc..f38c1fb0 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -36,6 +36,9 @@ void setAnimToMove(void* data) { CBaseAnimatedVariable* animvar = (CBaseAnimatedVariable*)data; animvar->setConfig(PANIMCFG); + + if (animvar->getWindow() && !animvar->getWindow()->m_vRealPosition.isBeingAnimated() && !animvar->getWindow()->m_vRealSize.isBeingAnimated()) + animvar->getWindow()->m_bAnimatingIn = false; } void Events::listener_mapWindow(void* owner, void* data) { diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 005f2832..88c775af 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -52,6 +52,7 @@ class CWorkspace; struct SLayerSurface; struct SAnimationPropertyConfig; class CHyprRenderer; +class CWindow; // Utility to define a concept as a list of possible type template @@ -135,6 +136,10 @@ class CBaseAnimatedVariable { m_bRemoveEndAfterRan = false; } + CWindow* getWindow() { + return (CWindow*)m_pWindow; + } + protected: void* m_pWindow = nullptr; void* m_pWorkspace = nullptr; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 58f4b31a..112be432 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -524,6 +524,10 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* g_pHyprOpenGL->m_RenderData.clipBox = rg.getExtents(); } + // if window is tiled and it's flying in, don't render on other mons (for slide) + if (!ignorePosition && !pWindow->m_bIsFloating && pWindow->m_vRealPosition.isBeingAnimated() && pWindow->m_bAnimatingIn && pWindow->m_iMonitorID != pMonitor->ID) + return; + // render window decorations first, if not fullscreen full if (mode == RENDER_PASS_ALL || mode == RENDER_PASS_MAIN) { From 3ed3b34c4aea77484fa3325f9f95c001b8d6a0fa Mon Sep 17 00:00:00 2001 From: djvs <2954343+djvs@users.noreply.github.com> Date: Sun, 17 Mar 2024 11:41:43 -0400 Subject: [PATCH 0132/2897] keybinds: add Dispatchers for "force float" and "force tiling" (non-toggle) (#5137) --------- Co-authored-by: djvs --- src/managers/KeybindManager.cpp | 19 ++++++++++++++++++- src/managers/KeybindManager.hpp | 4 ++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 2125e9ba..e45930af 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -25,6 +25,8 @@ CKeybindManager::CKeybindManager() { m_mDispatchers["killactive"] = killActive; m_mDispatchers["closewindow"] = kill; m_mDispatchers["togglefloating"] = toggleActiveFloating; + m_mDispatchers["setfloating"] = setActiveFloating; + m_mDispatchers["settiled"] = setActiveTiled; m_mDispatchers["workspace"] = changeworkspace; m_mDispatchers["renameworkspace"] = renameWorkspace; m_mDispatchers["fullscreen"] = fullscreenActive; @@ -828,6 +830,18 @@ void CKeybindManager::clearKeybinds() { } void CKeybindManager::toggleActiveFloating(std::string args) { + return toggleActiveFloatingCore(args, std::nullopt); +} + +void CKeybindManager::setActiveFloating(std::string args) { + return toggleActiveFloatingCore(args, true); +} + +void CKeybindManager::setActiveTiled(std::string args) { + return toggleActiveFloatingCore(args, false); +} + +void toggleActiveFloatingCore(std::string args, std::optional floatState) { CWindow* PWINDOW = nullptr; if (args != "active" && args.length() > 1) @@ -838,12 +852,15 @@ void CKeybindManager::toggleActiveFloating(std::string args) { if (!PWINDOW) return; + if (floatState.has_value() && floatState == PWINDOW->m_bIsFloating) + return; + // remove drag status g_pInputManager->currentlyDraggedWindow = nullptr; if (PWINDOW->m_sGroupData.pNextWindow && PWINDOW->m_sGroupData.pNextWindow != PWINDOW) { + const auto PCURRENT = PWINDOW->getGroupCurrent(); - const auto PCURRENT = PWINDOW->getGroupCurrent(); PCURRENT->m_bIsFloating = !PCURRENT->m_bIsFloating; g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PCURRENT); diff --git a/src/managers/KeybindManager.hpp b/src/managers/KeybindManager.hpp index 07b77398..5244918d 100644 --- a/src/managers/KeybindManager.hpp +++ b/src/managers/KeybindManager.hpp @@ -120,6 +120,8 @@ class CKeybindManager { static uint64_t spawnRaw(std::string); static void toggleActiveFloating(std::string); static void toggleActivePseudo(std::string); + static void setActiveFloating(std::string); + static void setActiveTiled(std::string); static void changeworkspace(std::string); static void fullscreenActive(std::string); static void fakeFullscreenActive(std::string); @@ -179,4 +181,6 @@ class CKeybindManager { friend class CConfigManager; }; +static void toggleActiveFloatingCore(std::string args, std::optional floatState); + inline std::unique_ptr g_pKeybindManager; From 3c21f5e07b853b1b37a7aa38a5084a114f0c1983 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sun, 17 Mar 2024 11:43:59 -0400 Subject: [PATCH 0133/2897] swipe: Touchscreen workspace swipe (#4489) * Workspace Swipe: Refactor update and end functions * Touch: Implement workspace swipe better ignoring additional fingers and new touches allow gaps-right and gaps-left to be different --- src/config/ConfigManager.cpp | 1 + src/helpers/WLClasses.hpp | 1 + src/managers/input/InputManager.hpp | 2 + src/managers/input/Swipe.cpp | 18 +++++++-- src/managers/input/Touch.cpp | 63 +++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 89195a27..ecb0937f 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -498,6 +498,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("gestures:workspace_swipe_forever", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe_numbered", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe_use_r", Hyprlang::INT{0}); + m_pConfig->addConfigValue("gestures:workspace_swipe_touch", Hyprlang::INT{0}); m_pConfig->addConfigValue("xwayland:use_nearest_neighbor", Hyprlang::INT{1}); m_pConfig->addConfigValue("xwayland:force_zero_scaling", Hyprlang::INT{0}); diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 5fc2692a..d48fdff7 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -283,6 +283,7 @@ struct SSwipeGesture { int initialDirection = 0; float avgSpeed = 0; int speedPoints = 0; + int touch_id = 0; CMonitor* pMonitor = nullptr; }; diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index fd3aefe5..d63de6ef 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -231,6 +231,8 @@ class CInputManager { // swipe void beginWorkspaceSwipe(); + void updateWorkspaceSwipe(double); + void endWorkspaceSwipe(); void setBorderCursorIcon(eBorderIconDirection); void setCursorIconOnBorder(CWindow* w); diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 937266af..68f7aa25 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -44,7 +44,10 @@ void CInputManager::beginWorkspaceSwipe() { void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; // no valid swipe + endWorkspaceSwipe(); +} +void CInputManager::endWorkspaceSwipe() { static auto PSWIPEPERC = CConfigValue("gestures:workspace_swipe_cancel_ratio"); static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); static auto PSWIPEFORC = CConfigValue("gestures:workspace_swipe_min_speed_to_force"); @@ -192,11 +195,18 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { } void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { + static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); if (!m_sActiveSwipe.pWorkspaceBegin) return; + const double delta = m_sActiveSwipe.delta + (VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx)); + updateWorkspaceSwipe(delta); +} + +void CInputManager::updateWorkspaceSwipe(double delta) { static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); - static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); static auto PSWIPEDIRLOCK = CConfigValue("gestures:workspace_swipe_direction_lock"); static auto PSWIPEDIRLOCKTHRESHOLD = CConfigValue("gestures:workspace_swipe_direction_lock_threshold"); @@ -209,10 +219,10 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); + const double d = m_sActiveSwipe.delta - delta; + m_sActiveSwipe.delta = delta; - m_sActiveSwipe.delta += VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx); - - m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(e->dx)) / (m_sActiveSwipe.speedPoints + 1); + m_sActiveSwipe.avgSpeed = (m_sActiveSwipe.avgSpeed * m_sActiveSwipe.speedPoints + abs(d)) / (m_sActiveSwipe.speedPoints + 1); m_sActiveSwipe.speedPoints++; std::string wsname = ""; diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 3247a229..92f8316d 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -1,7 +1,15 @@ #include "InputManager.hpp" #include "../../Compositor.hpp" +#include "../../config/ConfigValue.hpp" void CInputManager::onTouchDown(wlr_touch_down_event* e) { + static auto PSWIPETOUCH = CConfigValue("gestures:workspace_swipe_touch"); + static auto PGAPSOUTDATA = CConfigValue("general:gaps_out"); + auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); + // TODO: WORKSPACERULE.gapsOut.value_or() + auto gapsOut = *PGAPSOUT; + static auto PBORDERSIZE = CConfigValue("general:border_size"); + static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); EMIT_HOOK_EVENT_CANCELLABLE("touchDown", e); auto PMONITOR = g_pCompositor->getMonitorFromName(e->touch->output_name ? e->touch->output_name : ""); @@ -24,6 +32,30 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { return; } + // Don't propagate new touches when a workspace swipe is in progress. + if (m_sActiveSwipe.pWorkspaceBegin) { + return; + // TODO: Don't swipe if you touched a floating window. + } else if (*PSWIPETOUCH && (!m_pFoundLSToFocus || m_pFoundLSToFocus->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + const bool VERTANIMS = PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); + // TODO: support no_gaps_when_only? + const double TARGETLEFT = ((VERTANIMS ? gapsOut.top : gapsOut.left) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x); + const double TARGETRIGHT = 1 - (((VERTANIMS ? gapsOut.bottom : gapsOut.right) + *PBORDERSIZE) / (VERTANIMS ? PMONITOR->vecSize.y : PMONITOR->vecSize.x)); + const double POSITION = (VERTANIMS ? e->y : e->x); + if (POSITION < TARGETLEFT || POSITION > TARGETRIGHT) { + beginWorkspaceSwipe(); + m_sActiveSwipe.touch_id = e->touch_id; + // Set the initial direction based on which edge you started from + if (POSITION > 0.5) + m_sActiveSwipe.initialDirection = *PSWIPEINVR ? -1 : 1; + else + m_sActiveSwipe.initialDirection = *PSWIPEINVR ? 1 : -1; + return; + } + } + m_bLastInputTouch = true; m_sTouchData.touchFocusWindow = m_pFoundWindowToFocus; @@ -55,6 +87,13 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { void CInputManager::onTouchUp(wlr_touch_up_event* e) { EMIT_HOOK_EVENT_CANCELLABLE("touchUp", e); + if (m_sActiveSwipe.pWorkspaceBegin) { + // If there was a swipe from this finger, end it. + if (e->touch_id == m_sActiveSwipe.touch_id) + endWorkspaceSwipe(); + return; + } + if (m_sTouchData.touchFocusSurface) { wlr_seat_touch_notify_up(g_pCompositor->m_sSeat.seat, e->time_msec, e->touch_id); } @@ -62,6 +101,30 @@ void CInputManager::onTouchUp(wlr_touch_up_event* e) { void CInputManager::onTouchMove(wlr_touch_motion_event* e) { EMIT_HOOK_EVENT_CANCELLABLE("touchMove", e); + if (m_sActiveSwipe.pWorkspaceBegin) { + // Do nothing if this is using a different finger. + if (e->touch_id != m_sActiveSwipe.touch_id) + return; + const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || + m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); + static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); + static auto PSWIPEDIST = CConfigValue("gestures:workspace_swipe_distance"); + // Handle the workspace swipe if there is one + if (m_sActiveSwipe.initialDirection == -1) { + if (*PSWIPEINVR) + // go from 0 to -PSWIPEDIST + updateWorkspaceSwipe(*PSWIPEDIST * ((VERTANIMS ? e->y : e->x) - 1)); + else + // go from 0 to -PSWIPEDIST + updateWorkspaceSwipe(*PSWIPEDIST * (-1 * (VERTANIMS ? e->y : e->x))); + } else if (*PSWIPEINVR) + // go from 0 to PSWIPEDIST + updateWorkspaceSwipe(*PSWIPEDIST * (VERTANIMS ? e->y : e->x)); + else + // go from 0 to PSWIPEDIST + updateWorkspaceSwipe(*PSWIPEDIST * (1 - (VERTANIMS ? e->y : e->x))); + return; + } if (m_sTouchData.touchFocusWindow && g_pCompositor->windowValidMapped(m_sTouchData.touchFocusWindow)) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_sTouchData.touchFocusWindow->m_iMonitorID); From 30c5911718c02e0215bf0006faa6aa229558a501 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Mar 2024 16:08:54 +0000 Subject: [PATCH 0134/2897] renderer: minor fixups for misaligned surface rendering offsets fixes #5136 --- src/Window.cpp | 3 +++ src/render/Renderer.cpp | 10 ++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Window.cpp b/src/Window.cpp index c6c958ba..59ad5a3b 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -1058,6 +1058,9 @@ bool CWindow::opaque() { if (m_fAlpha.value() != 1.f || m_fActiveInactiveAlpha.value() != 1.f) return false; + if (m_vRealSize.goal().floor() != m_vReportedSize) + return false; + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); if (m_pWLSurface.small() && !m_pWLSurface.m_bFillIgnoreSmall) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 112be432..e2bcbf1e 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -92,10 +92,12 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) } } - if (!INTERACTIVERESIZEINPROGRESS && PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { - Vector2D size = - Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; - Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; + if (!INTERACTIVERESIZEINPROGRESS && PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal().floor() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { + Vector2D coeff = PWINDOW->m_vReportedSize / PWINDOW->m_vRealSize.value(); + Vector2D coeff2 = PWINDOW->m_vReportedSize / PWINDOW->m_vRealSize.goal(); + + Vector2D size = Vector2D{windowBox.w, windowBox.h} * coeff; + Vector2D correct = Vector2D{windowBox.w, windowBox.h} - Vector2D{windowBox.w, windowBox.h} * coeff2; windowBox.translate(correct / 2.0); From c34ad12183506cb5f52bfb65b44e3a274e996fc3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 17 Mar 2024 19:00:21 +0000 Subject: [PATCH 0135/2897] cursormgr: scale hotspot with buffer --- src/managers/CursorManager.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index c3916e4b..c4b624d4 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -128,8 +128,8 @@ void CCursorManager::setCursorFromName(const std::string& name) { Vector2D{m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY})); if (g_pCompositor->m_sWLRCursor) { - wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[0].hotspotX, m_sCurrentCursorShapeData.images[0].hotspotY, - m_fCursorScale); + wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[0].hotspotX / m_fCursorScale, + m_sCurrentCursorShapeData.images[0].hotspotY / m_fCursorScale, m_fCursorScale); if (m_vCursorBuffers.size() > 1) wlr_buffer_drop(&m_vCursorBuffers.front()->wlrBuffer.base); } @@ -160,8 +160,8 @@ void CCursorManager::tickAnimatedCursor() { Vector2D{m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotX, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotY})); if (g_pCompositor->m_sWLRCursor) - wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotX, - m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotY, m_fCursorScale); + wlr_cursor_set_buffer(g_pCompositor->m_sWLRCursor, getCursorBuffer(), m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotX / m_fCursorScale, + m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].hotspotY / m_fCursorScale, m_fCursorScale); wl_event_source_timer_update(m_pAnimationTimer, m_sCurrentCursorShapeData.images[m_iCurrentAnimationFrame].delay); } From 7587cadd0a4e94c9ba42c00307854052798cf9b2 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Mar 2024 04:15:04 +0000 Subject: [PATCH 0136/2897] renderer: add support for gles3.2 screen shaders --- src/render/OpenGL.cpp | 2 +- src/render/shaders/Textures.hpp | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 30803885..f79a10d1 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -547,7 +547,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { std::string fragmentShader((std::istreambuf_iterator(infile)), (std::istreambuf_iterator())); - m_sFinalScreenShader.program = createProgram(TEXVERTSRC, fragmentShader, true); + m_sFinalScreenShader.program = createProgram(fragmentShader.starts_with("#version 320 es") ? TEXVERTSRC320 : TEXVERTSRC, fragmentShader, true); if (!m_sFinalScreenShader.program) { g_pConfigManager->addParseError("Screen shader parser: Screen shader parse failed"); diff --git a/src/render/shaders/Textures.hpp b/src/render/shaders/Textures.hpp index 5e346c1e..59c7304f 100644 --- a/src/render/shaders/Textures.hpp +++ b/src/render/shaders/Textures.hpp @@ -80,6 +80,17 @@ void main() { v_texcoord = texcoord; })#"; +inline const std::string TEXVERTSRC320 = R"#(#version 320 es +uniform mat3 proj; +in vec2 pos; +in vec2 texcoord; +out vec2 v_texcoord; + +void main() { + gl_Position = vec4(proj * vec3(pos, 1.0), 1.0); + v_texcoord = texcoord; +})#"; + inline const std::string TEXFRAGSRCRGBA = R"#( precision highp float; varying vec2 v_texcoord; // is in 0-1 From 5eb33ff4d866ab64e5db33725473dc020fe355c1 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Mar 2024 16:35:22 +0000 Subject: [PATCH 0137/2897] screenshader: add screen_size uniform fixes #5059 --- src/render/OpenGL.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index f79a10d1..c06c81dc 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -558,6 +558,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.tex = glGetUniformLocation(m_sFinalScreenShader.program, "tex"); m_sFinalScreenShader.time = glGetUniformLocation(m_sFinalScreenShader.program, "time"); m_sFinalScreenShader.wl_output = glGetUniformLocation(m_sFinalScreenShader.program, "wl_output"); + m_sFinalScreenShader.fullSize = glGetUniformLocation(m_sFinalScreenShader.program, "screen_size"); if (m_sFinalScreenShader.time != -1 && *PDT != 0 && !g_pHyprRenderer->m_bCrashingInProgress) { // The screen shader uses the "time" uniform // Since the screen shader could change every frame, damage tracking *needs* to be disabled @@ -852,6 +853,8 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* if (usingFinalShader && shader->wl_output != -1) glUniform1i(shader->wl_output, m_RenderData.pMonitor->ID); + if (usingFinalShader && shader->fullSize != -1) + glUniform2f(shader->fullSize, m_RenderData.pMonitor->vecPixelSize.x, m_RenderData.pMonitor->vecPixelSize.y); if (CRASHING) { glUniform1f(shader->distort, g_pHyprRenderer->m_fCrashingDistort); From 4b74123649a42954453a7f4a452faa9ab94ecd08 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Mar 2024 18:11:20 +0000 Subject: [PATCH 0138/2897] socket2: add pin event fixes #4778 --- src/managers/KeybindManager.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index e45930af..4b406cb6 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -2037,6 +2037,9 @@ void CKeybindManager::pinActive(std::string args) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS); + + g_pEventManager->postEvent(SHyprIPCEvent{"pin", std::format("{:x},{}", (uintptr_t)PWINDOW, (int)PWINDOW->m_bPinned)}); + EMIT_HOOK_EVENT("pin", PWINDOW); } void CKeybindManager::mouse(std::string args) { From 4ffcdc41ff8233a92f02c633475ac3472b0998df Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Mar 2024 18:29:57 +0000 Subject: [PATCH 0139/2897] animations: fix layer slide with fade fixes #5151 --- src/helpers/WLClasses.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index c71271c8..d46f7e40 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -87,7 +87,8 @@ void SLayerSurface::startAnimation(bool in, bool instant) { } realSize.setValueAndWarp(geometry.size()); - alpha.setValueAndWarp(1.f); + alpha.setValueAndWarp(in ? 0.f : 1.f); + alpha = in ? 1.f : 0.f; Vector2D prePos; From 7283dde8784ece1e5c0a47e9cbcc1696535ef098 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 18 Mar 2024 23:51:32 +0000 Subject: [PATCH 0140/2897] screenShader: allow camel for screensize ref #5059 --- src/render/OpenGL.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index c06c81dc..c1375ba5 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -559,6 +559,8 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.time = glGetUniformLocation(m_sFinalScreenShader.program, "time"); m_sFinalScreenShader.wl_output = glGetUniformLocation(m_sFinalScreenShader.program, "wl_output"); m_sFinalScreenShader.fullSize = glGetUniformLocation(m_sFinalScreenShader.program, "screen_size"); + if (m_sFinalScreenShader.fullSize == -1) + m_sFinalScreenShader.fullSize = glGetUniformLocation(m_sFinalScreenShader.program, "screenSize"); if (m_sFinalScreenShader.time != -1 && *PDT != 0 && !g_pHyprRenderer->m_bCrashingInProgress) { // The screen shader uses the "time" uniform // Since the screen shader could change every frame, damage tracking *needs* to be disabled From 49f5fd59adbef25dc2c97364690fe747c8cc09e8 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 02:42:30 +0000 Subject: [PATCH 0141/2897] opengl: minor adjustment to getPreferredReadFormat fixes #4791 --- src/protocols/ToplevelExport.cpp | 11 ----------- src/render/OpenGL.cpp | 6 +++--- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index 88e56954..e3273f7a 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -179,17 +179,6 @@ void CToplevelExportProtocolManager::captureToplevel(wl_client* client, wl_resou g_pHyprRenderer->makeEGLCurrent(); - if (g_pHyprOpenGL->m_mMonitorRenderResources.contains(PMONITOR)) { - const auto& RDATA = g_pHyprOpenGL->m_mMonitorRenderResources.at(PMONITOR); - // bind the fb for its format. Suppress gl errors. -#ifndef GLES2 - glBindFramebuffer(GL_READ_FRAMEBUFFER, RDATA.offloadFB.m_iFb); -#else - glBindFramebuffer(GL_FRAMEBUFFER, RDATA.offloadFB.m_iFb); -#endif - } else - Debug::log(ERR, "No RDATA in toplevelexport???"); - PFRAME->shmFormat = g_pHyprOpenGL->getPreferredReadFormat(PMONITOR); if (PFRAME->shmFormat == DRM_FORMAT_INVALID) { Debug::log(ERR, "No format supported by renderer in capture toplevel"); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index c1375ba5..d34a90b0 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -2286,10 +2286,10 @@ inline const SGLPixelFormat GLES2_FORMATS[] = { }; uint32_t CHyprOpenGLImpl::getPreferredReadFormat(CMonitor* pMonitor) { - GLint glf = -1, glt = -1, as = -1; - glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf); + GLint glf = -1, glt = -1, as = 0; + /*glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT, &glf); glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE, &glt); - glGetIntegerv(GL_ALPHA_BITS, &as); + glGetIntegerv(GL_ALPHA_BITS, &as);*/ if (glf == 0 || glt == 0) { glf = drmFormatToGL(pMonitor->drmFormat); From 7a31c954e5962db07b1b83e8a7340c38e7988ab6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 02:45:11 +0000 Subject: [PATCH 0142/2897] tablet: minor focus fixes ref #3004 --- src/managers/input/Tablets.cpp | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index f692620c..387212c7 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -39,7 +39,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { switch (EVENT->tool->type) { case WLR_TABLET_TOOL_TYPE_MOUSE: wlr_cursor_move(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, EVENT->dx, EVENT->dy); - g_pInputManager->refocus(); + g_pInputManager->simulateMouseMovement(); + g_pInputManager->focusTablet(PTAB, EVENT->tool, true); g_pInputManager->m_tmrLastCursorMovement.reset(); break; default: @@ -53,7 +54,8 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { else wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, x, y); - g_pInputManager->refocus(); + g_pInputManager->simulateMouseMovement(); + g_pInputManager->focusTablet(PTAB, EVENT->tool, true); g_pInputManager->m_tmrLastCursorMovement.reset(); break; } @@ -62,7 +64,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { // TODO: this might be wrong if (PTOOL->active) { - g_pInputManager->refocus(); + g_pInputManager->simulateMouseMovement(); g_pInputManager->focusTablet(PTAB, EVENT->tool, true); } @@ -105,7 +107,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { // TODO: this might be wrong if (EVENT->state == WLR_TABLET_TOOL_TIP_DOWN) { - g_pInputManager->refocus(); + g_pInputManager->simulateMouseMovement(); g_pInputManager->focusTablet(PTAB, EVENT->tool); wlr_send_tablet_v2_tablet_tool_down(PTOOL->wlrTabletToolV2); } else { @@ -146,7 +148,7 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { } else { PTOOL->active = true; - g_pInputManager->refocus(); + g_pInputManager->simulateMouseMovement(); g_pInputManager->focusTablet(PTAB, EVENT->tool); } @@ -258,12 +260,12 @@ void CInputManager::focusTablet(STablet* pTab, wlr_tablet_tool* pTool, bool moti if (const auto PWINDOW = g_pCompositor->m_pLastWindow; PWINDOW) { const auto CURSORPOS = g_pInputManager->getMouseCoordsInternal(); - if (PTOOL->pSurface != g_pCompositor->m_pLastFocus) + if (PTOOL->pSurface != g_pInputManager->m_pLastMouseSurface) wlr_tablet_v2_tablet_tool_notify_proximity_out(PTOOL->wlrTabletToolV2); - if (g_pCompositor->m_pLastFocus) { + if (g_pInputManager->m_pLastMouseSurface) { PTOOL->pSurface = g_pCompositor->m_pLastFocus; - wlr_tablet_v2_tablet_tool_notify_proximity_in(PTOOL->wlrTabletToolV2, pTab->wlrTabletV2, g_pCompositor->m_pLastFocus); + wlr_tablet_v2_tablet_tool_notify_proximity_in(PTOOL->wlrTabletToolV2, pTab->wlrTabletV2, g_pInputManager->m_pLastMouseSurface); } if (motion) { From e6532ba024762ba15423ae0a0935dfe4fb4196b1 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 18 Mar 2024 19:52:52 -0700 Subject: [PATCH 0143/2897] animations: Fix incorrect animation when manually moving a window when its being created (#5141) * fix incorrect rendering when manually moving a window when its being created * add setAnimationsToMove --- src/Window.cpp | 9 +++++++++ src/Window.hpp | 1 + src/layout/DwindleLayout.cpp | 5 +++++ src/layout/IHyprLayout.cpp | 2 ++ src/layout/MasterLayout.cpp | 5 +++++ 5 files changed, 22 insertions(+) diff --git a/src/Window.cpp b/src/Window.cpp index 59ad5a3b..8130f017 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -389,6 +389,8 @@ void CWindow::moveToWorkspace(int workspaceID) { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + setAnimationsToMove(); + updateSpecialRenderData(); if (PWORKSPACE) { @@ -1147,3 +1149,10 @@ bool CWindow::visibleOnMonitor(CMonitor* pMonitor) { return wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, wbox.pWlr()); } + +void CWindow::setAnimationsToMove() { + auto* const PANIMCFG = g_pConfigManager->getAnimationPropertyConfig("windowsMove"); + m_vRealPosition.setConfig(PANIMCFG); + m_vRealSize.setConfig(PANIMCFG); + m_bAnimatingIn = false; +} diff --git a/src/Window.hpp b/src/Window.hpp index 11bd86c8..8350e197 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -419,6 +419,7 @@ class CWindow { void insertWindowToGroup(CWindow* pWindow); void updateGroupOutputs(); void switchWithWindowInGroup(CWindow* pWindow); + void setAnimationsToMove(); private: // For hidden windows and stuff diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 1ce6aa82..c34f04cc 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -924,6 +924,8 @@ void CHyprDwindleLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) default: UNREACHABLE(); } + pWindow->setAnimationsToMove(); + onWindowRemovedTiling(pWindow); m_vOverrideFocalPoint = focalPoint; @@ -969,6 +971,9 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); } + pWindow->setAnimationsToMove(); + pWindow2->setAnimationsToMove(); + // recalc the workspace getMasterNodeOnWorkspace(PNODE->workspaceID)->recalcSizePosRecursive(); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index f992899d..c8c00183 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -552,6 +552,8 @@ void IHyprLayout::moveActiveWindow(const Vector2D& delta, CWindow* pWindow) { return; } + PWINDOW->setAnimationsToMove(); + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + delta; g_pHyprRenderer->damageWindow(PWINDOW); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 7919d50f..1c6be8d6 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -970,6 +970,8 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { const auto PWINDOW2 = g_pCompositor->getWindowInDirection(pWindow, dir[0]); + pWindow->setAnimationsToMove(); + if (pWindow->m_iWorkspaceID != PWINDOW2->m_iWorkspaceID) { // if different monitors, send to monitor onWindowRemovedTiling(pWindow); @@ -1002,6 +1004,9 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { PNODE->pWindow = pWindow2; PNODE2->pWindow = pWindow; + pWindow->setAnimationsToMove(); + pWindow2->setAnimationsToMove(); + recalculateMonitor(pWindow->m_iMonitorID); if (PNODE2->workspaceID != PNODE->workspaceID) recalculateMonitor(pWindow2->m_iMonitorID); From 7617c03dfd0073654ca8c4d9a6f5db278d14cd28 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 02:53:10 +0000 Subject: [PATCH 0144/2897] window: set config only when both props end anims --- src/events/Windows.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index f38c1fb0..7c4ae404 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -35,10 +35,10 @@ void setAnimToMove(void* data) { CBaseAnimatedVariable* animvar = (CBaseAnimatedVariable*)data; - animvar->setConfig(PANIMCFG); - - if (animvar->getWindow() && !animvar->getWindow()->m_vRealPosition.isBeingAnimated() && !animvar->getWindow()->m_vRealSize.isBeingAnimated()) + if (animvar->getWindow() && !animvar->getWindow()->m_vRealPosition.isBeingAnimated() && !animvar->getWindow()->m_vRealSize.isBeingAnimated()) { + animvar->setConfig(PANIMCFG); animvar->getWindow()->m_bAnimatingIn = false; + } } void Events::listener_mapWindow(void* owner, void* data) { From 05c84304ccb1169b550504830139e07e28500a3b Mon Sep 17 00:00:00 2001 From: Epilepsy Gatherings <73647246+phonetic112@users.noreply.github.com> Date: Mon, 18 Mar 2024 22:53:51 -0400 Subject: [PATCH 0145/2897] github: remove redundant instruction (#5163) v0.34.0 is pretty old at this point. --- .github/ISSUE_TEMPLATE/bug.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index b6582979..2305c650 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -13,7 +13,7 @@ body: id: ver attributes: label: Hyprland Version - description: "Paste here the output of `hyprctl version`. For hyprland after 0.34.0, paste `hyprctl systeminfo` instead." + description: "Paste the output of `hyprctl systeminfo` here." value: "
System/Version info From 5c1097cbc19131a7770b2a3f01f6f24e626991d2 Mon Sep 17 00:00:00 2001 From: joshua <54235339+sujoshua@users.noreply.github.com> Date: Tue, 19 Mar 2024 23:54:33 +0800 Subject: [PATCH 0146/2897] IME: Improve handling of text-input and ime-relay (#5147) * input: Handling multiple surfaces for the text-input-v1 protocol implementation and imporve InputMethodRelay logic fixes #2708 * clang-format * minor style nits --------- Co-authored-by: Vaxry --- src/helpers/WLClasses.hpp | 9 +- src/managers/input/InputMethodRelay.cpp | 207 ++++++++++++++---------- src/managers/input/InputMethodRelay.hpp | 21 ++- src/protocols/TextInputV1.cpp | 8 +- 4 files changed, 145 insertions(+), 100 deletions(-) diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index d48fdff7..57f216b8 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -291,17 +291,14 @@ struct SSwipeGesture { struct STextInputV1; struct STextInput { - wlr_text_input_v3* pWlrInput = nullptr; - STextInputV1* pV1Input = nullptr; - - wlr_surface* pPendingSurface = nullptr; + wlr_text_input_v3* pWlrInput = nullptr; + STextInputV1* pV1Input = nullptr; + wlr_surface* focusedSurface = nullptr; DYNLISTENER(textInputEnable); DYNLISTENER(textInputDisable); DYNLISTENER(textInputCommit); DYNLISTENER(textInputDestroy); - - DYNLISTENER(pendingSurfaceDestroy); }; struct SIMEKbGrab { diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index fb668cc2..44ba3e42 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -87,14 +87,8 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { Debug::log(LOG, "IME Destroy"); - if (PTI) { - setPendingSurface(PTI, focusedSurface(PTI)); - - if (PTI->pWlrInput) - wlr_text_input_v3_send_leave(PTI->pWlrInput); - else - zwp_text_input_v1_send_leave(PTI->pV1Input->resourceImpl); - } + if (PTI) + onTextInputEnter(PTI->focusedSurface); }, this, "IMERelay"); @@ -144,16 +138,8 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { }, this, "IMERelay"); - const auto PTI = getFocusableTextInput(); - - if (PTI) { - if (PTI->pWlrInput) - wlr_text_input_v3_send_enter(PTI->pWlrInput, PTI->pPendingSurface); - else - zwp_text_input_v1_send_enter(PTI->pV1Input->resourceImpl, PTI->pPendingSurface->resource); - - setPendingSurface(PTI, nullptr); - } + if (const auto PTI = getFocusedTextInput(); PTI) + onTextInputEnter(PTI->focusedSurface); } wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) { @@ -322,22 +308,8 @@ SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) { } STextInput* CInputMethodRelay::getFocusedTextInput() { - - for (auto& ti : m_lTextInputs) { - if (focusedSurface(&ti)) { - return &ti; - } - } - - return nullptr; -} - -STextInput* CInputMethodRelay::getFocusableTextInput() { - for (auto& ti : m_lTextInputs) { - if (ti.pPendingSurface) { - return &ti; - } - } + if (m_pFocusedSurface) + return getTextInput(m_pFocusedSurface); return nullptr; } @@ -347,6 +319,13 @@ void CInputMethodRelay::onNewTextInput(wlr_text_input_v3* pInput) { } void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInputV1* pTIV1) { + + if (pInput) { + if (!setTextInputVersion(wl_resource_get_client(pInput->resource), 3)) + return; + } else if (!setTextInputVersion(pTIV1->client, 1)) + return; + const auto PTEXTINPUT = &m_lTextInputs.emplace_back(); PTEXTINPUT->pWlrInput = pInput; @@ -357,7 +336,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput PTEXTINPUT->hyprListener_textInputEnable.initCallback( pInput ? &pInput->events.enable : &pTIV1->sEnable, - [](void* owner, void* data) { + [&](void* owner, void* data) { const auto PINPUT = (STextInput*)owner; if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { @@ -365,6 +344,15 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput return; } + // v1 only, map surface to PTI + if (PINPUT->pV1Input) { + wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data); + PINPUT->focusedSurface = pSurface; + setSurfaceToPTI(pSurface, PINPUT); + if (m_pFocusedSurface == pSurface) + onTextInputEnter(pSurface); + } + Debug::log(LOG, "Enable TextInput"); wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); @@ -405,6 +393,7 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(PINPUT); g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); }, PTEXTINPUT, "textInput"); @@ -425,13 +414,13 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); } - g_pInputManager->m_sIMERelay.setPendingSurface(PINPUT, nullptr); - PINPUT->hyprListener_textInputCommit.removeCallback(); PINPUT->hyprListener_textInputDestroy.removeCallback(); PINPUT->hyprListener_textInputDisable.removeCallback(); PINPUT->hyprListener_textInputEnable.removeCallback(); + g_pInputManager->m_sIMERelay.removeTextInputVersion(PINPUT->pWlrInput ? wl_resource_get_client(PINPUT->pWlrInput->resource) : PINPUT->pV1Input->client); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(PINPUT); g_pInputManager->m_sIMERelay.removeTextInput(PINPUT); }, PTEXTINPUT, "textInput"); @@ -478,64 +467,110 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (!m_pWLRIME) return; - auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; }; + if (pSurface == m_pFocusedSurface) + return; - for (auto& ti : m_lTextInputs) { - if (ti.pPendingSurface) { + // say goodbye to the last focused surface + if (STextInput* lastTI = getTextInput(m_pFocusedSurface); lastTI) { + wlr_input_method_v2_send_deactivate(m_pWLRIME); + commitIMEState(lastTI); + onTextInputLeave(m_pFocusedSurface); + } - if (pSurface != ti.pPendingSurface) - setPendingSurface(&ti, nullptr); + // do some work for the new focused surface + m_pFocusedSurface = pSurface; - } else if (focusedSurface(&ti)) { - - if (pSurface != focusedSurface(&ti)) { - wlr_input_method_v2_send_deactivate(m_pWLRIME); - commitIMEState(&ti); - - if (ti.pWlrInput) - wlr_text_input_v3_send_leave(ti.pWlrInput); - else { - zwp_text_input_v1_send_leave(ti.pV1Input->resourceImpl); - ti.pV1Input->focusedSurface = nullptr; - ti.pV1Input->active = false; - } - } else { - continue; - } - } - - if (pSurface && client(&ti) == wl_resource_get_client(pSurface->resource)) { - - if (m_pWLRIME) { - if (ti.pWlrInput) - wlr_text_input_v3_send_enter(ti.pWlrInput, pSurface); - else { - zwp_text_input_v1_send_enter(ti.pV1Input->resourceImpl, pSurface->resource); - ti.pV1Input->focusedSurface = pSurface; - ti.pV1Input->active = true; - } - } else { - setPendingSurface(&ti, pSurface); + /* + * v3 only. v1 is handled by hyprListener_textInputEnable. + * POSSIBLE BUG here: if one client has multiple STextInput and multiple surfaces, for any pSurface we can only record the last found ti. + * since original code has the same problem, it may not be a big deal. + */ + if (getTextInputVersion(wl_resource_get_client(pSurface->resource)) == 3) { + if (!getTextInput(pSurface)) { + auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; }; + for (auto& ti : m_lTextInputs) { + if (client(&ti) == wl_resource_get_client(pSurface->resource) && ti.pWlrInput) + setSurfaceToPTI(pSurface, &ti); } } } + + onTextInputEnter(m_pFocusedSurface); } -void CInputMethodRelay::setPendingSurface(STextInput* pInput, wlr_surface* pSurface) { - pInput->pPendingSurface = pSurface; +void CInputMethodRelay::onTextInputLeave(wlr_surface* pSurface) { + if (!pSurface) + return; + STextInput* ti = getTextInput(pSurface); + if (!ti) + return; + + if (ti->pWlrInput) + wlr_text_input_v3_send_leave(ti->pWlrInput); + else { + zwp_text_input_v1_send_leave(ti->pV1Input->resourceImpl); + ti->pV1Input->focusedSurface = nullptr; + ti->pV1Input->active = false; + } +} + +void CInputMethodRelay::onTextInputEnter(wlr_surface* pSurface) { + if (!pSurface) + return; + + STextInput* ti = getTextInput(pSurface); + if (!ti) + return; + + if (ti->pWlrInput) + wlr_text_input_v3_send_enter(ti->pWlrInput, pSurface); + else { + zwp_text_input_v1_send_enter(ti->pV1Input->resourceImpl, pSurface->resource); + ti->pV1Input->focusedSurface = pSurface; + ti->pV1Input->active = true; + } +} + +void CInputMethodRelay::setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput) { if (pSurface) { - pInput->hyprListener_pendingSurfaceDestroy.initCallback( - &pSurface->events.destroy, - [](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; - - PINPUT->pPendingSurface = nullptr; - - PINPUT->hyprListener_pendingSurfaceDestroy.removeCallback(); - }, - pInput, "TextInput"); - } else { - pInput->hyprListener_pendingSurfaceDestroy.removeCallback(); + m_mSurfaceToTextInput[pSurface] = pInput; + pInput->focusedSurface = pSurface; } } + +void CInputMethodRelay::removeSurfaceToPTI(STextInput* pInput) { + if (pInput->focusedSurface) { + m_mSurfaceToTextInput.erase(pInput->focusedSurface); + pInput->focusedSurface = nullptr; + } +} + +STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface) { + auto result = m_mSurfaceToTextInput.find(pSurface); + if (result != m_mSurfaceToTextInput.end()) + return result->second; + + return nullptr; +} + +int CInputMethodRelay::setTextInputVersion(wl_client* pClient, int version) { + if (int v = getTextInputVersion(pClient); v != 0 && v != version) { + Debug::log(WARN, "Client attempt to register text-input-v{}, but it has already registered text-input-v{}, ignored", version, v); + return 0; + } + m_mClientTextInputVersion.insert({pClient, version}); + return 1; +} + +int CInputMethodRelay::getTextInputVersion(wl_client* pClient) { + auto result = m_mClientTextInputVersion.find(pClient); + if (result != m_mClientTextInputVersion.end()) + return result->second; + + return 0; +} + +void CInputMethodRelay::removeTextInputVersion(wl_client* pClient) { + m_mClientTextInputVersion.erase(pClient); +} diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index 9f9e95f6..39465cab 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -22,9 +22,6 @@ class CInputMethodRelay { void onKeyboardFocus(wlr_surface*); STextInput* getFocusedTextInput(); - STextInput* getFocusableTextInput(); - - void setPendingSurface(STextInput*, wlr_surface*); SIMEKbGrab* getIMEKeyboardGrab(SKeyboard*); @@ -45,8 +42,22 @@ class CInputMethodRelay { DYNLISTENER(IMEGrab); DYNLISTENER(IMENewPopup); - void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr); - wlr_surface* focusedSurface(STextInput* pInput); + void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr); + + wlr_surface* focusedSurface(STextInput* pInput); + wlr_surface* m_pFocusedSurface; + void onTextInputLeave(wlr_surface* pSurface); + void onTextInputEnter(wlr_surface* pSurface); + + std::unordered_map m_mSurfaceToTextInput; + void setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput); + STextInput* getTextInput(wlr_surface* pSurface); + void removeSurfaceToPTI(STextInput* pInput); + + std::unordered_map m_mClientTextInputVersion; + int setTextInputVersion(wl_client* pClient, int version); + int getTextInputVersion(wl_client* pClient); + void removeTextInputVersion(wl_client* pClient); friend class CHyprRenderer; friend class CInputManager; diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp index d69a79ca..8d1f6f97 100644 --- a/src/protocols/TextInputV1.cpp +++ b/src/protocols/TextInputV1.cpp @@ -113,8 +113,6 @@ void CTextInputV1ProtocolManager::removeTI(STextInputV1* pTI) { // if ((*TI)->resourceImpl) // wl_resource_destroy((*TI)->resourceImpl); - g_pInputManager->m_sIMERelay.removeTextInput((*TI)->pTextInput); - std::erase_if(m_pClients, [&](const auto& other) { return other.get() == pTI; }); } @@ -165,7 +163,11 @@ void CTextInputV1ProtocolManager::createTI(wl_client* client, wl_resource* resou void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) { const auto PTI = tiFromResource(resource); - PTI->pTextInput->hyprListener_textInputEnable.emit(nullptr); + if (!surface) { + Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI); + return; + } + PTI->pTextInput->hyprListener_textInputEnable.emit(surface); } void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) { From bcba3951f45f11245d424274130eb3a0ac790d93 Mon Sep 17 00:00:00 2001 From: phonetic112 <73647246+phonetic112@users.noreply.github.com> Date: Tue, 19 Mar 2024 12:03:31 -0400 Subject: [PATCH 0147/2897] input: Only limit drag resizes (#5164) * only limit drag resizes * change to not equals * remove extra parentheses --- src/layout/IHyprLayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index c8c00183..02f39d94 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -355,7 +355,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { canSkipUpdate = std::clamp(MSMONITOR - TIMERDELTA, 0.0, MSMONITOR) > totalMs * 1.0 / m_iMouseMoveEventCount; } - if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || (TIMERDELTA < MSMONITOR && canSkipUpdate)) + if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || (TIMERDELTA < MSMONITOR && canSkipUpdate && g_pInputManager->dragMode != MBIND_MOVE)) return; TIMER = std::chrono::high_resolution_clock::now(); From c32b2331d10605488d3f901189c975513c2823ad Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 18:55:17 +0000 Subject: [PATCH 0148/2897] constraint: set active flag before propagating props fixes #5170 --- src/desktop/Constraint.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/desktop/Constraint.cpp b/src/desktop/Constraint.cpp index 662f0990..2109ef1c 100644 --- a/src/desktop/Constraint.cpp +++ b/src/desktop/Constraint.cpp @@ -92,9 +92,10 @@ void CConstraint::deactivate() { if (!m_bActive) return; - wlr_pointer_constraint_v1_send_deactivated(m_pConstraint); m_bActive = false; + wlr_pointer_constraint_v1_send_deactivated(m_pConstraint); + if (isLocked()) g_pCompositor->warpCursorTo(logicPositionHint(), true); @@ -106,6 +107,8 @@ void CConstraint::activate() { if (m_bActive || m_bDead) return; + m_bActive = true; + // TODO: hack, probably not a super duper great idea if (g_pCompositor->m_sSeat.seat->pointer_state.focused_surface != m_pOwner->wlr()) { const auto SURFBOX = m_pOwner->getSurfaceBoxGlobal(); @@ -115,7 +118,6 @@ void CConstraint::activate() { g_pCompositor->warpCursorTo(logicPositionHint(), true); wlr_pointer_constraint_v1_send_activated(m_pConstraint); - m_bActive = true; } bool CConstraint::active() { From 05cd6d3df1e5faf3f7476724b0cfb156f4be43f6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 20:56:20 +0000 Subject: [PATCH 0149/2897] config/workspace: added workspace selectors --- src/Compositor.cpp | 4 +- src/Compositor.hpp | 2 +- src/Window.hpp | 14 +-- src/config/ConfigManager.cpp | 50 ++++---- src/desktop/Workspace.cpp | 202 ++++++++++++++++++++++++++++++++ src/desktop/Workspace.hpp | 2 + src/managers/KeybindManager.cpp | 4 +- 7 files changed, 239 insertions(+), 39 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 42ba9b5f..3ff67f20 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1290,10 +1290,10 @@ void CCompositor::sanityCheckWorkspaces() { } } -int CCompositor::getWindowsOnWorkspace(const int& id) { +int CCompositor::getWindowsOnWorkspace(const int& id, std::optional onlyTiled) { int no = 0; for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == id && w->m_bIsMapped) + if (w->m_iWorkspaceID == id && w->m_bIsMapped && !(onlyTiled.has_value() && !w->m_bIsFloating != onlyTiled.value())) no++; } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 84667656..56b83774 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -149,7 +149,7 @@ class CCompositor { CWorkspace* getWorkspaceByString(const std::string&); void sanityCheckWorkspaces(); void updateWorkspaceWindowDecos(const int&); - int getWindowsOnWorkspace(const int&); + int getWindowsOnWorkspace(const int& id, std::optional onlyTiled = {}); CWindow* getUrgentWindow(); bool hasUrgentWindowOnWorkspace(const int&); CWindow* getFirstWindowOnWorkspace(const int&); diff --git a/src/Window.hpp b/src/Window.hpp index 8350e197..d98bc921 100644 --- a/src/Window.hpp +++ b/src/Window.hpp @@ -175,13 +175,13 @@ struct SWindowRule { std::string szClass; std::string szInitialTitle; std::string szInitialClass; - int bX11 = -1; // -1 means "ANY" - int bFloating = -1; - int bFullscreen = -1; - int bPinned = -1; - int bFocus = -1; - int iOnWorkspace = -1; - std::string szWorkspace = ""; // empty means any + int bX11 = -1; // -1 means "ANY" + int bFloating = -1; + int bFullscreen = -1; + int bPinned = -1; + int bFocus = -1; + std::string szOnWorkspace = ""; // empty means any + std::string szWorkspace = ""; // empty means any }; class CWindow { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index ecb0937f..ee7b90bf 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -937,13 +937,7 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) { } SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) { - const auto WORKSPACEIDSTR = std::to_string(pWorkspace->m_iID); - const auto IT = std::find_if(m_dWorkspaceRules.begin(), m_dWorkspaceRules.end(), [&](const auto& other) { - return other.workspaceName == pWorkspace->m_szName /* name matches */ - || (pWorkspace->m_bIsSpecialWorkspace && other.workspaceName.starts_with("special:") && - other.workspaceName.substr(8) == pWorkspace->m_szName) /* special and special:name */ - || (pWorkspace->m_iID > 0 && WORKSPACEIDSTR == other.workspaceName); /* id matches and workspace is numerical */ - }); + const auto IT = std::find_if(m_dWorkspaceRules.begin(), m_dWorkspaceRules.end(), [&](const auto& other) { return pWorkspace->matchesStaticSelector(other.workspaceString); }); if (IT == m_dWorkspaceRules.end()) return SWorkspaceRule{}; return *IT; @@ -1039,8 +1033,9 @@ std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool continue; } - if (rule.iOnWorkspace != -1) { - if (rule.iOnWorkspace != g_pCompositor->getWindowsOnWorkspace(pWindow->m_iWorkspaceID)) + if (!rule.szOnWorkspace.empty()) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + if (!PWORKSPACE || !PWORKSPACE->matchesStaticSelector(rule.szOnWorkspace)) continue; } @@ -1327,9 +1322,8 @@ std::string CConfigManager::getBoundMonitorStringForWS(const std::string& wsname for (auto& wr : m_dWorkspaceRules) { const auto WSNAME = wr.workspaceName.starts_with("name:") ? wr.workspaceName.substr(5) : wr.workspaceName; - if (WSNAME == wsname) { + if (WSNAME == wsname) return wr.monitor; - } } return ""; @@ -2065,7 +2059,7 @@ std::optional CConfigManager::handleWindowRuleV2(const std::string& rule.bFocus = extract(FOCUSPOS + 6) == "1" ? 1 : 0; if (ONWORKSPACEPOS != std::string::npos) - rule.iOnWorkspace = configStringToInt(extract(ONWORKSPACEPOS + 12)); + rule.szOnWorkspace = extract(ONWORKSPACEPOS + 12); if (RULE == "unset") { std::erase_if(m_dWindowRules, [&](const SWindowRule& other) { @@ -2102,7 +2096,7 @@ std::optional CConfigManager::handleWindowRuleV2(const std::string& if (rule.bFocus != -1 && rule.bFocus != other.bFocus) return false; - if (rule.iOnWorkspace != -1 && rule.iOnWorkspace != other.iOnWorkspace) + if (!rule.szOnWorkspace.empty() && rule.szOnWorkspace != other.szOnWorkspace) return false; return true; @@ -2165,21 +2159,21 @@ std::optional CConfigManager::handleWorkspaceRules(const std::strin auto rules = value.substr(FIRST_DELIM + 1); SWorkspaceRule wsRule; wsRule.workspaceString = first_ident; - if (id == WORKSPACE_INVALID) { - // it could be the monitor. If so, second value MUST be - // the workspace. - const auto WORKSPACE_DELIM = value.find_first_of(',', FIRST_DELIM + 1); - auto wsIdent = removeBeginEndSpacesTabs(value.substr(FIRST_DELIM + 1, (WORKSPACE_DELIM - FIRST_DELIM - 1))); - id = getWorkspaceIDFromString(wsIdent, name); - if (id == WORKSPACE_INVALID) { - Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent); - return "Invalid workspace identifier found: " + wsIdent; - } - wsRule.monitor = first_ident; - wsRule.workspaceString = wsIdent; - wsRule.isDefault = true; // backwards compat - rules = value.substr(WORKSPACE_DELIM + 1); - } + // if (id == WORKSPACE_INVALID) { + // // it could be the monitor. If so, second value MUST be + // // the workspace. + // const auto WORKSPACE_DELIM = value.find_first_of(',', FIRST_DELIM + 1); + // auto wsIdent = removeBeginEndSpacesTabs(value.substr(FIRST_DELIM + 1, (WORKSPACE_DELIM - FIRST_DELIM - 1))); + // id = getWorkspaceIDFromString(wsIdent, name); + // if (id == WORKSPACE_INVALID) { + // Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent); + // return "Invalid workspace identifier found: " + wsIdent; + // } + // wsRule.monitor = first_ident; + // wsRule.workspaceString = wsIdent; + // wsRule.isDefault = true; // backwards compat + // rules = value.substr(WORKSPACE_DELIM + 1); + // } const static std::string ruleOnCreatedEmtpy = "on-created-empty:"; const static int ruleOnCreatedEmtpyLen = ruleOnCreatedEmtpy.length(); diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 23f76309..42d59dbb 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -182,3 +182,205 @@ std::string CWorkspace::getConfigName() { return "name:" + m_szName; } + +bool CWorkspace::matchesStaticSelector(const std::string& selector_) { + auto selector = removeBeginEndSpacesTabs(selector_); + + if (selector.empty()) + return true; + + if (isNumber(selector)) { + + std::string wsname = ""; + int wsid = getWorkspaceIDFromString(selector, wsname); + + if (wsid == WORKSPACE_INVALID) + return false; + + return wsid == m_iID; + + } else if (selector.starts_with("name:")) { + return m_szName == selector.substr(5); + } else { + // parse selector + + for (size_t i = 0; i < selector.length(); ++i) { + const char& cur = selector[i]; + if (std::isspace(cur)) + continue; + + // Allowed selectors: + // r - range: r[1-5] + // s - special: s[true] + // n - named: n[true] or n[s:string] or n[e:string] + // m - monitor: m[monitor_selector] + // w - windowCount: w[0-4] or w[1], optional flag t or f for tiled or floating, e.g. w[t0-1] + + const auto NEXTSPACE = selector.find_first_of(' ', i); + std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i); + i = NEXTSPACE; + + if (cur == 'r') { + int from = 0, to = 0; + if (!prop.starts_with("r[") || !prop.ends_with("]")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + prop = prop.substr(2, prop.length() - 3); + + if (!prop.contains("-")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + const auto DASHPOS = prop.find("-"); + const auto LHS = prop.substr(0, DASHPOS), RHS = prop.substr(DASHPOS + 1); + + if (!isNumber(LHS) || !isNumber(RHS)) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + try { + from = std::stoll(LHS); + to = std::stoll(RHS); + } catch (std::exception& e) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + if (to < from || to < 1 || from < 1) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + if (std::clamp(m_iID, from, to) != m_iID) + return false; + continue; + } + + if (cur == 's') { + if (!prop.starts_with("s[") || !prop.ends_with("]")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + prop = prop.substr(2, prop.length() - 3); + + const auto SHOULDBESPECIAL = configStringToInt(prop); + + if ((bool)SHOULDBESPECIAL != m_bIsSpecialWorkspace) + return false; + continue; + } + + if (cur == 'm') { + if (!prop.starts_with("m[") || !prop.ends_with("]")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + prop = prop.substr(2, prop.length() - 3); + + const auto PMONITOR = g_pCompositor->getMonitorFromString(prop); + + if (!(PMONITOR ? PMONITOR->ID == m_iMonitorID : false)) + return false; + continue; + } + + if (cur == 'n') { + if (!prop.starts_with("n[") || !prop.ends_with("]")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + prop = prop.substr(2, prop.length() - 3); + + if (prop.starts_with("s:")) + return m_szName.starts_with(prop.substr(2)); + if (prop.starts_with("e:")) + return m_szName.ends_with(prop.substr(2)); + + const auto WANTSNAMED = configStringToInt(prop); + + if (WANTSNAMED != (m_iID <= -1337)) + return false; + continue; + } + + if (cur == 'w') { + int from = 0, to = 0; + if (!prop.starts_with("w[") || !prop.ends_with("]")) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + prop = prop.substr(2, prop.length() - 3); + + int wantsOnlyTiled = -1; + + if (prop.starts_with("t")) { + wantsOnlyTiled = 1; + prop = prop.substr(1); + } else if (prop.starts_with("f")) { + wantsOnlyTiled = 0; + prop = prop.substr(1); + } + + if (!prop.contains("-")) { + // try single + + if (!isNumber(prop)) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + try { + from = std::stoll(prop); + } catch (std::exception& e) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + return g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)) == from; + } + + const auto DASHPOS = prop.find("-"); + const auto LHS = prop.substr(0, DASHPOS), RHS = prop.substr(DASHPOS + 1); + + if (!isNumber(LHS) || !isNumber(RHS)) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + try { + from = std::stoll(LHS); + to = std::stoll(RHS); + } catch (std::exception& e) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + if (to < from || to < 1 || from < 1) { + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + const auto WINDOWSONWORKSPACE = g_pCompositor->getWindowsOnWorkspace(m_iID, wantsOnlyTiled == -1 ? std::nullopt : std::optional((bool)wantsOnlyTiled)); + if (std::clamp(WINDOWSONWORKSPACE, from, to) != WINDOWSONWORKSPACE) + return false; + continue; + } + + Debug::log(LOG, "Invalid selector {}", selector); + return false; + } + + return true; + } + + UNREACHABLE(); + return false; +} \ No newline at end of file diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index 15b7c0e2..f1bdb333 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -64,4 +64,6 @@ class CWorkspace { void rememberPrevWorkspace(const CWorkspace* prevWorkspace); std::string getConfigName(); + + bool matchesStaticSelector(const std::string& selector); }; diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 4b406cb6..8a1d022b 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -871,10 +871,12 @@ void toggleActiveFloatingCore(std::string args, std::optional floatState) curr->updateSpecialRenderData(); curr = curr->m_sGroupData.pNextWindow; } + + g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); } else { PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating; - PWINDOW->updateDynamicRules(); + g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW); } From 07ab3b8cd654561ba346e40e16d44e918afa0ba0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 19 Mar 2024 22:12:26 +0000 Subject: [PATCH 0150/2897] hyprpm: log shell in build without fails --- hyprpm/src/core/PluginManager.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index 725e6a93..c5926c3e 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -221,12 +221,12 @@ bool CPluginManager::addNewPluginRepo(const std::string& url, const std::string& out += " -> " + cmd + "\n" + execAndGet(cmd) + "\n"; } + if (m_bVerbose) + std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; + if (!std::filesystem::exists("/tmp/hyprpm/new/" + p.output)) { progress.printMessageAbove(std::string{Colors::RED} + "✖" + Colors::RESET + " Plugin " + p.name + " failed to build.\n"); - if (m_bVerbose) - std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; - p.failed = true; continue; @@ -582,11 +582,12 @@ bool CPluginManager::updatePlugins(bool forceUpdateAll) { out += " -> " + cmd + "\n" + execAndGet(cmd) + "\n"; } + if (m_bVerbose) + std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; + if (!std::filesystem::exists("/tmp/hyprpm/update/" + p.output)) { std::cerr << "\n" << Colors::RED << "✖" << Colors::RESET << " Plugin " << p.name << " failed to build.\n"; failed = true; - if (m_bVerbose) - std::cout << Colors::BLUE << "[v] " << Colors::RESET << "shell returned: " << out << "\n"; break; } From f6038837bc12a5f22808ceea0641dd9fe17d8094 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 20 Mar 2024 01:30:19 +0000 Subject: [PATCH 0151/2897] constraint: do not disable constraints in destroy fixes #5170 --- src/desktop/Constraint.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/desktop/Constraint.cpp b/src/desktop/Constraint.cpp index 2109ef1c..e7858321 100644 --- a/src/desktop/Constraint.cpp +++ b/src/desktop/Constraint.cpp @@ -33,8 +33,11 @@ void CConstraint::initSignals() { } void CConstraint::onDestroy() { - if (active()) - deactivate(); + hyprListener_setConstraintRegion.removeCallback(); + hyprListener_destroyConstraint.removeCallback(); + + if (active() && isLocked()) + g_pCompositor->warpCursorTo(logicPositionHint(), true); // this is us m_pOwner->m_pConstraint.reset(); From 8593c45be3cfe8055d13315051d88588f848ad39 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 20 Mar 2024 01:44:51 +0000 Subject: [PATCH 0152/2897] refactor: move window.hpp to desktop/ --- src/Compositor.hpp | 2 +- src/config/ConfigManager.hpp | 3 ++- src/{ => desktop}/Window.cpp | 10 +++++----- src/{ => desktop}/Window.hpp | 20 +++++++++---------- src/helpers/WLClasses.hpp | 2 +- src/layout/IHyprLayout.cpp | 1 + src/layout/IHyprLayout.hpp | 3 ++- src/managers/AnimationManager.cpp | 1 + src/managers/AnimationManager.hpp | 3 ++- src/managers/input/InputManager.cpp | 1 + src/managers/input/InputManager.hpp | 2 +- src/render/Renderer.cpp | 1 + src/render/Renderer.hpp | 2 +- .../decorations/IHyprWindowDecoration.cpp | 2 +- 14 files changed, 30 insertions(+), 23 deletions(-) rename src/{ => desktop}/Window.cpp (99%) rename src/{ => desktop}/Window.hpp (97%) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 56b83774..e226fdd3 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -22,7 +22,7 @@ #include "debug/HyprNotificationOverlay.hpp" #include "helpers/Monitor.hpp" #include "desktop/Workspace.hpp" -#include "Window.hpp" +#include "desktop/Window.hpp" #include "render/Renderer.hpp" #include "render/OpenGL.hpp" #include "hyprerror/HyprError.hpp" diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 2effb644..a00aaec9 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -13,7 +13,6 @@ #include #include #include -#include "../Window.hpp" #include "../helpers/WLClasses.hpp" #include "../helpers/Monitor.hpp" #include "../helpers/VarList.hpp" @@ -28,6 +27,8 @@ #define HANDLE void* +class CWindow; + struct SWorkspaceRule { std::string monitor = ""; std::string workspaceString = ""; diff --git a/src/Window.cpp b/src/desktop/Window.cpp similarity index 99% rename from src/Window.cpp rename to src/desktop/Window.cpp index 8130f017..567c3243 100644 --- a/src/Window.cpp +++ b/src/desktop/Window.cpp @@ -1,9 +1,9 @@ #include "Window.hpp" -#include "Compositor.hpp" -#include "render/decorations/CHyprDropShadowDecoration.hpp" -#include "render/decorations/CHyprGroupBarDecoration.hpp" -#include "render/decorations/CHyprBorderDecoration.hpp" -#include "config/ConfigValue.hpp" +#include "../Compositor.hpp" +#include "../render/decorations/CHyprDropShadowDecoration.hpp" +#include "../render/decorations/CHyprGroupBarDecoration.hpp" +#include "../render/decorations/CHyprBorderDecoration.hpp" +#include "../config/ConfigValue.hpp" CWindow::CWindow() { m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); diff --git a/src/Window.hpp b/src/desktop/Window.hpp similarity index 97% rename from src/Window.hpp rename to src/desktop/Window.hpp index d98bc921..3ec8a54c 100644 --- a/src/Window.hpp +++ b/src/desktop/Window.hpp @@ -1,16 +1,16 @@ #pragma once -#include "defines.hpp" -#include "desktop/Subsurface.hpp" -#include "helpers/AnimatedVariable.hpp" -#include "render/decorations/IHyprWindowDecoration.hpp" +#include "../defines.hpp" +#include "Subsurface.hpp" +#include "../helpers/AnimatedVariable.hpp" +#include "../render/decorations/IHyprWindowDecoration.hpp" #include -#include "config/ConfigDataValues.hpp" -#include "helpers/Vector2D.hpp" -#include "desktop/WLSurface.hpp" -#include "desktop/Popup.hpp" -#include "macros.hpp" -#include "managers/XWaylandManager.hpp" +#include "../config/ConfigDataValues.hpp" +#include "../helpers/Vector2D.hpp" +#include "WLSurface.hpp" +#include "Popup.hpp" +#include "../macros.hpp" +#include "../managers/XWaylandManager.hpp" enum eIdleInhibitMode { IDLEINHIBIT_NONE = 0, diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 57f216b8..806bf778 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -3,7 +3,7 @@ #include "../events/Events.hpp" #include "../defines.hpp" #include "wlr-layer-shell-unstable-v1-protocol.h" -#include "../Window.hpp" +#include "../desktop/Window.hpp" #include "../desktop/Subsurface.hpp" #include "../desktop/Popup.hpp" #include "AnimatedVariable.hpp" diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 02f39d94..6a32144e 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -3,6 +3,7 @@ #include "../Compositor.hpp" #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../config/ConfigValue.hpp" +#include "../desktop/Window.hpp" void IHyprLayout::onWindowCreated(CWindow* pWindow, eDirection direction) { if (pWindow->m_bIsFloating) { diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index d3f8dfa6..b5926a07 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -1,9 +1,10 @@ #pragma once #include "../defines.hpp" -#include "../Window.hpp" #include +class CWindow; + struct SWindowRenderLayoutHints { bool isBorderGradient = false; CGradientValueData* borderGradient; diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index f9dfa6fa..7d2a86e7 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -3,6 +3,7 @@ #include "HookSystemManager.hpp" #include "macros.hpp" #include "../config/ConfigValue.hpp" +#include "../desktop/Window.hpp" int wlTick(void* data) { if (g_pAnimationManager) diff --git a/src/managers/AnimationManager.hpp b/src/managers/AnimationManager.hpp index ae82a60b..483c9813 100644 --- a/src/managers/AnimationManager.hpp +++ b/src/managers/AnimationManager.hpp @@ -5,9 +5,10 @@ #include #include "../helpers/AnimatedVariable.hpp" #include "../helpers/BezierCurve.hpp" -#include "../Window.hpp" #include "../helpers/Timer.hpp" +class CWindow; + class CAnimationManager { public: CAnimationManager(); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 9072f27a..04981e4e 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -3,6 +3,7 @@ #include "wlr/types/wlr_switch.h" #include #include "../../config/ConfigValue.hpp" +#include "../../desktop/Window.hpp" CInputManager::~CInputManager() { m_vConstraints.clear(); diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index d63de6ef..128badfc 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -3,11 +3,11 @@ #include "../../defines.hpp" #include #include "../../helpers/WLClasses.hpp" -#include "../../Window.hpp" #include "../../helpers/Timer.hpp" #include "InputMethodRelay.hpp" class CConstraint; +class CWindow; enum eClickBehaviorMode { CLICKMODE_DEFAULT = 0, diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e2bcbf1e..88035112 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -5,6 +5,7 @@ #include #include "../config/ConfigValue.hpp" #include "../managers/CursorManager.hpp" +#include "../desktop/Window.hpp" extern "C" { #include diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index e480b26d..fd41a566 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -3,7 +3,6 @@ #include "../defines.hpp" #include #include "../helpers/Monitor.hpp" -#include "../Window.hpp" #include "OpenGL.hpp" #include "Renderbuffer.hpp" #include "../helpers/Timer.hpp" @@ -11,6 +10,7 @@ struct SMonitorRule; class CWorkspace; +class CWindow; // TODO: add fuller damage tracking for updating only parts of a window enum DAMAGETRACKINGMODES { diff --git a/src/render/decorations/IHyprWindowDecoration.cpp b/src/render/decorations/IHyprWindowDecoration.cpp index 973f2700..a012848a 100644 --- a/src/render/decorations/IHyprWindowDecoration.cpp +++ b/src/render/decorations/IHyprWindowDecoration.cpp @@ -1,6 +1,6 @@ #include "IHyprWindowDecoration.hpp" -#include "../../Window.hpp" +class CWindow; IHyprWindowDecoration::IHyprWindowDecoration(CWindow* pWindow) { m_pWindow = pWindow; From 95ac8a34b1809375030b4ec2780a2b7a35ae8162 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:33:39 -0700 Subject: [PATCH 0153/2897] workspace: fix integer overflow in selector parser (#5177) --- src/desktop/Workspace.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 42d59dbb..5a5e2c06 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -218,7 +218,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { const auto NEXTSPACE = selector.find_first_of(' ', i); std::string prop = selector.substr(i, NEXTSPACE == std::string::npos ? std::string::npos : NEXTSPACE - i); - i = NEXTSPACE; + i = std::min(NEXTSPACE, std::string::npos - 1); if (cur == 'r') { int from = 0, to = 0; @@ -383,4 +383,4 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { UNREACHABLE(); return false; -} \ No newline at end of file +} From 9ddf1b105e1b63a77b851af5e541a9412b0e0928 Mon Sep 17 00:00:00 2001 From: Khalid Date: Wed, 20 Mar 2024 07:00:43 +0300 Subject: [PATCH 0154/2897] tablet: Add left_handed option for tablets (#5178) * Add left_handed option for tablets * Update left_handed tablet option's fallback string --- src/config/ConfigManager.cpp | 1 + src/managers/input/InputManager.cpp | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index ee7b90bf..d671ffb0 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -476,6 +476,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("input:tablet:region_position", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("input:tablet:region_size", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("input:tablet:relative_input", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:tablet:left_handed", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:pass_mouse_when_bound", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:scroll_event_delay", Hyprlang::INT{300}); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 04981e4e..7d820c8f 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1418,6 +1418,11 @@ void CInputManager::setTabletConfigs() { Debug::log(LOG, "Setting calibration matrix for device {}", t.name); libinput_device_config_calibration_set_matrix(LIBINPUTDEV, MATRICES[ROTATION]); + if (g_pConfigManager->getDeviceInt(t.name, "left_handed", "input:tablet:left_handed") == 0) + libinput_device_config_left_handed_set(LIBINPUTDEV, 0); + else + libinput_device_config_left_handed_set(LIBINPUTDEV, 1); + const auto OUTPUT = g_pConfigManager->getDeviceString(t.name, "output", "input:tablet:output"); const auto PMONITOR = g_pCompositor->getMonitorFromString(OUTPUT); if (!OUTPUT.empty() && OUTPUT != STRVAL_EMPTY && PMONITOR) { From 361357095c26c70876e239a37458cb413e537af5 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 20 Mar 2024 18:05:57 +0000 Subject: [PATCH 0155/2897] workspace: fix selectors with special: fixes #5187 --- src/desktop/Workspace.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 5a5e2c06..d5f72384 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -201,6 +201,8 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { } else if (selector.starts_with("name:")) { return m_szName == selector.substr(5); + } else if (selector.starts_with("special:")) { + return m_szName == selector; } else { // parse selector From d904f51716cf939772bf2bc581bcfb30fb7ed12b Mon Sep 17 00:00:00 2001 From: Nathan Hadley <116459177+linfindel@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:11:40 +0000 Subject: [PATCH 0156/2897] README: Fix Preview B image (#5188) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 70cce21d..1354fc6e 100644 --- a/README.md +++ b/README.md @@ -130,7 +130,7 @@ easy IPC, much more QoL stuff than other wlr-based compositors and more... [Stars Preview]: https://starchart.cc/vaxerski/Hyprland.svg [Preview A]: https://i.ibb.co/C1yTb0r/falf.png -[Preview B]: https://cdn.discordapp.com/attachments/1091569872535814185/1107675866101723277/screenshot-summer.png +[Preview B]: https://linfindel.github.io/cdn/hyprland-preview-b.png [Preview C]: https://i.ibb.co/B3GJg28/20221126-20h53m26s-grim.png From bfc95e992d460cbefe2c69de04da52e6089f6258 Mon Sep 17 00:00:00 2001 From: Horror Proton <107091537+horror-proton@users.noreply.github.com> Date: Thu, 21 Mar 2024 02:13:31 +0800 Subject: [PATCH 0157/2897] swipe: fix nullptr in `onSwipeUpdate` (#5191) --- src/managers/input/Swipe.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 68f7aa25..5c3b7c28 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -195,11 +195,11 @@ void CInputManager::endWorkspaceSwipe() { } void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { + if (!m_sActiveSwipe.pWorkspaceBegin) + return; static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); const bool VERTANIMS = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); - if (!m_sActiveSwipe.pWorkspaceBegin) - return; const double delta = m_sActiveSwipe.delta + (VERTANIMS ? (*PSWIPEINVR ? -e->dy : e->dy) : (*PSWIPEINVR ? -e->dx : e->dx)); updateWorkspaceSwipe(delta); From 214ec82ba7dcbb33b45963d13b84f9bd6c913614 Mon Sep 17 00:00:00 2001 From: Brett Alcox Date: Wed, 20 Mar 2024 20:54:10 -0500 Subject: [PATCH 0158/2897] build: fix builds without pch (#5198) --- src/layout/IHyprLayout.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index b5926a07..e168556e 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -4,6 +4,7 @@ #include class CWindow; +class CGradientValueData; struct SWindowRenderLayoutHints { bool isBorderGradient = false; From 4c796683c05a0eaccc14aae8875f06972f9f3c5e Mon Sep 17 00:00:00 2001 From: zakk4223 Date: Wed, 20 Mar 2024 21:55:13 -0400 Subject: [PATCH 0159/2897] config: Config error limit/hyprctl (#5165) * Add error_limit to limit the number of config error messages shown in notification * Add configerrors hyprctl command * Formatting * Formatting for not my code * Use CVarList, add escapeJSONStrings * Add indication there are more undisplayed errors * Restore suppress_errors; move getErrors() to ConfigManager * Formatting, wtf * Format --- src/config/ConfigManager.cpp | 11 +++++++++++ src/config/ConfigManager.hpp | 2 ++ src/debug/HyprCtl.cpp | 25 +++++++++++++++++++++++++ src/hyprerror/HyprError.cpp | 19 ++++++++++++++++--- 4 files changed, 54 insertions(+), 3 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d671ffb0..7925da64 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -372,6 +372,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("debug:damage_tracking", {(Hyprlang::INT)DAMAGE_TRACKING_FULL}); m_pConfig->addConfigValue("debug:manual_crash", Hyprlang::INT{0}); m_pConfig->addConfigValue("debug:suppress_errors", Hyprlang::INT{0}); + m_pConfig->addConfigValue("debug:error_limit", Hyprlang::INT{5}); m_pConfig->addConfigValue("debug:watchdog_timeout", Hyprlang::INT{5}); m_pConfig->addConfigValue("debug:disable_scale_checks", Hyprlang::INT{0}); @@ -609,6 +610,10 @@ std::string CConfigManager::getMainConfigPath() { return getConfigDir() + "/hypr/" + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); } +std::string CConfigManager::getErrors() { + return m_szConfigErrors; +} + void CConfigManager::reload() { EMIT_HOOK_EVENT("preConfigReload", nullptr); setDefaultAnimationVars(); @@ -740,6 +745,12 @@ void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { g_pHyprOpenGL->m_bReloadScreenShader = true; // parseError will be displayed next frame + + if (result.error) + m_szConfigErrors = result.getError(); + else + m_szConfigErrors = ""; + if (result.error && !std::any_cast(m_pConfig->getConfigValue("debug:suppress_errors"))) g_pHyprError->queueCreate(result.getError(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); else if (std::any_cast(m_pConfig->getConfigValue("autogenerated")) == 1) diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index a00aaec9..9fd1e097 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -142,6 +142,7 @@ class CConfigManager { void addExecRule(const SExecRequestedRule&); void handlePluginLoads(); + std::string getErrors(); // keywords std::optional handleRawExec(const std::string&, const std::string&); @@ -193,6 +194,7 @@ class CConfigManager { std::deque firstExecRequests; std::vector> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins + std::string m_szConfigErrors = ""; // internal methods void setAnimForChildren(SAnimationPropertyConfig* const); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index f13843a3..211b532e 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -17,6 +17,7 @@ #include "../config/ConfigValue.hpp" #include "../managers/CursorManager.hpp" +#include "../hyprerror/HyprError.hpp" static void trimTrailingComma(std::string& str) { if (!str.empty() && str.back() == ',') @@ -497,6 +498,29 @@ std::string layoutsRequest(eHyprCtlOutputFormat format, std::string request) { return result; } +std::string configErrorsRequest(eHyprCtlOutputFormat format, std::string request) { + std::string result = ""; + std::string currErrors = g_pConfigManager->getErrors(); + CVarList errLines(currErrors, 0, '\n'); + if (format == eHyprCtlOutputFormat::FORMAT_JSON) { + result += "["; + for (auto line : errLines) { + result += std::format( + R"#( + "{}",)#", + + escapeJSONStrings(line)); + } + trimTrailingComma(result); + result += "\n]\n"; + } else { + for (auto line : errLines) { + result += std::format("{}\n", line); + } + } + return result; +} + std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) { std::string result = ""; @@ -1531,6 +1555,7 @@ CHyprCtl::CHyprCtl() { registerCommand(SHyprCtlCommand{"animations", true, animationsRequest}); registerCommand(SHyprCtlCommand{"rollinglog", true, rollinglogRequest}); registerCommand(SHyprCtlCommand{"layouts", true, layoutsRequest}); + registerCommand(SHyprCtlCommand{"configerrors", true, configErrorsRequest}); registerCommand(SHyprCtlCommand{"monitors", false, monitorsRequest}); registerCommand(SHyprCtlCommand{"reload", false, reloadRequest}); diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 97a18e8c..a7636b1c 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -1,5 +1,6 @@ #include "HyprError.hpp" #include "../Compositor.hpp" +#include "../config/ConfigValue.hpp" CHyprError::CHyprError() { m_fFadeOpacity.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_NONE); @@ -58,6 +59,10 @@ void CHyprError::createQueued() { cairo_restore(CAIRO); const auto LINECOUNT = 1 + std::count(m_szQueued.begin(), m_szQueued.end(), '\n'); + static auto LINELIMIT = CConfigValue("debug:error_limit"); + + const auto VISLINECOUNT = std::min(LINECOUNT, *LINELIMIT); + const auto EXTRALINES = (VISLINECOUNT < LINECOUNT) ? 1 : 0; const double DEGREES = M_PI / 180.0; @@ -66,7 +71,7 @@ void CHyprError::createQueued() { const double X = PAD; const double Y = PAD; const double WIDTH = PMONITOR->vecPixelSize.x - PAD * 2; - const double HEIGHT = (FONTSIZE + 2 * (FONTSIZE / 10.0)) * LINECOUNT + 3; + const double HEIGHT = (FONTSIZE + 2 * (FONTSIZE / 10.0)) * (VISLINECOUNT + EXTRALINES) + 3; const double RADIUS = PAD > HEIGHT / 2 ? HEIGHT / 2 - 1 : PAD; m_bDamageBox = {0, 0, (int)PMONITOR->vecPixelSize.x, (int)HEIGHT + (int)PAD * 2}; @@ -91,8 +96,9 @@ void CHyprError::createQueued() { cairo_set_font_size(CAIRO, FONTSIZE); cairo_set_source_rgba(CAIRO, textColor.r, textColor.g, textColor.b, textColor.a); - float yoffset = FONTSIZE; - while (m_szQueued != "") { + float yoffset = FONTSIZE; + int renderedcnt = 0; + while (m_szQueued != "" && renderedcnt < VISLINECOUNT) { std::string current = m_szQueued.substr(0, m_szQueued.find('\n')); if (const auto NEWLPOS = m_szQueued.find('\n'); NEWLPOS != std::string::npos) m_szQueued = m_szQueued.substr(NEWLPOS + 1); @@ -101,7 +107,14 @@ void CHyprError::createQueued() { cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1); cairo_show_text(CAIRO, current.c_str()); yoffset += FONTSIZE + (FONTSIZE / 10.f); + renderedcnt++; } + if (VISLINECOUNT < LINECOUNT) { + std::string moreString = std::format("({} more...)", LINECOUNT - VISLINECOUNT); + cairo_move_to(CAIRO, PAD + 1 + RADIUS, yoffset + PAD + 1); + cairo_show_text(CAIRO, moreString.c_str()); + } + m_szQueued = ""; cairo_surface_flush(CAIROSURFACE); From ee00cb1dd87115f7c2b0fb41268e88050f28e7ed Mon Sep 17 00:00:00 2001 From: jill Date: Thu, 21 Mar 2024 17:46:23 +0300 Subject: [PATCH 0160/2897] opengl: report shader compilation errors from screen_shader (#5138) * opengl: report shader compilation errors from screen_shader * opengl: prefer .data() * opengl: move shader error logging to logError * opengl: quick glGetShaderiv -> glGetProgramiv fix * opengl: typo fix * opengl: format fixes * opengl: minor compile fixes * opengl: logError -> logShaderError --- src/render/OpenGL.cpp | 28 +++++++++++++++++++++++++--- src/render/OpenGL.hpp | 1 + 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index d34a90b0..df03e8e9 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -59,6 +59,23 @@ CHyprOpenGLImpl::CHyprOpenGLImpl() { m_tGlobalTimer.reset(); } +void CHyprOpenGLImpl::logShaderError(const GLuint& shader, bool program) { + GLint maxLength = 0; + if (program) + glGetProgramiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + else + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &maxLength); + + std::vector errorLog(maxLength); + if (program) + glGetProgramInfoLog(shader, maxLength, &maxLength, errorLog.data()); + else + glGetShaderInfoLog(shader, maxLength, &maxLength, errorLog.data()); + std::string errorStr(errorLog.begin(), errorLog.end()); + + g_pConfigManager->addParseError((program ? "Screen shader parser: Error linking program:" : "Screen shader parser: Error compiling shader: ") + errorStr); +} + GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string& frag, bool dynamic) { auto vertCompiled = compileShader(GL_VERTEX_SHADER, vert, dynamic); if (dynamic) { @@ -89,8 +106,10 @@ GLuint CHyprOpenGLImpl::createProgram(const std::string& vert, const std::string GLint ok; glGetProgramiv(prog, GL_LINK_STATUS, &ok); if (dynamic) { - if (ok == GL_FALSE) + if (ok == GL_FALSE) { + logShaderError(prog, true); return 0; + } } else { RASSERT(ok != GL_FALSE, "createProgram() failed! GL_LINK_STATUS not OK!"); } @@ -108,9 +127,12 @@ GLuint CHyprOpenGLImpl::compileShader(const GLuint& type, std::string src, bool GLint ok; glGetShaderiv(shader, GL_COMPILE_STATUS, &ok); + if (dynamic) { - if (ok == GL_FALSE) + if (ok == GL_FALSE) { + logShaderError(shader, false); return 0; + } } else { RASSERT(ok != GL_FALSE, "compileShader() failed! GL_COMPILE_STATUS not OK!"); } @@ -550,7 +572,7 @@ void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { m_sFinalScreenShader.program = createProgram(fragmentShader.starts_with("#version 320 es") ? TEXVERTSRC320 : TEXVERTSRC, fragmentShader, true); if (!m_sFinalScreenShader.program) { - g_pConfigManager->addParseError("Screen shader parser: Screen shader parse failed"); + // Error will have been sent by now by the underlying cause return; } diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index f6dff805..b18e9108 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -219,6 +219,7 @@ class CHyprOpenGLImpl { CShader m_sFinalScreenShader; CTimer m_tGlobalTimer; + void logShaderError(const GLuint&, bool program = false); GLuint createProgram(const std::string&, const std::string&, bool dynamic = false); GLuint compileShader(const GLuint&, std::string, bool dynamic = false); void createBGTextureForMonitor(CMonitor*); From f1d06b773f2030b8ed62e3e5e8d753001ce064d2 Mon Sep 17 00:00:00 2001 From: Praneeth Jain Date: Thu, 21 Mar 2024 20:20:19 +0530 Subject: [PATCH 0161/2897] hyprpm: add missing newline (#5207) --- hyprpm/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hyprpm/src/main.cpp b/hyprpm/src/main.cpp index e40d336d..38b32c83 100644 --- a/hyprpm/src/main.cpp +++ b/hyprpm/src/main.cpp @@ -56,7 +56,7 @@ int main(int argc, char** argv, char** envp) { force = true; std::cout << Colors::RED << "!" << Colors::RESET << " Using --force, I hope you know what you are doing.\n"; } else { - std::cerr << "Unrecognized option " << ARGS[i]; + std::cerr << "Unrecognized option " << ARGS[i] << "\n"; return 1; } } else { From 997ee82bdf3c5783dffb3b5a34bff60362422780 Mon Sep 17 00:00:00 2001 From: Andrey Donets <142721811+Ligthiago@users.noreply.github.com> Date: Thu, 21 Mar 2024 18:57:06 +0400 Subject: [PATCH 0162/2897] hyprctl: add missing commands to usage (#5211) --- hyprctl/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index 4d6066b5..b8072de9 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -30,6 +30,7 @@ commands: activeworkspace binds clients + configerrors cursorpos decorations devices @@ -45,8 +46,10 @@ commands: layouts monitors notify + output plugin reload + rollinglog setcursor seterror setprop From a94b902bef5eef3a4891726d51415c5d2e3391e3 Mon Sep 17 00:00:00 2001 From: Philipp Schilk Date: Thu, 21 Mar 2024 16:18:24 +0100 Subject: [PATCH 0163/2897] windowrules: Fix resizeparams parsing. (#5206) Parsing of resizeparams/relative vec2 did not correctly handle multiple spaces between x and y arguments, causing the following to fail to parse: bind = $mainMod CTRL, h, resizeactive, 10 0 This is unexpected, because most other config values are whitespace insensitive. --- src/Compositor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3ff67f20..f8138825 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2542,7 +2542,7 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con bool isExact = false; std::string x = args.substr(0, args.find_first_of(' ')); - std::string y = args.substr(args.find_first_of(' ') + 1); + std::string y = args.substr(args.find_last_of(' ') + 1); if (x == "exact") { x = y.substr(0, y.find_first_of(' ')); From 9bad62b85f179ad2c95c6e7f734768ef060a604b Mon Sep 17 00:00:00 2001 From: drendog <53359960+drendog@users.noreply.github.com> Date: Fri, 22 Mar 2024 02:28:50 +0100 Subject: [PATCH 0164/2897] layershell: release all mouse buttons before focus on new ls (#5219) --- src/events/Layers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index 4e61baa0..f4b52445 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -148,6 +148,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { (!g_pCompositor->m_sSeat.mouse || !g_pInputManager->isConstrained()); if (GRABSFOCUS) { + g_pInputManager->releaseAllMouseButtons(); g_pCompositor->focusSurface(layersurface->layerSurface->surface); const auto LOCAL = From c7c0e795d26b34391f0cb95fd900fc642316827f Mon Sep 17 00:00:00 2001 From: Holger Schurig Date: Fri, 22 Mar 2024 18:34:51 +0100 Subject: [PATCH 0165/2897] CGradientValueData: fix toString() method (#5220) --- src/config/ConfigDataValues.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config/ConfigDataValues.hpp b/src/config/ConfigDataValues.hpp index 39c60a5a..c162bb40 100644 --- a/src/config/ConfigDataValues.hpp +++ b/src/config/ConfigDataValues.hpp @@ -61,6 +61,7 @@ class CGradientValueData : public ICustomConfigValueData { } result += std::format("{}deg", (int)(m_fAngle * 180.0 / M_PI)); + return result; } }; From 397e08c16a7b7e414e8ef466e22fe5d4a581bafc Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Fri, 22 Mar 2024 17:41:20 +0000 Subject: [PATCH 0166/2897] input: focus window on mouse down on groupbar (#5224) modified: src/render/decorations/CHyprGroupBarDecoration.cpp --- src/render/decorations/CHyprGroupBarDecoration.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index defff9ba..a03d97f9 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -425,6 +425,7 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point const float BARRELATIVEX = pos.x - assignedBoxGlobal().x; const int WINDOWINDEX = (BARRELATIVEX) / (m_fBarWidth + BAR_HORIZONTAL_PADDING); + static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); // close window on middle click if (e->button == 274) { @@ -453,6 +454,9 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point if (pWindow != m_pWindow) pWindow->setGroupCurrent(pWindow); + if (!g_pCompositor->isWindowActive(pWindow) && *PFOLLOWMOUSE != 3) + g_pCompositor->focusWindow(pWindow); + if (pWindow->m_bIsFloating) g_pCompositor->changeWindowZOrder(pWindow, 1); From 461757e2fb39e166db83858d877fcbd730ece4aa Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 18:34:12 +0000 Subject: [PATCH 0167/2897] scripts: fix asan patch --- CMakeLists.txt | 1 + scripts/hyprlandStaticAsan.diff | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 71766a8c..e039ceba 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,6 +121,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) message(STATUS "Enabling ASan") target_link_libraries(Hyprland asan) + target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/libwayland-server.a) target_compile_options(Hyprland PUBLIC -fsanitize=address) endif() diff --git a/scripts/hyprlandStaticAsan.diff b/scripts/hyprlandStaticAsan.diff index 5499f793..72a24914 100644 --- a/scripts/hyprlandStaticAsan.diff +++ b/scripts/hyprlandStaticAsan.diff @@ -1,13 +1,13 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 857e21de..122d6a78 100755 +index 71766a8c..bd8cdc0e 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -101,7 +101,7 @@ message(STATUS "Checking deps...") find_package(Threads REQUIRED) find_package(PkgConfig REQUIRED) find_package(OpenGL REQUIRED) --pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2) # we do not check for wlroots, as we provide it ourselves -+pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 libffi) # we do not check for wlroots, as we provide it ourselves +-pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 hyprcursor) # we do not check for wlroots, as we provide it ourselves ++pkg_check_modules(deps REQUIRED IMPORTED_TARGET wayland-server wayland-client wayland-cursor wayland-protocols cairo libdrm xkbcommon libinput pango pangocairo pixman-1 hyprlang>=0.3.2 hyprcursor libffi) # we do not check for wlroots, as we provide it ourselves file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") @@ -18,4 +18,4 @@ index 857e21de..122d6a78 100755 + target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/libwayland-server.a) target_compile_options(Hyprland PUBLIC -fsanitize=address) endif() - \ No newline at end of file + From d2b42e29c66fc0f6411ce64fa7e14e1b5fcc1c3f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 18:45:24 +0000 Subject: [PATCH 0168/2897] IME: fix crashes with destroyed text-inputs ref #5189 --- src/helpers/WLClasses.cpp | 36 +++++++++++++++++++++++++ src/helpers/WLClasses.hpp | 4 +++ src/managers/input/InputMethodRelay.cpp | 21 ++++++++------- src/managers/input/InputMethodRelay.hpp | 1 + src/protocols/TextInputV1.hpp | 2 -- 5 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index d46f7e40..1c14567d 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -244,3 +244,39 @@ void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { xkb_keymap_unref(NEWKEYMAP); xkb_context_unref(PCONTEXT); } + +void STextInput::setFocusedSurface(wlr_surface* pSurface) { + focusedSurface = pSurface; + + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + + if (!pSurface) + return; + + hyprListener_surfaceUnmapped.initCallback( + &pSurface->events.unmap, + [this](void* owner, void* data) { + if (!focusedSurface) + return; + + focusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); + }, + this, "STextInput"); + + hyprListener_surfaceDestroyed.initCallback( + &pSurface->events.destroy, + [this](void* owner, void* data) { + if (!focusedSurface) + return; + + focusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); + }, + this, "STextInput"); +} \ No newline at end of file diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 806bf778..210405f6 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -295,10 +295,14 @@ struct STextInput { STextInputV1* pV1Input = nullptr; wlr_surface* focusedSurface = nullptr; + void setFocusedSurface(wlr_surface* pSurface); + DYNLISTENER(textInputEnable); DYNLISTENER(textInputDisable); DYNLISTENER(textInputCommit); DYNLISTENER(textInputDestroy); + DYNLISTENER(surfaceUnmapped); + DYNLISTENER(surfaceDestroyed); }; struct SIMEKbGrab { diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index 44ba3e42..89454d5b 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -143,7 +143,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { } wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) { - return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->pV1Input->focusedSurface; + return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->focusedSurface; } void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { @@ -346,8 +346,8 @@ void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInput // v1 only, map surface to PTI if (PINPUT->pV1Input) { - wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data); - PINPUT->focusedSurface = pSurface; + wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data); + PINPUT->setFocusedSurface(pSurface); setSurfaceToPTI(pSurface, PINPUT); if (m_pFocusedSurface == pSurface) onTextInputEnter(pSurface); @@ -510,8 +510,8 @@ void CInputMethodRelay::onTextInputLeave(wlr_surface* pSurface) { wlr_text_input_v3_send_leave(ti->pWlrInput); else { zwp_text_input_v1_send_leave(ti->pV1Input->resourceImpl); - ti->pV1Input->focusedSurface = nullptr; - ti->pV1Input->active = false; + ti->setFocusedSurface(nullptr); + ti->pV1Input->active = false; } } @@ -527,23 +527,26 @@ void CInputMethodRelay::onTextInputEnter(wlr_surface* pSurface) { wlr_text_input_v3_send_enter(ti->pWlrInput, pSurface); else { zwp_text_input_v1_send_enter(ti->pV1Input->resourceImpl, pSurface->resource); - ti->pV1Input->focusedSurface = pSurface; - ti->pV1Input->active = true; + ti->setFocusedSurface(pSurface); + ti->pV1Input->active = true; } } void CInputMethodRelay::setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput) { if (pSurface) { m_mSurfaceToTextInput[pSurface] = pInput; - pInput->focusedSurface = pSurface; + pInput->setFocusedSurface(pSurface); } } void CInputMethodRelay::removeSurfaceToPTI(STextInput* pInput) { if (pInput->focusedSurface) { m_mSurfaceToTextInput.erase(pInput->focusedSurface); - pInput->focusedSurface = nullptr; + pInput->setFocusedSurface(nullptr); + return; } + + std::erase_if(m_mSurfaceToTextInput, [pInput](const auto& el) { return el.second == pInput; }); } STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface) { diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index 39465cab..6f99cae2 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -62,4 +62,5 @@ class CInputMethodRelay { friend class CHyprRenderer; friend class CInputManager; friend class CTextInputV1ProtocolManager; + friend struct STextInput; }; diff --git a/src/protocols/TextInputV1.hpp b/src/protocols/TextInputV1.hpp index b279763d..9362a52e 100644 --- a/src/protocols/TextInputV1.hpp +++ b/src/protocols/TextInputV1.hpp @@ -13,8 +13,6 @@ struct STextInputV1 { wl_resource* resourceImpl = nullptr; - wlr_surface* focusedSurface = nullptr; - STextInput* pTextInput = nullptr; wl_signal sEnable; From 568b352b235705d208df3190dfd878afd30913ca Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 18:52:07 +0000 Subject: [PATCH 0169/2897] cmakelists: remove oopsie --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e039ceba..71766a8c 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,7 +121,6 @@ if(CMAKE_BUILD_TYPE MATCHES Debug OR CMAKE_BUILD_TYPE MATCHES DEBUG) message(STATUS "Enabling ASan") target_link_libraries(Hyprland asan) - target_link_libraries(Hyprland ${CMAKE_SOURCE_DIR}/libwayland-server.a) target_compile_options(Hyprland PUBLIC -fsanitize=address) endif() From 8c88689faf691a4369528e6d3d52c024cd61125d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 18:58:28 +0000 Subject: [PATCH 0170/2897] IME: guard unfocused TIs in leave --- src/managers/input/InputMethodRelay.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index 89454d5b..bdc46445 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -506,6 +506,9 @@ void CInputMethodRelay::onTextInputLeave(wlr_surface* pSurface) { if (!ti) return; + if (ti->pWlrInput && !ti->pWlrInput->focused_surface) + return; + if (ti->pWlrInput) wlr_text_input_v3_send_leave(ti->pWlrInput); else { From 9f2ed02f35232f0362db45d5f580025f5724500a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 22 Mar 2024 23:08:52 +0000 Subject: [PATCH 0171/2897] IME/TI: Fixes and refactoring Fixes #5189 --- src/helpers/WLClasses.cpp | 36 --- src/helpers/WLClasses.hpp | 19 +- src/managers/input/InputMethodRelay.cpp | 396 ++++-------------------- src/managers/input/InputMethodRelay.hpp | 35 +-- src/managers/input/TextInput.cpp | 273 ++++++++++++++++ src/managers/input/TextInput.hpp | 51 +++ src/protocols/TextInputV1.cpp | 10 +- src/protocols/TextInputV1.hpp | 4 +- 8 files changed, 403 insertions(+), 421 deletions(-) create mode 100644 src/managers/input/TextInput.cpp create mode 100644 src/managers/input/TextInput.hpp diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 1c14567d..d46f7e40 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -244,39 +244,3 @@ void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { xkb_keymap_unref(NEWKEYMAP); xkb_context_unref(PCONTEXT); } - -void STextInput::setFocusedSurface(wlr_surface* pSurface) { - focusedSurface = pSurface; - - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - - if (!pSurface) - return; - - hyprListener_surfaceUnmapped.initCallback( - &pSurface->events.unmap, - [this](void* owner, void* data) { - if (!focusedSurface) - return; - - focusedSurface = nullptr; - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); - }, - this, "STextInput"); - - hyprListener_surfaceDestroyed.initCallback( - &pSurface->events.destroy, - [this](void* owner, void* data) { - if (!focusedSurface) - return; - - focusedSurface = nullptr; - hyprListener_surfaceUnmapped.removeCallback(); - hyprListener_surfaceDestroyed.removeCallback(); - g_pInputManager->m_sIMERelay.removeSurfaceToPTI(this); - }, - this, "STextInput"); -} \ No newline at end of file diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 210405f6..a2e72282 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -288,23 +288,6 @@ struct SSwipeGesture { CMonitor* pMonitor = nullptr; }; -struct STextInputV1; - -struct STextInput { - wlr_text_input_v3* pWlrInput = nullptr; - STextInputV1* pV1Input = nullptr; - wlr_surface* focusedSurface = nullptr; - - void setFocusedSurface(wlr_surface* pSurface); - - DYNLISTENER(textInputEnable); - DYNLISTENER(textInputDisable); - DYNLISTENER(textInputCommit); - DYNLISTENER(textInputDestroy); - DYNLISTENER(surfaceUnmapped); - DYNLISTENER(surfaceDestroyed); -}; - struct SIMEKbGrab { wlr_input_method_keyboard_grab_v2* pWlrKbGrab = nullptr; @@ -319,7 +302,7 @@ struct SIMEPopup { int x, y; int realX, realY; bool visible; - Vector2D lastSize; + CBox lastBox; DYNLISTENER(mapPopup); DYNLISTENER(unmapPopup); diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index bdc46445..13e4c9df 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -28,46 +28,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { return; } - if (PTI->pWlrInput) { - if (PIMR->m_pWLRIME->current.preedit.text) { - wlr_text_input_v3_send_preedit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.preedit.text, PIMR->m_pWLRIME->current.preedit.cursor_begin, - PIMR->m_pWLRIME->current.preedit.cursor_end); - } - - if (PIMR->m_pWLRIME->current.commit_text) { - wlr_text_input_v3_send_commit_string(PTI->pWlrInput, PIMR->m_pWLRIME->current.commit_text); - } - - if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { - wlr_text_input_v3_send_delete_surrounding_text(PTI->pWlrInput, PIMR->m_pWLRIME->current.delete_.before_length, PIMR->m_pWLRIME->current.delete_.after_length); - } - - wlr_text_input_v3_send_done(PTI->pWlrInput); - } else { - if (PIMR->m_pWLRIME->current.preedit.text) { - zwp_text_input_v1_send_preedit_cursor(PTI->pV1Input->resourceImpl, PIMR->m_pWLRIME->current.preedit.cursor_begin); - zwp_text_input_v1_send_preedit_styling(PTI->pV1Input->resourceImpl, 0, std::string(PIMR->m_pWLRIME->current.preedit.text).length(), - ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); - zwp_text_input_v1_send_preedit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.preedit.text, ""); - } else { - zwp_text_input_v1_send_preedit_cursor(PTI->pV1Input->resourceImpl, PIMR->m_pWLRIME->current.preedit.cursor_begin); - zwp_text_input_v1_send_preedit_styling(PTI->pV1Input->resourceImpl, 0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); - zwp_text_input_v1_send_preedit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, "", ""); - } - - if (PIMR->m_pWLRIME->current.commit_text) { - zwp_text_input_v1_send_commit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.commit_text); - } - - if (PIMR->m_pWLRIME->current.delete_.before_length || PIMR->m_pWLRIME->current.delete_.after_length) { - zwp_text_input_v1_send_delete_surrounding_text(PTI->pV1Input->resourceImpl, - std::string(PIMR->m_pWLRIME->current.preedit.text).length() - PIMR->m_pWLRIME->current.delete_.before_length, - PIMR->m_pWLRIME->current.delete_.after_length + PIMR->m_pWLRIME->current.delete_.before_length); - - if (PIMR->m_pWLRIME->current.preedit.text) - zwp_text_input_v1_send_commit_string(PTI->pV1Input->resourceImpl, PTI->pV1Input->serial, PIMR->m_pWLRIME->current.preedit.text); - } - } + PTI->updateIMEState(PIMR->m_pWLRIME); }, this, "IMERelay"); @@ -88,7 +49,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { Debug::log(LOG, "IME Destroy"); if (PTI) - onTextInputEnter(PTI->focusedSurface); + PTI->enter(PTI->focusedSurface()); }, this, "IMERelay"); @@ -139,11 +100,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { this, "IMERelay"); if (const auto PTI = getFocusedTextInput(); PTI) - onTextInputEnter(PTI->focusedSurface); -} - -wlr_surface* CInputMethodRelay::focusedSurface(STextInput* pTI) { - return pTI->pWlrInput ? pTI->pWlrInput->focused_surface : pTI->focusedSurface; + PTI->enter(PTI->focusedSurface()); } void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { @@ -151,63 +108,46 @@ void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { return; // damage last known pos & size - g_pHyprRenderer->damageBox(pPopup->realX, pPopup->realY, pPopup->lastSize.x, pPopup->lastSize.y); + g_pHyprRenderer->damageBox(&pPopup->lastBox); const auto PFOCUSEDTI = getFocusedTextInput(); - if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI)) + if (!PFOCUSEDTI || !PFOCUSEDTI->focusedSurface()) return; - bool cursorRect = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE : true; - const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI); - CBox cursorBox = PFOCUSEDTI->pWlrInput ? PFOCUSEDTI->pWlrInput->current.cursor_rectangle : PFOCUSEDTI->pV1Input->cursorRectangle; - CMonitor* pMonitor = nullptr; + bool cursorRect = PFOCUSEDTI->hasCursorRectangle(); + const auto PFOCUSEDSURFACE = PFOCUSEDTI->focusedSurface(); + CBox cursorBox = PFOCUSEDTI->cursorBox(); - Vector2D parentPos; - Vector2D parentSize; + CBox parentBox; - if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) { - const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)); + const auto PSURFACE = CWLSurface::surfaceFromWlr(PFOCUSEDSURFACE); - if (PLS) { - parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition; - parentSize = Vector2D(PLS->geometry.width, PLS->geometry.height); - pMonitor = g_pCompositor->getMonitorFromID(PLS->monitorID); - } - } else { - const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE); + if (!PSURFACE) + parentBox = {0, 0, 200, 200}; + else + parentBox = PSURFACE->getSurfaceBoxGlobal().value_or(CBox{0, 0, 200, 200}); - if (PWINDOW) { - parentPos = PWINDOW->m_vRealPosition.goal(); - parentSize = PWINDOW->m_vRealSize.goal(); - pMonitor = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - } - } + if (!cursorRect) + cursorBox = {0, 0, (int)parentBox.w, (int)parentBox.h}; - if (!cursorRect) { - cursorBox = {0, 0, (int)parentSize.x, (int)parentSize.y}; - } + CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(cursorBox.middle()); - if (!pMonitor) - return; + if (cursorBox.y + parentBox.y + pPopup->pSurface->surface->current.height + cursorBox.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) + cursorBox.y -= pPopup->pSurface->surface->current.height + cursorBox.height; - CBox finalBox = cursorBox; + if (cursorBox.x + parentBox.x + pPopup->pSurface->surface->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) + cursorBox.x -= (cursorBox.x + parentBox.x + pPopup->pSurface->surface->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); - if (cursorBox.y + parentPos.y + pPopup->pSurface->surface->current.height + finalBox.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) - finalBox.y -= pPopup->pSurface->surface->current.height + finalBox.height; + pPopup->x = cursorBox.x; + pPopup->y = cursorBox.y + cursorBox.height; - if (cursorBox.x + parentPos.x + pPopup->pSurface->surface->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) - finalBox.x -= (cursorBox.x + parentPos.x + pPopup->pSurface->surface->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); + pPopup->realX = cursorBox.x + parentBox.x; + pPopup->realY = cursorBox.y + parentBox.y + cursorBox.height; - pPopup->x = finalBox.x; - pPopup->y = finalBox.y + finalBox.height; + pPopup->lastBox = cursorBox; - pPopup->realX = finalBox.x + parentPos.x; - pPopup->realY = finalBox.y + parentPos.y + finalBox.height; - - pPopup->lastSize = Vector2D(pPopup->pSurface->surface->current.width, pPopup->pSurface->surface->current.height); - - wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, finalBox.pWlr()); + wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, cursorBox.pWlr()); damagePopup(pPopup); } @@ -223,7 +163,7 @@ void Events::listener_mapInputPopup(void* owner, void* data) { g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP); - if (const auto PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PPOPUP->realX, PPOPUP->realY) + PPOPUP->lastSize / 2.f); PMONITOR) + if (const auto PMONITOR = g_pCompositor->getMonitorFromVector(PPOPUP->lastBox.middle()); PMONITOR) wlr_surface_send_enter(PPOPUP->pSurface->surface, PMONITOR->output); } @@ -232,7 +172,7 @@ void Events::listener_unmapInputPopup(void* owner, void* data) { Debug::log(LOG, "Unmapped an IME Popup"); - g_pHyprRenderer->damageBox(PPOPUP->realX, PPOPUP->realY, PPOPUP->lastSize.x, PPOPUP->lastSize.y); + g_pHyprRenderer->damageBox(&PPOPUP->lastBox); g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP); } @@ -267,12 +207,12 @@ void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) { const auto PFOCUSEDTI = getFocusedTextInput(); - if (!PFOCUSEDTI || !focusedSurface(PFOCUSEDTI)) + if (!PFOCUSEDTI || !PFOCUSEDTI->focusedSurface()) return; Vector2D parentPos; - const auto PFOCUSEDSURFACE = focusedSurface(PFOCUSEDTI); + const auto PFOCUSEDSURFACE = PFOCUSEDTI->focusedSurface(); if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) { const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)); @@ -307,276 +247,60 @@ SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) { return m_pKeyboardGrab.get(); } -STextInput* CInputMethodRelay::getFocusedTextInput() { - if (m_pFocusedSurface) - return getTextInput(m_pFocusedSurface); +CTextInput* CInputMethodRelay::getFocusedTextInput() { + if (!g_pCompositor->m_pLastFocus) + return nullptr; + + for (auto& ti : m_vTextInputs) { + if (ti->focusedSurface() == g_pCompositor->m_pLastFocus) + return ti.get(); + } return nullptr; } void CInputMethodRelay::onNewTextInput(wlr_text_input_v3* pInput) { - createNewTextInput(pInput); + m_vTextInputs.emplace_back(std::make_unique(pInput)); } -void CInputMethodRelay::createNewTextInput(wlr_text_input_v3* pInput, STextInputV1* pTIV1) { - - if (pInput) { - if (!setTextInputVersion(wl_resource_get_client(pInput->resource), 3)) - return; - } else if (!setTextInputVersion(pTIV1->client, 1)) - return; - - const auto PTEXTINPUT = &m_lTextInputs.emplace_back(); - - PTEXTINPUT->pWlrInput = pInput; - PTEXTINPUT->pV1Input = pTIV1; - - if (pTIV1) - pTIV1->pTextInput = PTEXTINPUT; - - PTEXTINPUT->hyprListener_textInputEnable.initCallback( - pInput ? &pInput->events.enable : &pTIV1->sEnable, - [&](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Enabling TextInput on no IME!"); - return; - } - - // v1 only, map surface to PTI - if (PINPUT->pV1Input) { - wlr_surface* pSurface = wlr_surface_from_resource((wl_resource*)data); - PINPUT->setFocusedSurface(pSurface); - setSurfaceToPTI(pSurface, PINPUT); - if (m_pFocusedSurface == pSurface) - onTextInputEnter(pSurface); - } - - Debug::log(LOG, "Enable TextInput"); - - wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); - }, - PTEXTINPUT, "textInput"); - - PTEXTINPUT->hyprListener_textInputCommit.initCallback( - pInput ? &pInput->events.commit : &pTIV1->sCommit, - [](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Committing TextInput on no IME!"); - return; - } - - if (!(PINPUT->pWlrInput ? PINPUT->pWlrInput->current_enabled : PINPUT->pV1Input->active)) { - Debug::log(WARN, "Disabled TextInput commit?"); - return; - } - - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); - }, - PTEXTINPUT, "textInput"); - - PTEXTINPUT->hyprListener_textInputDisable.initCallback( - pInput ? &pInput->events.disable : &pTIV1->sDisable, - [](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Disabling TextInput on no IME!"); - return; - } - - Debug::log(LOG, "Disable TextInput"); - - wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); - - g_pInputManager->m_sIMERelay.removeSurfaceToPTI(PINPUT); - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); - }, - PTEXTINPUT, "textInput"); - - PTEXTINPUT->hyprListener_textInputDestroy.initCallback( - pInput ? &pInput->events.destroy : &pTIV1->sDestroy, - [](void* owner, void* data) { - const auto PINPUT = (STextInput*)owner; - - if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { - // Debug::log(WARN, "Disabling TextInput on no IME!"); - return; - } - - if (PINPUT->pWlrInput && PINPUT->pWlrInput->current_enabled) { - wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); - - g_pInputManager->m_sIMERelay.commitIMEState(PINPUT); - } - - PINPUT->hyprListener_textInputCommit.removeCallback(); - PINPUT->hyprListener_textInputDestroy.removeCallback(); - PINPUT->hyprListener_textInputDisable.removeCallback(); - PINPUT->hyprListener_textInputEnable.removeCallback(); - - g_pInputManager->m_sIMERelay.removeTextInputVersion(PINPUT->pWlrInput ? wl_resource_get_client(PINPUT->pWlrInput->resource) : PINPUT->pV1Input->client); - g_pInputManager->m_sIMERelay.removeSurfaceToPTI(PINPUT); - g_pInputManager->m_sIMERelay.removeTextInput(PINPUT); - }, - PTEXTINPUT, "textInput"); +void CInputMethodRelay::onNewTextInput(STextInputV1* pTIV1) { + m_vTextInputs.emplace_back(std::make_unique(pTIV1)); } -void CInputMethodRelay::removeTextInput(STextInput* pInput) { - m_lTextInputs.remove_if([&](const auto& other) { return other.pWlrInput == pInput->pWlrInput && other.pV1Input == pInput->pV1Input; }); +void CInputMethodRelay::removeTextInput(CTextInput* pInput) { + m_vTextInputs.remove_if([&](const auto& other) { return other.get() == pInput; }); } -void CInputMethodRelay::commitIMEState(STextInput* pInput) { +void CInputMethodRelay::commitIMEState(CTextInput* pInput) { if (!m_pWLRIME) return; - if (pInput->pWlrInput) { - // V3 - if (pInput->pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) - wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->pWlrInput->current.surrounding.text, pInput->pWlrInput->current.surrounding.cursor, - pInput->pWlrInput->current.surrounding.anchor); - - wlr_input_method_v2_send_text_change_cause(m_pWLRIME, pInput->pWlrInput->current.text_change_cause); - - if (pInput->pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) - wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->pWlrInput->current.content_type.hint, pInput->pWlrInput->current.content_type.purpose); - } else { - // V1 - if (pInput->pV1Input->pendingSurrounding.isPending) - wlr_input_method_v2_send_surrounding_text(m_pWLRIME, pInput->pV1Input->pendingSurrounding.text.c_str(), pInput->pV1Input->pendingSurrounding.cursor, - pInput->pV1Input->pendingSurrounding.anchor); - - wlr_input_method_v2_send_text_change_cause(m_pWLRIME, 0); - - if (pInput->pV1Input->pendingContentType.isPending) - wlr_input_method_v2_send_content_type(m_pWLRIME, pInput->pV1Input->pendingContentType.hint, pInput->pV1Input->pendingContentType.purpose); - } - - for (auto& p : m_lIMEPopups) { - updateInputPopup(&p); - } - - wlr_input_method_v2_send_done(m_pWLRIME); + pInput->commitStateToIME(m_pWLRIME); } void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { if (!m_pWLRIME) return; - if (pSurface == m_pFocusedSurface) + if (pSurface == m_pLastKbFocus) return; - // say goodbye to the last focused surface - if (STextInput* lastTI = getTextInput(m_pFocusedSurface); lastTI) { - wlr_input_method_v2_send_deactivate(m_pWLRIME); - commitIMEState(lastTI); - onTextInputLeave(m_pFocusedSurface); + m_pLastKbFocus = pSurface; + + for (auto& ti : m_vTextInputs) { + if (!ti->focusedSurface()) + continue; + + ti->leave(); } - // do some work for the new focused surface - m_pFocusedSurface = pSurface; + for (auto& ti : m_vTextInputs) { + if (!ti->isV3()) + continue; - /* - * v3 only. v1 is handled by hyprListener_textInputEnable. - * POSSIBLE BUG here: if one client has multiple STextInput and multiple surfaces, for any pSurface we can only record the last found ti. - * since original code has the same problem, it may not be a big deal. - */ - if (getTextInputVersion(wl_resource_get_client(pSurface->resource)) == 3) { - if (!getTextInput(pSurface)) { - auto client = [](STextInput* pTI) -> wl_client* { return pTI->pWlrInput ? wl_resource_get_client(pTI->pWlrInput->resource) : pTI->pV1Input->client; }; - for (auto& ti : m_lTextInputs) { - if (client(&ti) == wl_resource_get_client(pSurface->resource) && ti.pWlrInput) - setSurfaceToPTI(pSurface, &ti); - } - } - } + if (ti->client() != wl_resource_get_client(pSurface->resource)) + continue; - onTextInputEnter(m_pFocusedSurface); -} - -void CInputMethodRelay::onTextInputLeave(wlr_surface* pSurface) { - if (!pSurface) - return; - - STextInput* ti = getTextInput(pSurface); - if (!ti) - return; - - if (ti->pWlrInput && !ti->pWlrInput->focused_surface) - return; - - if (ti->pWlrInput) - wlr_text_input_v3_send_leave(ti->pWlrInput); - else { - zwp_text_input_v1_send_leave(ti->pV1Input->resourceImpl); - ti->setFocusedSurface(nullptr); - ti->pV1Input->active = false; + ti->enter(pSurface); } } - -void CInputMethodRelay::onTextInputEnter(wlr_surface* pSurface) { - if (!pSurface) - return; - - STextInput* ti = getTextInput(pSurface); - if (!ti) - return; - - if (ti->pWlrInput) - wlr_text_input_v3_send_enter(ti->pWlrInput, pSurface); - else { - zwp_text_input_v1_send_enter(ti->pV1Input->resourceImpl, pSurface->resource); - ti->setFocusedSurface(pSurface); - ti->pV1Input->active = true; - } -} - -void CInputMethodRelay::setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput) { - if (pSurface) { - m_mSurfaceToTextInput[pSurface] = pInput; - pInput->setFocusedSurface(pSurface); - } -} - -void CInputMethodRelay::removeSurfaceToPTI(STextInput* pInput) { - if (pInput->focusedSurface) { - m_mSurfaceToTextInput.erase(pInput->focusedSurface); - pInput->setFocusedSurface(nullptr); - return; - } - - std::erase_if(m_mSurfaceToTextInput, [pInput](const auto& el) { return el.second == pInput; }); -} - -STextInput* CInputMethodRelay::getTextInput(wlr_surface* pSurface) { - auto result = m_mSurfaceToTextInput.find(pSurface); - if (result != m_mSurfaceToTextInput.end()) - return result->second; - - return nullptr; -} - -int CInputMethodRelay::setTextInputVersion(wl_client* pClient, int version) { - if (int v = getTextInputVersion(pClient); v != 0 && v != version) { - Debug::log(WARN, "Client attempt to register text-input-v{}, but it has already registered text-input-v{}, ignored", version, v); - return 0; - } - m_mClientTextInputVersion.insert({pClient, version}); - return 1; -} - -int CInputMethodRelay::getTextInputVersion(wl_client* pClient) { - auto result = m_mClientTextInputVersion.find(pClient); - if (result != m_mClientTextInputVersion.end()) - return result->second; - - return 0; -} - -void CInputMethodRelay::removeTextInputVersion(wl_client* pClient) { - m_mClientTextInputVersion.erase(pClient); -} diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index 6f99cae2..7618400f 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -3,6 +3,7 @@ #include #include "../../defines.hpp" #include "../../helpers/WLClasses.hpp" +#include "TextInput.hpp" class CInputManager; struct STextInputV1; @@ -13,15 +14,16 @@ class CInputMethodRelay { void onNewIME(wlr_input_method_v2*); void onNewTextInput(wlr_text_input_v3*); + void onNewTextInput(STextInputV1* pTIV1); wlr_input_method_v2* m_pWLRIME = nullptr; - void commitIMEState(STextInput* pInput); - void removeTextInput(STextInput* pInput); + void commitIMEState(CTextInput* pInput); + void removeTextInput(CTextInput* pInput); void onKeyboardFocus(wlr_surface*); - STextInput* getFocusedTextInput(); + CTextInput* getFocusedTextInput(); SIMEKbGrab* getIMEKeyboardGrab(SKeyboard*); @@ -31,10 +33,12 @@ class CInputMethodRelay { void removePopup(SIMEPopup*); private: - std::unique_ptr m_pKeyboardGrab; + std::unique_ptr m_pKeyboardGrab; - std::list m_lTextInputs; - std::list m_lIMEPopups; + std::list> m_vTextInputs; + std::list m_lIMEPopups; + + wlr_surface* m_pLastKbFocus = nullptr; DYNLISTENER(textInputNew); DYNLISTENER(IMECommit); @@ -42,25 +46,8 @@ class CInputMethodRelay { DYNLISTENER(IMEGrab); DYNLISTENER(IMENewPopup); - void createNewTextInput(wlr_text_input_v3*, STextInputV1* tiv1 = nullptr); - - wlr_surface* focusedSurface(STextInput* pInput); - wlr_surface* m_pFocusedSurface; - void onTextInputLeave(wlr_surface* pSurface); - void onTextInputEnter(wlr_surface* pSurface); - - std::unordered_map m_mSurfaceToTextInput; - void setSurfaceToPTI(wlr_surface* pSurface, STextInput* pInput); - STextInput* getTextInput(wlr_surface* pSurface); - void removeSurfaceToPTI(STextInput* pInput); - - std::unordered_map m_mClientTextInputVersion; - int setTextInputVersion(wl_client* pClient, int version); - int getTextInputVersion(wl_client* pClient); - void removeTextInputVersion(wl_client* pClient); - friend class CHyprRenderer; friend class CInputManager; friend class CTextInputV1ProtocolManager; - friend struct STextInput; + friend struct CTextInput; }; diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp new file mode 100644 index 00000000..a1916929 --- /dev/null +++ b/src/managers/input/TextInput.cpp @@ -0,0 +1,273 @@ +#include "TextInput.hpp" +#include "../../defines.hpp" +#include "InputManager.hpp" +#include "../../protocols/TextInputV1.hpp" +#include "../../Compositor.hpp" + +CTextInput::CTextInput(STextInputV1* ti) : pV1Input(ti) { + ti->pTextInput = this; + initCallbacks(); +} + +CTextInput::CTextInput(wlr_text_input_v3* ti) : pWlrInput(ti) { + initCallbacks(); +} + +CTextInput::~CTextInput() { + if (pV1Input) + pV1Input->pTextInput = nullptr; +} + +void CTextInput::tiV1Destroyed() { + pV1Input = nullptr; + + g_pInputManager->m_sIMERelay.removeTextInput(this); +} + +void CTextInput::initCallbacks() { + hyprListener_textInputEnable.initCallback( + isV3() ? &pWlrInput->events.enable : &pV1Input->sEnable, [this](void* owner, void* data) { onEnabled(); }, this, "textInput"); + + hyprListener_textInputCommit.initCallback( + isV3() ? &pWlrInput->events.commit : &pV1Input->sCommit, [this](void* owner, void* data) { onCommit(); }, this, "textInput"); + + hyprListener_textInputDisable.initCallback( + isV3() ? &pWlrInput->events.disable : &pV1Input->sDisable, [this](void* owner, void* data) { onDisabled(); }, this, "textInput"); + + hyprListener_textInputDestroy.initCallback( + isV3() ? &pWlrInput->events.destroy : &pV1Input->sDestroy, + [this](void* owner, void* data) { + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Disabling TextInput on no IME!"); + return; + } + + if (pWlrInput && pWlrInput->current_enabled) { + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + + g_pInputManager->m_sIMERelay.commitIMEState(this); + } + + hyprListener_textInputCommit.removeCallback(); + hyprListener_textInputDestroy.removeCallback(); + hyprListener_textInputDisable.removeCallback(); + hyprListener_textInputEnable.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + hyprListener_surfaceUnmapped.removeCallback(); + + g_pInputManager->m_sIMERelay.removeTextInput(this); + }, + this, "textInput"); +} + +void CTextInput::onEnabled(wlr_surface* surfV1) { + Debug::log(LOG, "TI ENABLE"); + + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Enabling TextInput on no IME!"); + return; + } + + // v1 only, map surface to PTI + if (!isV3()) { + wlr_surface* pSurface = surfV1; + setFocusedSurface(pSurface); + if (g_pCompositor->m_pLastFocus == pSurface) + enter(pSurface); + } + + wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); + g_pInputManager->m_sIMERelay.commitIMEState(this); +} + +void CTextInput::onDisabled() { + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Disabling TextInput on no IME!"); + return; + } + + leave(); + + hyprListener_surfaceDestroyed.removeCallback(); + hyprListener_surfaceUnmapped.removeCallback(); + + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + g_pInputManager->m_sIMERelay.commitIMEState(this); +} + +void CTextInput::onCommit() { + if (!g_pInputManager->m_sIMERelay.m_pWLRIME) { + // Debug::log(WARN, "Committing TextInput on no IME!"); + return; + } + + if (!(pWlrInput ? pWlrInput->current_enabled : pV1Input->active)) { + Debug::log(WARN, "Disabled TextInput commit?"); + return; + } + + g_pInputManager->m_sIMERelay.commitIMEState(this); +} + +void CTextInput::setFocusedSurface(wlr_surface* pSurface) { + if (pSurface == pFocusedSurface) + return; + + pFocusedSurface = pSurface; + + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + + if (!pSurface) + return; + + hyprListener_surfaceUnmapped.initCallback( + &pSurface->events.unmap, + [this](void* owner, void* data) { + Debug::log(LOG, "Unmap TI owner1"); + + pFocusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + }, + this, "CTextInput"); + + hyprListener_surfaceDestroyed.initCallback( + &pSurface->events.destroy, + [this](void* owner, void* data) { + Debug::log(LOG, "destroy TI owner1"); + + pFocusedSurface = nullptr; + hyprListener_surfaceUnmapped.removeCallback(); + hyprListener_surfaceDestroyed.removeCallback(); + }, + this, "CTextInput"); +} + +bool CTextInput::isV3() { + return pWlrInput; +} + +void CTextInput::enter(wlr_surface* pSurface) { + if (!pSurface || !pSurface->mapped) + return; + + if (pSurface == focusedSurface()) + return; + + if (focusedSurface()) { + leave(); + setFocusedSurface(nullptr); + } + + enterLocks++; + RASSERT(enterLocks == 1, "TextInput had != 1 lock in enter"); + + if (pWlrInput) + wlr_text_input_v3_send_enter(pWlrInput, pSurface); + else { + zwp_text_input_v1_send_enter(pV1Input->resourceImpl, pSurface->resource); + pV1Input->active = true; + } + + setFocusedSurface(pSurface); +} + +void CTextInput::leave() { + if (!focusedSurface()) + return; + + enterLocks--; + RASSERT(enterLocks == 0, "TextInput had != 0 locks in leave"); + + if (pWlrInput && pWlrInput->focused_surface) + wlr_text_input_v3_send_leave(pWlrInput); + else if (focusedSurface() && pV1Input) { + zwp_text_input_v1_send_leave(pV1Input->resourceImpl); + pV1Input->active = false; + } + + setFocusedSurface(nullptr); +} + +wlr_surface* CTextInput::focusedSurface() { + return pWlrInput ? pWlrInput->focused_surface : pFocusedSurface; +} + +wl_client* CTextInput::client() { + return pWlrInput ? wl_resource_get_client(pWlrInput->resource) : pV1Input->client; +} + +void CTextInput::commitStateToIME(wlr_input_method_v2* ime) { + if (isV3()) { + if (pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_SURROUNDING_TEXT) + wlr_input_method_v2_send_surrounding_text(ime, pWlrInput->current.surrounding.text, pWlrInput->current.surrounding.cursor, pWlrInput->current.surrounding.anchor); + + wlr_input_method_v2_send_text_change_cause(ime, pWlrInput->current.text_change_cause); + + if (pWlrInput->active_features & WLR_TEXT_INPUT_V3_FEATURE_CONTENT_TYPE) + wlr_input_method_v2_send_content_type(ime, pWlrInput->current.content_type.hint, pWlrInput->current.content_type.purpose); + } else { + if (pV1Input->pendingSurrounding.isPending) + wlr_input_method_v2_send_surrounding_text(ime, pV1Input->pendingSurrounding.text.c_str(), pV1Input->pendingSurrounding.cursor, pV1Input->pendingSurrounding.anchor); + + wlr_input_method_v2_send_text_change_cause(ime, 0); + + if (pV1Input->pendingContentType.isPending) + wlr_input_method_v2_send_content_type(ime, pV1Input->pendingContentType.hint, pV1Input->pendingContentType.purpose); + } + + for (auto& p : g_pInputManager->m_sIMERelay.m_lIMEPopups) { + g_pInputManager->m_sIMERelay.updateInputPopup(&p); + } + + wlr_input_method_v2_send_done(ime); +} + +void CTextInput::updateIMEState(wlr_input_method_v2* ime) { + if (isV3()) { + if (ime->current.preedit.text) { + wlr_text_input_v3_send_preedit_string(pWlrInput, ime->current.preedit.text, ime->current.preedit.cursor_begin, ime->current.preedit.cursor_end); + } + + if (ime->current.commit_text) { + wlr_text_input_v3_send_commit_string(pWlrInput, ime->current.commit_text); + } + + if (ime->current.delete_.before_length || ime->current.delete_.after_length) { + wlr_text_input_v3_send_delete_surrounding_text(pWlrInput, ime->current.delete_.before_length, ime->current.delete_.after_length); + } + + wlr_text_input_v3_send_done(pWlrInput); + } else { + if (ime->current.preedit.text) { + zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preedit.cursor_begin); + zwp_text_input_v1_send_preedit_styling(pV1Input->resourceImpl, 0, std::string(ime->current.preedit.text).length(), ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); + zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.preedit.text, ""); + } else { + zwp_text_input_v1_send_preedit_cursor(pV1Input->resourceImpl, ime->current.preedit.cursor_begin); + zwp_text_input_v1_send_preedit_styling(pV1Input->resourceImpl, 0, 0, ZWP_TEXT_INPUT_V1_PREEDIT_STYLE_HIGHLIGHT); + zwp_text_input_v1_send_preedit_string(pV1Input->resourceImpl, pV1Input->serial, "", ""); + } + + if (ime->current.commit_text) { + zwp_text_input_v1_send_commit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.commit_text); + } + + if (ime->current.delete_.before_length || ime->current.delete_.after_length) { + zwp_text_input_v1_send_delete_surrounding_text(pV1Input->resourceImpl, std::string(ime->current.preedit.text).length() - ime->current.delete_.before_length, + ime->current.delete_.after_length + ime->current.delete_.before_length); + + if (ime->current.preedit.text) + zwp_text_input_v1_send_commit_string(pV1Input->resourceImpl, pV1Input->serial, ime->current.preedit.text); + } + } +} + +bool CTextInput::hasCursorRectangle() { + return !isV3() || pWlrInput->current.features & WLR_TEXT_INPUT_V3_FEATURE_CURSOR_RECTANGLE; +} + +CBox CTextInput::cursorBox() { + return CBox{isV3() ? pWlrInput->current.cursor_rectangle : pV1Input->cursorRectangle}; +} \ No newline at end of file diff --git a/src/managers/input/TextInput.hpp b/src/managers/input/TextInput.hpp new file mode 100644 index 00000000..4acfb960 --- /dev/null +++ b/src/managers/input/TextInput.hpp @@ -0,0 +1,51 @@ +#pragma once + +#include "../../helpers/WLListener.hpp" +#include "../../macros.hpp" +#include "../../helpers/Box.hpp" + +struct wlr_text_input_v3; +struct wlr_surface; +struct wl_client; + +struct STextInputV1; + +class CTextInput { + public: + CTextInput(STextInputV1* ti); + CTextInput(wlr_text_input_v3* ti); + ~CTextInput(); + + bool isV3(); + void enter(wlr_surface* pSurface); + void leave(); + void tiV1Destroyed(); + wl_client* client(); + void commitStateToIME(wlr_input_method_v2* ime); + void updateIMEState(wlr_input_method_v2* ime); + + void onEnabled(wlr_surface* surfV1 = nullptr); + void onDisabled(); + void onCommit(); + + bool hasCursorRectangle(); + CBox cursorBox(); + + wlr_surface* focusedSurface(); + + private: + void setFocusedSurface(wlr_surface* pSurface); + void initCallbacks(); + + wlr_surface* pFocusedSurface = nullptr; + int enterLocks = 0; + wlr_text_input_v3* pWlrInput = nullptr; + STextInputV1* pV1Input = nullptr; + + DYNLISTENER(textInputEnable); + DYNLISTENER(textInputDisable); + DYNLISTENER(textInputCommit); + DYNLISTENER(textInputDestroy); + DYNLISTENER(surfaceUnmapped); + DYNLISTENER(surfaceDestroyed); +}; \ No newline at end of file diff --git a/src/protocols/TextInputV1.cpp b/src/protocols/TextInputV1.cpp index 8d1f6f97..7535033a 100644 --- a/src/protocols/TextInputV1.cpp +++ b/src/protocols/TextInputV1.cpp @@ -131,7 +131,7 @@ static void destroyTI(wl_resource* resource) { wl_resource_set_user_data(resource, nullptr); } - TI->pTextInput->hyprListener_textInputDestroy.emit(nullptr); + TI->pTextInput->tiV1Destroyed(); g_pProtocolManager->m_pTextInputV1ProtocolManager->removeTI(TI); } @@ -158,7 +158,7 @@ void CTextInputV1ProtocolManager::createTI(wl_client* client, wl_resource* resou wl_signal_init(&PTI->sDestroy); wl_signal_init(&PTI->sCommit); - g_pInputManager->m_sIMERelay.createNewTextInput(nullptr, PTI); + g_pInputManager->m_sIMERelay.onNewTextInput(PTI); } void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* resource, wl_resource* seat, wl_resource* surface) { @@ -167,12 +167,12 @@ void CTextInputV1ProtocolManager::handleActivate(wl_client* client, wl_resource* Debug::log(WARN, "Text-input-v1 PTI{:x}: No surface to activate text input on!", (uintptr_t)PTI); return; } - PTI->pTextInput->hyprListener_textInputEnable.emit(surface); + PTI->pTextInput->onEnabled(wlr_surface_from_resource(surface)); } void CTextInputV1ProtocolManager::handleDeactivate(wl_client* client, wl_resource* resource, wl_resource* seat) { const auto PTI = tiFromResource(resource); - PTI->pTextInput->hyprListener_textInputDisable.emit(nullptr); + PTI->pTextInput->onDisabled(); } void CTextInputV1ProtocolManager::handleShowInputPanel(wl_client* client, wl_resource* resource) { @@ -212,7 +212,7 @@ void CTextInputV1ProtocolManager::handleSetPreferredLanguage(wl_client* client, void CTextInputV1ProtocolManager::handleCommitState(wl_client* client, wl_resource* resource, uint32_t serial) { const auto PTI = tiFromResource(resource); PTI->serial = serial; - PTI->pTextInput->hyprListener_textInputCommit.emit(nullptr); + PTI->pTextInput->onCommit(); } void CTextInputV1ProtocolManager::handleInvokeAction(wl_client* client, wl_resource* resource, uint32_t button, uint32_t index) { diff --git a/src/protocols/TextInputV1.hpp b/src/protocols/TextInputV1.hpp index 9362a52e..0a1203f0 100644 --- a/src/protocols/TextInputV1.hpp +++ b/src/protocols/TextInputV1.hpp @@ -5,7 +5,7 @@ #include -struct STextInput; +class CTextInput; struct STextInputV1 { wl_client* client = nullptr; @@ -13,7 +13,7 @@ struct STextInputV1 { wl_resource* resourceImpl = nullptr; - STextInput* pTextInput = nullptr; + CTextInput* pTextInput = nullptr; wl_signal sEnable; wl_signal sDisable; From 0dfdb6678f5362fda449694639e8fee806ca1ae4 Mon Sep 17 00:00:00 2001 From: fufexan Date: Sat, 23 Mar 2024 00:03:18 +0000 Subject: [PATCH 0172/2897] [gha] Nix: update inputs --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 9e6464f0..a883fa8e 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ ] }, "locked": { - "lastModified": 1710257359, - "narHash": "sha256-43re5pzE/cswFAgw92/ugsB3+d5ufDaCcLtl9ztKfBo=", + "lastModified": 1711035742, + "narHash": "sha256-5vvhCSUGG9TA2G1eIRgokuYizhRnZu0ZbcU1MXfHsUE=", "owner": "hyprwm", "repo": "hyprcursor", - "rev": "1761f6cefd77f4fcd2039d930c88d6716ddc4974", + "rev": "6a92473237f430399a417e1c2da9d7fcd4970086", "type": "github" }, "original": { @@ -79,11 +79,11 @@ ] }, "locked": { - "lastModified": 1709914708, - "narHash": "sha256-bR4o3mynoTa1Wi4ZTjbnsZ6iqVcPGriXp56bZh5UFTk=", + "lastModified": 1710960526, + "narHash": "sha256-tt0UgVKWeLQ+tFzvqrm4uAZbzONwdGshpfiLHAQ1P2c=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "a685493fdbeec01ca8ccdf1f3655c044a8ce2fe2", + "rev": "a2f39421144d42541c057be235154ce21b76c0f6", "type": "github" }, "original": { @@ -94,11 +94,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710272261, - "narHash": "sha256-g0bDwXFmTE7uGDOs9HcJsfLFhH7fOsASbAuOzDC+fhQ=", + "lastModified": 1711001935, + "narHash": "sha256-URtGpHue7HHZK0mrHnSf8wJ6OmMKYSsoLmJybrOLFSQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "0ad13a6833440b8e238947e47bea7f11071dc2b2", + "rev": "20f77aa09916374aa3141cbc605c955626762c9a", "type": "github" }, "original": { From 059e85ae69e5d50bb6734532da4abdcf66167ab3 Mon Sep 17 00:00:00 2001 From: Khalid Date: Sat, 23 Mar 2024 23:31:03 +0300 Subject: [PATCH 0173/2897] input: Add options to set tablet's active area (#5199) * Add options to set tablet's active area * Set tablet's active area in `setTabletConfigs` * Fix formatting for new variables in ConfigManager * Report tablet's physical size with hyprctl --- src/config/ConfigManager.cpp | 12 ++++++++---- src/debug/HyprCtl.cpp | 2 +- src/helpers/WLClasses.hpp | 2 ++ src/managers/input/InputManager.cpp | 7 +++++++ src/managers/input/Tablets.cpp | 8 +++++++- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 7925da64..f0af317a 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -478,6 +478,8 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("input:tablet:region_size", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("input:tablet:relative_input", Hyprlang::INT{0}); m_pConfig->addConfigValue("input:tablet:left_handed", Hyprlang::INT{0}); + m_pConfig->addConfigValue("input:tablet:active_area_position", Hyprlang::VEC2{0, 0}); + m_pConfig->addConfigValue("input:tablet:active_area_size", Hyprlang::VEC2{0, 0}); m_pConfig->addConfigValue("binds:pass_mouse_when_bound", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:scroll_event_delay", Hyprlang::INT{300}); @@ -554,10 +556,12 @@ CConfigManager::CConfigManager() { m_pConfig->addSpecialConfigValue("device", "scroll_points", {STRVAL_EMPTY}); m_pConfig->addSpecialConfigValue("device", "transform", Hyprlang::INT{0}); m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY}); - m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices - m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets - m_pConfig->addSpecialConfigValue("device", "region_size", Hyprlang::VEC2{0, 0}); // only for tablets - m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "enabled", Hyprlang::INT{1}); // only for mice, touchpads, and touchdevices + m_pConfig->addSpecialConfigValue("device", "region_position", Hyprlang::VEC2{0, 0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "region_size", Hyprlang::VEC2{0, 0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "relative_input", Hyprlang::INT{0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "active_area_position", Hyprlang::VEC2{0, 0}); // only for tablets + m_pConfig->addSpecialConfigValue("device", "active_area_size", Hyprlang::VEC2{0, 0}); // only for tablets // keywords m_pConfig->registerHandler(&::handleRawExec, "exec", {false}); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 211b532e..903b7d7f 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -657,7 +657,7 @@ std::string devicesRequest(eHyprCtlOutputFormat format, std::string request) { } for (auto& d : g_pInputManager->m_lTablets) { - result += std::format("\tTablet at {:x}:\n\t\t{}\n", (uintptr_t)&d, d.name); + result += std::format("\tTablet at {:x}:\n\t\t{}\n\t\t\tsize: {}x{}mm\n", (uintptr_t)&d, d.name, d.wlrTablet->width_mm, d.wlrTablet->height_mm); } for (auto& d : g_pInputManager->m_lTabletTools) { diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index a2e72282..dbe8d389 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -217,6 +217,8 @@ struct STablet { std::string boundOutput = ""; + CBox activeArea; + // bool operator==(const STablet& b) const { return wlrDevice == b.wlrDevice; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 7d820c8f..94e6abec 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1438,6 +1438,13 @@ void CInputManager::setTabletConfigs() { auto regionBox = CBox{REGION_POS.x, REGION_POS.y, REGION_SIZE.x, REGION_SIZE.y}; if (!regionBox.empty()) wlr_cursor_map_input_to_region(g_pCompositor->m_sWLRCursor, t.wlrDevice, regionBox.pWlr()); + + const auto ACTIVE_AREA_SIZE = g_pConfigManager->getDeviceVec(t.name, "active_area_size", "input:tablet:active_area_size"); + const auto ACTIVE_AREA_POS = g_pConfigManager->getDeviceVec(t.name, "active_area_position", "input:tablet:active_area_position"); + if (ACTIVE_AREA_SIZE.x != 0 || ACTIVE_AREA_SIZE.y != 0) { + t.activeArea = CBox{ACTIVE_AREA_POS.x / t.wlrTablet->width_mm, ACTIVE_AREA_POS.y / t.wlrTablet->height_mm, + (ACTIVE_AREA_POS.x + ACTIVE_AREA_SIZE.x) / t.wlrTablet->width_mm, (ACTIVE_AREA_POS.y + ACTIVE_AREA_SIZE.y) / t.wlrTablet->height_mm}; + } } } } diff --git a/src/managers/input/Tablets.cpp b/src/managers/input/Tablets.cpp index 387212c7..9252fca4 100644 --- a/src/managers/input/Tablets.cpp +++ b/src/managers/input/Tablets.cpp @@ -51,8 +51,14 @@ void CInputManager::newTabletTool(wlr_input_device* pDevice) { if (PTAB->relativeInput) wlr_cursor_move(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, dx, dy); - else + else { + // Calculate transformations if active area is set + if (!PTAB->activeArea.empty()) { + x = (x - PTAB->activeArea.x) / (PTAB->activeArea.w - PTAB->activeArea.x); + y = (y - PTAB->activeArea.y) / (PTAB->activeArea.h - PTAB->activeArea.y); + } wlr_cursor_warp_absolute(g_pCompositor->m_sWLRCursor, PTAB->wlrDevice, x, y); + } g_pInputManager->simulateMouseMovement(); g_pInputManager->focusTablet(PTAB, EVENT->tool, true); From 0d91f82d835b65f339726e3fbbd9c5347baabf7e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 23 Mar 2024 21:10:54 +0000 Subject: [PATCH 0174/2897] config: be a bit louder in the disabled log warning --- src/config/ConfigManager.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f0af317a..11159131 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -586,11 +586,13 @@ CConfigManager::CConfigManager() { m_pConfig->commence(); - Debug::log(LOG, "NOTE: further logs to stdout / logfile are disabled by default. Use debug:disable_logs and debug:enable_stdout_logs to override this."); - setDefaultAnimationVars(); resetHLConfig(); + Debug::log(LOG, + "!!!!HEY YOU, YES YOU!!!!: further logs to stdout / logfile are disabled by default. BEFORE SENDING THIS LOG, ENABLE THEM. Use debug:disable_logs = false to do so: " + "https://wiki.hyprland.org/Configuring/Variables/#debug"); + Debug::disableLogs = reinterpret_cast(m_pConfig->getConfigValuePtr("debug:disable_logs")->getDataStaticPtr()); Debug::disableTime = reinterpret_cast(m_pConfig->getConfigValuePtr("debug:disable_time")->getDataStaticPtr()); From 2d5fda4810f706a1b6e2c0a1021ce57c8ad2e7a9 Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Sun, 24 Mar 2024 06:12:27 +0900 Subject: [PATCH 0175/2897] input: fix crash with text-input-v1 (#5234) --- src/managers/input/TextInput.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index a1916929..827d4dbe 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -71,9 +71,10 @@ void CTextInput::onEnabled(wlr_surface* surfV1) { // v1 only, map surface to PTI if (!isV3()) { wlr_surface* pSurface = surfV1; - setFocusedSurface(pSurface); if (g_pCompositor->m_pLastFocus == pSurface) enter(pSurface); + else + setFocusedSurface(pSurface); } wlr_input_method_v2_send_activate(g_pInputManager->m_sIMERelay.m_pWLRIME); From 295128ab2a3c4ad1715bb7cd926880316f00e667 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 23 Mar 2024 22:10:37 +0000 Subject: [PATCH 0176/2897] window: assign surface on create ref #5076 --- src/desktop/Window.cpp | 5 ----- src/events/Windows.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 567c3243..3145000c 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -468,8 +468,6 @@ void CWindow::onUnmap() { std::erase_if(g_pCompositor->m_vWindowFocusHistory, [&](const auto& other) { return other == this; }); - m_pWLSurface.unassign(); - hyprListener_unmapWindow.removeCallback(); if (*PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(m_iWorkspaceID) == 0 && g_pCompositor->isWorkspaceSpecial(m_iWorkspaceID)) { @@ -493,9 +491,6 @@ void CWindow::onUnmap() { } void CWindow::onMap() { - - m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(this), this); - // JIC, reset the callbacks. If any are set, we'll make sure they are cleared so we don't accidentally unset them. (In case a window got remapped) m_vRealPosition.resetAllCallbacks(); m_vRealSize.resetAllCallbacks(); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 7c4ae404..056d9108 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -877,6 +877,8 @@ void Events::listener_destroyWindow(void* owner, void* data) { g_pCompositor->m_pLastFocus = nullptr; } + PWINDOW->m_pWLSurface.unassign(); + PWINDOW->hyprListener_commitWindow.removeCallback(); PWINDOW->hyprListener_mapWindow.removeCallback(); PWINDOW->hyprListener_unmapWindow.removeCallback(); @@ -1217,6 +1219,8 @@ void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XWSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_setOverrideRedirect.initCallback(&XWSURFACE->events.set_override_redirect, &Events::listener_setOverrideRedirect, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_configureX11.initCallback(&XWSURFACE->events.request_configure, &Events::listener_configureX11, PNEWWINDOW, "XWayland Window"); + + PNEWWINDOW->m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(PNEWWINDOW), PNEWWINDOW); } void Events::listener_newXDGToplevel(wl_listener* listener, void* data) { @@ -1232,6 +1236,8 @@ void Events::listener_newXDGToplevel(wl_listener* listener, void* data) { PNEWWINDOW->hyprListener_mapWindow.initCallback(&XDGSURFACE->surface->events.map, &Events::listener_mapWindow, PNEWWINDOW, "XDG Window"); PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XDGSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XDG Window"); PNEWWINDOW->hyprListener_commitWindow.initCallback(&XDGSURFACE->surface->events.commit, &Events::listener_commitWindow, PNEWWINDOW, "XDG Window"); + + PNEWWINDOW->m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(PNEWWINDOW), PNEWWINDOW); } void Events::listener_NewXDGDeco(wl_listener* listener, void* data) { From c7fbea3368452c34c47a4a634e642de6cd4090cb Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 23 Mar 2024 15:14:50 -0700 Subject: [PATCH 0177/2897] animations: Fix animation issue in focusworkspaceoncurrentmonitor (#5202) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * dont render when workspace offset * add guard * can remove useless code now if workspace offset is not taken into account * clang-format * when special workspace is moved, set anim to move * add offset back * make it a configurable option because some folks apparently can't align their monitors correctly and may not want this feature😔 * remove config option --- src/helpers/Monitor.cpp | 1 + src/managers/AnimationManager.cpp | 12 ++++++------ src/render/Renderer.cpp | 6 ++++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 9126f936..3edb7ca4 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -667,6 +667,7 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { if (w->m_iWorkspaceID == pWorkspace->m_iID) { w->m_iMonitorID = ID; w->updateSurfaceScaleTransformDetails(); + w->setAnimationsToMove(); const auto MIDDLE = w->middle(); if (w->m_bIsFloating && !VECINRECT(MIDDLE, vecPosition.x, vecPosition.y, vecPosition.x + vecSize.x, vecPosition.y + vecSize.y) && w->m_iX11Type != 2) { diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 7d2a86e7..a14bc195 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -109,14 +109,13 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(w.get()); } - // if a workspace window is on any monitor, damage it + // if a special workspace window is on any monitor, damage it for (auto& w : g_pCompositor->m_vWindows) { for (auto& m : g_pCompositor->m_vMonitors) { - if (w->m_iWorkspaceID == PWORKSPACE->m_iID && g_pCompositor->windowValidMapped(w.get()) && g_pHyprRenderer->shouldRenderWindow(w.get(), m.get(), PWORKSPACE)) { + if (w->m_iWorkspaceID == PWORKSPACE->m_iID && PWORKSPACE->m_bIsSpecialWorkspace && g_pCompositor->windowValidMapped(w.get()) && + g_pHyprRenderer->shouldRenderWindow(w.get(), m.get(), PWORKSPACE)) { CBox bb = w->getFullWindowBoundingBox(); bb.translate(PWORKSPACE->m_vRenderOffset.value()); - if (PWORKSPACE->m_bIsSpecialWorkspace) - bb.scaleFromCenter(1.1); // for some reason special ws windows getting border artifacts if you close it too quickly... bb.intersection({m->vecPosition, m->vecSize}); g_pHyprRenderer->damageBox(&bb); } @@ -197,7 +196,8 @@ void CAnimationManager::tick() { PWINDOW->updateWindowDecos(); auto bb = PWINDOW->getFullWindowBoundingBox(); const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + if (PWINDOWWORKSPACE) + bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); g_pHyprRenderer->damageBox(&bb); } else if (PWORKSPACE) { for (auto& w : g_pCompositor->m_vWindows) { @@ -245,7 +245,7 @@ void CAnimationManager::tick() { BORDERSIZE + ROUNDINGSIZE); // bottom // damage for new box - CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value(), PWINDOW->m_vRealSize.value()}; + CBox WLRBOXNEW = PWINDOW->getFullWindowBoundingBox(); const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); if (PWINDOWWORKSPACE) WLRBOXNEW.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 88035112..7f83c429 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -217,7 +217,7 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo } } - if (pWindow->m_iWorkspaceID == pWorkspace->m_iID) + if (pWindow->m_iWorkspaceID == pWorkspace->m_iID && pWorkspace->m_iMonitorID == pMonitor->ID) return true; // if not, check if it maybe is active on a different monitor. @@ -228,9 +228,11 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo return true; if (pWindow->m_vRealPosition.isBeingAnimated()) { + if (PWINDOWWORKSPACE && !PWINDOWWORKSPACE->m_bIsSpecialWorkspace && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated()) + return false; // render window if window and monitor intersect // (when moving out of or through a monitor) - CBox windowBox = {pWindow->m_vRealPosition.value(), pWindow->m_vRealSize.value()}; + CBox windowBox = pWindow->getFullWindowBoundingBox(); const CBox monitorBox = {pMonitor->vecPosition, pMonitor->vecSize}; if (!windowBox.intersection(monitorBox).empty()) return true; From 432924b372b8e416ca627fa1adef2504dac1d2be Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 02:02:27 +0000 Subject: [PATCH 0178/2897] xwayland: assign wlr_surface on associate --- src/events/Windows.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 056d9108..d1cf9552 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -1190,11 +1190,15 @@ void Events::listener_associateX11(void* owner, void* data) { PWINDOW->hyprListener_mapWindow.initCallback(&PWINDOW->m_uSurface.xwayland->surface->events.map, &Events::listener_mapWindow, PWINDOW, "XWayland Window"); PWINDOW->hyprListener_commitWindow.initCallback(&PWINDOW->m_uSurface.xwayland->surface->events.commit, &Events::listener_commitWindow, PWINDOW, "XWayland Window"); + + PWINDOW->m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(PWINDOW), PWINDOW); } void Events::listener_dissociateX11(void* owner, void* data) { const auto PWINDOW = (CWindow*)owner; + PWINDOW->m_pWLSurface.unassign(); + PWINDOW->hyprListener_mapWindow.removeCallback(); PWINDOW->hyprListener_commitWindow.removeCallback(); } @@ -1219,8 +1223,6 @@ void Events::listener_surfaceXWayland(wl_listener* listener, void* data) { PNEWWINDOW->hyprListener_destroyWindow.initCallback(&XWSURFACE->events.destroy, &Events::listener_destroyWindow, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_setOverrideRedirect.initCallback(&XWSURFACE->events.set_override_redirect, &Events::listener_setOverrideRedirect, PNEWWINDOW, "XWayland Window"); PNEWWINDOW->hyprListener_configureX11.initCallback(&XWSURFACE->events.request_configure, &Events::listener_configureX11, PNEWWINDOW, "XWayland Window"); - - PNEWWINDOW->m_pWLSurface.assign(g_pXWaylandManager->getWindowSurface(PNEWWINDOW), PNEWWINDOW); } void Events::listener_newXDGToplevel(wl_listener* listener, void* data) { From 09e1128da29741ecdf193b3091afa54b061a915f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 02:21:28 +0000 Subject: [PATCH 0179/2897] cursormgr: initialize size to 0 Because the ctor expects that. Ref #5237 --- src/managers/CursorManager.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/CursorManager.hpp b/src/managers/CursorManager.hpp index 0e8d99bc..ff633592 100644 --- a/src/managers/CursorManager.hpp +++ b/src/managers/CursorManager.hpp @@ -55,7 +55,7 @@ class CCursorManager { std::unique_ptr m_pHyprcursor; std::string m_szTheme = ""; - int m_iSize = 24; + int m_iSize = 0; float m_fCursorScale = 1.0; Hyprcursor::SCursorStyleInfo m_sCurrentStyleInfo; From 86dc46ffea2fa72abe1228c1fad1b42d1507e45d Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 03:09:39 +0000 Subject: [PATCH 0180/2897] animationmgr: use realpos and size for border damage fixes #5239 --- src/managers/AnimationManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index a14bc195..93608383 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -245,7 +245,7 @@ void CAnimationManager::tick() { BORDERSIZE + ROUNDINGSIZE); // bottom // damage for new box - CBox WLRBOXNEW = PWINDOW->getFullWindowBoundingBox(); + CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value(), PWINDOW->m_vRealSize.value()}; const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); if (PWINDOWWORKSPACE) WLRBOXNEW.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); From acf15e5579a5d2bbbe4a13e87306445e31ea5e4f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 15:00:00 +0000 Subject: [PATCH 0181/2897] text-input: reset lock counter on surface destroy fixes #5231 --- src/managers/input/TextInput.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 827d4dbe..c42d4f1f 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -127,6 +127,8 @@ void CTextInput::setFocusedSurface(wlr_surface* pSurface) { [this](void* owner, void* data) { Debug::log(LOG, "Unmap TI owner1"); + if (enterLocks) + enterLocks--; pFocusedSurface = nullptr; hyprListener_surfaceUnmapped.removeCallback(); hyprListener_surfaceDestroyed.removeCallback(); @@ -138,6 +140,8 @@ void CTextInput::setFocusedSurface(wlr_surface* pSurface) { [this](void* owner, void* data) { Debug::log(LOG, "destroy TI owner1"); + if (enterLocks) + enterLocks--; pFocusedSurface = nullptr; hyprListener_surfaceUnmapped.removeCallback(); hyprListener_surfaceDestroyed.removeCallback(); From 5cc4bf699cfe4d5915b8ea9f2a7c8449cdc7bd2f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 16:08:25 +0000 Subject: [PATCH 0182/2897] IME: Refactor and fixup popups --- src/Compositor.cpp | 15 --- src/Compositor.hpp | 1 - src/events/Events.hpp | 6 - src/helpers/WLClasses.hpp | 20 --- src/managers/input/InputManager.cpp | 6 +- src/managers/input/InputMethodPopup.cpp | 168 ++++++++++++++++++++++++ src/managers/input/InputMethodPopup.hpp | 41 ++++++ src/managers/input/InputMethodRelay.cpp | 154 +++------------------- src/managers/input/InputMethodRelay.hpp | 21 +-- src/managers/input/TextInput.cpp | 4 +- src/render/Renderer.cpp | 20 +-- src/render/Renderer.hpp | 2 +- 12 files changed, 260 insertions(+), 198 deletions(-) create mode 100644 src/managers/input/InputMethodPopup.cpp create mode 100644 src/managers/input/InputMethodPopup.hpp diff --git a/src/Compositor.cpp b/src/Compositor.cpp index f8138825..9ae1adfb 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1163,21 +1163,6 @@ wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector< return nullptr; } -SIMEPopup* CCompositor::vectorToIMEPopup(const Vector2D& pos, std::list& popups) { - for (auto& popup : popups) { - auto surface = popup.pSurface->surface; - CBox box{ - popup.realX, - popup.realY, - surface->current.width, - surface->current.height, - }; - if (box.containsPoint(pos)) - return &popup; - } - return nullptr; -} - CWindow* CCompositor::getWindowFromSurface(wlr_surface* pSurface) { for (auto& w : m_vWindows) { if (!w->m_bIsMapped || w->m_bFadingOut) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index e226fdd3..df8de0c0 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -135,7 +135,6 @@ class CCompositor { bool monitorExists(CMonitor*); CWindow* vectorToWindowUnified(const Vector2D&, uint8_t properties, CWindow* pIgnoreWindow = nullptr); wlr_surface* vectorToLayerSurface(const Vector2D&, std::vector>*, Vector2D*, SLayerSurface**); - SIMEPopup* vectorToIMEPopup(const Vector2D& pos, std::list& popups); wlr_surface* vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl); Vector2D vectorToSurfaceLocal(const Vector2D&, CWindow*, wlr_surface*); CMonitor* getMonitorFromOutput(wlr_output*); diff --git a/src/events/Events.hpp b/src/events/Events.hpp index a105846e..9dbd75df 100644 --- a/src/events/Events.hpp +++ b/src/events/Events.hpp @@ -126,12 +126,6 @@ namespace Events { LISTENER(newTextInput); LISTENER(newVirtualKeyboard); - // IME Popups - DYNLISTENFUNC(mapInputPopup); - DYNLISTENFUNC(unmapInputPopup); - DYNLISTENFUNC(commitInputPopup); - DYNLISTENFUNC(destroyInputPopup); - // Touch LISTENER(touchBegin); LISTENER(touchEnd); diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index dbe8d389..7db656d8 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -298,26 +298,6 @@ struct SIMEKbGrab { DYNLISTENER(grabDestroy); }; -struct SIMEPopup { - wlr_input_popup_surface_v2* pSurface = nullptr; - - int x, y; - int realX, realY; - bool visible; - CBox lastBox; - - DYNLISTENER(mapPopup); - DYNLISTENER(unmapPopup); - DYNLISTENER(destroyPopup); - DYNLISTENER(commitPopup); - - DYNLISTENER(focusedSurfaceUnmap); - - bool operator==(const SIMEPopup& other) const { - return pSurface == other.pSurface; - } -}; - struct STouchDevice { wlr_input_device* pWlrDevice = nullptr; diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 94e6abec..9f38ab22 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -215,10 +215,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { // also IME popups if (!foundSurface) { - auto popup = g_pCompositor->vectorToIMEPopup(mouseCoords, m_sIMERelay.m_lIMEPopups); + auto popup = g_pInputManager->m_sIMERelay.popupFromCoords(mouseCoords); if (popup) { - foundSurface = popup->pSurface->surface; - surfacePos = Vector2D(popup->realX, popup->realY); + foundSurface = popup->getWlrSurface(); + surfacePos = popup->globalBox().pos(); } } diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp new file mode 100644 index 00000000..56fb2024 --- /dev/null +++ b/src/managers/input/InputMethodPopup.cpp @@ -0,0 +1,168 @@ +#include "InputMethodPopup.hpp" + +CInputPopup::CInputPopup(wlr_input_popup_surface_v2* surf) : pWlr(surf) { + surface.assign(surf->surface); + initCallbacks(); +} + +static void onCommit(void* owner, void* data) { + const auto PPOPUP = (CInputPopup*)owner; + PPOPUP->onCommit(); +} + +static void onMap(void* owner, void* data) { + const auto PPOPUP = (CInputPopup*)owner; + PPOPUP->onMap(); +} + +static void onUnmap(void* owner, void* data) { + const auto PPOPUP = (CInputPopup*)owner; + PPOPUP->onUnmap(); +} + +static void onDestroy(void* owner, void* data) { + const auto PPOPUP = (CInputPopup*)owner; + PPOPUP->onDestroy(); +} + +void CInputPopup::initCallbacks() { + hyprListener_commitPopup.initCallback(&pWlr->surface->events.commit, &::onCommit, this, "IME Popup"); + hyprListener_mapPopup.initCallback(&pWlr->surface->events.map, &::onMap, this, "IME Popup"); + hyprListener_unmapPopup.initCallback(&pWlr->surface->events.unmap, &::onUnmap, this, "IME Popup"); + hyprListener_destroyPopup.initCallback(&pWlr->events.destroy, &::onDestroy, this, "IME Popup"); +} + +CWLSurface* CInputPopup::queryOwner() { + const auto FOCUSED = g_pInputManager->m_sIMERelay.getFocusedTextInput(); + + if (!FOCUSED) + return nullptr; + + return CWLSurface::surfaceFromWlr(FOCUSED->focusedSurface()); +} + +void CInputPopup::onDestroy() { + hyprListener_commitPopup.removeCallback(); + hyprListener_destroyPopup.removeCallback(); + hyprListener_mapPopup.removeCallback(); + hyprListener_unmapPopup.removeCallback(); + + g_pInputManager->m_sIMERelay.removePopup(this); +} + +void CInputPopup::onMap() { + Debug::log(LOG, "Mapped an IME Popup"); + + updateBox(); + damageEntire(); +} + +void CInputPopup::onUnmap() { + Debug::log(LOG, "Unmapped an IME Popup"); + + damageEntire(); +} + +void CInputPopup::onCommit() { + updateBox(); +} + +void CInputPopup::damageEntire() { + const auto OWNER = queryOwner(); + + if (!OWNER) { + Debug::log(ERR, "BUG THIS: No owner in imepopup::damageentire"); + return; + } + + Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos(); + CBox global = lastBoxLocal.copy().translate(pos); + + g_pHyprRenderer->damageBox(&global); +} + +void CInputPopup::damageSurface() { + const auto OWNER = queryOwner(); + + if (!OWNER) { + Debug::log(ERR, "BUG THIS: No owner in imepopup::damagesurface"); + return; + } + + Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos(); + g_pHyprRenderer->damageSurface(surface.wlr(), pos.x, pos.y); +} + +void CInputPopup::updateBox() { + if (!surface.wlr()->mapped) + return; + + const auto OWNER = queryOwner(); + const auto PFOCUSEDTI = g_pInputManager->m_sIMERelay.getFocusedTextInput(); + + if (!PFOCUSEDTI) + return; + + bool cursorRect = PFOCUSEDTI->hasCursorRectangle(); + CBox cursorBoxLocal = PFOCUSEDTI->cursorBox(); + + CBox parentBox; + + if (!OWNER) + parentBox = {0, 0, 500, 500}; + else + parentBox = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}); + + if (!cursorRect) { + Vector2D coords = OWNER ? OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 500, 500}).pos() : Vector2D{0, 0}; + parentBox = {coords, {500, 500}}; + cursorBoxLocal = {0, 0, (int)parentBox.w, (int)parentBox.h}; + } + + if (cursorBoxLocal != lastBoxLocal) + damageEntire(); + + CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle()); + + if (cursorBoxLocal.y + parentBox.y + surface.wlr()->current.height + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) + cursorBoxLocal.y -= surface.wlr()->current.height + cursorBoxLocal.height; + + if (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) + cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); + + lastBoxLocal = cursorBoxLocal; + + wlr_input_popup_surface_v2_send_text_input_rectangle(pWlr, cursorBoxLocal.pWlr()); + + damageSurface(); + + if (const auto PM = g_pCompositor->getMonitorFromCursor(); PM && PM->ID != lastMonitor) { + const auto PML = g_pCompositor->getMonitorFromID(lastMonitor); + + if (PML) + wlr_surface_send_leave(surface.wlr(), PML->output); + + wlr_surface_send_enter(surface.wlr(), PM->output); + + lastMonitor = PM->ID; + } +} + +CBox CInputPopup::globalBox() { + const auto OWNER = queryOwner(); + + if (!OWNER) { + Debug::log(ERR, "BUG THIS: No owner in imepopup::globalbox"); + return {}; + } + + return lastBoxLocal.copy().translate(OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos()); +} + +bool CInputPopup::isVecInPopup(const Vector2D& point) { + return globalBox().containsPoint(point); +} + +wlr_surface* CInputPopup::getWlrSurface() { + return surface.wlr(); +} diff --git a/src/managers/input/InputMethodPopup.hpp b/src/managers/input/InputMethodPopup.hpp new file mode 100644 index 00000000..8bcf1101 --- /dev/null +++ b/src/managers/input/InputMethodPopup.hpp @@ -0,0 +1,41 @@ +#pragma once + +#include "../../helpers/WLListener.hpp" +#include "../../desktop/WLSurface.hpp" +#include "../../macros.hpp" +#include "../../helpers/Box.hpp" + +struct wlr_input_popup_surface_v2; + +class CInputPopup { + public: + CInputPopup(wlr_input_popup_surface_v2* surf); + + void onDestroy(); + void onMap(); + void onUnmap(); + void onCommit(); + + void damageEntire(); + void damageSurface(); + + bool isVecInPopup(const Vector2D& point); + + CBox globalBox(); + wlr_surface* getWlrSurface(); + + private: + void initCallbacks(); + CWLSurface* queryOwner(); + void updateBox(); + + wlr_input_popup_surface_v2* pWlr = nullptr; + CWLSurface surface; + CBox lastBoxLocal; + uint64_t lastMonitor = -1; + + DYNLISTENER(mapPopup); + DYNLISTENER(unmapPopup); + DYNLISTENER(destroyPopup); + DYNLISTENER(commitPopup); +}; \ No newline at end of file diff --git a/src/managers/input/InputMethodRelay.cpp b/src/managers/input/InputMethodRelay.cpp index 13e4c9df..2bd98a79 100644 --- a/src/managers/input/InputMethodRelay.cpp +++ b/src/managers/input/InputMethodRelay.cpp @@ -86,14 +86,7 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { hyprListener_IMENewPopup.initCallback( &m_pWLRIME->events.new_popup_surface, [&](void* owner, void* data) { - const auto PNEWPOPUP = &m_lIMEPopups.emplace_back(); - - PNEWPOPUP->pSurface = (wlr_input_popup_surface_v2*)data; - - PNEWPOPUP->hyprListener_commitPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.commit, &Events::listener_commitInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_mapPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.map, &Events::listener_mapInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_unmapPopup.initCallback(&PNEWPOPUP->pSurface->surface->events.unmap, &Events::listener_unmapInputPopup, PNEWPOPUP, "IME Popup"); - PNEWPOPUP->hyprListener_destroyPopup.initCallback(&PNEWPOPUP->pSurface->events.destroy, &Events::listener_destroyInputPopup, PNEWPOPUP, "IME Popup"); + m_vIMEPopups.emplace_back(std::make_unique((wlr_input_popup_surface_v2*)data)); Debug::log(LOG, "New input popup"); }, @@ -103,132 +96,12 @@ void CInputMethodRelay::onNewIME(wlr_input_method_v2* pIME) { PTI->enter(PTI->focusedSurface()); } -void CInputMethodRelay::updateInputPopup(SIMEPopup* pPopup) { - if (!pPopup->pSurface->surface->mapped) - return; - - // damage last known pos & size - g_pHyprRenderer->damageBox(&pPopup->lastBox); - - const auto PFOCUSEDTI = getFocusedTextInput(); - - if (!PFOCUSEDTI || !PFOCUSEDTI->focusedSurface()) - return; - - bool cursorRect = PFOCUSEDTI->hasCursorRectangle(); - const auto PFOCUSEDSURFACE = PFOCUSEDTI->focusedSurface(); - CBox cursorBox = PFOCUSEDTI->cursorBox(); - - CBox parentBox; - - const auto PSURFACE = CWLSurface::surfaceFromWlr(PFOCUSEDSURFACE); - - if (!PSURFACE) - parentBox = {0, 0, 200, 200}; - else - parentBox = PSURFACE->getSurfaceBoxGlobal().value_or(CBox{0, 0, 200, 200}); - - if (!cursorRect) - cursorBox = {0, 0, (int)parentBox.w, (int)parentBox.h}; - - CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(cursorBox.middle()); - - if (cursorBox.y + parentBox.y + pPopup->pSurface->surface->current.height + cursorBox.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) - cursorBox.y -= pPopup->pSurface->surface->current.height + cursorBox.height; - - if (cursorBox.x + parentBox.x + pPopup->pSurface->surface->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) - cursorBox.x -= (cursorBox.x + parentBox.x + pPopup->pSurface->surface->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); - - pPopup->x = cursorBox.x; - pPopup->y = cursorBox.y + cursorBox.height; - - pPopup->realX = cursorBox.x + parentBox.x; - pPopup->realY = cursorBox.y + parentBox.y + cursorBox.height; - - pPopup->lastBox = cursorBox; - - wlr_input_popup_surface_v2_send_text_input_rectangle(pPopup->pSurface, cursorBox.pWlr()); - - damagePopup(pPopup); +void CInputMethodRelay::setIMEPopupFocus(CInputPopup* pPopup, wlr_surface* pSurface) { + pPopup->onCommit(); } -void CInputMethodRelay::setIMEPopupFocus(SIMEPopup* pPopup, wlr_surface* pSurface) { - updateInputPopup(pPopup); -} - -void Events::listener_mapInputPopup(void* owner, void* data) { - const auto PPOPUP = (SIMEPopup*)owner; - - Debug::log(LOG, "Mapped an IME Popup"); - - g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP); - - if (const auto PMONITOR = g_pCompositor->getMonitorFromVector(PPOPUP->lastBox.middle()); PMONITOR) - wlr_surface_send_enter(PPOPUP->pSurface->surface, PMONITOR->output); -} - -void Events::listener_unmapInputPopup(void* owner, void* data) { - const auto PPOPUP = (SIMEPopup*)owner; - - Debug::log(LOG, "Unmapped an IME Popup"); - - g_pHyprRenderer->damageBox(&PPOPUP->lastBox); - - g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP); -} - -void Events::listener_destroyInputPopup(void* owner, void* data) { - const auto PPOPUP = (SIMEPopup*)owner; - - Debug::log(LOG, "Removed an IME Popup"); - - PPOPUP->hyprListener_commitPopup.removeCallback(); - PPOPUP->hyprListener_destroyPopup.removeCallback(); - PPOPUP->hyprListener_focusedSurfaceUnmap.removeCallback(); - PPOPUP->hyprListener_mapPopup.removeCallback(); - PPOPUP->hyprListener_unmapPopup.removeCallback(); - - g_pInputManager->m_sIMERelay.removePopup(PPOPUP); -} - -void Events::listener_commitInputPopup(void* owner, void* data) { - const auto PPOPUP = (SIMEPopup*)owner; - - g_pInputManager->m_sIMERelay.updateInputPopup(PPOPUP); -} - -void CInputMethodRelay::removePopup(SIMEPopup* pPopup) { - m_lIMEPopups.remove(*pPopup); -} - -void CInputMethodRelay::damagePopup(SIMEPopup* pPopup) { - if (!pPopup->pSurface->surface->mapped) - return; - - const auto PFOCUSEDTI = getFocusedTextInput(); - - if (!PFOCUSEDTI || !PFOCUSEDTI->focusedSurface()) - return; - - Vector2D parentPos; - - const auto PFOCUSEDSURFACE = PFOCUSEDTI->focusedSurface(); - - if (wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)) { - const auto PLS = g_pCompositor->getLayerSurfaceFromWlr(wlr_layer_surface_v1_try_from_wlr_surface(PFOCUSEDSURFACE)); - - if (PLS) { - parentPos = Vector2D(PLS->geometry.x, PLS->geometry.y) + g_pCompositor->getMonitorFromID(PLS->monitorID)->vecPosition; - } - } else { - const auto PWINDOW = g_pCompositor->getWindowFromSurface(PFOCUSEDSURFACE); - - if (PWINDOW) { - parentPos = PWINDOW->m_vRealPosition.goal(); - } - } - - g_pHyprRenderer->damageSurface(pPopup->pSurface->surface, parentPos.x + pPopup->x, parentPos.y + pPopup->y); +void CInputMethodRelay::removePopup(CInputPopup* pPopup) { + std::erase_if(m_vIMEPopups, [pPopup](const auto& other) { return other.get() == pPopup; }); } SIMEKbGrab* CInputMethodRelay::getIMEKeyboardGrab(SKeyboard* pKeyboard) { @@ -268,7 +141,13 @@ void CInputMethodRelay::onNewTextInput(STextInputV1* pTIV1) { } void CInputMethodRelay::removeTextInput(CTextInput* pInput) { - m_vTextInputs.remove_if([&](const auto& other) { return other.get() == pInput; }); + std::erase_if(m_vTextInputs, [pInput](const auto& other) { return other.get() == pInput; }); +} + +void CInputMethodRelay::updateAllPopups() { + for (auto& p : m_vIMEPopups) { + p->onCommit(); + } } void CInputMethodRelay::commitIMEState(CTextInput* pInput) { @@ -304,3 +183,12 @@ void CInputMethodRelay::onKeyboardFocus(wlr_surface* pSurface) { ti->enter(pSurface); } } + +CInputPopup* CInputMethodRelay::popupFromCoords(const Vector2D& point) { + for (auto& p : m_vIMEPopups) { + if (p->isVecInPopup(point)) + return p.get(); + } + + return nullptr; +} diff --git a/src/managers/input/InputMethodRelay.hpp b/src/managers/input/InputMethodRelay.hpp index 7618400f..f19b4bb5 100644 --- a/src/managers/input/InputMethodRelay.hpp +++ b/src/managers/input/InputMethodRelay.hpp @@ -4,8 +4,10 @@ #include "../../defines.hpp" #include "../../helpers/WLClasses.hpp" #include "TextInput.hpp" +#include "InputMethodPopup.hpp" class CInputManager; +class CHyprRenderer; struct STextInputV1; class CInputMethodRelay { @@ -27,18 +29,20 @@ class CInputMethodRelay { SIMEKbGrab* getIMEKeyboardGrab(SKeyboard*); - void setIMEPopupFocus(SIMEPopup*, wlr_surface*); - void updateInputPopup(SIMEPopup*); - void damagePopup(SIMEPopup*); - void removePopup(SIMEPopup*); + void setIMEPopupFocus(CInputPopup*, wlr_surface*); + void removePopup(CInputPopup*); + + CInputPopup* popupFromCoords(const Vector2D& point); + + void updateAllPopups(); private: - std::unique_ptr m_pKeyboardGrab; + std::unique_ptr m_pKeyboardGrab; - std::list> m_vTextInputs; - std::list m_lIMEPopups; + std::vector> m_vTextInputs; + std::vector> m_vIMEPopups; - wlr_surface* m_pLastKbFocus = nullptr; + wlr_surface* m_pLastKbFocus = nullptr; DYNLISTENER(textInputNew); DYNLISTENER(IMECommit); @@ -50,4 +54,5 @@ class CInputMethodRelay { friend class CInputManager; friend class CTextInputV1ProtocolManager; friend struct CTextInput; + friend class CHyprRenderer; }; diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index c42d4f1f..0e642f82 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -222,9 +222,7 @@ void CTextInput::commitStateToIME(wlr_input_method_v2* ime) { wlr_input_method_v2_send_content_type(ime, pV1Input->pendingContentType.hint, pV1Input->pendingContentType.purpose); } - for (auto& p : g_pInputManager->m_sIMERelay.m_lIMEPopups) { - g_pInputManager->m_sIMERelay.updateInputPopup(&p); - } + g_pInputManager->m_sIMERelay.updateAllPopups(); wlr_input_method_v2_send_done(ime); } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 7f83c429..a3112c1e 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -679,16 +679,20 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times g_pHyprOpenGL->m_RenderData.clipBox = {}; } -void CHyprRenderer::renderIMEPopup(SIMEPopup* pPopup, CMonitor* pMonitor, timespec* time) { - SRenderData renderdata = {pMonitor, time, pPopup->realX, pPopup->realY}; +void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, CMonitor* pMonitor, timespec* time) { + const auto POS = pPopup->globalBox().pos(); + + SRenderData renderdata = {pMonitor, time, POS.x, POS.y}; + + const auto SURF = pPopup->getWlrSurface(); renderdata.blur = false; - renderdata.surface = pPopup->pSurface->surface; + renderdata.surface = SURF; renderdata.decorate = false; - renderdata.w = pPopup->pSurface->surface->current.width; - renderdata.h = pPopup->pSurface->surface->current.height; + renderdata.w = SURF->current.width; + renderdata.h = SURF->current.height; - wlr_surface_for_each_surface(pPopup->pSurface->surface, renderSurface, &renderdata); + wlr_surface_for_each_surface(SURF, renderSurface, &renderdata); } void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMonitor* pMonitor, timespec* time) { @@ -830,8 +834,8 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* } // Render IME popups - for (auto& imep : g_pInputManager->m_sIMERelay.m_lIMEPopups) { - renderIMEPopup(&imep, pMonitor, time); + for (auto& imep : g_pInputManager->m_sIMERelay.m_vIMEPopups) { + renderIMEPopup(imep.get(), pMonitor, time); } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index fd41a566..1c6628f1 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -115,7 +115,7 @@ class CHyprRenderer { void renderLayer(SLayerSurface*, CMonitor*, timespec*); void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderDragIcon(CMonitor*, timespec*); - void renderIMEPopup(SIMEPopup*, CMonitor*, timespec*); + void renderIMEPopup(CInputPopup*, CMonitor*, timespec*); void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry); void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); From 1e82d5a04d0ab75ea1d9aa763d28c1767d58e898 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 17:19:35 +0000 Subject: [PATCH 0183/2897] ime: fix build without pch --- src/managers/input/InputMethodPopup.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 56fb2024..326b982e 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -1,4 +1,6 @@ #include "InputMethodPopup.hpp" +#include "InputManager.hpp" +#include "../../Compositor.hpp" CInputPopup::CInputPopup(wlr_input_popup_surface_v2* surf) : pWlr(surf) { surface.assign(surf->surface); From 294ff8609f80b8e9d16233de94e49f992d5de33a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 19:39:56 +0000 Subject: [PATCH 0184/2897] cursormgr: log theme loading failures --- src/managers/CursorManager.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index c4b624d4..ae258916 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -15,6 +15,9 @@ static int cursorAnimTimer(void* data) { CCursorManager::CCursorManager() { m_pHyprcursor = std::make_unique(m_szTheme.empty() ? nullptr : m_szTheme.c_str()); + if (!m_pHyprcursor->valid()) + Debug::log(ERR, "Hyprcursor failed loading theme \"{}\", falling back to X.", m_szTheme); + // find default size. First, HYPRCURSOR_SIZE, then XCURSOR_SIZE, then 24 auto SIZE = getenv("HYPRCURSOR_SIZE"); if (SIZE) { @@ -224,6 +227,9 @@ void CCursorManager::changeTheme(const std::string& name, const int size) { m_szTheme = name; m_iSize = size; + if (!m_pHyprcursor->valid()) + Debug::log(ERR, "Hyprcursor failed loading theme \"{}\", falling back to X.", m_szTheme); + setenv("XCURSOR_SIZE", std::to_string(m_iSize).c_str(), true); setenv("XCURSOR_THEME", name.c_str(), true); From 03e99f93ae3c98284bd9d489de490bca2b11824c Mon Sep 17 00:00:00 2001 From: Brett Alcox Date: Sun, 24 Mar 2024 15:38:10 -0500 Subject: [PATCH 0185/2897] renderer: forward decl for b_pch=false (#5250) --- src/render/Renderer.hpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 1c6628f1..011b17b9 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -11,6 +11,7 @@ struct SMonitorRule; class CWorkspace; class CWindow; +class CInputPopup; // TODO: add fuller damage tracking for updating only parts of a window enum DAMAGETRACKINGMODES { From 89543e8e3cb7d3d3e1755649779c3835bd5c5fd9 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 24 Mar 2024 20:47:09 +0000 Subject: [PATCH 0186/2897] cursormgr: don't set x theme in changeTheme --- src/managers/CursorManager.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/managers/CursorManager.cpp b/src/managers/CursorManager.cpp index ae258916..6c481cea 100644 --- a/src/managers/CursorManager.cpp +++ b/src/managers/CursorManager.cpp @@ -230,8 +230,5 @@ void CCursorManager::changeTheme(const std::string& name, const int size) { if (!m_pHyprcursor->valid()) Debug::log(ERR, "Hyprcursor failed loading theme \"{}\", falling back to X.", m_szTheme); - setenv("XCURSOR_SIZE", std::to_string(m_iSize).c_str(), true); - setenv("XCURSOR_THEME", name.c_str(), true); - updateTheme(); } From 8001b96bb5f801ea665fd482ba421e8703d986e7 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:41:56 -0700 Subject: [PATCH 0187/2897] renderer: dont render fullscreen special on wrong monitor (#5249) --- src/render/Renderer.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index a3112c1e..2059be0a 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -328,7 +328,8 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) continue; - renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL); + if (shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL); if (w->m_iWorkspaceID != pWorkspace->m_iID) continue; From 6b28bf563e3b4e5f6631985f24c88e8a8ebaa0d4 Mon Sep 17 00:00:00 2001 From: dmayle Date: Sun, 24 Mar 2024 18:46:59 -0700 Subject: [PATCH 0188/2897] keybinds: Fix exit trigger by moving it to monitor.frame (#5240) --- src/Compositor.hpp | 1 + src/events/Monitors.cpp | 7 +++++++ src/managers/KeybindManager.cpp | 2 +- src/managers/input/InputManager.cpp | 3 --- src/managers/input/InputManager.hpp | 2 -- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index df8de0c0..64cd6e43 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -118,6 +118,7 @@ class CCompositor { bool m_bUnsafeState = false; // unsafe state is when there is no monitors. bool m_bNextIsUnsafe = false; // because wlroots CMonitor* m_pUnsafeOutput = nullptr; // fallback output for the unsafe state + bool m_bExitTriggered = false; // For exit dispatcher bool m_bIsShuttingDown = false; // ------------------------------------------------- // diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index e235096b..a6fd5a4a 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -117,6 +117,13 @@ void Events::listener_newOutput(wl_listener* listener, void* data) { } void Events::listener_monitorFrame(void* owner, void* data) { + if (g_pCompositor->m_bExitTriggered) { + // Only signal cleanup once + g_pCompositor->m_bExitTriggered = false; + g_pCompositor->cleanup(); + return; + } + CMonitor* const PMONITOR = (CMonitor*)owner; if ((g_pCompositor->m_sWLRSession && !g_pCompositor->m_sWLRSession->active) || !g_pCompositor->m_bSessionActive || g_pCompositor->m_bUnsafeState) { diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 8a1d022b..a8d390fa 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1512,7 +1512,7 @@ void CKeybindManager::renameWorkspace(std::string args) { } void CKeybindManager::exitHyprland(std::string argz) { - g_pInputManager->m_bExitTriggered = true; + g_pCompositor->m_bExitTriggered = true; } void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 9f38ab22..94245587 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -1189,9 +1189,6 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar updateKeyboardsLeds(pKeyboard->keyboard); } - - if (m_bExitTriggered) - g_pCompositor->cleanup(); } void CInputManager::onKeyboardMod(void* data, SKeyboard* pKeyboard) { diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp index 128badfc..a89981f3 100644 --- a/src/managers/input/InputManager.hpp +++ b/src/managers/input/InputManager.hpp @@ -251,8 +251,6 @@ class CInputManager { void restoreCursorIconToApp(); // no-op if restored - bool m_bExitTriggered = false; // for exit dispatcher - friend class CKeybindManager; friend class CWLSurface; }; From 356414639fc06ace7045236ec41d673342981057 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 24 Mar 2024 18:50:41 -0700 Subject: [PATCH 0189/2897] core: fix missing workspace events during swapping (#5251) --- src/Compositor.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 9ae1adfb..bf6c4200 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2053,6 +2053,11 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) const auto LASTWIN = pMonitorA->ID == g_pCompositor->m_pLastMonitor->ID ? PWORKSPACEB->getLastFocusedWindow() : PWORKSPACEA->getLastFocusedWindow(); g_pCompositor->focusWindow(LASTWIN ? LASTWIN : (g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING))); + + const auto PNEWWORKSPACE = pMonitorA->ID == g_pCompositor->m_pLastMonitor->ID ? PWORKSPACEB : PWORKSPACEA; + g_pEventManager->postEvent(SHyprIPCEvent{"workspace", PNEWWORKSPACE->m_szName}); + g_pEventManager->postEvent(SHyprIPCEvent{"workspacev2", std::format("{},{}", PNEWWORKSPACE->m_iID, PNEWWORKSPACE->m_szName)}); + EMIT_HOOK_EVENT("workspace", PNEWWORKSPACE); } // event From ca17a89d86b73f37019c4cc0c7087303adbcc1f9 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 25 Mar 2024 16:08:55 +0000 Subject: [PATCH 0190/2897] renderer: allow blurring ls popups --- src/config/ConfigManager.cpp | 3 ++- src/desktop/Popup.cpp | 9 +++++++ src/desktop/Window.cpp | 10 +++++++ src/desktop/Window.hpp | 1 + src/helpers/WLClasses.cpp | 9 +++++++ src/helpers/WLClasses.hpp | 2 ++ src/render/OpenGL.cpp | 21 ++++++++++++++- src/render/Renderer.cpp | 52 ++++++++++++++++++++++-------------- 8 files changed, 85 insertions(+), 22 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 11159131..d13b871d 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -1906,7 +1906,8 @@ bool windowRuleValid(const std::string& RULE) { } bool layerRuleValid(const std::string& RULE) { - return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray") || RULE.starts_with("animation"); + return RULE == "noanim" || RULE == "blur" || RULE == "blurpopups" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray") || + RULE.starts_with("animation"); } std::optional CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 98d5881a..77e486fd 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -117,6 +117,9 @@ void CPopup::onMap() { unconstrain(); sendScale(); + + if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); } void CPopup::onUnmap() { @@ -131,6 +134,9 @@ void CPopup::onUnmap() { m_pSubsurfaceHead.reset(); g_pInputManager->simulateMouseMovement(); + + if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); } void CPopup::onCommit(bool ignoreSiblings) { @@ -158,6 +164,9 @@ void CPopup::onCommit(bool ignoreSiblings) { g_pHyprRenderer->damageSurface(m_sWLSurface.wlr(), COORDS.x, COORDS.y); m_bRequestedReposition = false; + + if (m_pLayerOwner && m_pLayerOwner->layer < ZWLR_LAYER_SHELL_V1_LAYER_TOP) + g_pHyprOpenGL->markBlurDirtyForMonitor(g_pCompositor->getMonitorFromID(m_pLayerOwner->layer)); } void CPopup::onReposition() { diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 3145000c..9151d57e 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1151,3 +1151,13 @@ void CWindow::setAnimationsToMove() { m_vRealSize.setConfig(PANIMCFG); m_bAnimatingIn = false; } + +int CWindow::popupsCount() { + if (m_bIsX11) + return 1; + + int no = 0; + wlr_xdg_surface_for_each_popup_surface( + m_uSurface.xdg, [](wlr_surface* s, int x, int y, void* data) { *(int*)data += 1; }, &no); + return no; +} diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index 3ec8a54c..d8b4012d 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -404,6 +404,7 @@ class CWindow { void onBorderAngleAnimEnd(void* ptr); bool isInCurvedCorner(double x, double y); bool hasPopupAt(const Vector2D& pos); + int popupsCount(); void applyGroupRules(); void createGroup(); diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index d46f7e40..e7ae69c0 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -37,6 +37,8 @@ void SLayerSurface::applyRules() { noAnimations = true; else if (rule.rule == "blur") forceBlur = true; + else if (rule.rule == "blurpopups") + forceBlurPopups = true; else if (rule.rule.starts_with("ignorealpha") || rule.rule.starts_with("ignorezero")) { const auto FIRST_SPACE_POS = rule.rule.find_first_of(' '); std::string alphaValue = ""; @@ -168,6 +170,13 @@ bool SLayerSurface::isFadedOut() { return !realPosition.isBeingAnimated() && !realSize.isBeingAnimated() && !alpha.isBeingAnimated(); } +int SLayerSurface::popupsCount() { + int no = 0; + wlr_layer_surface_v1_for_each_popup_surface( + layerSurface, [](wlr_surface* s, int x, int y, void* data) { *(int*)data += 1; }, &no); + return no; +} + void SKeyboard::updateXKBTranslationState(xkb_keymap* const keymap) { xkb_state_unref(xkbTranslationState); diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index 7db656d8..f1311e42 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -22,6 +22,7 @@ struct SLayerSurface { void applyRules(); void startAnimation(bool in, bool instant = false); bool isFadedOut(); + int popupsCount(); CAnimatedVariable realPosition; CAnimatedVariable realSize; @@ -58,6 +59,7 @@ struct SLayerSurface { bool noAnimations = false; bool forceBlur = false; + bool forceBlurPopups = false; int xray = -1; bool ignoreAlpha = false; float ignoreAlphaValue = 0.f; diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index df03e8e9..f5cf2624 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -147,6 +147,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { static auto PXRAY = CConfigValue("decoration:blur:xray"); static auto POPTIM = CConfigValue("decoration:blur:new_optimizations"); static auto PBLURSPECIAL = CConfigValue("decoration:blur:special"); + static auto PBLURPOPUPS = CConfigValue("decoration:blur:popups"); if (m_RenderData.mouseZoomFactor != 1.0 || g_pHyprRenderer->m_bCrashingInProgress) return true; @@ -167,23 +168,35 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { const auto XRAYMODE = ls->xray == -1 ? *PXRAY : ls->xray; if (ls->forceBlur && !XRAYMODE) return true; + + if (ls->popupsCount() > 0 && ls->forceBlurPopups) + return true; } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { const auto XRAYMODE = ls->xray == -1 ? *PXRAY : ls->xray; if (ls->forceBlur && !XRAYMODE) return true; + + if (ls->popupsCount() > 0 && ls->forceBlurPopups) + return true; } // these two block optimization for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { if (ls->forceBlur) return true; + + if (ls->popupsCount() > 0 && ls->forceBlurPopups) + return true; } for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { if (ls->forceBlur) return true; + + if (ls->popupsCount() > 0 && ls->forceBlurPopups) + return true; } if (*PBLURSPECIAL) { @@ -202,12 +215,18 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { return false; for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || (!w->m_bIsFloating && *POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID))) + if (!w->m_bIsMapped || w->isHidden()) continue; if (!g_pHyprRenderer->shouldRenderWindow(w.get())) continue; + if (w->popupsCount() > 0 && *PBLURPOPUPS) + return true; + + if (!w->m_bIsFloating && *POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + continue; + if (w->m_sAdditionalConfigData.forceNoBlur.toUnderlying() == true || w->m_sAdditionalConfigData.xray.toUnderlying() == true) continue; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 2059be0a..3e8b277f 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -55,12 +55,9 @@ CHyprRenderer::CHyprRenderer() { } static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { - static auto PBLURPOPUPS = CConfigValue("decoration:blur:popups"); - static auto PBLURPOPUPSIGNOREALPHA = CConfigValue("decoration:blur:popups_ignorealpha"); - - const auto TEXTURE = wlr_surface_get_texture(surface); - const auto RDATA = (SRenderData*)data; - const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE; + const auto TEXTURE = wlr_surface_get_texture(surface); + const auto RDATA = (SRenderData*)data; + const auto INTERACTIVERESIZEINPROGRESS = RDATA->pWindow && g_pInputManager->currentlyDraggedWindow == RDATA->pWindow && g_pInputManager->dragMode == MBIND_RESIZE; if (!TEXTURE) return; @@ -168,16 +165,9 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, rounding, true); } } else { - if (RDATA->blur && RDATA->popup && *PBLURPOPUPS) { - - if (*PBLURPOPUPSIGNOREALPHA != 1.f) { - g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; - g_pHyprOpenGL->m_RenderData.discardOpacity = *PBLURPOPUPSIGNOREALPHA; - } - - g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, surface, rounding, true); - g_pHyprOpenGL->m_RenderData.discardMode &= ~DISCARD_ALPHA; - } else + if (RDATA->blur && RDATA->popup) + g_pHyprOpenGL->renderTextureWithBlur(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, surface, rounding, true, RDATA->fadeAlpha); + else g_pHyprOpenGL->renderTexture(TEXTURE, &windowBox, RDATA->fadeAlpha * RDATA->alpha, rounding, true); } @@ -616,12 +606,28 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* renderdata.squishOversized = false; // don't squish popups renderdata.popup = true; + static CConfigValue PBLURPOPUPS = CConfigValue("decoration:blur:popups"); + static CConfigValue PBLURIGNOREA = CConfigValue("decoration:blur:popups_ignorealpha"); + + renderdata.blur = *PBLURPOPUPS; + + const auto DM = g_pHyprOpenGL->m_RenderData.discardMode; + const auto DA = g_pHyprOpenGL->m_RenderData.discardOpacity; + + if (renderdata.blur) { + g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; + g_pHyprOpenGL->m_RenderData.discardOpacity = *PBLURIGNOREA; + } + if (pWindow->m_sAdditionalConfigData.nearestNeighbor.toUnderlying()) g_pHyprOpenGL->m_RenderData.useNearestNeighbor = true; wlr_xdg_surface_for_each_popup_surface(pWindow->m_uSurface.xdg, renderSurface, &renderdata); g_pHyprOpenGL->m_RenderData.useNearestNeighbor = false; + + g_pHyprOpenGL->m_RenderData.discardMode = DM; + g_pHyprOpenGL->m_RenderData.discardOpacity = DA; } if (decorate) { @@ -664,20 +670,26 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times g_pHyprOpenGL->m_pCurrentLayer = pLayer; - if (pLayer->ignoreAlpha) { + const auto DM = g_pHyprOpenGL->m_RenderData.discardMode; + const auto DA = g_pHyprOpenGL->m_RenderData.discardOpacity; + + if (renderdata.blur && pLayer->ignoreAlpha) { g_pHyprOpenGL->m_RenderData.discardMode |= DISCARD_ALPHA; g_pHyprOpenGL->m_RenderData.discardOpacity = pLayer->ignoreAlphaValue; } + wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata); - g_pHyprOpenGL->m_RenderData.discardMode &= ~DISCARD_ALPHA; renderdata.squishOversized = false; // don't squish popups renderdata.dontRound = true; renderdata.popup = true; + renderdata.blur = pLayer->forceBlurPopups; wlr_layer_surface_v1_for_each_popup_surface(pLayer->layerSurface, renderSurface, &renderdata); - g_pHyprOpenGL->m_pCurrentLayer = nullptr; - g_pHyprOpenGL->m_RenderData.clipBox = {}; + g_pHyprOpenGL->m_pCurrentLayer = nullptr; + g_pHyprOpenGL->m_RenderData.clipBox = {}; + g_pHyprOpenGL->m_RenderData.discardMode = DM; + g_pHyprOpenGL->m_RenderData.discardOpacity = DA; } void CHyprRenderer::renderIMEPopup(CInputPopup* pPopup, CMonitor* pMonitor, timespec* time) { From ae17e900e720430c7848faf1b6e21b5f352c26ca Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 25 Mar 2024 16:20:30 +0000 Subject: [PATCH 0191/2897] layer-shell: render popups above everything --- src/Compositor.cpp | 23 ++++++++++++++++++++++- src/Compositor.hpp | 3 ++- src/helpers/WLClasses.cpp | 3 +++ src/managers/input/InputManager.cpp | 3 +++ src/render/Renderer.cpp | 14 +++++++++++--- src/render/Renderer.hpp | 2 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index bf6c4200..2d6e7856 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1143,13 +1143,34 @@ bool CCompositor::windowValidMapped(CWindow* pWindow) { return true; } +wlr_surface* CCompositor::vectorToLayerPopupSurface(const Vector2D& pos, CMonitor* monitor, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) { + for (auto& lsl : monitor->m_aLayerSurfaceLayers | std::views::reverse) { + for (auto& ls : lsl | std::views::reverse) { + if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->surface->mapped) || ls->alpha.value() == 0.f) + continue; + + auto SURFACEAT = wlr_layer_surface_v1_popup_surface_at(ls->layerSurface, pos.x - ls->geometry.x, pos.y - ls->geometry.y, &sCoords->x, &sCoords->y); + + if (SURFACEAT) { + if (!pixman_region32_not_empty(&SURFACEAT->input_region)) + continue; + + *ppLayerSurfaceFound = ls.get(); + return SURFACEAT; + } + } + } + + return nullptr; +} + wlr_surface* CCompositor::vectorToLayerSurface(const Vector2D& pos, std::vector>* layerSurfaces, Vector2D* sCoords, SLayerSurface** ppLayerSurfaceFound) { for (auto& ls : *layerSurfaces | std::views::reverse) { if (ls->fadingOut || !ls->layerSurface || (ls->layerSurface && !ls->layerSurface->surface->mapped) || ls->alpha.value() == 0.f) continue; - auto SURFACEAT = wlr_layer_surface_v1_surface_at(ls->layerSurface, pos.x - ls->geometry.x, pos.y - ls->geometry.y, &sCoords->x, &sCoords->y); + auto SURFACEAT = wlr_surface_surface_at(ls->layerSurface->surface, pos.x - ls->geometry.x, pos.y - ls->geometry.y, &sCoords->x, &sCoords->y); if (SURFACEAT) { if (!pixman_region32_not_empty(&SURFACEAT->input_region)) diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 64cd6e43..ace2a388 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -118,7 +118,7 @@ class CCompositor { bool m_bUnsafeState = false; // unsafe state is when there is no monitors. bool m_bNextIsUnsafe = false; // because wlroots CMonitor* m_pUnsafeOutput = nullptr; // fallback output for the unsafe state - bool m_bExitTriggered = false; // For exit dispatcher + bool m_bExitTriggered = false; // For exit dispatcher bool m_bIsShuttingDown = false; // ------------------------------------------------- // @@ -136,6 +136,7 @@ class CCompositor { bool monitorExists(CMonitor*); CWindow* vectorToWindowUnified(const Vector2D&, uint8_t properties, CWindow* pIgnoreWindow = nullptr); wlr_surface* vectorToLayerSurface(const Vector2D&, std::vector>*, Vector2D*, SLayerSurface**); + wlr_surface* vectorToLayerPopupSurface(const Vector2D&, CMonitor* monitor, Vector2D*, SLayerSurface**); wlr_surface* vectorWindowToSurface(const Vector2D&, CWindow*, Vector2D& sl); Vector2D vectorToSurfaceLocal(const Vector2D&, CWindow*, wlr_surface*); CMonitor* getMonitorFromOutput(wlr_output*); diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index e7ae69c0..5e18c274 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -171,6 +171,9 @@ bool SLayerSurface::isFadedOut() { } int SLayerSurface::popupsCount() { + if (!layerSurface || !mapped || fadingOut) + return 0; + int no = 0; wlr_layer_surface_v1_for_each_popup_surface( layerSurface, [](wlr_surface* s, int x, int y, void* data) { *(int*)data += 1; }, &no); diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 94245587..690463fa 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -209,6 +209,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { surfacePos = PMONITOR->vecPosition; } + if (!foundSurface) + foundSurface = g_pCompositor->vectorToLayerPopupSurface(mouseCoords, PMONITOR, &surfaceCoords, &pFoundLayerSurface); + // overlays are above fullscreen if (!foundSurface) foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY], &surfaceCoords, &pFoundLayerSurface); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 3e8b277f..4680568c 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -646,7 +646,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* g_pHyprOpenGL->m_RenderData.clipBox = CBox(); } -void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time) { +void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, timespec* time, bool popups) { if (pLayer->fadingOut) { g_pHyprOpenGL->renderSnapshot(&pLayer); return; @@ -678,13 +678,15 @@ void CHyprRenderer::renderLayer(SLayerSurface* pLayer, CMonitor* pMonitor, times g_pHyprOpenGL->m_RenderData.discardOpacity = pLayer->ignoreAlphaValue; } - wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata); + if (!popups) + wlr_surface_for_each_surface(pLayer->layerSurface->surface, renderSurface, &renderdata); renderdata.squishOversized = false; // don't squish popups renderdata.dontRound = true; renderdata.popup = true; renderdata.blur = pLayer->forceBlurPopups; - wlr_layer_surface_v1_for_each_popup_surface(pLayer->layerSurface, renderSurface, &renderdata); + if (popups) + wlr_layer_surface_v1_for_each_popup_surface(pLayer->layerSurface, renderSurface, &renderdata); g_pHyprOpenGL->m_pCurrentLayer = nullptr; g_pHyprOpenGL->m_RenderData.clipBox = {}; @@ -855,6 +857,12 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* renderLayer(ls.get(), pMonitor, time); } + for (auto& lsl : pMonitor->m_aLayerSurfaceLayers) { + for (auto& ls : lsl) { + renderLayer(ls.get(), pMonitor, time, true); + } + } + renderDragIcon(pMonitor, time); //g_pHyprOpenGL->restoreMatrix(); diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 011b17b9..d73b4c5f 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -113,7 +113,7 @@ class CHyprRenderer { void renderWorkspaceWindowsFullscreen(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) void renderWorkspaceWindows(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) void renderWindow(CWindow*, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false); - void renderLayer(SLayerSurface*, CMonitor*, timespec*); + void renderLayer(SLayerSurface*, CMonitor*, timespec*, bool popups = false); void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderDragIcon(CMonitor*, timespec*); void renderIMEPopup(CInputPopup*, CMonitor*, timespec*); From 414e37996d0c33a5792b8698146792a2a0359b93 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 25 Mar 2024 19:21:31 -0700 Subject: [PATCH 0192/2897] github: fix github issue template crash dir (#5269) --- .github/ISSUE_TEMPLATE/bug.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml index 2305c650..0bdaff4d 100644 --- a/.github/ISSUE_TEMPLATE/bug.yml +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -63,5 +63,5 @@ body: description: | Anything that can help. Please always ATTACH and not paste them. Logs can be found in /tmp/hypr - Crash reports are stored in ~/.hyprland or $XDG_CACHE_HOME/hyprland + Crash reports are stored in ~/.cache/hyprland or $XDG_CACHE_HOME/hyprland From a9d7526aae38dcdceb391fe9f00919c6c400abe3 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 26 Mar 2024 02:26:09 +0000 Subject: [PATCH 0193/2897] core: ensure m_pLastMonitor validity over unsafe state ref #5241 --- src/Compositor.cpp | 2 ++ src/events/Windows.cpp | 4 ++++ src/helpers/Monitor.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2d6e7856..68db0091 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2808,6 +2808,8 @@ void CCompositor::enterUnsafeState() { m_pUnsafeOutput->onConnect(false); m_bUnsafeState = true; + + setActiveMonitor(m_pUnsafeOutput); } void CCompositor::leaveUnsafeState() { diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index d1cf9552..0d1665b7 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -53,6 +53,10 @@ void Events::listener_mapWindow(void* owner, void* data) { static auto PNEWTAKESOVERFS = CConfigValue("misc:new_window_takes_over_fullscreen"); auto PMONITOR = g_pCompositor->m_pLastMonitor; + if (!g_pCompositor->m_pLastMonitor) { + g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({})); + PMONITOR = g_pCompositor->m_pLastMonitor; + } auto PWORKSPACE = PMONITOR->specialWorkspaceID ? g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID) : g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); PWINDOW->m_iMonitorID = PMONITOR->ID; PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 3edb7ca4..219257b9 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -310,7 +310,7 @@ void CMonitor::onDisconnect(bool destroy) { Debug::log(WARN, "wlr_output_commit_state failed in CMonitor::onDisconnect"); if (g_pCompositor->m_pLastMonitor == this) - g_pCompositor->setActiveMonitor(BACKUPMON); + g_pCompositor->setActiveMonitor(BACKUPMON ? BACKUPMON : g_pCompositor->m_pUnsafeOutput); if (g_pHyprRenderer->m_pMostHzMonitor == this) { int mostHz = 0; From 1a0b8d1263a318146ce63062115332c725e79edf Mon Sep 17 00:00:00 2001 From: vaxerski Date: Tue, 26 Mar 2024 13:35:03 +0000 Subject: [PATCH 0194/2897] renderer: minor fixes to misaligned reported surface rendering fixes #5257 --- src/render/Renderer.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 4680568c..f94a3688 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -91,11 +91,9 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) } if (!INTERACTIVERESIZEINPROGRESS && PSURFACE && PWINDOW && PWINDOW->m_vRealSize.goal().floor() > PWINDOW->m_vReportedSize && PWINDOW->m_vReportedSize > Vector2D{1, 1}) { - Vector2D coeff = PWINDOW->m_vReportedSize / PWINDOW->m_vRealSize.value(); - Vector2D coeff2 = PWINDOW->m_vReportedSize / PWINDOW->m_vRealSize.goal(); - - Vector2D size = Vector2D{windowBox.w, windowBox.h} * coeff; - Vector2D correct = Vector2D{windowBox.w, windowBox.h} - Vector2D{windowBox.w, windowBox.h} * coeff2; + Vector2D size = + Vector2D{windowBox.w * (PWINDOW->m_vReportedSize.x / PWINDOW->m_vRealSize.value().x), windowBox.h * (PWINDOW->m_vReportedSize.y / PWINDOW->m_vRealSize.value().y)}; + Vector2D correct = Vector2D{windowBox.w, windowBox.h} - size; windowBox.translate(correct / 2.0); From 9b7ae25ae83b5b0d6f61fe542391301a57d31270 Mon Sep 17 00:00:00 2001 From: Khalid Date: Tue, 26 Mar 2024 16:38:54 +0300 Subject: [PATCH 0195/2897] hyprctl: output json with `--batch` if requested (#5277) --- hyprctl/main.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/hyprctl/main.cpp b/hyprctl/main.cpp index b8072de9..0bf6f414 100644 --- a/hyprctl/main.cpp +++ b/hyprctl/main.cpp @@ -22,6 +22,7 @@ #include #include #include +#include const std::string USAGE = R"#(usage: hyprctl [(opt)flags] [command] [(opt)args] @@ -234,9 +235,14 @@ void requestHyprpaper(std::string arg) { std::cout << std::string(buffer); } -void batchRequest(std::string arg) { - std::string rq = "[[BATCH]]" + arg.substr(arg.find_first_of(" ") + 1); +void batchRequest(std::string arg, bool json) { + std::string commands = arg.substr(arg.find_first_of(" ") + 1); + if (json) { + commands = "j/" + std::regex_replace(commands, std::regex(";\\s*"), ";j/"); + } + + std::string rq = "[[BATCH]]" + commands; request(rq); } @@ -383,7 +389,7 @@ int main(int argc, char** argv) { int exitStatus = 0; if (fullRequest.contains("/--batch")) - batchRequest(fullRequest); + batchRequest(fullRequest, json); else if (fullRequest.contains("/hyprpaper")) requestHyprpaper(fullRequest); else if (fullRequest.contains("/switchxkblayout")) From ae52b7f4680716976d05b638aaa90e169d199117 Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Wed, 27 Mar 2024 00:16:09 +0900 Subject: [PATCH 0196/2897] textinput: fix ime when opening multiple windows (#5281) --- src/managers/input/TextInput.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 0e642f82..7bb6c81a 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -87,7 +87,11 @@ void CTextInput::onDisabled() { return; } - leave(); + if (!focusedSurface()) + return; + + if (!isV3()) + leave(); hyprListener_surfaceDestroyed.removeCallback(); hyprListener_surfaceUnmapped.removeCallback(); From 93d05114716e847c37f49d3cc2d0c5cb01d06a24 Mon Sep 17 00:00:00 2001 From: vaxerski Date: Wed, 27 Mar 2024 16:30:08 +0000 Subject: [PATCH 0197/2897] layershell: update render pos and size in arrange fixes #5258 --- src/render/Renderer.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index f94a3688..c48bbdd4 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -1618,6 +1618,9 @@ void CHyprRenderer::arrangeLayerArray(CMonitor* pMonitor, const std::vectorlayerSurface, box.width, box.height); + + ls->realPosition = box.pos(); + ls->realSize = box.size(); } } From 132ab8d035f2eb0ec75661526c6f342c5ec52159 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Mar 2024 01:39:17 +0000 Subject: [PATCH 0198/2897] layers: add animation direction overrides fixes #5285 --- src/helpers/WLClasses.cpp | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 5e18c274..96ba0fa5 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -65,11 +65,26 @@ void SLayerSurface::applyRules() { void SLayerSurface::startAnimation(bool in, bool instant) { const auto ANIMSTYLE = animationStyle.value_or(realPosition.m_pConfig->pValues->internalStyle); - if (ANIMSTYLE == "slide") { + if (ANIMSTYLE.starts_with("slide")) { // get closest edge - const auto MIDDLE = geometry.middle(); + const auto MIDDLE = geometry.middle(); - const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE); + const auto PMONITOR = g_pCompositor->getMonitorFromVector(MIDDLE); + + int force = -1; + + CVarList args(ANIMSTYLE, 0, 's'); + if (args.size() > 1) { + const auto ARG2 = args[1]; + if (ARG2 == "top") + force = 0; + else if (ARG2 == "bottom") + force = 1; + else if (ARG2 == "left") + force = 2; + else if (ARG2 == "right") + force = 3; + } const std::array edgePoints = { PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x / 2, 0}, @@ -78,13 +93,15 @@ void SLayerSurface::startAnimation(bool in, bool instant) { PMONITOR->vecPosition + Vector2D{PMONITOR->vecSize.x, PMONITOR->vecSize.y / 2}, }; - float closest = std::numeric_limits::max(); - size_t leader = 0; - for (size_t i = 0; i < 4; ++i) { - float dist = MIDDLE.distance(edgePoints[i]); - if (dist < closest) { - leader = i; - closest = dist; + float closest = std::numeric_limits::max(); + int leader = force; + if (leader == -1) { + for (size_t i = 0; i < 4; ++i) { + float dist = MIDDLE.distance(edgePoints[i]); + if (dist < closest) { + leader = i; + closest = dist; + } } } From 0869f65b0b7e13b0d7f522decfc21244beb21c3a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Mar 2024 02:04:30 +0000 Subject: [PATCH 0199/2897] input: add misc:hide_cursor_on_key_press fixes #3045 --- src/config/ConfigManager.cpp | 1 + src/render/Renderer.cpp | 77 ++++++++++++++++++++++++++++-------- src/render/Renderer.hpp | 9 ++++- 3 files changed, 69 insertions(+), 18 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index d13b871d..17dea1a7 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -349,6 +349,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("misc:background_color", Hyprlang::INT{0xff111111}); m_pConfig->addConfigValue("misc:new_window_takes_over_fullscreen", Hyprlang::INT{0}); m_pConfig->addConfigValue("misc:enable_hyprcursor", Hyprlang::INT{1}); + m_pConfig->addConfigValue("misc:hide_cursor_on_key_press", Hyprlang::INT{0}); m_pConfig->addConfigValue("group:insert_after_current", Hyprlang::INT{1}); m_pConfig->addConfigValue("group:focus_removed_window", Hyprlang::INT{1}); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index c48bbdd4..960add70 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -11,8 +11,13 @@ extern "C" { #include } -CHyprRenderer::CHyprRenderer() { +static int cursorTicker(void* data) { + g_pHyprRenderer->ensureCursorRenderingMode(); + wl_event_source_timer_update(g_pHyprRenderer->m_pCursorTicker, 500); + return 0; +} +CHyprRenderer::CHyprRenderer() { if (g_pCompositor->m_sWLRSession) { wlr_device* dev; wl_list_for_each(dev, &g_pCompositor->m_sWLRSession->devices, link) { @@ -52,6 +57,30 @@ CHyprRenderer::CHyprRenderer() { if (m_bNvidia) Debug::log(WARN, "NVIDIA detected, please remember to follow nvidia instructions on the wiki"); + + // cursor hiding stuff + + g_pHookSystem->hookDynamic("keyPress", [&](void* self, SCallbackInfo& info, std::any param) { + if (m_sCursorHiddenConditions.hiddenOnKeyboard) + return; + + m_sCursorHiddenConditions.hiddenOnKeyboard = true; + ensureCursorRenderingMode(); + }); + + g_pHookSystem->hookDynamic("mouseMove", [&](void* self, SCallbackInfo& info, std::any param) { + if (!m_sCursorHiddenConditions.hiddenOnKeyboard && m_sCursorHiddenConditions.hiddenOnTouch == g_pInputManager->m_bLastInputTouch && + !m_sCursorHiddenConditions.hiddenOnTimeout) + return; + + m_sCursorHiddenConditions.hiddenOnKeyboard = false; + m_sCursorHiddenConditions.hiddenOnTimeout = false; + m_sCursorHiddenConditions.hiddenOnTouch = g_pInputManager->m_bLastInputTouch; + ensureCursorRenderingMode(); + }); + + m_pCursorTicker = wl_event_loop_add_timer(g_pCompositor->m_sWLEventLoop, cursorTicker, nullptr); + wl_event_source_timer_update(m_pCursorTicker, 500); } static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { @@ -1090,8 +1119,6 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { if (g_pConfigManager->m_bWantsMonitorReload) g_pConfigManager->performMonitorReload(); - - ensureCursorRenderingMode(); // so that the cursor gets hidden/shown if the user requested timeouts } // // @@ -2269,29 +2296,45 @@ void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { void CHyprRenderer::ensureCursorRenderingMode() { static auto PCURSORTIMEOUT = CConfigValue("general:cursor_inactive_timeout"); static auto PHIDEONTOUCH = CConfigValue("misc:hide_cursor_on_touch"); + static auto PHIDEONKEY = CConfigValue("misc:hide_cursor_on_key_press"); - const auto PASSEDCURSORSECONDS = g_pInputManager->m_tmrLastCursorMovement.getSeconds(); + if (*PCURSORTIMEOUT <= 0) + m_sCursorHiddenConditions.hiddenOnTimeout = false; + if (*PHIDEONTOUCH == 0) + m_sCursorHiddenConditions.hiddenOnTouch = false; + if (*PHIDEONKEY == 0) + m_sCursorHiddenConditions.hiddenOnKeyboard = false; - if (*PCURSORTIMEOUT > 0 || *PHIDEONTOUCH) { - const bool HIDE = (*PCURSORTIMEOUT > 0 && *PCURSORTIMEOUT < PASSEDCURSORSECONDS) || (g_pInputManager->m_bLastInputTouch && *PHIDEONTOUCH); + if (*PCURSORTIMEOUT > 0) + m_sCursorHiddenConditions.hiddenOnTimeout = *PCURSORTIMEOUT < g_pInputManager->m_tmrLastCursorMovement.getSeconds(); - if (HIDE && !m_bCursorHidden) { - Debug::log(LOG, "Hiding the cursor (timeout)"); + const bool HIDE = m_sCursorHiddenConditions.hiddenOnTimeout || m_sCursorHiddenConditions.hiddenOnTouch || m_sCursorHiddenConditions.hiddenOnKeyboard; - for (auto& m : g_pCompositor->m_vMonitors) - g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? + if (HIDE == m_bCursorHidden) + return; - setCursorHidden(true); + if (HIDE) { + Debug::log(LOG, "Hiding the cursor (hl-mandated)"); - } else if (!HIDE && m_bCursorHidden) { - Debug::log(LOG, "Showing the cursor (timeout)"); + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->output->software_cursor_locks == 0) + continue; - for (auto& m : g_pCompositor->m_vMonitors) - g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? - - setCursorHidden(false); + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? } + + setCursorHidden(true); + } else { + Debug::log(LOG, "Showing the cursor (hl-mandated)"); + + for (auto& m : g_pCompositor->m_vMonitors) { + if (m->output->software_cursor_locks == 0) + continue; + + g_pHyprRenderer->damageMonitor(m.get()); // TODO: maybe just damage the cursor area? + } + setCursorHidden(false); } } diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index d73b4c5f..0a684af3 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -96,6 +96,7 @@ class CHyprRenderer { bool m_bCrashingInProgress = false; float m_fCrashingDistort = 0.5f; wl_event_source* m_pCrashingLoop = nullptr; + wl_event_source* m_pCursorTicker = nullptr; std::vector> m_vTearingControllers; @@ -128,7 +129,13 @@ class CHyprRenderer { bool m_bNvidia = false; - CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt); + struct { + bool hiddenOnTouch = false; + bool hiddenOnTimeout = false; + bool hiddenOnKeyboard = false; + } m_sCursorHiddenConditions; + + CRenderbuffer* getOrCreateRenderbuffer(wlr_buffer* buffer, uint32_t fmt); std::vector> m_vRenderbuffers; friend class CHyprOpenGLImpl; From c24034eb9d33f104f9e1f9016d93a2600dba2a92 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Thu, 28 Mar 2024 02:08:21 +0000 Subject: [PATCH 0200/2897] core: fix fullscreen + floating focus change (#5291) modified: src/Compositor.cpp --- src/Compositor.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 68db0091..2e49237c 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1568,7 +1568,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { // for tiled windows, we calc edges for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || w->m_bIsFloating || !isWorkspaceVisible(w->m_iWorkspaceID)) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->m_iWorkspaceID)) continue; if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_iWorkspaceID != w->m_iWorkspaceID) @@ -1657,7 +1657,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { constexpr float THRESHOLD = 0.3 * M_PI; for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || !w->m_bIsFloating || !isWorkspaceVisible(w->m_iWorkspaceID)) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_iWorkspaceID)) continue; if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_iWorkspaceID != w->m_iWorkspaceID) From 25718754534d0ccd87b198b63459497e63887f35 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Thu, 28 Mar 2024 02:28:16 +0000 Subject: [PATCH 0201/2897] format: fix format --- src/managers/input/TextInput.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 7bb6c81a..39a03c91 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -88,10 +88,10 @@ void CTextInput::onDisabled() { } if (!focusedSurface()) - return; + return; if (!isV3()) - leave(); + leave(); hyprListener_surfaceDestroyed.removeCallback(); hyprListener_surfaceUnmapped.removeCallback(); From 647d5a4ffc08ee654eb3ce951977789b1385a7f8 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:14:27 +0000 Subject: [PATCH 0202/2897] layers: fix bottom slide animation (#5307) modified: src/helpers/WLClasses.cpp --- src/helpers/WLClasses.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index 96ba0fa5..edcdfb14 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -118,7 +118,7 @@ void SLayerSurface::startAnimation(bool in, bool instant) { break; case 1: // BOTTOM - prePos = {geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecPosition.y}; + prePos = {geometry.x, PMONITOR->vecPosition.y + PMONITOR->vecSize.y}; break; case 2: // LEFT From 187caf4187ffc16ec159b1a5b15657a18dfc05e1 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Thu, 28 Mar 2024 14:15:34 +0000 Subject: [PATCH 0203/2897] layers: don't change workspace on layer restore focus (#5308) modified: src/events/Layers.cpp --- src/events/Layers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index f4b52445..a1fef175 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -237,7 +237,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface); - if (!foundSurface && g_pCompositor->m_pLastWindow) { + if (!foundSurface && g_pCompositor->m_pLastWindow && g_pCompositor->isWorkspaceVisible(g_pCompositor->m_pLastWindow->m_iWorkspaceID)) { // if there isn't any, focus the last window const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); From d8429eebc66e7091381502edc0fc7335790f62e4 Mon Sep 17 00:00:00 2001 From: Mihai Fufezan Date: Thu, 28 Mar 2024 18:43:58 +0200 Subject: [PATCH 0204/2897] flake.lock: update Fixes #5301 --- flake.lock | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index a883fa8e..288a335b 100644 --- a/flake.lock +++ b/flake.lock @@ -11,11 +11,11 @@ ] }, "locked": { - "lastModified": 1711035742, - "narHash": "sha256-5vvhCSUGG9TA2G1eIRgokuYizhRnZu0ZbcU1MXfHsUE=", + "lastModified": 1711466786, + "narHash": "sha256-sArxGyUBiCA1in+q6t0QqT+ZJiZ1PyBp7cNPKLmREM0=", "owner": "hyprwm", "repo": "hyprcursor", - "rev": "6a92473237f430399a417e1c2da9d7fcd4970086", + "rev": "d3876f34779cc03ee51e4aafc0d00a4f187c7544", "type": "github" }, "original": { @@ -79,11 +79,11 @@ ] }, "locked": { - "lastModified": 1710960526, - "narHash": "sha256-tt0UgVKWeLQ+tFzvqrm4uAZbzONwdGshpfiLHAQ1P2c=", + "lastModified": 1711250455, + "narHash": "sha256-LSq1ZsTpeD7xsqvlsepDEelWRDtAhqwetp6PusHXJRo=", "owner": "hyprwm", "repo": "hyprlang", - "rev": "a2f39421144d42541c057be235154ce21b76c0f6", + "rev": "b3e430f81f3364c5dd1a3cc9995706a4799eb3fa", "type": "github" }, "original": { @@ -94,11 +94,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1711001935, - "narHash": "sha256-URtGpHue7HHZK0mrHnSf8wJ6OmMKYSsoLmJybrOLFSQ=", + "lastModified": 1711523803, + "narHash": "sha256-UKcYiHWHQynzj6CN/vTcix4yd1eCu1uFdsuarupdCQQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "20f77aa09916374aa3141cbc605c955626762c9a", + "rev": "2726f127c15a4cc9810843b96cad73c7eb39e443", "type": "github" }, "original": { From 2930c5cb6f5d71dbdfd4d396287f90e19cd41228 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 29 Mar 2024 00:23:16 +0000 Subject: [PATCH 0205/2897] animvar: fixup update callbacks and cleanup --- src/desktop/Window.cpp | 16 ++++++++-------- src/desktop/Workspace.cpp | 8 +++----- src/helpers/AnimatedVariable.cpp | 25 ++++++++++++++++++++++++- src/helpers/AnimatedVariable.hpp | 28 ++++++++++++++++++++++++++-- src/helpers/WLClasses.cpp | 9 +++------ src/hyprerror/HyprError.cpp | 2 +- 6 files changed, 65 insertions(+), 23 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 9151d57e..81c77455 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -6,14 +6,14 @@ #include "../config/ConfigValue.hpp" CWindow::CWindow() { - m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_vRealSize.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_fBorderFadeAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("border"), (void*)this, AVARDAMAGE_BORDER); - m_fBorderAngleAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("borderangle"), (void*)this, AVARDAMAGE_BORDER); - m_fAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeIn"), (void*)this, AVARDAMAGE_ENTIRE); - m_fActiveInactiveAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"), (void*)this, AVARDAMAGE_ENTIRE); - m_cRealShadowColor.create(g_pConfigManager->getAnimationPropertyConfig("fadeShadow"), (void*)this, AVARDAMAGE_SHADOW); - m_fDimPercent.create(g_pConfigManager->getAnimationPropertyConfig("fadeDim"), (void*)this, AVARDAMAGE_ENTIRE); + m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), this, AVARDAMAGE_ENTIRE); + m_vRealSize.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), this, AVARDAMAGE_ENTIRE); + m_fBorderFadeAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("border"), this, AVARDAMAGE_BORDER); + m_fBorderAngleAnimationProgress.create(g_pConfigManager->getAnimationPropertyConfig("borderangle"), this, AVARDAMAGE_BORDER); + m_fAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeIn"), this, AVARDAMAGE_ENTIRE); + m_fActiveInactiveAlpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeSwitch"), this, AVARDAMAGE_ENTIRE); + m_cRealShadowColor.create(g_pConfigManager->getAnimationPropertyConfig("fadeShadow"), this, AVARDAMAGE_SHADOW); + m_fDimPercent.create(g_pConfigManager->getAnimationPropertyConfig("fadeDim"), this, AVARDAMAGE_ENTIRE); addWindowDeco(std::make_unique(this)); addWindowDeco(std::make_unique(this)); diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index d5f72384..440afc56 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -15,12 +15,10 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_szName = name; m_bIsSpecialWorkspace = special; - m_vRenderOffset.m_pWorkspace = this; - m_vRenderOffset.create(special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), nullptr, + m_vRenderOffset.create(special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), this, AVARDAMAGE_ENTIRE); - m_fAlpha.m_pWorkspace = this; - m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), - nullptr, AVARDAMAGE_ENTIRE); + m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), this, + AVARDAMAGE_ENTIRE); m_fAlpha.setValueAndWarp(1.f); m_vRenderOffset.registerVar(); diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp index 3a891e37..74575c83 100644 --- a/src/helpers/AnimatedVariable.cpp +++ b/src/helpers/AnimatedVariable.cpp @@ -6,7 +6,7 @@ CBaseAnimatedVariable::CBaseAnimatedVariable(ANIMATEDVARTYPE type) : m_Type(type ; // dummy var } -void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy) { m_eDamagePolicy = policy; m_pConfig = pAnimConfig; m_pWindow = pWindow; @@ -14,6 +14,29 @@ void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, void* m_bDummy = false; } +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy) { + m_eDamagePolicy = policy; + m_pConfig = pAnimConfig; + m_pLayer = pLayer; + + m_bDummy = false; +} + +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { + m_eDamagePolicy = policy; + m_pConfig = pAnimConfig; + m_pWorkspace = pWorkspace; + + m_bDummy = false; +} + +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy) { + m_eDamagePolicy = policy; + m_pConfig = pAnimConfig; + + m_bDummy = false; +} + CBaseAnimatedVariable::~CBaseAnimatedVariable() { unregister(); } diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 88c775af..82e30892 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -67,7 +67,10 @@ concept Animable = OneOf; class CBaseAnimatedVariable { public: CBaseAnimatedVariable(ANIMATEDVARTYPE type); - void create(SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy); CBaseAnimatedVariable(const CBaseAnimatedVariable&) = delete; CBaseAnimatedVariable(CBaseAnimatedVariable&&) = delete; @@ -204,11 +207,26 @@ class CAnimatedVariable : public CBaseAnimatedVariable { public: CAnimatedVariable() : CBaseAnimatedVariable(typeToANIMATEDVARTYPE) {} // dummy var - void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, void* pWindow, AVARDAMAGEPOLICY policy) { + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy) { create(pAnimConfig, pWindow, policy); m_Value = value; m_Goal = value; } + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy) { + create(pAnimConfig, pLayer, policy); + m_Value = value; + m_Goal = value; + } + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { + create(pAnimConfig, pWorkspace, policy); + m_Value = value; + m_Goal = value; + } + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy) { + create(pAnimConfig, policy); + m_Value = value; + m_Goal = value; + } using CBaseAnimatedVariable::create; @@ -261,10 +279,16 @@ class CAnimatedVariable : public CBaseAnimatedVariable { } void warp(bool endCallback = true) override { + if (m_Value == m_Goal) + return; + m_Value = m_Goal; m_bIsBeingAnimated = false; + if (m_fUpdateCallback) + m_fUpdateCallback(this); + if (endCallback) onAnimationEnd(); } diff --git a/src/helpers/WLClasses.cpp b/src/helpers/WLClasses.cpp index edcdfb14..084a719d 100644 --- a/src/helpers/WLClasses.cpp +++ b/src/helpers/WLClasses.cpp @@ -3,12 +3,9 @@ #include "../Compositor.hpp" SLayerSurface::SLayerSurface() { - alpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeLayers"), nullptr, AVARDAMAGE_ENTIRE); - realPosition.create(g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); - realSize.create(g_pConfigManager->getAnimationPropertyConfig("layers"), nullptr, AVARDAMAGE_ENTIRE); - alpha.m_pLayer = this; - realPosition.m_pLayer = this; - realSize.m_pLayer = this; + alpha.create(g_pConfigManager->getAnimationPropertyConfig("fadeLayers"), this, AVARDAMAGE_ENTIRE); + realPosition.create(g_pConfigManager->getAnimationPropertyConfig("layers"), this, AVARDAMAGE_ENTIRE); + realSize.create(g_pConfigManager->getAnimationPropertyConfig("layers"), this, AVARDAMAGE_ENTIRE); alpha.registerVar(); realPosition.registerVar(); realSize.registerVar(); diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index a7636b1c..73f9c5d5 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -3,7 +3,7 @@ #include "../config/ConfigValue.hpp" CHyprError::CHyprError() { - m_fFadeOpacity.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), nullptr, AVARDAMAGE_NONE); + m_fFadeOpacity.create(AVARTYPE_FLOAT, g_pConfigManager->getAnimationPropertyConfig("fadeIn"), AVARDAMAGE_NONE); m_fFadeOpacity.registerVar(); g_pHookSystem->hookDynamic("focusedMon", [&](void* self, SCallbackInfo& info, std::any param) { From fcd9d77b642c0cd45cae61cf10ed1924f2e7945b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 29 Mar 2024 00:43:50 +0000 Subject: [PATCH 0206/2897] layout: improve initial size prediction for floating --- src/events/Windows.cpp | 17 +---------- src/layout/DwindleLayout.cpp | 2 +- src/layout/DwindleLayout.hpp | 2 +- src/layout/IHyprLayout.cpp | 57 ++++++++++++++++++++++++++++++++++-- src/layout/IHyprLayout.hpp | 8 ++++- src/layout/MasterLayout.cpp | 2 +- src/layout/MasterLayout.hpp | 2 +- 7 files changed, 67 insertions(+), 23 deletions(-) diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 0d1665b7..00546550 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -782,22 +782,7 @@ void Events::listener_commitWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; if (!PWINDOW->m_bIsX11 && PWINDOW->m_uSurface.xdg->initial_commit) { - Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(); - - if (g_pXWaylandManager->shouldBeFloated(PWINDOW, true)) - predSize = {}; - - Vector2D maxSize = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->pending.max_width, PWINDOW->m_uSurface.xdg->toplevel->pending.max_height}; - - if ((maxSize.x > 0 && maxSize.x < predSize.x) || (maxSize.y > 0 && maxSize.y < predSize.y)) - predSize = {}; - - for (auto& r : g_pConfigManager->getMatchingRules(PWINDOW, true, true)) { - if (r.szRule.starts_with("float")) { - predSize = {}; - break; - } - } + Vector2D predSize = g_pLayoutManager->getCurrentLayout()->predictSizeForNewWindow(PWINDOW); Debug::log(LOG, "Layout predicts size {} for {}", predSize, PWINDOW); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index c34f04cc..fe8847ed 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -1116,7 +1116,7 @@ void CHyprDwindleLayout::onDisable() { m_lDwindleNodesData.clear(); } -Vector2D CHyprDwindleLayout::predictSizeForNewWindow() { +Vector2D CHyprDwindleLayout::predictSizeForNewWindowTiled() { if (!g_pCompositor->m_pLastMonitor) return {}; diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index 5ca90fcd..b8c752f4 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -59,7 +59,7 @@ class CHyprDwindleLayout : public IHyprLayout { virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); - virtual Vector2D predictSizeForNewWindow(); + virtual Vector2D predictSizeForNewWindowTiled(); virtual void onEnable(); virtual void onDisable(); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 6a32144e..1570fd73 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -644,8 +644,61 @@ void IHyprLayout::requestFocusForWindow(CWindow* pWindow) { g_pCompositor->warpCursorTo(pWindow->middle()); } -Vector2D IHyprLayout::predictSizeForNewWindow() { - return Vector2D{}; +Vector2D IHyprLayout::predictSizeForNewWindowFloating(CWindow* pWindow) { // get all rules, see if we have any size overrides. + Vector2D sizeOverride = {}; + if (g_pCompositor->m_pLastMonitor) { + for (auto& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) { + if (r.szRule.starts_with("size")) { + try { + const auto VALUE = r.szRule.substr(r.szRule.find(' ') + 1); + const auto SIZEXSTR = VALUE.substr(0, VALUE.find(' ')); + const auto SIZEYSTR = VALUE.substr(VALUE.find(' ') + 1); + + const auto MAXSIZE = g_pXWaylandManager->getMaxSizeForWindow(pWindow); + + const auto SIZEX = SIZEXSTR == "max" ? + std::clamp(MAXSIZE.x, 20.0, g_pCompositor->m_pLastMonitor->vecSize.x) : + (!SIZEXSTR.contains('%') ? std::stoi(SIZEXSTR) : std::stof(SIZEXSTR.substr(0, SIZEXSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.x); + const auto SIZEY = SIZEYSTR == "max" ? + std::clamp(MAXSIZE.y, 20.0, g_pCompositor->m_pLastMonitor->vecSize.y) : + (!SIZEYSTR.contains('%') ? std::stoi(SIZEYSTR) : std::stof(SIZEYSTR.substr(0, SIZEYSTR.length() - 1)) * 0.01 * g_pCompositor->m_pLastMonitor->vecSize.y); + + sizeOverride = {SIZEX, SIZEY}; + + } catch (...) { Debug::log(LOG, "Rule size failed, rule: {} -> {}", r.szRule, r.szValue); } + break; + } + } + } + + return sizeOverride; +} + +Vector2D IHyprLayout::predictSizeForNewWindow(CWindow* pWindow) { + bool shouldBeFloated = g_pXWaylandManager->shouldBeFloated(pWindow, true); + + if (!shouldBeFloated) { + for (auto& r : g_pConfigManager->getMatchingRules(pWindow, true, true)) { + if (r.szRule.starts_with("float")) { + shouldBeFloated = true; + break; + } + } + } + + Vector2D sizePredicted = {}; + + if (!shouldBeFloated) + sizePredicted = predictSizeForNewWindowTiled(); + else + sizePredicted = predictSizeForNewWindowFloating(pWindow); + + Vector2D maxSize = Vector2D{pWindow->m_uSurface.xdg->toplevel->pending.max_width, pWindow->m_uSurface.xdg->toplevel->pending.max_height}; + + if ((maxSize.x > 0 && maxSize.x < sizePredicted.x) || (maxSize.y > 0 && maxSize.y < sizePredicted.y)) + sizePredicted = {}; + + return sizePredicted; } IHyprLayout::~IHyprLayout() {} diff --git a/src/layout/IHyprLayout.hpp b/src/layout/IHyprLayout.hpp index e168556e..d6c41d3b 100644 --- a/src/layout/IHyprLayout.hpp +++ b/src/layout/IHyprLayout.hpp @@ -187,7 +187,13 @@ class IHyprLayout { Called to predict the size of a newly opened window to send it a configure. Return 0,0 if unpredictable */ - virtual Vector2D predictSizeForNewWindow(); + virtual Vector2D predictSizeForNewWindowTiled() = 0; + + /* + Prefer not overriding, use predictSizeForNewWindowTiled. + */ + virtual Vector2D predictSizeForNewWindow(CWindow* pWindow); + virtual Vector2D predictSizeForNewWindowFloating(CWindow* pWindow); private: int m_iMouseMoveEventCount; diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 1c6be8d6..ea54b0e2 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -1435,7 +1435,7 @@ void CHyprMasterLayout::replaceWindowDataWith(CWindow* from, CWindow* to) { applyNodeDataToWindow(PNODE); } -Vector2D CHyprMasterLayout::predictSizeForNewWindow() { +Vector2D CHyprMasterLayout::predictSizeForNewWindowTiled() { static auto PNEWISMASTER = CConfigValue("master:new_is_master"); if (!g_pCompositor->m_pLastMonitor) diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index 6f8ea120..1e48b5dd 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -65,7 +65,7 @@ class CHyprMasterLayout : public IHyprLayout { virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual void replaceWindowDataWith(CWindow* from, CWindow* to); - virtual Vector2D predictSizeForNewWindow(); + virtual Vector2D predictSizeForNewWindowTiled(); virtual void onEnable(); virtual void onDisable(); From 53aa184d2099b1f5c1b712df1484211bad3d6093 Mon Sep 17 00:00:00 2001 From: Muhamed Hobi Date: Fri, 29 Mar 2024 10:07:33 -0400 Subject: [PATCH 0207/2897] makefile: Remove old headers first (#5316) Windows.cpp was moved and I found myself having both versions in my include. Clear out the headers before dumping new ones. --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index c29f20a0..71097960 100644 --- a/Makefile +++ b/Makefile @@ -75,6 +75,7 @@ pluginenv: installheaders: @if [ ! -f ./src/version.h ]; then echo -en "You need to run $(MAKE) all first.\n" && exit 1; fi + rm -fr ${PREFIX}/include/hyprland mkdir -p ${PREFIX}/include/hyprland mkdir -p ${PREFIX}/include/hyprland/protocols mkdir -p ${PREFIX}/include/hyprland/wlroots From 3d1bf1405ee2b368b461164210ad1485d5f32178 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 29 Mar 2024 18:57:10 +0000 Subject: [PATCH 0208/2897] keybinds: add binds:disable_keybind_grabbing fixes #5273 --- src/config/ConfigManager.cpp | 1 + src/managers/KeybindManager.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 17dea1a7..1229e80b 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -490,6 +490,7 @@ CConfigManager::CConfigManager() { m_pConfig->addConfigValue("binds:focus_preferred_method", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:ignore_group_lock", Hyprlang::INT{0}); m_pConfig->addConfigValue("binds:movefocus_cycles_fullscreen", Hyprlang::INT{1}); + m_pConfig->addConfigValue("binds:disable_keybind_grabbing", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe", Hyprlang::INT{0}); m_pConfig->addConfigValue("gestures:workspace_swipe_fingers", Hyprlang::INT{3}); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index a8d390fa..57b1b4e0 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -501,7 +501,9 @@ bool CKeybindManager::handleKeybinds(const uint32_t modmask, const SPressedKeyWi if (g_pCompositor->m_sSeat.exclusiveClient) Debug::log(LOG, "Keybind handling only locked (inhibitor)"); - if (!m_lShortcutInhibitors.empty()) { + static auto PDISABLEINHIBIT = CConfigValue("binds:disable_keybind_grabbing"); + + if (!*PDISABLEINHIBIT && !m_lShortcutInhibitors.empty()) { for (auto& i : m_lShortcutInhibitors) { if (i.pWlrInhibitor->surface == g_pCompositor->m_pLastFocus) { Debug::log(LOG, "Keybind handling is disabled due to an inhibitor for surface {:x}", (uintptr_t)i.pWlrInhibitor->surface); From 54376d7b5f88bffd96ce9ded26637d83d7aa95b1 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Fri, 29 Mar 2024 19:06:08 +0000 Subject: [PATCH 0209/2897] compositor: remove windows from fading out on destroy ref #5321 --- src/Compositor.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2e49237c..7e81797f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -693,6 +693,8 @@ CMonitor* CCompositor::getMonitorFromVector(const Vector2D& point) { void CCompositor::removeWindowFromVectorSafe(CWindow* pWindow) { if (windowExists(pWindow) && !pWindow->m_bFadingOut) std::erase_if(m_vWindows, [&](std::unique_ptr& el) { return el.get() == pWindow; }); + + std::erase_if(m_vWindowsFadingOut, [&](CWindow* el) { return el == pWindow; }); } bool CCompositor::windowExists(CWindow* pWindow) { From 6fb8f502050c269597636c3b0bfcf046f7f6a947 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 30 Mar 2024 03:09:22 +0000 Subject: [PATCH 0210/2897] hyprpm: avoid crashes on corrupted headers ref #5329 --- hyprpm/src/core/PluginManager.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/hyprpm/src/core/PluginManager.cpp b/hyprpm/src/core/PluginManager.cpp index c5926c3e..965f2e9d 100644 --- a/hyprpm/src/core/PluginManager.cpp +++ b/hyprpm/src/core/PluginManager.cpp @@ -333,7 +333,12 @@ eHeadersErrors CPluginManager::headersValid() { std::string verHeaderContent((std::istreambuf_iterator(ifs)), (std::istreambuf_iterator())); ifs.close(); - std::string hash = verHeaderContent.substr(verHeaderContent.find("#define GIT_COMMIT_HASH") + 23); + const auto HASHPOS = verHeaderContent.find("#define GIT_COMMIT_HASH"); + + if (HASHPOS == std::string::npos || HASHPOS + 23 >= verHeaderContent.length()) + return HEADERS_CORRUPTED; + + std::string hash = verHeaderContent.substr(HASHPOS + 23); hash = hash.substr(0, hash.find_first_of('\n')); hash = hash.substr(hash.find_first_of('"') + 1); hash = hash.substr(0, hash.find_first_of('"')); From a17d7ba87b661e0f152fa59bc9efdf1da2a84c86 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 30 Mar 2024 09:57:43 -0700 Subject: [PATCH 0211/2897] dispatchers: fix swap workspaces wrong positioning of floating windows (#5328) --- src/Compositor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 7e81797f..6276b735 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -2024,7 +2024,7 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // additionally, move floating and fs windows manually if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.value() - pMonitorA->vecPosition + pMonitorB->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.goal() - pMonitorA->vecPosition + pMonitorB->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitorB->vecPosition; @@ -2049,7 +2049,7 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // additionally, move floating and fs windows manually if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.value() - pMonitorB->vecPosition + pMonitorA->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.goal() - pMonitorB->vecPosition + pMonitorA->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitorA->vecPosition; @@ -2226,7 +2226,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni if (w->m_bIsMapped && !w->isHidden()) { if (POLDMON) { if (w->m_bIsFloating) - w->m_vRealPosition = w->m_vRealPosition.value() - POLDMON->vecPosition + pMonitor->vecPosition; + w->m_vRealPosition = w->m_vRealPosition.goal() - POLDMON->vecPosition + pMonitor->vecPosition; if (w->m_bIsFullscreen) { w->m_vRealPosition = pMonitor->vecPosition; From 906e49814412921fd6d0e0188416665dd8ef3e0c Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 30 Mar 2024 09:58:18 -0700 Subject: [PATCH 0212/2897] dispatchers: open special ws on active monitor instead of mouse monitor (#5330) --- src/managers/KeybindManager.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 57b1b4e0..03887514 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -1624,9 +1624,6 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { } void CKeybindManager::toggleSpecialWorkspace(std::string args) { - - static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); - std::string workspaceName = ""; int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName); @@ -1636,7 +1633,7 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { } bool requestedWorkspaceIsAlreadyOpen = false; - const auto PMONITOR = *PFOLLOWMOUSE == 1 ? g_pCompositor->getMonitorFromCursor() : g_pCompositor->m_pLastMonitor; + const auto PMONITOR = g_pCompositor->m_pLastMonitor; int specialOpenOnMonitor = PMONITOR->specialWorkspaceID; for (auto& m : g_pCompositor->m_vMonitors) { From 77f26997fd00aaec958463414269fa3d8f62bb63 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sat, 30 Mar 2024 17:00:56 +0000 Subject: [PATCH 0213/2897] IME: don't assert on lock mismatch, just fix it --- src/managers/input/TextInput.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 39a03c91..eeea899d 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -170,7 +170,11 @@ void CTextInput::enter(wlr_surface* pSurface) { } enterLocks++; - RASSERT(enterLocks == 1, "TextInput had != 1 lock in enter"); + if (enterLocks != 1) { + Debug::log(ERR, "BUG THIS: TextInput has != 1 locks in enter"); + leave(); + enterLocks = 1; + } if (pWlrInput) wlr_text_input_v3_send_enter(pWlrInput, pSurface); @@ -187,7 +191,10 @@ void CTextInput::leave() { return; enterLocks--; - RASSERT(enterLocks == 0, "TextInput had != 0 locks in leave"); + if (enterLocks != 1) { + Debug::log(ERR, "BUG THIS: TextInput has != 0 locks in leave"); + enterLocks = 0; + } if (pWlrInput && pWlrInput->focused_surface) wlr_text_input_v3_send_leave(pWlrInput); From 1aed45f61d2dd48943a63cabf7bd77c19a59cf62 Mon Sep 17 00:00:00 2001 From: Aqa-Ib Date: Sun, 31 Mar 2024 01:48:39 +0100 Subject: [PATCH 0214/2897] core: Fix resizeparams (#5262) * Revert a94b902 * Fix resizeparams using CVarList * clang-format * fix * Use 's' as delimiter * remove size checks * fix tabs * fix mixing tabs and spaces --- src/Compositor.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 6276b735..30e769e3 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -10,6 +10,7 @@ #include // for sd_notify #endif #include +#include "helpers/VarList.hpp" int handleCritSignal(int signo, void* data) { Debug::log(LOG, "Hyprland received signal {}", signo); @@ -2545,7 +2546,7 @@ SLayerSurface* CCompositor::getLayerSurfaceFromSurface(wlr_surface* pSurface) { // returns a delta Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, const Vector2D& relativeTo) { - if (!args.contains(' ')) + if (!args.contains(' ') && !args.contains('\t')) return relativeTo; const auto PMONITOR = m_pLastMonitor; @@ -2554,12 +2555,13 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con bool yIsPercent = false; bool isExact = false; - std::string x = args.substr(0, args.find_first_of(' ')); - std::string y = args.substr(args.find_last_of(' ') + 1); + CVarList varList(args, 0, 's', true); + std::string x = varList[0]; + std::string y = varList[1]; if (x == "exact") { - x = y.substr(0, y.find_first_of(' ')); - y = y.substr(y.find_first_of(' ') + 1); + x = varList[1]; + y = varList[2]; isExact = true; } From 5e8c25d498ed5cb7852ae74a876b0c138a62d59d Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 30 Mar 2024 17:49:53 -0700 Subject: [PATCH 0215/2897] core: match all workspace rules instead of the first one only (#5340) --- src/Compositor.cpp | 15 ++++++++++---- src/config/ConfigManager.cpp | 12 +++++++----- src/config/ConfigManager.hpp | 2 +- src/desktop/Window.cpp | 29 +++++++++++++++++++-------- src/desktop/Workspace.cpp | 8 +++++--- src/layout/DwindleLayout.cpp | 25 ++++++++++++++++++------ src/layout/MasterLayout.cpp | 38 +++++++++++++++++++++++++----------- 7 files changed, 91 insertions(+), 38 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 30e769e3..3ac9a73f 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1260,8 +1260,13 @@ void CCompositor::sanityCheckWorkspaces() { auto it = m_vWorkspaces.begin(); while (it != m_vWorkspaces.end()) { - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(it->get()); - if (WORKSPACERULE.isPersistent) { + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(it->get()); + bool isPersistent = false; + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.isPersistent) + isPersistent = true; + } + if (isPersistent) { ++it; continue; } @@ -1288,8 +1293,10 @@ void CCompositor::sanityCheckWorkspaces() { continue; } if (!WORKSPACE->m_bOnCreatedEmptyExecuted) { - if (auto cmd = WORKSPACERULE.onCreatedEmptyRunCmd) - g_pKeybindManager->spawn(*cmd); + for (auto& wsRule : WORKSPACERULES) { + if (auto cmd = wsRule.onCreatedEmptyRunCmd) + g_pKeybindManager->spawn(*cmd); + } WORKSPACE->m_bOnCreatedEmptyExecuted = true; } diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 1229e80b..df2006ae 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -956,11 +956,13 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) { return SMonitorRule{.name = "", .resolution = Vector2D(0, 0), .offset = Vector2D(-INT32_MAX, -INT32_MAX), .scale = -1}; // 0, 0 is preferred and -1, -1 is auto } -SWorkspaceRule CConfigManager::getWorkspaceRuleFor(CWorkspace* pWorkspace) { - const auto IT = std::find_if(m_dWorkspaceRules.begin(), m_dWorkspaceRules.end(), [&](const auto& other) { return pWorkspace->matchesStaticSelector(other.workspaceString); }); - if (IT == m_dWorkspaceRules.end()) - return SWorkspaceRule{}; - return *IT; +std::vector CConfigManager::getWorkspaceRulesFor(CWorkspace* pWorkspace) { + std::vector results; + for (auto& rule : m_dWorkspaceRules) { + if (pWorkspace->matchesStaticSelector(rule.workspaceString)) + results.push_back(rule); + } + return results; } std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic, bool shadowExec) { diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 9fd1e097..5406d853 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -105,7 +105,7 @@ class CConfigManager { static std::string getMainConfigPath(); SMonitorRule getMonitorRuleFor(const CMonitor&); - SWorkspaceRule getWorkspaceRuleFor(CWorkspace*); + std::vector getWorkspaceRulesFor(CWorkspace*); std::string getDefaultWorkspaceFor(const std::string&); CMonitor* getBoundMonitorForWS(const std::string&); diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 81c77455..1336456a 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1088,20 +1088,33 @@ float CWindow::rounding() { } void CWindow::updateSpecialRenderData() { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); - const auto WORKSPACERULE = PWORKSPACE ? g_pConfigManager->getWorkspaceRuleFor(PWORKSPACE) : SWorkspaceRule{}; - bool border = true; + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + const auto WORKSPACERULES = PWORKSPACE ? g_pConfigManager->getWorkspaceRulesFor(PWORKSPACE) : std::vector{}; + bool border = true; static auto PNOBORDERONFLOATING = CConfigValue("general:no_border_on_floating"); if (m_bIsFloating && *PNOBORDERONFLOATING == 1) border = false; - m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(border); - m_sSpecialRenderData.borderSize = WORKSPACERULE.borderSize.value_or(-1); - m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true); - m_sSpecialRenderData.rounding = WORKSPACERULE.rounding.value_or(true); - m_sSpecialRenderData.shadow = WORKSPACERULE.shadow.value_or(true); + m_sSpecialRenderData.border = border; + m_sSpecialRenderData.borderSize = -1; + m_sSpecialRenderData.decorate = true; + m_sSpecialRenderData.rounding = true; + m_sSpecialRenderData.shadow = true; + + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.border.has_value()) + m_sSpecialRenderData.border = wsRule.border.value(); + if (wsRule.borderSize.has_value()) + m_sSpecialRenderData.borderSize = wsRule.borderSize.value(); + if (wsRule.decorate.has_value()) + m_sSpecialRenderData.decorate = wsRule.decorate.value(); + if (wsRule.rounding.has_value()) + m_sSpecialRenderData.rounding = wsRule.rounding.value(); + if (wsRule.shadow.has_value()) + m_sSpecialRenderData.shadow = wsRule.shadow.value(); + } } int CWindow::getRealBorderSize() { diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 440afc56..05843b59 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -24,9 +24,11 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_vRenderOffset.registerVar(); m_fAlpha.registerVar(); - const auto RULEFORTHIS = g_pConfigManager->getWorkspaceRuleFor(this); - if (RULEFORTHIS.defaultName.has_value()) - m_szName = RULEFORTHIS.defaultName.value(); + const auto RULESFORTHIS = g_pConfigManager->getWorkspaceRulesFor(this); + for (auto& rule : RULESFORTHIS) { + if (rule.defaultName.has_value()) + m_szName = rule.defaultName.value(); + } g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index fe8847ed..93f60e3f 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -128,7 +128,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for const auto PWINDOW = pNode->pWindow; // get specific gaps and rules for this workspace, // if user specified them in config - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(pNode->workspaceID)); if (!g_pCompositor->windowExists(PWINDOW)) { Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); @@ -147,10 +147,16 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for auto* const PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); auto* const PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); - auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); - auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); + auto gapsIn = *PGAPSIN; + auto gapsOut = *PGAPSOUT; + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.gapsIn.has_value()) + gapsIn = wsRule.gapsIn.value(); + if (wsRule.gapsOut.has_value()) + gapsOut = wsRule.gapsOut.value(); + } - CBox nodeBox = pNode->box; + CBox nodeBox = pNode->box; nodeBox.round(); PWINDOW->m_vSize = nodeBox.size(); @@ -161,10 +167,17 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { - PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2); - PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true); PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; + PWINDOW->m_sSpecialRenderData.border = (*PNOGAPSWHENONLY == 2); + PWINDOW->m_sSpecialRenderData.decorate = true; + + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.border.has_value()) + PWINDOW->m_sSpecialRenderData.border = wsRule.border.value(); + if (wsRule.decorate.has_value()) + PWINDOW->m_sSpecialRenderData.decorate = wsRule.decorate.value(); + } PWINDOW->updateWindowDecos(); diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index ea54b0e2..9c49197e 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -41,14 +41,17 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { } //create on the fly if it doesn't exist yet - const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); - PWORKSPACEDATA->workspaceID = ws; - static auto PORIENTATION = CConfigValue("master:orientation"); - const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts; + const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); + PWORKSPACEDATA->workspaceID = ws; + static auto PORIENTATION = CConfigValue("master:orientation"); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(ws)); + std::string orientationForWs = *PORIENTATION; - if (layoutoptsForWs.contains("orientation")) - orientationForWs = layoutoptsForWs.at("orientation"); + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.layoutopts.contains("orientation")) + orientationForWs = wsRule.layoutopts.at("orientation"); + } if (orientationForWs == "top") { PWORKSPACEDATA->orientation = ORIENTATION_TOP; @@ -626,7 +629,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { const auto PWINDOW = pNode->pWindow; // get specific gaps and rules for this workspace, // if user specified them in config - const auto WORKSPACERULE = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)); if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks) return; @@ -640,8 +643,14 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { auto* PGAPSIN = (CCssGapData*)(PGAPSINDATA.ptr())->getData(); auto* PGAPSOUT = (CCssGapData*)(PGAPSOUTDATA.ptr())->getData(); - auto gapsIn = WORKSPACERULE.gapsIn.value_or(*PGAPSIN); - auto gapsOut = WORKSPACERULE.gapsOut.value_or(*PGAPSOUT); + auto gapsIn = *PGAPSIN; + auto gapsOut = *PGAPSOUT; + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.gapsIn.has_value()) + gapsIn = wsRule.gapsIn.value(); + if (wsRule.gapsOut.has_value()) + gapsOut = wsRule.gapsOut.value(); + } if (!g_pCompositor->windowValidMapped(PWINDOW)) { Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); @@ -655,10 +664,17 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { - PWINDOW->m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(*PNOGAPSWHENONLY == 2); - PWINDOW->m_sSpecialRenderData.decorate = WORKSPACERULE.decorate.value_or(true); PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; + PWINDOW->m_sSpecialRenderData.border = (*PNOGAPSWHENONLY == 2); + PWINDOW->m_sSpecialRenderData.decorate = true; + + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.border.has_value()) + PWINDOW->m_sSpecialRenderData.border = wsRule.border.value(); + if (wsRule.decorate.has_value()) + PWINDOW->m_sSpecialRenderData.decorate = wsRule.decorate.value(); + } PWINDOW->updateWindowDecos(); From 1cc9a44318e53a34f41cc36483502de985b88cf8 Mon Sep 17 00:00:00 2001 From: Zach DeCook Date: Sat, 30 Mar 2024 20:50:25 -0400 Subject: [PATCH 0216/2897] input: Fix incorrect keyboard focus taken when no window was present (#5337) A non-keyboard layer never needs keyboard focus --- src/managers/input/InputManager.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 690463fa..4e2bf709 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -422,10 +422,8 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { unsetCursorImage(); } - if (pFoundLayerSurface && - (pFoundLayerSurface->layerSurface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE || - (pFoundLayerSurface->layer >= ZWLR_LAYER_SHELL_V1_LAYER_TOP && !g_pCompositor->m_pLastWindow)) && - FOLLOWMOUSE != 3 && allowKeyboardRefocus) { + if (pFoundLayerSurface && (pFoundLayerSurface->layerSurface->current.keyboard_interactive != ZWLR_LAYER_SURFACE_V1_KEYBOARD_INTERACTIVITY_NONE) && FOLLOWMOUSE != 3 && + allowKeyboardRefocus) { g_pCompositor->focusSurface(foundSurface); } From 16a9c16d9f99bd8be9f1bb15442b001fdf2ea759 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sat, 30 Mar 2024 18:14:26 -0700 Subject: [PATCH 0217/2897] renderer/animations: Fix various inaccurate damage tracking issues and offsets (#5297) --- src/desktop/Window.cpp | 38 ++++++++ src/desktop/Window.hpp | 4 + src/desktop/Workspace.cpp | 10 ++ src/helpers/Box.cpp | 25 ++--- src/helpers/Box.hpp | 2 +- src/managers/AnimationManager.cpp | 94 +++++++----------- src/render/Renderer.cpp | 97 ++++++++----------- src/render/Renderer.hpp | 4 +- .../decorations/CHyprBorderDecoration.cpp | 34 ++++++- .../decorations/CHyprBorderDecoration.hpp | 2 +- .../decorations/CHyprDropShadowDecoration.cpp | 42 +++++++- .../decorations/CHyprDropShadowDecoration.hpp | 2 +- .../decorations/CHyprGroupBarDecoration.cpp | 18 ++-- .../decorations/CHyprGroupBarDecoration.hpp | 2 +- .../decorations/IHyprWindowDecoration.hpp | 2 +- 15 files changed, 229 insertions(+), 147 deletions(-) diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 1336456a..891fd652 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -1165,6 +1165,44 @@ void CWindow::setAnimationsToMove() { m_bAnimatingIn = false; } +void CWindow::onWorkspaceAnimUpdate() { + // clip box for animated offsets + if (!m_bIsFloating || m_bPinned || m_bIsFullscreen) { + m_vFloatingOffset = Vector2D(0, 0); + return; + } + + Vector2D offset; + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + if (!PWORKSPACE) + return; + + const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); + if (!PWSMON) + return; + + const auto WINBB = getFullWindowBoundingBox(); + if (PWORKSPACE->m_vRenderOffset.value().x != 0) { + const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().x / PWSMON->vecSize.x; + + if (WINBB.x < PWSMON->vecPosition.x) + offset.x += (PWSMON->vecPosition.x - WINBB.x) * PROGRESS; + + if (WINBB.x + WINBB.width > PWSMON->vecPosition.x + PWSMON->vecSize.x) + offset.x += (WINBB.x + WINBB.width - PWSMON->vecPosition.x - PWSMON->vecSize.x) * PROGRESS; + } else if (PWORKSPACE->m_vRenderOffset.value().y != 0) { + const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().y / PWSMON->vecSize.y; + + if (WINBB.y < PWSMON->vecPosition.y) + offset.y += (PWSMON->vecPosition.y - WINBB.y) * PROGRESS; + + if (WINBB.y + WINBB.height > PWSMON->vecPosition.y + PWSMON->vecSize.y) + offset.y += (WINBB.y + WINBB.height - PWSMON->vecPosition.y - PWSMON->vecSize.y) * PROGRESS; + } + + m_vFloatingOffset = offset; +} + int CWindow::popupsCount() { if (m_bIsX11) return 1; diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index d8b4012d..bc1820a0 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -237,6 +237,9 @@ class CWindow { Vector2D m_vLastFloatingSize; Vector2D m_vLastFloatingPosition; + // for floating window offset in workspace animations + Vector2D m_vFloatingOffset = Vector2D(0, 0); + // this is used for pseudotiling bool m_bIsPseudotiled = false; Vector2D m_vPseudoSize = Vector2D(0, 0); @@ -421,6 +424,7 @@ class CWindow { void updateGroupOutputs(); void switchWithWindowInGroup(CWindow* pWindow); void setAnimationsToMove(); + void onWorkspaceAnimUpdate(); private: // For hidden windows and stuff diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 05843b59..a0c14bba 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -49,6 +49,16 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; static auto PWORKSPACEGAP = CConfigValue("general:gaps_workspaces"); + // set floating windows offset callbacks + m_vRenderOffset.setUpdateCallback([&](void*) { + for (auto& w : g_pCompositor->m_vWindows) { + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != m_iID) + continue; + + w->onWorkspaceAnimUpdate(); + }; + }); + if (ANIMSTYLE.starts_with("slidefade")) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); float movePerc = 100.f; diff --git a/src/helpers/Box.cpp b/src/helpers/Box.cpp index e9e0eeeb..8470b509 100644 --- a/src/helpers/Box.cpp +++ b/src/helpers/Box.cpp @@ -106,6 +106,11 @@ CBox& CBox::expand(const double& value) { w += value * 2.0; h += value * 2.0; + if (w <= 0 || h <= 0) { + w = 0; + h = 0; + } + return *this; } @@ -116,22 +121,20 @@ CBox& CBox::noNegativeSize() { return *this; } -CBox& CBox::intersection(const CBox other) { - const float newTop = std::max(y, other.y); +CBox CBox::intersection(const CBox other) const { + const float newX = std::max(x, other.x); + const float newY = std::max(y, other.y); const float newBottom = std::min(y + h, other.y + other.h); - const float newLeft = std::max(x, other.x); const float newRight = std::min(x + w, other.x + other.w); - y = newTop; - x = newLeft; - w = newRight - newLeft; - h = newBottom - newTop; + float newW = newRight - newX; + float newH = newBottom - newY; - if (w <= 0 || h <= 0) { - w = 0; - h = 0; + if (newW <= 0 || newH <= 0) { + newW = 0; + newH = 0; } - return *this; + return {newX, newY, newW, newH}; } CBox CBox::roundInternal() { diff --git a/src/helpers/Box.hpp b/src/helpers/Box.hpp index e38d6108..98ba8d47 100644 --- a/src/helpers/Box.hpp +++ b/src/helpers/Box.hpp @@ -52,9 +52,9 @@ class CBox { CBox& addExtents(const SWindowDecorationExtents& e); CBox& expand(const double& value); CBox& noNegativeSize(); - CBox& intersection(const CBox other); CBox copy() const; + CBox intersection(const CBox other) const; SWindowDecorationExtents extentsFrom(const CBox&); // this is the big box diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 93608383..fc768b77 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -87,11 +87,15 @@ void CAnimationManager::tick() { CBox WLRBOXPREV = {0, 0, 0, 0}; if (PWINDOW) { - CBox bb = PWINDOW->getFullWindowBoundingBox(); - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (PWINDOWWORKSPACE) - bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); - WLRBOXPREV = bb; + if (av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) { + g_pHyprRenderer->damageWindow(PWINDOW); + } else if (av->m_eDamagePolicy == AVARDAMAGE_BORDER) { + const auto PDECO = PWINDOW->getDecorationByType(DECORATION_BORDER); + PDECO->damageEntire(); + } else if (av->m_eDamagePolicy == AVARDAMAGE_SHADOW) { + const auto PDECO = PWINDOW->getDecorationByType(DECORATION_SHADOW); + PDECO->damageEntire(); + } PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); if (!PMONITOR) @@ -101,25 +105,35 @@ void CAnimationManager::tick() { PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); if (!PMONITOR) continue; - WLRBOXPREV = {PMONITOR->vecPosition, PMONITOR->vecSize}; + + // dont damage the whole monitor on workspace change, unless it's a special workspace, because dim/blur etc + if (PWORKSPACE->m_bIsSpecialWorkspace) + g_pHyprRenderer->damageMonitor(PMONITOR); // TODO: just make this into a damn callback already vax... for (auto& w : g_pCompositor->m_vWindows) { - if (!w->isHidden() && w->m_bIsMapped && w->m_bIsFloating) - g_pHyprRenderer->damageWindow(w.get()); + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID) + continue; + + if (w->m_bIsFloating && !w->m_bPinned) { + // still doing the full damage hack for floating because sometimes when the window + // goes through multiple monitors the last rendered frame is missing damage somehow?? + const CBox windowBoxNoOffset = w->getFullWindowBoundingBox(); + const CBox monitorBox = {PMONITOR->vecPosition, PMONITOR->vecSize}; + if (windowBoxNoOffset.intersection(monitorBox) != windowBoxNoOffset) // on edges between multiple monitors + g_pHyprRenderer->damageWindow(w.get(), true); + } + + if (PWORKSPACE->m_bIsSpecialWorkspace) + g_pHyprRenderer->damageWindow(w.get(), true); // hack for special too because it can cross multiple monitors } - // if a special workspace window is on any monitor, damage it + // damage any workspace window that is on any monitor for (auto& w : g_pCompositor->m_vWindows) { - for (auto& m : g_pCompositor->m_vMonitors) { - if (w->m_iWorkspaceID == PWORKSPACE->m_iID && PWORKSPACE->m_bIsSpecialWorkspace && g_pCompositor->windowValidMapped(w.get()) && - g_pHyprRenderer->shouldRenderWindow(w.get(), m.get(), PWORKSPACE)) { - CBox bb = w->getFullWindowBoundingBox(); - bb.translate(PWORKSPACE->m_vRenderOffset.value()); - bb.intersection({m->vecPosition, m->vecSize}); - g_pHyprRenderer->damageBox(&bb); - } - } + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->m_bPinned) + continue; + + g_pHyprRenderer->damageWindow(w.get()); } } else if (PLAYER) { WLRBOXPREV = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; @@ -194,26 +208,13 @@ void CAnimationManager::tick() { if (PWINDOW) { PWINDOW->updateWindowDecos(); - auto bb = PWINDOW->getFullWindowBoundingBox(); - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (PWINDOWWORKSPACE) - bb.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); - g_pHyprRenderer->damageBox(&bb); + g_pHyprRenderer->damageWindow(PWINDOW); } else if (PWORKSPACE) { for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden()) - continue; - - if (w->m_iWorkspaceID != PWORKSPACE->m_iID) + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID) continue; w->updateWindowDecos(); - - if (w->m_bIsFloating) { - auto bb = w->getFullWindowBoundingBox(); - bb.translate(PWORKSPACE->m_vRenderOffset.value()); - g_pHyprRenderer->damageBox(&bb); - } } } else if (PLAYER) { if (PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) @@ -229,31 +230,8 @@ void CAnimationManager::tick() { case AVARDAMAGE_BORDER: { RASSERT(PWINDOW, "Tried to AVARDAMAGE_BORDER a non-window AVAR!"); - // TODO: move this to the border class - - // damage only the border. - const auto ROUNDING = PWINDOW->rounding(); - const auto ROUNDINGSIZE = ROUNDING + 1; - const auto BORDERSIZE = PWINDOW->getRealBorderSize(); - - // damage for old box - g_pHyprRenderer->damageBox(WLRBOXPREV.x - BORDERSIZE, WLRBOXPREV.y - BORDERSIZE, WLRBOXPREV.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // top - g_pHyprRenderer->damageBox(WLRBOXPREV.x - BORDERSIZE, WLRBOXPREV.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, WLRBOXPREV.height + 2 * BORDERSIZE); // left - g_pHyprRenderer->damageBox(WLRBOXPREV.x + WLRBOXPREV.width - ROUNDINGSIZE, WLRBOXPREV.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, - WLRBOXPREV.height + 2 * BORDERSIZE); // right - g_pHyprRenderer->damageBox(WLRBOXPREV.x, WLRBOXPREV.y + WLRBOXPREV.height - ROUNDINGSIZE, WLRBOXPREV.width + 2 * BORDERSIZE, - BORDERSIZE + ROUNDINGSIZE); // bottom - - // damage for new box - CBox WLRBOXNEW = {PWINDOW->m_vRealPosition.value(), PWINDOW->m_vRealSize.value()}; - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - if (PWINDOWWORKSPACE) - WLRBOXNEW.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); - g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, WLRBOXNEW.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // top - g_pHyprRenderer->damageBox(WLRBOXNEW.x - BORDERSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, WLRBOXNEW.height + 2 * BORDERSIZE); // left - g_pHyprRenderer->damageBox(WLRBOXNEW.x + WLRBOXNEW.width - ROUNDINGSIZE, WLRBOXNEW.y - BORDERSIZE, BORDERSIZE + ROUNDINGSIZE, - WLRBOXNEW.height + 2 * BORDERSIZE); // right - g_pHyprRenderer->damageBox(WLRBOXNEW.x, WLRBOXNEW.y + WLRBOXNEW.height - ROUNDINGSIZE, WLRBOXNEW.width + 2 * BORDERSIZE, BORDERSIZE + ROUNDINGSIZE); // bottom + const auto PDECO = PWINDOW->getDecorationByType(DECORATION_BORDER); + PDECO->damageEntire(); break; } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 960add70..18110256 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -211,7 +211,7 @@ static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) g_pHyprOpenGL->m_RenderData.useNearestNeighbor = NEARESTNEIGHBORSET; } -bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWorkspace* pWorkspace) { +bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { CBox geometry = pWindow->getFullWindowBoundingBox(); if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr())) @@ -234,9 +234,12 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo } } - if (pWindow->m_iWorkspaceID == pWorkspace->m_iID && pWorkspace->m_iMonitorID == pMonitor->ID) + if (pWindow->m_iMonitorID == pMonitor->ID) return true; + if (!g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID) && pWindow->m_iMonitorID != pMonitor->ID) + return false; + // if not, check if it maybe is active on a different monitor. if (g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) return !pWindow->m_bIsFullscreen; // Do not draw fullscreen windows on other monitors @@ -244,12 +247,20 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor, CWo if (pMonitor->specialWorkspaceID == pWindow->m_iWorkspaceID) return true; + // if window is tiled and it's flying in, don't render on other mons (for slide) + if (!pWindow->m_bIsFloating && pWindow->m_vRealPosition.isBeingAnimated() && pWindow->m_bAnimatingIn && pWindow->m_iMonitorID != pMonitor->ID) + return false; + if (pWindow->m_vRealPosition.isBeingAnimated()) { if (PWINDOWWORKSPACE && !PWINDOWWORKSPACE->m_bIsSpecialWorkspace && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated()) return false; // render window if window and monitor intersect // (when moving out of or through a monitor) - CBox windowBox = pWindow->getFullWindowBoundingBox(); + CBox windowBox = pWindow->getFullWindowBoundingBox(); + if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated()) + windowBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + windowBox.translate(pWindow->m_vFloatingOffset); + const CBox monitorBox = {pMonitor->vecPosition, pMonitor->vecSize}; if (!windowBox.intersection(monitorBox).empty()) return true; @@ -292,7 +303,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp // loop over the tiled windows that are fading out for (auto& w : g_pCompositor->m_vWindows) { - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; if (w->m_fAlpha.value() == 0.f) @@ -309,7 +320,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp // and floating ones too for (auto& w : g_pCompositor->m_vWindows) { - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; if (w->m_fAlpha.value() == 0.f) @@ -345,7 +356,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) continue; - if (shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (shouldRenderWindow(w.get(), pMonitor)) renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL); if (w->m_iWorkspaceID != pWorkspace->m_iID) @@ -388,7 +399,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (w->m_bIsFloating) continue; // floating are in the second pass - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) @@ -418,7 +429,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) continue; - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; // render the bad boy @@ -433,7 +444,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (!w->m_bIsFloating || w->m_bPinned) continue; - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) @@ -510,47 +521,16 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, *PDIMAROUND * renderdata.alpha * renderdata.fadeAlpha)); } - // clip box for animated offsets - const Vector2D PREOFFSETPOS = {renderdata.x, renderdata.y}; - if (!ignorePosition && pWindow->m_bIsFloating && !pWindow->m_bPinned && !pWindow->m_bIsFullscreen) { - Vector2D offset; - - if (PWORKSPACE->m_vRenderOffset.value().x != 0) { - const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().x / PWSMON->vecSize.x; - const auto WINBB = pWindow->getFullWindowBoundingBox(); - - if (WINBB.x < PWSMON->vecPosition.x) { - offset.x = (PWSMON->vecPosition.x - WINBB.x) * PROGRESS; - } else if (WINBB.x + WINBB.width > PWSMON->vecPosition.x + PWSMON->vecSize.x) { - offset.x = (WINBB.x + WINBB.width - PWSMON->vecPosition.x - PWSMON->vecSize.x) * PROGRESS; - } - } else if (PWORKSPACE->m_vRenderOffset.value().y != 0) { - const auto PWSMON = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); - const auto PROGRESS = PWORKSPACE->m_vRenderOffset.value().y / PWSMON->vecSize.y; - const auto WINBB = pWindow->getFullWindowBoundingBox(); - - if (WINBB.y < PWSMON->vecPosition.y) { - offset.y = (PWSMON->vecPosition.y - WINBB.y) * PROGRESS; - } else if (WINBB.y + WINBB.height > PWSMON->vecPosition.y + PWSMON->vecSize.y) { - offset.y = (WINBB.y + WINBB.width - PWSMON->vecPosition.y - PWSMON->vecSize.y) * PROGRESS; - } - } - - renderdata.x += offset.x; - renderdata.y += offset.y; - } + renderdata.x += pWindow->m_vFloatingOffset.x; + renderdata.y += pWindow->m_vFloatingOffset.y; // if window is floating and we have a slide animation, clip it to its full bb if (!ignorePosition && pWindow->m_bIsFloating && !pWindow->m_bIsFullscreen && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !pWindow->m_bPinned) { - CRegion rg = pWindow->getFullWindowBoundingBox().translate(-pMonitor->vecPosition + PWORKSPACE->m_vRenderOffset.value()).scale(pMonitor->scale); + CRegion rg = + pWindow->getFullWindowBoundingBox().translate(-pMonitor->vecPosition + PWORKSPACE->m_vRenderOffset.value() + pWindow->m_vFloatingOffset).scale(pMonitor->scale); g_pHyprOpenGL->m_RenderData.clipBox = rg.getExtents(); } - // if window is tiled and it's flying in, don't render on other mons (for slide) - if (!ignorePosition && !pWindow->m_bIsFloating && pWindow->m_vRealPosition.isBeingAnimated() && pWindow->m_bAnimatingIn && pWindow->m_iMonitorID != pMonitor->ID) - return; - // render window decorations first, if not fullscreen full if (mode == RENDER_PASS_ALL || mode == RENDER_PASS_MAIN) { @@ -569,14 +549,14 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (wd->getDecorationLayer() != DECORATION_LAYER_BOTTOM) continue; - wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha, Vector2D{renderdata.x, renderdata.y} - PREOFFSETPOS); + wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha); } for (auto& wd : pWindow->m_dWindowDecorations) { if (wd->getDecorationLayer() != DECORATION_LAYER_UNDER) continue; - wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha, Vector2D{renderdata.x, renderdata.y} - PREOFFSETPOS); + wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha); } } @@ -601,7 +581,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (wd->getDecorationLayer() != DECORATION_LAYER_OVER) continue; - wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha, Vector2D{renderdata.x, renderdata.y} - PREOFFSETPOS); + wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha); } } @@ -662,7 +642,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* if (wd->getDecorationLayer() != DECORATION_LAYER_OVERLAY) continue; - wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha, Vector2D{renderdata.x, renderdata.y} - PREOFFSETPOS); + wd->draw(pMonitor, renderdata.alpha * renderdata.fadeAlpha); } } } @@ -861,7 +841,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* if (!w->m_bPinned || !w->m_bIsFloating) continue; - if (!shouldRenderWindow(w.get(), pMonitor, pWorkspace)) + if (!shouldRenderWindow(w.get(), pMonitor)) continue; // render the bad boy @@ -1739,15 +1719,22 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou damageBox.pixman()->extents.x2 - damageBox.pixman()->extents.x1, damageBox.pixman()->extents.y2 - damageBox.pixman()->extents.y1); } -void CHyprRenderer::damageWindow(CWindow* pWindow) { +void CHyprRenderer::damageWindow(CWindow* pWindow, bool forceFull) { if (g_pCompositor->m_bUnsafeState) return; - CBox damageBox = pWindow->getFullWindowBoundingBox(); + CBox windowBox = pWindow->getFullWindowBoundingBox(); + const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !pWindow->m_bPinned) + windowBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + windowBox.translate(pWindow->m_vFloatingOffset); + for (auto& m : g_pCompositor->m_vMonitors) { - CBox fixedDamageBox = {damageBox.x - m->vecPosition.x, damageBox.y - m->vecPosition.y, damageBox.width, damageBox.height}; - fixedDamageBox.scale(m->scale); - m->addDamage(&fixedDamageBox); + if (g_pHyprRenderer->shouldRenderWindow(pWindow, m.get()) || forceFull) { // only damage if window is rendered on monitor + CBox fixedDamageBox = {windowBox.x - m->vecPosition.x, windowBox.y - m->vecPosition.y, windowBox.width, windowBox.height}; + fixedDamageBox.scale(m->scale); + m->addDamage(&fixedDamageBox); + } } for (auto& wd : pWindow->m_dWindowDecorations) @@ -1756,7 +1743,7 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); if (*PLOGDAMAGE) - Debug::log(LOG, "Damage: Window ({}): xy: {}, {} wh: {}, {}", pWindow->m_szTitle, damageBox.x, damageBox.y, damageBox.width, damageBox.height); + Debug::log(LOG, "Damage: Window ({}): xy: {}, {} wh: {}, {}", pWindow->m_szTitle, windowBox.x, windowBox.y, windowBox.width, windowBox.height); } void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 0a684af3..613706a5 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -46,14 +46,14 @@ class CHyprRenderer { void outputMgrApplyTest(wlr_output_configuration_v1*, bool); void arrangeLayersForMonitor(const int&); void damageSurface(wlr_surface*, double, double, double scale = 1.0); - void damageWindow(CWindow*); + void damageWindow(CWindow*, bool forceFull = false); void damageBox(CBox*); void damageBox(const int& x, const int& y, const int& w, const int& h); void damageRegion(const CRegion&); void damageMonitor(CMonitor*); void damageMirrorsWith(CMonitor*, const CRegion&); bool applyMonitorRule(CMonitor*, SMonitorRule*, bool force = false); - bool shouldRenderWindow(CWindow*, CMonitor*, CWorkspace*); + bool shouldRenderWindow(CWindow*, CMonitor*); bool shouldRenderWindow(CWindow*); void ensureCursorRenderingMode(); bool shouldRenderCursor(); diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index ea40ee65..4981d2ea 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -45,14 +45,14 @@ CBox CHyprBorderDecoration::assignedBoxGlobal() { return box.translate(WORKSPACEOFFSET); } -void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) { +void CHyprBorderDecoration::draw(CMonitor* pMonitor, float a) { if (doesntWantBorders()) return; if (m_bAssignedGeometry.width < m_seExtents.topLeft.x + 1 || m_bAssignedGeometry.height < m_seExtents.topLeft.y + 1) return; - CBox windowBox = assignedBoxGlobal().translate(-pMonitor->vecPosition + offset).expand(-m_pWindow->getRealBorderSize()).scale(pMonitor->scale).round(); + CBox windowBox = assignedBoxGlobal().translate(-pMonitor->vecPosition + m_pWindow->m_vFloatingOffset).expand(-m_pWindow->getRealBorderSize()).scale(pMonitor->scale).round(); if (windowBox.width < 1 || windowBox.height < 1) return; @@ -87,7 +87,35 @@ void CHyprBorderDecoration::updateWindow(CWindow*) { } void CHyprBorderDecoration::damageEntire() { - ; // ignored, done in animationManager. todo, move. + if (!g_pCompositor->windowValidMapped(m_pWindow)) + return; + + auto surfaceBox = m_pWindow->getWindowMainSurfaceBox(); + const auto ROUNDING = m_pWindow->rounding(); + const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1; + const auto BORDERSIZE = m_pWindow->getRealBorderSize(); + + const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) + surfaceBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); + surfaceBox.translate(m_pWindow->m_vFloatingOffset); + + CBox surfaceBoxExpandedBorder = surfaceBox; + surfaceBoxExpandedBorder.expand(BORDERSIZE); + CBox surfaceBoxShrunkRounding = surfaceBox; + surfaceBoxShrunkRounding.expand(-ROUNDINGSIZE); + + CRegion borderRegion(surfaceBoxExpandedBorder); + borderRegion.subtract(surfaceBoxShrunkRounding); + + for (auto& m : g_pCompositor->m_vMonitors) { + if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow, m.get())) { + const CRegion monitorRegion({m->vecPosition, m->vecSize}); + borderRegion.subtract(monitorRegion); + } + } + + g_pHyprRenderer->damageRegion(borderRegion); } eDecorationLayer CHyprBorderDecoration::getDecorationLayer() { diff --git a/src/render/decorations/CHyprBorderDecoration.hpp b/src/render/decorations/CHyprBorderDecoration.hpp index 9c0bcc33..9b9df7ab 100644 --- a/src/render/decorations/CHyprBorderDecoration.hpp +++ b/src/render/decorations/CHyprBorderDecoration.hpp @@ -11,7 +11,7 @@ class CHyprBorderDecoration : public IHyprWindowDecoration { virtual void onPositioningReply(const SDecorationPositioningReply& reply); - virtual void draw(CMonitor*, float a, const Vector2D& offset); + virtual void draw(CMonitor*, float a); virtual eDecorationType getDecorationType(); diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 588b23a4..99d08828 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -41,9 +41,37 @@ void CHyprDropShadowDecoration::damageEntire() { if (*PSHADOWS != 1) return; // disabled - CBox dm = {m_vLastWindowPos.x - m_seExtents.topLeft.x, m_vLastWindowPos.y - m_seExtents.topLeft.y, m_vLastWindowSize.x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, - m_vLastWindowSize.y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; - g_pHyprRenderer->damageBox(&dm); + CBox shadowBox = {m_pWindow->m_vRealPosition.value().x - m_seExtents.topLeft.x, m_pWindow->m_vRealPosition.value().y - m_seExtents.topLeft.y, + m_pWindow->m_vRealSize.value().x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, + m_pWindow->m_vRealSize.value().y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; + + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) + shadowBox.translate(PWORKSPACE->m_vRenderOffset.value()); + shadowBox.translate(m_pWindow->m_vFloatingOffset); + + static auto PSHADOWIGNOREWINDOW = CConfigValue("decoration:shadow_ignore_window"); + const auto ROUNDING = m_pWindow->rounding(); + const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1; + + CRegion shadowRegion(shadowBox); + if (*PSHADOWIGNOREWINDOW) { + CBox surfaceBox = m_pWindow->getWindowMainSurfaceBox(); + if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) + surfaceBox.translate(PWORKSPACE->m_vRenderOffset.value()); + surfaceBox.translate(m_pWindow->m_vFloatingOffset); + surfaceBox.expand(-ROUNDINGSIZE); + shadowRegion.subtract(CRegion(surfaceBox)); + } + + for (auto& m : g_pCompositor->m_vMonitors) { + if (!g_pHyprRenderer->shouldRenderWindow(m_pWindow, m.get())) { + const CRegion monitorRegion({m->vecPosition, m->vecSize}); + shadowRegion.subtract(monitorRegion); + } + } + + g_pHyprRenderer->damageRegion(shadowRegion); } void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { @@ -54,7 +82,7 @@ void CHyprDropShadowDecoration::updateWindow(CWindow* pWindow) { m_bLastWindowBoxWithDecos = g_pDecorationPositioner->getBoxWithIncludedDecos(pWindow); } -void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) { +void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) { if (!g_pCompositor->windowValidMapped(m_pWindow)) return; @@ -98,12 +126,13 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D // scale the box in relation to the center of the box fullBox.scaleFromCenter(SHADOWSCALE).translate(*PSHADOWOFFSET); + updateWindow(m_pWindow); m_vLastWindowPos += WORKSPACEOFFSET; m_seExtents = {{m_vLastWindowPos.x - fullBox.x - pMonitor->vecPosition.x + 2, m_vLastWindowPos.y - fullBox.y - pMonitor->vecPosition.y + 2}, {fullBox.x + fullBox.width + pMonitor->vecPosition.x - m_vLastWindowPos.x - m_vLastWindowSize.x + 2, fullBox.y + fullBox.height + pMonitor->vecPosition.y - m_vLastWindowPos.y - m_vLastWindowSize.y + 2}}; - fullBox.translate(offset); + fullBox.translate(m_pWindow->m_vFloatingOffset); if (fullBox.width < 1 || fullBox.height < 1) return; // don't draw invisible shadows @@ -125,6 +154,9 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D windowBox.translate(-pMonitor->vecPosition + WORKSPACEOFFSET); withDecos.translate(-pMonitor->vecPosition + WORKSPACEOFFSET); + windowBox.translate(m_pWindow->m_vFloatingOffset); + withDecos.translate(m_pWindow->m_vFloatingOffset); + auto scaledExtentss = withDecos.extentsFrom(windowBox); scaledExtentss = scaledExtentss * pMonitor->scale; scaledExtentss = scaledExtentss.round(); diff --git a/src/render/decorations/CHyprDropShadowDecoration.hpp b/src/render/decorations/CHyprDropShadowDecoration.hpp index 3b389550..fcc5f873 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.hpp +++ b/src/render/decorations/CHyprDropShadowDecoration.hpp @@ -11,7 +11,7 @@ class CHyprDropShadowDecoration : public IHyprWindowDecoration { virtual void onPositioningReply(const SDecorationPositioningReply& reply); - virtual void draw(CMonitor*, float a, const Vector2D& offset); + virtual void draw(CMonitor*, float a); virtual eDecorationType getDecorationType(); diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index a03d97f9..ce683ac1 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -83,10 +83,11 @@ void CHyprGroupBarDecoration::updateWindow(CWindow* pWindow) { void CHyprGroupBarDecoration::damageEntire() { auto box = assignedBoxGlobal(); + box.translate(m_pWindow->m_vFloatingOffset); g_pHyprRenderer->damageBox(&box); } -void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& offset) { +void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a) { // get how many bars we will draw int barsToDraw = m_dwGroupMembers.size(); @@ -110,8 +111,9 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& int xoff = 0; for (int i = 0; i < barsToDraw; ++i) { - CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + offset.x, - ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + offset.y, m_fBarWidth, BAR_INDICATOR_HEIGHT}; + CBox rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, + ASSIGNEDBOX.y + ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y, m_fBarWidth, + BAR_INDICATOR_HEIGHT}; if (rect.width <= 0 || rect.height <= 0) break; @@ -135,7 +137,8 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& color.a *= a; g_pHyprOpenGL->renderRect(&rect, color); - rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + offset.x, ASSIGNEDBOX.y - pMonitor->vecPosition.y + offset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth, + rect = {ASSIGNEDBOX.x + xoff - pMonitor->vecPosition.x + m_pWindow->m_vFloatingOffset.x, + ASSIGNEDBOX.y - pMonitor->vecPosition.y + m_pWindow->m_vFloatingOffset.y + BAR_PADDING_OUTER_VERT, m_fBarWidth, ASSIGNEDBOX.h - BAR_INDICATOR_HEIGHT - BAR_PADDING_OUTER_VERT * 2}; rect.scale(pMonitor->scale); @@ -505,9 +508,8 @@ CBox CHyprGroupBarDecoration::assignedBoxGlobal() { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); - if (!PWORKSPACE) - return box; + if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) + box.translate(PWORKSPACE->m_vRenderOffset.value()); - const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); - return box.translate(WORKSPACEOFFSET); + return box; } diff --git a/src/render/decorations/CHyprGroupBarDecoration.hpp b/src/render/decorations/CHyprGroupBarDecoration.hpp index 04f5123b..24635f6e 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.hpp +++ b/src/render/decorations/CHyprGroupBarDecoration.hpp @@ -27,7 +27,7 @@ class CHyprGroupBarDecoration : public IHyprWindowDecoration { virtual void onPositioningReply(const SDecorationPositioningReply& reply); - virtual void draw(CMonitor*, float a, const Vector2D& offset); + virtual void draw(CMonitor*, float a); virtual eDecorationType getDecorationType(); diff --git a/src/render/decorations/IHyprWindowDecoration.hpp b/src/render/decorations/IHyprWindowDecoration.hpp index d3d1a5dd..10426439 100644 --- a/src/render/decorations/IHyprWindowDecoration.hpp +++ b/src/render/decorations/IHyprWindowDecoration.hpp @@ -39,7 +39,7 @@ class IHyprWindowDecoration { virtual void onPositioningReply(const SDecorationPositioningReply& reply) = 0; - virtual void draw(CMonitor*, float a, const Vector2D& offset = Vector2D()) = 0; + virtual void draw(CMonitor*, float a) = 0; virtual eDecorationType getDecorationType() = 0; From e1e41e54480282d9bec9957d3c578eb87bc1f2f2 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 31 Mar 2024 06:59:22 -0700 Subject: [PATCH 0218/2897] reenderer: Add 1 border damage to fix number rounding issues (#5343) * add 1 to border damage to avoid rounding issues * add 1 to rounding too --- src/render/decorations/CHyprBorderDecoration.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 4981d2ea..76e60348 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -92,8 +92,8 @@ void CHyprBorderDecoration::damageEntire() { auto surfaceBox = m_pWindow->getWindowMainSurfaceBox(); const auto ROUNDING = m_pWindow->rounding(); - const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 1; - const auto BORDERSIZE = m_pWindow->getRealBorderSize(); + const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 2; + const auto BORDERSIZE = m_pWindow->getRealBorderSize() + 1; const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) From 4156b55cf91a7cb90fd14582a1c5a9df5792933e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 31 Mar 2024 21:30:30 +0100 Subject: [PATCH 0219/2897] textinput: send deactivate on disable ti ref #5288 --- src/managers/input/TextInput.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index eeea899d..6b6f38c8 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -96,6 +96,9 @@ void CTextInput::onDisabled() { hyprListener_surfaceDestroyed.removeCallback(); hyprListener_surfaceUnmapped.removeCallback(); + if (!g_pInputManager->m_sIMERelay.m_pWLRIME->active) + return; + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); g_pInputManager->m_sIMERelay.commitIMEState(this); } @@ -204,6 +207,12 @@ void CTextInput::leave() { } setFocusedSurface(nullptr); + + if (!g_pInputManager->m_sIMERelay.m_pWLRIME->active) + return; + + wlr_input_method_v2_send_deactivate(g_pInputManager->m_sIMERelay.m_pWLRIME); + g_pInputManager->m_sIMERelay.commitIMEState(this); } wlr_surface* CTextInput::focusedSurface() { From 64c8ba2fb1977a055b9718c7c7cfb1740756d963 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 31 Mar 2024 21:34:11 +0100 Subject: [PATCH 0220/2897] avar: fix warp onEnd conditions ref #5348 --- src/helpers/AnimatedVariable.hpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 82e30892..2add41be 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -279,7 +279,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable { } void warp(bool endCallback = true) override { - if (m_Value == m_Goal) + if (!m_bIsBeingAnimated) return; m_Value = m_Goal; @@ -289,8 +289,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable { if (m_fUpdateCallback) m_fUpdateCallback(this); - if (endCallback) - onAnimationEnd(); + onAnimationEnd(); } private: From 9e8f0518961041b60e6c4843f545734e833d5355 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 31 Mar 2024 21:43:08 +0100 Subject: [PATCH 0221/2897] avar: minor fixes --- src/helpers/AnimatedVariable.hpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 2add41be..85ffb9ab 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -274,7 +274,8 @@ class CAnimatedVariable : public CBaseAnimatedVariable { // Sets the actual value and goal void setValueAndWarp(const VarType& v) { - m_Goal = v; + m_Goal = v; + m_bIsBeingAnimated = true; warp(); } @@ -289,7 +290,8 @@ class CAnimatedVariable : public CBaseAnimatedVariable { if (m_fUpdateCallback) m_fUpdateCallback(this); - onAnimationEnd(); + if (endCallback) + onAnimationEnd(); } private: From 8cb38d41d203f95ea9c2be79996a5f0deda3eabf Mon Sep 17 00:00:00 2001 From: Micovec <30734146+Micovec@users.noreply.github.com> Date: Sun, 31 Mar 2024 22:45:22 +0200 Subject: [PATCH 0222/2897] hyprctl: fix plugin list on no plugins (#5357) --- src/debug/HyprCtl.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index 903b7d7f..f61f5544 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -1449,7 +1449,10 @@ std::string dispatchPlugin(eHyprCtlOutputFormat format, std::string request) { g_pPluginSystem->unloadPlugin(PLUGIN); } else if (OPERATION == "list") { - const auto PLUGINS = g_pPluginSystem->getAllPlugins(); + const auto PLUGINS = g_pPluginSystem->getAllPlugins(); + + if (PLUGINS.size() == 0) + return "no plugins loaded"; std::string list = ""; for (auto& p : PLUGINS) { From ecc1f22e050e6542948fd022694d1d7f8716a560 Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Mon, 1 Apr 2024 08:41:00 +0900 Subject: [PATCH 0223/2897] textinput: fix typo (#5365) --- src/managers/input/TextInput.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/input/TextInput.cpp b/src/managers/input/TextInput.cpp index 6b6f38c8..8be13a4c 100644 --- a/src/managers/input/TextInput.cpp +++ b/src/managers/input/TextInput.cpp @@ -194,7 +194,7 @@ void CTextInput::leave() { return; enterLocks--; - if (enterLocks != 1) { + if (enterLocks != 0) { Debug::log(ERR, "BUG THIS: TextInput has != 0 locks in leave"); enterLocks = 0; } From 9ae0c47a21476d064ab93b6fb87cedbf20096b8e Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 31 Mar 2024 18:58:21 -0700 Subject: [PATCH 0224/2897] deco: fix groupbar offset (#5364) --- src/render/decorations/CHyprGroupBarDecoration.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index ce683ac1..50bf4627 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -508,7 +508,7 @@ CBox CHyprGroupBarDecoration::assignedBoxGlobal() { const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); - if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) + if (PWORKSPACE && !m_pWindow->m_bPinned) box.translate(PWORKSPACE->m_vRenderOffset.value()); return box; From ef7ac53e99c9c443241fd50a38e6edf528df3d7b Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Sun, 31 Mar 2024 19:02:47 -0700 Subject: [PATCH 0225/2897] master: Make master workspace orientation rule dynamic (#5339) * make master workspace orientation rule dynamic * fix rebase * fix special ws resizing * style --- src/layout/MasterLayout.cpp | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 9c49197e..cac64c6d 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -53,17 +53,16 @@ SMasterWorkspaceData* CHyprMasterLayout::getMasterWorkspaceData(const int& ws) { orientationForWs = wsRule.layoutopts.at("orientation"); } - if (orientationForWs == "top") { + if (orientationForWs == "top") PWORKSPACEDATA->orientation = ORIENTATION_TOP; - } else if (orientationForWs == "right") { + else if (orientationForWs == "right") PWORKSPACEDATA->orientation = ORIENTATION_RIGHT; - } else if (orientationForWs == "bottom") { + else if (orientationForWs == "bottom") PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; - } else if (orientationForWs == "center") { + else if (orientationForWs == "center") PWORKSPACEDATA->orientation = ORIENTATION_CENTER; - } else { + else PWORKSPACEDATA->orientation = ORIENTATION_LEFT; - } return PWORKSPACEDATA; } @@ -339,6 +338,26 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { if (!PMASTERNODE) return; + // dynamic workspace rules + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(ws)); + std::string orientationForWs; + + for (auto& wsRule : WORKSPACERULES) { + if (wsRule.layoutopts.contains("orientation")) + orientationForWs = wsRule.layoutopts.at("orientation"); + } + + if (orientationForWs == "top") + PWORKSPACEDATA->orientation = ORIENTATION_TOP; + else if (orientationForWs == "right") + PWORKSPACEDATA->orientation = ORIENTATION_RIGHT; + else if (orientationForWs == "bottom") + PWORKSPACEDATA->orientation = ORIENTATION_BOTTOM; + else if (orientationForWs == "center") + PWORKSPACEDATA->orientation = ORIENTATION_CENTER; + else if (orientationForWs == "left") + PWORKSPACEDATA->orientation = ORIENTATION_LEFT; + eOrientation orientation = PWORKSPACEDATA->orientation; bool centerMasterWindow = false; static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); @@ -753,7 +772,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne } const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PMONITOR->activeWorkspace); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); From 416b3d6167a996c7e94bd537cec20a12a0784efa Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 1 Apr 2024 03:54:05 +0100 Subject: [PATCH 0226/2897] socket2: sanitize data for newlines --- src/managers/EventManager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/managers/EventManager.cpp b/src/managers/EventManager.cpp index 8365c8c8..57824430 100644 --- a/src/managers/EventManager.cpp +++ b/src/managers/EventManager.cpp @@ -15,6 +15,7 @@ #include #include +#include CEventManager::CEventManager() {} @@ -139,7 +140,9 @@ void CEventManager::postEvent(const SHyprIPCEvent event) { } std::thread( - [&](const SHyprIPCEvent ev) { + [this](SHyprIPCEvent ev) { + std::replace(ev.data.begin(), ev.data.end(), '\n', ' '); + eventQueueMutex.lock(); m_dQueuedEvents.push_back(ev); eventQueueMutex.unlock(); From 800dbf71b0db04bf43ff5a87a9cff6e48de325a2 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 1 Apr 2024 08:16:18 -0700 Subject: [PATCH 0227/2897] renderer: Fix rendering when swiping workspaces (#5367) * fix rendering on swiping * add alpha check * fix floating fs check --- src/render/Renderer.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 18110256..aecd9524 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -225,13 +225,16 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_iMonitorID == pMonitor->ID) { - if (PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() || PWINDOWWORKSPACE->m_bForceRendering) { + if (PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() || PWINDOWWORKSPACE->m_bForceRendering) return true; - } else { - if (PWINDOWWORKSPACE->m_bHasFullscreenWindow && !pWindow->m_bIsFullscreen && !pWindow->m_bIsFloating && !pWindow->m_bCreatedOverFullscreen && - pWindow->m_fAlpha.value() == 0) - return false; - } + + // if hidden behind fullscreen + if (PWINDOWWORKSPACE->m_bHasFullscreenWindow && !pWindow->m_bIsFullscreen && (!pWindow->m_bIsFloating || !pWindow->m_bCreatedOverFullscreen) && + pWindow->m_fAlpha.value() == 0) + return false; + + if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID)) + return false; } if (pWindow->m_iMonitorID == pMonitor->ID) From 7513c0cea59f4e1f5336dc31ebfabd8362e02d69 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Mon, 1 Apr 2024 08:21:45 -0700 Subject: [PATCH 0228/2897] renderer: Fix layer and window damage sometimes missing 1 frame (#5370) * fix the layer and window damage missing 1 frame sometimes * remove extra loop --- src/managers/AnimationManager.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index fc768b77..6cc89cde 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -85,7 +85,6 @@ void CAnimationManager::tick() { CMonitor* PMONITOR = nullptr; bool animationsDisabled = animGlobalDisabled; - CBox WLRBOXPREV = {0, 0, 0, 0}; if (PWINDOW) { if (av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) { g_pHyprRenderer->damageWindow(PWINDOW); @@ -136,8 +135,12 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(w.get()); } } else if (PLAYER) { - WLRBOXPREV = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; - PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f); + // "some fucking layers miss 1 pixel???" -- vaxry + CBox expandBox = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; + expandBox.expand(5); + g_pHyprRenderer->damageBox(&expandBox); + + PMONITOR = g_pCompositor->getMonitorFromVector(Vector2D(PLAYER->geometry.x, PLAYER->geometry.y) + Vector2D(PLAYER->geometry.width, PLAYER->geometry.height) / 2.f); if (!PMONITOR) continue; animationsDisabled = animationsDisabled || PLAYER->noAnimations; @@ -204,8 +207,6 @@ void CAnimationManager::tick() { switch (av->m_eDamagePolicy) { case AVARDAMAGE_ENTIRE: { - g_pHyprRenderer->damageBox(&WLRBOXPREV); - if (PWINDOW) { PWINDOW->updateWindowDecos(); g_pHyprRenderer->damageWindow(PWINDOW); @@ -215,13 +216,17 @@ void CAnimationManager::tick() { continue; w->updateWindowDecos(); + + // damage any workspace window that is on any monitor + if (!w->m_bPinned) + g_pHyprRenderer->damageWindow(w.get()); } } else if (PLAYER) { if (PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND || PLAYER->layer == ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM) g_pHyprOpenGL->markBlurDirtyForMonitor(PMONITOR); // some fucking layers miss 1 pixel??? - CBox expandBox = WLRBOXPREV; + CBox expandBox = CBox{PLAYER->realPosition.value(), PLAYER->realSize.value()}; expandBox.expand(5); g_pHyprRenderer->damageBox(&expandBox); } From 108163f1e5e0e1423a170e78688a826963ec7a81 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 1 Apr 2024 16:22:21 +0100 Subject: [PATCH 0229/2897] animations: simplify window loop --- src/managers/AnimationManager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 6cc89cde..ab81841c 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -111,7 +111,7 @@ void CAnimationManager::tick() { // TODO: just make this into a damn callback already vax... for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID) + if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != PWORKSPACE->m_iID) continue; if (w->m_bIsFloating && !w->m_bPinned) { From db1506130b507f92e0daf3a36495fb985e242bbc Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Tue, 2 Apr 2024 00:37:59 +0900 Subject: [PATCH 0230/2897] IME: Fix ime popup coordinates and artifacts (#5373) * ime: fix incorrect popup coordinate * ime: fix popup artifacts --- src/managers/input/InputMethodPopup.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 326b982e..3332e9c3 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -77,10 +77,8 @@ void CInputPopup::damageEntire() { return; } - Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos(); - CBox global = lastBoxLocal.copy().translate(pos); - - g_pHyprRenderer->damageBox(&global); + Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos(); + g_pHyprRenderer->damageBox(pos.x, pos.y, surface.wlr()->current.width, surface.wlr()->current.height); } void CInputPopup::damageSurface() { @@ -127,7 +125,9 @@ void CInputPopup::updateBox() { CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle()); if (cursorBoxLocal.y + parentBox.y + surface.wlr()->current.height + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) - cursorBoxLocal.y -= surface.wlr()->current.height + cursorBoxLocal.height; + cursorBoxLocal.y -= surface.wlr()->current.height; + else + cursorBoxLocal.y += cursorBoxLocal.height; if (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); From 3875679755014997776e091ff8903acfb311dd2f Mon Sep 17 00:00:00 2001 From: Vaxry Date: Mon, 1 Apr 2024 19:30:37 +0100 Subject: [PATCH 0231/2897] props: bump ver to 0.38.0 --- props.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/props.json b/props.json index 81f6a4cb..dba78901 100644 --- a/props.json +++ b/props.json @@ -1,3 +1,3 @@ { - "version": "0.37.1" + "version": "0.38.0" } \ No newline at end of file From c377caee7abcd093fd09c386b20c32f291e86747 Mon Sep 17 00:00:00 2001 From: Jan Beich Date: Mon, 1 Apr 2024 20:18:18 +0000 Subject: [PATCH 0232/2897] hyprerror: align 32-bit types after 4c796683c05a (#5375) src/hyprerror/HyprError.cpp:64:33: error: no matching function for call to 'min' const auto VISLINECOUNT = std::min(LINECOUNT, *LINELIMIT); ^~~~~~~~ /usr/include/c++/v1/__algorithm/min.h:40:1: note: candidate template ignored: deduced conflicting types for parameter '_Tp' ('int' vs. 'long long') min(const _Tp& __a, const _Tp& __b) ^ /usr/include/c++/v1/__algorithm/min.h:51:1: note: candidate template ignored: could not match 'initializer_list<_Tp>' against 'int' min(initializer_list<_Tp> __t, _Compare __comp) ^ /usr/include/c++/v1/__algorithm/min.h:60:1: note: candidate function template not viable: requires single argument '__t', but 2 arguments were provided min(initializer_list<_Tp> __t) ^ /usr/include/c++/v1/__algorithm/min.h:31:1: note: candidate function template not viable: requires 3 arguments, but 2 were provided min(const _Tp& __a, const _Tp& __b, _Compare __comp) ^ --- src/hyprerror/HyprError.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hyprerror/HyprError.cpp b/src/hyprerror/HyprError.cpp index 73f9c5d5..de386097 100644 --- a/src/hyprerror/HyprError.cpp +++ b/src/hyprerror/HyprError.cpp @@ -58,7 +58,7 @@ void CHyprError::createQueued() { cairo_paint(CAIRO); cairo_restore(CAIRO); - const auto LINECOUNT = 1 + std::count(m_szQueued.begin(), m_szQueued.end(), '\n'); + const auto LINECOUNT = Hyprlang::INT{1} + std::count(m_szQueued.begin(), m_szQueued.end(), '\n'); static auto LINELIMIT = CConfigValue("debug:error_limit"); const auto VISLINECOUNT = std::min(LINECOUNT, *LINELIMIT); From af3a61a4e437fe728ef69c2739cae79e5a6254c0 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 2 Apr 2024 01:15:58 +0100 Subject: [PATCH 0233/2897] core: assert attempted UAFs in windowExists in prep of removing the thing altogether --- src/Compositor.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3ac9a73f..5fefb2b8 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -704,6 +704,11 @@ bool CCompositor::windowExists(CWindow* pWindow) { return true; } + // FIXME: this is here only temporarily, + // remove this func altogether if no reports + // of this being hit. + RASSERT(!pWindow, "windowExists: attempted UAF"); + return false; } @@ -1388,7 +1393,7 @@ bool CCompositor::isWindowActive(CWindow* pWindow) { if (!m_pLastWindow && !m_pLastFocus) return false; - if (!windowValidMapped(pWindow)) + if (!pWindow->m_bIsMapped) return false; const auto PSURFACE = pWindow->m_pWLSurface.wlr(); From 2e5b146e57364795aabeb2dea6fd2257db8b2c3a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 2 Apr 2024 12:10:03 +0100 Subject: [PATCH 0234/2897] workspace: remove lastFocusedWindow on unmap --- src/desktop/Workspace.cpp | 9 +++++++++ src/desktop/Workspace.hpp | 3 +++ 2 files changed, 12 insertions(+) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index a0c14bba..9200b4d7 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -30,6 +30,13 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_szName = rule.defaultName.value(); } + m_pFocusedWindowHook = g_pHookSystem->hookDynamic("closeWindow", [this](void* self, SCallbackInfo& info, std::any param) { + const auto PWINDOW = std::any_cast(param); + + if (PWINDOW == m_pLastFocusedWindow) + m_pLastFocusedWindow = nullptr; + }); + g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("createWorkspace", this); @@ -40,6 +47,8 @@ CWorkspace::~CWorkspace() { Debug::log(LOG, "Destroying workspace ID {}", m_iID); + g_pHookSystem->unhook(m_pFocusedWindowHook); + g_pEventManager->postEvent({"destroyworkspace", m_szName}); g_pEventManager->postEvent({"destroyworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("destroyWorkspace", this); diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index f1bdb333..0cae1859 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -66,4 +66,7 @@ class CWorkspace { std::string getConfigName(); bool matchesStaticSelector(const std::string& selector); + + private: + HOOK_CALLBACK_FN* m_pFocusedWindowHook = nullptr; }; From 04a35891a1cef8d1b5aad4229186611fcf096f1b Mon Sep 17 00:00:00 2001 From: Sungyoon Cho Date: Tue, 2 Apr 2024 20:22:41 +0900 Subject: [PATCH 0235/2897] IME: fix incorrect popup damage (#5383) --- src/managers/input/InputMethodPopup.cpp | 21 +++++++++++++-------- src/managers/input/InputMethodPopup.hpp | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 3332e9c3..36f25dd7 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -77,8 +77,10 @@ void CInputPopup::damageEntire() { return; } - Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos(); - g_pHyprRenderer->damageBox(pos.x, pos.y, surface.wlr()->current.width, surface.wlr()->current.height); + Vector2D pos = OWNER->getSurfaceBoxGlobal().value_or(CBox{0, 0, 0, 0}).pos() + lastBoxLocal.pos(); + CBox global = {pos, lastPopupSize}; + + g_pHyprRenderer->damageBox(&global); } void CInputPopup::damageSurface() { @@ -119,20 +121,23 @@ void CInputPopup::updateBox() { cursorBoxLocal = {0, 0, (int)parentBox.w, (int)parentBox.h}; } - if (cursorBoxLocal != lastBoxLocal) + Vector2D currentPopupSize = {surface.wlr()->current.width, surface.wlr()->current.height}; + + if (cursorBoxLocal != lastBoxLocal || currentPopupSize != lastPopupSize) damageEntire(); CMonitor* pMonitor = g_pCompositor->getMonitorFromVector(parentBox.middle()); - if (cursorBoxLocal.y + parentBox.y + surface.wlr()->current.height + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) - cursorBoxLocal.y -= surface.wlr()->current.height; + if (cursorBoxLocal.y + parentBox.y + currentPopupSize.y + cursorBoxLocal.height > pMonitor->vecPosition.y + pMonitor->vecSize.y) + cursorBoxLocal.y -= currentPopupSize.y; else cursorBoxLocal.y += cursorBoxLocal.height; - if (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width > pMonitor->vecPosition.x + pMonitor->vecSize.x) - cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + surface.wlr()->current.width) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); + if (cursorBoxLocal.x + parentBox.x + currentPopupSize.x > pMonitor->vecPosition.x + pMonitor->vecSize.x) + cursorBoxLocal.x -= (cursorBoxLocal.x + parentBox.x + currentPopupSize.x) - (pMonitor->vecPosition.x + pMonitor->vecSize.x); - lastBoxLocal = cursorBoxLocal; + lastBoxLocal = cursorBoxLocal; + lastPopupSize = currentPopupSize; wlr_input_popup_surface_v2_send_text_input_rectangle(pWlr, cursorBoxLocal.pWlr()); diff --git a/src/managers/input/InputMethodPopup.hpp b/src/managers/input/InputMethodPopup.hpp index 8bcf1101..71b2fe64 100644 --- a/src/managers/input/InputMethodPopup.hpp +++ b/src/managers/input/InputMethodPopup.hpp @@ -32,6 +32,7 @@ class CInputPopup { wlr_input_popup_surface_v2* pWlr = nullptr; CWLSurface surface; CBox lastBoxLocal; + Vector2D lastPopupSize; uint64_t lastMonitor = -1; DYNLISTENER(mapPopup); From 05eb2d4af212f279cc3c25ae9c654bce627db05c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 2 Apr 2024 12:46:05 +0100 Subject: [PATCH 0236/2897] master: guard window in moveWindowTo fixes #5374 --- src/layout/MasterLayout.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index cac64c6d..375840fb 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -1005,6 +1005,9 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { const auto PWINDOW2 = g_pCompositor->getWindowInDirection(pWindow, dir[0]); + if (!PWINDOW2) + return; + pWindow->setAnimationsToMove(); if (pWindow->m_iWorkspaceID != PWINDOW2->m_iWorkspaceID) { From fc0a7af7ba5c52f7a70309020f5cb27c19d068e6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Tue, 2 Apr 2024 16:10:55 +0100 Subject: [PATCH 0237/2897] IME: fix blurry ime on scaled ref #5387 --- src/managers/input/InputMethodPopup.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/managers/input/InputMethodPopup.cpp b/src/managers/input/InputMethodPopup.cpp index 36f25dd7..bc2876ad 100644 --- a/src/managers/input/InputMethodPopup.cpp +++ b/src/managers/input/InputMethodPopup.cpp @@ -57,6 +57,13 @@ void CInputPopup::onMap() { updateBox(); damageEntire(); + + const auto PMONITOR = g_pCompositor->getMonitorFromVector(globalBox().middle()); + + if (!PMONITOR) + return; + + g_pProtocolManager->m_pFractionalScaleProtocolManager->setPreferredScaleForSurface(surface.wlr(), PMONITOR->scale); } void CInputPopup::onUnmap() { @@ -121,7 +128,7 @@ void CInputPopup::updateBox() { cursorBoxLocal = {0, 0, (int)parentBox.w, (int)parentBox.h}; } - Vector2D currentPopupSize = {surface.wlr()->current.width, surface.wlr()->current.height}; + Vector2D currentPopupSize = surface.getViewporterCorrectedSize(); if (cursorBoxLocal != lastBoxLocal || currentPopupSize != lastPopupSize) damageEntire(); From ef23ef60c5641c5903f9cf40571ead7ad6aba1b9 Mon Sep 17 00:00:00 2001 From: Vaxry <43317083+vaxerski@users.noreply.github.com> Date: Tue, 2 Apr 2024 20:32:39 +0100 Subject: [PATCH 0238/2897] Workspace/core: Refactor workspace storage (#5380) * refactor workspaces to use ptrs * clang-format --- src/Compositor.cpp | 173 +++++++++--------- src/Compositor.hpp | 16 +- src/config/ConfigManager.cpp | 8 +- src/config/ConfigManager.hpp | 2 +- src/debug/HyprCtl.cpp | 83 ++++----- src/desktop/DesktopTypes.hpp | 6 + src/desktop/Window.cpp | 64 ++++--- src/desktop/Window.hpp | 42 +++-- src/desktop/Workspace.cpp | 36 +++- src/desktop/Workspace.hpp | 25 ++- src/events/Layers.cpp | 4 +- src/events/Windows.cpp | 30 +-- src/helpers/AnimatedVariable.cpp | 2 +- src/helpers/AnimatedVariable.hpp | 13 +- src/helpers/MiscFunctions.cpp | 20 +- src/helpers/Monitor.cpp | 80 ++++---- src/helpers/Monitor.hpp | 18 +- src/helpers/WLClasses.hpp | 14 +- src/layout/DwindleLayout.cpp | 53 +++--- src/layout/DwindleLayout.hpp | 2 +- src/layout/IHyprLayout.cpp | 22 +-- src/layout/MasterLayout.cpp | 116 ++++++------ src/layout/MasterLayout.hpp | 2 +- src/managers/AnimationManager.cpp | 18 +- src/managers/KeybindManager.cpp | 62 +++---- src/managers/XWaylandManager.cpp | 2 +- src/managers/input/IdleInhibitor.cpp | 2 +- src/managers/input/InputManager.cpp | 8 +- src/managers/input/Swipe.cpp | 14 +- src/managers/input/Touch.cpp | 2 +- src/render/OpenGL.cpp | 8 +- src/render/OpenGL.hpp | 2 +- src/render/Renderer.cpp | 80 ++++---- src/render/Renderer.hpp | 12 +- .../decorations/CHyprBorderDecoration.cpp | 4 +- .../decorations/CHyprDropShadowDecoration.cpp | 4 +- .../decorations/CHyprGroupBarDecoration.cpp | 4 +- 37 files changed, 544 insertions(+), 509 deletions(-) create mode 100644 src/desktop/DesktopTypes.hpp diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 5fefb2b8..001d7ca8 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -751,20 +751,20 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert auto floating = [&](bool aboveFullscreen) -> CWindow* { for (auto& w : m_vWindows | std::views::reverse) { - if (special && !isWorkspaceSpecial(w->m_iWorkspaceID)) // because special floating may creep up into regular + if (special && !w->onSpecialWorkspace()) // because special floating may creep up into regular continue; const auto BB = w->getWindowBoxUnified(properties); const auto PWINDOWMONITOR = getMonitorFromID(w->m_iMonitorID); // to avoid focusing windows behind special workspaces from other monitors - if (!*PSPECIALFALLTHRU && PWINDOWMONITOR && PWINDOWMONITOR->specialWorkspaceID && w->m_iWorkspaceID != PWINDOWMONITOR->specialWorkspaceID && + if (!*PSPECIALFALLTHRU && PWINDOWMONITOR && PWINDOWMONITOR->activeSpecialWorkspace && w->m_pWorkspace != PWINDOWMONITOR->activeSpecialWorkspace && BB.x >= PWINDOWMONITOR->vecPosition.x && BB.y >= PWINDOWMONITOR->vecPosition.y && BB.x + BB.width <= PWINDOWMONITOR->vecPosition.x + PWINDOWMONITOR->vecSize.x && BB.y + BB.height <= PWINDOWMONITOR->vecPosition.y + PWINDOWMONITOR->vecSize.y) continue; CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; - if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_iWorkspaceID) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && + if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->workspaceID()) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) { // OR windows should add focus to parent if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2) @@ -801,7 +801,7 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert if (properties & FLOATING_ONLY) return floating(false); - const int64_t WORKSPACEID = special ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; + const int64_t WORKSPACEID = special ? PMONITOR->activeSpecialWorkspaceID() : PMONITOR->activeWorkspaceID(); const auto PWORKSPACE = getWorkspaceByID(WORKSPACEID); if (PWORKSPACE->m_bHasFullscreenWindow) @@ -813,10 +813,10 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert // for windows, we need to check their extensions too, first. for (auto& w : m_vWindows) { - if (special != isWorkspaceSpecial(w->m_iWorkspaceID)) + if (special != w->onSpecialWorkspace()) continue; - if (!w->m_bIsX11 && !w->m_bIsFloating && w->m_bIsMapped && w->m_iWorkspaceID == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && + if (!w->m_bIsX11 && !w->m_bIsFloating && w->m_bIsMapped && w->workspaceID() == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow) { if (w->hasPopupAt(pos)) return w.get(); @@ -824,11 +824,11 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert } for (auto& w : m_vWindows) { - if (special != isWorkspaceSpecial(w->m_iWorkspaceID)) + if (special != w->onSpecialWorkspace()) continue; CBox box = (properties & USE_PROP_TILED) ? w->getWindowBoxUnified(properties) : CBox{w->m_vPosition, w->m_vSize}; - if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->m_iWorkspaceID == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && + if (!w->m_bIsFloating && w->m_bIsMapped && box.containsPoint(pos) && w->workspaceID() == WORKSPACEID && !w->isHidden() && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow) return w.get(); } @@ -837,10 +837,10 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert }; // special workspace - if (PMONITOR->specialWorkspaceID && !*PSPECIALFALLTHRU) + if (PMONITOR->activeSpecialWorkspace && !*PSPECIALFALLTHRU) return windowForWorkspace(true); - if (PMONITOR->specialWorkspaceID) { + if (PMONITOR->activeSpecialWorkspace) { const auto PWINDOW = windowForWorkspace(true); if (PWINDOW) @@ -997,15 +997,15 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { return; if (pWindow->m_bPinned) - pWindow->m_iWorkspaceID = m_pLastMonitor->activeWorkspace; + pWindow->m_pWorkspace = m_pLastMonitor->activeWorkspace; const auto PMONITOR = getMonitorFromID(pWindow->m_iMonitorID); - if (!isWorkspaceVisible(pWindow->m_iWorkspaceID)) { - const auto PWORKSPACE = getWorkspaceByID(pWindow->m_iWorkspaceID); + if (!isWorkspaceVisible(pWindow->workspaceID())) { + const auto PWORKSPACE = pWindow->m_pWorkspace; // This is to fix incorrect feedback on the focus history. PWORKSPACE->m_pLastFocusedWindow = pWindow; - PWORKSPACE->rememberPrevWorkspace(getWorkspaceByID(m_pLastMonitor->activeWorkspace)); + PWORKSPACE->rememberPrevWorkspace(m_pLastMonitor->activeWorkspace); PMONITOR->changeWorkspace(PWORKSPACE, false, true); // changeworkspace already calls focusWindow return; @@ -1016,7 +1016,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { /* If special fallthrough is enabled, this behavior will be disabled, as I have no better idea of nicely tracking which window focuses are "via keybinds" and which ones aren't. */ - if (PMONITOR->specialWorkspaceID && PMONITOR->specialWorkspaceID != pWindow->m_iWorkspaceID && !pWindow->m_bPinned && !*PSPECIALFALLTHROUGH) + if (PMONITOR->activeSpecialWorkspace && PMONITOR->activeSpecialWorkspace != pWindow->m_pWorkspace && !pWindow->m_bPinned && !*PSPECIALFALLTHROUGH) PMONITOR->setSpecialWorkspace(nullptr); // we need to make the PLASTWINDOW not equal to m_pLastWindow so that RENDERDATA is correct for an unfocused window @@ -1233,7 +1233,7 @@ CWindow* CCompositor::getWindowFromZWLRHandle(wl_resource* handle) { CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) { for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == ID && w->m_bIsFullscreen) + if (w->workspaceID() == ID && w->m_bIsFullscreen) return w.get(); } @@ -1242,20 +1242,20 @@ CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) { bool CCompositor::isWorkspaceVisible(const int& w) { for (auto& m : m_vMonitors) { - if (m->activeWorkspace == w) + if (m->activeWorkspaceID() == w) return true; - if (m->specialWorkspaceID == w) + if (m->activeSpecialWorkspaceID() == w) return true; } return false; } -CWorkspace* CCompositor::getWorkspaceByID(const int& id) { +PHLWORKSPACE CCompositor::getWorkspaceByID(const int& id) { for (auto& w : m_vWorkspaces) { - if (w->m_iID == id) - return w.get(); + if (w->m_iID == id && !w->inert()) + return w; } return nullptr; @@ -1265,7 +1265,7 @@ void CCompositor::sanityCheckWorkspaces() { auto it = m_vWorkspaces.begin(); while (it != m_vWorkspaces.end()) { - const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(it->get()); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(*it); bool isPersistent = false; for (auto& wsRule : WORKSPACERULES) { if (wsRule.isPersistent) @@ -1290,10 +1290,11 @@ void CCompositor::sanityCheckWorkspaces() { const auto PMONITOR = getMonitorFromID(WORKSPACE->m_iMonitorID); - if (PMONITOR && PMONITOR->specialWorkspaceID == WORKSPACE->m_iID) + if (PMONITOR && PMONITOR->activeSpecialWorkspace == WORKSPACE) PMONITOR->setSpecialWorkspace(nullptr); } + it->get()->markInert(); it = m_vWorkspaces.erase(it); continue; } @@ -1314,7 +1315,7 @@ void CCompositor::sanityCheckWorkspaces() { int CCompositor::getWindowsOnWorkspace(const int& id, std::optional onlyTiled) { int no = 0; for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == id && w->m_bIsMapped && !(onlyTiled.has_value() && !w->m_bIsFloating != onlyTiled.value())) + if (w->workspaceID() == id && w->m_bIsMapped && !(onlyTiled.has_value() && !w->m_bIsFloating != onlyTiled.value())) no++; } @@ -1332,7 +1333,7 @@ CWindow* CCompositor::getUrgentWindow() { bool CCompositor::hasUrgentWindowOnWorkspace(const int& id) { for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == id && w->m_bIsMapped && w->m_bIsUrgent) + if (w->workspaceID() == id && w->m_bIsMapped && w->m_bIsUrgent) return true; } @@ -1341,7 +1342,7 @@ bool CCompositor::hasUrgentWindowOnWorkspace(const int& id) { CWindow* CCompositor::getFirstWindowOnWorkspace(const int& id) { for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == id && w->m_bIsMapped && !w->isHidden()) + if (w->workspaceID() == id && w->m_bIsMapped && !w->isHidden()) return w.get(); } @@ -1357,7 +1358,7 @@ CWindow* CCompositor::getTopLeftWindowOnWorkspace(const int& id) { const auto PMONITOR = getMonitorFromID(PWORKSPACE->m_iMonitorID); for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID != id || !w->m_bIsMapped || w->isHidden()) + if (w->workspaceID() != id || !w->m_bIsMapped || w->isHidden()) continue; const auto WINDOWIDEALBB = w->getWindowIdealBoundingBoxIgnoreReserved(); @@ -1575,7 +1576,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { const auto POSA = Vector2D(WINDOWIDEALBB.x, WINDOWIDEALBB.y); const auto SIZEA = Vector2D(WINDOWIDEALBB.width, WINDOWIDEALBB.height); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; auto leaderValue = -1; CWindow* leaderWindow = nullptr; @@ -1583,10 +1584,10 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { // for tiled windows, we calc edges for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->m_iWorkspaceID)) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->workspaceID())) continue; - if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_iWorkspaceID != w->m_iWorkspaceID) + if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace) continue; if (PWORKSPACE->m_bHasFullscreenWindow && !w->m_bIsFullscreen && !w->m_bCreatedOverFullscreen) @@ -1672,10 +1673,10 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { constexpr float THRESHOLD = 0.3 * M_PI; for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_iWorkspaceID)) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->workspaceID())) continue; - if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_iWorkspaceID != w->m_iWorkspaceID) + if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace) continue; if (PWORKSPACE->m_bHasFullscreenWindow && !w->m_bIsFullscreen && !w->m_bCreatedOverFullscreen) @@ -1718,7 +1719,7 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow, bool focusableO if (floating.has_value() && w->m_bIsFloating != floating.value()) continue; - if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) + if (w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) return w.get(); } @@ -1726,7 +1727,7 @@ CWindow* CCompositor::getNextWindowOnWorkspace(CWindow* pWindow, bool focusableO if (floating.has_value() && w->m_bIsFloating != floating.value()) continue; - if (w.get() != pWindow && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) + if (w.get() != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) return w.get(); } @@ -1747,7 +1748,7 @@ CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow, bool focusableO if (floating.has_value() && w->m_bIsFloating != floating.value()) continue; - if (w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) + if (w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) return w.get(); } @@ -1755,7 +1756,7 @@ CWindow* CCompositor::getPrevWindowOnWorkspace(CWindow* pWindow, bool focusableO if (floating.has_value() && w->m_bIsFloating != floating.value()) continue; - if (w.get() != pWindow && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) + if (w.get() != pWindow && w->m_pWorkspace == pWindow->m_pWorkspace && w->m_bIsMapped && !w->isHidden() && (!focusableOnly || !w->m_sAdditionalConfigData.noFocus)) return w.get(); } @@ -1772,16 +1773,16 @@ int CCompositor::getNextAvailableNamedWorkspace() { return lowest - 1; } -CWorkspace* CCompositor::getWorkspaceByName(const std::string& name) { +PHLWORKSPACE CCompositor::getWorkspaceByName(const std::string& name) { for (auto& w : m_vWorkspaces) { - if (w->m_szName == name) - return w.get(); + if (w->m_szName == name && !w->inert()) + return w; } return nullptr; } -CWorkspace* CCompositor::getWorkspaceByString(const std::string& str) { +PHLWORKSPACE CCompositor::getWorkspaceByString(const std::string& str) { if (str.starts_with("name:")) { return getWorkspaceByName(str.substr(str.find_first_of(':') + 1)); } @@ -1896,7 +1897,7 @@ void CCompositor::updateAllWindowsAnimatedDecorationValues() { void CCompositor::updateWorkspaceWindows(const int64_t& id) { for (auto& w : m_vWindows) { - if (!w->m_bIsMapped || w->m_iWorkspaceID != id) + if (!w->m_bIsMapped || w->workspaceID() != id) continue; w->updateDynamicRules(); @@ -1964,7 +1965,7 @@ void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { pWindow->m_fBorderAngleAnimationProgress.setValueAndWarp(0.f); // opacity - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (pWindow->m_bIsFullscreen && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { pWindow->m_fActiveInactiveAlpha = *PFULLSCREENALPHA; } else { @@ -2020,16 +2021,16 @@ int CCompositor::getNextAvailableMonitorID(std::string const& name) { void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) { - const auto PWORKSPACEA = g_pCompositor->getWorkspaceByID(pMonitorA->activeWorkspace); - const auto PWORKSPACEB = g_pCompositor->getWorkspaceByID(pMonitorB->activeWorkspace); + const auto PWORKSPACEA = pMonitorA->activeWorkspace; + const auto PWORKSPACEB = pMonitorB->activeWorkspace; PWORKSPACEA->m_iMonitorID = pMonitorB->ID; PWORKSPACEA->moveToMonitor(pMonitorB->ID); for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == PWORKSPACEA->m_iID) { + if (w->m_pWorkspace == PWORKSPACEA) { if (w->m_bPinned) { - w->m_iWorkspaceID = PWORKSPACEB->m_iID; + w->m_pWorkspace = PWORKSPACEB; continue; } @@ -2052,9 +2053,9 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) PWORKSPACEB->moveToMonitor(pMonitorA->ID); for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == PWORKSPACEB->m_iID) { + if (w->m_pWorkspace == PWORKSPACEB) { if (w->m_bPinned) { - w->m_iWorkspaceID = PWORKSPACEA->m_iID; + w->m_pWorkspace = PWORKSPACEA; continue; } @@ -2073,8 +2074,8 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) } } - pMonitorA->activeWorkspace = PWORKSPACEB->m_iID; - pMonitorB->activeWorkspace = PWORKSPACEA->m_iID; + pMonitorA->activeWorkspace = PWORKSPACEB; + pMonitorB->activeWorkspace = PWORKSPACEA; PWORKSPACEA->rememberPrevWorkspace(PWORKSPACEB); PWORKSPACEB->rememberPrevWorkspace(PWORKSPACEA); @@ -2099,10 +2100,10 @@ void CCompositor::swapActiveWorkspaces(CMonitor* pMonitorA, CMonitor* pMonitorB) // event g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", PWORKSPACEA->m_szName + "," + pMonitorB->szName}); g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", PWORKSPACEA->m_iID, PWORKSPACEA->m_szName, pMonitorB->szName)}); - EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEA, pMonitorB})); + EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEA, pMonitorB})); g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", PWORKSPACEB->m_szName + "," + pMonitorA->szName}); g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", PWORKSPACEB->m_iID, PWORKSPACEB->m_szName, pMonitorA->szName)}); - EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEB, pMonitorA})); + EMIT_HOOK_EVENT("moveWorkspace", (std::vector{PWORKSPACEB, pMonitorA})); } CMonitor* CCompositor::getMonitorFromString(const std::string& name) { @@ -2179,9 +2180,9 @@ CMonitor* CCompositor::getMonitorFromString(const std::string& name) { return nullptr; } -void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMonitor, bool noWarpCursor) { +void CCompositor::moveWorkspaceToMonitor(PHLWORKSPACE pWorkspace, CMonitor* pMonitor, bool noWarpCursor) { - // We trust the workspace and monitor to be correct. + // We trust the monitor to be correct. if (pWorkspace->m_iMonitorID == pMonitor->ID) return; @@ -2190,7 +2191,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni const auto POLDMON = getMonitorFromID(pWorkspace->m_iMonitorID); - const bool SWITCHINGISACTIVE = POLDMON ? POLDMON->activeWorkspace == pWorkspace->m_iID : false; + const bool SWITCHINGISACTIVE = POLDMON ? POLDMON->activeWorkspace == pWorkspace : false; // fix old mon int nextWorkspaceOnMonitorID = -1; @@ -2227,9 +2228,9 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni pWorkspace->moveToMonitor(pMonitor->ID); for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == pWorkspace->m_iID) { + if (w->m_pWorkspace == pWorkspace) { if (w->m_bPinned) { - w->m_iWorkspaceID = nextWorkspaceOnMonitorID; + w->m_pWorkspace = g_pCompositor->getWorkspaceByID(nextWorkspaceOnMonitorID); continue; } @@ -2255,13 +2256,13 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni } if (SWITCHINGISACTIVE && POLDMON == g_pCompositor->m_pLastMonitor) { // if it was active, preserve its' status. If it wasn't, don't. - Debug::log(LOG, "moveWorkspaceToMonitor: SWITCHINGISACTIVE, active {} -> {}", pMonitor->activeWorkspace, pWorkspace->m_iID); + Debug::log(LOG, "moveWorkspaceToMonitor: SWITCHINGISACTIVE, active {} -> {}", pMonitor->activeWorkspaceID(), pWorkspace->m_iID); - if (const auto PWORKSPACE = getWorkspaceByID(pMonitor->activeWorkspace); PWORKSPACE) - getWorkspaceByID(pMonitor->activeWorkspace)->startAnim(false, false); + if (valid(pMonitor->activeWorkspace)) + pMonitor->activeWorkspace->startAnim(false, false); setActiveMonitor(pMonitor); - pMonitor->activeWorkspace = pWorkspace->m_iID; + pMonitor->activeWorkspace = pWorkspace; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitor->ID); pWorkspace->startAnim(true, true, true); @@ -2275,7 +2276,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni // finalize if (POLDMON) { g_pLayoutManager->getCurrentLayout()->recalculateMonitor(POLDMON->ID); - updateFullscreenFadeOnWorkspace(getWorkspaceByID(POLDMON->activeWorkspace)); + updateFullscreenFadeOnWorkspace(POLDMON->activeWorkspace); } updateFullscreenFadeOnWorkspace(pWorkspace); @@ -2283,7 +2284,7 @@ void CCompositor::moveWorkspaceToMonitor(CWorkspace* pWorkspace, CMonitor* pMoni // event g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspace", pWorkspace->m_szName + "," + pMonitor->szName}); g_pEventManager->postEvent(SHyprIPCEvent{"moveworkspacev2", std::format("{},{},{}", pWorkspace->m_iID, pWorkspace->m_szName, pMonitor->szName)}); - EMIT_HOOK_EVENT("moveWorkspace", (std::vector{pWorkspace, pMonitor})); + EMIT_HOOK_EVENT("moveWorkspace", (std::vector{pWorkspace, pMonitor})); } bool CCompositor::workspaceIDOutOfBounds(const int64_t& id) { @@ -2304,12 +2305,12 @@ bool CCompositor::workspaceIDOutOfBounds(const int64_t& id) { return std::clamp(id, lowestID, highestID) != id; } -void CCompositor::updateFullscreenFadeOnWorkspace(CWorkspace* pWorkspace) { +void CCompositor::updateFullscreenFadeOnWorkspace(PHLWORKSPACE pWorkspace) { const auto FULLSCREEN = pWorkspace->m_bHasFullscreenWindow; for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == pWorkspace->m_iID) { + if (w->m_pWorkspace == pWorkspace) { if (w->m_bFadingOut || w->m_bPinned || w->m_bIsFullscreen) continue; @@ -2323,7 +2324,7 @@ void CCompositor::updateFullscreenFadeOnWorkspace(CWorkspace* pWorkspace) { const auto PMONITOR = getMonitorFromID(pWorkspace->m_iMonitorID); - if (pWorkspace->m_iID == PMONITOR->activeWorkspace || pWorkspace->m_iID == PMONITOR->specialWorkspaceID) { + if (pWorkspace->m_iID == PMONITOR->activeWorkspaceID() || pWorkspace->m_iID == PMONITOR->activeSpecialWorkspaceID()) { for (auto& ls : PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { if (!ls->fadingOut) ls->alpha = FULLSCREEN && pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL ? 0.f : 1.f; @@ -2347,7 +2348,7 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode const auto PMONITOR = getMonitorFromID(pWindow->m_iMonitorID); - const auto PWORKSPACE = getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; const auto MODE = mode == FULLSCREEN_INVALID ? PWORKSPACE->m_efFullscreenMode : mode; @@ -2364,14 +2365,14 @@ void CCompositor::setWindowFullscreen(CWindow* pWindow, bool on, eFullscreenMode // make all windows on the same workspace under the fullscreen window for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == PWORKSPACE->m_iID && !w->m_bIsFullscreen && !w->m_bFadingOut && !w->m_bPinned) + if (w->m_pWorkspace == PWORKSPACE && !w->m_bIsFullscreen && !w->m_bFadingOut && !w->m_bPinned) w->m_bCreatedOverFullscreen = false; } updateFullscreenFadeOnWorkspace(PWORKSPACE); g_pXWaylandManager->setWindowSize(pWindow, pWindow->m_vRealSize.goal(), true); - forceReportSizesToWindowsOnWorkspace(pWindow->m_iWorkspaceID); + forceReportSizesToWindowsOnWorkspace(pWindow->workspaceID()); g_pInputManager->recheckIdleInhibitorStatus(); @@ -2398,7 +2399,7 @@ CWindow* CCompositor::getX11Parent(CWindow* pWindow) { void CCompositor::updateWorkspaceWindowDecos(const int& id) { for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID != id) + if (w->workspaceID() != id) continue; w->updateWindowDecos(); @@ -2440,7 +2441,7 @@ CWindow* CCompositor::getWindowByRegex(const std::string& regexp) { const bool FLOAT = regexp.starts_with("floating"); for (auto& w : m_vWindows) { - if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_iWorkspaceID != m_pLastWindow->m_iWorkspaceID || w->isHidden()) + if (!w->m_bIsMapped || w->m_bIsFloating != FLOAT || w->m_pWorkspace != m_pLastWindow->m_pWorkspace || w->isHidden()) continue; return w.get(); @@ -2608,13 +2609,13 @@ Vector2D CCompositor::parseWindowVectorArgsRelative(const std::string& args, con void CCompositor::forceReportSizesToWindowsOnWorkspace(const int& wid) { for (auto& w : m_vWindows) { - if (w->m_iWorkspaceID == wid && w->m_bIsMapped && !w->isHidden()) { + if (w->workspaceID() == wid && w->m_bIsMapped && !w->isHidden()) { g_pXWaylandManager->setWindowSize(w.get(), w->m_vRealSize.value(), true); } } } -CWorkspace* CCompositor::createNewWorkspace(const int& id, const int& monid, const std::string& name) { +PHLWORKSPACE CCompositor::createNewWorkspace(const int& id, const int& monid, const std::string& name) { const auto NAME = name == "" ? std::to_string(id) : name; auto monID = monid; @@ -2625,7 +2626,7 @@ CWorkspace* CCompositor::createNewWorkspace(const int& id, const int& monid, con const bool SPECIAL = id >= SPECIAL_WORKSPACE_START && id <= -2; - const auto PWORKSPACE = m_vWorkspaces.emplace_back(std::make_unique(id, monID, NAME, SPECIAL)).get(); + const auto PWORKSPACE = m_vWorkspaces.emplace_back(CWorkspace::create(id, monID, NAME, SPECIAL)); PWORKSPACE->m_fAlpha.setValueAndWarp(0); @@ -2656,7 +2657,7 @@ void CCompositor::setActiveMonitor(CMonitor* pMonitor) { return; } - const auto PWORKSPACE = getWorkspaceByID(pMonitor->activeWorkspace); + const auto PWORKSPACE = pMonitor->activeWorkspace; g_pEventManager->postEvent(SHyprIPCEvent{"focusedmon", pMonitor->szName + "," + (PWORKSPACE ? PWORKSPACE->m_szName : "?")}); EMIT_HOOK_EVENT("focusedMon", pMonitor); @@ -2682,7 +2683,7 @@ void CCompositor::performUserChecks() { ; // intentional } -void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorkspace) { +void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWorkspace) { if (!pWindow || !pWorkspace) return; @@ -2690,17 +2691,17 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks return; const bool FULLSCREEN = pWindow->m_bIsFullscreen; - const auto FULLSCREENMODE = getWorkspaceByID(pWindow->m_iWorkspaceID)->m_efFullscreenMode; + const auto FULLSCREENMODE = pWindow->m_pWorkspace->m_efFullscreenMode; if (FULLSCREEN) setWindowFullscreen(pWindow, false, FULLSCREEN_FULL); - pWindow->moveToWorkspace(pWorkspace->m_iID); + pWindow->moveToWorkspace(pWorkspace); if (!pWindow->m_bIsFloating) { g_pLayoutManager->getCurrentLayout()->onWindowRemovedTiling(pWindow); - pWindow->m_iWorkspaceID = pWorkspace->m_iID; - pWindow->m_iMonitorID = pWorkspace->m_iMonitorID; + pWindow->m_pWorkspace = pWorkspace; + pWindow->m_iMonitorID = pWorkspace->m_iMonitorID; g_pLayoutManager->getCurrentLayout()->onWindowCreatedTiling(pWindow); } else { const auto PWINDOWMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); @@ -2708,8 +2709,8 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks const auto PWORKSPACEMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); - pWindow->m_iWorkspaceID = pWorkspace->m_iID; - pWindow->m_iMonitorID = pWorkspace->m_iMonitorID; + pWindow->m_pWorkspace = pWorkspace; + pWindow->m_iMonitorID = pWorkspace->m_iMonitorID; pWindow->m_vRealPosition = POSTOMON + PWORKSPACEMONITOR->vecPosition; } @@ -2721,7 +2722,7 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks if (pWindow->m_sGroupData.pNextWindow) { CWindow* next = pWindow->m_sGroupData.pNextWindow; while (next != pWindow) { - next->moveToWorkspace(pWorkspace->m_iID); + next->moveToWorkspace(pWorkspace); next->updateToplevel(); next = next->m_sGroupData.pNextWindow; } @@ -2731,12 +2732,12 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorks setWindowFullscreen(pWindow, true, FULLSCREENMODE); g_pCompositor->updateWorkspaceWindows(pWorkspace->m_iID); - g_pCompositor->updateWorkspaceWindows(pWindow->m_iWorkspaceID); + g_pCompositor->updateWorkspaceWindows(pWindow->workspaceID()); } CWindow* CCompositor::getForceFocus() { for (auto& w : m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->m_iWorkspaceID)) + if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->workspaceID())) continue; if (!w->m_bStayFocused) @@ -2885,6 +2886,6 @@ void CCompositor::updateSuspendedStates() { if (!w->m_bIsMapped) continue; - w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->m_iWorkspaceID)); + w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->workspaceID())); } } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index ace2a388..98bbe899 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -92,7 +92,7 @@ class CCompositor { std::vector> m_vMonitors; std::vector> m_vRealMonitors; // for all monitors, even those turned off std::vector> m_vWindows; - std::vector> m_vWorkspaces; + std::vector m_vWorkspaces; std::vector m_vWindowsFadingOut; std::vector m_vSurfacesFadingOut; @@ -145,9 +145,9 @@ class CCompositor { CWindow* getWindowFromHandle(uint32_t); CWindow* getWindowFromZWLRHandle(wl_resource*); bool isWorkspaceVisible(const int&); - CWorkspace* getWorkspaceByID(const int&); - CWorkspace* getWorkspaceByName(const std::string&); - CWorkspace* getWorkspaceByString(const std::string&); + PHLWORKSPACE getWorkspaceByID(const int&); + PHLWORKSPACE getWorkspaceByName(const std::string&); + PHLWORKSPACE getWorkspaceByString(const std::string&); void sanityCheckWorkspaces(); void updateWorkspaceWindowDecos(const int&); int getWindowsOnWorkspace(const int& id, std::optional onlyTiled = {}); @@ -172,12 +172,12 @@ class CCompositor { void updateWorkspaceWindows(const int64_t& id); void updateWindowAnimatedDecorationValues(CWindow*); int getNextAvailableMonitorID(std::string const& name); - void moveWorkspaceToMonitor(CWorkspace*, CMonitor*, bool noWarpCursor = false); + void moveWorkspaceToMonitor(PHLWORKSPACE, CMonitor*, bool noWarpCursor = false); void swapActiveWorkspaces(CMonitor*, CMonitor*); CMonitor* getMonitorFromString(const std::string&); bool workspaceIDOutOfBounds(const int64_t&); void setWindowFullscreen(CWindow*, bool, eFullscreenMode mode = FULLSCREEN_INVALID); - void updateFullscreenFadeOnWorkspace(CWorkspace*); + void updateFullscreenFadeOnWorkspace(PHLWORKSPACE); CWindow* getX11Parent(CWindow*); void scheduleFrameForMonitor(CMonitor*); void addToFadingOutSafe(SLayerSurface*); @@ -189,13 +189,13 @@ class CCompositor { void closeWindow(CWindow*); Vector2D parseWindowVectorArgsRelative(const std::string&, const Vector2D&); void forceReportSizesToWindowsOnWorkspace(const int&); - CWorkspace* createNewWorkspace(const int&, const int&, const std::string& name = ""); // will be deleted next frame if left empty and unfocused! + PHLWORKSPACE createNewWorkspace(const int&, const int&, const std::string& name = ""); // will be deleted next frame if left empty and unfocused! void renameWorkspace(const int&, const std::string& name = ""); void setActiveMonitor(CMonitor*); bool isWorkspaceSpecial(const int&); int getNewSpecialID(); void performUserChecks(); - void moveWindowToWorkspaceSafe(CWindow* pWindow, CWorkspace* pWorkspace); + void moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWorkspace); CWindow* getForceFocus(); void notifyIdleActivity(); void setIdleActivityInhibit(bool inhibit); diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index df2006ae..87bb5bbd 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -956,7 +956,7 @@ SMonitorRule CConfigManager::getMonitorRuleFor(const CMonitor& PMONITOR) { return SMonitorRule{.name = "", .resolution = Vector2D(0, 0), .offset = Vector2D(-INT32_MAX, -INT32_MAX), .scale = -1}; // 0, 0 is preferred and -1, -1 is auto } -std::vector CConfigManager::getWorkspaceRulesFor(CWorkspace* pWorkspace) { +std::vector CConfigManager::getWorkspaceRulesFor(PHLWORKSPACE pWorkspace) { std::vector results; for (auto& rule : m_dWorkspaceRules) { if (pWorkspace->matchesStaticSelector(rule.workspaceString)) @@ -1056,13 +1056,13 @@ std::vector CConfigManager::getMatchingRules(CWindow* pWindow, bool } if (!rule.szOnWorkspace.empty()) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (!PWORKSPACE || !PWORKSPACE->matchesStaticSelector(rule.szOnWorkspace)) continue; } if (!rule.szWorkspace.empty()) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (!PWORKSPACE) continue; @@ -1287,7 +1287,7 @@ void CConfigManager::ensureVRR(CMonitor* pMonitor) { /* fullscreen */ m->vrrActive = true; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m->activeWorkspace); + const auto PWORKSPACE = m->activeWorkspace; if (!PWORKSPACE) return; // ??? diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index 5406d853..2ef94ca7 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -105,7 +105,7 @@ class CConfigManager { static std::string getMainConfigPath(); SMonitorRule getMonitorRuleFor(const CMonitor&); - std::vector getWorkspaceRulesFor(CWorkspace*); + std::vector getWorkspaceRulesFor(PHLWORKSPACE workspace); std::string getDefaultWorkspaceFor(const std::string&); CMonitor* getBoundMonitorForWS(const std::string&); diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index f61f5544..3c53d97f 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -24,15 +24,6 @@ static void trimTrailingComma(std::string& str) { str.pop_back(); } -static std::string getWorkspaceNameFromSpecialID(const int workspaceID) { - if (workspaceID == 0) - return ""; - const auto* workspace = g_pCompositor->getWorkspaceByID(workspaceID); - if (!workspace) - return ""; - return workspace->m_szName; -} - static std::string formatToString(uint32_t drmFormat) { switch (drmFormat) { case DRM_FORMAT_XRGB2101010: return "XRGB2101010"; @@ -116,8 +107,8 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { }},)#", m->ID, escapeJSONStrings(m->szName), escapeJSONStrings(m->szShortDescription), (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, - m->activeWorkspace, (m->activeWorkspace == -1 ? "" : escapeJSONStrings(g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName)), m->specialWorkspaceID, - escapeJSONStrings(getWorkspaceNameFromSpecialID(m->specialWorkspaceID)), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, + m->activeWorkspaceID(), (!m->activeWorkspace ? "" : escapeJSONStrings(m->activeWorkspace->m_szName)), m->activeSpecialWorkspaceID(), + escapeJSONStrings(m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "true" : "false"), (m->dpmsStatus ? "true" : "false"), (m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED ? "true" : "false"), m->tearingState.activelyTearing ? "true" : "false", formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); @@ -131,18 +122,17 @@ std::string monitorsRequest(eHyprCtlOutputFormat format, std::string request) { if (!m->output || m->ID == -1ull) continue; - result += - std::format("Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial " - "workspace: {} ({})\n\treserved: {} " - "{} {} {}\n\tscale: {:.2f}\n\ttransform: " - "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\tcurrentFormat: {}\n\tavailableModes: {}\n\n", - m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->szShortDescription, - (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), m->activeWorkspace, - (m->activeWorkspace == -1 ? "" : g_pCompositor->getWorkspaceByID(m->activeWorkspace)->m_szName), m->specialWorkspaceID, - getWorkspaceNameFromSpecialID(m->specialWorkspaceID), (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, - (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, - (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), m->tearingState.activelyTearing, formatToString(m->drmFormat), - availableModesForOutput(m.get(), format)); + result += std::format( + "Monitor {} (ID {}):\n\t{}x{}@{:.5f} at {}x{}\n\tdescription: {}\n\tmake: {}\n\tmodel: {}\n\tserial: {}\n\tactive workspace: {} ({})\n\tspecial " + "workspace: {} ({})\n\treserved: {} " + "{} {} {}\n\tscale: {:.2f}\n\ttransform: " + "{}\n\tfocused: {}\n\tdpmsStatus: {}\n\tvrr: {}\n\tactivelyTearing: {}\n\tcurrentFormat: {}\n\tavailableModes: {}\n\n", + m->szName, m->ID, (int)m->vecPixelSize.x, (int)m->vecPixelSize.y, m->refreshRate, (int)m->vecPosition.x, (int)m->vecPosition.y, m->szShortDescription, + (m->output->make ? m->output->make : ""), (m->output->model ? m->output->model : ""), (m->output->serial ? m->output->serial : ""), m->activeWorkspaceID(), + (!m->activeWorkspace ? "" : m->activeWorkspace->m_szName), m->activeSpecialWorkspaceID(), (m->activeSpecialWorkspace ? m->activeSpecialWorkspace->m_szName : ""), + (int)m->vecReservedTopLeft.x, (int)m->vecReservedTopLeft.y, (int)m->vecReservedBottomRight.x, (int)m->vecReservedBottomRight.y, m->scale, (int)m->transform, + (m.get() == g_pCompositor->m_pLastMonitor ? "yes" : "no"), (int)m->dpmsStatus, (int)(m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED), + m->tearingState.activelyTearing, formatToString(m->drmFormat), availableModesForOutput(m.get(), format)); } } @@ -211,30 +201,23 @@ static std::string getWindowData(CWindow* w, eHyprCtlOutputFormat format) { "focusHistoryID": {} }},)#", (uintptr_t)w, (w->m_bIsMapped ? "true" : "false"), (w->isHidden() ? "true" : "false"), (int)w->m_vRealPosition.goal().x, (int)w->m_vRealPosition.goal().y, - (int)w->m_vRealSize.goal().x, (int)w->m_vRealSize.goal().y, w->m_iWorkspaceID, - escapeJSONStrings(w->m_iWorkspaceID == -1 ? "" : - g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName : - std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))), - ((int)w->m_bIsFloating == 1 ? "true" : "false"), (int64_t)w->m_iMonitorID, escapeJSONStrings(g_pXWaylandManager->getAppIDClass(w)), - escapeJSONStrings(g_pXWaylandManager->getTitle(w)), escapeJSONStrings(w->m_szInitialClass), escapeJSONStrings(w->m_szInitialTitle), w->getPID(), - ((int)w->m_bIsX11 == 1 ? "true" : "false"), (w->m_bPinned ? "true" : "false"), (w->m_bIsFullscreen ? "true" : "false"), - (w->m_bIsFullscreen ? (g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? (int)g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_efFullscreenMode : 0) : 0), + (int)w->m_vRealSize.goal().x, (int)w->m_vRealSize.goal().y, w->m_pWorkspace ? w->workspaceID() : WORKSPACE_INVALID, + escapeJSONStrings(!w->m_pWorkspace ? "" : w->m_pWorkspace->m_szName), ((int)w->m_bIsFloating == 1 ? "true" : "false"), (int64_t)w->m_iMonitorID, + escapeJSONStrings(g_pXWaylandManager->getAppIDClass(w)), escapeJSONStrings(g_pXWaylandManager->getTitle(w)), escapeJSONStrings(w->m_szInitialClass), + escapeJSONStrings(w->m_szInitialTitle), w->getPID(), ((int)w->m_bIsX11 == 1 ? "true" : "false"), (w->m_bPinned ? "true" : "false"), + (w->m_bIsFullscreen ? "true" : "false"), (w->m_bIsFullscreen ? (w->m_pWorkspace ? (int)w->m_pWorkspace->m_efFullscreenMode : 0) : 0), w->m_bFakeFullscreenState ? "true" : "false", getGroupedData(w, format), (uintptr_t)w->m_pSwallowed, getFocusHistoryID(w)); } else { - return std::format( - "Window {:x} -> {}:\n\tmapped: {}\n\thidden: {}\n\tat: {},{}\n\tsize: {},{}\n\tworkspace: {} ({})\n\tfloating: {}\n\tmonitor: {}\n\tclass: {}\n\ttitle: " - "{}\n\tinitialClass: {}\n\tinitialTitle: {}\n\tpid: " - "{}\n\txwayland: {}\n\tpinned: " - "{}\n\tfullscreen: {}\n\tfullscreenmode: {}\n\tfakefullscreen: {}\n\tgrouped: {}\n\tswallowing: {:x}\n\tfocusHistoryID: {}\n\n", - (uintptr_t)w, w->m_szTitle, (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goal().x, (int)w->m_vRealPosition.goal().y, (int)w->m_vRealSize.goal().x, - (int)w->m_vRealSize.goal().y, w->m_iWorkspaceID, - (w->m_iWorkspaceID == -1 ? "" : - g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_szName : - std::string("Invalid workspace " + std::to_string(w->m_iWorkspaceID))), - (int)w->m_bIsFloating, (int64_t)w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w), g_pXWaylandManager->getTitle(w), w->m_szInitialClass, w->m_szInitialTitle, - w->getPID(), (int)w->m_bIsX11, (int)w->m_bPinned, (int)w->m_bIsFullscreen, - (w->m_bIsFullscreen ? (g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID) ? g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID)->m_efFullscreenMode : 0) : 0), - (int)w->m_bFakeFullscreenState, getGroupedData(w, format), (uintptr_t)w->m_pSwallowed, getFocusHistoryID(w)); + return std::format("Window {:x} -> {}:\n\tmapped: {}\n\thidden: {}\n\tat: {},{}\n\tsize: {},{}\n\tworkspace: {} ({})\n\tfloating: {}\n\tmonitor: {}\n\tclass: {}\n\ttitle: " + "{}\n\tinitialClass: {}\n\tinitialTitle: {}\n\tpid: " + "{}\n\txwayland: {}\n\tpinned: " + "{}\n\tfullscreen: {}\n\tfullscreenmode: {}\n\tfakefullscreen: {}\n\tgrouped: {}\n\tswallowing: {:x}\n\tfocusHistoryID: {}\n\n", + (uintptr_t)w, w->m_szTitle, (int)w->m_bIsMapped, (int)w->isHidden(), (int)w->m_vRealPosition.goal().x, (int)w->m_vRealPosition.goal().y, + (int)w->m_vRealSize.goal().x, (int)w->m_vRealSize.goal().y, w->m_pWorkspace ? w->workspaceID() : WORKSPACE_INVALID, + (!w->m_pWorkspace ? "" : std::to_string(w->workspaceID())), (int)w->m_bIsFloating, (int64_t)w->m_iMonitorID, g_pXWaylandManager->getAppIDClass(w), + g_pXWaylandManager->getTitle(w), w->m_szInitialClass, w->m_szInitialTitle, w->getPID(), (int)w->m_bIsX11, (int)w->m_bPinned, (int)w->m_bIsFullscreen, + (w->m_bIsFullscreen ? (w->m_pWorkspace ? w->m_pWorkspace->m_efFullscreenMode : 0) : 0), (int)w->m_bFakeFullscreenState, getGroupedData(w, format), + (uintptr_t)w->m_pSwallowed, getFocusHistoryID(w)); } } @@ -264,7 +247,7 @@ std::string clientsRequest(eHyprCtlOutputFormat format, std::string request) { return result; } -static std::string getWorkspaceData(CWorkspace* w, eHyprCtlOutputFormat format) { +static std::string getWorkspaceData(PHLWORKSPACE w, eHyprCtlOutputFormat format) { const auto PLASTW = w->getLastFocusedWindow(); const auto PMONITOR = g_pCompositor->getMonitorFromID(w->m_iMonitorID); if (format == eHyprCtlOutputFormat::FORMAT_JSON) { @@ -339,9 +322,9 @@ std::string activeWorkspaceRequest(eHyprCtlOutputFormat format, std::string requ return "unsafe state"; std::string result = ""; - auto w = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + auto w = g_pCompositor->m_pLastMonitor->activeWorkspace; - if (!w) + if (!valid(w)) return "internal error"; return getWorkspaceData(w, format); @@ -353,7 +336,7 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) if (format == eHyprCtlOutputFormat::FORMAT_JSON) { result += "["; for (auto& w : g_pCompositor->m_vWorkspaces) { - result += getWorkspaceData(w.get(), format); + result += getWorkspaceData(w, format); result += ","; } @@ -361,7 +344,7 @@ std::string workspacesRequest(eHyprCtlOutputFormat format, std::string request) result += "]"; } else { for (auto& w : g_pCompositor->m_vWorkspaces) { - result += getWorkspaceData(w.get(), format); + result += getWorkspaceData(w, format); } } diff --git a/src/desktop/DesktopTypes.hpp b/src/desktop/DesktopTypes.hpp new file mode 100644 index 00000000..1548f694 --- /dev/null +++ b/src/desktop/DesktopTypes.hpp @@ -0,0 +1,6 @@ +#pragma once +#include + +class CWorkspace; + +typedef std::shared_ptr PHLWORKSPACE; \ No newline at end of file diff --git a/src/desktop/Window.cpp b/src/desktop/Window.cpp index 891fd652..34ae857f 100644 --- a/src/desktop/Window.cpp +++ b/src/desktop/Window.cpp @@ -4,6 +4,7 @@ #include "../render/decorations/CHyprGroupBarDecoration.hpp" #include "../render/decorations/CHyprBorderDecoration.hpp" #include "../config/ConfigValue.hpp" +#include CWindow::CWindow() { m_vRealPosition.create(g_pConfigManager->getAnimationPropertyConfig("windowsIn"), this, AVARDAMAGE_ENTIRE); @@ -377,43 +378,37 @@ void CWindow::updateSurfaceScaleTransformDetails() { this); } -void CWindow::moveToWorkspace(int workspaceID) { - if (m_iWorkspaceID == workspaceID) +void CWindow::moveToWorkspace(PHLWORKSPACE pWorkspace) { + if (m_pWorkspace == pWorkspace) return; static auto PCLOSEONLASTSPECIAL = CConfigValue("misc:close_special_on_empty"); - const int OLDWORKSPACE = m_iWorkspaceID; + const auto OLDWORKSPACE = m_pWorkspace; - m_iWorkspaceID = workspaceID; - - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + m_pWorkspace = pWorkspace; setAnimationsToMove(); updateSpecialRenderData(); - if (PWORKSPACE) { - g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", std::format("{:x},{}", (uintptr_t)this, PWORKSPACE->m_szName)}); - g_pEventManager->postEvent(SHyprIPCEvent{"movewindowv2", std::format("{:x},{},{}", (uintptr_t)this, PWORKSPACE->m_iID, PWORKSPACE->m_szName)}); - EMIT_HOOK_EVENT("moveWindow", (std::vector{this, PWORKSPACE})); + if (valid(pWorkspace)) { + g_pEventManager->postEvent(SHyprIPCEvent{"movewindow", std::format("{:x},{}", (uintptr_t)this, pWorkspace->m_szName)}); + g_pEventManager->postEvent(SHyprIPCEvent{"movewindowv2", std::format("{:x},{},{}", (uintptr_t)this, pWorkspace->m_iID, pWorkspace->m_szName)}); + EMIT_HOOK_EVENT("moveWindow", (std::vector{this, pWorkspace})); } if (m_pSwallowed) { - m_pSwallowed->moveToWorkspace(workspaceID); + m_pSwallowed->moveToWorkspace(pWorkspace); m_pSwallowed->m_iMonitorID = m_iMonitorID; } // update xwayland coords g_pXWaylandManager->setWindowSize(this, m_vRealSize.value()); - if (g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE) == 0 && *PCLOSEONLASTSPECIAL) { - const auto PWS = g_pCompositor->getWorkspaceByID(OLDWORKSPACE); - - if (PWS) { - if (const auto PMONITOR = g_pCompositor->getMonitorFromID(PWS->m_iMonitorID); PMONITOR) - PMONITOR->setSpecialWorkspace(nullptr); - } + if (OLDWORKSPACE && g_pCompositor->isWorkspaceSpecial(OLDWORKSPACE->m_iID) && g_pCompositor->getWindowsOnWorkspace(OLDWORKSPACE->m_iID) == 0 && *PCLOSEONLASTSPECIAL) { + if (const auto PMONITOR = g_pCompositor->getMonitorFromID(OLDWORKSPACE->m_iMonitorID); PMONITOR) + PMONITOR->setSpecialWorkspace(nullptr); } } @@ -455,6 +450,8 @@ void CWindow::onUnmap() { if (g_pCompositor->m_pLastWindow == this) g_pCompositor->m_pLastWindow = nullptr; + m_iLastWorkspace = onSpecialWorkspace(); + m_vRealPosition.setCallbackOnEnd(unregisterVar); m_vRealSize.setCallbackOnEnd(unregisterVar); m_fBorderFadeAnimationProgress.setCallbackOnEnd(unregisterVar); @@ -470,9 +467,9 @@ void CWindow::onUnmap() { hyprListener_unmapWindow.removeCallback(); - if (*PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(m_iWorkspaceID) == 0 && g_pCompositor->isWorkspaceSpecial(m_iWorkspaceID)) { + if (*PCLOSEONLASTSPECIAL && g_pCompositor->getWindowsOnWorkspace(workspaceID()) == 0 && onSpecialWorkspace()) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); - if (PMONITOR && PMONITOR->specialWorkspaceID == m_iWorkspaceID) + if (PMONITOR && PMONITOR->activeSpecialWorkspace && PMONITOR->activeSpecialWorkspace == m_pWorkspace) PMONITOR->setSpecialWorkspace(nullptr); } @@ -481,13 +478,14 @@ void CWindow::onUnmap() { if (PMONITOR && PMONITOR->solitaryClient == this) PMONITOR->solitaryClient = nullptr; - g_pCompositor->updateWorkspaceWindows(m_iWorkspaceID); + g_pCompositor->updateWorkspaceWindows(workspaceID()); if (m_bIsX11) return; m_pSubsurfaceHead.reset(); m_pPopupHead.reset(); + m_pWorkspace.reset(); } void CWindow::onMap() { @@ -943,7 +941,7 @@ void CWindow::setGroupCurrent(CWindow* pWindow) { const auto PCURRENT = getGroupCurrent(); const bool FULLSCREEN = PCURRENT->m_bIsFullscreen; - const auto WORKSPACE = g_pCompositor->getWorkspaceByID(PCURRENT->m_iWorkspaceID); + const auto WORKSPACE = PCURRENT->m_pWorkspace; const auto PWINDOWSIZE = PCURRENT->m_vRealSize.goal(); const auto PWINDOWPOS = PCURRENT->m_vRealPosition.goal(); @@ -1034,11 +1032,13 @@ void CWindow::updateGroupOutputs() { if (!m_sGroupData.pNextWindow) return; - CWindow* curr = m_sGroupData.pNextWindow; + CWindow* curr = m_sGroupData.pNextWindow; + + const auto WS = m_pWorkspace; while (curr != this) { curr->m_iMonitorID = m_iMonitorID; - curr->moveToWorkspace(m_iWorkspaceID); + curr->moveToWorkspace(WS); curr->m_vRealPosition = m_vRealPosition.goal(); curr->m_vRealSize = m_vRealSize.goal(); @@ -1058,7 +1058,7 @@ bool CWindow::opaque() { if (m_vRealSize.goal().floor() != m_vReportedSize) return false; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + const auto PWORKSPACE = m_pWorkspace; if (m_pWLSurface.small() && !m_pWLSurface.m_bFillIgnoreSmall) return false; @@ -1088,7 +1088,7 @@ float CWindow::rounding() { } void CWindow::updateSpecialRenderData() { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + const auto PWORKSPACE = m_pWorkspace; const auto WORKSPACERULES = PWORKSPACE ? g_pConfigManager->getWorkspaceRulesFor(PWORKSPACE) : std::vector{}; bool border = true; @@ -1137,7 +1137,7 @@ bool CWindow::canBeTorn() { } bool CWindow::shouldSendFullscreenState() { - const auto MODE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID)->m_efFullscreenMode; + const auto MODE = m_pWorkspace->m_efFullscreenMode; return m_bDontSendFullscreen ? false : (m_bFakeFullscreenState || (m_bIsFullscreen && (MODE == FULLSCREEN_FULL))); } @@ -1173,7 +1173,7 @@ void CWindow::onWorkspaceAnimUpdate() { } Vector2D offset; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_iWorkspaceID); + const auto PWORKSPACE = m_pWorkspace; if (!PWORKSPACE) return; @@ -1212,3 +1212,11 @@ int CWindow::popupsCount() { m_uSurface.xdg, [](wlr_surface* s, int x, int y, void* data) { *(int*)data += 1; }, &no); return no; } + +int CWindow::workspaceID() { + return m_pWorkspace ? m_pWorkspace->m_iID : m_iLastWorkspace; +} + +bool CWindow::onSpecialWorkspace() { + return m_pWorkspace ? m_pWorkspace->m_bIsSpecialWorkspace : g_pCompositor->isWorkspaceSpecial(m_iLastWorkspace); +} diff --git a/src/desktop/Window.hpp b/src/desktop/Window.hpp index bc1820a0..ae62e77e 100644 --- a/src/desktop/Window.hpp +++ b/src/desktop/Window.hpp @@ -11,6 +11,7 @@ #include "Popup.hpp" #include "../macros.hpp" #include "../managers/XWaylandManager.hpp" +#include "DesktopTypes.hpp" enum eIdleInhibitMode { IDLEINHIBIT_NONE = 0, @@ -241,24 +242,24 @@ class CWindow { Vector2D m_vFloatingOffset = Vector2D(0, 0); // this is used for pseudotiling - bool m_bIsPseudotiled = false; - Vector2D m_vPseudoSize = Vector2D(0, 0); + bool m_bIsPseudotiled = false; + Vector2D m_vPseudoSize = Vector2D(0, 0); - bool m_bFirstMap = false; // for layouts - bool m_bIsFloating = false; - bool m_bDraggingTiled = false; // for dragging around tiled windows - bool m_bIsFullscreen = false; - bool m_bDontSendFullscreen = false; - bool m_bWasMaximized = false; - uint64_t m_iMonitorID = -1; - std::string m_szTitle = ""; - std::string m_szInitialTitle = ""; - std::string m_szInitialClass = ""; - int m_iWorkspaceID = -1; + bool m_bFirstMap = false; // for layouts + bool m_bIsFloating = false; + bool m_bDraggingTiled = false; // for dragging around tiled windows + bool m_bIsFullscreen = false; + bool m_bDontSendFullscreen = false; + bool m_bWasMaximized = false; + uint64_t m_iMonitorID = -1; + std::string m_szTitle = ""; + std::string m_szInitialTitle = ""; + std::string m_szInitialClass = ""; + PHLWORKSPACE m_pWorkspace; - bool m_bIsMapped = false; + bool m_bIsMapped = false; - bool m_bRequestsFloat = false; + bool m_bRequestsFloat = false; // This is for fullscreen apps bool m_bCreatedOverFullscreen = false; @@ -384,7 +385,7 @@ class CWindow { void destroyToplevelHandle(); void updateToplevel(); void updateSurfaceScaleTransformDetails(); - void moveToWorkspace(int); + void moveToWorkspace(PHLWORKSPACE); CWindow* X11TransientFor(); void onUnmap(); void onMap(); @@ -400,6 +401,8 @@ class CWindow { bool shouldSendFullscreenState(); void setSuspended(bool suspend); bool visibleOnMonitor(CMonitor* pMonitor); + int workspaceID(); + bool onSpecialWorkspace(); int getRealBorderSize(); void updateSpecialRenderData(); @@ -428,8 +431,9 @@ class CWindow { private: // For hidden windows and stuff - bool m_bHidden = false; - bool m_bSuspended = false; + bool m_bHidden = false; + bool m_bSuspended = false; + int m_iLastWorkspace = WORKSPACE_INVALID; }; /** @@ -464,7 +468,7 @@ struct std::formatter : std::formatter { std::format_to(out, "["); std::format_to(out, "Window {:x}: title: \"{}\"", (uintptr_t)w, w->m_szTitle); if (formatWorkspace) - std::format_to(out, ", workspace: {}", w->m_iWorkspaceID); + std::format_to(out, ", workspace: {}", w->m_pWorkspace ? w->workspaceID() : WORKSPACE_INVALID); if (formatMonitor) std::format_to(out, ", monitor: {}", w->m_iMonitorID); if (formatClass) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 9200b4d7..ccb0fa25 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -2,6 +2,12 @@ #include "../Compositor.hpp" #include "../config/ConfigValue.hpp" +PHLWORKSPACE CWorkspace::create(int id, int monitorID, std::string name, bool special) { + PHLWORKSPACE workspace = std::make_shared(id, monitorID, name, special); + workspace->init(workspace); + return workspace; +} + CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID); @@ -14,17 +20,22 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_iID = id; m_szName = name; m_bIsSpecialWorkspace = special; +} - m_vRenderOffset.create(special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), this, - AVARDAMAGE_ENTIRE); - m_fAlpha.create(AVARTYPE_FLOAT, special ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), this, +void CWorkspace::init(PHLWORKSPACE self) { + m_pSelf = self; + + m_vRenderOffset.create(m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), + self, AVARDAMAGE_ENTIRE); + m_fAlpha.create(AVARTYPE_FLOAT, + m_bIsSpecialWorkspace ? g_pConfigManager->getAnimationPropertyConfig("specialWorkspace") : g_pConfigManager->getAnimationPropertyConfig("workspaces"), self, AVARDAMAGE_ENTIRE); m_fAlpha.setValueAndWarp(1.f); m_vRenderOffset.registerVar(); m_fAlpha.registerVar(); - const auto RULESFORTHIS = g_pConfigManager->getWorkspaceRulesFor(this); + const auto RULESFORTHIS = g_pConfigManager->getWorkspaceRulesFor(self); for (auto& rule : RULESFORTHIS) { if (rule.defaultName.has_value()) m_szName = rule.defaultName.value(); @@ -37,6 +48,8 @@ CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { m_pLastFocusedWindow = nullptr; }); + m_bInert = false; + g_pEventManager->postEvent({"createworkspace", m_szName}); g_pEventManager->postEvent({"createworkspacev2", std::format("{},{}", m_iID, m_szName)}); EMIT_HOOK_EVENT("createWorkspace", this); @@ -61,7 +74,7 @@ void CWorkspace::startAnim(bool in, bool left, bool instant) { // set floating windows offset callbacks m_vRenderOffset.setUpdateCallback([&](void*) { for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != m_iID) + if (!g_pCompositor->windowValidMapped(w.get()) || w->workspaceID() != m_iID) continue; w->onWorkspaceAnimUpdate(); @@ -169,13 +182,13 @@ void CWorkspace::moveToMonitor(const int& id) { } CWindow* CWorkspace::getLastFocusedWindow() { - if (!g_pCompositor->windowValidMapped(m_pLastFocusedWindow) || m_pLastFocusedWindow->m_iWorkspaceID != m_iID) + if (!g_pCompositor->windowValidMapped(m_pLastFocusedWindow) || m_pLastFocusedWindow->workspaceID() != m_iID) return nullptr; return m_pLastFocusedWindow; } -void CWorkspace::rememberPrevWorkspace(const CWorkspace* prev) { +void CWorkspace::rememberPrevWorkspace(const PHLWORKSPACE& prev) { if (!prev) { m_sPrevWorkspace.iID = -1; m_sPrevWorkspace.name = ""; @@ -405,3 +418,12 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { UNREACHABLE(); return false; } + +void CWorkspace::markInert() { + m_bInert = true; + m_iID = WORKSPACE_INVALID; +} + +bool CWorkspace::inert() { + return m_bInert; +} diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index 0cae1859..1630baf5 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -3,6 +3,7 @@ #include "../helpers/AnimatedVariable.hpp" #include #include "../defines.hpp" +#include "DesktopTypes.hpp" enum eFullscreenMode : int8_t { FULLSCREEN_INVALID = -1, @@ -14,6 +15,8 @@ class CWindow; class CWorkspace { public: + static PHLWORKSPACE create(int id, int monitorID, std::string name, bool special = false); + // use create() don't use this CWorkspace(int id, int monitorID, std::string name, bool special = false); ~CWorkspace(); @@ -53,7 +56,10 @@ class CWorkspace { std::string m_szLastMonitor = ""; // Whether the user configured command for on-created-empty has been executed, if any - bool m_bOnCreatedEmptyExecuted = false; + bool m_bOnCreatedEmptyExecuted = false; + + // Inert: destroyed and invalid. If this is true, release the ptr you have. + bool inert(); void startAnim(bool in, bool left, bool instant = false); void setActive(bool on); @@ -61,12 +67,25 @@ class CWorkspace { void moveToMonitor(const int&); CWindow* getLastFocusedWindow(); - void rememberPrevWorkspace(const CWorkspace* prevWorkspace); + void rememberPrevWorkspace(const PHLWORKSPACE& prevWorkspace); std::string getConfigName(); bool matchesStaticSelector(const std::string& selector); + void markInert(); + private: - HOOK_CALLBACK_FN* m_pFocusedWindowHook = nullptr; + void init(PHLWORKSPACE self); + + HOOK_CALLBACK_FN* m_pFocusedWindowHook = nullptr; + bool m_bInert = true; + std::weak_ptr m_pSelf; }; + +inline bool valid(const PHLWORKSPACE& ref) { + if (!ref) + return false; + + return !ref->inert(); +} diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index a1fef175..bd27004b 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -163,7 +163,7 @@ void Events::listener_mapLayerSurface(void* owner, void* data) { CBox geomFixed = {layersurface->geometry.x + PMONITOR->vecPosition.x, layersurface->geometry.y + PMONITOR->vecPosition.y, layersurface->geometry.width, layersurface->geometry.height}; g_pHyprRenderer->damageBox(&geomFixed); - const auto WORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + const auto WORKSPACE = PMONITOR->activeWorkspace; const bool FULLSCREEN = WORKSPACE->m_bHasFullscreenWindow && WORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL; layersurface->startAnimation(!(layersurface->layer == ZWLR_LAYER_SHELL_V1_LAYER_TOP && FULLSCREEN && !GRABSFOCUS)); @@ -237,7 +237,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface); - if (!foundSurface && g_pCompositor->m_pLastWindow && g_pCompositor->isWorkspaceVisible(g_pCompositor->m_pLastWindow->m_iWorkspaceID)) { + if (!foundSurface && g_pCompositor->m_pLastWindow && g_pCompositor->isWorkspaceVisible(g_pCompositor->m_pLastWindow->workspaceID())) { // if there isn't any, focus the last window const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index 00546550..eb876cf2 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -57,9 +57,9 @@ void Events::listener_mapWindow(void* owner, void* data) { g_pCompositor->setActiveMonitor(g_pCompositor->getMonitorFromVector({})); PMONITOR = g_pCompositor->m_pLastMonitor; } - auto PWORKSPACE = PMONITOR->specialWorkspaceID ? g_pCompositor->getWorkspaceByID(PMONITOR->specialWorkspaceID) : g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + auto PWORKSPACE = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace : PMONITOR->activeWorkspace; PWINDOW->m_iMonitorID = PMONITOR->ID; - PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; + PWINDOW->m_pWorkspace = PWORKSPACE; PWINDOW->m_bIsMapped = true; PWINDOW->m_bReadyToDelete = false; PWINDOW->m_bFadingOut = false; @@ -153,7 +153,7 @@ void Events::listener_mapWindow(void* owner, void* data) { g_pKeybindManager->m_mDispatchers["focusmonitor"](std::to_string(PWINDOW->m_iMonitorID)); PMONITOR = PMONITORFROMID; } - PWINDOW->m_iWorkspaceID = PMONITOR->specialWorkspaceID ? PMONITOR->specialWorkspaceID : PMONITOR->activeWorkspace; + PWINDOW->m_pWorkspace = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspace : PMONITOR->activeWorkspace; Debug::log(LOG, "Rule monitor, applying to {:mw}", PWINDOW); } catch (std::exception& e) { Debug::log(ERR, "Rule monitor failed, rule: {} -> {} | err: {}", r.szRule, r.szValue, e.what()); } @@ -287,16 +287,16 @@ void Events::listener_mapWindow(void* owner, void* data) { PWORKSPACE = pWorkspace; - PWINDOW->m_iWorkspaceID = pWorkspace->m_iID; - PWINDOW->m_iMonitorID = pWorkspace->m_iMonitorID; + PWINDOW->m_pWorkspace = pWorkspace; + PWINDOW->m_iMonitorID = pWorkspace->m_iMonitorID; - if (g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->specialWorkspaceID && !pWorkspace->m_bIsSpecialWorkspace) + if (g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeSpecialWorkspace && !pWorkspace->m_bIsSpecialWorkspace) workspaceSilent = true; if (!workspaceSilent) { if (pWorkspace->m_bIsSpecialWorkspace) g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID)->setSpecialWorkspace(pWorkspace); - else if (PMONITOR->activeWorkspace != REQUESTEDWORKSPACEID) + else if (PMONITOR->activeWorkspaceID() != REQUESTEDWORKSPACEID) g_pKeybindManager->m_mDispatchers["workspace"](requestedWorkspaceName); PMONITOR = g_pCompositor->m_pLastMonitor; @@ -632,7 +632,7 @@ void Events::listener_mapWindow(void* owner, void* data) { // fix some xwayland apps that don't behave nicely PWINDOW->m_vReportedSize = PWINDOW->m_vPendingReportedSize; - g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); + g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID()); if (PMONITOR && PWINDOW->m_iX11Type == 2) PWINDOW->m_fX11SurfaceScaledBy = PMONITOR->scale; @@ -704,7 +704,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { } // remove the fullscreen window status from workspace if we closed it - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = PWINDOW->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && PWINDOW->m_bIsFullscreen) PWORKSPACE->m_bHasFullscreenWindow = false; @@ -723,7 +723,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { if (PWINDOWCANDIDATE != g_pCompositor->m_pLastWindow && PWINDOWCANDIDATE) g_pCompositor->focusWindow(PWINDOWCANDIDATE); - if (!PWINDOWCANDIDATE && g_pCompositor->getWindowsOnWorkspace(PWINDOW->m_iWorkspaceID) == 0) + if (!PWINDOWCANDIDATE && g_pCompositor->getWindowsOnWorkspace(PWINDOW->workspaceID()) == 0) g_pInputManager->refocus(); g_pInputManager->sendMotionEventsToFocused(); @@ -758,7 +758,7 @@ void Events::listener_unmapWindow(void* owner, void* data) { g_pInputManager->recheckIdleInhibitorStatus(); // force report all sizes (QT sometimes has an issue with this) - g_pCompositor->forceReportSizesToWindowsOnWorkspace(PWINDOW->m_iWorkspaceID); + g_pCompositor->forceReportSizesToWindowsOnWorkspace(PWINDOW->workspaceID()); // update lastwindow after focus PWINDOW->onUnmap(); @@ -934,7 +934,7 @@ void Events::listener_fullscreenWindow(void* owner, void* data) { const auto REQUESTED = &PWINDOW->m_uSurface.xdg->toplevel->requested; if (REQUESTED->fullscreen && PWINDOW->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = PWINDOW->m_pWorkspace; if (PWORKSPACE->m_efFullscreenMode != FULLSCREEN_FULL) { // Store that we were maximized PWINDOW->m_bWasMaximized = true; @@ -1094,10 +1094,10 @@ void Events::listener_configureX11(void* owner, void* data) { PWINDOW->updateWindowDecos(); - if (!g_pCompositor->isWorkspaceVisible(PWINDOW->m_iWorkspaceID)) + if (!g_pCompositor->isWorkspaceVisible(PWINDOW->workspaceID())) return; // further things are only for visible windows - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; + PWINDOW->m_pWorkspace = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; g_pCompositor->changeWindowZOrder(PWINDOW, true); @@ -1155,7 +1155,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { PWINDOW->m_vPosition = PWINDOW->m_vRealPosition.goal(); PWINDOW->m_vSize = PWINDOW->m_vRealSize.goal(); - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; + PWINDOW->m_pWorkspace = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; g_pCompositor->changeWindowZOrder(PWINDOW, true); PWINDOW->updateWindowDecos(); diff --git a/src/helpers/AnimatedVariable.cpp b/src/helpers/AnimatedVariable.cpp index 74575c83..65206af0 100644 --- a/src/helpers/AnimatedVariable.cpp +++ b/src/helpers/AnimatedVariable.cpp @@ -22,7 +22,7 @@ void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, SLayer m_bDummy = false; } -void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { +void CBaseAnimatedVariable::create(SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy) { m_eDamagePolicy = policy; m_pConfig = pAnimConfig; m_pWorkspace = pWorkspace; diff --git a/src/helpers/AnimatedVariable.hpp b/src/helpers/AnimatedVariable.hpp index 85ffb9ab..4c24f642 100644 --- a/src/helpers/AnimatedVariable.hpp +++ b/src/helpers/AnimatedVariable.hpp @@ -8,6 +8,7 @@ #include "Color.hpp" #include "../macros.hpp" #include "../debug/Log.hpp" +#include "../desktop/DesktopTypes.hpp" enum ANIMATEDVARTYPE { AVARTYPE_INVALID = -1, @@ -48,11 +49,11 @@ enum AVARDAMAGEPOLICY { }; class CAnimationManager; -class CWorkspace; struct SLayerSurface; struct SAnimationPropertyConfig; class CHyprRenderer; class CWindow; +class CWorkspace; // Utility to define a concept as a list of possible type template @@ -69,7 +70,7 @@ class CBaseAnimatedVariable { CBaseAnimatedVariable(ANIMATEDVARTYPE type); void create(SAnimationPropertyConfig* pAnimConfig, CWindow* pWindow, AVARDAMAGEPOLICY policy); void create(SAnimationPropertyConfig* pAnimConfig, SLayerSurface* pLayer, AVARDAMAGEPOLICY policy); - void create(SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy); + void create(SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy); void create(SAnimationPropertyConfig* pAnimConfig, AVARDAMAGEPOLICY policy); CBaseAnimatedVariable(const CBaseAnimatedVariable&) = delete; @@ -144,9 +145,9 @@ class CBaseAnimatedVariable { } protected: - void* m_pWindow = nullptr; - void* m_pWorkspace = nullptr; - void* m_pLayer = nullptr; + void* m_pWindow = nullptr; + std::weak_ptr m_pWorkspace; + void* m_pLayer = nullptr; SAnimationPropertyConfig* m_pConfig = nullptr; @@ -217,7 +218,7 @@ class CAnimatedVariable : public CBaseAnimatedVariable { m_Value = value; m_Goal = value; } - void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, CWorkspace* pWorkspace, AVARDAMAGEPOLICY policy) { + void create(const VarType& value, SAnimationPropertyConfig* pAnimConfig, PHLWORKSPACE pWorkspace, AVARDAMAGEPOLICY policy) { create(pAnimConfig, pWorkspace, policy); m_Value = value; m_Goal = value; diff --git a/src/helpers/MiscFunctions.cpp b/src/helpers/MiscFunctions.cpp index 2b83832c..779b45b1 100644 --- a/src/helpers/MiscFunctions.cpp +++ b/src/helpers/MiscFunctions.cpp @@ -289,9 +289,9 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { if (!g_pCompositor->m_pLastMonitor) return WORKSPACE_INVALID; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; - if (!PWORKSPACE) + if (!valid(PWORKSPACE)) return WORKSPACE_INVALID; const auto PLASTWORKSPACE = g_pCompositor->getWorkspaceByID(PWORKSPACE->m_sPrevWorkspace.iID); @@ -347,7 +347,8 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { std::sort(namedWSes.begin(), namedWSes.end()); // Just take a blind guess at where we'll probably end up - int predictedWSID = g_pCompositor->m_pLastMonitor->activeWorkspace + remains; + int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1; + int predictedWSID = activeWSID + remains; int remainingWSes = 0; char walkDir = in[1]; @@ -355,20 +356,20 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { predictedWSID = std::max(predictedWSID, 0); // Count how many invalidWSes are in between (how bad the prediction was) - int beginID = in[1] == '+' ? g_pCompositor->m_pLastMonitor->activeWorkspace + 1 : predictedWSID; - int endID = in[1] == '+' ? predictedWSID : g_pCompositor->m_pLastMonitor->activeWorkspace; + int beginID = in[1] == '+' ? activeWSID + 1 : predictedWSID; + int endID = in[1] == '+' ? predictedWSID : activeWSID; auto begin = invalidWSes.upper_bound(beginID - 1); // upper_bound is >, we want >= for (auto it = begin; *it <= endID && it != invalidWSes.end(); it++) { remainingWSes++; } // Handle named workspaces. They are treated like always before other workspaces - if (g_pCompositor->m_pLastMonitor->activeWorkspace < 0) { + if (activeWSID < 0) { // Behaviour similar to 'm' // Find current int currentItem = -1; for (size_t i = 0; i < namedWSes.size(); i++) { - if (namedWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) { + if (namedWSes[i] == activeWSID) { currentItem = i; break; } @@ -473,9 +474,10 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { remains = remains < 0 ? -((-remains) % validWSes.size()) : remains % validWSes.size(); // get the current item + int activeWSID = g_pCompositor->m_pLastMonitor->activeWorkspace ? g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID : 1; int currentItem = -1; for (size_t i = 0; i < validWSes.size(); i++) { - if (validWSes[i] == g_pCompositor->m_pLastMonitor->activeWorkspace) { + if (validWSes[i] == activeWSID) { currentItem = i; break; } @@ -496,7 +498,7 @@ int getWorkspaceIDFromString(const std::string& in, std::string& outName) { } else { if (in[0] == '+' || in[0] == '-') { if (g_pCompositor->m_pLastMonitor) { - const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PLUSMINUSRESULT = getPlusMinusKeywordResult(in, g_pCompositor->m_pLastMonitor->activeWorkspaceID()); if (!PLUSMINUSRESULT.has_value()) return WORKSPACE_INVALID; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 219257b9..4018cc8b 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -170,7 +170,7 @@ void CMonitor::onConnect(bool noRule) { for (auto& ws : g_pCompositor->m_vWorkspaces) { if (ws->m_szLastMonitor == szName || g_pCompositor->m_vMonitors.size() == 1 /* avoid lost workspaces on recover */) { - g_pCompositor->moveWorkspaceToMonitor(ws.get(), this); + g_pCompositor->moveWorkspaceToMonitor(ws, this); ws->startAnim(true, true, true); ws->m_szLastMonitor = ""; } @@ -281,10 +281,10 @@ void CMonitor::onDisconnect(bool destroy) { BACKUPMON->vecPosition.y + BACKUPMON->vecTransformedSize.y / 2.f); // move workspaces - std::deque wspToMove; + std::deque wspToMove; for (auto& w : g_pCompositor->m_vWorkspaces) { if (w->m_iMonitorID == ID || !g_pCompositor->getMonitorFromID(w->m_iMonitorID)) { - wspToMove.push_back(w.get()); + wspToMove.push_back(w); } } @@ -299,7 +299,7 @@ void CMonitor::onDisconnect(bool destroy) { g_pCompositor->m_pLastMonitor = nullptr; } - activeWorkspace = -1; + activeWorkspace.reset(); if (!destroy) wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output); @@ -403,17 +403,17 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { if (PNEWWORKSPACE) { // workspace exists, move it to the newly connected monitor g_pCompositor->moveWorkspaceToMonitor(PNEWWORKSPACE, this); - activeWorkspace = PNEWWORKSPACE->m_iID; + activeWorkspace = PNEWWORKSPACE; g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); PNEWWORKSPACE->startAnim(true, true, true); } else { if (newDefaultWorkspaceName == "") newDefaultWorkspaceName = std::to_string(WORKSPACEID); - PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(std::make_unique(WORKSPACEID, ID, newDefaultWorkspaceName)).get(); + PNEWWORKSPACE = g_pCompositor->m_vWorkspaces.emplace_back(CWorkspace::create(WORKSPACEID, ID, newDefaultWorkspaceName)); } - activeWorkspace = PNEWWORKSPACE->m_iID; + activeWorkspace = PNEWWORKSPACE; PNEWWORKSPACE->setActive(true); PNEWWORKSPACE->m_szLastMonitor = ""; @@ -481,10 +481,10 @@ void CMonitor::setMirror(const std::string& mirrorOf) { } // move all the WS - std::deque wspToMove; + std::deque wspToMove; for (auto& w : g_pCompositor->m_vWorkspaces) { if (w->m_iMonitorID == ID) { - wspToMove.push_back(w.get()); + wspToMove.push_back(w); } } @@ -493,7 +493,7 @@ void CMonitor::setMirror(const std::string& mirrorOf) { w->startAnim(true, true, true); } - activeWorkspace = -1; + activeWorkspace.reset(); wlr_output_layout_remove(g_pCompositor->m_sWLROutputLayout, output); @@ -532,24 +532,24 @@ float CMonitor::getDefaultScale() { return 1; } -void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool noMouseMove, bool noFocus) { +void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bool noMouseMove, bool noFocus) { if (!pWorkspace) return; if (pWorkspace->m_bIsSpecialWorkspace) { - if (specialWorkspaceID != pWorkspace->m_iID) { + if (activeSpecialWorkspace != pWorkspace) { Debug::log(LOG, "changeworkspace on special, togglespecialworkspace to id {}", pWorkspace->m_iID); g_pKeybindManager->m_mDispatchers["togglespecialworkspace"](pWorkspace->m_szName == "special" ? "" : pWorkspace->m_szName); } return; } - if (pWorkspace->m_iID == activeWorkspace) + if (pWorkspace == activeWorkspace) return; - const auto POLDWORKSPACE = g_pCompositor->getWorkspaceByID(activeWorkspace); + const auto POLDWORKSPACE = activeWorkspace; - activeWorkspace = pWorkspace->m_iID; + activeWorkspace = pWorkspace; if (!internal) { const auto ANIMTOLEFT = pWorkspace->m_iID > POLDWORKSPACE->m_iID; @@ -558,12 +558,11 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool // move pinned windows for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == POLDWORKSPACE->m_iID && w->m_bPinned) { - w->m_iWorkspaceID = pWorkspace->m_iID; - } + if (w->m_pWorkspace == POLDWORKSPACE && w->m_bPinned) + w->moveToWorkspace(pWorkspace); } - if (!noFocus && !g_pCompositor->m_pLastMonitor->specialWorkspaceID) { + if (!noFocus && !g_pCompositor->m_pLastMonitor->activeSpecialWorkspace) { static auto PFOLLOWMOUSE = CConfigValue("input:follow_mouse"); CWindow* pWindow = pWorkspace->getLastFocusedWindow(); @@ -599,37 +598,33 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool g_pCompositor->updateSuspendedStates(); - if (specialWorkspaceID) { - const auto PSPECIALWS = g_pCompositor->getWorkspaceByID(specialWorkspaceID); - if (PSPECIALWS->m_bHasFullscreenWindow) - g_pCompositor->updateFullscreenFadeOnWorkspace(PSPECIALWS); - } + if (activeSpecialWorkspace) + g_pCompositor->updateFullscreenFadeOnWorkspace(activeSpecialWorkspace); } void CMonitor::changeWorkspace(const int& id, bool internal, bool noMouseMove, bool noFocus) { changeWorkspace(g_pCompositor->getWorkspaceByID(id), internal, noMouseMove, noFocus); } -void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { +void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { g_pHyprRenderer->damageMonitor(this); if (!pWorkspace) { // remove special if exists - if (const auto EXISTINGSPECIAL = g_pCompositor->getWorkspaceByID(specialWorkspaceID); EXISTINGSPECIAL) { - EXISTINGSPECIAL->startAnim(false, false); + if (activeSpecialWorkspace) { + activeSpecialWorkspace->startAnim(false, false); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + szName}); } - specialWorkspaceID = 0; + activeSpecialWorkspace.reset(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(ID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(activeWorkspace); - if (const auto PLAST = PWORKSPACE->getLastFocusedWindow(); PLAST) + if (const auto PLAST = activeWorkspace->getLastFocusedWindow(); PLAST) g_pCompositor->focusWindow(PLAST); else g_pInputManager->refocus(); - g_pCompositor->updateFullscreenFadeOnWorkspace(PWORKSPACE); + g_pCompositor->updateFullscreenFadeOnWorkspace(activeWorkspace); g_pConfigManager->ensureVRR(this); @@ -638,20 +633,18 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { return; } - if (specialWorkspaceID) { - if (const auto EXISTINGSPECIAL = g_pCompositor->getWorkspaceByID(specialWorkspaceID); EXISTINGSPECIAL) - EXISTINGSPECIAL->startAnim(false, false); - } + if (activeSpecialWorkspace) + activeSpecialWorkspace->startAnim(false, false); bool animate = true; //close if open elsewhere const auto PMONITORWORKSPACEOWNER = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); - if (PMONITORWORKSPACEOWNER->specialWorkspaceID == pWorkspace->m_iID) { - PMONITORWORKSPACEOWNER->specialWorkspaceID = 0; + if (PMONITORWORKSPACEOWNER->activeSpecialWorkspace == pWorkspace) { + PMONITORWORKSPACEOWNER->activeSpecialWorkspace.reset(); g_pLayoutManager->getCurrentLayout()->recalculateMonitor(PMONITORWORKSPACEOWNER->ID); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + PMONITORWORKSPACEOWNER->szName}); - const auto PACTIVEWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITORWORKSPACEOWNER->activeWorkspace); + const auto PACTIVEWORKSPACE = PMONITORWORKSPACEOWNER->activeWorkspace; g_pCompositor->updateFullscreenFadeOnWorkspace(PACTIVEWORKSPACE); animate = false; @@ -659,12 +652,12 @@ void CMonitor::setSpecialWorkspace(CWorkspace* const pWorkspace) { // open special pWorkspace->m_iMonitorID = ID; - specialWorkspaceID = pWorkspace->m_iID; + activeSpecialWorkspace = pWorkspace; if (animate) pWorkspace->startAnim(true, true); for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == pWorkspace->m_iID) { + if (w->m_pWorkspace == pWorkspace) { w->m_iMonitorID = ID; w->updateSurfaceScaleTransformDetails(); w->setAnimationsToMove(); @@ -729,6 +722,13 @@ void CMonitor::updateMatrix() { } } +int64_t CMonitor::activeWorkspaceID() { + return activeWorkspace ? activeWorkspace->m_iID : 0; +} +int64_t CMonitor::activeSpecialWorkspaceID() { + return activeSpecialWorkspace ? activeSpecialWorkspace->m_iID : 0; +} + CMonitorState::CMonitorState(CMonitor* owner) { m_pOwner = owner; wlr_output_state_init(&m_state); diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp index 051c5305..909abb44 100644 --- a/src/helpers/Monitor.hpp +++ b/src/helpers/Monitor.hpp @@ -57,10 +57,11 @@ class CMonitor { bool primary = false; - uint64_t ID = -1; - int activeWorkspace = -1; - float setScale = 1; // scale set by cfg - float scale = 1; // real scale + uint64_t ID = -1; + PHLWORKSPACE activeWorkspace = nullptr; + PHLWORKSPACE activeSpecialWorkspace = nullptr; + float setScale = 1; // scale set by cfg + float scale = 1; // real scale std::string szName = ""; std::string szDescription = ""; @@ -119,9 +120,6 @@ class CMonitor { bool frameScheduledWhileBusy = false; } tearingState; - // for the special workspace. 0 means not open. - int specialWorkspaceID = 0; - std::array>, 4> m_aLayerSurfaceLayers; DYNLISTENER(monitorFrame); @@ -142,13 +140,15 @@ class CMonitor { bool isMirror(); bool matchesStaticSelector(const std::string& selector) const; float getDefaultScale(); - void changeWorkspace(CWorkspace* const pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false); + void changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal = false, bool noMouseMove = false, bool noFocus = false); void changeWorkspace(const int& id, bool internal = false, bool noMouseMove = false, bool noFocus = false); - void setSpecialWorkspace(CWorkspace* const pWorkspace); + void setSpecialWorkspace(const PHLWORKSPACE& pWorkspace); void setSpecialWorkspace(const int& id); void moveTo(const Vector2D& pos); Vector2D middle(); void updateMatrix(); + int64_t activeWorkspaceID(); + int64_t activeSpecialWorkspaceID(); bool m_bEnabled = false; bool m_bRenderingInitPassed = false; diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp index f1311e42..bad290e6 100644 --- a/src/helpers/WLClasses.hpp +++ b/src/helpers/WLClasses.hpp @@ -280,16 +280,16 @@ struct SIdleInhibitor { }; struct SSwipeGesture { - CWorkspace* pWorkspaceBegin = nullptr; + PHLWORKSPACE pWorkspaceBegin = nullptr; - double delta = 0; + double delta = 0; - int initialDirection = 0; - float avgSpeed = 0; - int speedPoints = 0; - int touch_id = 0; + int initialDirection = 0; + float avgSpeed = 0; + int speedPoints = 0; + int touch_id = 0; - CMonitor* pMonitor = nullptr; + CMonitor* pMonitor = nullptr; }; struct SIMEKbGrab { diff --git a/src/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 93f60e3f..67390010 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -105,7 +105,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { for (auto& m : g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == pNode->workspaceID) { + if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { PMONITOR = m.get(); break; } @@ -162,10 +162,10 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->m_vSize = nodeBox.size(); PWINDOW->m_vPosition = nodeBox.pos(); - const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto NODESONWORKSPACE = getNodesOnWorkspace(PWINDOW->workspaceID()); - if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && - (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { + if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && + (NODESONWORKSPACE == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -229,7 +229,7 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { + if (PWINDOW->onSpecialWorkspace() && !PWINDOW->m_bIsFullscreen) { // if special, we adjust the coords a bit static auto PSCALEFACTOR = CConfigValue("dwindle:special_scale_factor"); @@ -278,7 +278,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire overrideDirection = direction; // Populate the node with our window's data - PNODE->workspaceID = pWindow->m_iWorkspaceID; + PNODE->workspaceID = pWindow->workspaceID(); PNODE->pWindow = pWindow; PNODE->isNode = false; PNODE->layout = this; @@ -289,7 +289,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto MONFROMCURSOR = g_pCompositor->getMonitorFromVector(MOUSECOORDS); if (PMONITOR->ID == MONFROMCURSOR->ID && - (PNODE->workspaceID == PMONITOR->activeWorkspace || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->specialWorkspaceID)) && !*PUSEACTIVE) { + (PNODE->workspaceID == PMONITOR->activeWorkspaceID() || (g_pCompositor->isWorkspaceSpecial(PNODE->workspaceID) && PMONITOR->activeSpecialWorkspace)) && !*PUSEACTIVE) { OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); if (!OPENINGON && g_pCompositor->isPointOnReservedArea(MOUSECOORDS, PMONITOR)) @@ -297,7 +297,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire } else if (*PUSEACTIVE) { if (g_pCompositor->m_pLastWindow && !g_pCompositor->m_pLastWindow->m_bIsFloating && g_pCompositor->m_pLastWindow != pWindow && - g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID && g_pCompositor->m_pLastWindow->m_bIsMapped) { + g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace && g_pCompositor->m_pLastWindow->m_bIsMapped) { OPENINGON = getNodeFromWindow(g_pCompositor->m_pLastWindow); } else { OPENINGON = getNodeFromWindow(g_pCompositor->vectorToWindowUnified(MOUSECOORDS, RESERVED_EXTENTS | INPUT_EXTENTS)); @@ -307,7 +307,7 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire OPENINGON = getClosestNodeOnWorkspace(PNODE->workspaceID, MOUSECOORDS); } else - OPENINGON = getFirstNodeOnWorkspace(pWindow->m_iWorkspaceID); + OPENINGON = getFirstNodeOnWorkspace(pWindow->workspaceID()); Debug::log(LOG, "OPENINGON: {}, Monitor: {}", OPENINGON, PMONITOR->ID); @@ -551,40 +551,35 @@ void CHyprDwindleLayout::onWindowRemovedTiling(CWindow* pWindow) { void CHyprDwindleLayout::recalculateMonitor(const int& monid) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monid); - if (!PMONITOR) + if (!PMONITOR || !PMONITOR->activeWorkspace) return; // ??? g_pHyprRenderer->damageMonitor(PMONITOR); - if (PMONITOR->specialWorkspaceID) - calculateWorkspace(PMONITOR->specialWorkspaceID); + if (PMONITOR->activeSpecialWorkspace) + calculateWorkspace(PMONITOR->activeSpecialWorkspace); calculateWorkspace(PMONITOR->activeWorkspace); } -void CHyprDwindleLayout::calculateWorkspace(const int& ws) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); - - if (!PWORKSPACE) - return; - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); +void CHyprDwindleLayout::calculateWorkspace(const PHLWORKSPACE& pWorkspace) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!PMONITOR) return; - if (PWORKSPACE->m_bHasFullscreenWindow) { + if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); - if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { + if (pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + } else if (pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { SDwindleNodeData fakeNode; fakeNode.pWindow = PFULLWINDOW; fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - fakeNode.workspaceID = PWORKSPACE->m_iID; + fakeNode.workspaceID = pWorkspace->m_iID; PFULLWINDOW->m_vPosition = fakeNode.box.pos(); PFULLWINDOW->m_vSize = fakeNode.box.size(); fakeNode.ignoreFullscreenChecks = true; @@ -596,7 +591,7 @@ void CHyprDwindleLayout::calculateWorkspace(const int& ws) { return; } - const auto TOPNODE = getMasterNodeOnWorkspace(ws); + const auto TOPNODE = getMasterNodeOnWorkspace(pWorkspace->m_iID); if (TOPNODE) { TOPNODE->box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; @@ -813,7 +808,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && on) { // if the window wants to be fullscreen but there already is one, @@ -868,7 +863,7 @@ void CHyprDwindleLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscree SDwindleNodeData fakeNode; fakeNode.pWindow = pWindow; fakeNode.box = {PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft, PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight}; - fakeNode.workspaceID = pWindow->m_iWorkspaceID; + fakeNode.workspaceID = pWindow->workspaceID(); pWindow->m_vPosition = fakeNode.box.pos(); pWindow->m_vSize = fakeNode.box.size(); fakeNode.ignoreFullscreenChecks = true; @@ -981,7 +976,7 @@ void CHyprDwindleLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { if (PNODE->workspaceID != PNODE2->workspaceID) { std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID); - std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); + std::swap(pWindow2->m_pWorkspace, pWindow->m_pWorkspace); } pWindow->setAnimationsToMove(); @@ -1137,7 +1132,7 @@ Vector2D CHyprDwindleLayout::predictSizeForNewWindowTiled() { CWindow* candidate = g_pCompositor->m_pLastWindow; if (!candidate) - candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + candidate = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); // create a fake node SDwindleNodeData node; diff --git a/src/layout/DwindleLayout.hpp b/src/layout/DwindleLayout.hpp index b8c752f4..30c6e74a 100644 --- a/src/layout/DwindleLayout.hpp +++ b/src/layout/DwindleLayout.hpp @@ -78,7 +78,7 @@ class CHyprDwindleLayout : public IHyprLayout { int getNodesOnWorkspace(const int&); void applyNodeDataToWindow(SDwindleNodeData*, bool force = false); - void calculateWorkspace(const int& ws); + void calculateWorkspace(const PHLWORKSPACE& pWorkspace); SDwindleNodeData* getNodeFromWindow(CWindow*); SDwindleNodeData* getFirstNodeOnWorkspace(const int&); SDwindleNodeData* getClosestNodeOnWorkspace(const int&, const Vector2D&); diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index 1570fd73..3648faee 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -189,7 +189,7 @@ void IHyprLayout::onBeginDragWindow() { g_pCompositor->setWindowFullscreen(DRAGGINGWINDOW, false, FULLSCREEN_FULL); } - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(DRAGGINGWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = DRAGGINGWINDOW->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && (!DRAGGINGWINDOW->m_bCreatedOverFullscreen || !DRAGGINGWINDOW->m_bIsFloating)) { Debug::log(LOG, "Rejecting drag on a fullscreen workspace. (window under fullscreen)"); @@ -329,7 +329,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { static auto TIMER = std::chrono::high_resolution_clock::now(), MSTIMER = TIMER; - const auto SPECIAL = g_pCompositor->isWorkspaceSpecial(DRAGGINGWINDOW->m_iWorkspaceID); + const auto SPECIAL = DRAGGINGWINDOW->onSpecialWorkspace(); const auto DELTA = Vector2D(mousePos.x - m_vBeginDragXY.x, mousePos.y - m_vBeginDragXY.y); const auto TICKDELTA = Vector2D(mousePos.x - m_vLastDragXY.x, mousePos.y - m_vLastDragXY.y); @@ -479,10 +479,10 @@ void IHyprLayout::changeWindowFloatingMode(CWindow* pWindow) { if (!TILED) { const auto PNEWMON = g_pCompositor->getMonitorFromVector(pWindow->m_vRealPosition.value() + pWindow->m_vRealSize.value() / 2.f); pWindow->m_iMonitorID = PNEWMON->ID; - pWindow->moveToWorkspace(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); + pWindow->moveToWorkspace(PNEWMON->activeSpecialWorkspace ? PNEWMON->activeSpecialWorkspace : PNEWMON->activeWorkspace); pWindow->updateGroupOutputs(); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PNEWMON->specialWorkspaceID != 0 ? PNEWMON->specialWorkspaceID : PNEWMON->activeWorkspace); + const auto PWORKSPACE = PNEWMON->activeSpecialWorkspace ? PNEWMON->activeSpecialWorkspace : PNEWMON->activeWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) g_pCompositor->setWindowFullscreen(g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID), false); @@ -569,17 +569,17 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { if (!pWindow) return nullptr; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; // first of all, if this is a fullscreen workspace, if (PWORKSPACE->m_bHasFullscreenWindow) - return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->m_iWorkspaceID); + return g_pCompositor->getFullscreenWindowOnWorkspace(pWindow->workspaceID()); if (pWindow->m_bIsFloating) { // find whether there is a floating window below this one for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus && + if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_pWorkspace == pWindow->m_pWorkspace && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pWindow) { if (VECINRECT((pWindow->m_vSize / 2.f + pWindow->m_vPosition), w->m_vPosition.x, w->m_vPosition.y, w->m_vPosition.x + w->m_vSize.x, w->m_vPosition.y + w->m_vSize.y)) { @@ -589,7 +589,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { } // let's try the last tiled window. - if (m_pLastTiledWindow && m_pLastTiledWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID) + if (m_pLastTiledWindow && m_pLastTiledWindow->m_pWorkspace == pWindow->m_pWorkspace) return m_pLastTiledWindow; // if we don't, let's try to find any window that is in the middle @@ -599,7 +599,7 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { // if not, floating window for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_iWorkspaceID == pWindow->m_iWorkspaceID && !w->m_bX11ShouldntFocus && + if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 && w->m_pWorkspace == pWindow->m_pWorkspace && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != pWindow) return w.get(); } @@ -612,10 +612,10 @@ CWindow* IHyprLayout::getNextWindowCandidate(CWindow* pWindow) { auto pWindowCandidate = g_pCompositor->vectorToWindowUnified(pWindow->middle(), RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->m_iWorkspaceID); + pWindowCandidate = g_pCompositor->getTopLeftWindowOnWorkspace(pWindow->workspaceID()); if (!pWindowCandidate) - pWindowCandidate = g_pCompositor->getFirstWindowOnWorkspace(pWindow->m_iWorkspaceID); + pWindowCandidate = g_pCompositor->getFirstWindowOnWorkspace(pWindow->workspaceID()); if (!pWindowCandidate || pWindow == pWindowCandidate || !pWindowCandidate->m_bIsMapped || pWindowCandidate->isHidden() || pWindowCandidate->m_bX11ShouldntFocus || pWindowCandidate->m_iX11Type == 2 || pWindowCandidate->m_iMonitorID != g_pCompositor->m_pLastMonitor->ID) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 375840fb..2066ca76 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -90,7 +90,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc const auto PNODE = *PNEWTOP ? &m_lMasterNodesData.emplace_front() : &m_lMasterNodesData.emplace_back(); - PNODE->workspaceID = pWindow->m_iWorkspaceID; + PNODE->workspaceID = pWindow->workspaceID(); PNODE->pWindow = pWindow; static auto PNEWISMASTER = CConfigValue("master:new_is_master"); @@ -99,9 +99,9 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc static auto PMFACT = CConfigValue("master:mfact"); float lastSplitPercent = *PMFACT; - auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_iWorkspaceID == pWindow->m_iWorkspaceID ? + auto OPENINGON = isWindowTiled(g_pCompositor->m_pLastWindow) && g_pCompositor->m_pLastWindow->m_pWorkspace == pWindow->m_pWorkspace ? getNodeFromWindow(g_pCompositor->m_pLastWindow) : - getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); + getMasterNodeOnWorkspace(pWindow->workspaceID()); const auto MOUSECOORDS = g_pInputManager->getMouseCoordsInternal(); @@ -133,7 +133,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc pWindow->applyGroupRules(); static auto PDROPATCURSOR = CConfigValue("master:drop_at_cursor"); - const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWindow->workspaceID()); eOrientation orientation = PWORKSPACEDATA->orientation; const auto NODEIT = std::find(m_lMasterNodesData.begin(), m_lMasterNodesData.end(), *PNODE); @@ -142,7 +142,7 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc if (*PDROPATCURSOR && g_pInputManager->dragMode == MBIND_MOVE) { if (WINDOWSONWORKSPACE > 2) { for (auto it = m_lMasterNodesData.begin(); it != m_lMasterNodesData.end(); ++it) { - if (it->workspaceID != pWindow->m_iWorkspaceID) + if (it->workspaceID != pWindow->workspaceID()) continue; const CBox box = it->pWindow->getWindowIdealBoundingBoxIgnoreReserved(); if (box.containsPoint(MOUSECOORDS)) { @@ -286,41 +286,36 @@ void CHyprMasterLayout::onWindowRemovedTiling(CWindow* pWindow) { void CHyprMasterLayout::recalculateMonitor(const int& monid) { const auto PMONITOR = g_pCompositor->getMonitorFromID(monid); - if (!PMONITOR) + if (!PMONITOR || !PMONITOR->activeWorkspace) return; g_pHyprRenderer->damageMonitor(PMONITOR); - if (PMONITOR->specialWorkspaceID) - calculateWorkspace(PMONITOR->specialWorkspaceID); + if (PMONITOR->activeSpecialWorkspace) + calculateWorkspace(PMONITOR->activeSpecialWorkspace); calculateWorkspace(PMONITOR->activeWorkspace); } -void CHyprMasterLayout::calculateWorkspace(const int& ws) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(ws); - - if (!PWORKSPACE) - return; - - const auto PMONITOR = g_pCompositor->getMonitorFromID(PWORKSPACE->m_iMonitorID); +void CHyprMasterLayout::calculateWorkspace(PHLWORKSPACE pWorkspace) { + const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); if (!PMONITOR) return; - if (PWORKSPACE->m_bHasFullscreenWindow) { + if (pWorkspace->m_bHasFullscreenWindow) { // massive hack from the fullscreen func - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); + const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); - if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { + if (pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL) { PFULLWINDOW->m_vRealPosition = PMONITOR->vecPosition; PFULLWINDOW->m_vRealSize = PMONITOR->vecSize; - } else if (PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { + } else if (pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { SMasterNodeData fakeNode; fakeNode.pWindow = PFULLWINDOW; fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = PWORKSPACE->m_iID; + fakeNode.workspaceID = pWorkspace->m_iID; PFULLWINDOW->m_vPosition = fakeNode.position; PFULLWINDOW->m_vSize = fakeNode.size; fakeNode.ignoreFullscreenChecks = true; @@ -332,14 +327,14 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { return; } - const auto PWORKSPACEDATA = getMasterWorkspaceData(ws); - const auto PMASTERNODE = getMasterNodeOnWorkspace(PWORKSPACE->m_iID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(pWorkspace->m_iID); + const auto PMASTERNODE = getMasterNodeOnWorkspace(pWorkspace->m_iID); if (!PMASTERNODE) return; // dynamic workspace rules - const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(ws)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(pWorkspace); std::string orientationForWs; for (auto& wsRule : WORKSPACERULES) { @@ -363,8 +358,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); - const auto MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); - const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); + const auto MASTERS = getMastersOnWorkspace(pWorkspace->m_iID); + const auto WINDOWS = getNodesOnWorkspace(pWorkspace->m_iID); const auto STACKWINDOWS = WINDOWS - MASTERS; const auto WSSIZE = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; const auto WSPOS = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; @@ -387,7 +382,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { // check the total width and height so that later // if larger/smaller than screen size them down/up for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID == PWORKSPACE->m_iID) { + if (nd.workspaceID == pWorkspace->m_iID) { if (nd.isMaster) masterAccumulatedSize += totalSize / MASTERS * nd.percSize; else @@ -414,7 +409,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextY = WSSIZE.y - HEIGHT; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || !nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || !nd.isMaster) continue; float WIDTH = mastersLeft > 1 ? widthLeft / mastersLeft * nd.percSize : widthLeft; @@ -451,7 +446,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || !nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || !nd.isMaster) continue; float HEIGHT = mastersLeft > 1 ? heightLeft / mastersLeft * nd.percSize : heightLeft; @@ -488,7 +483,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextY = PMASTERNODE->size.y; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; float WIDTH = slavesLeft > 1 ? widthLeft / slavesLeft * nd.percSize : widthLeft; @@ -518,7 +513,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { nextX = PMASTERNODE->size.x; for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; float HEIGHT = slavesLeft > 1 ? heightLeft / slavesLeft * nd.percSize : heightLeft; @@ -558,7 +553,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { float slaveAccumulatedHeightR = 0; if (*PSMARTRESIZING) { for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; if (onRight) { @@ -572,7 +567,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { } for (auto& nd : m_lMasterNodesData) { - if (nd.workspaceID != PWORKSPACE->m_iID || nd.isMaster) + if (nd.workspaceID != pWorkspace->m_iID || nd.isMaster) continue; if (onRight) { @@ -625,7 +620,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { if (g_pCompositor->isWorkspaceSpecial(pNode->workspaceID)) { for (auto& m : g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == pNode->workspaceID) { + if (m->activeSpecialWorkspaceID() == pNode->workspaceID) { PMONITOR = m.get(); break; } @@ -648,7 +643,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { const auto PWINDOW = pNode->pWindow; // get specific gaps and rules for this workspace, // if user specified them in config - const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)); + const auto WORKSPACERULES = g_pConfigManager->getWorkspaceRulesFor(PWINDOW->m_pWorkspace); if (PWINDOW->m_bIsFullscreen && !pNode->ignoreFullscreenChecks) return; @@ -679,9 +674,8 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->m_vSize = pNode->size; PWINDOW->m_vPosition = pNode->position; - if (*PNOGAPSWHENONLY && !g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && - (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 || - (PWINDOW->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { + if (*PNOGAPSWHENONLY && !PWINDOW->onSpecialWorkspace() && + (getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 || (PWINDOW->m_bIsFullscreen && PWINDOW->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_MAXIMIZED))) { PWINDOW->m_sSpecialRenderData.rounding = false; PWINDOW->m_sSpecialRenderData.shadow = false; @@ -721,7 +715,7 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { calcPos = calcPos + RESERVED.topLeft; calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); - if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID) && !PWINDOW->m_bIsFullscreen) { + if (PWINDOW->onSpecialWorkspace() && !PWINDOW->m_bIsFullscreen) { static auto PSCALEFACTOR = CConfigValue("master:special_scale_factor"); CBox wb = {calcPos + (calcSize - calcSize * *PSCALEFACTOR) / 2.f, calcSize * *PSCALEFACTOR}; @@ -772,7 +766,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne } const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); static auto ALWAYSCENTER = CConfigValue("master:always_center_master"); static auto PSMARTRESIZING = CConfigValue("master:smart_resizing"); @@ -793,7 +787,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto WINDOWS = getNodesOnWorkspace(PNODE->workspaceID); const auto STACKWINDOWS = WINDOWS - MASTERS; - if (getNodesOnWorkspace(PWINDOW->m_iWorkspaceID) == 1 && !centered) + if (getNodesOnWorkspace(PWINDOW->workspaceID()) == 1 && !centered) return; m_bForceWarps = true; @@ -815,7 +809,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne default: UNREACHABLE(); } - const auto workspaceIdForResizing = PMONITOR->specialWorkspaceID == 0 ? PMONITOR->activeWorkspace : PMONITOR->specialWorkspaceID; + const auto workspaceIdForResizing = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeWorkspaceID() : PMONITOR->activeSpecialWorkspaceID(); for (auto& n : m_lMasterNodesData) { if (n.isMaster && n.workspaceID == workspaceIdForResizing) n.percMaster = std::clamp(n.percMaster + delta, 0.05, 0.95); @@ -908,7 +902,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen return; // ignore const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && on) { // if the window wants to be fullscreen but there already is one, @@ -964,7 +958,7 @@ void CHyprMasterLayout::fullscreenRequestForWindow(CWindow* pWindow, eFullscreen fakeNode.pWindow = pWindow; fakeNode.position = PMONITOR->vecPosition + PMONITOR->vecReservedTopLeft; fakeNode.size = PMONITOR->vecSize - PMONITOR->vecReservedTopLeft - PMONITOR->vecReservedBottomRight; - fakeNode.workspaceID = pWindow->m_iWorkspaceID; + fakeNode.workspaceID = pWindow->workspaceID(); pWindow->m_vPosition = fakeNode.position; pWindow->m_vSize = fakeNode.size; fakeNode.ignoreFullscreenChecks = true; @@ -1010,10 +1004,10 @@ void CHyprMasterLayout::moveWindowTo(CWindow* pWindow, const std::string& dir) { pWindow->setAnimationsToMove(); - if (pWindow->m_iWorkspaceID != PWINDOW2->m_iWorkspaceID) { + if (pWindow->m_pWorkspace != PWINDOW2->m_pWorkspace) { // if different monitors, send to monitor onWindowRemovedTiling(pWindow); - pWindow->moveToWorkspace(PWINDOW2->m_iWorkspaceID); + pWindow->moveToWorkspace(PWINDOW2->m_pWorkspace); pWindow->m_iMonitorID = PWINDOW2->m_iMonitorID; const auto pMonitor = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); g_pCompositor->setActiveMonitor(pMonitor); @@ -1035,7 +1029,7 @@ void CHyprMasterLayout::switchWindows(CWindow* pWindow, CWindow* pWindow2) { if (PNODE->workspaceID != PNODE2->workspaceID) { std::swap(pWindow2->m_iMonitorID, pWindow->m_iMonitorID); - std::swap(pWindow2->m_iWorkspaceID, pWindow->m_iWorkspaceID); + std::swap(pWindow2->m_pWorkspace, pWindow->m_pWorkspace); } // massive hack: just swap window pointers, lol @@ -1061,7 +1055,7 @@ void CHyprMasterLayout::alterSplitRatio(CWindow* pWindow, float ratio, bool exac if (!PNODE) return; - const auto PMASTER = getMasterNodeOnWorkspace(pWindow->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(pWindow->workspaceID()); float newRatio = exact ? ratio : PMASTER->percMaster + ratio; PMASTER->percMaster = std::clamp(newRatio, 0.05f, 0.95f); @@ -1097,7 +1091,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri return; if (header.pWindow->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID); + const auto PWORKSPACE = header.pWindow->m_pWorkspace; const auto FSMODE = PWORKSPACE->m_efFullscreenMode; static auto INHERITFULLSCREEN = CConfigValue("master:inherit_fullscreen"); g_pCompositor->setWindowFullscreen(header.pWindow, false, FULLSCREEN_FULL); @@ -1137,7 +1131,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!isWindowTiled(PWINDOW)) return 0; - const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->workspaceID()); if (!PMASTER) return 0; @@ -1175,7 +1169,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PWINDOW) return 0; - const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->m_iWorkspaceID); + const auto PMASTER = getMasterNodeOnWorkspace(PWINDOW->workspaceID()); if (!PMASTER) return 0; @@ -1252,8 +1246,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PNODE = getNodeFromWindow(header.pWindow); - const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); - const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); + const auto WINDOWS = getNodesOnWorkspace(header.pWindow->workspaceID()); + const auto MASTERS = getMastersOnWorkspace(header.pWindow->workspaceID()); static auto SMALLSPLIT = CConfigValue("master:allow_small_split"); if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) @@ -1263,7 +1257,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PNODE || PNODE->isMaster) { // first non-master node for (auto& n : m_lMasterNodesData) { - if (n.workspaceID == header.pWindow->m_iWorkspaceID && !n.isMaster) { + if (n.workspaceID == header.pWindow->workspaceID() && !n.isMaster) { n.isMaster = true; break; } @@ -1284,8 +1278,8 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto PNODE = getNodeFromWindow(header.pWindow); - const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); - const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); + const auto WINDOWS = getNodesOnWorkspace(header.pWindow->workspaceID()); + const auto MASTERS = getMastersOnWorkspace(header.pWindow->workspaceID()); if (WINDOWS < 2 || MASTERS < 2) return 0; @@ -1295,7 +1289,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri if (!PNODE || !PNODE->isMaster) { // first non-master node for (auto& nd : m_lMasterNodesData | std::views::reverse) { - if (nd.workspaceID == header.pWindow->m_iWorkspaceID && nd.isMaster) { + if (nd.workspaceID == header.pWindow->workspaceID() && nd.isMaster) { nd.isMaster = false; break; } @@ -1313,7 +1307,7 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); if (command == "orientationleft") PWORKSPACEDATA->orientation = ORIENTATION_LEFT; @@ -1421,7 +1415,7 @@ void CHyprMasterLayout::runOrientationCycle(SLayoutMessageHeader& header, CVarLi g_pCompositor->setWindowFullscreen(PWINDOW, false, FULLSCREEN_FULL); - const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACEDATA = getMasterWorkspaceData(PWINDOW->workspaceID()); int nextOrPrev = 0; for (size_t i = 0; i < cycle.size(); ++i) { @@ -1479,19 +1473,19 @@ Vector2D CHyprMasterLayout::predictSizeForNewWindowTiled() { if (!g_pCompositor->m_pLastMonitor) return {}; - const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const int NODES = getNodesOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); if (NODES <= 0) return g_pCompositor->m_pLastMonitor->vecSize; - const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto MASTER = getMasterNodeOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); if (!MASTER) // wtf return {}; if (*PNEWISMASTER) { return MASTER->size; } else { - const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto SLAVES = NODES - getMastersOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace->m_iID); // TODO: make this better return {g_pCompositor->m_pLastMonitor->vecSize.x - MASTER->size.x, g_pCompositor->m_pLastMonitor->vecSize.y / (SLAVES + 1)}; diff --git a/src/layout/MasterLayout.hpp b/src/layout/MasterLayout.hpp index 1e48b5dd..922d7bb6 100644 --- a/src/layout/MasterLayout.hpp +++ b/src/layout/MasterLayout.hpp @@ -84,7 +84,7 @@ class CHyprMasterLayout : public IHyprLayout { SMasterNodeData* getNodeFromWindow(CWindow*); SMasterNodeData* getMasterNodeOnWorkspace(const int&); SMasterWorkspaceData* getMasterWorkspaceData(const int&); - void calculateWorkspace(const int&); + void calculateWorkspace(PHLWORKSPACE); CWindow* getNextWindow(CWindow*, bool); int getMastersOnWorkspace(const int&); diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index ab81841c..a9a72941 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -79,11 +79,11 @@ void CAnimationManager::tick() { const float SPENT = av->getPercent(); // window stuff - const auto PWINDOW = (CWindow*)av->m_pWindow; - const auto PWORKSPACE = (CWorkspace*)av->m_pWorkspace; - const auto PLAYER = (SLayerSurface*)av->m_pLayer; - CMonitor* PMONITOR = nullptr; - bool animationsDisabled = animGlobalDisabled; + const auto PWINDOW = (CWindow*)av->m_pWindow; + PHLWORKSPACE PWORKSPACE = av->m_pWorkspace.lock(); + const auto PLAYER = (SLayerSurface*)av->m_pLayer; + CMonitor* PMONITOR = nullptr; + bool animationsDisabled = animGlobalDisabled; if (PWINDOW) { if (av->m_eDamagePolicy == AVARDAMAGE_ENTIRE) { @@ -111,7 +111,7 @@ void CAnimationManager::tick() { // TODO: just make this into a damn callback already vax... for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != PWORKSPACE->m_iID) + if (!w->m_bIsMapped || w->isHidden() || w->m_pWorkspace != PWORKSPACE) continue; if (w->m_bIsFloating && !w->m_bPinned) { @@ -129,7 +129,7 @@ void CAnimationManager::tick() { // damage any workspace window that is on any monitor for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->m_bPinned) + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE || w->m_bPinned) continue; g_pHyprRenderer->damageWindow(w.get()); @@ -146,7 +146,7 @@ void CAnimationManager::tick() { animationsDisabled = animationsDisabled || PLAYER->noAnimations; } - const bool VISIBLE = PWINDOW ? g_pCompositor->isWorkspaceVisible(PWINDOW->m_iWorkspaceID) : true; + const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? g_pCompositor->isWorkspaceVisible(PWINDOW->workspaceID()) : true; // beziers are with a switch unforto // TODO: maybe do something cleaner @@ -212,7 +212,7 @@ void CAnimationManager::tick() { g_pHyprRenderer->damageWindow(PWINDOW); } else if (PWORKSPACE) { for (auto& w : g_pCompositor->m_vWindows) { - if (!g_pCompositor->windowValidMapped(w.get()) || w->m_iWorkspaceID != PWORKSPACE->m_iID) + if (!g_pCompositor->windowValidMapped(w.get()) || w->m_pWorkspace != PWORKSPACE) continue; w->updateWindowDecos(); diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 03887514..df27a8cf 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -225,13 +225,13 @@ bool CKeybindManager::tryMoveFocusToMonitor(CMonitor* monitor) { return false; } - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); - const auto PNEWMAINWORKSPACE = g_pCompositor->getWorkspaceByID(monitor->activeWorkspace); + const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; + const auto PNEWMAINWORKSPACE = monitor->activeWorkspace; g_pInputManager->unconstrainMouse(); PNEWMAINWORKSPACE->rememberPrevWorkspace(PWORKSPACE); - const auto PNEWWORKSPACE = monitor->specialWorkspaceID != 0 ? g_pCompositor->getWorkspaceByID(monitor->specialWorkspaceID) : PNEWMAINWORKSPACE; + const auto PNEWWORKSPACE = monitor->activeSpecialWorkspace ? monitor->activeSpecialWorkspace : PNEWMAINWORKSPACE; const auto PNEWWINDOW = PNEWWORKSPACE->getLastFocusedWindow(); if (PNEWWINDOW) { @@ -259,8 +259,8 @@ void CKeybindManager::switchToWindow(CWindow* PWINDOWTOCHANGETO) { // remove constraints g_pInputManager->unconstrainMouse(); - if (PLASTWINDOW && PLASTWINDOW->m_iWorkspaceID == PWINDOWTOCHANGETO->m_iWorkspaceID && PLASTWINDOW->m_bIsFullscreen) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PLASTWINDOW->m_iWorkspaceID); + if (PLASTWINDOW && PLASTWINDOW->m_pWorkspace == PWINDOWTOCHANGETO->m_pWorkspace && PLASTWINDOW->m_bIsFullscreen) { + const auto PWORKSPACE = PLASTWINDOW->m_pWorkspace; const auto FSMODE = PWORKSPACE->m_efFullscreenMode; if (!PWINDOWTOCHANGETO->m_bPinned) @@ -874,11 +874,11 @@ void toggleActiveFloatingCore(std::string args, std::optional floatState) curr = curr->m_sGroupData.pNextWindow; } - g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); + g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID()); } else { PWINDOW->m_bIsFloating = !PWINDOW->m_bIsFloating; - g_pCompositor->updateWorkspaceWindows(PWINDOW->m_iWorkspaceID); + g_pCompositor->updateWorkspaceWindows(PWINDOW->workspaceID()); g_pLayoutManager->getCurrentLayout()->changeWindowFloatingMode(PWINDOW); } @@ -927,7 +927,7 @@ void CKeybindManager::changeworkspace(std::string args) { if (!PMONITOR) return; - const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + const auto PCURRENTWORKSPACE = PMONITOR->activeWorkspace; const bool EXPLICITPREVIOUS = args.starts_with("previous"); if (args.starts_with("previous")) { @@ -1044,14 +1044,14 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { return; } - if (WORKSPACEID == PWINDOW->m_iWorkspaceID) { + if (WORKSPACEID == PWINDOW->workspaceID()) { Debug::log(LOG, "Not moving to workspace because it didn't change."); return; } auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); CMonitor* pMonitor = nullptr; - const auto POLDWS = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + const auto POLDWS = PWINDOW->m_pWorkspace; static auto PALLOWWORKSPACECYCLES = CConfigValue("binds:allow_workspace_cycles"); g_pHyprRenderer->damageWindow(PWINDOW); @@ -1106,7 +1106,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { return; } - if (WORKSPACEID == PWINDOW->m_iWorkspaceID) + if (WORKSPACEID == PWINDOW->workspaceID()) return; g_pHyprRenderer->damageWindow(PWINDOW); @@ -1220,7 +1220,7 @@ void CKeybindManager::moveActiveTo(std::string args) { if (!PNEWMONITOR) return; - moveActiveToWorkspace(std::to_string(PNEWMONITOR->activeWorkspace)); + moveActiveToWorkspace(PNEWMONITOR->activeWorkspace->getConfigName()); return; } @@ -1265,7 +1265,7 @@ void CKeybindManager::moveActiveTo(std::string args) { if (!PMONITORTOCHANGETO) return; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITORTOCHANGETO->activeWorkspace); + const auto PWORKSPACE = PMONITORTOCHANGETO->activeWorkspace; moveActiveToWorkspace(PWORKSPACE->getConfigName()); } @@ -1324,7 +1324,7 @@ void CKeybindManager::toggleSplit(std::string args) { if (!header.pWindow) return; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID); + const auto PWORKSPACE = header.pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) return; @@ -1339,7 +1339,7 @@ void CKeybindManager::swapSplit(std::string args) { if (!header.pWindow) return; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(header.pWindow->m_iWorkspaceID); + const auto PWORKSPACE = header.pWindow->m_pWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow) return; @@ -1447,7 +1447,7 @@ void CKeybindManager::moveCursor(std::string args) { void CKeybindManager::workspaceOpt(std::string args) { // current workspace - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; if (!PWORKSPACE) return; // ???? @@ -1457,7 +1457,7 @@ void CKeybindManager::workspaceOpt(std::string args) { // apply for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID) + if (!w->m_bIsMapped || w->m_pWorkspace != PWORKSPACE) continue; w->m_bIsPseudotiled = PWORKSPACE->m_bDefaultPseudo; @@ -1472,7 +1472,7 @@ void CKeybindManager::workspaceOpt(std::string args) { ptrs.push_back(w.get()); for (auto& w : ptrs) { - if (!w->m_bIsMapped || w->m_iWorkspaceID != PWORKSPACE->m_iID || w->isHidden()) + if (!w->m_bIsMapped || w->m_pWorkspace != PWORKSPACE || w->isHidden()) continue; if (!w->m_bRequestsFloat && w->m_bIsFloating != PWORKSPACE->m_bDefaultFloating) { @@ -1526,7 +1526,7 @@ void CKeybindManager::moveCurrentWorkspaceToMonitor(std::string args) { } // get the current workspace - const auto PCURRENTWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PCURRENTWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; if (!PCURRENTWORKSPACE) { Debug::log(ERR, "moveCurrentWorkspaceToMonitor invalid workspace!"); @@ -1595,7 +1595,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { static auto PBACKANDFORTH = CConfigValue("binds:workspace_back_and_forth"); - if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspace == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) { + if (*PBACKANDFORTH && PCURRMONITOR->activeWorkspaceID() == workspaceID && pWorkspace->m_sPrevWorkspace.iID != -1) { const int PREVWORKSPACEID = pWorkspace->m_sPrevWorkspace.iID; const auto PREVWORKSPACENAME = pWorkspace->m_sPrevWorkspace.name; // Workspace to focus is previous workspace @@ -1612,7 +1612,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { Debug::log(ERR, "focusWorkspaceOnCurrentMonitor old monitor doesn't exist!"); return; } - if (POLDMONITOR->activeWorkspace == workspaceID) { + if (POLDMONITOR->activeWorkspaceID() == workspaceID) { g_pCompositor->swapActiveWorkspaces(POLDMONITOR, PCURRMONITOR); return; } else { @@ -1634,10 +1634,10 @@ void CKeybindManager::toggleSpecialWorkspace(std::string args) { bool requestedWorkspaceIsAlreadyOpen = false; const auto PMONITOR = g_pCompositor->m_pLastMonitor; - int specialOpenOnMonitor = PMONITOR->specialWorkspaceID; + int specialOpenOnMonitor = PMONITOR->activeSpecialWorkspaceID(); for (auto& m : g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == workspaceID) { + if (m->activeSpecialWorkspaceID() == workspaceID) { requestedWorkspaceIsAlreadyOpen = true; break; } @@ -1750,8 +1750,8 @@ void CKeybindManager::circleNext(std::string arg) { if (!g_pCompositor->m_pLastWindow) { // if we have a clear focus, find the first window and get the next focusable. - if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace) > 0) { - const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspace); + if (g_pCompositor->getWindowsOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()) > 0) { + const auto PWINDOW = g_pCompositor->getFirstWindowOnWorkspace(g_pCompositor->m_pLastMonitor->activeWorkspaceID()); switchToWindow(PWINDOW); } @@ -1781,13 +1781,13 @@ void CKeybindManager::focusWindow(std::string regexp) { Debug::log(LOG, "Focusing to window name: {}", PWINDOW->m_szTitle); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = PWINDOW->m_pWorkspace; if (!PWORKSPACE) { Debug::log(ERR, "BUG THIS: null workspace in focusWindow"); return; } - if (g_pCompositor->m_pLastMonitor->activeWorkspace != PWINDOW->m_iWorkspaceID) { + if (g_pCompositor->m_pLastMonitor->activeWorkspace != PWINDOW->m_pWorkspace) { Debug::log(LOG, "Fake executing workspace to move focus"); changeworkspace(PWORKSPACE->getConfigName()); } @@ -1975,7 +1975,7 @@ void CKeybindManager::swapnext(std::string arg) { const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; const auto PLASTCYCLED = g_pCompositor->windowValidMapped(g_pCompositor->m_pLastWindow->m_pLastCycledWindow) && - g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_iWorkspaceID == PLASTWINDOW->m_iWorkspaceID ? + g_pCompositor->m_pLastWindow->m_pLastCycledWindow->m_pWorkspace == PLASTWINDOW->m_pWorkspace ? g_pCompositor->m_pLastWindow->m_pLastCycledWindow : nullptr; @@ -2029,13 +2029,13 @@ void CKeybindManager::pinActive(std::string args) { if (!PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) return; - PWINDOW->m_bPinned = !PWINDOW->m_bPinned; - PWINDOW->m_iWorkspaceID = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeWorkspace; + PWINDOW->m_bPinned = !PWINDOW->m_bPinned; + PWINDOW->m_pWorkspace = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID)->activeWorkspace; PWINDOW->updateDynamicRules(); g_pCompositor->updateWindowAnimatedDecorationValues(PWINDOW); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); + const auto PWORKSPACE = PWINDOW->m_pWorkspace; PWORKSPACE->m_pLastFocusedWindow = g_pCompositor->vectorToWindowUnified(g_pInputManager->getMouseCoordsInternal(), RESERVED_EXTENTS | INPUT_EXTENTS); diff --git a/src/managers/XWaylandManager.cpp b/src/managers/XWaylandManager.cpp index e37a08f7..325229e7 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -74,7 +74,7 @@ void CHyprXWaylandManager::activateWindow(CWindow* pWindow, bool activate) { } if (!pWindow->m_bPinned) - g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID)->m_pLastFocusedWindow = pWindow; + pWindow->m_pWorkspace->m_pLastFocusedWindow = pWindow; } void CHyprXWaylandManager::getGeometryForWindow(CWindow* pWindow, CBox* pbox) { diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 46e4fea1..12d768f5 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -65,7 +65,7 @@ void CInputManager::recheckIdleInhibitorStatus() { return; } - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->m_iWorkspaceID)) { + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->workspaceID())) { g_pCompositor->setIdleActivityInhibit(false); return; } diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp index 4e2bf709..a37cfbe5 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -230,7 +230,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { foundSurface = g_pCompositor->vectorToLayerSurface(mouseCoords, &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface); // then, we check if the workspace doesnt have a fullscreen window - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + const auto PWORKSPACE = PMONITOR->activeWorkspace; if (PWORKSPACE->m_bHasFullscreenWindow && !foundSurface && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); @@ -244,7 +244,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (PWINDOWIDEAL && ((PWINDOWIDEAL->m_bIsFloating && PWINDOWIDEAL->m_bCreatedOverFullscreen) /* floating over fullscreen */ - || (PMONITOR->specialWorkspaceID == PWINDOWIDEAL->m_iWorkspaceID) /* on an open special workspace */)) + || (PMONITOR->activeSpecialWorkspace == PWINDOWIDEAL->m_pWorkspace) /* on an open special workspace */)) pFoundWindow = PWINDOWIDEAL; if (!pFoundWindow->m_bIsX11) { @@ -260,10 +260,10 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { if (!foundSurface) { if (PWORKSPACE->m_bHasFullscreenWindow && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_MAXIMIZED) { - if (PMONITOR->specialWorkspaceID) { + if (PMONITOR->activeSpecialWorkspace) { pFoundWindow = g_pCompositor->vectorToWindowUnified(mouseCoords, RESERVED_EXTENTS | INPUT_EXTENTS | ALLOW_FLOATING); - if (pFoundWindow && !g_pCompositor->isWorkspaceSpecial(pFoundWindow->m_iWorkspaceID)) { + if (pFoundWindow && !pFoundWindow->onSpecialWorkspace()) { pFoundWindow = g_pCompositor->getFullscreenWindowOnWorkspace(PWORKSPACE->m_iID); } } else { diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 5c3b7c28..47a6f5bd 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -24,7 +24,7 @@ void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) { } void CInputManager::beginWorkspaceSwipe() { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(g_pCompositor->m_pLastMonitor->activeWorkspace); + const auto PWORKSPACE = g_pCompositor->m_pLastMonitor->activeWorkspace; Debug::log(LOG, "Starting a swipe from {}", PWORKSPACE->m_szName); @@ -80,14 +80,14 @@ void CInputManager::endWorkspaceSwipe() { workspaceIDRight = maxWorkspace + 1; } - auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER - auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER + auto PWORKSPACER = g_pCompositor->getWorkspaceByID(workspaceIDRight); // not guaranteed if PSWIPENEW || PSWIPENUMBER + auto PWORKSPACEL = g_pCompositor->getWorkspaceByID(workspaceIDLeft); // not guaranteed if PSWIPENUMBER - const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value(); - const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP; - const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; + const auto RENDEROFFSETMIDDLE = m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset.value(); + const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP; + const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; - CWorkspace* pSwitchedTo = nullptr; + PHLWORKSPACE pSwitchedTo = nullptr; if ((abs(m_sActiveSwipe.delta) < *PSWIPEDIST * *PSWIPEPERC && (*PSWIPEFORC == 0 || (*PSWIPEFORC != 0 && m_sActiveSwipe.avgSpeed < *PSWIPEFORC))) || abs(m_sActiveSwipe.delta) < 2) { diff --git a/src/managers/input/Touch.cpp b/src/managers/input/Touch.cpp index 92f8316d..6fbda869 100644 --- a/src/managers/input/Touch.cpp +++ b/src/managers/input/Touch.cpp @@ -37,7 +37,7 @@ void CInputManager::onTouchDown(wlr_touch_down_event* e) { return; // TODO: Don't swipe if you touched a floating window. } else if (*PSWIPETOUCH && (!m_pFoundLSToFocus || m_pFoundLSToFocus->layer <= ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM)) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(PMONITOR->activeWorkspace); + const auto PWORKSPACE = PMONITOR->activeWorkspace; const bool VERTANIMS = PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle == "slidevert" || PWORKSPACE->m_vRenderOffset.getConfig()->pValues->internalStyle.starts_with("slidefadevert"); // TODO: support no_gaps_when_only? diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index f5cf2624..0628838c 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -224,7 +224,7 @@ bool CHyprOpenGLImpl::passRequiresIntrospection(CMonitor* pMonitor) { if (w->popupsCount() > 0 && *PBLURPOPUPS) return true; - if (!w->m_bIsFloating && *POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (!w->m_bIsFloating && *POPTIM && !w->onSpecialWorkspace()) continue; if (w->m_sAdditionalConfigData.forceNoBlur.toUnderlying() == true || w->m_sAdditionalConfigData.xray.toUnderlying() == true) @@ -1342,7 +1342,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { const auto PSURFACE = pWindow->m_pWLSurface.wlr(); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; const float A = pWindow->m_fAlpha.value() * pWindow->m_fActiveInactiveAlpha.value() * PWORKSPACE->m_fAlpha.value(); if (A >= 1.f) { @@ -1364,7 +1364,7 @@ void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { bool hasWindows = false; for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID == pMonitor->activeWorkspace && !w->isHidden() && w->m_bIsMapped && (!w->m_bIsFloating || *PBLURXRAY)) { + if (w->m_pWorkspace == pMonitor->activeWorkspace && !w->isHidden() && w->m_bIsMapped && (!w->m_bIsFloating || *PBLURXRAY)) { // check if window is valid if (!windowShouldBeBlurred(w.get())) @@ -1456,7 +1456,7 @@ bool CHyprOpenGLImpl::shouldUseNewBlurOptimizations(SLayerSurface* pLayer, CWind if (pLayer && pLayer->xray == 0) return false; - if ((*PBLURNEWOPTIMIZE && pWindow && !pWindow->m_bIsFloating && !g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) || *PBLURXRAY) + if ((*PBLURNEWOPTIMIZE && pWindow && !pWindow->m_bIsFloating && !pWindow->onSpecialWorkspace()) || *PBLURXRAY) return true; if ((pLayer && pLayer->xray == 1) || (pWindow && pWindow->m_sAdditionalConfigData.xray.toUnderlying() == 1)) diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index b18e9108..65f3e6ba 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -91,7 +91,7 @@ struct SMonitorRenderData { struct SCurrentRenderData { CMonitor* pMonitor = nullptr; - CWorkspace* pWorkspace = nullptr; + PHLWORKSPACE pWorkspace = nullptr; float projection[9]; float savedProjection[9]; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index aecd9524..cc682fad 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -217,13 +217,13 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { if (!wlr_output_layout_intersects(g_pCompositor->m_sWLROutputLayout, pMonitor->output, geometry.pWlr())) return false; - if (pWindow->m_iWorkspaceID == -1) + if (!pWindow->m_pWorkspace && !pWindow->m_bFadingOut) return false; if (pWindow->m_bPinned) return true; - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWINDOWWORKSPACE = pWindow->m_pWorkspace; if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_iMonitorID == pMonitor->ID) { if (PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() || PWINDOWWORKSPACE->m_bForceRendering) return true; @@ -233,21 +233,21 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { pWindow->m_fAlpha.value() == 0) return false; - if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID)) + if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->workspaceID())) return false; } if (pWindow->m_iMonitorID == pMonitor->ID) return true; - if (!g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID) && pWindow->m_iMonitorID != pMonitor->ID) + if (!g_pCompositor->isWorkspaceVisible(pWindow->workspaceID()) && pWindow->m_iMonitorID != pMonitor->ID) return false; // if not, check if it maybe is active on a different monitor. - if (g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) + if (g_pCompositor->isWorkspaceVisible(pWindow->workspaceID()) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) return !pWindow->m_bIsFullscreen; // Do not draw fullscreen windows on other monitors - if (pMonitor->specialWorkspaceID == pWindow->m_iWorkspaceID) + if (pMonitor->activeSpecialWorkspace == pWindow->m_pWorkspace) return true; // if window is tiled and it's flying in, don't render on other mons (for slide) @@ -277,29 +277,29 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) { if (!g_pCompositor->windowValidMapped(pWindow)) return false; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; - if (pWindow->m_iWorkspaceID == -1) + if (!pWindow->m_pWorkspace) return false; if (pWindow->m_bPinned || PWORKSPACE->m_bForceRendering) return true; - if (g_pCompositor->isWorkspaceVisible(pWindow->m_iWorkspaceID)) + if (g_pCompositor->isWorkspaceVisible(pWindow->workspaceID())) return true; for (auto& m : g_pCompositor->m_vMonitors) { if (PWORKSPACE && PWORKSPACE->m_iMonitorID == m->ID && (PWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWORKSPACE->m_fAlpha.isBeingAnimated())) return true; - if (m->specialWorkspaceID && g_pCompositor->isWorkspaceSpecial(pWindow->m_iWorkspaceID)) + if (m->activeSpecialWorkspace && pWindow->onSpecialWorkspace()) return true; } return false; } -void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time) { +void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) { CWindow* pWorkspaceWindow = nullptr; EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); @@ -315,7 +315,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (w->m_bIsFullscreen || w->m_bIsFloating) continue; - if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; renderWindow(w.get(), pMonitor, time, true, RENDER_PASS_ALL); @@ -332,7 +332,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (w->m_bIsFullscreen || !w->m_bIsFloating) continue; - if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID) @@ -343,9 +343,9 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp // TODO: this pass sucks for (auto& w : g_pCompositor->m_vWindows) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(w->m_iWorkspaceID); + const auto PWORKSPACE = w->m_pWorkspace; - if (w->m_iWorkspaceID != pWorkspace->m_iID || !w->m_bIsFullscreen) { + if (w->m_pWorkspace != pWorkspace || !w->m_bIsFullscreen) { if (!(PWORKSPACE && (PWORKSPACE->m_vRenderOffset.isBeingAnimated() || PWORKSPACE->m_fAlpha.isBeingAnimated() || PWORKSPACE->m_bForceRendering))) continue; @@ -356,13 +356,13 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp if (!w->m_bIsFullscreen) continue; - if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; if (shouldRenderWindow(w.get(), pMonitor)) renderWindow(w.get(), pMonitor, time, pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL, RENDER_PASS_ALL); - if (w->m_iWorkspaceID != pWorkspace->m_iID) + if (w->m_pWorkspace != pWorkspace) continue; pWorkspaceWindow = w.get(); @@ -376,10 +376,10 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp // then render windows over fullscreen. for (auto& w : g_pCompositor->m_vWindows) { - if (w->m_iWorkspaceID != pWorkspaceWindow->m_iWorkspaceID || (!w->m_bCreatedOverFullscreen && !w->m_bPinned) || (!w->m_bIsMapped && !w->m_bFadingOut) || w->m_bIsFullscreen) + if (w->m_pWorkspace != pWorkspaceWindow->m_pWorkspace || (!w->m_bCreatedOverFullscreen && !w->m_bPinned) || (!w->m_bIsMapped && !w->m_bFadingOut) || w->m_bIsFullscreen) continue; - if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (w->m_iMonitorID == pWorkspace->m_iMonitorID && pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID) @@ -389,7 +389,7 @@ void CHyprRenderer::renderWorkspaceWindowsFullscreen(CMonitor* pMonitor, CWorksp } } -void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time) { +void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time) { CWindow* lastWindow = nullptr; EMIT_HOOK_EVENT("render", RENDER_PRE_WINDOWS); @@ -405,7 +405,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (!shouldRenderWindow(w.get(), pMonitor)) continue; - if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; // render active window after all others of this pass @@ -429,7 +429,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (w->m_bIsFloating) continue; // floating are in the second pass - if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; if (!shouldRenderWindow(w.get(), pMonitor)) @@ -450,7 +450,7 @@ void CHyprRenderer::renderWorkspaceWindows(CMonitor* pMonitor, CWorkspace* pWork if (!shouldRenderWindow(w.get(), pMonitor)) continue; - if (pWorkspace->m_bIsSpecialWorkspace != g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID)) + if (pWorkspace->m_bIsSpecialWorkspace != w->onSpecialWorkspace()) continue; if (pWorkspace->m_bIsSpecialWorkspace && w->m_iMonitorID != pWorkspace->m_iMonitorID) @@ -476,7 +476,7 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* TRACY_GPU_ZONE("RenderWindow"); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWORKSPACE = pWindow->m_pWorkspace; const auto REALPOS = pWindow->m_vRealPosition.value() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.value()); static auto PDIMAROUND = CConfigValue("decoration:dim_around"); static auto PBLUR = CConfigValue("decoration:blur:enabled"); @@ -732,7 +732,7 @@ void CHyprRenderer::renderSessionLockSurface(SSessionLockSurface* pSurface, CMon wlr_surface_for_each_surface(pSurface->pWlrLockSurface->surface, renderSurface, &renderdata); } -void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { +void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* time, const Vector2D& translate, const float& scale) { static auto PDIMSPECIAL = CConfigValue("decoration:dim_special"); static auto PBLURSPECIAL = CConfigValue("decoration:blur:special"); static auto PBLUR = CConfigValue("decoration:blur:enabled"); @@ -810,7 +810,7 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* for (auto& ws : g_pCompositor->m_vWorkspaces) { if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { const auto SPECIALANIMPROGRS = ws->m_vRenderOffset.isBeingAnimated() ? ws->m_vRenderOffset.getCurveValue() : ws->m_fAlpha.getCurveValue(); - const bool ANIMOUT = !pMonitor->specialWorkspaceID; + const bool ANIMOUT = !pMonitor->activeSpecialWorkspace; if (*PDIMSPECIAL != 0.f) { CBox monbox = {translate.x, translate.y, pMonitor->vecTransformedSize.x * scale, pMonitor->vecTransformedSize.y * scale}; @@ -830,9 +830,9 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* for (auto& ws : g_pCompositor->m_vWorkspaces) { if (ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { if (ws->m_bHasFullscreenWindow) - renderWorkspaceWindowsFullscreen(pMonitor, ws.get(), time); + renderWorkspaceWindowsFullscreen(pMonitor, ws, time); else - renderWorkspaceWindows(pMonitor, ws.get(), time); + renderWorkspaceWindows(pMonitor, ws, time); } } @@ -1273,7 +1273,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { renderCursor = false; } else { CBox renderBox = {0, 0, (int)pMonitor->vecPixelSize.x, (int)pMonitor->vecPixelSize.y}; - renderWorkspace(pMonitor, g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace), &now, renderBox); + renderWorkspace(pMonitor, pMonitor->activeWorkspace, &now, renderBox); renderLockscreen(pMonitor, &now, renderBox); @@ -1379,7 +1379,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { } } -void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry) { +void CHyprRenderer::renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry) { Vector2D translate = {geometry.x, geometry.y}; float scale = (float)geometry.width / pMonitor->vecPixelSize.x; @@ -1727,7 +1727,7 @@ void CHyprRenderer::damageWindow(CWindow* pWindow, bool forceFull) { return; CBox windowBox = pWindow->getFullWindowBoundingBox(); - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + const auto PWINDOWWORKSPACE = pWindow->m_pWorkspace; if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !pWindow->m_bPinned) windowBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); windowBox.translate(pWindow->m_vFloatingOffset); @@ -2402,16 +2402,16 @@ void CHyprRenderer::initiateManualCrash() { **PDT = 0; } -void CHyprRenderer::setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace) { +void CHyprRenderer::setOccludedForMainWorkspace(CRegion& region, PHLWORKSPACE pWorkspace) { CRegion rg; const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); - if (!PMONITOR->specialWorkspaceID) + if (!PMONITOR->activeSpecialWorkspace) return; for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != PMONITOR->specialWorkspaceID) + if (!w->m_bIsMapped || w->isHidden() || w->m_pWorkspace != PMONITOR->activeSpecialWorkspace) continue; if (!w->opaque()) @@ -2431,13 +2431,13 @@ void CHyprRenderer::setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWo region.subtract(rg); } -void CHyprRenderer::setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace) { +void CHyprRenderer::setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace) { CRegion rg; const auto PMONITOR = g_pCompositor->getMonitorFromID(pWorkspace->m_iMonitorID); for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || w->m_iWorkspaceID != pWorkspace->m_iID) + if (!w->m_bIsMapped || w->isHidden() || w->m_pWorkspace != pWorkspace) continue; if (!w->opaque()) @@ -2489,9 +2489,9 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { if (g_pHyprNotificationOverlay->hasAny()) return; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pMonitor->activeWorkspace); + const auto PWORKSPACE = pMonitor->activeWorkspace; - if (!PWORKSPACE || !PWORKSPACE->m_bHasFullscreenWindow || g_pInputManager->m_sDrag.drag || g_pCompositor->m_sSeat.exclusiveClient || pMonitor->specialWorkspaceID || + if (!PWORKSPACE || !PWORKSPACE->m_bHasFullscreenWindow || g_pInputManager->m_sDrag.drag || g_pCompositor->m_sSeat.exclusiveClient || pMonitor->activeSpecialWorkspace || PWORKSPACE->m_fAlpha.value() != 1.f || PWORKSPACE->m_vRenderOffset.value() != Vector2D{}) return; @@ -2519,11 +2519,11 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) { if (w.get() == PCANDIDATE || (!w->m_bIsMapped && !w->m_bFadingOut) || w->isHidden()) continue; - if (w->m_iWorkspaceID == PCANDIDATE->m_iWorkspaceID && w->m_bIsFloating && w->m_bCreatedOverFullscreen && w->visibleOnMonitor(pMonitor)) + if (w->m_pWorkspace == PCANDIDATE->m_pWorkspace && w->m_bIsFloating && w->m_bCreatedOverFullscreen && w->visibleOnMonitor(pMonitor)) return; } - if (pMonitor->specialWorkspaceID != 0) + if (pMonitor->activeSpecialWorkspace) return; // check if it did not open any subsurfaces or shit diff --git a/src/render/Renderer.hpp b/src/render/Renderer.hpp index 613706a5..bc5ff43c 100644 --- a/src/render/Renderer.hpp +++ b/src/render/Renderer.hpp @@ -61,8 +61,8 @@ class CHyprRenderer { void calculateUVForSurface(CWindow*, wlr_surface*, bool main = false, const Vector2D& projSize = {}, bool fixMisalignedFSV1 = false); std::tuple getRenderTimes(CMonitor* pMonitor); // avg max min void renderLockscreen(CMonitor* pMonitor, timespec* now, const CBox& geometry); - void setOccludedForBackLayers(CRegion& region, CWorkspace* pWorkspace); - void setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace); // TODO: merge occlusion methods + void setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWorkspace); + void setOccludedForMainWorkspace(CRegion& region, PHLWORKSPACE pWorkspace); // TODO: merge occlusion methods bool canSkipBackBufferClear(CMonitor* pMonitor); void recheckSolitaryForMonitor(CMonitor* pMonitor); void setCursorSurface(wlr_surface* surf, int hotspotX, int hotspotY, bool force = false); @@ -111,15 +111,15 @@ class CHyprRenderer { private: void arrangeLayerArray(CMonitor*, const std::vector>&, bool, CBox*); - void renderWorkspaceWindowsFullscreen(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) - void renderWorkspaceWindows(CMonitor*, CWorkspace*, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) + void renderWorkspaceWindowsFullscreen(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (fullscreen) (tiled, floating, pinned, but no special) + void renderWorkspaceWindows(CMonitor*, PHLWORKSPACE, timespec*); // renders workspace windows (no fullscreen) (tiled, floating, pinned, but no special) void renderWindow(CWindow*, CMonitor*, timespec*, bool, eRenderPassMode, bool ignorePosition = false, bool ignoreAllGeometry = false); void renderLayer(SLayerSurface*, CMonitor*, timespec*, bool popups = false); void renderSessionLockSurface(SSessionLockSurface*, CMonitor*, timespec*); void renderDragIcon(CMonitor*, timespec*); void renderIMEPopup(CInputPopup*, CMonitor*, timespec*); - void renderWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const CBox& geometry); - void renderAllClientsForWorkspace(CMonitor* pMonitor, CWorkspace* pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); + void renderWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const CBox& geometry); + void renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPACE pWorkspace, timespec* now, const Vector2D& translate = {0, 0}, const float& scale = 1.f); bool m_bCursorHidden = false; bool m_bCursorHasSurface = false; diff --git a/src/render/decorations/CHyprBorderDecoration.cpp b/src/render/decorations/CHyprBorderDecoration.cpp index 76e60348..a45b2a5c 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -36,7 +36,7 @@ CBox CHyprBorderDecoration::assignedBoxGlobal() { CBox box = m_bAssignedGeometry; box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_BOTTOM | DECORATION_EDGE_LEFT | DECORATION_EDGE_RIGHT | DECORATION_EDGE_TOP, m_pWindow)); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + const auto PWORKSPACE = m_pWindow->m_pWorkspace; if (!PWORKSPACE) return box; @@ -95,7 +95,7 @@ void CHyprBorderDecoration::damageEntire() { const auto ROUNDINGSIZE = ROUNDING - M_SQRT1_2 * ROUNDING + 2; const auto BORDERSIZE = m_pWindow->getRealBorderSize() + 1; - const auto PWINDOWWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + const auto PWINDOWWORKSPACE = m_pWindow->m_pWorkspace; if (PWINDOWWORKSPACE && PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) surfaceBox.translate(PWINDOWWORKSPACE->m_vRenderOffset.value()); surfaceBox.translate(m_pWindow->m_vFloatingOffset); diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 99d08828..62b2192d 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -45,7 +45,7 @@ void CHyprDropShadowDecoration::damageEntire() { m_pWindow->m_vRealSize.value().x + m_seExtents.topLeft.x + m_seExtents.bottomRight.x, m_pWindow->m_vRealSize.value().y + m_seExtents.topLeft.y + m_seExtents.bottomRight.y}; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + const auto PWORKSPACE = m_pWindow->m_pWorkspace; if (PWORKSPACE && PWORKSPACE->m_vRenderOffset.isBeingAnimated() && !m_pWindow->m_bPinned) shadowBox.translate(PWORKSPACE->m_vRenderOffset.value()); shadowBox.translate(m_pWindow->m_vFloatingOffset); @@ -110,7 +110,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) { const auto ROUNDINGBASE = m_pWindow->rounding(); const auto ROUNDING = ROUNDINGBASE > 0 ? ROUNDINGBASE + m_pWindow->getRealBorderSize() : 0; - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + const auto PWORKSPACE = m_pWindow->m_pWorkspace; const auto WORKSPACEOFFSET = PWORKSPACE && !m_pWindow->m_bPinned ? PWORKSPACE->m_vRenderOffset.value() : Vector2D(); // draw the shadow diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 50bf4627..e9aa5f0c 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -423,7 +423,7 @@ bool CHyprGroupBarDecoration::onEndWindowDragOnDeco(const Vector2D& pos, CWindow } bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_pointer_button_event* e) { - if (m_pWindow->m_bIsFullscreen && g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID)->m_efFullscreenMode == FULLSCREEN_FULL) + if (m_pWindow->m_bIsFullscreen && m_pWindow->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL) return true; const float BARRELATIVEX = pos.x - assignedBoxGlobal().x; @@ -506,7 +506,7 @@ CBox CHyprGroupBarDecoration::assignedBoxGlobal() { CBox box = m_bAssignedBox; box.translate(g_pDecorationPositioner->getEdgeDefinedPoint(DECORATION_EDGE_TOP, m_pWindow)); - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m_pWindow->m_iWorkspaceID); + const auto PWORKSPACE = m_pWindow->m_pWorkspace; if (PWORKSPACE && !m_pWindow->m_bPinned) box.translate(PWORKSPACE->m_vRenderOffset.value()); From 153c8f35ce5f24b066de916269a94fce1d4f3357 Mon Sep 17 00:00:00 2001 From: MightyPlaza <123664421+MightyPlaza@users.noreply.github.com> Date: Tue, 2 Apr 2024 21:58:45 +0000 Subject: [PATCH 0239/2897] workspace: fix special unnamed workspace rules (#5390) modified: src/desktop/Workspace.cpp --- src/desktop/Workspace.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index ccb0fa25..8e49c998 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -233,7 +233,7 @@ bool CWorkspace::matchesStaticSelector(const std::string& selector_) { } else if (selector.starts_with("name:")) { return m_szName == selector.substr(5); - } else if (selector.starts_with("special:")) { + } else if (selector.starts_with("special")) { return m_szName == selector; } else { // parse selector From 3965faafacf18f6e43be91ba326ddfce3948eb3d Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:22:27 -0700 Subject: [PATCH 0240/2897] master: fix center resizing (#5394) --- src/layout/MasterLayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index 2066ca76..f8f710f6 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -799,7 +799,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne case ORIENTATION_TOP: delta = pixResize.y / PMONITOR->vecSize.y; break; case ORIENTATION_CENTER: delta = pixResize.x / PMONITOR->vecSize.x; - if (WINDOWS > 2) { + if (WINDOWS > 2 || *ALWAYSCENTER) { if (!NONE || !PNODE->isMaster) delta *= 2; if ((!PNODE->isMaster && DISPLAYLEFT) || (PNODE->isMaster && LEFT && *PSMARTRESIZING)) From fbdaf74a82b38e11a0a6914b3c9f7cb934ac1624 Mon Sep 17 00:00:00 2001 From: thejch <66577496+thejch@users.noreply.github.com> Date: Tue, 2 Apr 2024 17:22:59 -0700 Subject: [PATCH 0241/2897] master: fix swapped workspaces (#5397) --- src/layout/MasterLayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layout/MasterLayout.cpp b/src/layout/MasterLayout.cpp index f8f710f6..ea906943 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -809,7 +809,7 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne default: UNREACHABLE(); } - const auto workspaceIdForResizing = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeWorkspaceID() : PMONITOR->activeSpecialWorkspaceID(); + const auto workspaceIdForResizing = PMONITOR->activeSpecialWorkspace ? PMONITOR->activeSpecialWorkspaceID() : PMONITOR->activeWorkspaceID(); for (auto& n : m_lMasterNodesData) { if (n.isMaster && n.workspaceID == workspaceIdForResizing) n.percMaster = std::clamp(n.percMaster + delta, 0.05, 0.95); From 347b83903474ab9e95fa9d4ba123f6f78ab38d40 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 10:09:42 +0100 Subject: [PATCH 0242/2897] workspaces: add visible flag --- src/Compositor.cpp | 26 +++++------- src/Compositor.hpp | 2 +- src/desktop/Popup.cpp | 10 +++++ src/desktop/Subsurface.cpp | 2 +- src/desktop/Workspace.cpp | 7 ---- src/desktop/Workspace.hpp | 3 ++ src/events/Layers.cpp | 2 +- src/events/Windows.cpp | 59 ++++++++++++++-------------- src/helpers/Monitor.cpp | 15 +++++-- src/managers/AnimationManager.cpp | 2 +- src/managers/input/IdleInhibitor.cpp | 2 +- src/render/Renderer.cpp | 8 ++-- 12 files changed, 72 insertions(+), 66 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 001d7ca8..3b7b5d9b 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -764,7 +764,7 @@ CWindow* CCompositor::vectorToWindowUnified(const Vector2D& pos, uint8_t propert continue; CBox box = {BB.x - BORDER_GRAB_AREA, BB.y - BORDER_GRAB_AREA, BB.width + 2 * BORDER_GRAB_AREA, BB.height + 2 * BORDER_GRAB_AREA}; - if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->workspaceID()) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && + if (w->m_bIsFloating && w->m_bIsMapped && isWorkspaceVisible(w->m_pWorkspace) && !w->isHidden() && !w->m_bPinned && !w->m_sAdditionalConfigData.noFocus && w.get() != pIgnoreWindow && (!aboveFullscreen || w->m_bCreatedOverFullscreen)) { // OR windows should add focus to parent if (w->m_bX11ShouldntFocus && w->m_iX11Type != 2) @@ -1001,7 +1001,7 @@ void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { const auto PMONITOR = getMonitorFromID(pWindow->m_iMonitorID); - if (!isWorkspaceVisible(pWindow->workspaceID())) { + if (!isWorkspaceVisible(pWindow->m_pWorkspace)) { const auto PWORKSPACE = pWindow->m_pWorkspace; // This is to fix incorrect feedback on the focus history. PWORKSPACE->m_pLastFocusedWindow = pWindow; @@ -1240,16 +1240,8 @@ CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) { return nullptr; } -bool CCompositor::isWorkspaceVisible(const int& w) { - for (auto& m : m_vMonitors) { - if (m->activeWorkspaceID() == w) - return true; - - if (m->activeSpecialWorkspaceID() == w) - return true; - } - - return false; +bool CCompositor::isWorkspaceVisible(PHLWORKSPACE w) { + return w->m_bVisible; } PHLWORKSPACE CCompositor::getWorkspaceByID(const int& id) { @@ -1280,7 +1272,7 @@ void CCompositor::sanityCheckWorkspaces() { const auto WINDOWSONWORKSPACE = getWindowsOnWorkspace(WORKSPACE->m_iID); if (WINDOWSONWORKSPACE == 0) { - if (!isWorkspaceVisible(WORKSPACE->m_iID)) { + if (!isWorkspaceVisible(WORKSPACE)) { if (WORKSPACE->m_bIsSpecialWorkspace) { if (WORKSPACE->m_fAlpha.value() > 0.f /* don't abruptly end the fadeout */) { @@ -1584,7 +1576,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { // for tiled windows, we calc edges for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->workspaceID())) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace)) continue; if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace) @@ -1673,7 +1665,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { constexpr float THRESHOLD = 0.3 * M_PI; for (auto& w : m_vWindows) { - if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->workspaceID())) + if (w.get() == pWindow || !w->m_bIsMapped || w->isHidden() || (!w->m_bIsFullscreen && !w->m_bIsFloating) || !isWorkspaceVisible(w->m_pWorkspace)) continue; if (pWindow->m_iMonitorID == w->m_iMonitorID && pWindow->m_pWorkspace != w->m_pWorkspace) @@ -2737,7 +2729,7 @@ void CCompositor::moveWindowToWorkspaceSafe(CWindow* pWindow, PHLWORKSPACE pWork CWindow* CCompositor::getForceFocus() { for (auto& w : m_vWindows) { - if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->workspaceID())) + if (!w->m_bIsMapped || w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace)) continue; if (!w->m_bStayFocused) @@ -2886,6 +2878,6 @@ void CCompositor::updateSuspendedStates() { if (!w->m_bIsMapped) continue; - w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->workspaceID())); + w->setSuspended(w->isHidden() || !isWorkspaceVisible(w->m_pWorkspace)); } } diff --git a/src/Compositor.hpp b/src/Compositor.hpp index 98bbe899..4604f687 100644 --- a/src/Compositor.hpp +++ b/src/Compositor.hpp @@ -144,7 +144,7 @@ class CCompositor { CWindow* getWindowFromSurface(wlr_surface*); CWindow* getWindowFromHandle(uint32_t); CWindow* getWindowFromZWLRHandle(wl_resource*); - bool isWorkspaceVisible(const int&); + bool isWorkspaceVisible(PHLWORKSPACE); PHLWORKSPACE getWorkspaceByID(const int&); PHLWORKSPACE getWorkspaceByName(const std::string&); PHLWORKSPACE getWorkspaceByString(const std::string&); diff --git a/src/desktop/Popup.cpp b/src/desktop/Popup.cpp index 77e486fd..a32b28d6 100644 --- a/src/desktop/Popup.cpp +++ b/src/desktop/Popup.cpp @@ -1,4 +1,5 @@ #include "Popup.hpp" +#include "../config/ConfigValue.hpp" #include "../Compositor.hpp" CPopup::CPopup(CWindow* pOwner) : m_pWindowOwner(pOwner) { @@ -145,6 +146,15 @@ void CPopup::onCommit(bool ignoreSiblings) { return; } + if (m_pWindowOwner && (!m_pWindowOwner->m_bIsMapped || !m_pWindowOwner->m_pWorkspace->m_bVisible)) { + m_vLastSize = {m_pWLR->base->current.geometry.width, m_pWLR->base->current.geometry.height}; + + static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); + if (*PLOGDAMAGE) + Debug::log(LOG, "Refusing to commit damage from a subsurface of {} because it's invisible.", m_pWindowOwner); + return; + } + const auto COORDS = coordsGlobal(); const auto COORDSLOCAL = coordsRelativeToParent(); diff --git a/src/desktop/Subsurface.cpp b/src/desktop/Subsurface.cpp index c3538ee1..e337c798 100644 --- a/src/desktop/Subsurface.cpp +++ b/src/desktop/Subsurface.cpp @@ -117,7 +117,7 @@ void CSubsurface::recheckDamageForSubsurfaces() { void CSubsurface::onCommit() { // no damaging if it's not visible - if (m_pWindowParent && !g_pHyprRenderer->shouldRenderWindow(m_pWindowParent)) { + if (m_pWindowParent && (!m_pWindowParent->m_bIsMapped || !m_pWindowParent->m_pWorkspace->m_bVisible)) { m_vLastSize = Vector2D{m_sWLSurface.wlr()->current.width, m_sWLSurface.wlr()->current.height}; static auto PLOGDAMAGE = CConfigValue("debug:log_damage"); diff --git a/src/desktop/Workspace.cpp b/src/desktop/Workspace.cpp index 8e49c998..1df18c3b 100644 --- a/src/desktop/Workspace.cpp +++ b/src/desktop/Workspace.cpp @@ -9,13 +9,6 @@ PHLWORKSPACE CWorkspace::create(int id, int monitorID, std::string name, bool sp } CWorkspace::CWorkspace(int id, int monitorID, std::string name, bool special) { - const auto PMONITOR = g_pCompositor->getMonitorFromID(monitorID); - - if (!PMONITOR) { - Debug::log(ERR, "Attempted a creation of CWorkspace with an invalid monitor?"); - return; - } - m_iMonitorID = monitorID; m_iID = id; m_szName = name; diff --git a/src/desktop/Workspace.hpp b/src/desktop/Workspace.hpp index 1630baf5..deb108ec 100644 --- a/src/desktop/Workspace.hpp +++ b/src/desktop/Workspace.hpp @@ -42,6 +42,9 @@ class CWorkspace { CAnimatedVariable m_fAlpha; bool m_bForceRendering = false; + // allows damage to propagate. + bool m_bVisible = false; + // "scratchpad" bool m_bIsSpecialWorkspace = false; diff --git a/src/events/Layers.cpp b/src/events/Layers.cpp index bd27004b..ab002ef6 100644 --- a/src/events/Layers.cpp +++ b/src/events/Layers.cpp @@ -237,7 +237,7 @@ void Events::listener_unmapLayerSurface(void* owner, void* data) { foundSurface = g_pCompositor->vectorToLayerSurface(g_pInputManager->getMouseCoordsInternal(), &PMONITOR->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP], &surfaceCoords, &pFoundLayerSurface); - if (!foundSurface && g_pCompositor->m_pLastWindow && g_pCompositor->isWorkspaceVisible(g_pCompositor->m_pLastWindow->workspaceID())) { + if (!foundSurface && g_pCompositor->m_pLastWindow && g_pCompositor->isWorkspaceVisible(g_pCompositor->m_pLastWindow->m_pWorkspace)) { // if there isn't any, focus the last window const auto PLASTWINDOW = g_pCompositor->m_pLastWindow; g_pCompositor->focusWindow(nullptr); diff --git a/src/events/Windows.cpp b/src/events/Windows.cpp index eb876cf2..b1db5286 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -800,6 +800,35 @@ void Events::listener_commitWindow(void* owner, void* data) { PWINDOW->m_pPendingSizeAck.reset(); } + if (!PWINDOW->m_bIsX11 && !PWINDOW->m_bIsFullscreen && PWINDOW->m_bIsFloating) { + const auto MINSIZE = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->current.min_width, PWINDOW->m_uSurface.xdg->toplevel->current.min_height}; + const auto MAXSIZE = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->current.max_width, PWINDOW->m_uSurface.xdg->toplevel->current.max_height}; + + if (MAXSIZE > Vector2D{1, 1}) { + const auto REALSIZE = PWINDOW->m_vRealSize.goal(); + Vector2D newSize = REALSIZE; + + if (MAXSIZE.x < newSize.x) + newSize.x = MAXSIZE.x; + if (MAXSIZE.y < newSize.y) + newSize.y = MAXSIZE.y; + if (MINSIZE.x > newSize.x) + newSize.x = MINSIZE.x; + if (MINSIZE.y > newSize.y) + newSize.y = MINSIZE.y; + + const Vector2D DELTA = REALSIZE - newSize; + + PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + DELTA / 2.0; + PWINDOW->m_vRealSize = newSize; + g_pXWaylandManager->setWindowSize(PWINDOW, newSize, true); + g_pHyprRenderer->damageWindow(PWINDOW); + } + } + + if (!PWINDOW->m_pWorkspace->m_bVisible) + return; + g_pHyprRenderer->damageSurface(PWINDOW->m_pWLSurface.wlr(), PWINDOW->m_vRealPosition.goal().x, PWINDOW->m_vRealPosition.goal().y, PWINDOW->m_bIsX11 ? 1.0 / PWINDOW->m_fX11SurfaceScaledBy : 1.0); @@ -823,34 +852,6 @@ void Events::listener_commitWindow(void* owner, void* data) { } } } - - if (PWINDOW->m_bIsX11 || !PWINDOW->m_bIsFloating || PWINDOW->m_bIsFullscreen) - return; - - const auto MINSIZE = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->current.min_width, PWINDOW->m_uSurface.xdg->toplevel->current.min_height}; - const auto MAXSIZE = Vector2D{PWINDOW->m_uSurface.xdg->toplevel->current.max_width, PWINDOW->m_uSurface.xdg->toplevel->current.max_height}; - - if (MAXSIZE < Vector2D{1, 1}) - return; - - const auto REALSIZE = PWINDOW->m_vRealSize.goal(); - Vector2D newSize = REALSIZE; - - if (MAXSIZE.x < newSize.x) - newSize.x = MAXSIZE.x; - if (MAXSIZE.y < newSize.y) - newSize.y = MAXSIZE.y; - if (MINSIZE.x > newSize.x) - newSize.x = MINSIZE.x; - if (MINSIZE.y > newSize.y) - newSize.y = MINSIZE.y; - - const Vector2D DELTA = REALSIZE - newSize; - - PWINDOW->m_vRealPosition = PWINDOW->m_vRealPosition.goal() + DELTA / 2.0; - PWINDOW->m_vRealSize = newSize; - g_pXWaylandManager->setWindowSize(PWINDOW, newSize, true); - g_pHyprRenderer->damageWindow(PWINDOW); } void Events::listener_destroyWindow(void* owner, void* data) { @@ -1094,7 +1095,7 @@ void Events::listener_configureX11(void* owner, void* data) { PWINDOW->updateWindowDecos(); - if (!g_pCompositor->isWorkspaceVisible(PWINDOW->workspaceID())) + if (!g_pCompositor->isWorkspaceVisible(PWINDOW->m_pWorkspace)) return; // further things are only for visible windows PWINDOW->m_pWorkspace = g_pCompositor->getMonitorFromVector(PWINDOW->m_vRealPosition.value() + PWINDOW->m_vRealSize.value() / 2.f)->activeWorkspace; diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 4018cc8b..152356e4 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -416,6 +416,7 @@ void CMonitor::setupDefaultWS(const SMonitorRule& monitorRule) { activeWorkspace = PNEWWORKSPACE; PNEWWORKSPACE->setActive(true); + PNEWWORKSPACE->m_bVisible = true; PNEWWORKSPACE->m_szLastMonitor = ""; } @@ -547,7 +548,9 @@ void CMonitor::changeWorkspace(const PHLWORKSPACE& pWorkspace, bool internal, bo if (pWorkspace == activeWorkspace) return; - const auto POLDWORKSPACE = activeWorkspace; + const auto POLDWORKSPACE = activeWorkspace; + POLDWORKSPACE->m_bVisible = false; + pWorkspace->m_bVisible = true; activeWorkspace = pWorkspace; @@ -612,6 +615,7 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { if (!pWorkspace) { // remove special if exists if (activeSpecialWorkspace) { + activeSpecialWorkspace->m_bVisible = false; activeSpecialWorkspace->startAnim(false, false); g_pEventManager->postEvent(SHyprIPCEvent{"activespecial", "," + szName}); } @@ -633,8 +637,10 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { return; } - if (activeSpecialWorkspace) + if (activeSpecialWorkspace) { + activeSpecialWorkspace->m_bVisible = false; activeSpecialWorkspace->startAnim(false, false); + } bool animate = true; //close if open elsewhere @@ -651,8 +657,9 @@ void CMonitor::setSpecialWorkspace(const PHLWORKSPACE& pWorkspace) { } // open special - pWorkspace->m_iMonitorID = ID; - activeSpecialWorkspace = pWorkspace; + pWorkspace->m_iMonitorID = ID; + activeSpecialWorkspace = pWorkspace; + activeSpecialWorkspace->m_bVisible = true; if (animate) pWorkspace->startAnim(true, true); diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index a9a72941..ac849b58 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -146,7 +146,7 @@ void CAnimationManager::tick() { animationsDisabled = animationsDisabled || PLAYER->noAnimations; } - const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? g_pCompositor->isWorkspaceVisible(PWINDOW->workspaceID()) : true; + const bool VISIBLE = PWINDOW && PWINDOW->m_pWorkspace ? g_pCompositor->isWorkspaceVisible(PWINDOW->m_pWorkspace) : true; // beziers are with a switch unforto // TODO: maybe do something cleaner diff --git a/src/managers/input/IdleInhibitor.cpp b/src/managers/input/IdleInhibitor.cpp index 12d768f5..7e7ee3c9 100644 --- a/src/managers/input/IdleInhibitor.cpp +++ b/src/managers/input/IdleInhibitor.cpp @@ -65,7 +65,7 @@ void CInputManager::recheckIdleInhibitorStatus() { return; } - if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->workspaceID())) { + if (w->m_eIdleInhibitMode == IDLEINHIBIT_FULLSCREEN && w->m_bIsFullscreen && g_pCompositor->isWorkspaceVisible(w->m_pWorkspace)) { g_pCompositor->setIdleActivityInhibit(false); return; } diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index cc682fad..446cb9bf 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -233,18 +233,18 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { pWindow->m_fAlpha.value() == 0) return false; - if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->workspaceID())) + if (!PWINDOWWORKSPACE->m_vRenderOffset.isBeingAnimated() && !PWINDOWWORKSPACE->m_fAlpha.isBeingAnimated() && !g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) return false; } if (pWindow->m_iMonitorID == pMonitor->ID) return true; - if (!g_pCompositor->isWorkspaceVisible(pWindow->workspaceID()) && pWindow->m_iMonitorID != pMonitor->ID) + if (!g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace) && pWindow->m_iMonitorID != pMonitor->ID) return false; // if not, check if it maybe is active on a different monitor. - if (g_pCompositor->isWorkspaceVisible(pWindow->workspaceID()) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) + if (g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace) && pWindow->m_bIsFloating /* tiled windows can't be multi-ws */) return !pWindow->m_bIsFullscreen; // Do not draw fullscreen windows on other monitors if (pMonitor->activeSpecialWorkspace == pWindow->m_pWorkspace) @@ -285,7 +285,7 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow) { if (pWindow->m_bPinned || PWORKSPACE->m_bForceRendering) return true; - if (g_pCompositor->isWorkspaceVisible(pWindow->workspaceID())) + if (g_pCompositor->isWorkspaceVisible(pWindow->m_pWorkspace)) return true; for (auto& m : g_pCompositor->m_vMonitors) { From efdc1af04420b59917f8530a20ccfabe658f636a Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 14:09:58 +0100 Subject: [PATCH 0243/2897] renderer: some fixes for renderModif --- src/protocols/Screencopy.cpp | 4 ++ src/render/OpenGL.cpp | 61 +++++++++++++++++-- src/render/OpenGL.hpp | 5 ++ src/render/Renderer.cpp | 27 +++++++- .../decorations/CHyprDropShadowDecoration.cpp | 3 + 5 files changed, 91 insertions(+), 9 deletions(-) diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index a0c05b22..9807cc55 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -485,7 +485,9 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec* CBox monbox = CBox{0, 0, frame->pMonitor->vecTransformedSize.x, frame->pMonitor->vecTransformedSize.y}.translate({-frame->box.x, -frame->box.y}); g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->setRenderModifEnabled(false); g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); + g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); #ifndef GLES2 @@ -544,7 +546,9 @@ bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) { .translate({-frame->box.x, -frame->box.y}) // vvvv kinda ass-backwards but that's how I designed the renderer... sigh. .transform(wlr_output_transform_invert(frame->pMonitor->output->transform), frame->pMonitor->vecPixelSize.x, frame->pMonitor->vecPixelSize.y); g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->setRenderModifEnabled(false); g_pHyprOpenGL->renderTexture(sourceTex, &monbox, 1); + g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); g_pHyprRenderer->endRender(); diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 0628838c..f9b44a80 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -795,6 +795,8 @@ void CHyprOpenGLImpl::renderRectWithDamage(CBox* box, const CColor& col, CRegion } glDisableVertexAttribArray(m_RenderData.pCurrentMonData->m_shQUAD.posAttrib); + + scissor((CBox*)nullptr); } void CHyprOpenGLImpl::renderTexture(wlr_texture* tex, CBox* pBox, float alpha, int round, bool allowCustomUV) { @@ -1480,6 +1482,8 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo if (texDamage.empty()) return; + m_RenderData.renderModif.applyToRegion(texDamage); + if (*PBLURENABLED == 0 || (*PNOBLUROVERSIZED && m_RenderData.primarySurfaceUVTopLeft != Vector2D(-1, -1)) || (m_pCurrentWindow && (m_pCurrentWindow->m_sAdditionalConfigData.forceNoBlur || m_pCurrentWindow->m_sAdditionalConfigData.forceRGBX))) { renderTexture(tex, pBox, a, round, false, true); @@ -1509,7 +1513,9 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo CFramebuffer* POUTFB = nullptr; if (!USENEWOPTIMIZE) { - inverseOpaque.translate({pBox->x, pBox->y}).intersect(texDamage); + inverseOpaque.translate({pBox->x, pBox->y}); + m_RenderData.renderModif.applyToRegion(inverseOpaque); + inverseOpaque.intersect(texDamage); POUTFB = blurMainFramebufferWithDamage(a, &inverseOpaque); } else { @@ -1542,12 +1548,11 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo CBox MONITORBOX = {0, 0, m_RenderData.pMonitor->vecTransformedSize.x, m_RenderData.pMonitor->vecTransformedSize.y}; // render our great blurred FB static auto PBLURIGNOREOPACITY = CConfigValue("decoration:blur:ignore_opacity"); - m_bEndFrame = true; // fix transformed - const auto SAVEDRENDERMODIF = m_RenderData.renderModif; - m_RenderData.renderModif = {}; // fix shit + setMonitorTransformEnabled(true); + setRenderModifEnabled(false); renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); - m_bEndFrame = false; - m_RenderData.renderModif = SAVEDRENDERMODIF; + setMonitorTransformEnabled(false); + setRenderModifEnabled(true); // render the window, but clear stencil glClearStencil(0); @@ -1587,6 +1592,7 @@ void CHyprOpenGLImpl::renderBorder(CBox* box, const CGradientValueData& grad, in return; int scaledBorderSize = std::round(borderSize * m_RenderData.pMonitor->scale); + scaledBorderSize = std::round(scaledBorderSize * m_RenderData.renderModif.combinedScale()); // adjust box box->x -= scaledBorderSize; @@ -2223,6 +2229,10 @@ void CHyprOpenGLImpl::setMonitorTransformEnabled(bool enabled) { m_bEndFrame = enabled; } +void CHyprOpenGLImpl::setRenderModifEnabled(bool enabled) { + m_RenderData.renderModif.enabled = enabled; +} + inline const SGLPixelFormat GLES2_FORMATS[] = { { .drmFormat = DRM_FORMAT_ARGB8888, @@ -2358,6 +2368,9 @@ const SGLPixelFormat* CHyprOpenGLImpl::getPixelFormatFromDRM(uint32_t drmFormat) } void SRenderModifData::applyToBox(CBox& box) { + if (!enabled) + return; + for (auto& [type, val] : modifs) { try { switch (type) { @@ -2378,3 +2391,39 @@ void SRenderModifData::applyToBox(CBox& box) { } catch (std::bad_any_cast& e) { Debug::log(ERR, "BUG THIS OR PLUGIN ERROR: caught a bad_any_cast in SRenderModifData::applyToBox!"); } } } + +void SRenderModifData::applyToRegion(CRegion& rg) { + if (!enabled) + return; + + for (auto& [type, val] : modifs) { + try { + switch (type) { + case RMOD_TYPE_SCALE: rg.scale(std::any_cast(val)); break; + case RMOD_TYPE_SCALECENTER: rg.scale(std::any_cast(val)); break; + case RMOD_TYPE_TRANSLATE: rg.translate(std::any_cast(val)); break; + case RMOD_TYPE_ROTATE: /* TODO */ + case RMOD_TYPE_ROTATECENTER: break; + } + } catch (std::bad_any_cast& e) { Debug::log(ERR, "BUG THIS OR PLUGIN ERROR: caught a bad_any_cast in SRenderModifData::applyToRegion!"); } + } +} + +float SRenderModifData::combinedScale() { + if (!enabled) + return 1; + + float scale = 1.f; + for (auto& [type, val] : modifs) { + try { + switch (type) { + case RMOD_TYPE_SCALE: scale *= std::any_cast(val); break; + case RMOD_TYPE_SCALECENTER: + case RMOD_TYPE_TRANSLATE: + case RMOD_TYPE_ROTATE: + case RMOD_TYPE_ROTATECENTER: break; + } + } catch (std::bad_any_cast& e) { Debug::log(ERR, "BUG THIS OR PLUGIN ERROR: caught a bad_any_cast in SRenderModifData::combinedScale!"); } + } + return scale; +} diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 65f3e6ba..6af2a00f 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -47,6 +47,10 @@ struct SRenderModifData { std::vector> modifs; void applyToBox(CBox& box); + void applyToRegion(CRegion& rg); + float combinedScale(); + + bool enabled = true; }; struct SGLPixelFormat { @@ -138,6 +142,7 @@ class CHyprOpenGLImpl { void renderTextureMatte(const CTexture& tex, CBox* pBox, CFramebuffer& matte); void setMonitorTransformEnabled(bool enabled); + void setRenderModifEnabled(bool enabled); void saveMatrix(); void setMatrixScaleTranslate(const Vector2D& translate, const float& scale); diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 446cb9bf..e738de9b 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -760,13 +760,35 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC // g_pHyprOpenGL->setMatrixScaleTranslate(translate, scale); g_pHyprOpenGL->m_RenderData.renderModif = RENDERMODIFDATA; + if (!pWorkspace) { + // allow rendering without a workspace. In this case, just render layers. + g_pHyprOpenGL->blend(true); + + for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { + renderLayer(ls.get(), pMonitor, time); + } + for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]) { + renderLayer(ls.get(), pMonitor, time); + } + for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_TOP]) { + renderLayer(ls.get(), pMonitor, time); + } + for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_OVERLAY]) { + renderLayer(ls.get(), pMonitor, time); + } + + g_pHyprOpenGL->m_RenderData.renderModif = {}; + + return; + } + // for storing damage when we optimize for occlusion CRegion preOccludedDamage{g_pHyprOpenGL->m_RenderData.damage}; // Render layer surfaces below windows for monitor // if we have a fullscreen, opaque window that convers the screen, we can skip this. // TODO: check better with solitary after MR for tearing. - const auto PFULLWINDOW = g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID); + const auto PFULLWINDOW = pWorkspace ? g_pCompositor->getFullscreenWindowOnWorkspace(pWorkspace->m_iID) : nullptr; if (!pWorkspace->m_bHasFullscreenWindow || pWorkspace->m_efFullscreenMode != FULLSCREEN_FULL || !PFULLWINDOW || PFULLWINDOW->m_vRealSize.isBeingAnimated() || !PFULLWINDOW->opaque() || pWorkspace->m_vRenderOffset.value() != Vector2D{}) { @@ -804,8 +826,6 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC g_pHyprOpenGL->m_RenderData.damage = preOccludedDamage; - g_pHyprOpenGL->m_RenderData.renderModif = {}; - // and then special for (auto& ws : g_pCompositor->m_vWorkspaces) { if (ws->m_iMonitorID == pMonitor->ID && ws->m_fAlpha.value() > 0.f && ws->m_bIsSpecialWorkspace) { @@ -2450,6 +2470,7 @@ void CHyprRenderer::setOccludedForBackLayers(CRegion& region, PHLWORKSPACE pWork CBox box = {POS.x, POS.y, SIZE.x, SIZE.y}; box.scale(PMONITOR->scale); + g_pHyprOpenGL->m_RenderData.renderModif.applyToBox(box); rg.add(box); } diff --git a/src/render/decorations/CHyprDropShadowDecoration.cpp b/src/render/decorations/CHyprDropShadowDecoration.cpp index 62b2192d..bba2c639 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -171,6 +171,7 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) { g_pHyprOpenGL->m_RenderData.damage = fullBox; g_pHyprOpenGL->m_RenderData.damage.subtract(windowBox.copy().expand(-ROUNDING * pMonitor->scale)).intersect(saveDamage); + g_pHyprOpenGL->m_RenderData.renderModif.applyToRegion(g_pHyprOpenGL->m_RenderData.damage); alphaFB.bind(); @@ -194,7 +195,9 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a) { CBox monbox = {0, 0, pMonitor->vecTransformedSize.x, pMonitor->vecTransformedSize.y}; g_pHyprOpenGL->setMonitorTransformEnabled(true); + g_pHyprOpenGL->setRenderModifEnabled(false); g_pHyprOpenGL->renderTextureMatte(alphaSwapFB.m_cTex, &monbox, alphaFB); + g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); g_pHyprOpenGL->m_RenderData.damage = saveDamage; From 3981f85e9487224e8c193160cbd7ae7137a11204 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 14:23:19 +0100 Subject: [PATCH 0244/2897] opengl: log framebuffer errors --- src/render/Framebuffer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/render/Framebuffer.cpp b/src/render/Framebuffer.cpp index d35e5119..83325dd7 100644 --- a/src/render/Framebuffer.cpp +++ b/src/render/Framebuffer.cpp @@ -43,7 +43,7 @@ bool CFramebuffer::alloc(int w, int h, uint32_t drmFormat) { #endif auto status = glCheckFramebufferStatus(GL_FRAMEBUFFER); - RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Framebuffer incomplete, couldn't create! (FB status: {})", status); + RASSERT((status == GL_FRAMEBUFFER_COMPLETE), "Framebuffer incomplete, couldn't create! (FB status: {}, GL Error: 0x{:x})", status, (int)glGetError()); Debug::log(LOG, "Framebuffer created, status {}", status); } From 64964c4e3beaf890fc9d12eb0e1804373f0fabe6 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 14:28:15 +0100 Subject: [PATCH 0245/2897] renderer: render back layer for workspace-less passes --- src/render/Renderer.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index e738de9b..b43f3a2d 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -762,6 +762,13 @@ void CHyprRenderer::renderAllClientsForWorkspace(CMonitor* pMonitor, PHLWORKSPAC if (!pWorkspace) { // allow rendering without a workspace. In this case, just render layers. + g_pHyprOpenGL->blend(false); + if (!canSkipBackBufferClear(pMonitor)) { + if (*PRENDERTEX /* inverted cfg flag */) + g_pHyprOpenGL->clear(CColor(*PBACKGROUNDCOLOR)); + else + g_pHyprOpenGL->clearWithTex(); // will apply the hypr "wallpaper" + } g_pHyprOpenGL->blend(true); for (auto& ls : pMonitor->m_aLayerSurfaceLayers[ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND]) { From 91061a2084f4b3b2f64c955b4d02b8f5c94541be Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 15:08:29 +0100 Subject: [PATCH 0246/2897] opengl: fix modif in blur --- src/render/OpenGL.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index f9b44a80..c2401cef 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1549,10 +1549,8 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo // render our great blurred FB static auto PBLURIGNOREOPACITY = CConfigValue("decoration:blur:ignore_opacity"); setMonitorTransformEnabled(true); - setRenderModifEnabled(false); renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); setMonitorTransformEnabled(false); - setRenderModifEnabled(true); // render the window, but clear stencil glClearStencil(0); From 93915502d2677b70382b7cba09620b445f6b832e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 17:08:11 +0100 Subject: [PATCH 0247/2897] blur: block modif only on no new optimize --- src/render/OpenGL.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index c2401cef..8be8e54e 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -1549,7 +1549,11 @@ void CHyprOpenGLImpl::renderTextureWithBlur(const CTexture& tex, CBox* pBox, flo // render our great blurred FB static auto PBLURIGNOREOPACITY = CConfigValue("decoration:blur:ignore_opacity"); setMonitorTransformEnabled(true); + if (!USENEWOPTIMIZE) + setRenderModifEnabled(false); renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, *PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); + if (!USENEWOPTIMIZE) + setRenderModifEnabled(true); setMonitorTransformEnabled(false); // render the window, but clear stencil From d88d5898807bf6f2462cecfb977b7624dafbf52e Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 19:20:47 +0100 Subject: [PATCH 0248/2897] swipe: add events --- src/managers/input/Swipe.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/managers/input/Swipe.cpp b/src/managers/input/Swipe.cpp index 47a6f5bd..ba91394e 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -7,6 +7,8 @@ void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) { static auto PSWIPEFINGERS = CConfigValue("gestures:workspace_swipe_fingers"); static auto PSWIPENEW = CConfigValue("gestures:workspace_swipe_create_new"); + EMIT_HOOK_EVENT_CANCELLABLE("swipeBegin", e); + if (e->fingers != *PSWIPEFINGERS || *PSWIPE == 0 || g_pSessionLockManager->isSessionLocked()) return; @@ -42,6 +44,8 @@ void CInputManager::beginWorkspaceSwipe() { } void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { + EMIT_HOOK_EVENT_CANCELLABLE("swipeEnd", e); + if (!m_sActiveSwipe.pWorkspaceBegin) return; // no valid swipe endWorkspaceSwipe(); @@ -195,6 +199,8 @@ void CInputManager::endWorkspaceSwipe() { } void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { + EMIT_HOOK_EVENT_CANCELLABLE("swipeUpdate", e); + if (!m_sActiveSwipe.pWorkspaceBegin) return; static auto PSWIPEINVR = CConfigValue("gestures:workspace_swipe_invert"); From 10146f5ec50caeae2d835f5f6296137e2ac6f243 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 20:42:38 +0100 Subject: [PATCH 0249/2897] core: fix some crash conditions around workspace ptrs in CWindow ref #5402, supersedes #5409 --- src/Compositor.cpp | 2 +- src/render/Renderer.cpp | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 3b7b5d9b..033af696 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -1241,7 +1241,7 @@ CWindow* CCompositor::getFullscreenWindowOnWorkspace(const int& ID) { } bool CCompositor::isWorkspaceVisible(PHLWORKSPACE w) { - return w->m_bVisible; + return valid(w) && w->m_bVisible; } PHLWORKSPACE CCompositor::getWorkspaceByID(const int& id) { diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index b43f3a2d..af6b7aae 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -220,6 +220,9 @@ bool CHyprRenderer::shouldRenderWindow(CWindow* pWindow, CMonitor* pMonitor) { if (!pWindow->m_pWorkspace && !pWindow->m_bFadingOut) return false; + if (!pWindow->m_pWorkspace && pWindow->m_bFadingOut) + return pWindow->workspaceID() == pMonitor->activeWorkspaceID(); + if (pWindow->m_bPinned) return true; @@ -1760,7 +1763,7 @@ void CHyprRenderer::damageWindow(CWindow* pWindow, bool forceFull) { windowBox.translate(pWindow->m_vFloatingOffset); for (auto& m : g_pCompositor->m_vMonitors) { - if (g_pHyprRenderer->shouldRenderWindow(pWindow, m.get()) || forceFull) { // only damage if window is rendered on monitor + if (forceFull || g_pHyprRenderer->shouldRenderWindow(pWindow, m.get())) { // only damage if window is rendered on monitor CBox fixedDamageBox = {windowBox.x - m->vecPosition.x, windowBox.y - m->vecPosition.y, windowBox.width, windowBox.height}; fixedDamageBox.scale(m->scale); m->addDamage(&fixedDamageBox); From d605e475118fd66e625a5a23c687cd01a34b302c Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 3 Apr 2024 21:35:16 +0100 Subject: [PATCH 0250/2897] renderer: block screen shader on screencopy --- src/protocols/Screencopy.cpp | 2 ++ src/protocols/ToplevelExport.cpp | 2 ++ src/render/OpenGL.cpp | 3 ++- src/render/OpenGL.hpp | 1 + 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/protocols/Screencopy.cpp b/src/protocols/Screencopy.cpp index 9807cc55..476df0b8 100644 --- a/src/protocols/Screencopy.cpp +++ b/src/protocols/Screencopy.cpp @@ -504,6 +504,7 @@ bool CScreencopyProtocolManager::copyFrameShm(SScreencopyFrame* frame, timespec* return false; } + g_pHyprOpenGL->m_RenderData.blockScreenShader = true; g_pHyprRenderer->endRender(); g_pHyprRenderer->makeEGLCurrent(); @@ -551,6 +552,7 @@ bool CScreencopyProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame) { g_pHyprOpenGL->setRenderModifEnabled(true); g_pHyprOpenGL->setMonitorTransformEnabled(false); + g_pHyprOpenGL->m_RenderData.blockScreenShader = true; g_pHyprRenderer->endRender(); wlr_texture_destroy(sourceTex); diff --git a/src/protocols/ToplevelExport.cpp b/src/protocols/ToplevelExport.cpp index e3273f7a..e2006afb 100644 --- a/src/protocols/ToplevelExport.cpp +++ b/src/protocols/ToplevelExport.cpp @@ -402,6 +402,7 @@ bool CToplevelExportProtocolManager::copyFrameShm(SScreencopyFrame* frame, times return false; } + g_pHyprOpenGL->m_RenderData.blockScreenShader = true; g_pHyprRenderer->endRender(); g_pHyprRenderer->makeEGLCurrent(); @@ -441,6 +442,7 @@ bool CToplevelExportProtocolManager::copyFrameDmabuf(SScreencopyFrame* frame, ti if (frame->overlayCursor) g_pHyprRenderer->renderSoftwareCursors(PMONITOR, fakeDamage, g_pInputManager->getMouseCoordsInternal() - frame->pWindow->m_vRealPosition.value()); + g_pHyprOpenGL->m_RenderData.blockScreenShader = true; g_pHyprRenderer->endRender(); return true; } diff --git a/src/render/OpenGL.cpp b/src/render/OpenGL.cpp index 8be8e54e..9e3fb47b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -365,7 +365,7 @@ void CHyprOpenGLImpl::end() { } m_bEndFrame = true; - m_bApplyFinalShader = true; + m_bApplyFinalShader = !m_RenderData.blockScreenShader; if (m_RenderData.mouseZoomUseMouse) m_RenderData.useNearestNeighbor = true; @@ -388,6 +388,7 @@ void CHyprOpenGLImpl::end() { m_RenderData.mouseZoomFactor = 1.f; m_RenderData.mouseZoomUseMouse = true; m_RenderData.forceIntrospection = false; + m_RenderData.blockScreenShader = false; m_RenderData.currentFB = nullptr; m_RenderData.mainFB = nullptr; m_RenderData.outFB = nullptr; diff --git a/src/render/OpenGL.hpp b/src/render/OpenGL.hpp index 6af2a00f..08a1583d 100644 --- a/src/render/OpenGL.hpp +++ b/src/render/OpenGL.hpp @@ -112,6 +112,7 @@ struct SCurrentRenderData { bool mouseZoomUseMouse = true; // true by default bool useNearestNeighbor = false; bool forceIntrospection = false; // cleaned in ::end() + bool blockScreenShader = false; Vector2D primarySurfaceUVTopLeft = Vector2D(-1, -1); Vector2D primarySurfaceUVBottomRight = Vector2D(-1, -1); From 949eb426136aef2690c31acc6389016aa8755ac8 Mon Sep 17 00:00:00 2001 From: Micovec <30734146+Micovec@users.noreply.github.com> Date: Wed, 3 Apr 2024 22:41:10 +0200 Subject: [PATCH 0251/2897] hyprctl: improve help pages (#5385) --- hyprctl/Strings.hpp | 158 ++++++++++++++++++++++++++++++++++++++++++++ hyprctl/main.cpp | 76 ++++++++------------- 2 files changed, 185 insertions(+), 49 deletions(-) create mode 100644 hyprctl/Strings.hpp diff --git a/hyprctl/Strings.hpp b/hyprctl/Strings.hpp new file mode 100644 index 00000000..951c6a7f --- /dev/null +++ b/hyprctl/Strings.hpp @@ -0,0 +1,158 @@ +#pragma once + +const std::string_view USAGE = R"#(usage: hyprctl [flags] [args...|--help] + +commands: + activewindow → Gets the active window name and its properties + activeworkspace → Gets the active workspace and its properties + animations → Gets the current config'd info about animations + and beziers + binds → Lists all registered binds + clients → Lists all windows with their properties + configerrors → Lists all current config parsing errors + cursorpos → Gets the current cursor position in global layout + coordinates + decorations → Lists all decorations and their info + devices → Lists all connected keyboards and mice + dismissnotify [amount] → Dismisses all or up to AMOUNT notifications + dispatch [args] → Issue a dispatch to call a keybind + dispatcher with arguments + getoption