mirror of
https://github.com/polybar/polybar.git
synced 2024-11-25 13:55:47 -05:00
refactor(i3): Rewrite of the i3 module
This commit is contained in:
parent
c4e9f9d035
commit
774dec5d17
8 changed files with 156 additions and 145 deletions
13
README.md
13
README.md
|
@ -686,6 +686,18 @@ See [the bspwm module](#module-internalbspwm) for details on `label-dimmed`.
|
||||||
~~~ ini
|
~~~ ini
|
||||||
[module/i3]
|
[module/i3]
|
||||||
type = internal/i3
|
type = internal/i3
|
||||||
|
|
||||||
|
; Only show workspaces defined on the same output as the bar
|
||||||
|
;
|
||||||
|
; Useful if you want to show monitor specific workspaces
|
||||||
|
; in different bars
|
||||||
|
;
|
||||||
|
; Default: false
|
||||||
|
pin-workspaces = true
|
||||||
|
|
||||||
|
; Limit the amount of chars to output for each workspace name
|
||||||
|
; Default: 0
|
||||||
|
wsname-maxlen = 2
|
||||||
~~~
|
~~~
|
||||||
|
|
||||||
##### Extra formatting (example)
|
##### Extra formatting (example)
|
||||||
|
@ -706,6 +718,7 @@ See [the bspwm module](#module-internalbspwm) for details on `label-dimmed`.
|
||||||
; %name%
|
; %name%
|
||||||
; %icon%
|
; %icon%
|
||||||
; %index%
|
; %index%
|
||||||
|
; %output%
|
||||||
; Default: %icon% %name%
|
; Default: %icon% %name%
|
||||||
label-focused = %icon%
|
label-focused = %icon%
|
||||||
label-focused-foreground = #ffffff
|
label-focused-foreground = #ffffff
|
||||||
|
|
|
@ -146,16 +146,16 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose> {
|
||||||
// }}}
|
// }}}
|
||||||
// Set size and position {{{
|
// Set size and position {{{
|
||||||
|
|
||||||
GET_CONFIG_VALUE(m_bar.dock, "dock");
|
GET_CONFIG_VALUE(bs, m_bar.dock, "dock");
|
||||||
GET_CONFIG_VALUE(m_bar.bottom, "bottom");
|
GET_CONFIG_VALUE(bs, m_bar.bottom, "bottom");
|
||||||
GET_CONFIG_VALUE(m_bar.spacing, "spacing");
|
GET_CONFIG_VALUE(bs, m_bar.spacing, "spacing");
|
||||||
GET_CONFIG_VALUE(m_bar.lineheight, "lineheight");
|
GET_CONFIG_VALUE(bs, m_bar.lineheight, "lineheight");
|
||||||
GET_CONFIG_VALUE(m_bar.offset_x, "offset_x");
|
GET_CONFIG_VALUE(bs, m_bar.offset_x, "offset_x");
|
||||||
GET_CONFIG_VALUE(m_bar.offset_y, "offset_y");
|
GET_CONFIG_VALUE(bs, m_bar.offset_y, "offset_y");
|
||||||
GET_CONFIG_VALUE(m_bar.padding_left, "padding_left");
|
GET_CONFIG_VALUE(bs, m_bar.padding_left, "padding_left");
|
||||||
GET_CONFIG_VALUE(m_bar.padding_right, "padding_right");
|
GET_CONFIG_VALUE(bs, m_bar.padding_right, "padding_right");
|
||||||
GET_CONFIG_VALUE(m_bar.module_margin_left, "module_margin_left");
|
GET_CONFIG_VALUE(bs, m_bar.module_margin_left, "module_margin_left");
|
||||||
GET_CONFIG_VALUE(m_bar.module_margin_right, "module_margin_right");
|
GET_CONFIG_VALUE(bs, m_bar.module_margin_right, "module_margin_right");
|
||||||
|
|
||||||
auto w = m_conf.get<string>(bs, "width", "100%");
|
auto w = m_conf.get<string>(bs, "width", "100%");
|
||||||
auto h = m_conf.get<string>(bs, "height", "24");
|
auto h = m_conf.get<string>(bs, "height", "24");
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "utils/file.hpp"
|
#include "utils/file.hpp"
|
||||||
#include "utils/string.hpp"
|
#include "utils/string.hpp"
|
||||||
|
|
||||||
#define GET_CONFIG_VALUE(var, name) var = m_conf.get<decltype(var)>(bs, name, var)
|
#define GET_CONFIG_VALUE(section, var, name) var = m_conf.get<decltype(var)>(section, name, var)
|
||||||
|
|
||||||
LEMONBUDDY_NS
|
LEMONBUDDY_NS
|
||||||
|
|
||||||
|
|
|
@ -49,11 +49,12 @@ namespace modules {
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
// Load configuration values {{{
|
||||||
|
|
||||||
m_monitor = m_bar.monitor->name;
|
m_monitor = m_bar.monitor->name;
|
||||||
m_log.trace("%s: Primary monitor '%s'", name(), m_monitor);
|
m_log.trace("%s: Primary monitor '%s'", name(), m_monitor);
|
||||||
|
|
||||||
m_subscriber = bspwm_util::make_subscriber();
|
// }}}
|
||||||
|
|
||||||
// Add formats and create components {{{
|
// Add formats and create components {{{
|
||||||
|
|
||||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MODE});
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MODE});
|
||||||
|
@ -88,8 +89,6 @@ namespace modules {
|
||||||
get_optional_config_label(m_conf, name(), "label-private")));
|
get_optional_config_label(m_conf, name(), "label-private")));
|
||||||
}
|
}
|
||||||
|
|
||||||
// }}}
|
|
||||||
|
|
||||||
m_icons = iconset_t{new iconset()};
|
m_icons = iconset_t{new iconset()};
|
||||||
m_icons->add(
|
m_icons->add(
|
||||||
DEFAULT_WS_ICON, icon_t{new icon(m_conf.get<string>(name(), DEFAULT_WS_ICON, ""))});
|
DEFAULT_WS_ICON, icon_t{new icon(m_conf.get<string>(name(), DEFAULT_WS_ICON, ""))});
|
||||||
|
@ -100,6 +99,13 @@ namespace modules {
|
||||||
m_icons->add(vec[0], icon_t{new icon{vec[1]}});
|
m_icons->add(vec[0], icon_t{new icon{vec[1]}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// Create ipc subscriber {{{
|
||||||
|
|
||||||
|
m_subscriber = bspwm_util::make_subscriber();
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_event() {
|
bool has_event() {
|
||||||
|
@ -331,10 +337,8 @@ namespace modules {
|
||||||
private:
|
private:
|
||||||
static constexpr auto DEFAULT_WS_ICON = "workspace_icon-default";
|
static constexpr auto DEFAULT_WS_ICON = "workspace_icon-default";
|
||||||
static constexpr auto DEFAULT_WS_LABEL = "%icon% %name%";
|
static constexpr auto DEFAULT_WS_LABEL = "%icon% %name%";
|
||||||
|
|
||||||
static constexpr auto TAG_LABEL_STATE = "<label-state>";
|
static constexpr auto TAG_LABEL_STATE = "<label-state>";
|
||||||
static constexpr auto TAG_LABEL_MODE = "<label-mode>";
|
static constexpr auto TAG_LABEL_MODE = "<label-mode>";
|
||||||
|
|
||||||
static constexpr auto EVENT_CLICK = "bwm";
|
static constexpr auto EVENT_CLICK = "bwm";
|
||||||
|
|
||||||
bspwm_util::connection_t m_subscriber;
|
bspwm_util::connection_t m_subscriber;
|
||||||
|
|
|
@ -1,89 +1,69 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// #include <i3ipc++/ipc-util.hpp>
|
#include <i3ipc++/ipc.hpp>
|
||||||
// #include <i3ipc++/ipc.hpp>
|
|
||||||
|
|
||||||
#include "config.hpp"
|
#include "config.hpp"
|
||||||
|
#include "components/config.hpp"
|
||||||
#include "drawtypes/iconset.hpp"
|
#include "drawtypes/iconset.hpp"
|
||||||
#include "drawtypes/label.hpp"
|
#include "drawtypes/label.hpp"
|
||||||
#include "modules/meta.hpp"
|
#include "modules/meta.hpp"
|
||||||
|
#include "utils/i3.hpp"
|
||||||
|
#include "utils/io.hpp"
|
||||||
|
|
||||||
LEMONBUDDY_NS
|
LEMONBUDDY_NS
|
||||||
|
|
||||||
namespace modules {
|
namespace modules {
|
||||||
|
// meta types {{{
|
||||||
|
|
||||||
enum class i3_flag {
|
enum class i3_flag {
|
||||||
WORKSPACE_NONE,
|
WORKSPACE_NONE,
|
||||||
WORKSPACE_FOCUSED,
|
WORKSPACE_FOCUSED,
|
||||||
WORKSPACE_UNFOCUSED,
|
WORKSPACE_UNFOCUSED,
|
||||||
WORKSPACE_VISIBLE,
|
WORKSPACE_VISIBLE,
|
||||||
WORKSPACE_URGENT,
|
WORKSPACE_URGENT,
|
||||||
WORKSPACE_DIMMED, // used when the monitor is out of focus
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct i3_workspace {
|
struct i3_workspace {
|
||||||
explicit i3_workspace(int idx, i3_flag flag, label_t&& label_)
|
int index;
|
||||||
: idx(idx), flag(flag), label(forward<decltype(label_)>(label_)) {}
|
|
||||||
|
|
||||||
operator bool() {
|
|
||||||
return label && label.get();
|
|
||||||
}
|
|
||||||
|
|
||||||
int idx;
|
|
||||||
i3_flag flag;
|
i3_flag flag;
|
||||||
label_t label;
|
label_t label;
|
||||||
};
|
|
||||||
|
|
||||||
namespace i3ipc {
|
i3_workspace(int index_, i3_flag flag_, label_t&& label_)
|
||||||
static const int ET_WORKSPACE = 1;
|
: index(index_), flag(flag_), label(forward<decltype(label_)>(label_)) {}
|
||||||
static const int ET_OUTPUT = 2;
|
|
||||||
static const int ET_WINDOW = 4;
|
|
||||||
|
|
||||||
class ws {
|
operator bool() {
|
||||||
public:
|
return label && *label;
|
||||||
bool focused;
|
|
||||||
bool urgent;
|
|
||||||
bool visible;
|
|
||||||
string output;
|
|
||||||
string name;
|
|
||||||
unsigned int num;
|
|
||||||
};
|
|
||||||
|
|
||||||
class connection {
|
|
||||||
public:
|
|
||||||
void subscribe(int) {}
|
|
||||||
void send_command(string) {}
|
|
||||||
void prepare_to_event_handling() {}
|
|
||||||
void handle_event() {}
|
|
||||||
vector<unique_ptr<ws>> get_workspaces() {
|
|
||||||
return {};
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
|
||||||
|
|
||||||
using i3_workspace_t = unique_ptr<i3_workspace>;
|
using i3_workspace_t = unique_ptr<i3_workspace>;
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
|
||||||
class i3_module : public event_module<i3_module> {
|
class i3_module : public event_module<i3_module> {
|
||||||
public:
|
public:
|
||||||
using event_module::event_module;
|
using event_module::event_module;
|
||||||
|
|
||||||
~i3_module() {
|
~i3_module() {
|
||||||
if (!m_ipc)
|
// Shutdown ipc connection {{{
|
||||||
return;
|
|
||||||
// FIXME: Hack to release the recv lock. Will need to patch the ipc lib
|
try {
|
||||||
m_ipc->send_command("workspace back_and_forth");
|
shutdown(m_ipc.get_event_socket_fd(), SHUT_RD);
|
||||||
m_ipc->send_command("workspace back_and_forth");
|
shutdown(m_ipc.get_main_socket_fd(), SHUT_RD);
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
try {
|
// Load configuration values {{{
|
||||||
m_ipc = make_unique<i3ipc::connection>();
|
|
||||||
} catch (std::runtime_error& e) {
|
|
||||||
throw module_error(e.what());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_localworkspaces = m_conf.get<bool>(name(), "local_workspaces", m_localworkspaces);
|
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
||||||
m_workspace_name_strip_nchars =
|
GET_CONFIG_VALUE(name(), m_wsname_maxlen, "wsname-maxlen");
|
||||||
m_conf.get<size_t>(name(), "workspace_name_strip_nchars", m_workspace_name_strip_nchars);
|
|
||||||
|
// }}}
|
||||||
|
// Add formats and create components {{{
|
||||||
|
|
||||||
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE});
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE});
|
||||||
|
|
||||||
|
@ -96,123 +76,140 @@ namespace modules {
|
||||||
get_optional_config_label(m_conf, name(), "label-visible", DEFAULT_WS_LABEL)));
|
get_optional_config_label(m_conf, name(), "label-visible", DEFAULT_WS_LABEL)));
|
||||||
m_statelabels.insert(make_pair(i3_flag::WORKSPACE_URGENT,
|
m_statelabels.insert(make_pair(i3_flag::WORKSPACE_URGENT,
|
||||||
get_optional_config_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL)));
|
get_optional_config_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL)));
|
||||||
m_statelabels.insert(make_pair(
|
|
||||||
i3_flag::WORKSPACE_DIMMED, get_optional_config_label(m_conf, name(), "label-dimmed")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_icons = iconset_t{new iconset()};
|
m_icons = iconset_t{new iconset()};
|
||||||
m_icons->add(
|
m_icons->add(
|
||||||
DEFAULT_WS_ICON, icon_t{new icon(m_conf.get<string>(name(), DEFAULT_WS_ICON, ""))});
|
DEFAULT_WS_ICON, icon_t{new icon(m_conf.get<string>(name(), DEFAULT_WS_ICON, ""))});
|
||||||
|
|
||||||
|
// }}}
|
||||||
|
// Add formats and create components {{{
|
||||||
|
|
||||||
for (auto workspace : m_conf.get_list<string>(name(), "workspace_icon", {})) {
|
for (auto workspace : m_conf.get_list<string>(name(), "workspace_icon", {})) {
|
||||||
auto vec = string_util::split(workspace, ';');
|
auto vec = string_util::split(workspace, ';');
|
||||||
if (vec.size() == 2)
|
if (vec.size() == 2)
|
||||||
m_icons->add(vec[0], icon_t{new icon{vec[1]}});
|
m_icons->add(vec[0], icon_t{new icon{vec[1]}});
|
||||||
}
|
}
|
||||||
|
|
||||||
// m_ipc->subscribe(i3ipc::ET_WORKSPACE | i3ipc::ET_OUTPUT | i3ipc::ET_WINDOW);
|
// }}}
|
||||||
// m_ipc->subscribe(i3ipc::ET_WORKSPACE | i3ipc::ET_OUTPUT);
|
// Subscribe to ipc events {{{
|
||||||
// m_ipc->prepare_to_event_handling();
|
|
||||||
|
try {
|
||||||
|
m_ipc.subscribe(i3ipc::ET_WORKSPACE);
|
||||||
|
m_ipc.prepare_to_event_handling();
|
||||||
|
} catch (std::runtime_error& e) {
|
||||||
|
throw module_error(e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_event() {
|
bool has_event() {
|
||||||
if (!m_ipc || !enabled())
|
// Wait for ipc events {{{
|
||||||
return false;
|
|
||||||
m_ipc->handle_event();
|
try {
|
||||||
|
m_ipc.handle_event();
|
||||||
return true;
|
return true;
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
if (enabled())
|
||||||
|
m_log.err("%s: Error while handling ipc event (%s)", name(), err.what());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool update() {
|
bool update() {
|
||||||
if (!enabled())
|
// Refresh workspace data {{{
|
||||||
return false;
|
|
||||||
|
|
||||||
i3ipc::connection connection;
|
|
||||||
|
|
||||||
try {
|
|
||||||
// for (auto &&m : connection.get_outputs()) {
|
|
||||||
// if (m->name == m_monitor) {
|
|
||||||
// monitor_focused = m->active;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
m_workspaces.clear();
|
m_workspaces.clear();
|
||||||
|
i3_util::connection_t ipc;
|
||||||
|
|
||||||
auto workspaces = connection.get_workspaces();
|
try {
|
||||||
|
auto workspaces = ipc.get_workspaces();
|
||||||
|
string focused_output;
|
||||||
|
bool output_unfocused = false;
|
||||||
|
|
||||||
string focused_monitor;
|
for (auto&& workspace : workspaces)
|
||||||
|
if (workspace->focused) {
|
||||||
for (auto&& ws : workspaces) {
|
focused_output = workspace->output;
|
||||||
if (ws->focused) {
|
|
||||||
focused_monitor = ws->output;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
bool monitor_focused = (focused_monitor == m_monitor);
|
if (focused_output != m_bar.monitor->name)
|
||||||
|
output_unfocused = true;
|
||||||
|
|
||||||
for (auto&& ws : connection.get_workspaces()) {
|
for (auto&& workspace : workspaces) {
|
||||||
if (m_localworkspaces && ws->output != m_monitor)
|
if (m_pinworkspaces && workspace->output != m_bar.monitor->name)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto flag = i3_flag::WORKSPACE_NONE;
|
auto flag = i3_flag::WORKSPACE_NONE;
|
||||||
|
if (workspace->focused)
|
||||||
if (ws->focused)
|
|
||||||
flag = i3_flag::WORKSPACE_FOCUSED;
|
flag = i3_flag::WORKSPACE_FOCUSED;
|
||||||
else if (ws->urgent)
|
else if (workspace->urgent)
|
||||||
flag = i3_flag::WORKSPACE_URGENT;
|
flag = i3_flag::WORKSPACE_URGENT;
|
||||||
else if (ws->visible)
|
else if (!workspace->visible || (workspace->visible && workspace->output != focused_output))
|
||||||
flag = i3_flag::WORKSPACE_VISIBLE;
|
|
||||||
else
|
|
||||||
flag = i3_flag::WORKSPACE_UNFOCUSED;
|
flag = i3_flag::WORKSPACE_UNFOCUSED;
|
||||||
|
else
|
||||||
|
flag = i3_flag::WORKSPACE_VISIBLE;
|
||||||
|
|
||||||
// if (!monitor_focused)
|
string wsname{workspace->name};
|
||||||
// flag = i3_flag::WORKSPACE_DIMMED;
|
if (m_wsname_maxlen > 0 && wsname.length() > m_wsname_maxlen)
|
||||||
|
wsname.erase(m_wsname_maxlen);
|
||||||
|
|
||||||
auto workspace_name = ws->name;
|
auto icon = m_icons->get(workspace->name, DEFAULT_WS_ICON);
|
||||||
if (m_workspace_name_strip_nchars > 0 &&
|
|
||||||
workspace_name.length() > m_workspace_name_strip_nchars)
|
|
||||||
workspace_name.erase(0, m_workspace_name_strip_nchars);
|
|
||||||
|
|
||||||
auto icon = m_icons->get(workspace_name, DEFAULT_WS_ICON);
|
|
||||||
auto label = m_statelabels.find(flag)->second->clone();
|
auto label = m_statelabels.find(flag)->second->clone();
|
||||||
|
|
||||||
if (!monitor_focused)
|
label->replace_token("%output%", workspace->output);
|
||||||
label->replace_defined_values(m_statelabels.find(i3_flag::WORKSPACE_DIMMED)->second);
|
label->replace_token("%name%", wsname);
|
||||||
|
|
||||||
label->replace_token("%name%", workspace_name);
|
|
||||||
label->replace_token("%icon%", icon->m_text);
|
label->replace_token("%icon%", icon->m_text);
|
||||||
label->replace_token("%index%", to_string(ws->num));
|
label->replace_token("%index%", to_string(workspace->num));
|
||||||
|
m_workspaces.emplace_back(make_unique<i3_workspace>(workspace->num, flag, std::move(label)));
|
||||||
m_workspaces.emplace_back(make_unique<i3_workspace>(ws->num, flag, std::move(label)));
|
|
||||||
}
|
|
||||||
} catch (std::runtime_error& e) {
|
|
||||||
m_log.err("%s: %s", name(), e.what());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
m_log.err("%s: %s", name(), err.what());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool build(builder* builder, string tag) {
|
bool build(builder* builder, string tag) {
|
||||||
|
// Output workspace info {{{
|
||||||
|
|
||||||
if (tag != TAG_LABEL_STATE)
|
if (tag != TAG_LABEL_STATE)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (auto&& ws : m_workspaces) {
|
for (auto&& ws : m_workspaces) {
|
||||||
builder->cmd(mousebtn::LEFT, string{EVENT_CLICK} + to_string(ws.get()->idx));
|
builder->cmd(mousebtn::LEFT, string{EVENT_CLICK} + to_string(ws.get()->index));
|
||||||
builder->node(ws.get()->label);
|
builder->node(ws.get()->label);
|
||||||
builder->cmd_close(true);
|
builder->cmd_close(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool handle_event(string cmd) {
|
bool handle_event(string cmd) {
|
||||||
if (cmd.find(EVENT_CLICK) == string::npos || cmd.length() < strlen(EVENT_CLICK))
|
// Send ipc commands {{{
|
||||||
|
|
||||||
|
if (cmd.find(EVENT_CLICK) == string::npos)
|
||||||
|
return false;
|
||||||
|
if (cmd.length() < strlen(EVENT_CLICK))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_ipc->send_command("workspace number " + cmd.substr(strlen(EVENT_CLICK)));
|
try {
|
||||||
|
i3_util::connection_t ipc;
|
||||||
|
m_log.info("%s: Sending workspace focus command to ipc handler", name());
|
||||||
|
ipc.send_command("workspace number "+ cmd.substr(strlen(EVENT_CLICK)));
|
||||||
|
} catch (const std::exception& err) {
|
||||||
|
m_log.err("%s: %s", name(), err.what());
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
|
// }}}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool receive_events() const {
|
bool receive_events() const {
|
||||||
|
@ -222,24 +219,17 @@ namespace modules {
|
||||||
private:
|
private:
|
||||||
static constexpr auto DEFAULT_WS_ICON = "workspace_icon-default";
|
static constexpr auto DEFAULT_WS_ICON = "workspace_icon-default";
|
||||||
static constexpr auto DEFAULT_WS_LABEL = "%icon% %name%";
|
static constexpr auto DEFAULT_WS_LABEL = "%icon% %name%";
|
||||||
|
|
||||||
static constexpr auto TAG_LABEL_STATE = "<label-state>";
|
static constexpr auto TAG_LABEL_STATE = "<label-state>";
|
||||||
|
|
||||||
static constexpr auto EVENT_CLICK = "i3";
|
static constexpr auto EVENT_CLICK = "i3";
|
||||||
|
|
||||||
unique_ptr<i3ipc::connection> m_ipc;
|
|
||||||
|
|
||||||
map<i3_flag, label_t> m_statelabels;
|
map<i3_flag, label_t> m_statelabels;
|
||||||
vector<i3_workspace_t> m_workspaces;
|
vector<i3_workspace_t> m_workspaces;
|
||||||
|
|
||||||
// map<i3_flag, label_t> mode_labels;
|
|
||||||
// vector<label_t> modes;
|
|
||||||
|
|
||||||
iconset_t m_icons;
|
iconset_t m_icons;
|
||||||
string m_monitor;
|
|
||||||
|
|
||||||
bool m_localworkspaces = true;
|
bool m_pinworkspaces = false;
|
||||||
size_t m_workspace_name_strip_nchars = 0;
|
size_t m_wsname_maxlen = 0;
|
||||||
|
|
||||||
|
i3_util::connection_t m_ipc;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -107,19 +107,19 @@ namespace bspwm_util {
|
||||||
* Generate a payload object with properly formatted data
|
* Generate a payload object with properly formatted data
|
||||||
* ready to be sent to the bspwm ipc controller
|
* ready to be sent to the bspwm ipc controller
|
||||||
*/
|
*/
|
||||||
unique_ptr<payload> make_payload(string cmd) {
|
payload_t make_payload(string cmd) {
|
||||||
auto pl = make_unique<payload>();
|
payload_t payload{new payload_t::element_type{}};
|
||||||
auto size = sizeof(pl->data);
|
auto size = sizeof(payload->data);
|
||||||
int offset = 0;
|
int offset = 0;
|
||||||
int chars = 0;
|
int chars = 0;
|
||||||
|
|
||||||
for (auto&& word : string_util::split(cmd, ' ')) {
|
for (auto&& word : string_util::split(cmd, ' ')) {
|
||||||
chars = snprintf(pl->data + offset, size - offset, "%s%c", word.c_str(), 0);
|
chars = snprintf(payload->data + offset, size - offset, "%s%c", word.c_str(), 0);
|
||||||
pl->len += chars;
|
payload->len += chars;
|
||||||
offset += chars;
|
offset += chars;
|
||||||
}
|
}
|
||||||
|
|
||||||
return pl;
|
return payload;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
#include <xcb/xcb.h>
|
#include <xcb/xcb.h>
|
||||||
#include <xcb/xcb_icccm.h>
|
#include <xcb/xcb_icccm.h>
|
||||||
|
|
||||||
|
#include <i3ipc++/ipc.hpp>
|
||||||
|
|
||||||
#include "common.hpp"
|
#include "common.hpp"
|
||||||
#include "components/x11/connection.hpp"
|
#include "components/x11/connection.hpp"
|
||||||
#include "components/x11/randr.hpp"
|
#include "components/x11/randr.hpp"
|
||||||
|
@ -13,6 +15,8 @@
|
||||||
LEMONBUDDY_NS
|
LEMONBUDDY_NS
|
||||||
|
|
||||||
namespace i3_util {
|
namespace i3_util {
|
||||||
|
using connection_t = i3ipc::connection;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all i3 root windows
|
* Get all i3 root windows
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 47d4c43bbb2d7529bb1e178115b61247e0010fd6
|
Subproject commit 13a8118c45eb213a67a2349d92969f85666afb3c
|
Loading…
Reference in a new issue