mirror of
https://github.com/polybar/polybar.git
synced 2024-11-18 13:55:11 -05:00
parent
809e5748b6
commit
f4529dde99
5 changed files with 50 additions and 12 deletions
|
@ -125,6 +125,7 @@ label-empty-padding = 2
|
||||||
type = internal/i3
|
type = internal/i3
|
||||||
format = <label-state> <label-mode>
|
format = <label-state> <label-mode>
|
||||||
index-sort = true
|
index-sort = true
|
||||||
|
wrapping-scroll = false
|
||||||
|
|
||||||
label-mode = %mode%
|
label-mode = %mode%
|
||||||
label-mode-padding = 2
|
label-mode-padding = 2
|
||||||
|
|
|
@ -65,12 +65,13 @@ namespace modules {
|
||||||
label_t m_modelabel;
|
label_t m_modelabel;
|
||||||
bool m_modeactive{false};
|
bool m_modeactive{false};
|
||||||
|
|
||||||
bool m_click = true;
|
bool m_click{true};
|
||||||
bool m_scroll = true;
|
bool m_scroll{true};
|
||||||
bool m_indexsort = false;
|
bool m_wrap{true};
|
||||||
bool m_pinworkspaces = false;
|
bool m_indexsort{false};
|
||||||
bool m_strip_wsnumbers = false;
|
bool m_pinworkspaces{false};
|
||||||
size_t m_wsname_maxlen = 0;
|
bool m_strip_wsnumbers{false};
|
||||||
|
size_t m_wsname_maxlen{0};
|
||||||
|
|
||||||
unique_ptr<i3_util::connection_t> m_ipc;
|
unique_ptr<i3_util::connection_t> m_ipc;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,9 @@ class connection;
|
||||||
|
|
||||||
namespace i3_util {
|
namespace i3_util {
|
||||||
using connection_t = i3ipc::connection;
|
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 = "");
|
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);
|
bool restack_above_root(connection& conn, const monitor_t& mon, const xcb_window_t win);
|
||||||
|
|
|
@ -30,6 +30,7 @@ namespace modules {
|
||||||
// Load configuration values
|
// Load configuration values
|
||||||
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
||||||
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
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_indexsort, "index-sort");
|
||||||
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
||||||
GET_CONFIG_VALUE(name(), m_strip_wsnumbers, "strip-wsnumbers");
|
GET_CONFIG_VALUE(name(), m_strip_wsnumbers, "strip-wsnumbers");
|
||||||
|
@ -207,15 +208,35 @@ namespace modules {
|
||||||
|
|
||||||
bool i3_module::handle_event(string cmd) {
|
bool i3_module::handle_event(string cmd) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
||||||
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
const i3_util::connection_t conn{};
|
||||||
i3_util::connection_t{}.send_command("workspace number " + cmd.substr(strlen(EVENT_CLICK)));
|
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) {
|
} 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());
|
const i3_util::connection_t conn{};
|
||||||
i3_util::connection_t{}.send_command("workspace next_on_output");
|
|
||||||
|
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) {
|
} 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());
|
const i3_util::connection_t conn{};
|
||||||
i3_util::connection_t{}.send_command("workspace prev_on_output");
|
|
||||||
|
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 {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,18 @@
|
||||||
POLYBAR_NS
|
POLYBAR_NS
|
||||||
|
|
||||||
namespace i3_util {
|
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
|
* Get all i3 root windows
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue