From 14dec2e15c9d8cbcc13032348398ffed969e67c1 Mon Sep 17 00:00:00 2001 From: outfoxxed Date: Tue, 5 Sep 2023 02:12:35 -0700 Subject: [PATCH] Add support for hyprland movewindow dispatcher Note that this support is worse than hy3:movwindow and you should still use that. This fixes the api breakage though. --- flake.lock | 20 ++++++++++---------- src/Hy3Layout.cpp | 44 +++++++++++++++++++++++++++++++------------- src/Hy3Layout.hpp | 2 ++ 3 files changed, 43 insertions(+), 23 deletions(-) diff --git a/flake.lock b/flake.lock index af24f17..0356e87 100644 --- a/flake.lock +++ b/flake.lock @@ -9,11 +9,11 @@ "xdph": "xdph" }, "locked": { - "lastModified": 1692123043, - "narHash": "sha256-6YoTjAZgtJb9OzKrZxtLxjfYiGWSqMmh1Wyh9dvwXn8=", + "lastModified": 1693851147, + "narHash": "sha256-kkI7FXwKufOmNIIQQHr868tneIV8ggqupBA0EJ/jAuI=", "owner": "hyprwm", "repo": "Hyprland", - "rev": "4986d74ef201171a930c312a8e3b72a22d9b84ee", + "rev": "4ddcda93f5887792a953332bf1b487e4b2c3b4ed", "type": "github" }, "original": { @@ -49,11 +49,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1691654369, - "narHash": "sha256-gSILTEx1jRaJjwZxRlnu3ZwMn1FVNk80qlwiCX8kmpo=", + "lastModified": 1693158576, + "narHash": "sha256-aRTTXkYvhXosGx535iAFUaoFboUrZSYb1Ooih/auGp0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "ce5e4a6ef2e59d89a971bc434ca8ca222b9c7f5e", + "rev": "a999c1cc0c9eb2095729d5aa03e0d8f7ed256780", "type": "github" }, "original": { @@ -87,18 +87,18 @@ "flake": false, "locked": { "host": "gitlab.freedesktop.org", - "lastModified": 1691073628, - "narHash": "sha256-LlxE3o3UzRY7APYVLGNKM30DBMcDifCRIQiMVSbYLIc=", + "lastModified": 1692976565, + "narHash": "sha256-eBKkG7tMxg92NskEn8dHRFY245JwjirWRoOZzW6DnUw=", "owner": "wlroots", "repo": "wlroots", - "rev": "c74f89d4f84bfed0284d3908aee5d207698c70c5", + "rev": "717ded9bb0191ea31bf4368be32e7a15fe1b8294", "type": "gitlab" }, "original": { "host": "gitlab.freedesktop.org", "owner": "wlroots", "repo": "wlroots", - "rev": "c74f89d4f84bfed0284d3908aee5d207698c70c5", + "rev": "717ded9bb0191ea31bf4368be32e7a15fe1b8294", "type": "gitlab" } }, diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp index 12a67ab..a3af261 100644 --- a/src/Hy3Layout.cpp +++ b/src/Hy3Layout.cpp @@ -673,6 +673,20 @@ void Hy3Layout::switchWindows(CWindow* pWindowA, CWindow* pWindowB) { // todo } +void Hy3Layout::moveWindowTo(CWindow* window, const std::string& direction) { + auto* node = this->getNodeFromWindow(window); + if (node == nullptr) return; + + ShiftDirection shift; + if (direction == "l") shift = ShiftDirection::Left; + else if (direction == "r") shift = ShiftDirection::Right; + else if (direction == "u") shift = ShiftDirection::Up; + else if (direction == "d") shift = ShiftDirection::Down; + else return; + + this->shiftNode(*node, shift, false, false); +} + void Hy3Layout::alterSplitRatio(CWindow* pWindow, float delta, bool exact) { // todo } @@ -874,24 +888,28 @@ void Hy3Layout::changeGroupEphemeralityOn(Hy3Node& node, bool ephemeral) { ); } +void Hy3Layout::shiftNode(Hy3Node& node, ShiftDirection direction, bool once, bool visible) { + if (once && node.parent != nullptr && node.parent->data.as_group.children.size() == 1) { + if (node.parent->parent == nullptr) { + node.parent->data.as_group.setLayout(Hy3GroupLayout::SplitH); + node.parent->recalcSizePosRecursive(); + } else { + auto* node2 = node.parent; + Hy3Node::swapData(node, *node2); + node2->layout->nodes.remove(node); + node2->recalcSizePosRecursive(); + } + } else { + this->shiftOrGetFocus(node, direction, true, once, visible); + } +} + void Hy3Layout::shiftWindow(int workspace, ShiftDirection direction, bool once, bool visible) { auto* node = this->getWorkspaceFocusedNode(workspace); Debug::log(LOG, "ShiftWindow %p %d", node, direction); if (node == nullptr) return; - if (once && node->parent != nullptr && node->parent->data.as_group.children.size() == 1) { - if (node->parent->parent == nullptr) { - node->parent->data.as_group.setLayout(Hy3GroupLayout::SplitH); - node->parent->recalcSizePosRecursive(); - } else { - auto* node2 = node->parent; - Hy3Node::swapData(*node, *node2); - node2->layout->nodes.remove(*node); - node2->recalcSizePosRecursive(); - } - } else { - this->shiftOrGetFocus(*node, direction, true, once, visible); - } + this->shiftNode(*node, direction, once, visible); } void Hy3Layout::shiftFocus(int workspace, ShiftDirection direction, bool visible) { diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp index 83f81c7..f532f73 100644 --- a/src/Hy3Layout.hpp +++ b/src/Hy3Layout.hpp @@ -79,6 +79,7 @@ public: virtual std::any layoutMessage(SLayoutMessageHeader header, std::string content); virtual SWindowRenderLayoutHints requestRenderHints(CWindow*); virtual void switchWindows(CWindow*, CWindow*); + virtual void moveWindowTo(CWindow*, const std::string& direction); virtual void alterSplitRatio(CWindow*, float, bool); virtual std::string getLayoutName(); virtual CWindow* getNextWindowCandidate(CWindow*); @@ -102,6 +103,7 @@ public: void toggleTabGroupOn(Hy3Node&); 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 changeFocus(int workspace, FocusShift);