mirror of
https://github.com/Trensa-Organization/hy3.git
synced 2025-03-15 18:53:40 +01:00
Add focusTab index mode
This commit is contained in:
parent
f4f72dc961
commit
c087452a8f
3 changed files with 44 additions and 19 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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*);
|
||||
|
|
13
src/main.cpp
13
src/main.cpp
|
@ -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) {
|
||||
|
|
Loading…
Add table
Reference in a new issue