32cfd86d13f7ee756ae2f0c2074e2534c1e124f4
- Author
- outfoxxed <outfoxxed@outfoxxed.me>
- Committer
- outfoxxed <outfoxxed@outfoxxed.me>
- Date
Message
Diff
This diff is truncated to protect this page.
1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
2index 6782798eeedf33e4d97c42c84ff0aee9a6accbfe..1b9ad1f55340b0980caf259f98c936c2d1c8c3aa 100644
3--- a/src/Hy3Layout.cpp
4+++ b/src/Hy3Layout.cpp
5@@ -577,196 +577,169 @@ void Hy3Layout::makeGroupOn(CWindow* window, Hy3GroupLayout layout) {
6 return;
7 }
8
9-void Hy3Layout::shiftWindow(CWindow* window, ShiftDirection direction) {
10- Debug::log(LOG, "ShiftWindow %p %d", window, direction);
11+Hy3Node* shiftOrGetFocus(Hy3Node& node, ShiftDirection direction, bool shift);
12+
13+void Hy3Layout::shiftFocus(CWindow* window, ShiftDirection direction) {
14+ Debug::log(LOG, "ShiftFocus %p %d", window, direction);
15 auto* node = this->getNodeFromWindow(window);
16 if (node == nullptr) return;
17
18- auto& group = node->parent->data.as_group;
19+ Hy3Node* target;
20+ if ((target = shiftOrGetFocus(*node, direction, false))) {
21+ g_pCompositor->focusWindow(target->data.as_window);
22+ }
23+}
24
25- enum class ShiftAction {
26- ShiftUp,
27- ShiftDown,
28- BreakGroup,
29- };
30+void Hy3Layout::shiftWindow(CWindow* window, ShiftDirection direction) {
31+ Debug::log(LOG, "ShiftWindow %p %d", window, direction);
32+ auto* node = this->getNodeFromWindow(window);
33+ if (node == nullptr) return;
34
35- ShiftAction action;
36
37- switch (group.layout) {
38- case Hy3GroupLayout::SplitH:
39- case Hy3GroupLayout::Tabbed:
40- switch (direction) {
41- case ShiftDirection::Left:
42- action = ShiftAction::ShiftUp;
43- break;
44- case ShiftDirection::Right:
45- action = ShiftAction::ShiftDown;
46- break;
47- case ShiftDirection::Up:
48- case ShiftDirection::Down:
49- action = ShiftAction::BreakGroup;
50- break;
51- }
52- break;
53- case Hy3GroupLayout::SplitV:
54- switch (direction) {
55- case ShiftDirection::Up:
56- action = ShiftAction::ShiftUp;
57- break;
58- case ShiftDirection::Down:
59- action = ShiftAction::ShiftDown;
60- break;
61- case ShiftDirection::Left:
62- case ShiftDirection::Right:
63- action = ShiftAction::BreakGroup;
64- break;
65- }
66- break;
67- }
68+ shiftOrGetFocus(*node, direction, true);
69+}
70
71- Debug::log(LOG, "ShiftWindow 2 %d", action);
72+Hy3Node* findCommonParentNode(Hy3Node& a, Hy3Node& b) {
73+ Hy3Node* last_node = nullptr;
74+ Hy3Node* searcher = &a;
75
76- Hy3Node* target_group;
77- switch (action) {
78- case ShiftAction::ShiftUp:
79- if (node == group.children.front()) {
80- action = ShiftAction::BreakGroup;
81- } else {
82- auto iter = std::find(group.children.begin(), group.children.end(), node);
83- auto target = *std::prev(iter);
84- if (target->data.type == Hy3NodeData::Group) {
85- target_group = target;
86- goto entergroup;
87- } else {
88- swapNodeData(*node, *target);
89- }
90- }
91- break;
92- case ShiftAction::ShiftDown:
93- if (node == group.children.back()) {
94- action = ShiftAction::BreakGroup;
95- } else {
96- auto iter = std::find(group.children.begin(), group.children.end(), node);
97- auto target = *std::next(iter);
98- if (target->data.type == Hy3NodeData::Group) {
99- target_group = target;
100- goto entergroup;
101- } else {
102- swapNodeData(*node, *target);
103+ while (searcher != nullptr) {
104+ if (searcher->data.type == Hy3NodeData::Group) {
105diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
106index 37aab20603be1236c3d7e2e54d5d67c78d9a1acf..f2bd79812693f79311e5099cf89cc6e305702abf 100644
107--- a/src/Hy3Layout.hpp
108+++ b/src/Hy3Layout.hpp
109@@ -104,8 +104,7 @@ public:
110
111 void makeGroupOn(CWindow*, Hy3GroupLayout);
112 void shiftWindow(CWindow*, ShiftDirection);
113-
114- Hy3Node* findCommonParentNode(Hy3Node&, Hy3Node&);
115+ void shiftFocus(CWindow*, ShiftDirection);
116
117 private:
118 std::list<Hy3Node> nodes;
119diff --git a/src/main.cpp b/src/main.cpp
120index 2bda5ec22e9ae90bee7707f2948537a4c190c38d..f5f2321eb34acebffa3b82e9be7d1ef6f3d9a0f1 100644
121--- a/src/main.cpp
122+++ b/src/main.cpp
123@@ -50,6 +50,21 @@ void dispatch_movewindow(std::string arg) {
124 }
125 }
126
127+void dispatch_movefocus(std::string arg) {
128+ CWindow* window = window_for_action();
129+ if (window == nullptr) return;
130+
131+ if (arg == "l") {
132+ g_Hy3Layout->shiftFocus(window, ShiftDirection::Left);
133+ } else if (arg == "u") {
134+ g_Hy3Layout->shiftFocus(window, ShiftDirection::Up);
135+ } else if (arg == "d") {
136+ g_Hy3Layout->shiftFocus(window, ShiftDirection::Down);
137+ } else if (arg == "r") {
138+ g_Hy3Layout->shiftFocus(window, ShiftDirection::Right);
139+ }
140+}
141+
142 APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
143 PHANDLE = handle;
144
145@@ -57,6 +72,7 @@ APICALL EXPORT PLUGIN_DESCRIPTION_INFO PLUGIN_INIT(HANDLE handle) {
146 HyprlandAPI::addLayout(PHANDLE, "hy3", g_Hy3Layout.get());
147
148 HyprlandAPI::addDispatcher(PHANDLE, "hy3_makegroup", dispatch_makegroup);
149+ HyprlandAPI::addDispatcher(PHANDLE, "hy3_movefocus", dispatch_movefocus);
150 HyprlandAPI::addDispatcher(PHANDLE, "hy3_movewindow", dispatch_movewindow);
151
152 return {"hy3", "i3 like layout for hyprland", "outfoxxed", "0.1"};