Diff
1diff --git a/src/Hy3Layout.cpp b/src/Hy3Layout.cpp
2index ac106b078ae1836d2f5c07d4ff6d86e1e6474e94..e9dcbc849ea4e16a6360a1dffe4a20e170c07c93 100644
3--- a/src/Hy3Layout.cpp
4+++ b/src/Hy3Layout.cpp
5@@ -1804,7 +1804,8 @@ void Hy3Layout::focusTab(
6 int workspace,
7 TabFocus target,
8 TabFocusMousePriority mouse,
9- bool wrap_scroll
10+ bool wrap_scroll,
11+ int index
12 ) {
13 auto* node = this->getWorkspaceRootGroup(workspace);
14 if (node == nullptr) return;
15@@ -1842,23 +1843,39 @@ hastab:
16 return;
17
18 auto& children = tab_node->data.as_group.children;
19- auto node_iter
20- = std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child);
21- if (node_iter == children.end()) return;
22- if (target == TabFocus::Left) {
23- if (node_iter == children.begin()) {
24- if (wrap_scroll) node_iter = std::prev(children.end());
25- else return;
26- } else node_iter = std::prev(node_iter);
27-
28- tab_focused_node = *node_iter;
29+ if (target == TabFocus::Index) {
30+ int i = 1;
31+
32+ for (auto* node: children) {
33+ if (i == index) {
34+ tab_focused_node = node;
35+ goto cont;
36+ }
37+
38+ i++;
39+ }
40+
41+ return;
42+ cont:;
43 } else {
44- if (node_iter == std::prev(children.end())) {
45- if (wrap_scroll) node_iter = children.begin();
46- else return;
47- } else node_iter = std::next(node_iter);
48+ auto node_iter
49+ = std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child);
50+ if (node_iter == children.end()) return;
51+ if (target == TabFocus::Left) {
52+ if (node_iter == children.begin()) {
53+ if (wrap_scroll) node_iter = std::prev(children.end());
54+ else return;
55+ } else node_iter = std::prev(node_iter);
56+
57+ tab_focused_node = *node_iter;
58+ } else {
59+ if (node_iter == std::prev(children.end())) {
60+ if (wrap_scroll) node_iter = children.begin();
61+ else return;
62+ } else node_iter = std::next(node_iter);
63
64- tab_focused_node = *node_iter;
65+ tab_focused_node = *node_iter;
66+ }
67 }
68 }
69
70diff --git a/src/Hy3Layout.hpp b/src/Hy3Layout.hpp
71index ac01478830b5fd552a3ce6dd78163e255b5784e7..944b2f02148f7ff3d961de9a1bf15367f48ac471 100644
72--- a/src/Hy3Layout.hpp
73+++ b/src/Hy3Layout.hpp
74@@ -35,6 +35,7 @@ enum class TabFocus {
75 MouseLocation,
76 Left,
77 Right,
78+ Index,
79 };
80
81 enum class TabFocusMousePriority {
82@@ -159,7 +160,7 @@ public:
83 void shiftWindow(int, ShiftDirection, bool);
84 void shiftFocus(int, ShiftDirection, bool);
85 void changeFocus(int, FocusShift);
86- void focusTab(int, TabFocus, TabFocusMousePriority, bool);
87+ void focusTab(int, TabFocus, TabFocusMousePriority, bool, int);
88 void killFocusedNode(int);
89
90 bool shouldRenderSelected(CWindow*);
91diff --git a/src/main.cpp b/src/main.cpp
92index 1aa5bbd97e68db0e0b1bf766b8d83535b60b8933..3b5b322aac93de0fba4453bdfcfba33a34b63690 100644
93--- a/src/main.cpp
94+++ b/src/main.cpp
95@@ -103,11 +103,18 @@ void dispatch_focustab(std::string value) {
96 TabFocus focus;
97 auto mouse = TabFocusMousePriority::Ignore;
98 bool wrap_scroll = false;
99+ int index = 0;
100
101 if (args[i] == "l" || args[i] == "left") focus = TabFocus::Left;
102 else if (args[i] == "r" || args[i] == "right") focus = TabFocus::Right;
103- else if (args[i] == "mouse") {
104- g_Hy3Layout->focusTab(workspace, TabFocus::MouseLocation, mouse, false);
105+ else if (args[i] == "index") {
106+ i++;
107+ focus = TabFocus::Index;
108+ if (!isNumber(args[i])) return;
109+ index = std::stoi(args[i]);
110+ Debug::log(LOG, "Focus index '%s' -> %d, errno: %d", args[i].c_str(), index, errno);
111+ } else if (args[i] == "mouse") {
112+ g_Hy3Layout->focusTab(workspace, TabFocus::MouseLocation, mouse, false, 0);
113 return;
114 } else return;
115
116@@ -123,7 +130,7 @@ void dispatch_focustab(std::string value) {
117
118 if (args[i++] == "wrap") wrap_scroll = true;
119
120- g_Hy3Layout->focusTab(workspace, focus, mouse, wrap_scroll);
121+ g_Hy3Layout->focusTab(workspace, focus, mouse, wrap_scroll, index);
122 }
123
124 void dispatch_killactive(std::string value) {