From 68beb8d7448abc7815792be16564ad18bded2028 Mon Sep 17 00:00:00 2001 From: Vasili Karaev Date: Thu, 30 Mar 2017 13:53:35 +0300 Subject: [PATCH] fix(i3): Check whether current ws is focused before issuing scroll commands #503 --- src/modules/i3.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/modules/i3.cpp b/src/modules/i3.cpp index 482f6770..ae77ec20 100644 --- a/src/modules/i3.cpp +++ b/src/modules/i3.cpp @@ -220,27 +220,23 @@ namespace modules { } auto workspaces = i3_util::workspaces(conn, m_bar.monitor->name); - auto current_ws_iter = find_if(workspaces.begin(), workspaces.end(), - [](auto ws) { return ws->focused || ws->visible; }); - auto target_ws_iter = current_ws_iter; + auto current_ws = *find_if(workspaces.begin(), workspaces.end(), + [](auto ws) { return ws->visible; }); - if (scrolldir == "next") { - if (*current_ws_iter == workspaces.back() && m_wrap) { - target_ws_iter = workspaces.begin(); - } else if (*current_ws_iter != workspaces.back()) { - target_ws_iter = std::next(current_ws_iter); + if (scrolldir == "next" && (m_wrap || workspaces.back() != current_ws)) { + if (!current_ws->focused) { + m_log.info("%s: Sending workspace focus command to ipc handler", name()); + conn.send_command("workspace " + current_ws->name); } - } else if (scrolldir == "prev") { - if (*current_ws_iter == workspaces.front() && m_wrap) { - target_ws_iter = std::prev(workspaces.end()); - } else if (*current_ws_iter != workspaces.front()) { - target_ws_iter = std::prev(current_ws_iter); + m_log.info("%s: Sending workspace next_on_output command to ipc handler", name()); + conn.send_command("workspace next_on_output"); + } else if (scrolldir == "prev" && (m_wrap || workspaces.front() != current_ws)) { + if (!current_ws->focused) { + m_log.info("%s: Sending workspace focus command to ipc handler", name()); + conn.send_command("workspace " + current_ws->name); } - } - - if (current_ws_iter != target_ws_iter) { - m_log.info("%s: Sending workspace focus command to ipc handler", name()); - conn.send_command("workspace " + (*target_ws_iter)->name); + m_log.info("%s: Sending workspace prev_on_output command to ipc handler", name()); + conn.send_command("workspace prev_on_output"); } } catch (const exception& err) {