feat(bspwm,i3): Configurable scroll direction
This commit is contained in:
parent
698c494068
commit
4870204b4f
@ -74,6 +74,7 @@ namespace modules {
|
|||||||
|
|
||||||
bool m_click{true};
|
bool m_click{true};
|
||||||
bool m_scroll{true};
|
bool m_scroll{true};
|
||||||
|
bool m_revscroll{true};
|
||||||
bool m_pinworkspaces{true};
|
bool m_pinworkspaces{true};
|
||||||
string_util::hash_type m_hash{0U};
|
string_util::hash_type m_hash{0U};
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ namespace modules {
|
|||||||
|
|
||||||
bool m_click{true};
|
bool m_click{true};
|
||||||
bool m_scroll{true};
|
bool m_scroll{true};
|
||||||
|
bool m_revscroll{true};
|
||||||
bool m_wrap{true};
|
bool m_wrap{true};
|
||||||
bool m_indexsort{false};
|
bool m_indexsort{false};
|
||||||
bool m_pinworkspaces{false};
|
bool m_pinworkspaces{false};
|
||||||
|
@ -53,6 +53,7 @@ namespace modules {
|
|||||||
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
||||||
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
||||||
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
||||||
|
GET_CONFIG_VALUE(name(), m_revscroll, "reverse-scroll");
|
||||||
|
|
||||||
// Add formats and create components
|
// Add formats and create components
|
||||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE});
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE});
|
||||||
@ -430,12 +431,6 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
string modifier;
|
|
||||||
|
|
||||||
if (m_pinworkspaces) {
|
|
||||||
modifier = ".local";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
||||||
cmd.erase(0, strlen(EVENT_CLICK));
|
cmd.erase(0, strlen(EVENT_CLICK));
|
||||||
|
|
||||||
@ -449,10 +444,27 @@ namespace modules {
|
|||||||
} else {
|
} else {
|
||||||
m_log.err("%s: Invalid monitor index in command: %s", name(), cmd);
|
m_log.err("%s: Invalid monitor index in command: %s", name(), cmd);
|
||||||
}
|
}
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
|
||||||
send_command("desktop -f prev" + modifier, "Sending desktop prev command to ipc handler");
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
string modifier;
|
||||||
|
string scrolldir;
|
||||||
|
|
||||||
|
if (m_pinworkspaces) {
|
||||||
|
modifier = ".local";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
||||||
|
scrolldir = m_revscroll ? "prev" : "next";
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
||||||
send_command("desktop -f next" + modifier, "Sending desktop next command to ipc handler");
|
scrolldir = m_revscroll ? "next" : "prev";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!scrolldir.empty()) {
|
||||||
|
send_command("desktop -f " + scrolldir + modifier, "Sending desktop " + scrolldir + " command to ipc handler");
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -31,6 +31,7 @@ namespace modules {
|
|||||||
// Load configuration values
|
// Load configuration values
|
||||||
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
||||||
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
||||||
|
GET_CONFIG_VALUE(name(), m_revscroll, "reverse-scroll");
|
||||||
GET_CONFIG_VALUE(name(), m_wrap, "wrapping-scroll");
|
GET_CONFIG_VALUE(name(), m_wrap, "wrapping-scroll");
|
||||||
GET_CONFIG_VALUE(name(), m_indexsort, "index-sort");
|
GET_CONFIG_VALUE(name(), m_indexsort, "index-sort");
|
||||||
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
||||||
@ -193,38 +194,36 @@ namespace modules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool i3_module::handle_event(string cmd) {
|
bool i3_module::handle_event(string cmd) {
|
||||||
|
if (cmd.find(EVENT_PREFIX) != 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
string scrolldir;
|
||||||
|
const i3_util::connection_t conn{};
|
||||||
|
|
||||||
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
||||||
const i3_util::connection_t conn{};
|
|
||||||
const string workspace_num{cmd.substr(strlen(EVENT_CLICK))};
|
const string workspace_num{cmd.substr(strlen(EVENT_CLICK))};
|
||||||
|
|
||||||
if (i3_util::focused_workspace(conn)->num != atoi(workspace_num.c_str())) {
|
if (i3_util::focused_workspace(conn)->num != atoi(workspace_num.c_str())) {
|
||||||
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
||||||
conn.send_command("workspace number " + workspace_num);
|
conn.send_command("workspace number " + workspace_num);
|
||||||
} else {
|
|
||||||
m_log.warn("%s: Ignoring workspace focus command (reason: workspace already focused)", name());
|
|
||||||
}
|
}
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
||||||
const i3_util::connection_t conn{};
|
scrolldir = m_revscroll ? "next" : "prev";
|
||||||
|
|
||||||
if (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).back() != *i3_util::focused_workspace(conn)) {
|
|
||||||
m_log.info("%s: Sending workspace next command to ipc handler", name());
|
|
||||||
conn.send_command("workspace next_on_output");
|
|
||||||
} else {
|
|
||||||
m_log.warn("%s: Ignoring workspace next command (reason: `wrapping-scroll = false`)", name());
|
|
||||||
}
|
|
||||||
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
||||||
const i3_util::connection_t conn{};
|
scrolldir = m_revscroll ? "prev" : "next";
|
||||||
|
|
||||||
if (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).front() != *i3_util::focused_workspace(conn)) {
|
|
||||||
m_log.info("%s: Sending workspace prev command to ipc handler", name());
|
|
||||||
conn.send_command("workspace prev_on_output");
|
|
||||||
} else {
|
|
||||||
m_log.warn("%s: Ignoring workspace prev command (reason: `wrapping-scroll = false`)", name());
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (scrolldir == "next" && (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).back() != *i3_util::focused_workspace(conn))) {
|
||||||
|
m_log.info("%s: Sending workspace next command to ipc handler", name());
|
||||||
|
i3_util::connection_t{}.send_command("workspace next_on_output");
|
||||||
|
} else if (scrolldir == "prev" && (m_wrap || *i3_util::workspaces(conn, m_bar.monitor->name).front() != *i3_util::focused_workspace(conn))) {
|
||||||
|
m_log.info("%s: Sending workspace prev command to ipc handler", name());
|
||||||
|
i3_util::connection_t{}.send_command("workspace prev_on_output");
|
||||||
|
}
|
||||||
} catch (const exception& err) {
|
} catch (const exception& err) {
|
||||||
m_log.err("%s: %s", name(), err.what());
|
m_log.err("%s: %s", name(), err.what());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user