diff options
42 files changed, 2160 insertions, 2322 deletions
diff --git a/.github/actions/setup_base/action.yml b/.github/actions/setup_base/action.yml index 2985ce9a..8a33dd55 100644 --- a/.github/actions/setup_base/action.yml +++ b/.github/actions/setup_base/action.yml @@ -23,6 +23,7 @@ runs: glm \ glslang \ go \ + hyprlang \ jq \ libc++ \ libdisplay-info \ diff --git a/CMakeLists.txt b/CMakeLists.txt index f894212c..857e21de 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) # 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) # we do not check for wlroots, as we provide it ourselves file(GLOB_RECURSE SRCFILES CONFIGURE_DEPENDS "src/*.cpp") @@ -26,6 +26,26 @@ "hyprlang": { "inputs": { "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1708005943, + "narHash": "sha256-9TT3xk++LI5/SPYgjYX34xZ4ebR93c1uerIq+SE/ues=", + "owner": "hyprwm", + "repo": "hyprlang", + "rev": "aeb3e012adc7b3235335c540b214b82267c2b983", + "type": "github" + }, + "original": { + "owner": "hyprwm", + "repo": "hyprlang", + "type": "github" + } + }, + "hyprlang_2": { + "inputs": { + "nixpkgs": [ "xdph", "nixpkgs" ] @@ -63,6 +83,7 @@ "root": { "inputs": { "hyprland-protocols": "hyprland-protocols", + "hyprlang": "hyprlang", "nixpkgs": "nixpkgs", "systems": "systems", "wlroots": "wlroots", @@ -108,7 +129,7 @@ "hyprland-protocols": [ "hyprland-protocols" ], - "hyprlang": "hyprlang", + "hyprlang": "hyprlang_2", "nixpkgs": [ "nixpkgs" ], @@ -22,6 +22,11 @@ inputs.systems.follows = "systems"; }; + hyprlang = { + url = "github:hyprwm/hyprlang"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + xdph = { url = "github:hyprwm/xdg-desktop-portal-hyprland"; inputs.nixpkgs.follows = "nixpkgs"; @@ -86,7 +91,7 @@ name = "hyprland-shell"; nativeBuildInputs = with pkgsFor.${system}; [cmake python3]; buildInputs = [self.packages.${system}.wlroots-hyprland]; - hardeningDisable = [ "fortify" ]; + hardeningDisable = ["fortify"]; inputsFrom = [ self.packages.${system}.wlroots-hyprland self.packages.${system}.hyprland diff --git a/nix/default.nix b/nix/default.nix index 751457ca..6062a215 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -9,6 +9,7 @@ cairo, git, hyprland-protocols, + hyprlang, jq, libGL, libdrm, @@ -75,6 +76,7 @@ assert lib.assertMsg (!hidpiXWayland) "The option `hidpiXWayland` has been remov cairo git hyprland-protocols + hyprlang libdrm libGL libinput diff --git a/nix/overlays.nix b/nix/overlays.nix index e82379c2..0a84d93e 100644 --- a/nix/overlays.nix +++ b/nix/overlays.nix @@ -22,6 +22,7 @@ in { hyprland-packages = lib.composeManyExtensions [ # Dependencies inputs.hyprland-protocols.overlays.default + inputs.hyprlang.overlays.default self.overlays.wlroots-hyprland self.overlays.udis86 # Hyprland packages themselves diff --git a/nix/patches/meson-build.patch b/nix/patches/meson-build.patch index 844eacae..aefbf1bc 100644 --- a/nix/patches/meson-build.patch +++ b/nix/patches/meson-build.patch @@ -34,16 +34,17 @@ index 1d2c7f9f..c5ef4e67 100644 headers = globber.stdout().strip().split('\n') foreach file : headers diff --git a/src/meson.build b/src/meson.build -index 0af864b9..38723b8c 100644 +index 45701f5f..3505cefe 100644 --- a/src/meson.build +++ b/src/meson.build -@@ -9,16 +9,16 @@ executable('Hyprland', src, +@@ -9,17 +9,17 @@ executable('Hyprland', src, server_protos, dependency('wayland-server'), dependency('wayland-client'), - wlroots.get_variable('wlroots'), + dependency('wlroots'), dependency('cairo'), + dependency('hyprlang', version: '>= 0.3.2'), dependency('libdrm'), dependency('egl'), dependency('xkbcommon'), diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 8c4c453c..479b5378 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -699,11 +699,11 @@ 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 = &g_pConfigManager->getConfigValuePtr("general:resize_on_border")->intValue; - static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; - static auto* const PBORDERGRABEXTEND = &g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area")->intValue; - static auto* const PSPECIALFALLTHRU = &g_pConfigManager->getConfigValuePtr("input:special_fallthrough")->intValue; - const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; + 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; // pinned windows on top of floating regardless if (properties & ALLOW_FLOATING) { @@ -793,7 +793,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) { @@ -893,8 +893,8 @@ CMonitor* CCompositor::getRealMonitorFromOutput(wlr_output* out) { void CCompositor::focusWindow(CWindow* pWindow, wlr_surface* pSurface) { - static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; - static auto* const PSPECIALFALLTHROUGH = &g_pConfigManager->getConfigValuePtr("input:special_fallthrough")->intValue; + 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"); if (g_pCompositor->m_sSeat.exclusiveClient) { Debug::log(LOG, "Disallowing setting focus to a window due to there being an active input inhibitor layer."); @@ -968,7 +968,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 @@ -1035,7 +1035,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(); } @@ -1502,7 +1502,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { return nullptr; // 0 -> history, 1 -> shared length - static auto* const PMETHOD = &g_pConfigManager->getConfigValuePtr("binds:focus_preferred_method")->intValue; + static auto* const PMETHOD = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:focus_preferred_method"); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); @@ -1564,7 +1564,7 @@ CWindow* CCompositor::getWindowInDirection(CWindow* pWindow, char dir) { break; } - if (*PMETHOD == 0 /* history */) { + if (**PMETHOD == 0 /* history */) { if (intersectLength > 0) { // get idx @@ -1863,21 +1863,30 @@ void CCompositor::updateWorkspaceWindows(const int64_t& id) { void CCompositor::updateWindowAnimatedDecorationValues(CWindow* pWindow) { // optimization - static auto* const ACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.active_border")->data.get(); - static auto* const INACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.inactive_border")->data.get(); - static auto* const NOGROUPACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.nogroup_border_active")->data.get(); - static auto* const NOGROUPINACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("general:col.nogroup_border")->data.get(); - static auto* const GROUPACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:col.border_active")->data.get(); - static auto* const GROUPINACTIVECOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:col.border_inactive")->data.get(); - static auto* const GROUPACTIVELOCKEDCOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:col.border_locked_active")->data.get(); - static auto* const GROUPINACTIVELOCKEDCOL = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:col.border_locked_inactive")->data.get(); - static auto* const PINACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity")->floatValue; - static auto* const PACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:active_opacity")->floatValue; - static auto* const PFULLSCREENALPHA = &g_pConfigManager->getConfigValuePtr("decoration:fullscreen_opacity")->floatValue; - static auto* const PSHADOWCOL = &g_pConfigManager->getConfigValuePtr("decoration:col.shadow")->intValue; - static auto* const PSHADOWCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("decoration:col.shadow_inactive")->intValue; - static auto* const PDIMSTRENGTH = &g_pConfigManager->getConfigValuePtr("decoration:dim_strength")->floatValue; - static auto* const PDIMENABLED = &g_pConfigManager->getConfigValuePtr("decoration:dim_inactive")->intValue; + 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"); + + 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 setBorderColor = [&](CGradientValueData grad) -> void { if (grad == pWindow->m_cRealBorderColor) @@ -1915,31 +1924,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 @@ -2439,9 +2448,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 = &g_pConfigManager->getConfigValuePtr("general:no_cursor_warps")->intValue; + static auto* const PNOWARPS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_cursor_warps"); - if (*PNOWARPS && !force) + if (**PNOWARPS && !force) return; if (!m_sSeat.mouse) @@ -2704,7 +2713,7 @@ void CCompositor::setIdleActivityInhibit(bool enabled) { wlr_idle_notifier_v1_set_inhibited(g_pCompositor->m_sWLRIdleNotifier, !enabled); } void CCompositor::arrangeMonitors() { - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); std::vector<CMonitor*> toArrange; std::vector<CMonitor*> arranged; @@ -2753,9 +2762,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 75a45d8f..ece5b658 100644 --- a/src/Window.cpp +++ b/src/Window.cpp @@ -371,7 +371,7 @@ void CWindow::moveToWorkspace(int workspaceID) { if (m_iWorkspaceID == workspaceID) return; - static auto* const PCLOSEONLASTSPECIAL = &g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty")->intValue; + static auto* const PCLOSEONLASTSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty"); const int OLDWORKSPACE = m_iWorkspaceID; @@ -394,7 +394,7 @@ void CWindow::moveToWorkspace(int workspaceID) { // update xwayland coords g_pXWaylandManager->setWindowSize(this, m_vRealSize.vec()); - 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) { @@ -437,7 +437,7 @@ void unregisterVar(void* ptr) { } void CWindow::onUnmap() { - static auto* const PCLOSEONLASTSPECIAL = &g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty")->intValue; + static auto* const PCLOSEONLASTSPECIAL = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:close_special_on_empty"); if (g_pCompositor->m_pLastWindow == this) g_pCompositor->m_pLastWindow = nullptr; @@ -459,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); @@ -1023,19 +1023,21 @@ bool CWindow::opaque() { } float CWindow::rounding() { - static auto* const PROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; + static auto* const PROUNDING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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; - if (m_bIsFloating && g_pConfigManager->getConfigValuePtr("general:no_border_on_floating")->intValue == 1) + static auto* const* PNOBORDERONFLOATING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_border_on_floating"); + + if (m_bIsFloating && **PNOBORDERONFLOATING == 1) border = false; m_sSpecialRenderData.border = WORKSPACERULE.border.value_or(border); @@ -1055,7 +1057,9 @@ int CWindow::getRealBorderSize() { if (m_sSpecialRenderData.borderSize.toUnderlying() != -1) return m_sSpecialRenderData.borderSize.toUnderlying(); - return g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; + static auto* const* PBORDERSIZE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:border_size"); + + return **PBORDERSIZE; } bool CWindow::canBeTorn() { diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index f1326c2a..4d3e6358 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -15,35 +15,545 @@ #include <iostream> #include <sstream> -extern "C" char** environ; +extern "C" char** environ; -CConfigManager::CConfigManager() { - configValues["general:col.active_border"].data = std::make_shared<CGradientValueData>(0xffffffff); - configValues["general:col.inactive_border"].data = std::make_shared<CGradientValueData>(0xff444444); - configValues["general:col.nogroup_border"].data = std::make_shared<CGradientValueData>(0xffffaaff); - configValues["general:col.nogroup_border_active"].data = std::make_shared<CGradientValueData>(0xffff00ff); +static Hyprlang::CParseResult configHandleGradientSet(const char* VALUE, void** data) { + std::string V = VALUE; - configValues["group:col.border_active"].data = std::make_shared<CGradientValueData>(0x66ffff00); - configValues["group:col.border_inactive"].data = std::make_shared<CGradientValueData>(0x66777700); - configValues["group:col.border_locked_active"].data = std::make_shared<CGradientValueData>(0x66ff5500); - configValues["group:col.border_locked_inactive"].data = std::make_shared<CGradientValueData>(0x66775500); + if (!*data) + *data = new CGradientValueData(); - configValues["group:groupbar:col.active"].data = std::make_shared<CGradientValueData>(0x66ffff00); - configValues["group:groupbar:col.inactive"].data = std::make_shared<CGradientValueData>(0x66777700); - configValues["group:groupbar:col.locked_active"].data = std::make_shared<CGradientValueData>(0x66ff5500); - configValues["group:groupbar:col.locked_inactive"].data = std::make_shared<CGradientValueData>(0x66775500); + const auto DATA = reinterpret_cast<CGradientValueData*>(*data); - 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."); + CVarList varlist(V, 0, ' '); + DATA->m_vColors.clear(); - setDefaultVars(); - setDefaultAnimationVars(); + std::string parseError = ""; + + for (auto& var : varlist) { + if (var.find("deg") != std::string::npos) { + // last arg + try { + DATA->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (PI / 180.0); // radians + } catch (...) { + Debug::log(WARN, "Error parsing gradient {}", V); + parseError = "Error parsing gradient " + V; + } + + break; + } + + if (DATA->m_vColors.size() >= 10) { + Debug::log(WARN, "Error parsing gradient {}: max colors is 10.", V); + parseError = "Error parsing gradient " + V + ": max colors is 10."; + break; + } + + try { + DATA->m_vColors.push_back(CColor(configStringToInt(var))); + } catch (std::exception& e) { + Debug::log(WARN, "Error parsing gradient {}", V); + parseError = "Error parsing gradient " + V + ": " + e.what(); + } + } + + if (DATA->m_vColors.size() == 0) { + Debug::log(WARN, "Error parsing gradient {}", V); + parseError = "Error parsing gradient " + V + ": No colors?"; + + DATA->m_vColors.push_back(0); // transparent + } + + Hyprlang::CParseResult result; + if (!parseError.empty()) + result.setError(parseError.c_str()); + + return result; +} + +static void configHandleGradientDestroy(void** data) { + if (*data) + delete reinterpret_cast<CGradientValueData*>(*data); +} + +static Hyprlang::CParseResult handleRawExec(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleRawExec(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleExecOnce(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleExecOnce(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleMonitor(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleMonitor(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleBezier(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleBezier(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleAnimation(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleAnimation(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleBind(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleBind(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleUnbind(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleUnbind(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleWindowRule(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleWindowRule(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleLayerRule(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleLayerRule(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleWindowRuleV2(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleWindowRuleV2(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleBlurLS(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleBlurLS(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleWorkspaceRules(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleWorkspaceRules(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleSubmap(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleSubmap(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleSource(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleSource(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handleEnv(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handleEnv(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +static Hyprlang::CParseResult handlePlugin(const char* c, const char* v) { + const std::string VALUE = v; + const std::string COMMAND = c; + + const auto RESULT = g_pConfigManager->handlePlugin(COMMAND, VALUE); + + Hyprlang::CParseResult result; + if (RESULT.has_value()) + result.setError(RESULT.value().c_str()); + return result; +} + +CConfigManager::CConfigManager() { + const auto ERR = verifyConfigExists(); configPaths.emplace_back(getMainConfigPath()); + m_pConfig = std::make_unique<Hyprlang::CConfig>(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:gaps_in", {5L}); + m_pConfig->addConfigValue("general:gaps_out", {20L}); + 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:layout", {"dwindle"}); + m_pConfig->addConfigValue("general:allow_tearing", {0L}); + + m_pConfig->addConfigValue("misc:disable_hyprland_logo", {0L}); + m_pConfig->addConfigValue("misc:disable_splash_rendering", {0L}); + 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: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: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("group:insert_after_current", {1L}); + m_pConfig->addConfigValue("group:focus_removed_window", {1L}); + m_pConfig->addConfigValue("group:groupbar:enabled", {1L}); + 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("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: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("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: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: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: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_inactive", {(Hyprlang::INT)INT_MAX}); + m_pConfig->addConfigValue("decoration:dim_inactive", {0L}); + 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: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:default_split_ratio", {1.f}); + m_pConfig->addConfigValue("dwindle:smart_split", {0L}); + m_pConfig->addConfigValue("dwindle:smart_resizing", {1L}); + + 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: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("animations:enabled", {1L}); + m_pConfig->addConfigValue("animations:first_launch_animation", {1L}); + + 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:sensitivity", {0.f}); + m_pConfig->addConfigValue("input:accel_profile", {STRVAL_EMPTY}); + m_pConfig->addConfigValue("input:kb_file", {STRVAL_EMPTY}); + m_pConfig->addConfigValue("input:kb_layout", {"us"}); + m_pConfig->addConfigValue("input:kb_variant", {STRVAL_EMPTY}); + 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:force_no_accel", {0L}); + m_pConfig->addConfigValue("input:float_switch_override_focus", {1L}); + m_pConfig->addConfigValue("input:left_handed", {0L}); + 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_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: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:scroll_factor", {1.f}); + m_pConfig->addConfigValue("input:touchdevice:transform", {0L}); + m_pConfig->addConfigValue("input:touchdevice:output", {STRVAL_EMPTY}); + m_pConfig->addConfigValue("input:touchdevice:enabled", {1L}); + m_pConfig->addConfigValue("input:tablet:transform", {0L}); + 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("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("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_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("xwayland:use_nearest_neighbor", {1L}); + m_pConfig->addConfigValue("xwayland:force_zero_scaling", {0L}); + + m_pConfig->addConfigValue("opengl:nvidia_anti_flicker", {1L}); + + m_pConfig->addConfigValue("autogenerated", {0L}); + + m_pConfig->addConfigValue("general:col.active_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffffffff"}); + m_pConfig->addConfigValue("general:col.inactive_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xff444444"}); + m_pConfig->addConfigValue("general:col.nogroup_border", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffffaaff"}); + m_pConfig->addConfigValue("general:col.nogroup_border_active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0xffff00ff"}); + + m_pConfig->addConfigValue("group:col.border_active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66ffff00"}); + m_pConfig->addConfigValue("group:col.border_inactive", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66777700"}); + m_pConfig->addConfigValue("group:col.border_locked_active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66ff5500"}); + m_pConfig->addConfigValue("group:col.border_locked_inactive", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66775500"}); + + m_pConfig->addConfigValue("group:groupbar:col.active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66ffff00"}); + m_pConfig->addConfigValue("group:groupbar:col.inactive", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66777700"}); + m_pConfig->addConfigValue("group:groupbar:col.locked_active", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66ff5500"}); + m_pConfig->addConfigValue("group:groupbar:col.locked_inactive", Hyprlang::CConfigCustomValueType{&configHandleGradientSet, configHandleGradientDestroy, "0x66775500"}); + + // devices + m_pConfig->addSpecialCategory("device", {"name"}); + m_pConfig->addSpecialConfigValue("device", "sensitivity", {0.F}); + m_pConfig->addSpecialConfigValue("device", "accel_profile", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "kb_file", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "kb_layout", {"us"}); + m_pConfig->addSpecialConfigValue("device", "kb_variant", {STRVAL_EMPTY}); + 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", "tap_button_map", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "numlock_by_default", {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", "scroll_method", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "scroll_button", {0L}); + m_pConfig->addSpecialConfigValue("device", "scroll_button_lock", {0L}); + m_pConfig->addSpecialConfigValue("device", "scroll_points", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "transform", {0L}); + m_pConfig->addSpecialConfigValue("device", "output", {STRVAL_EMPTY}); + m_pConfig->addSpecialConfigValue("device", "enabled", {1L}); // 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 + + // keywords + m_pConfig->registerHandler(&::handleRawExec, "exec", {false}); + m_pConfig->registerHandler(&::handleExecOnce, "exec-once", {false}); + m_pConfig->registerHandler(&::handleMonitor, "monitor", {false}); + m_pConfig->registerHandler(&::handleBind, "bind", {true}); + m_pConfig->registerHandler(&::handleUnbind, "unbind", {false}); + m_pConfig->registerHandler(&::handleWorkspaceRules, "workspace", {false}); + m_pConfig->registerHandler(&::handleWindowRule, "windowrule", {false}); + m_pConfig->registerHandler(&::handleLayerRule, "layerrule", {false}); + m_pConfig->registerHandler(&::handleWindowRuleV2, "windowrulev2", {false}); + m_pConfig->registerHandler(&::handleBezier, "bezier", {false}); + m_pConfig->registerHandler(&::handleAnimation, "animation", {false}); + m_pConfig->registerHandler(&::handleSource, "source", {false}); + m_pConfig->registerHandler(&::handleSubmap, "submap", {false}); + m_pConfig->registerHandler(&::handleBlurLS, "blurls", {false}); + m_pConfig->registerHandler(&::handlePlugin, "plugin", {false}); + m_pConfig->registerHandler(&::handleEnv, "env", {true}); + + // pluginza + m_pConfig->addSpecialCategory("plugin", {nullptr, true}); + + 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."); - Debug::disableLogs = &configValues["debug:disable_logs"].intValue; - Debug::disableTime = &configValues["debug:disable_time"].intValue; + setDefaultAnimationVars(); + resetHLConfig(); + + Debug::disableLogs = reinterpret_cast<int64_t* const*>(m_pConfig->getConfigValuePtr("debug:disable_logs")->getDataStaticPtr()); + Debug::disableTime = reinterpret_cast<int64_t* const*>(m_pConfig->getConfigValuePtr("debug:disable_time")->getDataStaticPtr()); - populateEnvironment(); + if (ERR.has_value()) + g_pHyprError->queueCreate(ERR.value(), CColor{1.0, 0.1, 0.1, 1.0}); } std::string CConfigManager::getConfigDir() { @@ -62,268 +572,12 @@ std::string CConfigManager::getMainConfigPath() { return getConfigDir() + "/hypr/" + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf"); } -void CConfigManager::populateEnvironment() { - environmentVariables.clear(); - for (char** env = environ; *env; ++env) { - const std::string ENVVAR = *env; - const auto VARIABLE = ENVVAR.substr(0, ENVVAR.find_first_of('=')); - const auto VALUE = ENVVAR.substr(ENVVAR.find_first_of('=') + 1); - environmentVariables.emplace_back(std::make_pair<>(VARIABLE, VALUE)); - } - - std::sort(environmentVariables.begin(), environmentVariables.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); }); -} - -void CConfigManager::setDefaultVars() { - configValues["general:max_fps"].intValue = 60; - configValues["general:sensitivity"].floatValue = 1.0f; - configValues["general:apply_sens_to_raw"].intValue = 0; - configValues["general:border_size"].intValue = 1; - configValues["general:no_border_on_floating"].intValue = 0; - configValues["general:border_part_of_window"].intValue = 1; - configValues["general:gaps_in"].intValue = 5; - configValues["general:gaps_out"].intValue = 20; - configValues["general:gaps_workspaces"].intValue = 0; - ((CGradientValueData*)configValues["general:col.active_border"].data.get())->reset(0xffffffff); - ((CGradientValueData*)configValues["general:col.inactive_border"].data.get())->reset(0xff444444); - ((CGradientValueData*)configValues["general:col.nogroup_border"].data.get())->reset(0xff444444); - ((CGradientValueData*)configValues["general:col.nogroup_border_active"].data.get())->reset(0xffff00ff); - configValues["general:cursor_inactive_timeout"].intValue = 0; - configValues["general:no_cursor_warps"].intValue = 0; - configValues["general:no_focus_fallback"].intValue = 0; - configValues["general:resize_on_border"].intValue = 0; - configValues["general:extend_border_grab_area"].intValue = 15; - configValues["general:hover_icon_on_border"].intValue = 1; - configValues["general:layout"].strValue = "dwindle"; - configValues["general:allow_tearing"].intValue = 0; - - configValues["misc:disable_hyprland_logo"].intValue = 0; - configValues["misc:disable_splash_rendering"].intValue = 0; - configValues["misc:force_default_wallpaper"].intValue = -1; - configValues["misc:vfr"].intValue = 1; - configValues["misc:vrr"].intValue = 0; - configValues["misc:mouse_move_enables_dpms"].intValue = 0; - configValues["misc:key_press_enables_dpms"].intValue = 0; - configValues["misc:always_follow_on_dnd"].intValue = 1; - configValues["misc:layers_hog_keyboard_focus"].intValue = 1; - configValues["misc:animate_manual_resizes"].intValue = 0; - configValues["misc:animate_mouse_windowdragging"].intValue = 0; - configValues["misc:disable_autoreload"].intValue = 0; - configValues["misc:enable_swallow"].intValue = 0; - configValues["misc:swallow_regex"].strValue = STRVAL_EMPTY; - configValues["misc:swallow_exception_regex"].strValue = STRVAL_EMPTY; - configValues["misc:focus_on_activate"].intValue = 0; - configValues["misc:no_direct_scanout"].intValue = 1; - configValues["misc:hide_cursor_on_touch"].intValue = 1; - configValues["misc:mouse_move_focuses_monitor"].intValue = 1; - configValues["misc:render_ahead_of_time"].intValue = 0; - configValues["misc:render_ahead_safezone"].intValue = 1; - configValues["misc:cursor_zoom_factor"].floatValue = 1.f; - configValues["misc:cursor_zoom_rigid"].intValue = 0; - configValues["misc:allow_session_lock_restore"].intValue = 0; - configValues["misc:close_special_on_empty"].intValue = 1; - configValues["misc:background_color"].intValue = 0xff111111; - configValues["misc:new_window_takes_over_fullscreen"].intValue = 0; - - ((CGradientValueData*)configValues["group:col.border_active"].data.get())->reset(0x66ffff00); - ((CGradientValueData*)configValues["group:col.border_inactive"].data.get())->reset(0x66777700); - ((CGradientValueData*)configValues["group:col.border_locked_active"].data.get())->reset(0x66ff5500); - ((CGradientValueData*)configValues["group:col.border_locked_inactive"].data.get())->reset(0x66775500); - - configValues["group:insert_after_current"].intValue = 1; - configValues["group:focus_removed_window"].intValue = 1; - - configValues["group:groupbar:enabled"].intValue = 1; - configValues["group:groupbar:font_family"].strValue = "Sans"; - configValues["group:groupbar:font_size"].intValue = 8; - configValues["group:groupbar:gradients"].intValue = 1; - configValues["group:groupbar:height"].intValue = 14; - configValues["group:groupbar:priority"].intValue = 3; - configValues["group:groupbar:render_titles"].intValue = 1; - configValues["group:groupbar:scrolling"].intValue = 1; - configValues["group:groupbar:text_color"].intValue = 0xffffffff; - - ((CGradientValueData*)configValues["group:groupbar:col.active"].data.get())->reset(0x66ffff00); - ((CGradientValueData*)configValues["group:groupbar:col.inactive"].data.get())->reset(0x66777700); - ((CGradientValueData*)configValues["group:groupbar:col.locked_active"].data.get())->reset(0x66ff5500); - ((CGradientValueData*)configValues["group:groupbar:col.locked_inactive"].data.get())->reset(0x66775500); - - configValues["debug:int"].intValue = 0; - configValues["debug:log_damage"].intValue = 0; - configValues["debug:overlay"].intValue = 0; - configValues["debug:damage_blink"].intValue = 0; - configValues["debug:disable_logs"].intValue = 1; - configValues["debug:disable_time"].intValue = 1; - configValues["debug:enable_stdout_logs"].intValue = 0; - configValues["debug:damage_tracking"].intValue = DAMAGE_TRACKING_FULL; - configValues["debug:manual_crash"].intValue = 0; - configValues["debug:suppress_errors"].intValue = 0; - configValues["debug:watchdog_timeout"].intValue = 5; - configValues["debug:disable_scale_checks"].intValue = 0; - - configValues["decoration:rounding"].intValue = 0; - configValues["decoration:blur:enabled"].intValue = 1; - configValues["decoration:blur:size"].intValue = 8; - configValues["decoration:blur:passes"].intValue = 1; - configValues["decoration:blur:ignore_opacity"].intValue = 0; - configValues["decoration:blur:new_optimizations"].intValue = 1; - configValues["decoration:blur:xray"].intValue = 0; - configValues["decoration:blur:contrast"].floatValue = 0.8916; - configValues["decoration:blur:brightness"].floatValue = 1.0; - configValues["decoration:blur:vibrancy"].floatValue = 0.1696; - configValues["decoration:blur:vibrancy_darkness"].floatValue = 0.0; - configValues["decoration:blur:noise"].floatValue = 0.0117; - configValues["decoration:blur:special"].intValue = 0; - configValues["decoration:blur:popups"].intValue = 0; - configValues["decoration:blur:popups_ignorealpha"].floatValue = 0.2; - configValues["decoration:active_opacity"].floatValue = 1; - configValues["decoration:inactive_opacity"].floatValue = 1; - configValues["decoration:fullscreen_opacity"].floatValue = 1; - configValues["decoration:no_blur_on_oversized"].intValue = 0; - configValues["decoration:drop_shadow"].intValue = 1; - configValues["decoration:shadow_range"].intValue = 4; - configValues["decoration:shadow_render_power"].intValue = 3; - configValues["decoration:shadow_ignore_window"].intValue = 1; - configValues["decoration:shadow_offset"].vecValue = Vector2D(); - configValues["decoration:shadow_scale"].floatValue = 1.f; - configValues["decoration:col.shadow"].intValue = 0xee1a1a1a; - configValues["decoration:col.shadow_inactive"].intValue = INT_MAX; - configValues["decoration:dim_inactive"].intValue = 0; - configValues["decoration:dim_strength"].floatValue = 0.5f; - configValues["decoration:dim_special"].floatValue = 0.2f; - configValues["decoration:dim_around"].floatValue = 0.4f; - configValues["decoration:screen_shader"].strValue = STRVAL_EMPTY; - - configValues["dwindle:pseudotile"].intValue = 0; - configValues["dwindle:force_split"].intValue = 0; - configValues["dwindle:permanent_direction_override"].intValue = 0; - configValues["dwindle:preserve_split"].intValue = 0; - configValues["dwindle:special_scale_factor"].floatValue = 1.f; - configValues["dwindle:split_width_multiplier"].floatValue = 1.0f; - configValues["dwindle:no_gaps_when_only"].intValue = 0; - configValues["dwindle:use_active_for_splits"].intValue = 1; - configValues["dwindle:default_split_ratio"].floatValue = 1.f; - configValues["dwindle:smart_split"].intValue = 0; - configValues["dwindle:smart_resizing"].intValue = 1; - - configValues["master:special_scale_factor"].floatValue = 1.f; - configValues["master:mfact"].floatValue = 0.55f; - configValues["master:new_is_master"].intValue = 1; - configValues["master:always_center_master"].intValue = 0; - configValues["master:new_on_top"].intValue = 0; - configValues["master:no_gaps_when_only"].intValue = 0; - configValues["master:orientation"].strValue = "left"; - configValues["master:inherit_fullscreen"].intValue = 1; - configValues["master:allow_small_split"].intValue = 0; - configValues["master:smart_resizing"].intValue = 1; - configValues["master:drop_at_cursor"].intValue = 1; - - configValues["animations:enabled"].intValue = 1; - configValues["animations:first_launch_animation"].intValue = 1; - - configValues["input:follow_mouse"].intValue = 1; - configValues["input:mouse_refocus"].intValue = 1; - configValues["input:special_fallthrough"].intValue = 0; - configValues["input:sensitivity"].floatValue = 0.f; - configValues["input:accel_profile"].strValue = STRVAL_EMPTY; - configValues["input:kb_file"].strValue = STRVAL_EMPTY; - configValues["input:kb_layout"].strValue = "us"; - configValues["input:kb_variant"].strValue = STRVAL_EMPTY; - configValues["input:kb_options"].strValue = STRVAL_EMPTY; - configValues["input:kb_rules"].strValue = STRVAL_EMPTY; - configValues["input:kb_model"].strValue = STRVAL_EMPTY; - configValues["input:repeat_rate"].intValue = 25; - configValues["input:repeat_delay"].intValue = 600; - configValues["input:natural_scroll"].intValue = 0; - configValues["input:numlock_by_default"].intValue = 0; - configValues["input:force_no_accel"].intValue = 0; - configValues["input:float_switch_override_focus"].intValue = 1; - configValues["input:left_handed"].intValue = 0; - configValues["input:scroll_method"].strValue = STRVAL_EMPTY; - configValues["input:scroll_button"].intValue = 0; - configValues["input:scroll_button_lock"].intValue = 0; - configValues["input:scroll_points"].strValue = STRVAL_EMPTY; - configValues["input:touchpad:natural_scroll"].intValue = 0; - configValues["input:touchpad:disable_while_typing"].intValue = 1; - configValues["input:touchpad:clickfinger_behavior"].intValue = 0; - configValues["input:touchpad:tap_button_map"].strValue = STRVAL_EMPTY; - configValues["input:touchpad:middle_button_emulation"].intValue = 0; - configValues["input:touchpad:tap-to-click"].intValue = 1; - configValues["input:touchpad:tap-and-drag"].intValue = 1; - configValues["input:touchpad:drag_lock"].intValue = 0; - configValues["input:touchpad:scroll_factor"].floatValue = 1.f; - configValues["input:touchdevice:transform"].intValue = 0; - configValues["input:touchdevice:output"].strValue = STRVAL_EMPTY; - configValues["input:touchdevice:enabled"].intValue = 1; - configValues["input:tablet:transform"].intValue = 0; - configValues["input:tablet:output"].strValue = STRVAL_EMPTY; - configValues["input:tablet:region_position"].vecValue = Vector2D(); - configValues["input:tablet:region_size"].vecValue = Vector2D(); - configValues["input:tablet:relative_input"].intValue = 0; - - configValues["binds:pass_mouse_when_bound"].intValue = 0; - configValues["binds:scroll_event_delay"].intValue = 300; - configValues["binds:workspace_back_and_forth"].intValue = 0; - configValues["binds:allow_workspace_cycles"].intValue = 0; - configValues["binds:workspace_center_on"].intValue = 1; - configValues["binds:focus_preferred_method"].intValue = 0; - configValues["binds:ignore_group_lock"].intValue = 0; - configValues["binds:movefocus_cycles_fullscreen"].intValue = 1; - - configValues["gestures:workspace_swipe"].intValue = 0; - configValues["gestures:workspace_swipe_fingers"].intValue = 3; - configValues["gestures:workspace_swipe_distance"].intValue = 300; - configValues["gestures:workspace_swipe_invert"].intValue = 1; - configValues["gestures:workspace_swipe_min_speed_to_force"].intValue = 30; - configValues["gestures:workspace_swipe_cancel_ratio"].floatValue = 0.5f; - configValues["gestures:workspace_swipe_create_new"].intValue = 1; - configValues["gestures:workspace_swipe_direction_lock"].intValue = 1; - configValues["gestures:workspace_swipe_direction_lock_threshold"].intValue = 10; - configValues["gestures:workspace_swipe_forever"].intValue = 0; - configValues["gestures:workspace_swipe_numbered"].intValue = 0; - configValues["gestures:workspace_swipe_use_r"].intValue = 0; - - configValues["xwayland:use_nearest_neighbor"].intValue = 1; - configValues["xwayland:force_zero_scaling"].intValue = 0; - - configValues["opengl:nvidia_anti_flicker"].intValue = 1; - - configValues["autogenerated"].intValue = 0; -} - -void CConfigManager::setDeviceDefaultVars(const std::string& dev) { - auto& cfgValues = deviceConfigs[dev]; - - cfgValues["sensitivity"].floatValue = 0.f; - cfgValues["accel_profile"].strValue = STRVAL_EMPTY; - cfgValues["kb_file"].strValue = STRVAL_EMPTY; - cfgValues["kb_layout"].strValue = "us"; - cfgValues["kb_variant"].strValue = STRVAL_EMPTY; - cfgValues["kb_options"].strValue = STRVAL_EMPTY; - cfgValues["kb_rules"].strValue = STRVAL_EMPTY; - cfgValues["kb_model"].strValue = STRVAL_EMPTY; - cfgValues["repeat_rate"].intValue = 25; - cfgValues["repeat_delay"].intValue = 600; - cfgValues["natural_scroll"].intValue = 0; - cfgValues["tap_button_map"].strValue = STRVAL_EMPTY; - cfgValues["numlock_by_default"].intValue = 0; - cfgValues["disable_while_typing"].intValue = 1; - cfgValues["clickfinger_behavior"].intValue = 0; - cfgValues["middle_button_emulation"].intValue = 0; - cfgValues["tap-to-click"].intValue = 1; - cfgValues["tap-and-drag"].intValue = 1; - cfgValues["drag_lock"].intValue = 0; - cfgValues["left_handed"].intValue = 0; - cfgValues["scroll_method"].strValue = STRVAL_EMPTY; - cfgValues["scroll_button"].intValue = 0; - cfgValues["scroll_button_lock"].intValue = 0; - cfgValues["scroll_points"].strValue = STRVAL_EMPTY; - cfgValues["transform"].intValue = 0; - cfgValues["output"].strValue = STRVAL_EMPTY; - cfgValues["enabled"].intValue = 1; // only for mice, touchpads, and touchdevices - cfgValues["region_position"].vecValue = Vector2D(); // only for tablets - cfgValues["region_size"].vecValue = Vector2D(); // only for tablets - cfgValues["relative_input"].intValue = 0; // only for tablets +void CConfigManager::reload() { + setDefaultAnimationVars(); + resetHLConfig(); + configCurrentPath = getMainConfigPath(); + const auto ERR = m_pConfig->parse(); + postConfigReload(ERR); } void CConfigManager::setDefaultAnimationVars() { @@ -375,14 +629,154 @@ void CConfigManager::setDefaultAnimationVars() { CREATEANIMCFG("specialWorkspace", "workspaces"); } -void CConfigManager::init() { +std::optional<std::string> CConfigManager::verifyConfigExists() { + std::string mainConfigPath = getMainConfigPath(); + + if (g_pCompositor->explicitConfigPath.empty() && !std::filesystem::exists(mainConfigPath)) { + std::string configPath = std::filesystem::path(mainConfigPath).parent_path(); + + if (!std::filesystem::is_directory(configPath)) { + Debug::log(WARN, "Creating config home directory"); + try { + std::filesystem::create_directories(configPath); + } catch (...) { return "Broken config file! (Could not create config directory)"; } + } + + Debug::log(WARN, "No config file found; attempting to generate."); + std::ofstream ofs; + ofs.open(mainConfigPath, std::ios::trunc); + ofs << AUTOCONFIG; + ofs.close(); + } + + if (!std::filesystem::exists(mainConfigPath)) + return "broken config dir?"; + + return {}; +} + +std::optional<std::string> CConfigManager::resetHLConfig() { + m_dMonitorRules.clear(); + m_dWindowRules.clear(); + g_pKeybindManager->clearKeybinds(); + g_pAnimationManager->removeAllBeziers(); + m_mAdditionalReservedAreas.clear(); + m_dBlurLSNamespaces.clear(); + m_dWorkspaceRules.clear(); + setDefaultAnimationVars(); // reset anims + m_vDeclaredPlugins.clear(); + m_dLayerRules.clear(); + m_vFailedPluginConfigValues.clear(); + + // paths + configPaths.clear(); + std::string mainConfigPath = getMainConfigPath(); + Debug::log(LOG, "Using config: {}", mainConfigPath); + configPaths.push_back(mainConfigPath); + + const auto RET = verifyConfigExists(); + + return RET; +} + +void CConfigManager::postConfigReload(const Hyprlang::CParseResult& result) { + for (auto& w : g_pCompositor->m_vWindows) { + w->uncacheWindowDecos(); + } + + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); + + // Update the keyboard layout to the cfg'd one if this is not the first launch + if (!isFirstLaunch) { + g_pInputManager->setKeyboardLayout(); + g_pInputManager->setPointerConfigs(); + g_pInputManager->setTouchDeviceConfigs(); + g_pInputManager->setTabletConfigs(); + } + + if (!isFirstLaunch) + g_pHyprOpenGL->m_bReloadScreenShader = true; + + // parseError will be displayed next frame + if (result.error && !std::any_cast<Hyprlang::INT>(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<Hyprlang::INT>(m_pConfig->getConfigValue("autogenerated")) == 1) + g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + getMainConfigPath() + " )\nSUPER+Q -> kitty\nSUPER+M -> exit Hyprland", + CColor(1.0, 1.0, 70.0 / 255.0, 1.0)); + else + g_pHyprError->destroy(); + + // Set the modes for all monitors as we configured them + // not on first launch because monitors might not exist yet + // and they'll be taken care of in the newMonitor event + // ignore if nomonitorreload is set + if (!isFirstLaunch && !m_bNoMonitorReload) { + // check + performMonitorReload(); + ensureMonitorStatus(); + ensureVRR(); + } + + if (!isFirstLaunch && !g_pCompositor->m_bUnsafeState) + refreshGroupBarGradients(); + + // Updates dynamic window and workspace rules + for (auto& w : g_pCompositor->m_vWindows) { + if (!w->m_bIsMapped) + continue; + + w->updateDynamicRules(); + w->updateSpecialRenderData(); + } + + // Update window border colors + g_pCompositor->updateAllWindowsAnimatedDecorationValues(); + + // update layout + g_pLayoutManager->switchToLayout(std::any_cast<Hyprlang::STRING>(m_pConfig->getConfigValue("general:layout"))); + + // manual crash + if (std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:manual_crash")) && !m_bManualCrashInitiated) { + m_bManualCrashInitiated = true; + g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, ICON_INFO); + } else if (m_bManualCrashInitiated && !std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:manual_crash"))) { + // cowabunga it is + g_pHyprRenderer->initiateManualCrash(); + } + + Debug::disableStdout = !std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:enable_stdout_logs")); + if (Debug::disableStdout && isFirstLaunch) + Debug::log(LOG, "Disabling stdout logs! Check the log for further logs."); + + for (auto& m : g_pCompositor->m_vMonitors) { + // mark blur dirty + g_pHyprOpenGL->markBlurDirtyForMonitor(m.get()); + + g_pCompositor->scheduleFrameForMonitor(m.get()); + + // Force the compositor to fully re-render all monitors + m->forceFullFrames = 2; + } + + // Reset no monitor reload + m_bNoMonitorReload = false; + + // update plugins + handlePluginLoads(); + + EMIT_HOOK_EVENT("configReloaded", nullptr); + if (g_pEventManager) + g_pEventManager->postEvent(SHyprIPCEvent{"configreloaded", ""}); +} - loadConfigLoadVars(); +void CConfigManager::init() { const std::string CONFIGPATH = getMainConfigPath(); + reload(); - struct stat fileStat; - int err = stat(CONFIGPATH.c_str(), &fileStat); + struct stat fileStat; + int err = stat(CONFIGPATH.c_str(), &fileStat); if (err != 0) { Debug::log(WARN, "Error at statting config, error {}", errno); } @@ -392,184 +786,639 @@ void CConfigManager::init() { isFirstLaunch = false; } -void CConfigManager::configSetValueSafe(const std::string& COMMAND, const std::string& VALUE) { - if (!configValues.contains(COMMAND)) { - if (!COMMAND.starts_with("device:") /* devices parsed later */ && !COMMAND.starts_with("plugin:") /* plugins parsed later */) { - if (COMMAND[0] == '$') { - // register a dynamic var - bool found = false; - for (auto& [var, val] : configDynamicVars) { - if (var == COMMAND.substr(1)) { - Debug::log(LOG, "Registered new value for dynamic var \"{}\" -> {}", COMMAND, VALUE); - val = VALUE; - found = true; - } - } +std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& VALUE) { + int needsLayoutRecalc = COMMAND == "monitor"; // 0 - no, 1 - yes, 2 - maybe - if (!found) { - Debug::log(LOG, "Registered dynamic var \"{}\" -> {}", COMMAND, VALUE); - configDynamicVars.emplace_back(std::make_pair<>(COMMAND.substr(1), VALUE)); - std::sort(configDynamicVars.begin(), configDynamicVars.end(), [&](const auto& a, const auto& b) { return a.first.length() > b.first.length(); }); - } - } else { - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field."; - } + const auto RET = m_pConfig->parseDynamic(COMMAND.c_str(), VALUE.c_str()); - return; + // invalidate layouts if they changed + if (needsLayoutRecalc) { + if (needsLayoutRecalc == 1 || COMMAND.contains("gaps_") || COMMAND.starts_with("dwindle:") || COMMAND.starts_with("master:")) { + for (auto& m : g_pCompositor->m_vMonitors) + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); } } - SConfigValue* CONFIGENTRY = nullptr; + // Update window border colors + g_pCompositor->updateAllWindowsAnimatedDecorationValues(); - if (COMMAND.starts_with("device:")) { - const auto DEVICE = COMMAND.substr(7).substr(0, COMMAND.find_last_of(':') - 7); - const auto CONFIGVAR = COMMAND.substr(COMMAND.find_last_of(':') + 1); + // manual crash + if (std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:manual_crash")) && !m_bManualCrashInitiated) { + m_bManualCrashInitiated = true; + if (g_pHyprNotificationOverlay) { + g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, + ICON_INFO); + } + } else if (m_bManualCrashInitiated && !std::any_cast<Hyprlang::INT>(m_pConfig->getConfigValue("debug:manual_crash"))) { + // cowabunga it is + g_pHyprRenderer->initiateManualCrash(); + } - if (!deviceConfigExists(DEVICE)) - setDeviceDefaultVars(DEVICE); + return RET.error ? RET.getError() : ""; +} - auto it = deviceConfigs.find(DEVICE); +void CConfigManager::tick() { + std::string CONFIGPATH = getMainConfigPath(); + if (!std::filesystem::exists(CONFIGPATH)) { + Debug::log(ERR, "Config doesn't exist??"); + return; + } - if (it->second.find(CONFIGVAR) == it->second.end()) { - if (it->second.contains("touch_output") || it->second.contains("touch_transform")) { - parseError = "touch_output and touch_transform have been changed to output and transform respectively"; - return; - } + bool parse = false; - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">: No such field."; - return; + for (auto& cf : configPaths) { + struct stat fileStat; + int err = stat(cf.c_str(), &fileStat); + if (err != 0) { + Debug::log(WARN, "Error at ticking config at {}, error {}: {}", cf, err, strerror(err)); + continue; } - CONFIGENTRY = &it->second.at(CONFIGVAR); - } else if (COMMAND.starts_with("plugin:")) { - for (auto& [handle, pMap] : pluginConfigs) { - auto it = std::find_if(pMap->begin(), pMap->end(), [&](const auto& other) { return other.first == COMMAND; }); - if (it == pMap->end()) { - continue; // May be in another plugin - } - - CONFIGENTRY = &it->second; + // check if we need to reload cfg + if (fileStat.st_mtime != configModifyTimes[cf] || m_bForceReload) { + parse = true; + configModifyTimes[cf] = fileStat.st_mtime; } + } - if (!CONFIGENTRY) { - m_vFailedPluginConfigValues.emplace_back(std::make_pair<>(COMMAND, VALUE)); - return; // silent ignore - } - } else { - CONFIGENTRY = &configValues.at(COMMAND); + if (parse) { + m_bForceReload = false; + + reload(); } +} - CONFIGENTRY->set = true; +Hyprlang::CConfigValue* CConfigManager::getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback) { - if (CONFIGENTRY->intValue != -INT64_MAX) { - try { - CONFIGENTRY->intValue = configStringToInt(VALUE); - } catch (std::exception& e) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. " + e.what(); - } - } else if (CONFIGENTRY->floatValue != -__FLT_MAX__) { - try { - CONFIGENTRY->floatValue = stof(VALUE); - } catch (...) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">."; + const auto VAL = m_pConfig->getSpecialConfigValuePtr("device", val.c_str(), dev.c_str()); + + if ((!VAL || !VAL->m_bSetByUser) && !fallback.empty()) { + return m_pConfig->getConfigValuePtr(fallback.c_str()); + } + + return VAL; +} + +int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v, const std::string& fallback) { + return std::any_cast<Hyprlang::INT>(getConfigValueSafeDevice(dev, v, fallback)->getValue()); +} + +float CConfigManager::getDeviceFloat(const std::string& dev, const std::string& v, const std::string& fallback) { + return std::any_cast<Hyprlang::FLOAT>(getConfigValueSafeDevice(dev, v, fallback)->getValue()); +} + +Vector2D CConfigManager::getDeviceVec(const std::string& dev, const std::string& v, const std::string& fallback) { + return std::any_cast<Hyprlang::VEC2>(getConfigValueSafeDevice(dev, v, fallback)->getValue()); +} + +std::string CConfigManager::getDeviceString(const std::string& dev, const std::string& v, const std::string& fallback) { + const auto VAL = std::string{std::any_cast<Hyprlang::STRING>(getConfigValueSafeDevice(dev, v, fallback)->getValue())}; + + if (VAL == STRVAL_EMPTY) + return ""; + + return VAL; +} + +SMonitorRule CConfigManager::getMonitorRuleFor(const std::string& name, const std::string& displayName) { + SMonitorRule* found = nullptr; + + for (auto& r : m_dMonitorRules) { + if (r.name == name || + (r.name.starts_with("desc:") && + (r.name.substr(5) == displayName || r.name.substr(5) == removeBeginEndSpacesTabs(displayName.substr(0, displayName.find_first_of('(')))))) { + found = &r; + break; } - } else if (CONFIGENTRY->strValue != "") { - try { - CONFIGENTRY->strValue = VALUE; - } catch (...) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">."; + } + + if (found) + return *found; + + Debug::log(WARN, "No rule found for {}, trying to use the first.", name); + + for (auto& r : m_dMonitorRules) { + if (r.name == "") { + found = &r; + break; } - } else if (CONFIGENTRY->vecValue != Vector2D(-__FLT_MAX__, -__FLT_MAX__)) { - try { - if (const auto SPACEPOS = VALUE.find(' '); SPACEPOS != std::string::npos) { - const auto X = VALUE.substr(0, SPACEPOS); - const auto Y = VALUE.substr(SPACEPOS + 1); + } + + if (found) + return *found; + + Debug::log(WARN, "No rules configured. Using the default hardcoded one."); + + 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 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 */ + }); + if (IT == m_dWorkspaceRules.end()) + return SWorkspaceRule{}; + return *IT; +} + +std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) { + if (!g_pCompositor->windowValidMapped(pWindow)) + return std::vector<SWindowRule>(); + + std::vector<SWindowRule> returns; + + std::string title = g_pXWaylandManager->getTitle(pWindow); + std::string appidclass = g_pXWaylandManager->getAppIDClass(pWindow); + + Debug::log(LOG, "Searching for matching rules for {} (title: {})", appidclass, title); + + // since some rules will be applied later, we need to store some flags + bool hasFloating = pWindow->m_bIsFloating; + bool hasFullscreen = pWindow->m_bIsFullscreen; + + for (auto& rule : m_dWindowRules) { + // check if we have a matching rule + if (!rule.v2) { + try { + if (rule.szValue.starts_with("title:")) { + // we have a title rule. + std::regex RULECHECK(rule.szValue.substr(6)); - if (isNumber(X, true) && isNumber(Y, true)) { - CONFIGENTRY->vecValue = Vector2D(std::stof(X), std::stof(Y)); + if (!std::regex_search(title, RULECHECK)) + continue; + } else { + std::regex classCheck(rule.szValue); + + if (!std::regex_search(appidclass, classCheck)) + continue; } - } else { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">."; + } catch (...) { + Debug::log(ERR, "Regex error at {}", rule.szValue); + continue; } - } catch (...) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">."; - } - } else if (CONFIGENTRY->data.get() != nullptr) { + } else { + try { + if (rule.szClass != "") { + std::regex RULECHECK(rule.szClass); - switch (CONFIGENTRY->data->getDataType()) { - case CVD_TYPE_GRADIENT: { + if (!std::regex_search(appidclass, RULECHECK)) + continue; + } - CVarList varlist(VALUE, 0, ' '); + if (rule.szTitle != "") { + std::regex RULECHECK(rule.szTitle); - CGradientValueData* data = (CGradientValueData*)CONFIGENTRY->data.get(); - data->m_vColors.clear(); + if (!std::regex_search(title, RULECHECK)) + continue; + } - for (auto& var : varlist) { - if (var.find("deg") != std::string::npos) { - // last arg - try { - data->m_fAngle = std::stoi(var.substr(0, var.find("deg"))) * (PI / 180.0); // radians - } catch (...) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">."; - } + if (rule.szInitialTitle != "") { + std::regex RULECHECK(rule.szInitialTitle); - break; - } + if (!std::regex_search(pWindow->m_szInitialTitle, RULECHECK)) + continue; + } - if (data->m_vColors.size() >= 10) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. Max colors in a gradient is 10."; - break; - } + if (rule.szInitialClass != "") { + std::regex RULECHECK(rule.szInitialClass); - try { - data->m_vColors.push_back(CColor(configStringToInt(var))); - } catch (std::exception& e) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. " + e.what(); + if (!std::regex_search(pWindow->m_szInitialClass, RULECHECK)) + continue; + } + + if (rule.bX11 != -1) { + if (pWindow->m_bIsX11 != rule.bX11) + continue; + } + + if (rule.bFloating != -1) { + if (hasFloating != rule.bFloating) + continue; + } + + if (rule.bFullscreen != -1) { + if (hasFullscreen != rule.bFullscreen) + continue; + } + + if (rule.bPinned != -1) { + if (pWindow->m_bPinned != rule.bPinned) + continue; + } + + if (rule.bFocus != -1) { + if (rule.bFocus != (g_pCompositor->m_pLastWindow == pWindow)) + continue; + } + + if (rule.iOnWorkspace != -1) { + if (rule.iOnWorkspace != g_pCompositor->getWindowsOnWorkspace(pWindow->m_iWorkspaceID)) + continue; + } + + if (!rule.szWorkspace.empty()) { + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); + + if (!PWORKSPACE) + continue; + + if (rule.szWorkspace.starts_with("name:")) { + if (PWORKSPACE->m_szName != rule.szWorkspace.substr(5)) + continue; + } else { + // number + if (!isNumber(rule.szWorkspace)) + throw std::runtime_error("szWorkspace not name: or number"); + + const int64_t ID = std::stoll(rule.szWorkspace); + + if (PWORKSPACE->m_iID != ID) + continue; } } + } catch (std::exception& e) { + Debug::log(ERR, "Regex error at {} ({})", rule.szValue, e.what()); + continue; + } + } - if (data->m_vColors.size() == 0) { - Debug::log(WARN, "Error reading value of {}", COMMAND); - parseError = "Error setting value <" + VALUE + "> for field <" + COMMAND + ">. No colors provided."; + // applies. Read the rule and behave accordingly + Debug::log(LOG, "Window rule {} -> {} matched {}", rule.szRule, rule.szValue, pWindow); + + returns.push_back(rule); + + if (dynamic) + continue; + + if (rule.szRule == "float") + hasFloating = true; + else if (rule.szRule == "fullscreen") + hasFullscreen = true; + } + + std::vector<uint64_t> PIDs = {(uint64_t)pWindow->getPID()}; + while (getPPIDof(PIDs.back()) > 10) + PIDs.push_back(getPPIDof(PIDs.back())); + + bool anyExecFound = false; + + for (auto& er : execRequestedRules) { + if (std::ranges::any_of(PIDs, [&](const auto& pid) { return pid == er.iPid; })) { + returns.push_back({er.szRule, "execRule"}); + anyExecFound = true; + } + } + + if (anyExecFound) // 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; }); })); + + return returns; +} + +std::vector<SLayerRule> CConfigManager::getMatchingRules(SLayerSurface* pLS) { + std::vector<SLayerRule> returns; + + if (!pLS->layerSurface || pLS->fadingOut) + return returns; + + for (auto& lr : m_dLayerRules) { + if (lr.targetNamespace.starts_with("address:0x")) { + if (std::format("address:0x{:x}", (uintptr_t)pLS) != lr.targetNamespace) + continue; + } else { + std::regex NSCHECK(lr.targetNamespace); + + if (!pLS->layerSurface->_namespace || !std::regex_search(pLS->layerSurface->_namespace, NSCHECK)) + continue; + } + + // hit + returns.push_back(lr); + } + + if (pLS->layerSurface->_namespace && shouldBlurLS(pLS->layerSurface->_namespace)) + returns.push_back({pLS->layerSurface->_namespace, "blur"}); + + return returns; +} + +void CConfigManager::dispatchExecOnce() { + if (firstExecDispatched || isFirstLaunch) + return; - data->m_vColors.push_back(0); // transparent + // update dbus env + if (g_pCompositor->m_sWLRSession) + handleRawExec("", +#ifdef USES_SYSTEMD + "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP QT_QPA_PLATFORMTHEME && hash " + "dbus-update-activation-environment 2>/dev/null && " +#endif + "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP HYPRLAND_INSTANCE_SIGNATURE QT_QPA_PLATFORMTHEME"); + + firstExecDispatched = true; + + for (auto& c : firstExecRequests) { + handleRawExec("", c); + } + + firstExecRequests.clear(); // free some kb of memory :P + + // set input, fixes some certain issues + g_pInputManager->setKeyboardLayout(); + g_pInputManager->setPointerConfigs(); + g_pInputManager->setTouchDeviceConfigs(); + g_pInputManager->setTabletConfigs(); + + // check for user's possible errors with their setup and notify them if needed + g_pCompositor->performUserChecks(); +} + +void CConfigManager::performMonitorReload() { + + bool overAgain = false; + + for (auto& m : g_pCompositor->m_vRealMonitors) { + if (!m->output || m->isUnsafeFallback) + continue; + + auto rule = getMonitorRuleFor(m->szName, m->szDescription); + + if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule)) { + overAgain = true; + break; + } + + // ensure mirror + m->setMirror(rule.mirrorOf); + + g_pHyprRenderer->arrangeLayersForMonitor(m->ID); + } + + if (overAgain) + performMonitorReload(); + + m_bWantsMonitorReload = false; + + EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr); +} + +void* const* CConfigManager::getConfigValuePtr(const std::string& val) { + const auto VAL = m_pConfig->getConfigValuePtr(val.c_str()); + if (!VAL) + return nullptr; + return VAL->getDataStaticPtr(); +} + +Hyprlang::CConfigValue* CConfigManager::getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat) { + if (!specialCat.empty()) + return m_pConfig->getSpecialConfigValuePtr(specialCat.c_str(), name.c_str(), nullptr); + + return m_pConfig->getConfigValuePtr(name.c_str()); +} + +bool CConfigManager::deviceConfigExists(const std::string& dev) { + auto copy = dev; + std::replace(copy.begin(), copy.end(), ' ', '-'); + + return m_pConfig->specialCategoryExistsForKey("device", copy.c_str()); +} + +bool CConfigManager::shouldBlurLS(const std::string& ns) { + for (auto& bls : m_dBlurLSNamespaces) { + if (bls == ns) { + return true; + } + } + + return false; +} + +void CConfigManager::ensureMonitorStatus() { + for (auto& rm : g_pCompositor->m_vRealMonitors) { + if (!rm->output || rm->isUnsafeFallback) + continue; + + auto rule = getMonitorRuleFor(rm->szName, rm->szDescription); + + if (rule.disabled == rm->m_bEnabled) + g_pHyprRenderer->applyMonitorRule(rm.get(), &rule); + } +} + +void CConfigManager::ensureVRR(CMonitor* pMonitor) { + static auto* const PVRR = reinterpret_cast<Hyprlang::INT* const*>(getConfigValuePtr("misc:vrr")); + + static auto ensureVRRForDisplay = [&](CMonitor* m) -> void { + if (!m->output || m->createdByUser) + return; + + const auto USEVRR = m->activeMonitorRule.vrr.has_value() ? m->activeMonitorRule.vrr.value() : **PVRR; + + if (USEVRR == 0) { + if (m->vrrActive) { + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); + + if (!m->state.commit()) + Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> false", m->output->name); + } + m->vrrActive = false; + return; + } else if (USEVRR == 1) { + if (!m->vrrActive) { + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 1); + + if (!m->state.test()) { + Debug::log(LOG, "Pending output {} does not accept VRR.", m->output->name); + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); } - break; + if (!m->state.commit()) + Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> true", m->output->name); } - default: { - UNREACHABLE(); + m->vrrActive = true; + return; + } else if (USEVRR == 2) { + /* fullscreen */ + m->vrrActive = true; + + const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m->activeWorkspace); + + if (!PWORKSPACE) + return; // ??? + + const auto WORKSPACEFULL = PWORKSPACE->m_bHasFullscreenWindow && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL; + + if (WORKSPACEFULL && m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED) { + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 1); + + if (!m->state.test()) { + Debug::log(LOG, "Pending output {} does not accept VRR.", m->output->name); + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); + } + + if (!m->state.commit()) + Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> true", m->output->name); + + } else if (!WORKSPACEFULL && m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) { + wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); + + if (!m->state.commit()) + Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> false", m->output->name); } } + }; + + if (pMonitor) { + ensureVRRForDisplay(pMonitor); + return; + } + + for (auto& m : g_pCompositor->m_vMonitors) { + ensureVRRForDisplay(m.get()); + } +} + +SAnimationPropertyConfig* CConfigManager::getAnimationPropertyConfig(const std::string& name) { + return &animationConfig[name]; +} + +void CConfigManager::addParseError(const std::string& err) { + g_pHyprError->queueCreate(err + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); +} + +CMonitor* CConfigManager::getBoundMonitorForWS(const std::string& wsname) { + auto monitor = getBoundMonitorStringForWS(wsname); + if (monitor.substr(0, 5) == "desc:") + return g_pCompositor->getMonitorFromDesc(monitor.substr(5)); + else + return g_pCompositor->getMonitorFromName(monitor); +} + +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) { + return wr.monitor; + } } - if (COMMAND == "decoration:screen_shader" && VALUE != STRVAL_EMPTY) { - const auto PATH = absolutePath(VALUE, configCurrentPath); + return ""; +} - configPaths.push_back(PATH); +const std::deque<SWorkspaceRule>& CConfigManager::getAllWorkspaceRules() { + return m_dWorkspaceRules; +} - struct stat fileStat; - int err = stat(PATH.c_str(), &fileStat); - if (err != 0) { - Debug::log(WARN, "Error at ticking config at {}, error {}: {}", PATH, err, strerror(err)); - return; +void CConfigManager::addExecRule(const SExecRequestedRule& rule) { + execRequestedRules.push_back(rule); +} + +void CConfigManager::handlePluginLoads() { + if (g_pPluginSystem == nullptr) + return; + + bool pluginsChanged = false; + auto failedPlugins = g_pPluginSystem->updateConfigPlugins(m_vDeclaredPlugins, pluginsChanged); + + if (!failedPlugins.empty()) { + std::stringstream error; + error << "Failed to load the following plugins:"; + + for (auto path : failedPlugins) { + error << "\n" << path; } - configModifyTimes[PATH] = fileStat.st_mtime; + g_pHyprError->queueCreate(error.str(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); + } + + if (pluginsChanged) { + g_pHyprError->destroy(); + m_bForceReload = true; + tick(); } } -void CConfigManager::handleRawExec(const std::string& command, const std::string& args) { - // Exec in the background dont wait for it. +ICustomConfigValueData::~ICustomConfigValueData() { + ; // empty +} + +std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAnimationConfig() { + return animationConfig; +} + +void onPluginLoadUnload(const std::string& name, bool load) { + // +} + +void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) { + if (!name.starts_with("plugin:")) + return; + + std::string field = name.substr(7); + + m_pConfig->addSpecialConfigValue("plugin", field.c_str(), value); + pluginVariables.push_back({handle, field}); +} + +void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) { + pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn}); + m_pConfig->registerHandler(fn, name.c_str(), opts); +} + +void CConfigManager::removePluginConfig(HANDLE handle) { + for (auto& k : pluginKeywords) { + if (k.handle != handle) + continue; + + m_pConfig->unregisterHandler(k.name.c_str()); + } + + std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; }); + for (auto& [h, n] : pluginVariables) { + if (h != handle) + continue; + + m_pConfig->removeSpecialConfigValue("plugin", n.c_str()); + } + std::erase_if(pluginVariables, [handle](const auto& other) { return other.handle == handle; }); +} + +std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) { + for (auto other = m_dWorkspaceRules.begin(); other != m_dWorkspaceRules.end(); ++other) { + if (other->isDefault) { + if (other->monitor == name) + return other->workspaceString; + if (other->monitor.substr(0, 5) == "desc:") { + auto monitor = g_pCompositor->getMonitorFromDesc(other->monitor.substr(5)); + if (monitor && monitor->szName == name) + return other->workspaceString; + } + } + } + return ""; +} + +std::optional<std::string> CConfigManager::handleRawExec(const std::string& command, const std::string& args) { + if (isFirstLaunch) { + firstExecRequests.push_back(args); + return {}; + } + g_pKeybindManager->spawn(args); + return {}; +} + +std::optional<std::string> CConfigManager::handleExecOnce(const std::string& command, const std::string& args) { + if (isFirstLaunch) + firstExecRequests.push_back(args); + + return {}; } static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { @@ -627,7 +1476,7 @@ static bool parseModeLine(const std::string& modeline, drmModeModeInfo& mode) { return true; } -void CConfigManager::handleMonitor(const std::string& command, const std::string& args) { +std::optional<std::string> CConfigManager::handleMonitor(const std::string& command, const std::string& args) { // get the monitor config SMonitorRule newrule; @@ -643,8 +1492,7 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string const auto TSF = std::stoi(ARGS[2]); if (std::clamp(TSF, 0, 7) != TSF) { Debug::log(ERR, "invalid transform {} in monitor", TSF); - parseError = "invalid transform"; - return; + return "invalid transform"; } const auto TRANSFORM = (wl_output_transform)TSF; @@ -653,11 +1501,11 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string for (auto& r : m_dMonitorRules) { if (r.name == newrule.name) { r.transform = TRANSFORM; - return; + return {}; } } - return; + return {}; } else if (ARGS[1] == "addreserved") { int top = std::stoi(ARGS[2]); @@ -669,17 +1517,17 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string m_mAdditionalReservedAreas[newrule.name] = {top, bottom, left, right}; - return; // this is not a rule, ignore + return {}; } else { Debug::log(ERR, "ConfigManager parseMonitor, curitem bogus???"); - return; + return "parse error: curitem bogus"; } std::erase_if(m_dMonitorRules, [&](const auto& other) { return other.name == newrule.name; }); m_dMonitorRules.push_back(newrule); - return; + return {}; } if (ARGS[1].starts_with("pref")) { @@ -706,13 +1554,15 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string 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 (newrule.scale < 0.25f) { - parseError = "not a valid scale."; + error = "invalid scale"; newrule.scale = 1; } } @@ -746,8 +1596,7 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string argno++; } else { Debug::log(ERR, "Config error: invalid monitor syntax"); - parseError = "invalid syntax at \"" + ARGS[argno] + "\""; - return; + return "invalid syntax at \"" + ARGS[argno] + "\""; } argno++; @@ -756,33 +1605,39 @@ void CConfigManager::handleMonitor(const std::string& command, const std::string std::erase_if(m_dMonitorRules, [&](const auto& other) { return other.name == newrule.name; }); m_dMonitorRules.push_back(newrule); + + if (error.empty()) + return {}; + return error; } -void CConfigManager::handleBezier(const std::string& command, const std::string& args) { +std::optional<std::string> CConfigManager::handleBezier(const std::string& command, const std::string& args) { const auto ARGS = CVarList(args); std::string bezierName = ARGS[0]; if (ARGS[1] == "") - parseError = "too few arguments"; + return "too few arguments"; float p1x = std::stof(ARGS[1]); if (ARGS[2] == "") - parseError = "too few arguments"; + return "too few arguments"; float p1y = std::stof(ARGS[2]); if (ARGS[3] == "") - parseError = "too few arguments"; + return "too few arguments"; float p2x = std::stof(ARGS[3]); if (ARGS[4] == "") - parseError = "too few arguments"; + return "too few arguments"; float p2y = std::stof(ARGS[4]); if (ARGS[5] != "") - parseError = "too many arguments"; + return "too many arguments"; g_pAnimationManager->addBezierWithName(bezierName, Vector2D(p1x, p1y), Vector2D(p2x, p2y)); + + return {}; } void CConfigManager::setAnimForChildren(SAnimationPropertyConfig* const ANIM) { @@ -796,7 +1651,7 @@ void CConfigManager::setAnimForChildren(SAnimationPropertyConfig* const ANIM) { } }; -void CConfigManager::handleAnimation(const std::string& command, const std::string& args) { +std::optional<std::string> CConfigManager::handleAnimation(const std::string& command, const std::string& args) { const auto ARGS = CVarList(args); // Master on/off @@ -806,10 +1661,8 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri const auto PANIM = animationConfig.find(ANIMNAME); - if (PANIM == animationConfig.end()) { - parseError = "no such animation"; - return; - } + if (PANIM == animationConfig.end()) + return "no such animation"; PANIM->second.overridden = true; PANIM->second.pValues = &PANIM->second; @@ -817,9 +1670,8 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri // on/off PANIM->second.internalEnabled = ARGS[1] == "1"; - if (ARGS[1] != "0" && ARGS[1] != "1") { - parseError = "invalid animation on/off state"; - } + if (ARGS[1] != "0" && ARGS[1] != "1") + return "invalid animation on/off state"; if (PANIM->second.internalEnabled) { // speed @@ -827,20 +1679,20 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri PANIM->second.internalSpeed = std::stof(ARGS[2]); if (PANIM->second.internalSpeed <= 0) { - parseError = "invalid speed"; PANIM->second.internalSpeed = 1.f; + return "invalid speed"; } } else { PANIM->second.internalSpeed = 10.f; - parseError = "invalid speed"; + return "invalid speed"; } // curve PANIM->second.internalBezier = ARGS[3]; if (!g_pAnimationManager->bezierExists(ARGS[3])) { - parseError = "no such bezier"; PANIM->second.internalBezier = "default"; + return "no such bezier"; } // style @@ -850,15 +1702,17 @@ void CConfigManager::handleAnimation(const std::string& command, const std::stri const auto ERR = g_pAnimationManager->styleValidInConfigVar(ANIMNAME, ARGS[4]); if (ERR != "") - parseError = ERR; + return ERR; } } // now, check for children, recursively setAnimForChildren(&PANIM->second); + + return {}; } -void CConfigManager::handleBind(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleBind(const std::string& command, const std::string& value) { // example: // bind[fl]=SUPER,G,exec,dmenu_run <args> @@ -888,30 +1742,22 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v } else if (arg == 'i') { ignoreMods = true; } else { - parseError = "bind: invalid flag"; - return; + return "bind: invalid flag"; } } - if (release && repeat) { - parseError = "flags r and e are mutually exclusive"; - return; - } + if (release && repeat) + return "flags r and e are mutually exclusive"; - if (mouse && (repeat || release || locked)) { - parseError = "flag m is exclusive"; - return; - } + if (mouse && (repeat || release || locked)) + return "flag m is exclusive"; const auto ARGS = CVarList(value, 4); - if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse)) { - parseError = "bind: too few args"; - return; - } else if ((ARGS.size() > 4 && !mouse) || (ARGS.size() > 3 && mouse)) { - parseError = "bind: too many args"; - return; - } + if ((ARGS.size() < 3 && !mouse) || (ARGS.size() < 3 && mouse)) + return "bind: too few args"; + else if ((ARGS.size() > 4 && !mouse) || (ARGS.size() > 3 && mouse)) + return "bind: too many args"; const auto MOD = g_pKeybindManager->stringToModMask(ARGS[0]); const auto MODSTR = ARGS[0]; @@ -932,14 +1778,12 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v if (DISPATCHER == g_pKeybindManager->m_mDispatchers.end()) { Debug::log(ERR, "Invalid dispatcher!"); - parseError = "Invalid dispatcher, requested \"" + HANDLER + "\" does not exist"; - return; + return "Invalid dispatcher, requested \"" + HANDLER + "\" does not exist"; } if (MOD == 0 && MODSTR != "") { Debug::log(ERR, "Invalid mod!"); - parseError = "Invalid mod, requested mod \"" + MODSTR + "\" is not a valid mod."; - return; + return "Invalid mod, requested mod \"" + MODSTR + "\" is not a valid mod."; } if (KEY != "") { @@ -952,9 +1796,11 @@ void CConfigManager::handleBind(const std::string& command, const std::string& v else g_pKeybindManager->addKeybind(SKeybind{KEY, 0, MOD, HANDLER, COMMAND, locked, m_szCurrentSubmap, release, repeat, mouse, nonConsuming, transparent, ignoreMods}); } + + return {}; } -void CConfigManager::handleUnbind(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleUnbind(const std::string& command, const std::string& value) { const auto ARGS = CVarList(value); const auto MOD = g_pKeybindManager->stringToModMask(ARGS[0]); @@ -962,6 +1808,8 @@ void CConfigManager::handleUnbind(const std::string& command, const std::string& const auto KEY = ARGS[1]; g_pKeybindManager->removeKeybind(MOD, KEY); + + return {}; } bool windowRuleValid(const std::string& RULE) { @@ -978,50 +1826,49 @@ bool layerRuleValid(const std::string& RULE) { return RULE == "noanim" || RULE == "blur" || RULE.starts_with("ignorealpha") || RULE.starts_with("ignorezero") || RULE.starts_with("xray"); } -void CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleWindowRule(const std::string& command, const std::string& value) { const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); // check rule and value - if (RULE == "" || VALUE == "") { - return; - } + if (RULE == "" || VALUE == "") + return "empty rule?"; if (RULE == "unset") { std::erase_if(m_dWindowRules, [&](const SWindowRule& other) { return other.szValue == VALUE; }); - return; + return {}; } // verify we support a rule if (!windowRuleValid(RULE)) { Debug::log(ERR, "Invalid rule found: {}", RULE); - parseError = "Invalid rule found: " + RULE; - return; + return "Invalid rule: " + RULE; } if (RULE.starts_with("size") || RULE.starts_with("maxsize") || RULE.starts_with("minsize")) m_dWindowRules.push_front({RULE, VALUE}); else m_dWindowRules.push_back({RULE, VALUE}); + + return {}; } -void CConfigManager::handleLayerRule(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleLayerRule(const std::string& command, const std::string& value) { const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); const auto VALUE = removeBeginEndSpacesTabs(value.substr(value.find_first_of(',') + 1)); // check rule and value if (RULE == "" || VALUE == "") - return; + return "empty rule?"; if (RULE == "unset") { std::erase_if(m_dLayerRules, [&](const SLayerRule& other) { return other.targetNamespace == VALUE; }); - return; + return {}; } if (!layerRuleValid(RULE)) { Debug::log(ERR, "Invalid rule found: {}", RULE); - parseError = "Invalid rule found: " + RULE; - return; + return "Invalid rule found: " + RULE; } m_dLayerRules.push_back({VALUE, RULE}); @@ -1030,16 +1877,17 @@ void CConfigManager::handleLayerRule(const std::string& command, const std::stri for (auto& lsl : m->m_aLayerSurfaceLayers) for (auto& ls : lsl) ls->applyRules(); + + return {}; } -void CConfigManager::handleWindowRuleV2(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleWindowRuleV2(const std::string& command, const std::string& value) { const auto RULE = removeBeginEndSpacesTabs(value.substr(0, value.find_first_of(','))); const auto VALUE = value.substr(value.find_first_of(',') + 1); if (!windowRuleValid(RULE) && RULE != "unset") { Debug::log(ERR, "Invalid rulev2 found: {}", RULE); - parseError = "Invalid rulev2 found: " + RULE; - return; + return "Invalid rulev2 found: " + RULE; } // now we estract shit from the value @@ -1074,8 +1922,7 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s X11POS == std::string::npos && FLOATPOS == std::string::npos && FULLSCREENPOS == std::string::npos && PINNEDPOS == std::string::npos && WORKSPACEPOS == std::string::npos && FOCUSPOS == std::string::npos && ONWORKSPACEPOS == std::string::npos) { Debug::log(ERR, "Invalid rulev2 syntax: {}", VALUE); - parseError = "Invalid rulev2 syntax: " + VALUE; - return; + return "Invalid rulev2 syntax: " + VALUE; } auto extract = [&](size_t pos) -> std::string { @@ -1190,13 +2037,15 @@ void CConfigManager::handleWindowRuleV2(const std::string& command, const std::s return true; } }); - return; + return {}; } if (RULE.starts_with("size") || RULE.starts_with("maxsize") || RULE.starts_with("minsize")) m_dWindowRules.push_front(rule); else m_dWindowRules.push_back(rule); + + return {}; } void CConfigManager::updateBlurredLS(const std::string& name, const bool forceBlur) { @@ -1220,19 +2069,21 @@ void CConfigManager::updateBlurredLS(const std::string& name, const bool forceBl } } -void CConfigManager::handleBlurLS(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleBlurLS(const std::string& command, const std::string& value) { if (value.starts_with("remove,")) { const auto TOREMOVE = removeBeginEndSpacesTabs(value.substr(7)); if (std::erase_if(m_dBlurLSNamespaces, [&](const auto& other) { return other == TOREMOVE; })) updateBlurredLS(TOREMOVE, false); - return; + return {}; } m_dBlurLSNamespaces.emplace_back(value); updateBlurredLS(value, true); + + return {}; } -void CConfigManager::handleWorkspaceRules(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleWorkspaceRules(const std::string& command, const std::string& value) { // This can either be the monitor or the workspace identifier const auto FIRST_DELIM = value.find_first_of(','); @@ -1251,8 +2102,7 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: id = getWorkspaceIDFromString(wsIdent, name); if (id == WORKSPACE_INVALID) { Debug::log(ERR, "Invalid workspace identifier found: {}", wsIdent); - parseError = "Invalid workspace identifier found: " + wsIdent; - return; + return "Invalid workspace identifier found: " + wsIdent; } wsRule.monitor = first_ident; wsRule.workspaceString = wsIdent; @@ -1263,7 +2113,7 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: const static std::string ruleOnCreatedEmtpy = "on-created-empty:"; const static int ruleOnCreatedEmtpyLen = ruleOnCreatedEmtpy.length(); - auto assignRule = [&](std::string rule) { + auto assignRule = [&](std::string rule) -> std::optional<std::string> { size_t delim = std::string::npos; if ((delim = rule.find("gapsin:")) != std::string::npos) wsRule.gapsIn = std::stoi(rule.substr(delim + 7)); @@ -1292,8 +2142,7 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: if (!opt.contains(":")) { // invalid Debug::log(ERR, "Invalid workspace rule found: {}", rule); - parseError = "Invalid workspace rule found: " + rule; - return; + return "Invalid workspace rule found: " + rule; } std::string val = opt.substr(opt.find(":") + 1); @@ -1301,16 +2150,16 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: wsRule.layoutopts[opt] = val; } + + return {}; }; - size_t pos = 0; - std::string rule; - while ((pos = rules.find(',')) != std::string::npos) { - rule = rules.substr(0, pos); - assignRule(rule); - rules.erase(0, pos + 1); + CVarList rulesList{rules, 0, ',', true}; + for (auto& r : rulesList) { + const auto R = assignRule(r); + if (R.has_value()) + return R; } - assignRule(rules); // match remaining rule wsRule.workspaceId = id; wsRule.workspaceName = name; @@ -1321,28 +2170,31 @@ void CConfigManager::handleWorkspaceRules(const std::string& command, const std: m_dWorkspaceRules.emplace_back(wsRule); else *IT = wsRule; + + return {}; } -void CConfigManager::handleSubmap(const std::string& command, const std::string& submap) { +std::optional<std::string> CConfigManager::handleSubmap(const std::string& command, const std::string& submap) { if (submap == "reset") m_szCurrentSubmap = ""; else m_szCurrentSubmap = submap; + + return {}; } -void CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { +std::optional<std::string> CConfigManager::handleSource(const std::string& command, const std::string& rawpath) { if (rawpath.length() < 2) { Debug::log(ERR, "source= path garbage"); - parseError = "source path " + rawpath + " bogus!"; - return; + return "source path " + rawpath + " bogus!"; } std::unique_ptr<glob_t, void (*)(glob_t*)> glob_buf{new glob_t, [](glob_t* g) { globfree(g); }}; memset(glob_buf.get(), 0, sizeof(glob_t)); if (auto r = glob(absolutePath(rawpath, configCurrentPath).c_str(), GLOB_TILDE, nullptr, glob_buf.get()); r != 0) { - parseError = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory"); - Debug::log(ERR, "{}", parseError); - return; + std::string err = std::format("source= globbing error: {}", r == GLOB_NOMATCH ? "found no match" : GLOB_ABORTED ? "read error" : "out of memory"); + Debug::log(ERR, "{}", err); + return err; } for (size_t i = 0; i < glob_buf->gl_pathc; i++) { @@ -1355,8 +2207,7 @@ void CConfigManager::handleSource(const std::string& command, const std::string& } Debug::log(ERR, "source= file doesnt exist"); - parseError = "source file " + value + " doesn't exist!"; - return; + return "source file " + value + " doesn't exist!"; } configPaths.push_back(value); @@ -1364,59 +2215,29 @@ void CConfigManager::handleSource(const std::string& command, const std::string& int err = stat(value.c_str(), &fileStat); if (err != 0) { Debug::log(WARN, "Error at ticking config at {}, error {}: {}", value, err, strerror(err)); - return; + return {}; } - configModifyTimes[value] = fileStat.st_mtime; - - std::ifstream ifs; - ifs.open(value); - - std::string line = ""; - int linenum = 1; - if (ifs.is_open()) { - auto configCurrentPathBackup = configCurrentPath; + configModifyTimes[value] = fileStat.st_mtime; + auto configCurrentPathBackup = configCurrentPath; + configCurrentPath = value; - while (std::getline(ifs, line)) { - // Read line by line. - try { - configCurrentPath = value; - parseLine(line); - } catch (...) { - Debug::log(ERR, "Error reading line from config. Line:"); - Debug::log(NONE, "{}", line.c_str()); + m_pConfig->parseFile(value.c_str()); - parseError += "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): Line parsing error."; - } - - if (parseError != "" && !parseError.starts_with("Config error at line")) { - parseError = "Config error at line " + std::to_string(linenum) + " (" + configCurrentPath + "): " + parseError; - } - - ++linenum; - } - - ifs.close(); - - configCurrentPath = configCurrentPathBackup; - } + configCurrentPath = configCurrentPathBackup; } -} -void CConfigManager::handleBindWS(const std::string& command, const std::string& value) { - parseError = "bindws has been deprecated in favor of workspace rules, see the wiki -> workspace rules"; + return {}; } -void CConfigManager::handleEnv(const std::string& command, const std::string& value) { +std::optional<std::string> CConfigManager::handleEnv(const std::string& command, const std::string& value) { if (!isFirstLaunch) - return; + return {}; const auto ARGS = CVarList(value, 2); - if (ARGS[0].empty()) { - parseError = "env empty"; - return; - } + if (ARGS[0].empty()) + return "env empty"; setenv(ARGS[0].c_str(), ARGS[1].c_str(), 1); @@ -1431,1068 +2252,15 @@ void CConfigManager::handleEnv(const std::string& command, const std::string& va ARGS[0]; handleRawExec("", CMD); } -} - -void CConfigManager::handlePlugin(const std::string& command, const std::string& path) { - if (std::find(m_vDeclaredPlugins.begin(), m_vDeclaredPlugins.end(), path) != m_vDeclaredPlugins.end()) { - parseError = "plugin '" + path + "' declared twice"; - return; - } - - m_vDeclaredPlugins.push_back(path); -} - -std::string CConfigManager::parseKeyword(const std::string& COMMAND, const std::string& VALUE, bool dynamic) { - if (dynamic) { - parseError = ""; - currentCategory = ""; - } - - int needsLayoutRecalc = COMMAND == "monitor"; // 0 - no, 1 - yes, 2 - maybe - - if (COMMAND == "exec") { - if (isFirstLaunch) { - firstExecRequests.push_back(VALUE); - } else { - handleRawExec(COMMAND, VALUE); - } - } else if (COMMAND == "exec-once") { - if (isFirstLaunch) { - firstExecRequests.push_back(VALUE); - } - } else if (COMMAND == "monitor") - handleMonitor(COMMAND, VALUE); - else if (COMMAND.starts_with("bind")) - handleBind(COMMAND, VALUE); - else if (COMMAND == "unbind") - handleUnbind(COMMAND, VALUE); - else if (COMMAND == "workspace") - handleWorkspaceRules(COMMAND, VALUE); - else if (COMMAND == "windowrule") - handleWindowRule(COMMAND, VALUE); - else if (COMMAND == "windowrulev2") - handleWindowRuleV2(COMMAND, VALUE); - else if (COMMAND == "layerrule") - handleLayerRule(COMMAND, VALUE); - else if (COMMAND == "bezier") - handleBezier(COMMAND, VALUE); - else if (COMMAND == "animation") - handleAnimation(COMMAND, VALUE); - else if (COMMAND == "source") - handleSource(COMMAND, VALUE); - else if (COMMAND == "submap") - handleSubmap(COMMAND, VALUE); - else if (COMMAND == "blurls") - handleBlurLS(COMMAND, VALUE); - else if (COMMAND == "wsbind") - handleBindWS(COMMAND, VALUE); - else if (COMMAND == "plugin") - handlePlugin(COMMAND, VALUE); - else if (COMMAND.starts_with("env")) - handleEnv(COMMAND, VALUE); - else { - // try config - const auto IT = std::find_if(pluginKeywords.begin(), pluginKeywords.end(), [&](const auto& other) { return other.name == COMMAND; }); - - if (IT != pluginKeywords.end()) { - IT->fn(COMMAND, VALUE); - } else { - configSetValueSafe(currentCategory + (currentCategory == "" ? "" : ":") + COMMAND, VALUE); - needsLayoutRecalc = 2; - } - } - - if (dynamic) { - std::string retval = parseError; - parseError = ""; - - // invalidate layouts if they changed - if (needsLayoutRecalc) { - if (needsLayoutRecalc == 1 || COMMAND.contains("gaps_") || COMMAND.starts_with("dwindle:") || COMMAND.starts_with("master:")) { - for (auto& m : g_pCompositor->m_vMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); - } - } - - // Update window border colors - g_pCompositor->updateAllWindowsAnimatedDecorationValues(); - - // manual crash - if (configValues["debug:manual_crash"].intValue && !m_bManualCrashInitiated) { - m_bManualCrashInitiated = true; - if (g_pHyprNotificationOverlay) { - g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, - ICON_INFO); - } - } else if (m_bManualCrashInitiated && !configValues["debug:manual_crash"].intValue) { - // cowabunga it is - g_pHyprRenderer->initiateManualCrash(); - } - - return retval; - } - - return parseError; -} - -void CConfigManager::applyUserDefinedVars(std::string& line, const size_t equalsPlace) { - auto dollarPlace = line.find_first_of('$', equalsPlace); - - int times = 0; - - while (dollarPlace != std::string::npos) { - times++; - - const auto STRAFTERDOLLAR = line.substr(dollarPlace + 1); - bool found = false; - for (auto& [var, value] : configDynamicVars) { - if (STRAFTERDOLLAR.starts_with(var)) { - line.replace(dollarPlace, var.length() + 1, value); - found = true; - break; - } - } - - if (!found) { - // maybe env? - for (auto& [var, value] : environmentVariables) { - if (STRAFTERDOLLAR.starts_with(var)) { - line.replace(dollarPlace, var.length() + 1, value); - break; - } - } - } - - dollarPlace = line.find_first_of('$', dollarPlace + 1); - - if (times > 256 /* arbitrary limit */) { - line = ""; - parseError = "Maximum variable recursion limit hit. Evaluating the line led to too many variable substitutions."; - Debug::log(ERR, "Variable recursion limit hit in configmanager"); - break; - } - } -} - -void CConfigManager::parseLine(std::string& line) { - // first check if its not a comment - if (line[0] == '#') - return; - - // now, cut the comment off. ## is an escape. - for (long unsigned int i = 1; i < line.length(); ++i) { - if (line[i] == '#') { - if (i + 1 < line.length() && line[i + 1] != '#') { - line = line.substr(0, i); - break; // no need to parse more - } - - i++; - } - } - - size_t startPos = 0; - while ((startPos = line.find("##", startPos)) != std::string::npos && startPos < line.length() - 1 && startPos > 0) { - line.replace(startPos, 2, "#"); - startPos++; - } - - line = removeBeginEndSpacesTabs(line); - - if (line.contains(" {")) { - auto cat = line.substr(0, line.find(" {")); - transform(cat.begin(), cat.end(), cat.begin(), ::tolower); - std::replace(cat.begin(), cat.end(), ' ', '-'); - if (currentCategory.length() != 0) { - currentCategory.push_back(':'); - currentCategory.append(cat); - } else { - currentCategory = cat; - } - - return; - } - - if (line.contains("}") && currentCategory != "") { - - const auto LASTSEP = currentCategory.find_last_of(':'); - - if (LASTSEP == std::string::npos || currentCategory.starts_with("device")) - currentCategory = ""; - else - currentCategory = currentCategory.substr(0, LASTSEP); - - return; - } - - // And parse - // check if command - const auto EQUALSPLACE = line.find_first_of('='); - - // apply vars - applyUserDefinedVars(line, EQUALSPLACE); - - if (EQUALSPLACE == std::string::npos) - return; - - const auto COMMAND = removeBeginEndSpacesTabs(line.substr(0, EQUALSPLACE)); - const auto VALUE = removeBeginEndSpacesTabs(line.substr(EQUALSPLACE + 1)); - // - - parseKeyword(COMMAND, VALUE); -} - -void CConfigManager::loadConfigLoadVars() { - EMIT_HOOK_EVENT("preConfigReload", nullptr); - - Debug::log(LOG, "Reloading the config!"); - parseError = ""; // reset the error - currentCategory = ""; // reset the category - - // reset all vars before loading - setDefaultVars(); - m_dMonitorRules.clear(); - m_dWindowRules.clear(); - g_pKeybindManager->clearKeybinds(); - g_pAnimationManager->removeAllBeziers(); - m_mAdditionalReservedAreas.clear(); - configDynamicVars.clear(); - deviceConfigs.clear(); - m_dBlurLSNamespaces.clear(); - m_dWorkspaceRules.clear(); - setDefaultAnimationVars(); // reset anims - m_vDeclaredPlugins.clear(); - m_dLayerRules.clear(); - m_vFailedPluginConfigValues.clear(); - - // paths - configPaths.clear(); - std::string mainConfigPath = getMainConfigPath(); - Debug::log(LOG, "Using config: {}", mainConfigPath); - configPaths.push_back(mainConfigPath); - - if (g_pCompositor->explicitConfigPath.empty() && !std::filesystem::exists(mainConfigPath)) { - std::string configPath = std::filesystem::path(mainConfigPath).parent_path(); - - if (!std::filesystem::is_directory(configPath)) { - Debug::log(WARN, "Creating config home directory"); - try { - std::filesystem::create_directories(configPath); - } catch (...) { - parseError = "Broken config file! (Could not create config directory)"; - return; - } - } - - Debug::log(WARN, "No config file found; attempting to generate."); - std::ofstream ofs; - ofs.open(mainConfigPath, std::ios::trunc); - ofs << AUTOCONFIG; - ofs.close(); - } - - std::ifstream ifs; - ifs.open(mainConfigPath); - - if (!ifs.good()) { - ifs.close(); - - if (!g_pCompositor->explicitConfigPath.empty()) { - Debug::log(WARN, "Config reading error!"); - parseError = "Broken config file! (Could not read)"; - return; - } - - Debug::log(WARN, "Config reading error. Attempting to generate, backing up old one if exists"); - - if (std::filesystem::exists(mainConfigPath)) - std::filesystem::rename(mainConfigPath, mainConfigPath + ".backup"); - - // Create default config - std::ofstream ofs; - ofs.open(mainConfigPath, std::ios::trunc); - ofs << AUTOCONFIG; - ofs.close(); - - // Try to re-open - ifs.open(mainConfigPath); - if (!ifs.good()) { - parseError = "Broken config file! (Could not open)"; - return; - } - } - - std::string line = ""; - int linenum = 1; - if (ifs.is_open()) { - while (std::getline(ifs, line)) { - // Read line by line. - try { - configCurrentPath = mainConfigPath; - parseLine(line); - } catch (...) { - Debug::log(ERR, "Error reading line from config. Line:"); - Debug::log(NONE, "{}", line); - - parseError += "Config error at line " + std::to_string(linenum) + " (" + mainConfigPath + "): Line parsing error."; - } - - if (parseError != "" && !parseError.starts_with("Config error at line")) { - parseError = "Config error at line " + std::to_string(linenum) + " (" + mainConfigPath + "): " + parseError; - } - - ++linenum; - } - - ifs.close(); - } - - for (auto& w : g_pCompositor->m_vWindows) { - w->uncacheWindowDecos(); - } - - for (auto& m : g_pCompositor->m_vMonitors) - g_pLayoutManager->getCurrentLayout()->recalculateMonitor(m->ID); - - // Update the keyboard layout to the cfg'd one if this is not the first launch - if (!isFirstLaunch) { - g_pInputManager->setKeyboardLayout(); - g_pInputManager->setPointerConfigs(); - g_pInputManager->setTouchDeviceConfigs(); - g_pInputManager->setTabletConfigs(); - } - - if (!isFirstLaunch) - g_pHyprOpenGL->m_bReloadScreenShader = true; - - // parseError will be displayed next frame - if (parseError != "" && !configValues["debug:suppress_errors"].intValue) - g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); - else if (configValues["autogenerated"].intValue == 1) - g_pHyprError->queueCreate("Warning: You're using an autogenerated config! (config file: " + mainConfigPath + " )\nSUPER+Q -> kitty\nSUPER+M -> exit Hyprland", - CColor(1.0, 1.0, 70.0 / 255.0, 1.0)); - else - g_pHyprError->destroy(); - - // Set the modes for all monitors as we configured them - // not on first launch because monitors might not exist yet - // and they'll be taken care of in the newMonitor event - // ignore if nomonitorreload is set - if (!isFirstLaunch && !m_bNoMonitorReload) { - // check - performMonitorReload(); - ensureMonitorStatus(); - ensureVRR(); - } - - if (!isFirstLaunch && !g_pCompositor->m_bUnsafeState) - refreshGroupBarGradients(); - - // Updates dynamic window and workspace rules - for (auto& w : g_pCompositor->m_vWindows) { - if (!w->m_bIsMapped) - continue; - - w->updateDynamicRules(); - w->updateSpecialRenderData(); - } - - // Update window border colors - g_pCompositor->updateAllWindowsAnimatedDecorationValues(); - - // update layout - g_pLayoutManager->switchToLayout(configValues["general:layout"].strValue); - - // manual crash - if (configValues["debug:manual_crash"].intValue && !m_bManualCrashInitiated) { - m_bManualCrashInitiated = true; - g_pHyprNotificationOverlay->addNotification("Manual crash has been set up. Set debug:manual_crash back to 0 in order to crash the compositor.", CColor(0), 5000, ICON_INFO); - } else if (m_bManualCrashInitiated && !configValues["debug:manual_crash"].intValue) { - // cowabunga it is - g_pHyprRenderer->initiateManualCrash(); - } - - Debug::disableStdout = !configValues["debug:enable_stdout_logs"].intValue; - if (Debug::disableStdout && isFirstLaunch) - Debug::log(LOG, "Disabling stdout logs! Check the log for further logs."); - - for (auto& m : g_pCompositor->m_vMonitors) { - // mark blur dirty - g_pHyprOpenGL->markBlurDirtyForMonitor(m.get()); - - g_pCompositor->scheduleFrameForMonitor(m.get()); - - // Force the compositor to fully re-render all monitors - m->forceFullFrames = 2; - } - - // Reset no monitor reload - m_bNoMonitorReload = false; - - // update plugins - handlePluginLoads(); - - EMIT_HOOK_EVENT("configReloaded", nullptr); - if (g_pEventManager) - g_pEventManager->postEvent(SHyprIPCEvent{"configreloaded", ""}); -} - -void CConfigManager::tick() { - std::string CONFIGPATH = getMainConfigPath(); - if (!std::filesystem::exists(CONFIGPATH)) { - Debug::log(ERR, "Config doesn't exist??"); - return; - } - - bool parse = false; - - for (auto& cf : configPaths) { - struct stat fileStat; - int err = stat(cf.c_str(), &fileStat); - if (err != 0) { - Debug::log(WARN, "Error at ticking config at {}, error {}: {}", cf, err, strerror(err)); - continue; - } - - // check if we need to reload cfg - if (fileStat.st_mtime != configModifyTimes[cf] || m_bForceReload) { - parse = true; - configModifyTimes[cf] = fileStat.st_mtime; - } - } - - if (parse) { - m_bForceReload = false; - - loadConfigLoadVars(); - } -} - -std::mutex configmtx; -SConfigValue CConfigManager::getConfigValueSafe(const std::string& val) { - std::lock_guard<std::mutex> lg(configmtx); - - SConfigValue copy = configValues[val]; - - return copy; -} - -SConfigValue CConfigManager::getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback) { - std::lock_guard<std::mutex> lg(configmtx); - - const auto it = deviceConfigs.find(dev); - - if (it == deviceConfigs.end()) { - if (fallback.empty()) { - Debug::log(ERR, "getConfigValueSafeDevice: No device config for {} found???", dev); - return SConfigValue(); - } - return configValues[fallback]; - } - - const SConfigValue DEVICECONFIG = it->second[val]; - - if (!DEVICECONFIG.set && !fallback.empty()) { - return configValues[fallback]; - } - - return DEVICECONFIG; -} - -int CConfigManager::getInt(const std::string& v) { - return getConfigValueSafe(v).intValue; -} - -float CConfigManager::getFloat(const std::string& v) { - return getConfigValueSafe(v).floatValue; -} - -Vector2D CConfigManager::getVec(const std::string& v) { - return getConfigValueSafe(v).vecValue; -} - -std::string CConfigManager::getString(const std::string& v) { - auto VAL = getConfigValueSafe(v).strValue; - - if (VAL == STRVAL_EMPTY) - return ""; - - return VAL; -} - -int CConfigManager::getDeviceInt(const std::string& dev, const std::string& v, const std::string& fallback) { - return getConfigValueSafeDevice(dev, v, fallback).intValue; -} - -float CConfigManager::getDeviceFloat(const std::string& dev, const std::string& v, const std::string& fallback) { - return getConfigValueSafeDevice(dev, v, fallback).floatValue; -} - -Vector2D CConfigManager::getDeviceVec(const std::string& dev, const std::string& v, const std::string& fallback) { - return getConfigValueSafeDevice(dev, v, fallback).vecValue; -} - -std::string CConfigManager::getDeviceString(const std::string& dev, const std::string& v, const std::string& fallback) { - auto VAL = getConfigValueSafeDevice(dev, v, fallback).strValue; - - if (VAL == STRVAL_EMPTY) - return ""; - - return VAL; -} - -void CConfigManager::setInt(const std::string& v, int val) { - configValues[v].intValue = val; -} - -void CConfigManager::setFloat(const std::string& v, float val) { - configValues[v].floatValue = val; -} - -void CConfigManager::setVec(const std::string& v, Vector2D val) { - configValues[v].vecValue = val; -} - -void CConfigManager::setString(const std::string& v, const std::string& val) { - configValues[v].strValue = val; -} - -SMonitorRule CConfigManager::getMonitorRuleFor(const std::string& name, const std::string& displayName) { - SMonitorRule* found = nullptr; - - for (auto& r : m_dMonitorRules) { - if (r.name == name || - (r.name.starts_with("desc:") && - (r.name.substr(5) == displayName || r.name.substr(5) == removeBeginEndSpacesTabs(displayName.substr(0, displayName.find_first_of('(')))))) { - found = &r; - break; - } - } - - if (found) - return *found; - - Debug::log(WARN, "No rule found for {}, trying to use the first.", name); - - for (auto& r : m_dMonitorRules) { - if (r.name == "") { - found = &r; - break; - } - } - - if (found) - return *found; - - Debug::log(WARN, "No rules configured. Using the default hardcoded one."); - - 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 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 */ - }); - if (IT == m_dWorkspaceRules.end()) - return SWorkspaceRule{}; - return *IT; -} - -std::vector<SWindowRule> CConfigManager::getMatchingRules(CWindow* pWindow, bool dynamic) { - if (!g_pCompositor->windowValidMapped(pWindow)) - return std::vector<SWindowRule>(); - - std::vector<SWindowRule> returns; - - std::string title = g_pXWaylandManager->getTitle(pWindow); - std::string appidclass = g_pXWaylandManager->getAppIDClass(pWindow); - - Debug::log(LOG, "Searching for matching rules for {} (title: {})", appidclass, title); - - // since some rules will be applied later, we need to store some flags - bool hasFloating = pWindow->m_bIsFloating; - bool hasFullscreen = pWindow->m_bIsFullscreen; - - for (auto& rule : m_dWindowRules) { - // check if we have a matching rule - if (!rule.v2) { - try { - if (rule.szValue.starts_with("title:")) { - // we have a title rule. - std::regex RULECHECK(rule.szValue.substr(6)); - - if (!std::regex_search(title, RULECHECK)) - continue; - } else { - std::regex classCheck(rule.szValue); - - if (!std::regex_search(appidclass, classCheck)) - continue; - } - } catch (...) { - Debug::log(ERR, "Regex error at {}", rule.szValue); - continue; - } - } else { - try { - if (rule.szClass != "") { - std::regex RULECHECK(rule.szClass); - - if (!std::regex_search(appidclass, RULECHECK)) - continue; - } - - if (rule.szTitle != "") { - std::regex RULECHECK(rule.szTitle); - - if (!std::regex_search(title, RULECHECK)) - continue; - } - - if (rule.szInitialTitle != "") { - std::regex RULECHECK(rule.szInitialTitle); - - if (!std::regex_search(pWindow->m_szInitialTitle, RULECHECK)) - continue; - } - - if (rule.szInitialClass != "") { - std::regex RULECHECK(rule.szInitialClass); - - if (!std::regex_search(pWindow->m_szInitialClass, RULECHECK)) - continue; - } - - if (rule.bX11 != -1) { - if (pWindow->m_bIsX11 != rule.bX11) - continue; - } - - if (rule.bFloating != -1) { - if (hasFloating != rule.bFloating) - continue; - } - - if (rule.bFullscreen != -1) { - if (hasFullscreen != rule.bFullscreen) - continue; - } - - if (rule.bPinned != -1) { - if (pWindow->m_bPinned != rule.bPinned) - continue; - } - - if (rule.bFocus != -1) { - if (rule.bFocus != (g_pCompositor->m_pLastWindow == pWindow)) - continue; - } - - if (rule.iOnWorkspace != -1) { - if (rule.iOnWorkspace != g_pCompositor->getWindowsOnWorkspace(pWindow->m_iWorkspaceID)) - continue; - } - - if (!rule.szWorkspace.empty()) { - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); - - if (!PWORKSPACE) - continue; - - if (rule.szWorkspace.starts_with("name:")) { - if (PWORKSPACE->m_szName != rule.szWorkspace.substr(5)) - continue; - } else { - // number - if (!isNumber(rule.szWorkspace)) - throw std::runtime_error("szWorkspace not name: or number"); - - const int64_t ID = std::stoll(rule.szWorkspace); - - if (PWORKSPACE->m_iID != ID) - continue; - } - } - } catch (std::exception& e) { - Debug::log(ERR, "Regex error at {} ({})", rule.szValue, e.what()); - continue; - } - } - - // applies. Read the rule and behave accordingly - Debug::log(LOG, "Window rule {} -> {} matched {}", rule.szRule, rule.szValue, pWindow); - - returns.push_back(rule); - - if (dynamic) - continue; - - if (rule.szRule == "float") - hasFloating = true; - else if (rule.szRule == "fullscreen") - hasFullscreen = true; - } - - std::vector<uint64_t> PIDs = {(uint64_t)pWindow->getPID()}; - while (getPPIDof(PIDs.back()) > 10) - PIDs.push_back(getPPIDof(PIDs.back())); - - bool anyExecFound = false; - for (auto& er : execRequestedRules) { - if (std::ranges::any_of(PIDs, [&](const auto& pid) { return pid == er.iPid; })) { - returns.push_back({er.szRule, "execRule"}); - anyExecFound = true; - } - } - - if (anyExecFound) // 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; }); })); - - return returns; -} - -std::vector<SLayerRule> CConfigManager::getMatchingRules(SLayerSurface* pLS) { - std::vector<SLayerRule> returns; - - if (!pLS->layerSurface || pLS->fadingOut) - return returns; - - for (auto& lr : m_dLayerRules) { - if (lr.targetNamespace.starts_with("address:0x")) { - if (std::format("address:0x{:x}", (uintptr_t)pLS) != lr.targetNamespace) - continue; - } else { - std::regex NSCHECK(lr.targetNamespace); - - if (!pLS->layerSurface->_namespace || !std::regex_search(pLS->layerSurface->_namespace, NSCHECK)) - continue; - } - - // hit - returns.push_back(lr); - } - - if (pLS->layerSurface->_namespace && shouldBlurLS(pLS->layerSurface->_namespace)) - returns.push_back({pLS->layerSurface->_namespace, "blur"}); - - return returns; -} - -void CConfigManager::dispatchExecOnce() { - if (firstExecDispatched || isFirstLaunch) - return; - - // update dbus env - if (g_pCompositor->m_sWLRSession) - handleRawExec("", -#ifdef USES_SYSTEMD - "systemctl --user import-environment DISPLAY WAYLAND_DISPLAY HYPRLAND_INSTANCE_SIGNATURE XDG_CURRENT_DESKTOP QT_QPA_PLATFORMTHEME && hash " - "dbus-update-activation-environment 2>/dev/null && " -#endif - "dbus-update-activation-environment --systemd WAYLAND_DISPLAY XDG_CURRENT_DESKTOP HYPRLAND_INSTANCE_SIGNATURE QT_QPA_PLATFORMTHEME"); - - firstExecDispatched = true; - - for (auto& c : firstExecRequests) { - handleRawExec("", c); - } - - firstExecRequests.clear(); // free some kb of memory :P - - // set input, fixes some certain issues - g_pInputManager->setKeyboardLayout(); - g_pInputManager->setPointerConfigs(); - g_pInputManager->setTouchDeviceConfigs(); - g_pInputManager->setTabletConfigs(); - - // check for user's possible errors with their setup and notify them if needed - g_pCompositor->performUserChecks(); + return {}; } -void CConfigManager::performMonitorReload() { - - bool overAgain = false; - - for (auto& m : g_pCompositor->m_vRealMonitors) { - if (!m->output || m->isUnsafeFallback) - continue; - - auto rule = getMonitorRuleFor(m->szName, m->szDescription); - - if (!g_pHyprRenderer->applyMonitorRule(m.get(), &rule)) { - overAgain = true; - break; - } - - // ensure mirror - m->setMirror(rule.mirrorOf); - - g_pHyprRenderer->arrangeLayersForMonitor(m->ID); - } - - if (overAgain) - performMonitorReload(); - - m_bWantsMonitorReload = false; - - EMIT_HOOK_EVENT("monitorLayoutChanged", nullptr); -} - -SConfigValue* CConfigManager::getConfigValuePtr(const std::string& val) { - return &configValues[val]; -} - -SConfigValue* CConfigManager::getConfigValuePtrSafe(const std::string& val) { - if (val.starts_with("device:")) { - const auto DEVICE = val.substr(7, val.find_last_of(':') - 7); - const auto CONFIGVAR = val.substr(val.find_last_of(':') + 1); - - const auto DEVICECONF = deviceConfigs.find(DEVICE); - if (DEVICECONF == deviceConfigs.end()) - return nullptr; - - const auto IT = DEVICECONF->second.find(CONFIGVAR); - - if (IT == DEVICECONF->second.end()) - return nullptr; - - return &IT->second; - } else if (val.starts_with("plugin:")) { - for (auto& [pl, pMap] : pluginConfigs) { - const auto IT = pMap->find(val); - - if (IT != pMap->end()) - return &IT->second; - } +std::optional<std::string> CConfigManager::handlePlugin(const std::string& command, const std::string& path) { + if (std::find(m_vDeclaredPlugins.begin(), m_vDeclaredPlugins.end(), path) != m_vDeclaredPlugins.end()) + return "plugin '" + path + "' declared twice"; - return nullptr; - } - - const auto IT = configValues.find(val); - - if (IT == configValues.end()) - return nullptr; - - return &(IT->second); -} - -bool CConfigManager::deviceConfigExists(const std::string& dev) { - auto copy = dev; - std::replace(copy.begin(), copy.end(), ' ', '-'); - - return deviceConfigs.contains(copy); -} - -bool CConfigManager::shouldBlurLS(const std::string& ns) { - for (auto& bls : m_dBlurLSNamespaces) { - if (bls == ns) { - return true; - } - } - - return false; -} - -void CConfigManager::ensureMonitorStatus() { - for (auto& rm : g_pCompositor->m_vRealMonitors) { - if (!rm->output || rm->isUnsafeFallback) - continue; - - auto rule = getMonitorRuleFor(rm->szName, rm->szDescription); - - if (rule.disabled == rm->m_bEnabled) - g_pHyprRenderer->applyMonitorRule(rm.get(), &rule); - } -} - -void CConfigManager::ensureVRR(CMonitor* pMonitor) { - static auto* const PVRR = &getConfigValuePtr("misc:vrr")->intValue; - - static auto ensureVRRForDisplay = [&](CMonitor* m) -> void { - if (!m->output || m->createdByUser) - return; - - const auto USEVRR = m->activeMonitorRule.vrr.has_value() ? m->activeMonitorRule.vrr.value() : *PVRR; - - if (USEVRR == 0) { - if (m->vrrActive) { - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); - - if (!m->state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> false", m->output->name); - } - m->vrrActive = false; - return; - } else if (USEVRR == 1) { - if (!m->vrrActive) { - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 1); - - if (!m->state.test()) { - Debug::log(LOG, "Pending output {} does not accept VRR.", m->output->name); - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); - } - - if (!m->state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> true", m->output->name); - } - m->vrrActive = true; - return; - } else if (USEVRR == 2) { - /* fullscreen */ - m->vrrActive = true; - - const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(m->activeWorkspace); - - if (!PWORKSPACE) - return; // ??? - - const auto WORKSPACEFULL = PWORKSPACE->m_bHasFullscreenWindow && PWORKSPACE->m_efFullscreenMode == FULLSCREEN_FULL; - - if (WORKSPACEFULL && m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_DISABLED) { - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 1); - - if (!m->state.test()) { - Debug::log(LOG, "Pending output {} does not accept VRR.", m->output->name); - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); - } - - if (!m->state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> true", m->output->name); - - } else if (!WORKSPACEFULL && m->output->adaptive_sync_status == WLR_OUTPUT_ADAPTIVE_SYNC_ENABLED) { - wlr_output_state_set_adaptive_sync_enabled(m->state.wlr(), 0); - - if (!m->state.commit()) - Debug::log(ERR, "Couldn't commit output {} in ensureVRR -> false", m->output->name); - } - } - }; - - if (pMonitor) { - ensureVRRForDisplay(pMonitor); - return; - } - - for (auto& m : g_pCompositor->m_vMonitors) { - ensureVRRForDisplay(m.get()); - } -} - -SAnimationPropertyConfig* CConfigManager::getAnimationPropertyConfig(const std::string& name) { - return &animationConfig[name]; -} - -void CConfigManager::addParseError(const std::string& err) { - if (parseError == "") - parseError = err; - - g_pHyprError->queueCreate(parseError + "\nHyprland may not work correctly.", CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); -} - -CMonitor* CConfigManager::getBoundMonitorForWS(const std::string& wsname) { - auto monitor = getBoundMonitorStringForWS(wsname); - if (monitor.substr(0, 5) == "desc:") - return g_pCompositor->getMonitorFromDesc(monitor.substr(5)); - else - return g_pCompositor->getMonitorFromName(monitor); -} - -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) { - return wr.monitor; - } - } - - return ""; -} - -const std::deque<SWorkspaceRule>& CConfigManager::getAllWorkspaceRules() { - return m_dWorkspaceRules; -} - -void CConfigManager::addExecRule(const SExecRequestedRule& rule) { - execRequestedRules.push_back(rule); -} - -void CConfigManager::handlePluginLoads() { - if (g_pPluginSystem == nullptr) - return; - - bool pluginsChanged = false; - auto failedPlugins = g_pPluginSystem->updateConfigPlugins(m_vDeclaredPlugins, pluginsChanged); - - if (!failedPlugins.empty()) { - std::stringstream error; - error << "Failed to load the following plugins:"; - - for (auto path : failedPlugins) { - error << "\n" << path; - } - - g_pHyprError->queueCreate(error.str(), CColor(1.0, 50.0 / 255.0, 50.0 / 255.0, 1.0)); - } - - if (pluginsChanged) { - g_pHyprError->destroy(); - m_bForceReload = true; - tick(); - } -} - -ICustomConfigValueData::~ICustomConfigValueData() { - ; // empty -} - -std::unordered_map<std::string, SAnimationPropertyConfig> CConfigManager::getAnimationConfig() { - return animationConfig; -} - -void CConfigManager::addPluginConfigVar(HANDLE handle, const std::string& name, const SConfigValue& value) { - auto CONFIGMAPIT = std::find_if(pluginConfigs.begin(), pluginConfigs.end(), [&](const auto& other) { return other.first == handle; }); - - if (CONFIGMAPIT == pluginConfigs.end()) { - pluginConfigs.emplace( - std::pair<HANDLE, std::unique_ptr<std::unordered_map<std::string, SConfigValue>>>(handle, std::make_unique<std::unordered_map<std::string, SConfigValue>>())); - CONFIGMAPIT = std::find_if(pluginConfigs.begin(), pluginConfigs.end(), [&](const auto& other) { return other.first == handle; }); - } - - (*CONFIGMAPIT->second)[name] = value; - - if (const auto IT = std::find_if(m_vFailedPluginConfigValues.begin(), m_vFailedPluginConfigValues.end(), [&](const auto& other) { return other.first == name; }); - IT != m_vFailedPluginConfigValues.end()) { - configSetValueSafe(IT->first, IT->second); - } -} - -void CConfigManager::addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string&, const std::string&)> fn) { - pluginKeywords.emplace_back(SPluginKeyword{handle, name, fn}); -} - -void CConfigManager::removePluginConfig(HANDLE handle) { - std::erase_if(pluginConfigs, [&](const auto& other) { return other.first == handle; }); - std::erase_if(pluginKeywords, [&](const auto& other) { return other.handle == handle; }); -} + m_vDeclaredPlugins.push_back(path); -std::string CConfigManager::getDefaultWorkspaceFor(const std::string& name) { - for (auto other = m_dWorkspaceRules.begin(); other != m_dWorkspaceRules.end(); ++other) { - if (other->isDefault) { - if (other->monitor == name) - return other->workspaceString; - if (other->monitor.substr(0, 5) == "desc:") { - auto monitor = g_pCompositor->getMonitorFromDesc(other->monitor.substr(5)); - if (monitor && monitor->szName == name) - return other->workspaceString; - } - } - } - return ""; -} + return {}; +}
\ No newline at end of file diff --git a/src/config/ConfigManager.hpp b/src/config/ConfigManager.hpp index ecd781b7..8bf2f7be 100644 --- a/src/config/ConfigManager.hpp +++ b/src/config/ConfigManager.hpp @@ -21,21 +21,13 @@ #include "defaultConfig.hpp" #include "ConfigDataValues.hpp" +#include <hyprlang.hpp> + #define INITANIMCFG(name) animationConfig[name] = {} #define CREATEANIMCFG(name, parent) animationConfig[name] = {false, "", "", 0.f, -1, &animationConfig["global"], &animationConfig[parent]} #define HANDLE void* -struct SConfigValue { - int64_t intValue = -INT64_MAX; - float floatValue = -__FLT_MAX__; - std::string strValue = ""; - Vector2D vecValue = Vector2D(-__FLT_MAX__, -__FLT_MAX__); - std::shared_ptr<ICustomConfigValueData> data; - - bool set = false; // used for device configs -}; - struct SWorkspaceRule { std::string monitor = ""; std::string workspaceString = ""; @@ -74,9 +66,14 @@ struct SAnimationPropertyConfig { }; struct SPluginKeyword { - HANDLE handle = 0; - std::string name = ""; - std::function<void(const std::string&, const std::string&)> fn; + HANDLE handle = 0; + std::string name = ""; + Hyprlang::PCONFIGHANDLERFUNC fn = nullptr; +}; + +struct SPluginVariable { + HANDLE handle = 0; + std::string name = ""; }; struct SExecRequestedRule { @@ -91,24 +88,17 @@ class CConfigManager { void tick(); void init(); - int getInt(const std::string&); - float getFloat(const std::string&); - Vector2D getVec(const std::string&); - std::string getString(const std::string&); - void setFloat(const std::string&, float); - void setInt(const std::string&, int); - void setVec(const std::string&, Vector2D); - void setString(const std::string&, const std::string&); - int getDeviceInt(const std::string&, const std::string&, const std::string& fallback = ""); float getDeviceFloat(const std::string&, const std::string&, const std::string& fallback = ""); Vector2D getDeviceVec(const std::string&, const std::string&, const std::string& fallback = ""); std::string getDeviceString(const std::string&, const std::string&, const std::string& fallback = ""); bool deviceConfigExists(const std::string&); + Hyprlang::CConfigValue* getConfigValueSafeDevice(const std::string& dev, const std::string& val, const std::string& fallback); bool shouldBlurLS(const std::string&); - SConfigValue* getConfigValuePtr(const std::string&); - SConfigValue* getConfigValuePtrSafe(const std::string&); + void* const* getConfigValuePtr(const std::string&); + Hyprlang::CConfigValue* getHyprlangConfigValuePtr(const std::string& name, const std::string& specialCat = ""); + void onPluginLoadUnload(const std::string& name, bool load); static std::string getConfigDir(); static std::string getMainConfigPath(); @@ -127,8 +117,8 @@ class CConfigManager { std::unordered_map<std::string, SAnimationPropertyConfig> getAnimationConfig(); - void addPluginConfigVar(HANDLE handle, const std::string& name, const SConfigValue& value); - void addPluginKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& cmd, const std::string& val)> fun); + void addPluginConfigVar(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value); + void addPluginKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fun, Hyprlang::SHandlerOptions opts = {}); void removePluginConfig(HANDLE handle); // no-op when done. @@ -141,7 +131,7 @@ class CConfigManager { void ensureMonitorStatus(); void ensureVRR(CMonitor* pMonitor = nullptr); - std::string parseKeyword(const std::string&, const std::string&, bool dynamic = false); + std::string parseKeyword(const std::string&, const std::string&); void addParseError(const std::string&); @@ -151,77 +141,65 @@ class CConfigManager { void handlePluginLoads(); - std::string configCurrentPath; + // keywords + std::optional<std::string> handleRawExec(const std::string&, const std::string&); + std::optional<std::string> handleExecOnce(const std::string&, const std::string&); + std::optional<std::string> handleMonitor(const std::string&, const std::string&); + std::optional<std::string> handleBind(const std::string&, const std::string&); + std::optional<std::string> handleUnbind(const std::string&, const std::string&); + std::optional<std::string> handleWindowRule(const std::string&, const std::string&); + std::optional<std::string> handleLayerRule(const std::string&, const std::string&); + std::optional<std::string> handleWindowRuleV2(const std::string&, const std::string&); + std::optional<std::string> handleWorkspaceRules(const std::string&, const std::string&); + std::optional<std::string> handleBezier(const std::string&, const std::string&); + std::optional<std::string> handleAnimation(const std::string&, const std::string&); + std::optional<std::string> handleSource(const std::string&, const std::string&); + std::optional<std::string> handleSubmap(const std::string&, const std::string&); + std::optional<std::string> handleBlurLS(const std::string&, const std::string&); + std::optional<std::string> handleBindWS(const std::string&, const std::string&); + std::optional<std::string> handleEnv(const std::string&, const std::string&); + std::optional<std::string> handlePlugin(const std::string&, const std::string&); + + std::string configCurrentPath; private: - std::deque<std::string> configPaths; // stores all the config paths - std::unordered_map<std::string, time_t> configModifyTimes; // stores modify times - std::vector<std::pair<std::string, std::string>> configDynamicVars; // stores dynamic vars declared by the user - std::unordered_map<std::string, SConfigValue> configValues; - std::unordered_map<std::string, std::unordered_map<std::string, SConfigValue>> deviceConfigs; // stores device configs - - std::unordered_map<std::string, SAnimationPropertyConfig> animationConfig; // stores all the animations with their set values - - std::string currentCategory = ""; // For storing the category of the current item + std::unique_ptr<Hyprlang::CConfig> m_pConfig; - std::string parseError = ""; // For storing a parse error to display later + std::deque<std::string> configPaths; // stores all the config paths + std::unordered_map<std::string, time_t> configModifyTimes; // stores modify times - std::string m_szCurrentSubmap = ""; // For storing the current keybind submap + std::unordered_map<std::string, SAnimationPropertyConfig> animationConfig; // stores all the animations with their set values - std::vector<SExecRequestedRule> execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty + std::string m_szCurrentSubmap = ""; // For storing the current keybind submap - std::vector<std::string> m_vDeclaredPlugins; - std::unordered_map<HANDLE, std::unique_ptr<std::unordered_map<std::string, SConfigValue>>> pluginConfigs; // stores plugin configs - std::vector<SPluginKeyword> pluginKeywords; + std::vector<SExecRequestedRule> execRequestedRules; // rules requested with exec, e.g. [workspace 2] kitty - bool isFirstLaunch = true; // For exec-once + std::vector<std::string> m_vDeclaredPlugins; + std::vector<SPluginKeyword> pluginKeywords; + std::vector<SPluginVariable> pluginVariables; - std::deque<SMonitorRule> m_dMonitorRules; - std::deque<SWorkspaceRule> m_dWorkspaceRules; - std::deque<SWindowRule> m_dWindowRules; - std::deque<SLayerRule> m_dLayerRules; - std::deque<std::string> m_dBlurLSNamespaces; + bool isFirstLaunch = true; // For exec-once - bool firstExecDispatched = false; - bool m_bManualCrashInitiated = false; - std::deque<std::string> firstExecRequests; + std::deque<SMonitorRule> m_dMonitorRules; + std::deque<SWorkspaceRule> m_dWorkspaceRules; + std::deque<SWindowRule> m_dWindowRules; + std::deque<SLayerRule> m_dLayerRules; + std::deque<std::string> m_dBlurLSNamespaces; - std::vector<std::pair<std::string, std::string>> environmentVariables; + bool firstExecDispatched = false; + bool m_bManualCrashInitiated = false; + std::deque<std::string> firstExecRequests; - std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins + std::vector<std::pair<std::string, std::string>> m_vFailedPluginConfigValues; // for plugin values of unloaded plugins // internal methods - void setDefaultVars(); - void setDefaultAnimationVars(); - void setDeviceDefaultVars(const std::string&); - void populateEnvironment(); - - void setAnimForChildren(SAnimationPropertyConfig* const); - void updateBlurredLS(const std::string&, const bool); - - void applyUserDefinedVars(std::string&, const size_t); - void loadConfigLoadVars(); - SConfigValue getConfigValueSafe(const std::string&); - SConfigValue getConfigValueSafeDevice(const std::string&, const std::string&, const std::string& fallback = ""); - void parseLine(std::string&); - void configSetValueSafe(const std::string&, const std::string&); - void handleDeviceConfig(const std::string&, const std::string&); - void handleRawExec(const std::string&, const std::string&); - void handleMonitor(const std::string&, const std::string&); - void handleBind(const std::string&, const std::string&); - void handleUnbind(const std::string&, const std::string&); - void handleWindowRule(const std::string&, const std::string&); - void handleLayerRule(const std::string&, const std::string&); - void handleWindowRuleV2(const std::string&, const std::string&); - void handleWorkspaceRules(const std::string&, const std::string&); - void handleBezier(const std::string&, const std::string&); - void handleAnimation(const std::string&, const std::string&); - void handleSource(const std::string&, const std::string&); - void handleSubmap(const std::string&, const std::string&); - void handleBlurLS(const std::string&, const std::string&); - void handleBindWS(const std::string&, const std::string&); - void handleEnv(const std::string&, const std::string&); - void handlePlugin(const std::string&, const std::string&); + void setAnimForChildren(SAnimationPropertyConfig* const); + void updateBlurredLS(const std::string&, const bool); + void setDefaultAnimationVars(); + std::optional<std::string> resetHLConfig(); + std::optional<std::string> verifyConfigExists(); + void postConfigReload(const Hyprlang::CParseResult& result); + void reload(); }; inline std::unique_ptr<CConfigManager> g_pConfigManager; diff --git a/src/config/defaultConfig.hpp b/src/config/defaultConfig.hpp index 5eabf475..95e98e4f 100644 --- a/src/config/defaultConfig.hpp +++ b/src/config/defaultConfig.hpp @@ -4,9 +4,9 @@ inline const std::string AUTOCONFIG = R"#( ######################################################################################## -AUTOGENERATED HYPR CONFIG. -PLEASE USE THE CONFIG PROVIDED IN THE GIT REPO /examples/hypr.conf AND EDIT IT, -OR EDIT THIS ONE ACCORDING TO THE WIKI INSTRUCTIONS. +# AUTOGENERATED HYPR CONFIG. +# PLEASE USE THE CONFIG PROVIDED IN THE GIT REPO /examples/hypr.conf AND EDIT IT, +# OR EDIT THIS ONE ACCORDING TO THE WIKI INSTRUCTIONS. ######################################################################################## # diff --git a/src/debug/HyprCtl.cpp b/src/debug/HyprCtl.cpp index e805bca6..b0f70e98 100644 --- a/src/debug/HyprCtl.cpp +++ b/src/debug/HyprCtl.cpp @@ -14,6 +14,7 @@ #include <sstream> #include <string> +#include <typeindex> static void trimTrailingComma(std::string& str) { if (!str.empty() && str.back() == ',') @@ -856,7 +857,7 @@ std::string dispatchKeyword(eHyprCtlOutputFormat format, std::string in) { const auto VALUE = in.substr(in.find_first_of(' ') + 1); - std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE, true); + std::string retval = g_pConfigManager->parseKeyword(COMMAND, VALUE); if (COMMAND == "monitor") g_pConfigManager->m_bWantsMonitorReload = true; // for monitor keywords @@ -868,8 +869,10 @@ 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"); + if (COMMAND.contains("general:layout")) - g_pLayoutManager->switchToLayout(g_pConfigManager->getString("general:layout")); // update layout + g_pLayoutManager->switchToLayout(*PLAYOUT); // update layout if (COMMAND.contains("decoration:screen_shader")) g_pHyprOpenGL->m_bReloadScreenShader = true; @@ -1193,28 +1196,40 @@ std::string dispatchGetOption(eHyprCtlOutputFormat format, std::string request) nextItem(); nextItem(); - const auto PCFGOPT = g_pConfigManager->getConfigValuePtrSafe(curitem); + const auto VAR = g_pConfigManager->getHyprlangConfigValuePtr(curitem); - if (!PCFGOPT) + if (!VAR) return "no such option"; - if (format == eHyprCtlOutputFormat::FORMAT_NORMAL) - return std::format("option {}\n\tint: {}\n\tfloat: {:.5f}\n\tstr: \"{}\"\n\tdata: {:x}\n\tset: {}", curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue, - (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set); - else { - return std::format( - R"#( -{{ - "option": "{}", - "int": {}, - "float": {:.5f}, - "str": "{}", - "data": "0x{:x}", - "set": {} -}} -)#", - curitem, PCFGOPT->intValue, PCFGOPT->floatValue, PCFGOPT->strValue, (uintptr_t)PCFGOPT->data.get(), PCFGOPT->set); + const auto VAL = VAR->getValue(); + const auto TYPE = std::type_index(VAL.type()); + + if (format == FORMAT_NORMAL) { + if (TYPE == typeid(Hyprlang::INT)) + return std::format("int: {}\nset: {}", std::any_cast<Hyprlang::INT>(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::FLOAT)) + return std::format("float: {:2f}\nset: {}", std::any_cast<Hyprlang::FLOAT>(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::VEC2)) + return std::format("vec2: [{}, {}]\nset: {}", std::any_cast<Hyprlang::VEC2>(VAL).x, std::any_cast<Hyprlang::VEC2>(VAL).y, VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::STRING)) + return std::format("str: {}\nset: {}", std::any_cast<Hyprlang::STRING>(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) + return std::format("custom type at: {:x}\nset: {}", (uintptr_t)std::any_cast<Hyprlang::CUSTOMTYPE*>(VAL), VAR->m_bSetByUser); + } else { + if (TYPE == typeid(Hyprlang::INT)) + return std::format("{{\"option\": \"{}\", \"int\": {}, \"set\": {} }}", curitem, std::any_cast<Hyprlang::INT>(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::FLOAT)) + return std::format("{{\"option\": \"{}\", \"float\": {:2f}, \"set\": {} }}", curitem, std::any_cast<Hyprlang::FLOAT>(VAL), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::VEC2)) + return std::format("{{\"option\": \"{}\", \"vec2\": [{},{}], \"set\": {} }}", curitem, std::any_cast<Hyprlang::VEC2>(VAL).x, std::any_cast<Hyprlang::VEC2>(VAL).y, + VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::STRING)) + return std::format("{{\"option\": \"{}\", \"str\": \"{}\", \"set\": {} }}", curitem, escapeJSONStrings(std::any_cast<Hyprlang::STRING>(VAL)), VAR->m_bSetByUser); + else if (TYPE == typeid(Hyprlang::CUSTOMTYPE*)) + return std::format("{{\"option\": \"{}\", \"custom\": \"{:x}\", \"set\": {} }}", curitem, (uintptr_t)std::any_cast<Hyprlang::CUSTOMTYPE*>(VAL), VAR->m_bSetByUser); } + + return "invalid type (internal error)"; } std::string decorationRequest(eHyprCtlOutputFormat format, std::string request) { diff --git a/src/debug/Log.cpp b/src/debug/Log.cpp index 404904a2..66c430d5 100644 --- a/src/debug/Log.cpp +++ b/src/debug/Log.cpp @@ -22,7 +22,7 @@ void Debug::wlrLog(wlr_log_importance level, const char* fmt, va_list args) { rollingLog += output + "\n"; - if (!disableLogs || !*disableLogs) { + if (!disableLogs || !**disableLogs) { std::ofstream ofs; ofs.open(logFile, std::ios::out | std::ios::app); ofs << "[wlr] " << output << "\n"; diff --git a/src/debug/Log.hpp b/src/debug/Log.hpp index 3d2ed48c..a43d6fee 100644 --- a/src/debug/Log.hpp +++ b/src/debug/Log.hpp @@ -21,16 +21,16 @@ enum LogLevel { }; namespace Debug { - inline std::string logFile; - inline int64_t* disableLogs = nullptr; - inline int64_t* disableTime = nullptr; - inline bool disableStdout = false; - inline bool trace = false; - inline bool shuttingDown = false; + inline std::string logFile; + inline int64_t* const* disableLogs = nullptr; + inline int64_t* const* disableTime = nullptr; + inline bool disableStdout = false; + inline bool trace = false; + inline bool shuttingDown = false; - inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log + inline std::string rollingLog = ""; // rolling log contains the ROLLING_LOG_SIZE tail of the log - void init(const std::string& IS); + void init(const std::string& IS); template <typename... Args> void log(LogLevel level, std::format_string<Args...> fmt, Args&&... args) { if (level == TRACE && !trace) @@ -52,7 +52,7 @@ namespace Debug { } // print date and time to the ofs - if (disableTime && !*disableTime) { + if (disableTime && !**disableTime) { #ifndef _LIBCPP_VERSION logMsg += std::format("[{:%T}] ", std::chrono::hh_mm_ss{std::chrono::system_clock::now() - std::chrono::floor<std::chrono::days>(std::chrono::system_clock::now())}); #else @@ -73,7 +73,7 @@ namespace Debug { if (rollingLog.size() > ROLLING_LOG_SIZE) rollingLog = rollingLog.substr(rollingLog.size() - ROLLING_LOG_SIZE); - if (!disableLogs || !*disableLogs) { + if (!disableLogs || !**disableLogs) { // log to a file std::ofstream ofs; ofs.open(logFile, std::ios::out | std::ios::app); diff --git a/src/events/Monitors.cpp b/src/events/Monitors.cpp index f54c2d37..01ea24f8 100644 --- a/src/events/Monitors.cpp +++ b/src/events/Monitors.cpp @@ -147,12 +147,12 @@ void Events::listener_monitorFrame(void* owner, void* data) { PMONITOR->tearingState.frameScheduledWhileBusy = false; } - static auto* const PENABLERAT = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_of_time")->intValue; - static auto* const PRATSAFE = &g_pConfigManager->getConfigValuePtr("misc:render_ahead_safezone")->intValue; + 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"); PMONITOR->lastPresentationTimer.reset(); - if (*PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) { + if (**PENABLERAT && !PMONITOR->tearingState.nextRenderTorn) { if (!PMONITOR->RATScheduled) { // render g_pHyprRenderer->renderMonitor(PMONITOR); @@ -162,14 +162,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 36f82cd8..ea45ad48 100644 --- a/src/events/Windows.cpp +++ b/src/events/Windows.cpp @@ -40,13 +40,13 @@ void setAnimToMove(void* data) { void Events::listener_mapWindow(void* owner, void* data) { CWindow* PWINDOW = (CWindow*)owner; - static auto* const PINACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:inactive_opacity")->floatValue; - static auto* const PACTIVEALPHA = &g_pConfigManager->getConfigValuePtr("decoration:active_opacity")->floatValue; - static auto* const PDIMSTRENGTH = &g_pConfigManager->getConfigValuePtr("decoration:dim_strength")->floatValue; - static auto* const PSWALLOW = &g_pConfigManager->getConfigValuePtr("misc:enable_swallow")->intValue; - static auto* const PSWALLOWREGEX = &g_pConfigManager->getConfigValuePtr("misc:swallow_regex")->strValue; - static auto* const PSWALLOWEXREGEX = &g_pConfigManager->getConfigValuePtr("misc:swallow_exception_regex")->strValue; - static auto* const PNEWTAKESOVERFS = &g_pConfigManager->getConfigValuePtr("misc:new_window_takes_over_fullscreen")->intValue; + 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"); auto PMONITOR = g_pCompositor->m_pLastMonitor; const auto PWORKSPACE = @@ -464,9 +464,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; @@ -478,10 +478,10 @@ void Events::listener_mapWindow(void* owner, void* data) { (PWINDOW->m_iX11Type != 2 || (PWINDOW->m_bIsX11 && wlr_xwayland_or_surface_wants_focus(PWINDOW->m_uSurface.xwayland))) && !workspaceSilent && (!PFORCEFOCUS || PFORCEFOCUS == PWINDOW)) { 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); } @@ -550,7 +550,7 @@ void Events::listener_mapWindow(void* owner, void* data) { } // verify swallowing - if (*PSWALLOW && *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)) { @@ -597,7 +597,7 @@ void Events::listener_mapWindow(void* owner, void* data) { if (finalFound) { bool valid = std::regex_match(g_pXWaylandManager->getAppIDClass(finalFound), rgx); - if (*PSWALLOWEXREGEX != STRVAL_EMPTY) { + if (std::string{*PSWALLOWEXREGEX} != STRVAL_EMPTY) { std::regex exc(*PSWALLOWEXREGEX); valid = valid && !std::regex_match(g_pXWaylandManager->getTitle(finalFound), exc); @@ -969,7 +969,7 @@ 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; - static auto* const PFOCUSONACTIVATE = &g_pConfigManager->getConfigValuePtr("misc:focus_on_activate")->intValue; + static auto* const PFOCUSONACTIVATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:focus_on_activate"); Debug::log(LOG, "Activate request for surface at {:x}", (uintptr_t)E->surface); @@ -986,7 +986,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) @@ -999,7 +999,7 @@ void Events::listener_activateXDG(wl_listener* listener, void* data) { void Events::listener_activateX11(void* owner, void* data) { const auto PWINDOW = (CWindow*)owner; - static auto* const PFOCUSONACTIVATE = &g_pConfigManager->getConfigValuePtr("misc:focus_on_activate")->intValue; + static auto* const PFOCUSONACTIVATE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:focus_on_activate"); Debug::log(LOG, "X11 Activate request for window {}", PWINDOW); @@ -1023,7 +1023,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) @@ -1064,8 +1064,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 = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; - if (*PXWLFORCESCALEZERO) { + 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); } @@ -1115,7 +1115,7 @@ void Events::listener_unmanagedSetGeometry(void* owner, void* data) { return; } - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); const auto LOGICALPOS = g_pXWaylandManager->xwaylandToWaylandCoords({PWINDOW->m_uSurface.xwayland->x, PWINDOW->m_uSurface.xwayland->y}); @@ -1130,7 +1130,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.goalv() - PWINDOW->m_vRealSize.goalv() / PMONITOR->scale; PWINDOW->m_vRealSize.setValueAndWarp(PWINDOW->m_vRealSize.goalv() / PMONITOR->scale); diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp index 97bdf59a..db385902 100644 --- a/src/helpers/Monitor.cpp +++ b/src/helpers/Monitor.cpp @@ -316,8 +316,8 @@ void CMonitor::onDisconnect(bool destroy) { } void CMonitor::addDamage(const pixman_region32_t* rg) { - static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue; - if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { + static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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)) @@ -329,8 +329,8 @@ void CMonitor::addDamage(const CRegion* rg) { } void CMonitor::addDamage(const CBox* box) { - static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue; - if (*PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { + static auto* const PZOOMFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor"); + if (**PZOOMFACTOR != 1.f && g_pCompositor->getMonitorFromCursor() == this) { wlr_damage_ring_add_whole(&damage); g_pCompositor->scheduleFrameForMonitor(this); } @@ -541,11 +541,11 @@ void CMonitor::changeWorkspace(CWorkspace* const pWorkspace, bool internal, bool } if (!noFocus && !g_pCompositor->m_pLastMonitor->specialWorkspaceID) { - static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; + static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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/SubsurfaceTree.cpp b/src/helpers/SubsurfaceTree.cpp index a8226e19..b4ea6d85 100644 --- a/src/helpers/SubsurfaceTree.cpp +++ b/src/helpers/SubsurfaceTree.cpp @@ -225,8 +225,8 @@ void Events::listener_commitSubsurface(void* owner, void* data) { 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 = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; - if (*PLOGDAMAGE) + 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; } diff --git a/src/helpers/Vector2D.cpp b/src/helpers/Vector2D.cpp index 4cd3476b..c74da0b1 100644 --- a/src/helpers/Vector2D.cpp +++ b/src/helpers/Vector2D.cpp @@ -12,6 +12,11 @@ Vector2D::Vector2D() { y = 0; } +Vector2D::Vector2D(const Hyprlang::VEC2& ref) { + x = ref.x; + y = ref.y; +} + Vector2D::~Vector2D() {} double Vector2D::normalize() { diff --git a/src/helpers/Vector2D.hpp b/src/helpers/Vector2D.hpp index 44eae3f3..309ed3bc 100644 --- a/src/helpers/Vector2D.hpp +++ b/src/helpers/Vector2D.hpp @@ -3,12 +3,14 @@ #include <cmath> #include <format> #include "../macros.hpp" +#include <hyprlang.hpp> class Vector2D { public: Vector2D(double, double); Vector2D(); ~Vector2D(); + Vector2D(const Hyprlang::VEC2&); double x = 0; double y = 0; diff --git a/src/helpers/Watchdog.cpp b/src/helpers/Watchdog.cpp index 2a26ee29..ce4d2707 100644 --- a/src/helpers/Watchdog.cpp +++ b/src/helpers/Watchdog.cpp @@ -13,7 +13,7 @@ CWatchdog::CWatchdog() { m_iMainThreadPID = pthread_self(); m_pWatchdog = std::make_unique<std::thread>([this] { - static auto* const PTIMEOUT = &g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout")->intValue; + static auto* const PTIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout"); while (1337) { std::unique_lock lk(m_mWatchdogMutex); @@ -21,7 +21,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 +37,9 @@ CWatchdog::CWatchdog() { } void CWatchdog::startWatching() { - static auto* const PTIMEOUT = &g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout")->intValue; + static auto* const PTIMEOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:watchdog_timeout"); - if (*PTIMEOUT == 0) + if (**PTIMEOUT == 0) return; m_tTriggered = std::chrono::high_resolution_clock::now(); diff --git a/src/helpers/Workspace.cpp b/src/helpers/Workspace.cpp index 213607d0..53d028d5 100644 --- a/src/helpers/Workspace.cpp +++ b/src/helpers/Workspace.cpp @@ -38,8 +38,8 @@ CWorkspace::~CWorkspace() { } void CWorkspace::startAnim(bool in, bool left, bool instant) { - const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; - const auto PWORKSPACEGAP = &g_pConfigManager->getConfigValuePtr("general:gaps_workspaces")->intValue; + const auto ANIMSTYLE = m_fAlpha.m_pConfig->pValues->internalStyle; + static auto* const PWORKSPACEGAP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_workspaces"); if (ANIMSTYLE.starts_with("slidefade")) { const auto PMONITOR = g_pCompositor->getMonitorFromID(m_iMonitorID); @@ -91,7 +91,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. @@ -104,7 +104,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/layout/DwindleLayout.cpp b/src/layout/DwindleLayout.cpp index 9db011d1..5bdf8748 100644 --- a/src/layout/DwindleLayout.cpp +++ b/src/layout/DwindleLayout.cpp @@ -4,13 +4,12 @@ void SDwindleNodeData::recalcSizePosRecursive(bool force, bool horizontalOverride, bool verticalOverride) { if (children[0]) { - static auto* const PSMARTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:smart_split")->intValue; - static auto* const PPRESERVESPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:preserve_split")->intValue; - static auto* const PFLMULT = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue; + 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"); - 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; @@ -135,12 +134,12 @@ void CHyprDwindleLayout::applyNodeDataToWindow(SDwindleNodeData* pNode, bool for PWINDOW->updateSpecialRenderData(); - static auto* const PGAPSIN = &g_pConfigManager->getConfigValuePtr("general:gaps_in")->intValue; - static auto* const PGAPSOUT = &g_pConfigManager->getConfigValuePtr("general:gaps_out")->intValue; - static auto* const PNOGAPSWHENONLY = &g_pConfigManager->getConfigValuePtr("dwindle:no_gaps_when_only")->intValue; + static auto* const PGAPSIN = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_in"); + static auto* const PGAPSOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_out"); + static auto* const PNOGAPSWHENONLY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("dwindle:no_gaps_when_only"); - 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->windowExists(PWINDOW) || !PWINDOW->m_bIsMapped) { Debug::log(ERR, "Node {} holding invalid {}!!", pNode, PWINDOW); @@ -156,10 +155,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; @@ -216,9 +215,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 = &g_pConfigManager->getConfigValuePtr("dwindle:special_scale_factor")->floatValue; + static auto* const PSCALEFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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(); @@ -256,8 +255,8 @@ void CHyprDwindleLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection dire const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); - static auto* const PUSEACTIVE = &g_pConfigManager->getConfigValuePtr("dwindle:use_active_for_splits")->intValue; - static auto* const PDEFAULTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:default_split_ratio")->floatValue; + 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"); if (direction != DIRECTION_DEFAULT && overrideDirection == DIRECTION_DEFAULT) overrideDirection = direction; @@ -274,13 +273,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); @@ -342,8 +341,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 = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue; - (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); + static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); + (**USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); OPENINGON->pWindow->setGroupCurrent(pWindow); pWindow->applyGroupRules(); @@ -366,17 +365,17 @@ 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 = &g_pConfigManager->getConfigValuePtr("dwindle:split_width_multiplier")->floatValue; + const auto PWIDTHMULTIPLIER = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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 = &g_pConfigManager->getConfigValuePtr("dwindle:force_split")->intValue; - static auto* const PERMANENTDIRECTIONOVERRIDE = &g_pConfigManager->getConfigValuePtr("dwindle:permanent_direction_override")->intValue; - static auto* const PSMARTSPLIT = &g_pConfigManager->getConfigValuePtr("dwindle:smart_split")->intValue; + 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"); bool horizontalOverride = false; bool verticalOverride = false; @@ -400,9 +399,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; @@ -433,11 +432,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; @@ -447,7 +446,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 { @@ -466,7 +465,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)}; @@ -610,8 +609,8 @@ void CHyprDwindleLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorn return; } - const auto PANIMATE = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; - const auto PSMARTRESIZING = &g_pConfigManager->getConfigValuePtr("dwindle:smart_resizing")->intValue; + 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"); // get some data about our window const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); @@ -654,7 +653,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; } @@ -668,7 +667,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; @@ -702,14 +701,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) { @@ -717,14 +716,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 @@ -743,11 +742,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; @@ -762,11 +761,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; @@ -781,8 +780,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); } } diff --git a/src/layout/IHyprLayout.cpp b/src/layout/IHyprLayout.cpp index ee692178..49e20435 100644 --- a/src/layout/IHyprLayout.cpp +++ b/src/layout/IHyprLayout.cpp @@ -87,7 +87,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { desiredGeometry.y = xy.y; } - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); if (!PMONITOR) { Debug::log(ERR, "{:m} has an invalid monitor in onWindowCreatedFloating!!!", pWindow); @@ -151,7 +151,7 @@ void IHyprLayout::onWindowCreatedFloating(CWindow* pWindow) { } } - if (*PXWLFORCESCALEZERO && pWindow->m_bIsX11) + if (**PXWLFORCESCALEZERO && pWindow->m_bIsX11) pWindow->m_vRealSize = pWindow->m_vRealSize.goalv() / PMONITOR->scale; if (pWindow->m_bX11DoesntWantBorders || (pWindow->m_bIsX11 && pWindow->m_uSurface.xwayland->override_redirect)) { @@ -275,8 +275,8 @@ void IHyprLayout::onEndDragWindow() { return; if (pWindow->m_sGroupData.pNextWindow && DRAGGINGWINDOW->canBeGroupedInto(pWindow)) { - static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue; - (*USECURRPOS ? pWindow : pWindow->getGroupTail())->insertWindowToGroup(DRAGGINGWINDOW); + static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); + (**USECURRPOS ? pWindow : pWindow->getGroupTail())->insertWindowToGroup(DRAGGINGWINDOW); pWindow->setGroupCurrent(DRAGGINGWINDOW); DRAGGINGWINDOW->updateWindowDecos(); @@ -309,8 +309,8 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { 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 = &g_pConfigManager->getConfigValuePtr("misc:animate_mouse_windowdragging")->intValue; - static auto* const PANIMATE = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; + 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"); if ((abs(TICKDELTA.x) < 1.f && abs(TICKDELTA.y) < 1.f) || (std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now() - TIMER).count() < @@ -328,7 +328,7 @@ void IHyprLayout::onMouseMove(const Vector2D& mousePos) { CBox wb = {m_vBeginDragPositionXY + DELTA, DRAGGINGWINDOW->m_vRealSize.goalv()}; wb.round(); - if (*PANIMATEMOUSE) + if (**PANIMATEMOUSE) DRAGGINGWINDOW->m_vRealPosition = wb.pos(); else DRAGGINGWINDOW->m_vRealPosition.setValueAndWarp(wb.pos()); @@ -386,7 +386,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 c27e7e9e..2f09396b 100644 --- a/src/layout/MasterLayout.cpp +++ b/src/layout/MasterLayout.cpp @@ -39,11 +39,11 @@ 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 = &g_pConfigManager->getConfigValuePtr("master:orientation")->strValue; - const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts; - auto orientationForWs = *orientation; + const auto PWORKSPACEDATA = &m_lMasterWorkspacesData.emplace_back(); + PWORKSPACEDATA->workspaceID = ws; + const auto orientation = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("master:orientation"); + const auto layoutoptsForWs = g_pConfigManager->getWorkspaceRuleFor(g_pCompositor->getWorkspaceByID(ws)).layoutopts; + std::string orientationForWs = *orientation; if (layoutoptsForWs.contains("orientation")) orientationForWs = layoutoptsForWs.at("orientation"); @@ -80,20 +80,20 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc if (pWindow->m_bIsFloating) return; - static auto* const PNEWTOP = &g_pConfigManager->getConfigValuePtr("master:new_on_top")->intValue; + static auto* const PNEWTOP = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_on_top"); 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 = &g_pConfigManager->getConfigValuePtr("master:new_is_master")->intValue; + static auto* const PNEWISMASTER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:new_is_master"); const auto WINDOWSONWORKSPACE = getNodesOnWorkspace(PNODE->workspaceID); - static auto* const PMFACT = &g_pConfigManager->getConfigValuePtr("master:mfact")->floatValue; - float lastSplitPercent = *PMFACT; + static auto* const PMFACT = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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) : @@ -112,8 +112,8 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc m_lMasterNodesData.remove(*PNODE); - static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue; - (*USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); + static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); + (**USECURRPOS ? OPENINGON->pWindow : OPENINGON->pWindow->getGroupTail())->insertWindowToGroup(pWindow); OPENINGON->pWindow->setGroupCurrent(pWindow); pWindow->applyGroupRules(); @@ -128,14 +128,14 @@ void CHyprMasterLayout::onWindowCreatedTiling(CWindow* pWindow, eDirection direc pWindow->applyGroupRules(); - static auto* const PDROPATCURSOR = &g_pConfigManager->getConfigValuePtr("master:drop_at_cursor")->intValue; + 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); 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) @@ -191,7 +191,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) { @@ -239,14 +239,14 @@ void CHyprMasterLayout::onWindowRemovedTiling(CWindow* pWindow) { const auto WORKSPACEID = PNODE->workspaceID; const auto MASTERSLEFT = getMastersOnWorkspace(WORKSPACEID); - static const auto* SMALLSPLIT = &g_pConfigManager->getConfigValuePtr("master:allow_small_split")->intValue; + static const auto* SMALLSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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) { @@ -338,8 +338,8 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { eOrientation orientation = PWORKSPACEDATA->orientation; bool centerMasterWindow = false; - static auto* const ALWAYSCENTER = &g_pConfigManager->getConfigValuePtr("master:always_center_master")->intValue; - static auto* const PSMARTRESIZING = &g_pConfigManager->getConfigValuePtr("master:smart_resizing")->intValue; + 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 MASTERS = getMastersOnWorkspace(PWORKSPACE->m_iID); const auto WINDOWS = getNodesOnWorkspace(PWORKSPACE->m_iID); @@ -348,7 +348,7 @@ void CHyprMasterLayout::calculateWorkspace(const int& ws) { 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; @@ -361,7 +361,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) { @@ -399,7 +399,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; } @@ -436,7 +436,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; } @@ -473,7 +473,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; } @@ -503,7 +503,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; } @@ -534,7 +534,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; @@ -569,7 +569,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; @@ -633,13 +633,13 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { PWINDOW->updateSpecialRenderData(); - static auto* const PGAPSIN = &g_pConfigManager->getConfigValuePtr("general:gaps_in")->intValue; - static auto* const PGAPSOUT = &g_pConfigManager->getConfigValuePtr("general:gaps_out")->intValue; - static auto* const PNOGAPSWHENONLY = &g_pConfigManager->getConfigValuePtr("master:no_gaps_when_only")->intValue; - static auto* const PANIMATE = &g_pConfigManager->getConfigValuePtr("misc:animate_manual_resizes")->intValue; + static auto* const PGAPSIN = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_in"); + static auto* const PGAPSOUT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:gaps_out"); + 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"); - 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); @@ -649,11 +649,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; @@ -685,9 +685,9 @@ void CHyprMasterLayout::applyNodeDataToWindow(SMasterNodeData* pNode) { calcSize = calcSize - (RESERVED.topLeft + RESERVED.bottomRight); if (g_pCompositor->isWorkspaceSpecial(PWINDOW->m_iWorkspaceID)) { - static auto* const PSCALEFACTOR = &g_pConfigManager->getConfigValuePtr("master:special_scale_factor")->floatValue; + static auto* const PSCALEFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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(); @@ -736,11 +736,11 @@ void CHyprMasterLayout::resizeActiveWindow(const Vector2D& pixResize, eRectCorne const auto PMONITOR = g_pCompositor->getMonitorFromID(PWINDOW->m_iMonitorID); const auto PWORKSPACEDATA = getMasterWorkspaceData(PMONITOR->activeWorkspace); - static auto* const ALWAYSCENTER = &g_pConfigManager->getConfigValuePtr("master:always_center_master")->intValue; - static auto* const PSMARTRESIZING = &g_pConfigManager->getConfigValuePtr("master:smart_resizing")->intValue; + 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 centered = orientation == ORIENTATION_CENTER && (*ALWAYSCENTER == 1); + 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); @@ -797,7 +797,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); @@ -1055,8 +1055,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 = &g_pConfigManager->getConfigValuePtr("master:inherit_fullscreen")->intValue; - return *INHERIT == 1; + static auto* const INHERIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:inherit_fullscreen"); + return **INHERIT == 1; } return false; @@ -1233,9 +1233,9 @@ std::any CHyprMasterLayout::layoutMessage(SLayoutMessageHeader header, std::stri const auto WINDOWS = getNodesOnWorkspace(header.pWindow->m_iWorkspaceID); const auto MASTERS = getMastersOnWorkspace(header.pWindow->m_iWorkspaceID); - static const auto* SMALLSPLIT = &g_pConfigManager->getConfigValuePtr("master:allow_small_split")->intValue; + static const auto* SMALLSPLIT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("master:allow_small_split"); - if (MASTERS + 2 > WINDOWS && *SMALLSPLIT == 0) + if (MASTERS + 2 > WINDOWS && **SMALLSPLIT == 0) return 0; prepareLoseFocus(header.pWindow); diff --git a/src/managers/AnimationManager.cpp b/src/managers/AnimationManager.cpp index 120e6f49..5d2f3ce3 100644 --- a/src/managers/AnimationManager.cpp +++ b/src/managers/AnimationManager.cpp @@ -53,12 +53,12 @@ void CAnimationManager::tick() { bool animGlobalDisabled = false; - static auto* const PANIMENABLED = &g_pConfigManager->getConfigValuePtr("animations:enabled")->intValue; + static auto* const PANIMENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("animations:enabled"); - if (!*PANIMENABLED) + if (!**PANIMENABLED) animGlobalDisabled = true; - static auto* const PSHADOWSENABLED = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; + static auto* const PSHADOWSENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:drop_shadow"); const auto DEFAULTBEZIER = m_mBezierCurves.find("default"); @@ -66,7 +66,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; @@ -232,9 +232,9 @@ void CAnimationManager::tick() { // TODO: move this to the border class // damage only the border. - static auto* const PROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; - const auto ROUNDINGSIZE = *PROUNDING + 1; - const auto BORDERSIZE = PWINDOW->getRealBorderSize(); + 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 diff --git a/src/managers/KeybindManager.cpp b/src/managers/KeybindManager.cpp index 1b68f862..0d2b7ecc 100644 --- a/src/managers/KeybindManager.cpp +++ b/src/managers/KeybindManager.cpp @@ -164,19 +164,26 @@ void CKeybindManager::updateXKBTranslationState() { m_pXKBTranslationState = nullptr; } - const auto FILEPATH = g_pConfigManager->getString("input:kb_file"); - const auto RULES = g_pConfigManager->getString("input:kb_rules"); - const auto MODEL = g_pConfigManager->getString("input:kb_model"); - const auto LAYOUT = g_pConfigManager->getString("input:kb_layout"); - const auto VARIANT = g_pConfigManager->getString("input:kb_variant"); - const auto OPTIONS = g_pConfigManager->getString("input:kb_options"); - - 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); + 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"); + + 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"); + + 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,9 +376,9 @@ bool CKeybindManager::onKeyEvent(wlr_keyboard_key_event* e, SKeyboard* pKeyboard bool CKeybindManager::onAxisEvent(wlr_pointer_axis_event* e) { const auto MODS = g_pInputManager->accumulateModsFromAllKBs(); - static auto* const PDELAY = &g_pConfigManager->getConfigValuePtr("binds:scroll_event_delay")->intValue; + static auto* const PDELAY = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:scroll_event_delay"); - if (m_tScrollTimer.getMillis() < *PDELAY) { + if (m_tScrollTimer.getMillis() < **PDELAY) { m_tScrollTimer.reset(); return true; // timer hasn't passed yet! } @@ -864,9 +871,9 @@ 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 = &g_pConfigManager->getConfigValuePtr("binds:workspace_back_and_forth")->intValue; - static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; - static auto* const PWORKSPACECENTERON = &g_pConfigManager->getConfigValuePtr("binds:workspace_center_on")->intValue; + 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"); const auto PMONITOR = g_pCompositor->m_pLastMonitor; @@ -901,7 +908,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(); @@ -933,14 +940,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); @@ -1001,7 +1008,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { auto pWorkspace = g_pCompositor->getWorkspaceByID(WORKSPACEID); CMonitor* pMonitor = nullptr; const auto POLDWS = g_pCompositor->getWorkspaceByID(PWINDOW->m_iWorkspaceID); - static auto* const PALLOWWORKSPACECYCLES = &g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles")->intValue; + static auto* const PALLOWWORKSPACECYCLES = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:allow_workspace_cycles"); g_pHyprRenderer->damageWindow(PWINDOW); @@ -1027,7 +1034,7 @@ void CKeybindManager::moveActiveToWorkspace(std::string args) { g_pCompositor->focusWindow(PWINDOW); g_pCompositor->warpCursorTo(PWINDOW->middle()); - if (*PALLOWWORKSPACECYCLES) + if (**PALLOWWORKSPACECYCLES) pWorkspace->rememberPrevWorkspace(POLDWS); } @@ -1079,7 +1086,7 @@ void CKeybindManager::moveActiveToWorkspaceSilent(std::string args) { } void CKeybindManager::moveFocusTo(std::string args) { - static auto* const PFULLCYCLE = &g_pConfigManager->getConfigValuePtr("binds:movefocus_cycles_fullscreen")->intValue; + static auto* const PFULLCYCLE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:movefocus_cycles_fullscreen"); char arg = args[0]; if (!isDirection(args)) { @@ -1096,7 +1103,7 @@ void CKeybindManager::moveFocusTo(std::string args) { // remove constraints g_pInputManager->unconstrainMouse(); - 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); @@ -1111,8 +1118,8 @@ void CKeybindManager::moveFocusTo(std::string args) { if (tryMoveFocusToMonitor(g_pCompositor->getMonitorInDirection(arg))) return; - static auto* const PNOFALLBACK = &g_pConfigManager->getConfigValuePtr("general:no_focus_fallback")->intValue; - if (*PNOFALLBACK) + static auto* const PNOFALLBACK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("general:no_focus_fallback"); + if (**PNOFALLBACK) return; Debug::log(LOG, "No monitor found in direction {}, falling back to next window on current workspace", arg); @@ -1570,7 +1577,7 @@ void CKeybindManager::focusWorkspaceOnCurrentMonitor(std::string args) { void CKeybindManager::toggleSpecialWorkspace(std::string args) { - static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; + static auto* const PFOLLOWMOUSE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("input:follow_mouse"); std::string workspaceName = ""; int workspaceID = getWorkspaceIDFromString("special:" + args, workspaceName); @@ -1581,7 +1588,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) { @@ -2093,8 +2100,8 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi g_pLayoutManager->getCurrentLayout()->onWindowRemoved(pWindow); // This removes groupped property! - static const auto* USECURRPOS = &g_pConfigManager->getConfigValuePtr("group:insert_after_current")->intValue; - pWindowInDirection = *USECURRPOS ? pWindowInDirection : pWindowInDirection->getGroupTail(); + static const auto* USECURRPOS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:insert_after_current"); + pWindowInDirection = **USECURRPOS ? pWindowInDirection : pWindowInDirection->getGroupTail(); pWindowInDirection->insertWindowToGroup(pWindow); pWindowInDirection->setGroupCurrent(pWindow); @@ -2108,7 +2115,7 @@ void CKeybindManager::moveWindowIntoGroup(CWindow* pWindow, CWindow* pWindowInDi } void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& dir) { - static auto* const BFOCUSREMOVEDWINDOW = &g_pConfigManager->getConfigValuePtr("group:focus_removed_window")->intValue; + static auto* const BFOCUSREMOVEDWINDOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:focus_removed_window"); const auto PWINDOWPREV = pWindow->getGroupPrevious(); eDirection direction; @@ -2135,7 +2142,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 { @@ -2147,9 +2154,9 @@ void CKeybindManager::moveWindowOutOfGroup(CWindow* pWindow, const std::string& void CKeybindManager::moveIntoGroup(std::string args) { char arg = args[0]; - static auto* const PIGNOREGROUPLOCK = &g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock")->intValue; + static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); - if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) + if (!**PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) return; if (!isDirection(args)) { @@ -2168,16 +2175,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 = &g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock")->intValue; + static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); - if (!*PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) + if (!**PIGNOREGROUPLOCK && g_pKeybindManager->m_bGroupsLocked) return; CWindow* PWINDOW = nullptr; @@ -2196,7 +2203,7 @@ void CKeybindManager::moveOutOfGroup(std::string args) { void CKeybindManager::moveWindowOrGroup(std::string args) { char arg = args[0]; - static auto* const PIGNOREGROUPLOCK = &g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock")->intValue; + static auto* const PIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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); @@ -2207,7 +2214,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; } @@ -2220,13 +2227,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 @@ -2238,14 +2245,14 @@ void CKeybindManager::moveWindowOrGroup(std::string args) { } void CKeybindManager::setIgnoreGroupLock(std::string args) { - static auto* const BIGNOREGROUPLOCK = &g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock")->intValue; + static auto* const BIGNOREGROUPLOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("binds:ignore_group_lock"); if (args == "toggle") - *BIGNOREGROUPLOCK = !*BIGNOREGROUPLOCK; + **BIGNOREGROUPLOCK = !*BIGNOREGROUPLOCK; else - *BIGNOREGROUPLOCK = args == "on"; + **BIGNOREGROUPLOCK = args == "on"; - g_pEventManager->postEvent(SHyprIPCEvent{"ignoregrouplock", std::to_string(*BIGNOREGROUPLOCK)}); + g_pEventManager->postEvent(SHyprIPCEvent{"ignoregrouplock", std::to_string(**BIGNOREGROUPLOCK)}); } void CKeybindManager::denyWindowFromGroup(std::string args) { diff --git a/src/managers/SessionLockManager.cpp b/src/managers/SessionLockManager.cpp index 9774490b..0c13c5a4 100644 --- a/src/managers/SessionLockManager.cpp +++ b/src/managers/SessionLockManager.cpp @@ -44,9 +44,9 @@ static void handleSurfaceDestroy(void* owner, void* data) { void CSessionLockManager::onNewSessionLock(wlr_session_lock_v1* pWlrLock) { - static auto* const PALLOWRELOCK = &g_pConfigManager->getConfigValuePtr("misc:allow_session_lock_restore")->intValue; + static auto* const PALLOWRELOCK = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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 3fa83de4..ee58a8ce 100644 --- a/src/managers/ThreadManager.cpp +++ b/src/managers/ThreadManager.cpp @@ -7,9 +7,9 @@ int slowUpdate = 0; int handleTimer(void* data) { const auto PTM = (CThreadManager*)data; - static auto* const PDISABLECFGRELOAD = &g_pConfigManager->getConfigValuePtr("misc:disable_autoreload")->intValue; + static auto* const PDISABLECFGRELOAD = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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 7956c38a..b46004e6 100644 --- a/src/managers/XWaylandManager.cpp +++ b/src/managers/XWaylandManager.cpp @@ -147,7 +147,7 @@ void CHyprXWaylandManager::sendCloseWindow(CWindow* pWindow) { void CHyprXWaylandManager::setWindowSize(CWindow* pWindow, Vector2D size, bool force) { - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); const auto PMONITOR = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID); @@ -159,7 +159,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 } @@ -172,7 +172,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; } @@ -317,12 +317,12 @@ Vector2D CHyprXWaylandManager::getMaxSizeForWindow(CWindow* pWindow) { Vector2D CHyprXWaylandManager::xwaylandToWaylandCoords(const Vector2D& coord) { - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); 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}); @@ -339,7 +339,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 dab83b1d..81342b67 100644 --- a/src/managers/input/InputManager.cpp +++ b/src/managers/input/InputManager.cpp @@ -16,20 +16,20 @@ CInputManager::~CInputManager() { } void CInputManager::onMouseMoved(wlr_pointer_motion_event* e) { - static auto* const PSENS = &g_pConfigManager->getConfigValuePtr("general:sensitivity")->floatValue; - static auto* const PNOACCEL = &g_pConfigManager->getConfigValuePtr("input:force_no_accel")->intValue; - static auto* const PSENSTORAW = &g_pConfigManager->getConfigValuePtr("general:apply_sens_to_raw")->intValue; + 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"); - 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 +73,17 @@ void CInputManager::sendMotionEventsToFocused() { } void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) { - static auto* const PFOLLOWMOUSE = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; - static auto* const PMOUSEREFOCUS = &g_pConfigManager->getConfigValuePtr("input:mouse_refocus")->intValue; - static auto* const PMOUSEDPMS = &g_pConfigManager->getConfigValuePtr("misc:mouse_move_enables_dpms")->intValue; - static auto* const PFOLLOWONDND = &g_pConfigManager->getConfigValuePtr("misc:always_follow_on_dnd")->intValue; - static auto* const PFLOATBEHAVIOR = &g_pConfigManager->getConfigValuePtr("input:float_switch_override_focus")->intValue; - static auto* const PMOUSEFOCUSMON = &g_pConfigManager->getConfigValuePtr("misc:mouse_move_focuses_monitor")->intValue; - static auto* const PRESIZEONBORDER = &g_pConfigManager->getConfigValuePtr("general:resize_on_border")->intValue; - static auto* const PRESIZECURSORICON = &g_pConfigManager->getConfigValuePtr("general:hover_icon_on_border")->intValue; - static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue; - - const auto FOLLOWMOUSE = *PFOLLOWONDND && m_sDrag.drag ? 1 : *PFOLLOWMOUSE; + 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"); + + const auto FOLLOWMOUSE = **PFOLLOWONDND && m_sDrag.drag ? 1 : **PFOLLOWMOUSE; m_pFoundSurfaceToFocus = nullptr; m_pFoundLSToFocus = nullptr; @@ -97,7 +97,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 +121,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) @@ -220,7 +220,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()) { @@ -320,7 +320,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(); } @@ -390,7 +390,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) { @@ -400,7 +400,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); @@ -438,7 +438,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(); } @@ -605,15 +605,15 @@ void CInputManager::setClickMode(eClickBehaviorMode mode) { void CInputManager::processMouseDownNormal(wlr_pointer_button_event* e) { // notify the keybind manager - static auto* const PPASSMOUSE = &g_pConfigManager->getConfigValuePtr("binds:pass_mouse_when_bound")->intValue; + 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 = &g_pConfigManager->getConfigValuePtr("input:follow_mouse")->intValue; - static auto* const PRESIZEONBORDER = &g_pConfigManager->getConfigValuePtr("general:resize_on_border")->intValue; - static auto* const PBORDERSIZE = &g_pConfigManager->getConfigValuePtr("general:border_size")->intValue; - static auto* const PBORDERGRABEXTEND = &g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area")->intValue; - const auto BORDER_GRAB_AREA = *PRESIZEONBORDER ? *PBORDERSIZE + *PBORDERGRABEXTEND : 0; + 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; - if (!PASS && !*PPASSMOUSE) + if (!PASS && !**PPASSMOUSE) return; const auto mouseCoords = g_pInputManager->getMouseCoordsInternal(); @@ -624,7 +624,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.vec().x, w->m_vRealPosition.vec().y, w->m_vRealSize.vec().x, w->m_vRealSize.vec().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}; @@ -638,7 +638,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 || !g_pCompositor->m_sSeat.mouse->currentConstraint) /* No constraints */ @@ -693,9 +693,9 @@ void CInputManager::processMouseDownKill(wlr_pointer_button_event* e) { } void CInputManager::onMouseWheel(wlr_pointer_axis_event* e) { - static auto* const PSCROLLFACTOR = &g_pConfigManager->getConfigValuePtr("input:touchpad:scroll_factor")->floatValue; + static auto* const PSCROLLFACTOR = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("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<std::string, std::any>{{"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("mouseAxis", EMAP); @@ -1182,8 +1182,8 @@ void CInputManager::onKeyboardKey(wlr_keyboard_key_event* e, SKeyboard* pKeyboar const auto EMAP = std::unordered_map<std::string, std::any>{{"keyboard", pKeyboard}, {"event", e}}; EMIT_HOOK_EVENT_CANCELLABLE("keyPress", EMAP); - static auto* const PDPMS = &g_pConfigManager->getConfigValuePtr("misc:key_press_enables_dpms")->intValue; - if (*PDPMS && !g_pCompositor->m_bDPMSStateON) { + static auto* const PDPMS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:key_press_enables_dpms"); + if (**PDPMS && !g_pCompositor->m_bDPMSStateON) { // enable dpms g_pKeybindManager->dpms("on"); } @@ -1675,17 +1675,17 @@ void CInputManager::setCursorIconOnBorder(CWindow* w) { return; } - static auto* const PROUNDING = &g_pConfigManager->getConfigValuePtr("decoration:rounding")->intValue; - static const auto* PEXTENDBORDERGRAB = &g_pConfigManager->getConfigValuePtr("general:extend_border_grab_area")->intValue; + 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(); // give a small leeway (10 px) for corner icon - const auto CORNER = *PROUNDING + BORDERSIZE + 10; + 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 38ec8aa2..1cc1b031 100644 --- a/src/managers/input/Swipe.cpp +++ b/src/managers/input/Swipe.cpp @@ -2,11 +2,11 @@ #include "../../Compositor.hpp" void CInputManager::onSwipeBegin(wlr_pointer_swipe_begin_event* e) { - static auto* const PSWIPE = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe")->intValue; - static auto* const PSWIPEFINGERS = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_fingers")->intValue; - static auto* const PSWIPENEW = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new")->intValue; + 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"); - if (e->fingers != *PSWIPEFINGERS || *PSWIPE == 0 || g_pSessionLockManager->isSessionLocked()) + if (e->fingers != **PSWIPEFINGERS || **PSWIPE == 0 || g_pSessionLockManager->isSessionLocked()) return; int onMonitor = 0; @@ -16,7 +16,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 +44,20 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; // no valid swipe - static auto* const PSWIPEPERC = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_cancel_ratio")->floatValue; - static auto* const PSWIPEDIST = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance")->intValue; - static auto* const PSWIPEFORC = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_min_speed_to_force")->intValue; - static auto* const PSWIPENEW = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new")->intValue; - static auto* const PSWIPENUMBER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered")->intValue; - static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue; - static auto* const PWORKSPACEGAP = &g_pConfigManager->getConfigValuePtr("general:gaps_workspaces")->intValue; + 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" || 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 +68,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 +80,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.vec(); - 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) { @@ -100,16 +100,16 @@ void CInputManager::onSwipeEnd(wlr_pointer_swipe_end_event* e) { if (PWORKSPACEL) { if (VERTANIMS) - PWORKSPACEL->m_vRenderOffset = Vector2D({0, -YDISTANCE}); + PWORKSPACEL->m_vRenderOffset = Vector2D{0, -YDISTANCE}; else - PWORKSPACEL->m_vRenderOffset = Vector2D({-XDISTANCE, 0}); + PWORKSPACEL->m_vRenderOffset = Vector2D{-XDISTANCE, 0}; } } else if (PWORKSPACER) { // to right if (VERTANIMS) - PWORKSPACER->m_vRenderOffset = Vector2D({0, YDISTANCE}); + PWORKSPACER->m_vRenderOffset = Vector2D{0, YDISTANCE}; else - PWORKSPACER->m_vRenderOffset = Vector2D({XDISTANCE, 0}); + PWORKSPACER->m_vRenderOffset = Vector2D{XDISTANCE, 0}; } m_sActiveSwipe.pWorkspaceBegin->m_vRenderOffset = Vector2D(); @@ -194,40 +194,40 @@ void CInputManager::onSwipeUpdate(wlr_pointer_swipe_update_event* e) { if (!m_sActiveSwipe.pWorkspaceBegin) return; - static auto* const PSWIPEDIST = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_distance")->intValue; - static auto* const PSWIPEINVR = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_invert")->intValue; - static auto* const PSWIPENEW = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_create_new")->intValue; - static auto* const PSWIPEDIRLOCK = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock")->intValue; - static auto* const PSWIPEDIRLOCKTHRESHOLD = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_direction_lock_threshold")->intValue; - static auto* const PSWIPEFOREVER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_forever")->intValue; - static auto* const PSWIPENUMBER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_numbered")->intValue; - static auto* const PSWIPEUSER = &g_pConfigManager->getConfigValuePtr("gestures:workspace_swipe_use_r")->intValue; - static auto* const PWORKSPACEGAP = &g_pConfigManager->getConfigValuePtr("general:gaps_workspaces")->intValue; - - const auto XDISTANCE = m_sActiveSwipe.pMonitor->vecSize.x + *PWORKSPACEGAP; - const auto YDISTANCE = m_sActiveSwipe.pMonitor->vecSize.y + *PWORKSPACEGAP; + 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"); + + 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 +236,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 +247,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 +275,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 +287,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 +315,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 +329,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/meson.build b/src/meson.build index 0af864b9..2d72280c 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('hyprlang', version: '>= 0.3.2'), dependency('libdrm'), dependency('egl'), dependency('xkbcommon'), diff --git a/src/plugins/PluginAPI.cpp b/src/plugins/PluginAPI.cpp index b6a353ea..b6326960 100644 --- a/src/plugins/PluginAPI.cpp +++ b/src/plugins/PluginAPI.cpp @@ -147,7 +147,7 @@ APICALL bool HyprlandAPI::removeWindowDecoration(HANDLE handle, IHyprWindowDecor return false; } -APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, const SConfigValue& value) { +APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!g_pPluginSystem->m_bAllowConfigVars) @@ -163,7 +163,7 @@ APICALL bool HyprlandAPI::addConfigValue(HANDLE handle, const std::string& name, return true; } -APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& key, const std::string& val)> fn) { +APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!g_pPluginSystem->m_bAllowConfigVars) @@ -172,17 +172,20 @@ APICALL bool HyprlandAPI::addConfigKeyword(HANDLE handle, const std::string& nam if (!PLUGIN) return false; - g_pConfigManager->addPluginKeyword(handle, name, fn); + g_pConfigManager->addPluginKeyword(handle, name, fn, opts); return true; } -APICALL SConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) { +APICALL Hyprlang::CConfigValue* HyprlandAPI::getConfigValue(HANDLE handle, const std::string& name) { auto* const PLUGIN = g_pPluginSystem->getPluginByHandle(handle); if (!PLUGIN) return nullptr; - return g_pConfigManager->getConfigValuePtrSafe(name); + if (name.starts_with("plugin:")) + return g_pConfigManager->getHyprlangConfigValuePtr(name.substr(7), "plugin"); + + return g_pConfigManager->getHyprlangConfigValuePtr(name); } APICALL void* HyprlandAPI::getFunctionAddressFromSignature(HANDLE handle, const std::string& sig) { diff --git a/src/plugins/PluginAPI.hpp b/src/plugins/PluginAPI.hpp index e7a6c899..a7a998b4 100644 --- a/src/plugins/PluginAPI.hpp +++ b/src/plugins/PluginAPI.hpp @@ -112,7 +112,7 @@ namespace HyprlandAPI { returns: true on success, false on fail */ - APICALL bool addConfigValue(HANDLE handle, const std::string& name, const SConfigValue& value); + APICALL bool addConfigValue(HANDLE handle, const std::string& name, const Hyprlang::CConfigValue& value); /* Add a config keyword. @@ -120,15 +120,17 @@ namespace HyprlandAPI { returns: true on success, false on fail */ - APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, std::function<void(const std::string& key, const std::string& val)> fn); + APICALL bool addConfigKeyword(HANDLE handle, const std::string& name, Hyprlang::PCONFIGHANDLERFUNC fn, Hyprlang::SHandlerOptions opts); /* Get a config value. + Please see the <hyprlang.hpp> header or https://hyprland.org/hyprlang/ for docs regarding Hyprlang types. + returns: a pointer to the config value struct, which is guaranteed to be valid for the life of this plugin, unless another `addConfigValue` is called afterwards. nullptr on error. */ - APICALL SConfigValue* getConfigValue(HANDLE handle, const std::string& name); + APICALL Hyprlang::CConfigValue* getConfigValue(HANDLE handle, const std::string& name); /* Register a static (pointer) callback to a selected event. diff --git a/src/protocols/XDGOutput.cpp b/src/protocols/XDGOutput.cpp index 49845b94..9f6e071d 100644 --- a/src/protocols/XDGOutput.cpp +++ b/src/protocols/XDGOutput.cpp @@ -112,7 +112,7 @@ void CXDGOutputProtocol::onManagerGetXDGOutput(wl_client* client, wl_resource* r } void CXDGOutputProtocol::updateOutputDetails(SXDGOutput* pOutput) { - static auto* const PXWLFORCESCALEZERO = &g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling")->intValue; + static auto* const PXWLFORCESCALEZERO = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:force_zero_scaling"); if (!pOutput->resource->good() || !pOutput->monitor) return; @@ -120,7 +120,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 e9df3b05..a73cfd5b 100644 --- a/src/render/OpenGL.cpp +++ b/src/render/OpenGL.cpp @@ -120,18 +120,18 @@ 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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; - static auto* const PXRAY = &g_pConfigManager->getConfigValuePtr("decoration:blur:xray")->intValue; - static auto* const POPTIM = &g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations")->intValue; - static auto* const PBLURSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:blur:special")->intValue; + 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"); - if (m_RenderData.mouseZoomFactor != 1.0) + if (m_RenderData.mouseZoomFactor != 1.0 || g_pHyprRenderer->m_bCrashingInProgress) return true; if (!pMonitor->mirrors.empty()) return true; - if (*PBLUR == 0) + if (**PBLUR == 0) return false; if (m_RenderData.pCurrentMonData->blurFBShouldRender) @@ -141,13 +141,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; } @@ -168,7 +168,7 @@ 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() || (!w->m_bIsFloating && **POPTIM && !g_pCompositor->isWorkspaceSpecial(w->m_iWorkspaceID))) continue; if (!g_pHyprRenderer->shouldRenderWindow(w.get())) @@ -243,8 +243,9 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, CFramebuffer* m_bFakeFrame = fb; if (m_bReloadScreenShader) { - m_bReloadScreenShader = false; - applyScreenShader(g_pConfigManager->getString("decoration:screen_shader")); + m_bReloadScreenShader = false; + static auto* const PSHADER = (Hyprlang::STRING const*)g_pConfigManager->getConfigValuePtr("decoration:screen_shader"); + applyScreenShader(*PSHADER); } const auto PRBO = g_pHyprRenderer->getCurrentRBO(); @@ -274,7 +275,7 @@ void CHyprOpenGLImpl::begin(CMonitor* pMonitor, CRegion* pDamage, CFramebuffer* } void CHyprOpenGLImpl::end() { - static auto* const PZOOMRIGID = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_rigid")->intValue; + static auto* const PZOOMRIGID = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_rigid"); TRACY_GPU_ZONE("RenderEnd"); @@ -294,7 +295,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; @@ -313,7 +314,7 @@ void CHyprOpenGLImpl::end() { blend(false); - if (m_sFinalScreenShader.program < 1) + if (m_sFinalScreenShader.program < 1 && !g_pHyprRenderer->m_bCrashingInProgress) renderTexturePrimitive(m_RenderData.pCurrentMonData->offloadFB.m_cTex, &monbox); else renderTexture(m_RenderData.pCurrentMonData->offloadFB.m_cTex, &monbox, 1.f); @@ -505,6 +506,8 @@ void CHyprOpenGLImpl::initShaders() { void CHyprOpenGLImpl::applyScreenShader(const std::string& path) { + static auto* const PDT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); + m_sFinalScreenShader.destroy(); if (path == "" || path == STRVAL_EMPTY) @@ -530,7 +533,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 && g_pConfigManager->getInt("debug:damage_tracking") != 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" @@ -754,7 +757,8 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* CBox newBox = *pBox; m_RenderData.renderModif.applyToBox(newBox); - static auto* const PDIMINACTIVE = &g_pConfigManager->getConfigValuePtr("decoration:dim_inactive")->intValue; + 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"); // get transform const auto TRANSFORM = wlr_output_transform_invert(!m_bEndFrame ? WL_OUTPUT_TRANSFORM_NORMAL : m_RenderData.pMonitor->transform); @@ -814,7 +818,7 @@ void CHyprOpenGLImpl::renderTextureInternalWithDamage(const CTexture& tex, CBox* #endif glUniform1i(shader->tex, 0); - if ((usingFinalShader && g_pConfigManager->getInt("debug:damage_tracking") == 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 @@ -855,7 +859,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.fl(); glUniform3f(shader->tint, 1.f - DIM, 1.f - DIM, 1.f - DIM); @@ -1039,16 +1043,16 @@ CFramebuffer* CHyprOpenGLImpl::blurMainFramebufferWithDamage(float a, CRegion* o wlr_matrix_multiply(glMatrix, m_RenderData.projection, matrix); // get the config settings - static auto* const PBLURSIZE = &g_pConfigManager->getConfigValuePtr("decoration:blur:size")->intValue; - static auto* const PBLURPASSES = &g_pConfigManager->getConfigValuePtr("decoration:blur:passes")->intValue; - static auto* const PBLURVIBRANCY = &g_pConfigManager->getConfigValuePtr("decoration:blur:vibrancy")->floatValue; - static auto* const PBLURVIBRANCYDARKNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:vibrancy_darkness")->floatValue; + 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"); // 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; @@ -1059,8 +1063,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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:contrast")->floatValue; - static auto* const PBLURBRIGHTNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:brightness")->floatValue; + 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"); PMIRRORSWAPFB->bind(); @@ -1078,8 +1082,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); @@ -1123,13 +1127,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)); @@ -1166,20 +1170,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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:noise")->floatValue; - static auto* const PBLURBRIGHTNESS = &g_pConfigManager->getConfigValuePtr("decoration:blur:brightness")->floatValue; + 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"); if (currentRenderToFB == PMIRRORFB) PMIRRORSWAPFB->bind(); @@ -1200,8 +1204,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); @@ -1240,11 +1244,11 @@ void CHyprOpenGLImpl::markBlurDirtyForMonitor(CMonitor* pMonitor) { } void CHyprOpenGLImpl::preRender(CMonitor* pMonitor) { - static auto* const PBLURNEWOPTIMIZE = &g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations")->intValue; - static auto* const PBLURXRAY = &g_pConfigManager->getConfigValuePtr("decoration:blur:xray")->intValue; - static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; + 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"); - if (!*PBLURNEWOPTIMIZE || !m_mMonitorRenderResources[pMonitor].blurFBDirty || !*PBLUR) + if (!**PBLURNEWOPTIMIZE || !m_mMonitorRenderResources[pMonitor].blurFBDirty || !**PBLUR) return; // ignore if solitary present, nothing to blur @@ -1289,7 +1293,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())) @@ -1362,15 +1366,15 @@ void CHyprOpenGLImpl::preWindowPass() { } bool CHyprOpenGLImpl::preBlurQueued() { - static auto* const PBLURNEWOPTIMIZE = &g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations")->intValue; - static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; + 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"); - 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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:new_optimizations")->intValue; - static auto* const PBLURXRAY = &g_pConfigManager->getConfigValuePtr("decoration:blur:xray")->intValue; + 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"); if (!m_RenderData.pCurrentMonData->blurFB.m_cTex.m_iTexID) return false; @@ -1381,7 +1385,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)) @@ -1393,8 +1397,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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; - static auto* const PNOBLUROVERSIZED = &g_pConfigManager->getConfigValuePtr("decoration:no_blur_on_oversized")->intValue; + 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"); TRACY_GPU_ZONE("RenderTextureWithBlur"); @@ -1405,7 +1409,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; @@ -1466,11 +1470,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 = &g_pConfigManager->getConfigValuePtr("decoration:blur:ignore_opacity")->intValue; + 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); + renderTextureInternalWithDamage(POUTFB->m_cTex, &MONITORBOX, **PBLURIGNOREOPACITY ? blurA : a * blurA, &texDamage, 0, false, false, false); m_bEndFrame = false; m_RenderData.renderModif = SAVEDRENDERMODIF; @@ -1620,8 +1624,9 @@ 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 - const auto BLURVAL = g_pConfigManager->getInt("decoration:blur:enabled"); - g_pConfigManager->setInt("decoration:blur:enabled", 0); + static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + const auto BLURVAL = **PBLUR; + **PBLUR = 0; // TODO: how can we make this the size of the window? setting it to window's size makes the entire screen render with the wrong res forever more. odd. glViewport(0, 0, PMONITOR->vecPixelSize.x, PMONITOR->vecPixelSize.y); @@ -1632,7 +1637,7 @@ void CHyprOpenGLImpl::makeRawWindowSnapshot(CWindow* pWindow, CFramebuffer* pFra g_pHyprRenderer->renderWindow(pWindow, PMONITOR, &now, false, RENDER_PASS_ALL, true); - g_pConfigManager->setInt("decoration:blur:enabled", BLURVAL); + **PBLUR = BLURVAL; g_pHyprRenderer->endRender(); } @@ -1672,14 +1677,15 @@ 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 - const auto BLURVAL = g_pConfigManager->getInt("decoration:blur:enabled"); - g_pConfigManager->setInt("decoration:blur:enabled", 0); + static auto* const PBLUR = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); + const auto BLURVAL = **PBLUR; + **PBLUR = 0; clear(CColor(0, 0, 0, 0)); // JIC g_pHyprRenderer->renderWindow(pWindow, PMONITOR, &now, !pWindow->m_bX11DoesntWantBorders, RENDER_PASS_ALL); - g_pConfigManager->setInt("decoration:blur:enabled", BLURVAL); + **PBLUR = BLURVAL; g_pHyprRenderer->endRender(); @@ -1730,7 +1736,7 @@ void CHyprOpenGLImpl::renderSnapshot(CWindow** pWindow) { RASSERT(m_RenderData.pMonitor, "Tried to render snapshot rect without begin()!"); const auto PWINDOW = *pWindow; - static auto* const PDIMAROUND = &g_pConfigManager->getConfigValuePtr("decoration:dim_around")->floatValue; + static auto* const PDIMAROUND = (Hyprlang::FLOAT* const*)g_pConfigManager->getConfigValuePtr("decoration:dim_around"); auto it = m_mWindowFramebuffers.begin(); for (; it != m_mWindowFramebuffers.end(); it++) { @@ -1757,9 +1763,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.fl())); + g_pHyprOpenGL->renderRect(&monbox, CColor(0, 0, 0, **PDIMAROUND * PWINDOW->m_fAlpha.fl())); g_pHyprRenderer->damageMonitor(PMONITOR); } @@ -1812,9 +1818,9 @@ void CHyprOpenGLImpl::renderRoundedShadow(CBox* box, int round, int range, const box = &newBox; - static auto* const PSHADOWPOWER = &g_pConfigManager->getConfigValuePtr("decoration:shadow_render_power")->intValue; + static auto* const PSHADOWPOWER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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; @@ -1926,15 +1932,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 = &g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo")->intValue; - static auto* const PNOSPLASH = &g_pConfigManager->getConfigValuePtr("misc:disable_splash_rendering")->intValue; - static auto* const PFORCEWALLPAPER = &g_pConfigManager->getConfigValuePtr("misc:force_default_wallpaper")->intValue; + 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"); - const auto FORCEWALLPAPER = std::clamp(*PFORCEWALLPAPER, static_cast<int64_t>(-1L), static_cast<int64_t>(2L)); + const auto FORCEWALLPAPER = std::clamp(**PFORCEWALLPAPER, static_cast<int64_t>(-1L), static_cast<int64_t>(2L)); static std::string texPath = ""; - if (*PRENDERTEX) + if (**PRENDERTEX) return; // release the last tex if exists @@ -1956,7 +1962,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"; diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp index 6e3f92c1..9d7bb5e1 100644 --- a/src/render/Renderer.cpp +++ b/src/render/Renderer.cpp @@ -48,8 +48,8 @@ CHyprRenderer::CHyprRenderer() { } static void renderSurface(struct wlr_surface* surface, int x, int y, void* data) { - static auto* const PBLURPOPUPS = &g_pConfigManager->getConfigValuePtr("decoration:blur:popups")->intValue; - static auto* const PBLURPOPUPSIGNOREALPHA = &g_pConfigManager->getConfigValuePtr("decoration:blur:popups_ignorealpha")->floatValue; + 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"); const auto TEXTURE = wlr_surface_get_texture(surface); const auto RDATA = (SRenderData*)data; @@ -148,11 +148,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); @@ -409,8 +409,8 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* const auto PWORKSPACE = g_pCompositor->getWorkspaceByID(pWindow->m_iWorkspaceID); const auto REALPOS = pWindow->m_vRealPosition.vec() + (pWindow->m_bPinned ? Vector2D{} : PWORKSPACE->m_vRenderOffset.vec()); - static auto* const PDIMAROUND = &g_pConfigManager->getConfigValuePtr("decoration:dim_around")->floatValue; - static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; + 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)}; @@ -452,7 +452,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 +521,11 @@ void CHyprRenderer::renderWindow(CWindow* pWindow, CMonitor* pMonitor, timespec* } } - static auto* const PXWLUSENN = &g_pConfigManager->getConfigValuePtr("xwayland:use_nearest_neighbor")->intValue; - if ((pWindow->m_bIsX11 && *PXWLUSENN) || pWindow->m_sAdditionalConfigData.nearestNeighbor.toUnderlying()) + static auto* const PXWLUSENN = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("xwayland:use_nearest_neighbor"); + 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_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, @@ -657,11 +657,11 @@ 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 = &g_pConfigManager->getConfigValuePtr("decoration:dim_special")->floatValue; - static auto* const PBLURSPECIAL = &g_pConfigManager->getConfigValuePtr("decoration:blur:special")->intValue; - static auto* const PBLUR = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; - static auto* const PRENDERTEX = &g_pConfigManager->getConfigValuePtr("misc:disable_hyprland_logo")->intValue; - static auto* const PBACKGROUNDCOLOR = &g_pConfigManager->getConfigValuePtr("misc:background_color")->intValue; + 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"); SRenderModifData RENDERMODIFDATA; if (translate != Vector2D{0, 0}) @@ -699,8 +699,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" } @@ -736,12 +736,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)); } @@ -943,23 +943,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 = &g_pConfigManager->getConfigValuePtr("debug:overlay")->intValue; - static auto* const PDAMAGETRACKINGMODE = &g_pConfigManager->getConfigValuePtr("debug:damage_tracking")->intValue; - static auto* const PDAMAGEBLINK = &g_pConfigManager->getConfigValuePtr("debug:damage_blink")->intValue; - static auto* const PNODIRECTSCANOUT = &g_pConfigManager->getConfigValuePtr("misc:no_direct_scanout")->intValue; - static auto* const PVFR = &g_pConfigManager->getConfigValuePtr("misc:vfr")->intValue; - static auto* const PZOOMFACTOR = &g_pConfigManager->getConfigValuePtr("misc:cursor_zoom_factor")->floatValue; - static auto* const PANIMENABLED = &g_pConfigManager->getConfigValuePtr("animations:enabled")->intValue; - static auto* const PFIRSTLAUNCHANIM = &g_pConfigManager->getConfigValuePtr("animations:first_launch_animation")->intValue; - static auto* const PTEARINGENABLED = &g_pConfigManager->getConfigValuePtr("general:allow_tearing")->intValue; + 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 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; @@ -969,7 +969,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 { @@ -982,18 +982,17 @@ 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) { pMonitor->framesToSkip -= 1; if (!pMonitor->noFrameSchedule) g_pCompositor->scheduleFrameForMonitor(pMonitor); - else { + else Debug::log(LOG, "NoFrameSchedule hit for {}.", pMonitor->szName); - } + g_pLayoutManager->getCurrentLayout()->recalculateMonitor(pMonitor->ID); if (pMonitor->framesToSkip > 10) @@ -1003,7 +1002,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 @@ -1044,7 +1043,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; } @@ -1063,7 +1062,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { shouldTear = true; } - if (!*PNODIRECTSCANOUT && !shouldTear) { + if (!**PNODIRECTSCANOUT && !shouldTear) { if (attemptDirectScanout(pMonitor)) { return; } else if (m_pLastScanout) { @@ -1085,10 +1084,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; } @@ -1108,21 +1107,21 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { g_pCompositor->cleanupFadingOut(pMonitor->ID); // 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}; pMonitor->lastFrameDamage = damage; } else { - static auto* const PBLURENABLED = &g_pConfigManager->getConfigValuePtr("decoration:blur:enabled")->intValue; + static auto* const PBLURENABLED = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("decoration:blur:enabled"); // if we use blur we need to expand the damage for proper blurring - if (*PBLURENABLED == 1) { + if (**PBLURENABLED == 1) { // TODO: can this be optimized? - static auto* const PBLURSIZE = &g_pConfigManager->getConfigValuePtr("decoration:blur:size")->intValue; - static auto* const PBLURPASSES = &g_pConfigManager->getConfigValuePtr("decoration:blur:passes")->intValue; + 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. + **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 @@ -1147,7 +1146,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; @@ -1191,17 +1190,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; @@ -1216,7 +1215,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); @@ -1238,10 +1237,10 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { const auto TRANSFORM = wlr_output_transform_invert(pMonitor->output->transform); wlr_region_transform(frameDamage.pixman(), pMonitor->lastFrameDamage.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); @@ -1269,7 +1268,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; @@ -1277,7 +1276,7 @@ void CHyprRenderer::renderMonitor(CMonitor* pMonitor) { const float µs = std::chrono::duration_cast<std::chrono::nanoseconds>(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<std::chrono::nanoseconds>(endRenderOverlay - renderStartOverlay).count() / 1000.f; g_pDebugOverlay->renderDataNoOverlay(pMonitor, µsNoOverlay); @@ -1346,7 +1345,7 @@ void CHyprRenderer::outputMgrApplyTest(wlr_output_configuration_v1* config, bool if (!head->state.enabled) { commandForCfg += "disabled"; if (!test) - g_pConfigManager->parseKeyword("monitor", commandForCfg, true); + g_pConfigManager->parseKeyword("monitor", commandForCfg); continue; } @@ -1365,7 +1364,7 @@ void CHyprRenderer::outputMgrApplyTest(wlr_output_configuration_v1* config, bool std::to_string((int)head->state.transform); if (!test) { - g_pConfigManager->parseKeyword("monitor", commandForCfg, true); + g_pConfigManager->parseKeyword("monitor", commandForCfg); wlr_output_state_set_adaptive_sync_enabled(PMONITOR->state.wlr(), head->state.adaptive_sync_enabled); } @@ -1619,9 +1618,9 @@ void CHyprRenderer::damageSurface(wlr_surface* pSurface, double x, double y, dou m->addDamage(&damageBoxForEach); } - static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; + static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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); } @@ -1640,9 +1639,9 @@ void CHyprRenderer::damageWindow(CWindow* pWindow) { for (auto& wd : pWindow->m_dWindowDecorations) wd->damageEntire(); - static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; + static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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); } @@ -1653,9 +1652,9 @@ void CHyprRenderer::damageMonitor(CMonitor* pMonitor) { CBox damageBox = {0, 0, INT16_MAX, INT16_MAX}; pMonitor->addDamage(&damageBox); - static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; + static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); - if (*PLOGDAMAGE) + if (**PLOGDAMAGE) Debug::log(LOG, "Damage: Monitor {}", pMonitor->szName); } @@ -1672,9 +1671,9 @@ void CHyprRenderer::damageBox(CBox* pBox) { m->addDamage(&damageBox); } - static auto* const PLOGDAMAGE = &g_pConfigManager->getConfigValuePtr("debug:log_damage")->intValue; + static auto* const PLOGDAMAGE = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:log_damage"); - if (*PLOGDAMAGE) + if (**PLOGDAMAGE) Debug::log(LOG, "Damage: Box: xy: {}, {} wh: {}, {}", pBox->x, pBox->y, pBox->width, pBox->height); } @@ -1730,7 +1729,7 @@ DAMAGETRACKINGMODES CHyprRenderer::damageTrackingModeFromStr(const std::string& bool CHyprRenderer::applyMonitorRule(CMonitor* pMonitor, SMonitorRule* pMonitorRule, bool force) { - static auto* const PDISABLESCALECHECKS = &g_pConfigManager->getConfigValuePtr("debug:disable_scale_checks")->intValue; + static auto* const PDISABLESCALECHECKS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:disable_scale_checks"); Debug::log(LOG, "Applying monitor rule for {}", pMonitor->szName); @@ -2007,7 +2006,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. @@ -2175,13 +2174,13 @@ void CHyprRenderer::setCursorFromName(const std::string& name, bool force) { } void CHyprRenderer::ensureCursorRenderingMode() { - static auto* const PCURSORTIMEOUT = &g_pConfigManager->getConfigValuePtr("general:cursor_inactive_timeout")->intValue; - static auto* const PHIDEONTOUCH = &g_pConfigManager->getConfigValuePtr("misc:hide_cursor_on_touch")->intValue; + 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"); 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)"); @@ -2272,7 +2271,9 @@ void CHyprRenderer::initiateManualCrash() { g_pHyprOpenGL->m_tGlobalTimer.reset(); - g_pConfigManager->setInt("debug:damage_tracking", 0); + static auto* const PDT = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("debug:damage_tracking"); + + **PDT = 0; } void CHyprRenderer::setOccludedForMainWorkspace(CRegion& region, CWorkspace* pWorkspace) { @@ -2491,7 +2492,7 @@ bool CHyprRenderer::beginRender(CMonitor* pMonitor, CRegion& damage, eRenderMode void CHyprRenderer::endRender() { const auto PMONITOR = g_pHyprOpenGL->m_RenderData.pMonitor; - static auto* const PNVIDIAANTIFLICKER = &g_pConfigManager->getConfigValuePtr("opengl:nvidia_anti_flicker")->intValue; + static auto* const PNVIDIAANTIFLICKER = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("opengl:nvidia_anti_flicker"); if (m_eRenderMode != RENDER_MODE_TO_BUFFER_READ_ONLY) g_pHyprOpenGL->end(); @@ -2504,7 +2505,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 77ebdd57..1ed6c144 100644 --- a/src/render/decorations/CHyprBorderDecoration.cpp +++ b/src/render/decorations/CHyprBorderDecoration.cpp @@ -94,9 +94,9 @@ eDecorationLayer CHyprBorderDecoration::getDecorationLayer() { } uint64_t CHyprBorderDecoration::getDecorationFlags() { - static auto* const PPARTOFWINDOW = &g_pConfigManager->getConfigValuePtr("general:border_part_of_window")->intValue; + static auto* const PPARTOFWINDOW = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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 0e5e9d94..3f1f38c4 100644 --- a/src/render/decorations/CHyprDropShadowDecoration.cpp +++ b/src/render/decorations/CHyprDropShadowDecoration.cpp @@ -35,9 +35,9 @@ std::string CHyprDropShadowDecoration::getDisplayName() { } void CHyprDropShadowDecoration::damageEntire() { - static auto* const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; + static auto* const PSHADOWS = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("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 +70,13 @@ void CHyprDropShadowDecoration::draw(CMonitor* pMonitor, float a, const Vector2D if (m_pWindow->m_sAdditionalConfigData.forceNoShadow) return; - static auto* const PSHADOWS = &g_pConfigManager->getConfigValuePtr("decoration:drop_shadow")->intValue; - static auto* const PSHADOWSIZE = &g_pConfigManager->getConfigValuePtr("decoration:shadow_range")->intValue; - static auto* const PSHADOWIGNOREWINDOW = &g_pConfigManager->getConfigValuePtr("decoration:shadow_ignore_window")->intValue; - static auto* const PSHADOWSCALE = &g_pConfigManager->getConfigValuePtr("decoration:shadow_scale")->floatValue; - static auto* const PSHADOWOFFSET = &g_pConfigManager->getConfigValuePtr("decoration:shadow_offset")->vecValue; + 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"); - if (*PSHADOWS != 1) + if (**PSHADOWS != 1) return; // disabled const auto ROUNDINGBASE = m_pWindow->rounding(); @@ -87,15 +87,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}, @@ -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.col().a), a); // render black window box ("clip") g_pHyprOpenGL->renderRect(&windowBox, CColor(0, 0, 0, 1.0), ROUNDING * pMonitor->scale); @@ -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.col(), a); } if (m_seExtents != m_seReportedExtents) diff --git a/src/render/decorations/CHyprGroupBarDecoration.cpp b/src/render/decorations/CHyprGroupBarDecoration.cpp index 257f47ed..20c0240f 100644 --- a/src/render/decorations/CHyprGroupBarDecoration.cpp +++ b/src/render/decorations/CHyprGroupBarDecoration.cpp @@ -15,30 +15,31 @@ constexpr int BAR_TEXT_PAD = 2; constexpr int BAR_HORIZONTAL_PADDING = 2; CHyprGroupBarDecoration::CHyprGroupBarDecoration(CWindow* pWindow) : IHyprWindowDecoration(pWindow) { - static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; - static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; + 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; - 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 = &g_pConfigManager->getConfigValuePtr("group:groupbar:height")->intValue; - static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; - static auto* const PRENDERTITLES = &g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles")->intValue; - static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; + 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"); SDecorationPositioningInfo info; info.policy = DECORATION_POSITION_STICKY; info.edges = DECORATION_EDGE_TOP; - info.priority = g_pConfigManager->getConfigValuePtr("group:groupbar:priority")->intValue; + 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}}; @@ -88,20 +89,20 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& // get how many bars we will draw int barsToDraw = m_dwGroupMembers.size(); - static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; - static auto* const PRENDERTITLES = &g_pConfigManager->getConfigValuePtr("group:groupbar:render_titles")->intValue; - static auto* const PTITLEFONTSIZE = &g_pConfigManager->getConfigValuePtr("group:groupbar:font_size")->intValue; - static auto* const PHEIGHT = &g_pConfigManager->getConfigValuePtr("group:groupbar:height")->intValue; - static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; + 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"); - 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); @@ -116,17 +117,20 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& rect.scale(pMonitor->scale); - static auto* const PGROUPCOLACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.active")->data; - static auto* const PGROUPCOLINACTIVE = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive")->data; - static auto* const PGROUPCOLACTIVELOCKED = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_active")->data; - static auto* const PGROUPCOLINACTIVELOCKED = &g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_inactive")->data; + 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(); const bool GROUPLOCKED = m_pWindow->getGroupHead()->m_sGroupData.locked; - const auto* const PCOLACTIVE = GROUPLOCKED ? PGROUPCOLACTIVELOCKED : PGROUPCOLACTIVE; - const auto* const PCOLINACTIVE = GROUPLOCKED ? PGROUPCOLINACTIVELOCKED : PGROUPCOLINACTIVE; + const auto* const PCOLACTIVE = GROUPLOCKED ? GROUPCOLACTIVELOCKED : GROUPCOLACTIVE; + const auto* const PCOLINACTIVE = GROUPLOCKED ? GROUPCOLINACTIVELOCKED : GROUPCOLINACTIVE; - CColor color = - m_dwGroupMembers[i] == g_pCompositor->m_pLastWindow ? ((CGradientValueData*)PCOLACTIVE->get())->m_vColors[0] : ((CGradientValueData*)PCOLINACTIVE->get())->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); @@ -141,17 +145,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<CTitleTex>(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); } @@ -159,7 +163,7 @@ void CHyprGroupBarDecoration::draw(CMonitor* pMonitor, float a, const Vector2D& xoff += BAR_HORIZONTAL_PADDING + m_fBarWidth; } - if (*PRENDERTITLES) + if (**PRENDERTITLES) invalidateTextures(); } @@ -183,11 +187,11 @@ CTitleTex::CTitleTex(CWindow* pWindow, const Vector2D& bufferSize) { const auto CAIRO = cairo_create(CAIROSURFACE); const auto MONITORSCALE = g_pCompositor->getMonitorFromID(pWindow->m_iMonitorID)->scale; - static auto* const PTITLEFONTFAMILY = &g_pConfigManager->getConfigValuePtr("group:groupbar:font_family")->strValue; - static auto* const PTITLEFONTSIZE = &g_pConfigManager->getConfigValuePtr("group:groupbar:font_size")->intValue; - static auto* const PTEXTCOLOR = &g_pConfigManager->getConfigValuePtr("group:groupbar:text_color")->intValue; + 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"); - const CColor COLOR = CColor(*PTEXTCOLOR); + const CColor COLOR = CColor(**PTEXTCOLOR); // clear the pixmap cairo_save(CAIRO); @@ -199,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->c_str()); - pango_font_description_set_size(fontDesc, *PTITLEFONTSIZE * MONITORSCALE * PANGO_SCALE); + PangoFontDescription* fontDesc = pango_font_description_from_string(*PTITLEFONTFAMILY); + pango_font_description_set_size(fontDesc, **PTITLEFONTSIZE * PANGO_SCALE); pango_layout_set_font_description(layout, fontDesc); pango_font_description_free(fontDesc); @@ -297,13 +301,17 @@ void renderGradientTo(CTexture& tex, CGradientValueData* grad) { } void refreshGroupBarGradients() { - static auto* const PGRADIENTS = &g_pConfigManager->getConfigValuePtr("group:groupbar:enabled")->intValue; - static auto* const PENABLED = &g_pConfigManager->getConfigValuePtr("group:groupbar:gradients")->intValue; - - CGradientValueData* PGROUPCOLACTIVE = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.active")->data.get(); - CGradientValueData* PGROUPCOLINACTIVE = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.inactive")->data.get(); - CGradientValueData* PGROUPCOLACTIVELOCKED = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_active")->data.get(); - CGradientValueData* PGROUPCOLINACTIVELOCKED = (CGradientValueData*)g_pConfigManager->getConfigValuePtr("group:groupbar:col.locked_inactive")->data.get(); + 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* 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(); g_pHyprRenderer->makeEGLCurrent(); @@ -314,13 +322,13 @@ void refreshGroupBarGradients() { m_tGradientLockedInactive.destroyTexture(); } - if (!*PENABLED || !*PGRADIENTS) + if (!**PENABLED || !**PGRADIENTS) return; - renderGradientTo(m_tGradientActive, PGROUPCOLACTIVE); - renderGradientTo(m_tGradientInactive, PGROUPCOLINACTIVE); - renderGradientTo(m_tGradientLockedActive, PGROUPCOLACTIVELOCKED); - renderGradientTo(m_tGradientLockedInactive, PGROUPCOLINACTIVELOCKED); + renderGradientTo(m_tGradientActive, GROUPCOLACTIVE); + renderGradientTo(m_tGradientInactive, GROUPCOLINACTIVE); + renderGradientTo(m_tGradientLockedActive, GROUPCOLACTIVELOCKED); + renderGradientTo(m_tGradientLockedInactive, GROUPCOLINACTIVELOCKED); } bool CHyprGroupBarDecoration::onBeginWindowDragOnDeco(const Vector2D& pos) { @@ -452,11 +460,10 @@ bool CHyprGroupBarDecoration::onMouseButtonOnDeco(const Vector2D& pos, wlr_point } bool CHyprGroupBarDecoration::onScrollOnDeco(const Vector2D& pos, wlr_pointer_axis_event* e) { - static auto* const PGROUPBARSCROLLING = &g_pConfigManager->getConfigValuePtr("group:groupbar:scrolling")->intValue; + static auto* const PGROUPBARSCROLLING = (Hyprlang::INT* const*)g_pConfigManager->getConfigValuePtr("group:groupbar:scrolling"); - if (!*PGROUPBARSCROLLING || !m_pWindow->m_sGroupData.pNextWindow) { + if (!**PGROUPBARSCROLLING || !m_pWindow->m_sGroupData.pNextWindow) return false; - } if (e->delta > 0) m_pWindow->setGroupCurrent(m_pWindow->m_sGroupData.pNextWindow); |