1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

fix(i3): Check whether current ws is found (#826)

Fixes dereference of end() iterator in case current workspace is not found (#824).

Fixes #824
This commit is contained in:
Vasili Karaev 2017-11-01 18:47:07 +03:00 committed by Patrick Ziegler
parent a3e9bb9847
commit dc0edfb994

View file

@ -220,20 +220,25 @@ namespace modules {
}
auto workspaces = i3_util::workspaces(conn, m_bar.monitor->name);
auto current_ws = *find_if(workspaces.begin(), workspaces.end(),
[](auto ws) { return ws->visible; });
auto current_ws = find_if(workspaces.begin(), workspaces.end(),
[](auto ws) { return ws->visible; });
if (scrolldir == "next" && (m_wrap || workspaces.back() != current_ws)) {
if (!current_ws->focused) {
if (current_ws == workspaces.end()) {
m_log.warn("%s: Current workspace not found", name());
return false;
}
if (scrolldir == "next" && (m_wrap || next(current_ws) != workspaces.end())) {
if (!(*current_ws)->focused) {
m_log.info("%s: Sending workspace focus command to ipc handler", name());
conn.send_command("workspace " + current_ws->name);
conn.send_command("workspace " + (*current_ws)->name);
}
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) {
} else if (scrolldir == "prev" && (m_wrap || current_ws != workspaces.begin())) {
if (!(*current_ws)->focused) {
m_log.info("%s: Sending workspace focus command to ipc handler", name());
conn.send_command("workspace " + current_ws->name);
conn.send_command("workspace " + (*current_ws)->name);
}
m_log.info("%s: Sending workspace prev_on_output command to ipc handler", name());
conn.send_command("workspace prev_on_output");