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

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

@ -125,6 +125,7 @@ label-empty-padding = 2
type = internal/i3
format = <label-state> <label-mode>
index-sort = true
wrapping-scroll = false
label-mode = %mode%
label-mode-padding = 2

View file

@ -65,12 +65,13 @@ namespace modules {
label_t m_modelabel;
bool m_modeactive{false};
bool m_click = true;
bool m_scroll = true;
bool m_indexsort = false;
bool m_pinworkspaces = false;
bool m_strip_wsnumbers = false;
size_t m_wsname_maxlen = 0;
bool m_click{true};
bool m_scroll{true};
bool m_wrap{true};
bool m_indexsort{false};
bool m_pinworkspaces{false};
bool m_strip_wsnumbers{false};
size_t m_wsname_maxlen{0};
unique_ptr<i3_util::connection_t> m_ipc;
};

View file

@ -11,6 +11,9 @@ class connection;
namespace i3_util {
using connection_t = i3ipc::connection;
using workspace_t = i3ipc::workspace_t;
shared_ptr<workspace_t> focused_workspace(const connection_t&);
vector<xcb_window_t> root_windows(connection& conn, const string& output_name = "");
bool restack_above_root(connection& conn, const monitor_t& mon, const xcb_window_t win);

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) {
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());
i3_util::connection_t{}.send_command("workspace number " + cmd.substr(strlen(EVENT_CLICK)));
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");
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
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());
i3_util::connection_t{}.send_command("workspace prev_on_output");
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) {
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;
}

View file

@ -12,6 +12,18 @@
POLYBAR_NS
namespace i3_util {
/**
* Get currently focused workspace
*/
shared_ptr<workspace_t> focused_workspace(const connection_t& conn) {
for (auto&& ws : conn.get_workspaces()) {
if (ws->focused) {
return ws;
}
}
return nullptr;
}
/**
* Get all i3 root windows
*/