2016-11-02 19:22:45 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
|
2016-11-19 14:49:03 +00:00
|
|
|
#include "drawtypes/iconset.hpp"
|
|
|
|
#include "drawtypes/label.hpp"
|
2016-11-30 17:23:18 +00:00
|
|
|
#include "modules/bspwm.hpp"
|
|
|
|
#include "utils/file.hpp"
|
2016-11-19 14:49:03 +00:00
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "modules/meta/base.inl"
|
|
|
|
#include "modules/meta/event_module.inl"
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
namespace modules {
|
2016-11-20 22:04:31 +00:00
|
|
|
template class module<bspwm_module>;
|
|
|
|
template class event_module<bspwm_module>;
|
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
void bspwm_module::setup() {
|
|
|
|
auto socket_path = bspwm_util::get_socket_path();
|
|
|
|
|
|
|
|
if (!file_util::exists(socket_path)) {
|
|
|
|
throw module_error("Could not find socket: " + (socket_path.empty() ? "<empty>" : socket_path));
|
|
|
|
}
|
|
|
|
|
2016-11-11 10:05:21 +00:00
|
|
|
// Create ipc subscriber
|
|
|
|
m_subscriber = bspwm_util::make_subscriber();
|
2016-11-03 16:54:26 +00:00
|
|
|
|
2016-11-11 10:05:21 +00:00
|
|
|
// Load configuration values
|
2016-11-03 16:54:26 +00:00
|
|
|
GET_CONFIG_VALUE(name(), m_pinworkspaces, "pin-workspaces");
|
2016-11-12 12:37:07 +00:00
|
|
|
GET_CONFIG_VALUE(name(), m_click, "enable-click");
|
|
|
|
GET_CONFIG_VALUE(name(), m_scroll, "enable-scroll");
|
2016-11-03 16:54:26 +00:00
|
|
|
|
2016-11-11 10:05:21 +00:00
|
|
|
// Add formats and create components
|
2016-11-12 11:56:39 +00:00
|
|
|
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_STATE, {TAG_LABEL_STATE}, {TAG_LABEL_MONITOR, TAG_LABEL_MODE});
|
2016-11-03 16:54:26 +00:00
|
|
|
|
|
|
|
if (m_formatter->has(TAG_LABEL_MONITOR)) {
|
|
|
|
m_monitorlabel = load_optional_label(m_conf, name(), "label-monitor", DEFAULT_MONITOR_LABEL);
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
if (m_formatter->has(TAG_LABEL_STATE)) {
|
2016-11-12 11:56:39 +00:00
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_ACTIVE, load_optional_label(m_conf, name(), "label-active", DEFAULT_WS_LABEL)));
|
2016-11-02 19:22:45 +00:00
|
|
|
m_statelabels.insert(make_pair(
|
2016-11-12 11:56:39 +00:00
|
|
|
state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL)));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_URGENT, load_optional_label(m_conf, name(), "label-urgent", DEFAULT_WS_LABEL)));
|
2016-11-29 14:53:32 +00:00
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_OCCUPIED, load_optional_label(m_conf, name(), "label-occupied", DEFAULT_WS_LABEL)));
|
2016-11-12 11:56:39 +00:00
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL)));
|
2016-11-29 14:53:32 +00:00
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_FOCUSED_OCCUPIED, load_either_config_label(m_conf, name(), "label-focused-occupied", "label-focused", DEFAULT_WS_LABEL)));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_FOCUSED_URGENT, load_either_config_label(m_conf, name(), "label-focused-urgent", "label-focused", DEFAULT_WS_LABEL)));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_FOCUSED_EMPTY, load_either_config_label(m_conf, name(), "label-focused-empty", "label-focused", DEFAULT_WS_LABEL)));
|
2016-11-12 11:56:39 +00:00
|
|
|
m_statelabels.insert(make_pair(state_ws::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed")));
|
2016-11-19 14:49:03 +00:00
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_DIMMED_ACTIVE, load_optional_label(m_conf, name(), "label-dimmed-active")));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_DIMMED_URGENT, load_optional_label(m_conf, name(), "label-dimmed-urgent")));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_DIMMED_EMPTY, load_optional_label(m_conf, name(), "label-dimmed-empty")));
|
|
|
|
m_statelabels.insert(
|
|
|
|
make_pair(state_ws::WORKSPACE_DIMMED_OCCUPIED, load_optional_label(m_conf, name(), "label-dimmed-occupied")));
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (m_formatter->has(TAG_LABEL_MODE)) {
|
2016-11-12 11:56:39 +00:00
|
|
|
m_modelabels.insert(
|
|
|
|
make_pair(state_mode::MODE_LAYOUT_MONOCLE, load_optional_label(m_conf, name(), "label-monocle")));
|
|
|
|
m_modelabels.insert(make_pair(state_mode::MODE_LAYOUT_TILED, load_optional_label(m_conf, name(), "label-tiled")));
|
|
|
|
m_modelabels.insert(
|
|
|
|
make_pair(state_mode::MODE_STATE_FULLSCREEN, load_optional_label(m_conf, name(), "label-fullscreen")));
|
|
|
|
m_modelabels.insert(
|
|
|
|
make_pair(state_mode::MODE_STATE_FLOATING, load_optional_label(m_conf, name(), "label-floating")));
|
|
|
|
m_modelabels.insert(make_pair(state_mode::MODE_NODE_LOCKED, load_optional_label(m_conf, name(), "label-locked")));
|
|
|
|
m_modelabels.insert(make_pair(state_mode::MODE_NODE_STICKY, load_optional_label(m_conf, name(), "label-sticky")));
|
|
|
|
m_modelabels.insert(
|
|
|
|
make_pair(state_mode::MODE_NODE_PRIVATE, load_optional_label(m_conf, name(), "label-private")));
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
m_icons = make_shared<iconset>();
|
|
|
|
m_icons->add(DEFAULT_WS_ICON, make_shared<label>(m_conf.get<string>(name(), DEFAULT_WS_ICON, "")));
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
for (const auto& workspace : m_conf.get_list<string>(name(), "ws-icon", {})) {
|
2016-11-02 19:22:45 +00:00
|
|
|
auto vec = string_util::split(workspace, ';');
|
|
|
|
if (vec.size() == 2) {
|
2016-11-25 12:55:15 +00:00
|
|
|
m_icons->add(vec[0], make_shared<label>(vec[1]));
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
void bspwm_module::stop() {
|
2016-11-02 19:22:45 +00:00
|
|
|
if (m_subscriber) {
|
|
|
|
m_log.info("%s: Disconnecting from socket", name());
|
|
|
|
m_subscriber->disconnect();
|
|
|
|
}
|
|
|
|
event_module::stop();
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
bool bspwm_module::has_event() {
|
2016-11-02 19:22:45 +00:00
|
|
|
if (m_subscriber->poll(POLLHUP, 0)) {
|
|
|
|
m_log.warn("%s: Reconnecting to socket...", name());
|
|
|
|
m_subscriber = bspwm_util::make_subscriber();
|
|
|
|
}
|
|
|
|
|
|
|
|
ssize_t bytes = 0;
|
|
|
|
m_subscriber->receive(1, bytes, MSG_PEEK);
|
|
|
|
return bytes > 0;
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
bool bspwm_module::update() {
|
2016-11-02 19:22:45 +00:00
|
|
|
ssize_t bytes = 0;
|
|
|
|
string data = m_subscriber->receive(BUFSIZ - 1, bytes, 0);
|
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
if (bytes == 0) {
|
2016-11-02 19:22:45 +00:00
|
|
|
return false;
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
data = string_util::strip_trailing_newline(data);
|
|
|
|
|
|
|
|
unsigned long pos;
|
2016-11-25 12:55:15 +00:00
|
|
|
while ((pos = data.find('\n')) != string::npos) {
|
|
|
|
data.erase(pos);
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
if (data.empty()) {
|
2016-11-02 19:22:45 +00:00
|
|
|
return false;
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
const auto prefix = string{BSPWM_STATUS_PREFIX};
|
|
|
|
|
|
|
|
// If there were more than 1 row available in the channel
|
|
|
|
// we'll strip out the old updates
|
2016-11-25 12:55:15 +00:00
|
|
|
if ((pos = data.find_last_of(prefix)) > 0) {
|
2016-11-02 19:22:45 +00:00
|
|
|
data = data.substr(pos);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
if (data.compare(0, prefix.length(), prefix) != 0) {
|
|
|
|
m_log.err("%s: Unknown status '%s'", name(), data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long hash;
|
2016-11-25 12:55:15 +00:00
|
|
|
if ((hash = string_util::hash(data)) == m_hash) {
|
2016-11-02 19:22:45 +00:00
|
|
|
return false;
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
m_hash = hash;
|
|
|
|
|
|
|
|
// Extract the string for the defined monitor
|
2016-11-03 16:54:26 +00:00
|
|
|
if (m_pinworkspaces) {
|
2016-11-11 10:05:21 +00:00
|
|
|
const auto needle_active = ":M" + m_bar.monitor->name + ":";
|
|
|
|
const auto needle_inactive = ":m" + m_bar.monitor->name + ":";
|
2016-11-03 16:54:26 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
if ((pos = data.find(prefix)) != string::npos) {
|
2016-11-03 16:54:26 +00:00
|
|
|
data = data.replace(pos, prefix.length(), ":");
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
|
|
|
if ((pos = data.find(needle_active)) != string::npos) {
|
2016-11-03 16:54:26 +00:00
|
|
|
data.erase(0, pos + 1);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
|
|
|
if ((pos = data.find(needle_inactive)) != string::npos) {
|
2016-11-03 16:54:26 +00:00
|
|
|
data.erase(0, pos + 1);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
|
|
|
if ((pos = data.find(":m", 1)) != string::npos) {
|
2016-11-03 16:54:26 +00:00
|
|
|
data.erase(pos);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
|
|
|
if ((pos = data.find(":M", 1)) != string::npos) {
|
2016-11-03 16:54:26 +00:00
|
|
|
data.erase(pos);
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-12 11:56:39 +00:00
|
|
|
} else if ((pos = data.find(prefix)) != string::npos) {
|
2016-11-02 19:22:45 +00:00
|
|
|
data = data.replace(pos, prefix.length(), ":");
|
2016-11-03 16:54:26 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
int workspace_n = 0;
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
m_monitors.clear();
|
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
for (auto&& tag : string_util::split(data, ':')) {
|
2016-11-03 16:54:26 +00:00
|
|
|
if (tag.empty()) {
|
2016-11-02 19:22:45 +00:00
|
|
|
continue;
|
2016-11-03 16:54:26 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
auto value = !tag.empty() ? tag.substr(1) : "";
|
2016-11-03 16:54:26 +00:00
|
|
|
auto workspace_flag = state_ws::WORKSPACE_NONE;
|
|
|
|
auto mode_flag = state_mode::MODE_NONE;
|
|
|
|
|
|
|
|
if (tag[0] == 'm' || tag[0] == 'M') {
|
|
|
|
m_monitors.emplace_back(make_unique<bspwm_monitor>());
|
|
|
|
m_monitors.back()->name = value;
|
|
|
|
|
|
|
|
if (m_monitorlabel) {
|
|
|
|
m_monitors.back()->label = m_monitorlabel->clone();
|
|
|
|
m_monitors.back()->label->replace_token("%name%", value);
|
|
|
|
}
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
switch (tag[0]) {
|
|
|
|
case 'm':
|
2016-11-03 16:54:26 +00:00
|
|
|
m_monitors.back()->focused = false;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'M':
|
2016-11-03 16:54:26 +00:00
|
|
|
m_monitors.back()->focused = true;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2016-11-29 14:53:32 +00:00
|
|
|
workspace_flag = state_ws::WORKSPACE_FOCUSED_EMPTY;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'O':
|
2016-11-29 14:53:32 +00:00
|
|
|
workspace_flag = state_ws::WORKSPACE_FOCUSED_OCCUPIED;
|
|
|
|
break;
|
|
|
|
case 'U':
|
|
|
|
workspace_flag = state_ws::WORKSPACE_FOCUSED_URGENT;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
workspace_flag = state_ws::WORKSPACE_EMPTY;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'o':
|
2016-11-03 16:54:26 +00:00
|
|
|
workspace_flag = state_ws::WORKSPACE_OCCUPIED;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'u':
|
2016-11-03 16:54:26 +00:00
|
|
|
workspace_flag = state_ws::WORKSPACE_URGENT;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
switch (value[0]) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'M':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_LAYOUT_MONOCLE;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'T':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_LAYOUT_TILED;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_log.warn("%s: Undefined L => '%s'", name(), value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
switch (value[0]) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'T':
|
|
|
|
break;
|
|
|
|
case '=':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_STATE_FULLSCREEN;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'F':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_STATE_FLOATING;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_log.warn("%s: Undefined T => '%s'", name(), value);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'G':
|
2016-11-03 16:54:26 +00:00
|
|
|
if (!m_monitors.back()->focused) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-11-02 19:22:45 +00:00
|
|
|
for (int i = 0; i < (int)value.length(); i++) {
|
|
|
|
switch (value[i]) {
|
|
|
|
case 0:
|
|
|
|
break;
|
|
|
|
case 'L':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_NODE_LOCKED;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'S':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_NODE_STICKY;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
case 'P':
|
2016-11-03 16:54:26 +00:00
|
|
|
mode_flag = state_mode::MODE_NODE_PRIVATE;
|
2016-11-02 19:22:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
m_log.warn("%s: Undefined G => '%s'", name(), value.substr(i, 1));
|
|
|
|
}
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
if (mode_flag != state_mode::MODE_NONE && !m_modelabels.empty()) {
|
|
|
|
m_monitors.back()->modes.emplace_back(m_modelabels.find(mode_flag)->second->clone());
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
|
|
|
|
default:
|
|
|
|
m_log.warn("%s: Undefined tag => '%s'", name(), tag.substr(0, 1));
|
|
|
|
}
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
if (workspace_flag != state_ws::WORKSPACE_NONE && m_formatter->has(TAG_LABEL_STATE)) {
|
2016-11-02 19:22:45 +00:00
|
|
|
auto icon = m_icons->get(value, DEFAULT_WS_ICON);
|
|
|
|
auto label = m_statelabels.find(workspace_flag)->second->clone();
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
if (!m_monitors.back()->focused) {
|
|
|
|
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED)->second);
|
2016-11-15 06:33:10 +00:00
|
|
|
switch (workspace_flag) {
|
2016-11-19 14:49:03 +00:00
|
|
|
case state_ws::WORKSPACE_ACTIVE:
|
|
|
|
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED_ACTIVE)->second);
|
|
|
|
break;
|
|
|
|
case state_ws::WORKSPACE_OCCUPIED:
|
|
|
|
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED_OCCUPIED)->second);
|
|
|
|
break;
|
|
|
|
case state_ws::WORKSPACE_URGENT:
|
|
|
|
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED_URGENT)->second);
|
|
|
|
break;
|
|
|
|
case state_ws::WORKSPACE_EMPTY:
|
|
|
|
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED_EMPTY)->second);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2016-11-15 06:33:10 +00:00
|
|
|
}
|
2016-11-03 16:54:26 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
label->reset_tokens();
|
|
|
|
label->replace_token("%name%", value);
|
|
|
|
label->replace_token("%icon%", icon->get());
|
|
|
|
label->replace_token("%index%", to_string(++workspace_n));
|
|
|
|
|
2016-11-12 11:56:39 +00:00
|
|
|
m_monitors.back()->workspaces.emplace_back(make_pair(workspace_flag, move(label)));
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
if (mode_flag != state_mode::MODE_NONE && !m_modelabels.empty()) {
|
|
|
|
m_monitors.back()->modes.emplace_back(m_modelabels.find(mode_flag)->second->clone());
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
string bspwm_module::get_output() {
|
2016-11-03 16:54:26 +00:00
|
|
|
string output;
|
|
|
|
for (m_index = 0; m_index < m_monitors.size(); m_index++) {
|
|
|
|
if (m_index > 0) {
|
|
|
|
m_builder->space(m_formatter->get(DEFAULT_FORMAT)->spacing);
|
|
|
|
}
|
|
|
|
output += event_module::get_output();
|
|
|
|
}
|
|
|
|
return output;
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
bool bspwm_module::build(builder* builder, const string& tag) const {
|
2016-11-03 16:54:26 +00:00
|
|
|
if (tag == TAG_LABEL_MONITOR) {
|
|
|
|
builder->node(m_monitors[m_index]->label);
|
|
|
|
return true;
|
|
|
|
} else if (tag == TAG_LABEL_STATE) {
|
|
|
|
int workspace_n = 0;
|
|
|
|
|
2016-11-13 00:13:39 +00:00
|
|
|
if (m_scroll) {
|
|
|
|
builder->cmd(mousebtn::SCROLL_DOWN, EVENT_SCROLL_DOWN);
|
|
|
|
builder->cmd(mousebtn::SCROLL_UP, EVENT_SCROLL_UP);
|
|
|
|
}
|
2016-11-12 12:37:07 +00:00
|
|
|
|
2016-11-13 00:13:39 +00:00
|
|
|
for (auto&& ws : m_monitors[m_index]->workspaces) {
|
2016-11-03 16:54:26 +00:00
|
|
|
if (ws.second.get()) {
|
2016-11-12 12:37:07 +00:00
|
|
|
if (m_click) {
|
|
|
|
string event{EVENT_CLICK};
|
|
|
|
event += to_string(m_index);
|
|
|
|
event += "+";
|
|
|
|
event += to_string(++workspace_n);
|
|
|
|
|
|
|
|
builder->cmd(mousebtn::LEFT, event);
|
|
|
|
builder->node(ws.second);
|
2016-11-24 18:24:47 +00:00
|
|
|
builder->cmd_close();
|
2016-11-12 12:37:07 +00:00
|
|
|
} else {
|
2016-11-26 08:38:55 +00:00
|
|
|
workspace_n++;
|
2016-11-12 12:37:07 +00:00
|
|
|
builder->node(ws.second);
|
|
|
|
}
|
|
|
|
}
|
2016-11-13 00:13:39 +00:00
|
|
|
}
|
2016-11-03 16:54:26 +00:00
|
|
|
|
2016-11-13 00:13:39 +00:00
|
|
|
if (m_scroll) {
|
2016-11-24 18:24:47 +00:00
|
|
|
builder->cmd_close();
|
|
|
|
builder->cmd_close();
|
2016-11-03 16:54:26 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
return workspace_n > 0;
|
|
|
|
} else if (tag == TAG_LABEL_MODE && m_monitors[m_index]->focused) {
|
|
|
|
int modes_n = 0;
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
for (auto&& mode : m_monitors[m_index]->modes) {
|
2016-11-11 10:04:53 +00:00
|
|
|
if (*mode.get()) {
|
|
|
|
builder->node(mode);
|
|
|
|
modes_n++;
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
return modes_n > 0;
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 16:54:26 +00:00
|
|
|
return false;
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-30 17:23:18 +00:00
|
|
|
bool bspwm_module::handle_event(string cmd) {
|
2016-11-11 18:55:37 +00:00
|
|
|
if (cmd.find(EVENT_PREFIX) != 0) {
|
2016-11-02 19:22:45 +00:00
|
|
|
return false;
|
2016-11-03 16:54:26 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-12 11:56:39 +00:00
|
|
|
auto send_command = [this](string payload_cmd, string log_info) {
|
|
|
|
try {
|
2016-11-03 16:54:26 +00:00
|
|
|
auto ipc = bspwm_util::make_connection();
|
2016-11-11 18:55:37 +00:00
|
|
|
auto payload = bspwm_util::make_payload(payload_cmd);
|
|
|
|
m_log.info("%s: %s", name(), log_info);
|
2016-11-03 16:54:26 +00:00
|
|
|
ipc->send(payload->data, payload->len, 0);
|
|
|
|
ipc->disconnect();
|
2016-11-12 11:56:39 +00:00
|
|
|
} catch (const system_error& err) {
|
|
|
|
m_log.err("%s: %s", name(), err.what());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
if (cmd.compare(0, strlen(EVENT_CLICK), EVENT_CLICK) == 0) {
|
|
|
|
cmd.erase(0, strlen(EVENT_CLICK));
|
2016-11-11 18:55:37 +00:00
|
|
|
|
2016-11-12 11:56:39 +00:00
|
|
|
size_t separator = string_util::find_nth(cmd, 0, "+", 1);
|
|
|
|
size_t monitor_n = std::atoi(cmd.substr(0, separator).c_str());
|
|
|
|
string workspace_n = cmd.substr(separator + 1);
|
2016-11-11 18:55:37 +00:00
|
|
|
|
2016-11-12 11:56:39 +00:00
|
|
|
if (monitor_n < m_monitors.size()) {
|
|
|
|
send_command("desktop -f " + m_monitors[monitor_n]->name + ":^" + workspace_n,
|
2016-11-11 18:55:37 +00:00
|
|
|
"Sending desktop focus command to ipc handler");
|
2016-11-12 11:56:39 +00:00
|
|
|
} else {
|
|
|
|
m_log.err("%s: Invalid monitor index in command: %s", name(), cmd);
|
2016-11-03 16:54:26 +00:00
|
|
|
}
|
2016-11-12 11:56:39 +00:00
|
|
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_UP), EVENT_SCROLL_UP) == 0) {
|
|
|
|
send_command("desktop -f next", "Sending desktop next command to ipc handler");
|
|
|
|
} else if (cmd.compare(0, strlen(EVENT_SCROLL_DOWN), EVENT_SCROLL_DOWN) == 0) {
|
|
|
|
send_command("desktop -f prev", "Sending desktop prev command to ipc handler");
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2016-11-30 17:23:18 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|