Add focusTab index mode

This commit is contained in:
outfoxxed 2023-06-28 12:58:31 -07:00
parent f4f72dc961
commit c087452a8f
No known key found for this signature in database
GPG key ID: 4C88A185FB89301E
3 changed files with 44 additions and 19 deletions

View file

@ -1804,7 +1804,8 @@ void Hy3Layout::focusTab(
int workspace, int workspace,
TabFocus target, TabFocus target,
TabFocusMousePriority mouse, TabFocusMousePriority mouse,
bool wrap_scroll bool wrap_scroll,
int index
) { ) {
auto* node = this->getWorkspaceRootGroup(workspace); auto* node = this->getWorkspaceRootGroup(workspace);
if (node == nullptr) return; if (node == nullptr) return;
@ -1842,23 +1843,39 @@ hastab:
return; return;
auto& children = tab_node->data.as_group.children; auto& children = tab_node->data.as_group.children;
auto node_iter if (target == TabFocus::Index) {
= std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child); int i = 1;
if (node_iter == children.end()) return;
if (target == TabFocus::Left) {
if (node_iter == children.begin()) {
if (wrap_scroll) node_iter = std::prev(children.end());
else return;
} else node_iter = std::prev(node_iter);
tab_focused_node = *node_iter; for (auto* node: children) {
if (i == index) {
tab_focused_node = node;
goto cont;
}
i++;
}
return;
cont:;
} else { } else {
if (node_iter == std::prev(children.end())) { auto node_iter
if (wrap_scroll) node_iter = children.begin(); = std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child);
else return; if (node_iter == children.end()) return;
} else node_iter = std::next(node_iter); if (target == TabFocus::Left) {
if (node_iter == children.begin()) {
if (wrap_scroll) node_iter = std::prev(children.end());
else return;
} else node_iter = std::prev(node_iter);
tab_focused_node = *node_iter; tab_focused_node = *node_iter;
} else {
if (node_iter == std::prev(children.end())) {
if (wrap_scroll) node_iter = children.begin();
else return;
} else node_iter = std::next(node_iter);
tab_focused_node = *node_iter;
}
} }
} }

View file

@ -35,6 +35,7 @@ enum class TabFocus {
MouseLocation, MouseLocation,
Left, Left,
Right, Right,
Index,
}; };
enum class TabFocusMousePriority { enum class TabFocusMousePriority {
@ -159,7 +160,7 @@ public:
void shiftWindow(int, ShiftDirection, bool); void shiftWindow(int, ShiftDirection, bool);
void shiftFocus(int, ShiftDirection, bool); void shiftFocus(int, ShiftDirection, bool);
void changeFocus(int, FocusShift); void changeFocus(int, FocusShift);
void focusTab(int, TabFocus, TabFocusMousePriority, bool); void focusTab(int, TabFocus, TabFocusMousePriority, bool, int);
void killFocusedNode(int); void killFocusedNode(int);
bool shouldRenderSelected(CWindow*); bool shouldRenderSelected(CWindow*);

View file

@ -103,11 +103,18 @@ void dispatch_focustab(std::string value) {
TabFocus focus; TabFocus focus;
auto mouse = TabFocusMousePriority::Ignore; auto mouse = TabFocusMousePriority::Ignore;
bool wrap_scroll = false; bool wrap_scroll = false;
int index = 0;
if (args[i] == "l" || args[i] == "left") focus = TabFocus::Left; if (args[i] == "l" || args[i] == "left") focus = TabFocus::Left;
else if (args[i] == "r" || args[i] == "right") focus = TabFocus::Right; else if (args[i] == "r" || args[i] == "right") focus = TabFocus::Right;
else if (args[i] == "mouse") { else if (args[i] == "index") {
g_Hy3Layout->focusTab(workspace, TabFocus::MouseLocation, mouse, false); i++;
focus = TabFocus::Index;
if (!isNumber(args[i])) return;
index = std::stoi(args[i]);
Debug::log(LOG, "Focus index '%s' -> %d, errno: %d", args[i].c_str(), index, errno);
} else if (args[i] == "mouse") {
g_Hy3Layout->focusTab(workspace, TabFocus::MouseLocation, mouse, false, 0);
return; return;
} else return; } else return;
@ -123,7 +130,7 @@ void dispatch_focustab(std::string value) {
if (args[i++] == "wrap") wrap_scroll = true; if (args[i++] == "wrap") wrap_scroll = true;
g_Hy3Layout->focusTab(workspace, focus, mouse, wrap_scroll); g_Hy3Layout->focusTab(workspace, focus, mouse, wrap_scroll, index);
} }
void dispatch_killactive(std::string value) { void dispatch_killactive(std::string value) {