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,
TabFocus target,
TabFocusMousePriority mouse,
bool wrap_scroll
bool wrap_scroll,
int index
) {
auto* node = this->getWorkspaceRootGroup(workspace);
if (node == nullptr) return;
@ -1842,23 +1843,39 @@ hastab:
return;
auto& children = tab_node->data.as_group.children;
auto node_iter
= std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child);
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);
if (target == TabFocus::Index) {
int i = 1;
tab_focused_node = *node_iter;
for (auto* node: children) {
if (i == index) {
tab_focused_node = node;
goto cont;
}
i++;
}
return;
cont:;
} else {
if (node_iter == std::prev(children.end())) {
if (wrap_scroll) node_iter = children.begin();
else return;
} else node_iter = std::next(node_iter);
auto node_iter
= std::find(children.begin(), children.end(), tab_node->data.as_group.focused_child);
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;
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,
Left,
Right,
Index,
};
enum class TabFocusMousePriority {
@ -159,7 +160,7 @@ public:
void shiftWindow(int, ShiftDirection, bool);
void shiftFocus(int, ShiftDirection, bool);
void changeFocus(int, FocusShift);
void focusTab(int, TabFocus, TabFocusMousePriority, bool);
void focusTab(int, TabFocus, TabFocusMousePriority, bool, int);
void killFocusedNode(int);
bool shouldRenderSelected(CWindow*);

View file

@ -103,11 +103,18 @@ void dispatch_focustab(std::string value) {
TabFocus focus;
auto mouse = TabFocusMousePriority::Ignore;
bool wrap_scroll = false;
int index = 0;
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] == "mouse") {
g_Hy3Layout->focusTab(workspace, TabFocus::MouseLocation, mouse, false);
else if (args[i] == "index") {
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;
} else return;
@ -123,7 +130,7 @@ void dispatch_focustab(std::string value) {
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) {