diff --git a/include/modules/bspwm.hpp b/include/modules/bspwm.hpp index 48620df2..054b0039 100644 --- a/include/modules/bspwm.hpp +++ b/include/modules/bspwm.hpp @@ -74,6 +74,7 @@ namespace modules { bool m_click{true}; bool m_scroll{true}; + bool m_revscroll{true}; bool m_pinworkspaces{true}; string_util::hash_type m_hash{0U}; diff --git a/include/modules/i3.hpp b/include/modules/i3.hpp index b959a0c2..ac92f6c5 100644 --- a/include/modules/i3.hpp +++ b/include/modules/i3.hpp @@ -67,6 +67,7 @@ namespace modules { bool m_click{true}; bool m_scroll{true}; + bool m_revscroll{true}; bool m_wrap{true}; bool m_indexsort{false}; bool m_pinworkspaces{false}; diff --git a/src/modules/bspwm.cpp b/src/modules/bspwm.cpp index 2513f0ca..203a65cc 100644 --- a/src/modules/bspwm.cpp +++ b/src/modules/bspwm.cpp @@ -53,6 +53,7 @@ namespace modules { GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces"); GET_CONFIG_VALUE(name(), m_click, "enable-click"); GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll"); + GET_CONFIG_VALUE(name(), m_revscroll, "reverse-scroll"); // Add formats and create components 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) { cmd.erase(0, strlen(EVENT_CLICK)); @@ -449,10 +444,27 @@ namespace modules { } else { 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) { - 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; diff --git a/src/modules/i3.cpp b/src/modules/i3.cpp index d66f7068..29657726 100644 --- a/src/modules/i3.cpp +++ b/src/modules/i3.cpp @@ -31,6 +31,7 @@ namespace modules { // Load configuration values GET_CONFIG_VALUE(name(), m_click, "enable-click"); 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_indexsort, "index-sort"); GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces"); @@ -193,38 +194,36 @@ namespace modules { } bool i3_module::handle_event(string cmd) { + if (cmd.find(EVENT_PREFIX) != 0) { + return false; + } + try { + string scrolldir; + const i3_util::connection_t conn{}; + 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))}; if (i3_util::focused_workspace(conn)->num != atoi(workspace_num.c_str())) { m_log.info("%s: Sending workspace focus command to ipc handler", name()); 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) { - const i3_util::connection_t conn{}; - - 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()); - } + scrolldir = m_revscroll ? "next" : "prev"; } else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) { - const i3_util::connection_t conn{}; - - 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()); - } + scrolldir = m_revscroll ? "prev" : "next"; } else { 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) { m_log.err("%s: %s", name(), err.what()); }