From fdc4749ac7010a05ed4cc9f7450dcf93aeb65999 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Wed, 3 Apr 2024 21:45:40 -0700 Subject: [PATCH] fixup: fix breakage from hyprland#5380 --- flake.lock | 7 +- flake.nix | 2 +- src/Hy3Layout.cpp | 163 +++++++++++++++++++++----------------------- src/Hy3Layout.hpp | 37 +++++----- src/Hy3Node.cpp | 11 ++- src/Hy3Node.hpp | 2 +- src/TabGroup.cpp | 12 ++-- src/TabGroup.hpp | 2 +- src/dispatchers.cpp | 64 +++++++++-------- src/globals.hpp | 1 + 10 files changed, 143 insertions(+), 158 deletions(-) diff --git a/flake.lock b/flake.lock index f3a4c36..ce30305 100644 --- a/flake.lock +++ b/flake.lock @@ -37,16 +37,15 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1711996237, - "narHash": "sha256-oa82eFINs1HkEnx3Nu+GEQQxXXNkJzSci3HZU//OJ2Y=", + "lastModified": 1712189807, + "narHash": "sha256-hmEBPDk1GbpPzpa0gLhJ0XJ5rvt+dMddKNQGr9J8XyA=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "3875679755014997776e091ff8903acfb311dd2f", + "rev": "b7d71bc0e1084bc1a296ae906503709a74fde4d9", "type": "github" }, "original": { "owner": "hyprwm", - "ref": "v0.38.0", "repo": "Hyprland", "type": "github" } diff --git a/flake.nix b/flake.nix index f675e78..a375308 100644 --- a/flake.nix +++ b/flake.nix @@ -1,6 +1,6 @@ { inputs = { - hyprland.url = "github:hyprwm/Hyprland?ref=v0.38.0"; + hyprland.url = "github:hyprwm/Hyprland"; }; outputs = { self, hyprland, ... }: let diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 5fc3346..a1f54a0 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -36,7 +37,7 @@ bool performContainment(Hy3Node& node, bool contained, CWindow* window) { node.layout->nodes.push_back({ .parent = &node, .data = window, - .workspace_id = node.workspace_id, + .workspace = node.workspace, .layout = node.layout, }); @@ -78,7 +79,7 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { (uintptr_t) window, window->m_bIsFloating, window->m_iMonitorID, - window->m_iWorkspaceID + window->m_pWorkspace->m_iID ); if (window->m_bIsFloating) return; @@ -97,7 +98,7 @@ void Hy3Layout::onWindowCreatedTiling(CWindow* window, eDirection) { this->nodes.push_back({ .parent = nullptr, .data = window, - .workspace_id = window->m_iWorkspaceID, + .workspace = window->m_pWorkspace, .layout = this, }); @@ -115,26 +116,24 @@ void Hy3Layout::insertNode(Hy3Node& node) { return; } - auto* workspace = g_pCompositor->getWorkspaceByID(node.workspace_id); - - if (workspace == nullptr) { + if (!valid(node.workspace)) { hy3_log( ERR, "insertNode called for node {:x} with invalid workspace id {}", (uintptr_t) &node, - node.workspace_id + node.workspace->m_iID ); return; } node.reparenting = true; - auto* monitor = g_pCompositor->getMonitorFromID(workspace->m_iMonitorID); + auto* monitor = g_pCompositor->getMonitorFromID(node.workspace->m_iMonitorID); Hy3Node* opening_into; Hy3Node* opening_after = nullptr; - auto* root = this->getWorkspaceRootGroup(node.workspace_id); + auto* root = this->getWorkspaceRootGroup(node.workspace); if (root != nullptr) { opening_after = root->getFocusedNode(); @@ -148,7 +147,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { if (opening_after == nullptr) { if (g_pCompositor->m_pLastWindow != nullptr - && g_pCompositor->m_pLastWindow->m_iWorkspaceID == node.workspace_id + && g_pCompositor->m_pLastWindow->m_pWorkspace == node.workspace && !g_pCompositor->m_pLastWindow->m_bIsFloating && (node.data.type == Hy3NodeType::Window || g_pCompositor->m_pLastWindow != node.data.as_window) @@ -161,7 +160,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { RESERVED_EXTENTS | INPUT_EXTENTS ); - if (mouse_window != nullptr && mouse_window->m_iWorkspaceID == node.workspace_id) { + if (mouse_window != nullptr && mouse_window->m_pWorkspace == node.workspace) { opening_after = this->getNodeFromWindow(mouse_window); } } @@ -178,7 +177,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { if (opening_after != nullptr) { opening_into = opening_after->parent; } else { - if ((opening_into = this->getWorkspaceRootGroup(node.workspace_id)) == nullptr) { + if ((opening_into = this->getWorkspaceRootGroup(node.workspace)) == nullptr) { static const auto tab_first_window = ConfigValue("plugin:hy3:tab_first_window"); @@ -191,7 +190,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { .data = height > width ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH, .position = monitor->vecPosition + monitor->vecReservedTopLeft, .size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight, - .workspace_id = node.workspace_id, + .workspace = node.workspace, .layout = this, }); @@ -203,7 +202,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { .data = Hy3GroupLayout::Tabbed, .position = parent.position, .size = parent.size, - .workspace_id = node.workspace_id, + .workspace = node.workspace, .layout = this, }); @@ -220,14 +219,14 @@ void Hy3Layout::insertNode(Hy3Node& node) { return; } - if (opening_into->workspace_id != node.workspace_id) { + if (opening_into->workspace != node.workspace) { hy3_log( WARN, "opening_into node ({:x}) is on workspace {} which does not match the new window " "(workspace {})", (uintptr_t) opening_into, - opening_into->workspace_id, - node.workspace_id + opening_into->workspace->m_iID, + node.workspace->m_iID ); } @@ -244,7 +243,7 @@ void Hy3Layout::insertNode(Hy3Node& node) { auto& target_group = opening_into->data.as_group; if (*at_enable && opening_after != nullptr && target_group.children.size() > 1 && target_group.layout != Hy3GroupLayout::Tabbed - && this->shouldAutotileWorkspace(opening_into->workspace_id)) + && this->shouldAutotileWorkspace(opening_into->workspace)) { auto is_horizontal = target_group.layout == Hy3GroupLayout::SplitH; auto trigger = is_horizontal ? *at_trigger_width : *at_trigger_height; @@ -380,7 +379,7 @@ void Hy3Layout::recalculateMonitor(const int& monitor_id) { top_node->recalcSizePosRecursive(); } - top_node = this->getWorkspaceRootGroup(monitor->specialWorkspaceID); + top_node = this->getWorkspaceRootGroup(monitor->activeSpecialWorkspace); if (top_node != nullptr) { top_node->position = monitor->vecPosition + monitor->vecReservedTopLeft; @@ -500,15 +499,14 @@ void Hy3Layout::fullscreenRequestForWindow( bool on ) { if (!g_pCompositor->windowValidMapped(window)) return; - if (on == window->m_bIsFullscreen || g_pCompositor->isWorkspaceSpecial(window->m_iWorkspaceID)) + if (on == window->m_bIsFullscreen || window->m_pWorkspace->m_bIsSpecialWorkspace) return; const auto monitor = g_pCompositor->getMonitorFromID(window->m_iMonitorID); - const auto workspace = g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID); - if (workspace->m_bHasFullscreenWindow && on) return; + if (window->m_pWorkspace->m_bHasFullscreenWindow && on) return; window->m_bIsFullscreen = on; - workspace->m_bHasFullscreenWindow = !workspace->m_bHasFullscreenWindow; + window->m_pWorkspace->m_bHasFullscreenWindow = !window->m_pWorkspace->m_bHasFullscreenWindow; if (!window->m_bIsFullscreen) { auto* node = this->getNodeFromWindow(window); @@ -526,7 +524,7 @@ void Hy3Layout::fullscreenRequestForWindow( window->m_sSpecialRenderData.decorate = true; } } else { - workspace->m_efFullscreenMode = fullscreen_mode; + window->m_pWorkspace->m_efFullscreenMode = fullscreen_mode; // save position and size if floating if (window->m_bIsFloating) { @@ -565,7 +563,7 @@ void Hy3Layout::fullscreenRequestForWindow( .size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight, .gap_topleft_offset = gap_pos_offset, .gap_bottomright_offset = gap_size_offset, - .workspace_id = window->m_iWorkspaceID, + .workspace = window->m_pWorkspace, }; this->applyNodeDataToWindow(&fakeNode); @@ -628,17 +626,15 @@ void Hy3Layout::alterSplitRatio(CWindow* pWindow, float delta, bool exact) { std::string Hy3Layout::getLayoutName() { return "hy3"; } CWindow* Hy3Layout::getNextWindowCandidate(CWindow* window) { - auto* workspace = g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID); - - if (workspace->m_bHasFullscreenWindow) { - return g_pCompositor->getFullscreenWindowOnWorkspace(window->m_iWorkspaceID); + if (window->m_pWorkspace->m_bHasFullscreenWindow) { + return g_pCompositor->getFullscreenWindowOnWorkspace(window->m_pWorkspace->m_iID); } // return the first floating window on the same workspace that has not asked not to be focused if (window->m_bIsFloating) { for (auto& w: g_pCompositor->m_vWindows | std::views::reverse) { if (w->m_bIsMapped && !w->isHidden() && w->m_bIsFloating && w->m_iX11Type != 2 - && w->m_iWorkspaceID == window->m_iWorkspaceID && !w->m_bX11ShouldntFocus + && w->m_pWorkspace == window->m_pWorkspace && !w->m_bX11ShouldntFocus && !w->m_sAdditionalConfigData.noFocus && w.get() != window) { return w.get(); @@ -646,7 +642,7 @@ CWindow* Hy3Layout::getNextWindowCandidate(CWindow* window) { } } - auto* node = this->getWorkspaceFocusedNode(window->m_iWorkspaceID, true); + auto* node = this->getWorkspaceFocusedNode(window->m_pWorkspace, true); if (node == nullptr) return nullptr; switch (node->data.type) { @@ -706,7 +702,7 @@ void Hy3Layout::onDisable() { } void Hy3Layout::makeGroupOnWorkspace( - int workspace, + const PHLWORKSPACE& workspace, Hy3GroupLayout layout, GroupEphemeralityOption ephemeral ) { @@ -714,40 +710,40 @@ void Hy3Layout::makeGroupOnWorkspace( this->makeGroupOn(node, layout, ephemeral); } -void Hy3Layout::makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption ephemeral) { +void Hy3Layout::makeOppositeGroupOnWorkspace(const PHLWORKSPACE& workspace, GroupEphemeralityOption ephemeral) { auto* node = this->getWorkspaceFocusedNode(workspace); this->makeOppositeGroupOn(node, ephemeral); } -void Hy3Layout::changeGroupOnWorkspace(int workspace, Hy3GroupLayout layout) { +void Hy3Layout::changeGroupOnWorkspace(const PHLWORKSPACE& workspace, Hy3GroupLayout layout) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; this->changeGroupOn(*node, layout); } -void Hy3Layout::untabGroupOnWorkspace(int workspace) { +void Hy3Layout::untabGroupOnWorkspace(const PHLWORKSPACE& workspace) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; this->untabGroupOn(*node); } -void Hy3Layout::toggleTabGroupOnWorkspace(int workspace) { +void Hy3Layout::toggleTabGroupOnWorkspace(const PHLWORKSPACE& workspace) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; this->toggleTabGroupOn(*node); } -void Hy3Layout::changeGroupToOppositeOnWorkspace(int workspace) { +void Hy3Layout::changeGroupToOppositeOnWorkspace(const PHLWORKSPACE& workspace) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; this->changeGroupToOppositeOn(*node); } -void Hy3Layout::changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral) { +void Hy3Layout::changeGroupEphemeralityOnWorkspace(const PHLWORKSPACE& workspace, bool ephemeral) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; @@ -868,19 +864,18 @@ void Hy3Layout::shiftNode(Hy3Node& node, ShiftDirection direction, bool once, bo } } -void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, bool visible) { +void Hy3Layout::shiftWindow(const PHLWORKSPACE& workspace, ShiftDirection direction, bool once, bool visible) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; this->shiftNode(*node, direction, once, visible); } -void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible) { +void Hy3Layout::shiftFocus(const PHLWORKSPACE& workspace, ShiftDirection direction, bool visible) { auto* current_window = g_pCompositor->m_pLastWindow; if (current_window != nullptr) { - auto* p_workspace = g_pCompositor->getWorkspaceByID(current_window->m_iWorkspaceID); - if (p_workspace->m_bHasFullscreenWindow) return; + if (current_window->m_pWorkspace->m_bHasFullscreenWindow) return; if (current_window->m_bIsFloating) { auto* next_window = g_pCompositor->getWindowInDirection( @@ -908,12 +903,12 @@ void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible } } -void changeNodeWorkspaceRecursive(Hy3Node& node, CWorkspace* workspace) { - node.workspace_id = workspace->m_iID; +void changeNodeWorkspaceRecursive(Hy3Node& node, const PHLWORKSPACE& workspace) { + node.workspace = workspace; if (node.data.type == Hy3NodeType::Window) { auto* window = node.data.as_window; - window->moveToWorkspace(workspace->m_iID); + window->moveToWorkspace(workspace); window->updateToplevel(); window->updateDynamicRules(); } else { @@ -923,42 +918,39 @@ void changeNodeWorkspaceRecursive(Hy3Node& node, CWorkspace* workspace) { } } -void Hy3Layout::moveNodeToWorkspace(int origin, std::string wsname, bool follow) { +void Hy3Layout::moveNodeToWorkspace(const PHLWORKSPACE& origin, std::string wsname, bool follow) { std::string target_name; - auto target = getWorkspaceIDFromString(wsname, target_name); + auto target_id = getWorkspaceIDFromString(wsname, target_name); - if (target == WORKSPACE_INVALID) { + if (target_id == WORKSPACE_INVALID) { hy3_log(ERR, "moveNodeToWorkspace called with invalid workspace {}", wsname); return; } - if (origin == target) return; + auto workspace = g_pCompositor->getWorkspaceByID(target_id); + + if (origin == workspace) return; auto* node = this->getWorkspaceFocusedNode(origin); auto* focused_window = g_pCompositor->m_pLastWindow; auto* focused_window_node = this->getNodeFromWindow(focused_window); - auto* workspace = g_pCompositor->getWorkspaceByID(target); + auto origin_ws = node != nullptr ? node->workspace + : focused_window != nullptr ? focused_window->m_pWorkspace + : nullptr; - auto wsid = node != nullptr ? node->workspace_id - : focused_window != nullptr ? focused_window->m_iWorkspaceID - : WORKSPACE_INVALID; - - if (wsid == WORKSPACE_INVALID) return; - - auto* origin_ws = g_pCompositor->getWorkspaceByID(wsid); + if (!valid(origin_ws)) return; if (workspace == nullptr) { - hy3_log(LOG, "creating target workspace {} for node move", target); + hy3_log(LOG, "creating target workspace {} for node move", target_id); - workspace = g_pCompositor->createNewWorkspace(target, origin_ws->m_iMonitorID, target_name); + workspace = g_pCompositor->createNewWorkspace(target_id, origin_ws->m_iMonitorID, target_name); } // floating or fullscreen if (focused_window != nullptr && (focused_window_node == nullptr || focused_window->m_bIsFullscreen)) { - hy3_log(LOG, "{:x}, {:x}", (uintptr_t) focused_window, (uintptr_t) workspace); g_pCompositor->moveWindowToWorkspaceSafe(focused_window, workspace); } else { if (node == nullptr) return; @@ -967,8 +959,8 @@ void Hy3Layout::moveNodeToWorkspace(int origin, std::string wsname, bool follow) LOG, "moving node {:x} from workspace {} to workspace {} (follow: {})", (uintptr_t) node, - origin, - target, + origin->m_iID, + workspace->m_iID, follow ); @@ -997,7 +989,7 @@ void Hy3Layout::moveNodeToWorkspace(int origin, std::string wsname, bool follow) } } -void Hy3Layout::changeFocus(int workspace, FocusShift shift) { +void Hy3Layout::changeFocus(const PHLWORKSPACE& workspace, FocusShift shift) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr) return; @@ -1117,7 +1109,7 @@ Hy3Node* findTabBarAt(Hy3Node& node, Vector2D pos, Hy3Node** focused_node) { } void Hy3Layout::focusTab( - int workspace, + const PHLWORKSPACE& workspace, TabFocus target, TabFocusMousePriority mouse, bool wrap_scroll, @@ -1209,7 +1201,7 @@ hastab: tab_node->recalcSizePosRecursive(); } -void Hy3Layout::setNodeSwallow(int workspace, SetSwallowOption option) { +void Hy3Layout::setNodeSwallow(const PHLWORKSPACE& workspace, SetSwallowOption option) { auto* node = this->getWorkspaceFocusedNode(workspace); if (node == nullptr || node->parent == nullptr) return; @@ -1221,7 +1213,7 @@ void Hy3Layout::setNodeSwallow(int workspace, SetSwallowOption option) { } } -void Hy3Layout::killFocusedNode(int workspace) { +void Hy3Layout::killFocusedNode(const PHLWORKSPACE& workspace) { if (g_pCompositor->m_pLastWindow != nullptr && g_pCompositor->m_pLastWindow->m_bIsFloating) { g_pCompositor->closeWindow(g_pCompositor->m_pLastWindow); } else { @@ -1238,11 +1230,10 @@ void Hy3Layout::killFocusedNode(int workspace) { } } -void Hy3Layout::expand(int workspace_id, ExpandOption option, ExpandFullscreenOption fs_option) { - auto* node = this->getWorkspaceFocusedNode(workspace_id, false, true); +void Hy3Layout::expand(const PHLWORKSPACE& workspace, ExpandOption option, ExpandFullscreenOption fs_option) { + auto* node = this->getWorkspaceFocusedNode(workspace, false, true); if (node == nullptr) return; - const auto workspace = g_pCompositor->getWorkspaceByID(workspace_id); const auto monitor = g_pCompositor->getMonitorFromID(workspace->m_iMonitorID); switch (option) { @@ -1300,7 +1291,7 @@ void Hy3Layout::expand(int workspace_id, ExpandOption option, ExpandFullscreenOp fullscreen: if (node->data.type != Hy3NodeType::Window) return; window = node->data.as_window; - if (!window->m_bIsFullscreen || g_pCompositor->isWorkspaceSpecial(window->m_iWorkspaceID)) return; + if (!window->m_bIsFullscreen || window->m_pWorkspace->m_bIsSpecialWorkspace) return; if (workspace->m_bHasFullscreenWindow) return; @@ -1325,7 +1316,7 @@ fsupdate: bool Hy3Layout::shouldRenderSelected(CWindow* window) { if (window == nullptr) return false; - auto* root = this->getWorkspaceRootGroup(window->m_iWorkspaceID); + auto* root = this->getWorkspaceRootGroup(window->m_pWorkspace); if (root == nullptr || root->data.as_group.focused_child == nullptr) return false; auto* focused = root->getFocusedNode(); if (focused == nullptr @@ -1344,9 +1335,9 @@ bool Hy3Layout::shouldRenderSelected(CWindow* window) { } } -Hy3Node* Hy3Layout::getWorkspaceRootGroup(const int& workspace) { +Hy3Node* Hy3Layout::getWorkspaceRootGroup(const PHLWORKSPACE& workspace) { for (auto& node: this->nodes) { - if (node.workspace_id == workspace && node.parent == nullptr + if (node.workspace == workspace && node.parent == nullptr && node.data.type == Hy3NodeType::Group && !node.reparenting) { return &node; @@ -1357,7 +1348,7 @@ Hy3Node* Hy3Layout::getWorkspaceRootGroup(const int& workspace) { } Hy3Node* Hy3Layout::getWorkspaceFocusedNode( - const int& workspace, + const PHLWORKSPACE& workspace, bool ignore_group_focus, bool stop_at_expanded ) { @@ -1449,21 +1440,19 @@ Hy3Node* Hy3Layout::getNodeFromWindow(CWindow* window) { void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { if (node->data.type != Hy3NodeType::Window) return; auto* window = node->data.as_window; - auto root_node = this->getWorkspaceRootGroup(window->m_iWorkspaceID); + auto root_node = this->getWorkspaceRootGroup(window->m_pWorkspace); CMonitor* monitor = nullptr; - auto* workspace = g_pCompositor->getWorkspaceByID(node->workspace_id); - - if (g_pCompositor->isWorkspaceSpecial(node->workspace_id)) { + if (node->workspace->m_bIsSpecialWorkspace) { for (auto& m: g_pCompositor->m_vMonitors) { - if (m->specialWorkspaceID == node->workspace_id) { + if (m->activeSpecialWorkspace == node->workspace) { monitor = m.get(); break; } } } else { - monitor = g_pCompositor->getMonitorFromID(workspace->m_iMonitorID); + monitor = g_pCompositor->getMonitorFromID(node->workspace->m_iMonitorID); } if (monitor == nullptr) { @@ -1476,7 +1465,7 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { return; } - const auto workspace_rules = g_pConfigManager->getWorkspaceRulesFor(workspace); + const auto workspace_rules = g_pConfigManager->getWorkspaceRulesFor(node->workspace); // clang-format off static const auto gaps_in = ConfigValue("general:gaps_in"); @@ -1507,10 +1496,10 @@ void Hy3Layout::applyNodeDataToWindow(Hy3Node* node, bool no_animation) { auto only_node = root_node != nullptr && root_node->data.as_group.children.size() == 1 && root_node->data.as_group.children.front()->data.type == Hy3NodeType::Window; - if (!g_pCompositor->isWorkspaceSpecial(window->m_iWorkspaceID) + if (!window->m_pWorkspace->m_bIsSpecialWorkspace && ((*no_gaps_when_only != 0 && (only_node || window->m_bIsFullscreen)) || (window->m_bIsFullscreen - && g_pCompositor->getWorkspaceByID(window->m_iWorkspaceID)->m_efFullscreenMode + && window->m_pWorkspace->m_efFullscreenMode == FULLSCREEN_FULL))) { window->m_sSpecialRenderData.border = *no_gaps_when_only == 2; @@ -1640,7 +1629,7 @@ Hy3Node* Hy3Layout::shiftOrGetFocus( .data = shiftIsVertical(direction) ? Hy3GroupLayout::SplitV : Hy3GroupLayout::SplitH, .position = break_parent->position, .size = break_parent->size, - .workspace_id = break_parent->workspace_id, + .workspace = break_parent->workspace, .layout = this, }); @@ -1848,10 +1837,10 @@ void Hy3Layout::updateAutotileWorkspaces() { } } -bool Hy3Layout::shouldAutotileWorkspace(int workspace_id) { +bool Hy3Layout::shouldAutotileWorkspace(const PHLWORKSPACE& workspace) { if (this->autotile.workspace_blacklist) { - return !this->autotile.workspaces.contains(workspace_id); + return !this->autotile.workspaces.contains(workspace->m_iID); } else { - return this->autotile.workspaces.empty() || this->autotile.workspaces.contains(workspace_id); + return this->autotile.workspaces.empty() || this->autotile.workspaces.contains(workspace->m_iID); } } diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index d269229..93333c3 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -1,5 +1,6 @@ #pragma once +#include class Hy3Layout; enum class GroupEphemeralityOption { @@ -95,13 +96,13 @@ public: virtual void onDisable(); void insertNode(Hy3Node& node); - void makeGroupOnWorkspace(int workspace, Hy3GroupLayout, GroupEphemeralityOption); - void makeOppositeGroupOnWorkspace(int workspace, GroupEphemeralityOption); - void changeGroupOnWorkspace(int workspace, Hy3GroupLayout); - void untabGroupOnWorkspace(int workspace); - void toggleTabGroupOnWorkspace(int workspace); - void changeGroupToOppositeOnWorkspace(int workspace); - void changeGroupEphemeralityOnWorkspace(int workspace, bool ephemeral); + void makeGroupOnWorkspace(const PHLWORKSPACE& workspace, Hy3GroupLayout, GroupEphemeralityOption); + void makeOppositeGroupOnWorkspace(const PHLWORKSPACE& workspace, GroupEphemeralityOption); + void changeGroupOnWorkspace(const PHLWORKSPACE& workspace, Hy3GroupLayout); + void untabGroupOnWorkspace(const PHLWORKSPACE& workspace); + void toggleTabGroupOnWorkspace(const PHLWORKSPACE& workspace); + void changeGroupToOppositeOnWorkspace(const PHLWORKSPACE& workspace); + void changeGroupEphemeralityOnWorkspace(const PHLWORKSPACE& workspace, bool ephemeral); void makeGroupOn(Hy3Node*, Hy3GroupLayout, GroupEphemeralityOption); void makeOppositeGroupOn(Hy3Node*, GroupEphemeralityOption); void changeGroupOn(Hy3Node&, Hy3GroupLayout); @@ -110,20 +111,20 @@ public: void changeGroupToOppositeOn(Hy3Node&); void changeGroupEphemeralityOn(Hy3Node&, bool ephemeral); void shiftNode(Hy3Node&, ShiftDirection, bool once, bool visible); - void shiftWindow(int workspace, ShiftDirection, bool once, bool visible); - void shiftFocus(int workspace, ShiftDirection, bool visible); - void moveNodeToWorkspace(int origin, std::string wsname, bool follow); - void changeFocus(int workspace, FocusShift); - void focusTab(int workspace, TabFocus target, TabFocusMousePriority, bool wrap_scroll, int index); - void setNodeSwallow(int workspace, SetSwallowOption); - void killFocusedNode(int workspace); - void expand(int workspace, ExpandOption, ExpandFullscreenOption); + void shiftWindow(const PHLWORKSPACE& workspace, ShiftDirection, bool once, bool visible); + void shiftFocus(const PHLWORKSPACE& workspace, ShiftDirection, bool visible); + void moveNodeToWorkspace(const PHLWORKSPACE& origin, std::string wsname, bool follow); + void changeFocus(const PHLWORKSPACE& workspace, FocusShift); + void focusTab(const PHLWORKSPACE& workspace, TabFocus target, TabFocusMousePriority, bool wrap_scroll, int index); + void setNodeSwallow(const PHLWORKSPACE& workspace, SetSwallowOption); + void killFocusedNode(const PHLWORKSPACE& workspace); + void expand(const PHLWORKSPACE& workspace, ExpandOption, ExpandFullscreenOption); bool shouldRenderSelected(CWindow*); - Hy3Node* getWorkspaceRootGroup(const int& workspace); + Hy3Node* getWorkspaceRootGroup(const PHLWORKSPACE& workspace); Hy3Node* getWorkspaceFocusedNode( - const int& workspace, + const PHLWORKSPACE& workspace, bool ignore_group_focus = false, bool stop_at_expanded = false ); @@ -146,7 +147,7 @@ private: Hy3Node* shiftOrGetFocus(Hy3Node&, ShiftDirection, bool shift, bool once, bool visible); void updateAutotileWorkspaces(); - bool shouldAutotileWorkspace(int); + bool shouldAutotileWorkspace(const PHLWORKSPACE& workspace); void resizeNode(Hy3Node*, Vector2D, ShiftDirection resize_edge_x, ShiftDirection resize_edge_y); struct { diff --git a/src/Hy3Node.cpp b/src/Hy3Node.cpp index 5eed0fc..9572d7b 100644 --- a/src/Hy3Node.cpp +++ b/src/Hy3Node.cpp @@ -290,10 +290,9 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { // clang-format on if (this->data.type == Hy3NodeType::Window && this->data.as_window->m_bIsFullscreen) { - auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); - auto* monitor = g_pCompositor->getMonitorFromID(workspace->m_iMonitorID); + auto* monitor = g_pCompositor->getMonitorFromID(this->workspace->m_iMonitorID); - if (workspace->m_efFullscreenMode == FULLSCREEN_FULL) { + if (this->workspace->m_efFullscreenMode == FULLSCREEN_FULL) { this->data.as_window->m_vRealPosition = monitor->vecPosition; this->data.as_window->m_vRealSize = monitor->vecSize; return; @@ -305,7 +304,7 @@ void Hy3Node::recalcSizePosRecursive(bool no_animation) { .size = monitor->vecSize - monitor->vecReservedTopLeft - monitor->vecReservedBottomRight, .gap_topleft_offset = gap_topleft_offset, .gap_bottomright_offset = gap_bottomright_offset, - .workspace_id = this->workspace_id, + .workspace = this->workspace, }; this->layout->applyNodeDataToWindow(&fake_node); @@ -522,7 +521,7 @@ void Hy3Node::updateTabBar(bool no_animation) { FindTopWindowInNodeResult result; findTopWindowInNode(*this, result); group.tab_bar->target_window = result.window; - if (result.window != nullptr) group.tab_bar->workspace_id = result.window->m_iWorkspaceID; + if (result.window != nullptr) group.tab_bar->workspace = result.window->m_pWorkspace; } else if (group.tab_bar != nullptr) { group.tab_bar->bar.beginDestroy(); group.tab_bar = nullptr; @@ -771,7 +770,7 @@ Hy3Node* Hy3Node::intoGroup(Hy3GroupLayout layout, GroupEphemeralityOption ephem this->layout->nodes.push_back({ .parent = this, .data = layout, - .workspace_id = this->workspace_id, + .workspace = this->workspace, .layout = this->layout, }); diff --git a/src/Hy3Node.hpp b/src/Hy3Node.hpp index 759feaf..772d01f 100644 --- a/src/Hy3Node.hpp +++ b/src/Hy3Node.hpp @@ -87,7 +87,7 @@ struct Hy3Node { Vector2D gap_topleft_offset; Vector2D gap_bottomright_offset; float size_ratio = 1.0; - int workspace_id = -1; + PHLWORKSPACE workspace = nullptr; bool hidden = false; Hy3Layout* layout = nullptr; diff --git a/src/TabGroup.cpp b/src/TabGroup.cpp index 46651dd..08fe876 100644 --- a/src/TabGroup.cpp +++ b/src/TabGroup.cpp @@ -444,12 +444,11 @@ void Hy3TabGroup::updateWithGroup(Hy3Node& node, bool warp) { void Hy3TabGroup::tick() { static const auto enter_from_top = ConfigValue("plugin:hy3:tabs:from_top"); static const auto padding = ConfigValue("plugin:hy3:tabs:padding"); - auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); this->bar.tick(); - if (workspace != nullptr) { - if (workspace->m_bHasFullscreenWindow) { + if (valid(this->workspace)) { + if (this->workspace->m_bHasFullscreenWindow) { if (this->bar.fade_opacity.goal() != 0.0) this->bar.fade_opacity = 0.0; } else { if (this->bar.fade_opacity.goal() != 1.0) this->bar.fade_opacity = 1.0; @@ -489,15 +488,14 @@ void Hy3TabGroup::renderTabBar() { static const auto padding = ConfigValue("plugin:hy3:tabs:padding"); auto* monitor = g_pHyprOpenGL->m_RenderData.pMonitor; - auto* workspace = g_pCompositor->getWorkspaceByID(this->workspace_id); auto scale = monitor->scale; auto monitor_size = monitor->vecSize; auto pos = this->pos.value() - monitor->vecPosition; auto size = this->size.value(); - if (workspace != nullptr) { - pos = pos + workspace->m_vRenderOffset.value(); + if (valid(this->workspace)) { + pos = pos + this->workspace->m_vRenderOffset.value(); } auto scaled_pos = Vector2D(std::round(pos.x * scale), std::round(pos.y * scale)); @@ -563,7 +561,7 @@ void Hy3TabGroup::renderTabBar() { } auto fade_opacity = - this->bar.fade_opacity.value() * (workspace == nullptr ? 1.0 : workspace->m_fAlpha.value()); + this->bar.fade_opacity.value() * (valid(this->workspace) ? this->workspace->m_fAlpha.value() : 1.0); auto render_entry = [&](Hy3TabBarEntry& entry) { Vector2D entry_pos = { diff --git a/src/TabGroup.hpp b/src/TabGroup.hpp index 77f7874..3d77624 100644 --- a/src/TabGroup.hpp +++ b/src/TabGroup.hpp @@ -86,7 +86,7 @@ private: class Hy3TabGroup { public: CWindow* target_window = nullptr; - int workspace_id = -1; + PHLWORKSPACE workspace = nullptr; bool hidden = false; Hy3TabBar bar; CAnimatedVariable pos; diff --git a/src/dispatchers.cpp b/src/dispatchers.cpp index 667b1cf..843b17a 100644 --- a/src/dispatchers.cpp +++ b/src/dispatchers.cpp @@ -1,27 +1,26 @@ #include #include +#include #include #include "dispatchers.hpp" #include "globals.hpp" -int workspace_for_action(bool allow_fullscreen = false) { - if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return -1; +PHLWORKSPACE workspace_for_action(bool allow_fullscreen = false) { + if (g_pLayoutManager->getCurrentLayout() != g_Hy3Layout.get()) return nullptr; - int workspace_id = g_pCompositor->m_pLastMonitor->activeWorkspace; + auto workspace = g_pCompositor->m_pLastMonitor->activeWorkspace; - if (workspace_id == -1) return -1; - auto* workspace = g_pCompositor->getWorkspaceByID(workspace_id); - if (workspace == nullptr) return -1; - if (!allow_fullscreen && workspace->m_bHasFullscreenWindow) return -1; + if (!valid(workspace)) return nullptr; + if (!allow_fullscreen && workspace->m_bHasFullscreenWindow) return nullptr; - return workspace_id; + return workspace; } void dispatch_makegroup(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -44,8 +43,8 @@ void dispatch_makegroup(std::string value) { } void dispatch_changegroup(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -65,8 +64,8 @@ void dispatch_changegroup(std::string value) { } void dispatch_setephemeral(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -84,8 +83,8 @@ std::optional parseShiftArg(std::string arg) { } void dispatch_movewindow(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -109,8 +108,8 @@ void dispatch_movewindow(std::string value) { } void dispatch_movefocus(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -120,8 +119,8 @@ void dispatch_movefocus(std::string value) { } void dispatch_move_to_workspace(std::string value) { - int origin_workspace = workspace_for_action(true); - if (origin_workspace == -1) return; + auto origin_workspace = workspace_for_action(true); + if (!valid(origin_workspace)) return; auto args = CVarList(value); @@ -134,8 +133,8 @@ void dispatch_move_to_workspace(std::string value) { } void dispatch_changefocus(std::string arg) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; if (arg == "top") g_Hy3Layout->changeFocus(workspace, FocusShift::Top); else if (arg == "bottom") g_Hy3Layout->changeFocus(workspace, FocusShift::Bottom); @@ -146,8 +145,8 @@ void dispatch_changefocus(std::string arg) { } void dispatch_focustab(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto i = 0; auto args = CVarList(value); @@ -186,8 +185,8 @@ void dispatch_focustab(std::string value) { } void dispatch_setswallow(std::string arg) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; SetSwallowOption option; if (arg == "true") { @@ -202,15 +201,15 @@ void dispatch_setswallow(std::string arg) { } void dispatch_killactive(std::string value) { - int workspace = workspace_for_action(true); - if (workspace == -1) return; + auto workspace = workspace_for_action(true); + if (!valid(workspace)) return; g_Hy3Layout->killFocusedNode(workspace); } void dispatch_expand(std::string value) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); + if (!valid(workspace)) return; auto args = CVarList(value); @@ -234,11 +233,10 @@ void dispatch_expand(std::string value) { } void dispatch_debug(std::string arg) { - int workspace = workspace_for_action(); - if (workspace == -1) return; + auto workspace = workspace_for_action(); auto* root = g_Hy3Layout->getWorkspaceRootGroup(workspace); - if (workspace == -1) { + if (!valid(workspace)) { hy3_log(LOG, "DEBUG NODES: no nodes on workspace"); } else { hy3_log(LOG, "DEBUG NODES\n{}", root->debugNode().c_str()); diff --git a/src/globals.hpp b/src/globals.hpp index 48839ca..ede0c8f 100644 --- a/src/globals.hpp +++ b/src/globals.hpp @@ -2,6 +2,7 @@ #include +#include #include #include