feat(i3): Conditional wrap around on scroll

Ref #242
This commit is contained in:
Michael Carlberg
2016-12-14 00:46:33 +01:00
parent 809e5748b6
commit f4529dde99
5 changed files with 50 additions and 12 deletions

View File

@ -30,6 +30,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_wrap, "wrapping-scroll");
GET_CONFIG_VALUE(name(), m_indexsort, "index-sort");
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
GET_CONFIG_VALUE(name(), m_strip_wsnumbers, "strip-wsnumbers");
@ -207,15 +208,35 @@ namespace modules {
bool i3_module::handle_event(string cmd) {
try {
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
m_log.info("%s: Sending workspace focus command to ipc handler", name());
i3_util::connection_t{}.send_command("workspace number " + cmd.substr(strlen(EVENT_CLICK)));
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) {
m_log.info("%s: Sending workspace prev command to ipc handler", name());
i3_util::connection_t{}.send_command("workspace next_on_output");
const i3_util::connection_t conn{};
if (m_wrap || conn.get_workspaces().back()->num != i3_util::focused_workspace(conn)->num) {
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: `wrap = false`)", name());
}
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
m_log.info("%s: Sending workspace next command to ipc handler", name());
i3_util::connection_t{}.send_command("workspace prev_on_output");
const i3_util::connection_t conn{};
if (m_wrap || conn.get_workspaces().front()->num != i3_util::focused_workspace(conn)->num) {
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 {
return false;
}