mirror of
https://github.com/polybar/polybar.git
synced 2024-12-02 14:05:27 -05:00
refactor: Moved global signals to separate namespace
This commit is contained in:
parent
20991a3465
commit
1445b95af8
5 changed files with 118 additions and 95 deletions
|
@ -7,6 +7,7 @@
|
|||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/parser.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "components/x11/connection.hpp"
|
||||
#include "components/x11/draw.hpp"
|
||||
|
@ -27,10 +28,6 @@
|
|||
|
||||
LEMONBUDDY_NS
|
||||
|
||||
namespace bar_signals {
|
||||
delegate::Signal1<string> action_click;
|
||||
};
|
||||
|
||||
class bar : public xpp::event::sink<evt::button_press, evt::expose> {
|
||||
public:
|
||||
/**
|
||||
|
@ -48,19 +45,19 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose> {
|
|||
*/
|
||||
~bar() {
|
||||
std::lock_guard<threading_util::spin_lock> lck(m_lock);
|
||||
parser_signals::alignment_change.disconnect(this, &bar::on_alignment_change);
|
||||
parser_signals::attribute_set.disconnect(this, &bar::on_attribute_set);
|
||||
parser_signals::attribute_unset.disconnect(this, &bar::on_attribute_unset);
|
||||
parser_signals::attribute_toggle.disconnect(this, &bar::on_attribute_toggle);
|
||||
parser_signals::action_block_open.disconnect(this, &bar::on_action_block_open);
|
||||
parser_signals::action_block_close.disconnect(this, &bar::on_action_block_close);
|
||||
parser_signals::color_change.disconnect(this, &bar::on_color_change);
|
||||
parser_signals::font_change.disconnect(this, &bar::on_font_change);
|
||||
parser_signals::pixel_offset.disconnect(this, &bar::on_pixel_offset);
|
||||
parser_signals::ascii_text_write.disconnect(this, &bar::draw_character);
|
||||
parser_signals::unicode_text_write.disconnect(this, &bar::draw_character);
|
||||
g_signals::parser::alignment_change.disconnect(this, &bar::on_alignment_change);
|
||||
g_signals::parser::attribute_set.disconnect(this, &bar::on_attribute_set);
|
||||
g_signals::parser::attribute_unset.disconnect(this, &bar::on_attribute_unset);
|
||||
g_signals::parser::attribute_toggle.disconnect(this, &bar::on_attribute_toggle);
|
||||
g_signals::parser::action_block_open.disconnect(this, &bar::on_action_block_open);
|
||||
g_signals::parser::action_block_close.disconnect(this, &bar::on_action_block_close);
|
||||
g_signals::parser::color_change.disconnect(this, &bar::on_color_change);
|
||||
g_signals::parser::font_change.disconnect(this, &bar::on_font_change);
|
||||
g_signals::parser::pixel_offset.disconnect(this, &bar::on_pixel_offset);
|
||||
g_signals::parser::ascii_text_write.disconnect(this, &bar::draw_character);
|
||||
g_signals::parser::unicode_text_write.disconnect(this, &bar::draw_character);
|
||||
if (m_tray.align != alignment::NONE)
|
||||
tray_signals::report_slotcount.disconnect(this, &bar::on_tray_report);
|
||||
g_signals::tray::report_slotcount.disconnect(this, &bar::on_tray_report);
|
||||
if (m_sinkattached)
|
||||
m_connection.detach_sink(this, 1);
|
||||
m_window.destroy();
|
||||
|
@ -470,20 +467,20 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose> {
|
|||
// }}}
|
||||
// Connect signal handlers {{{
|
||||
|
||||
parser_signals::alignment_change.connect(this, &bar::on_alignment_change);
|
||||
parser_signals::attribute_set.connect(this, &bar::on_attribute_set);
|
||||
parser_signals::attribute_unset.connect(this, &bar::on_attribute_unset);
|
||||
parser_signals::attribute_toggle.connect(this, &bar::on_attribute_toggle);
|
||||
parser_signals::action_block_open.connect(this, &bar::on_action_block_open);
|
||||
parser_signals::action_block_close.connect(this, &bar::on_action_block_close);
|
||||
parser_signals::color_change.connect(this, &bar::on_color_change);
|
||||
parser_signals::font_change.connect(this, &bar::on_font_change);
|
||||
parser_signals::pixel_offset.connect(this, &bar::on_pixel_offset);
|
||||
parser_signals::ascii_text_write.connect(this, &bar::draw_character);
|
||||
parser_signals::unicode_text_write.connect(this, &bar::draw_character);
|
||||
g_signals::parser::alignment_change.connect(this, &bar::on_alignment_change);
|
||||
g_signals::parser::attribute_set.connect(this, &bar::on_attribute_set);
|
||||
g_signals::parser::attribute_unset.connect(this, &bar::on_attribute_unset);
|
||||
g_signals::parser::attribute_toggle.connect(this, &bar::on_attribute_toggle);
|
||||
g_signals::parser::action_block_open.connect(this, &bar::on_action_block_open);
|
||||
g_signals::parser::action_block_close.connect(this, &bar::on_action_block_close);
|
||||
g_signals::parser::color_change.connect(this, &bar::on_color_change);
|
||||
g_signals::parser::font_change.connect(this, &bar::on_font_change);
|
||||
g_signals::parser::pixel_offset.connect(this, &bar::on_pixel_offset);
|
||||
g_signals::parser::ascii_text_write.connect(this, &bar::draw_character);
|
||||
g_signals::parser::unicode_text_write.connect(this, &bar::draw_character);
|
||||
|
||||
if (m_tray.align != alignment::NONE)
|
||||
tray_signals::report_slotcount.connect(this, &bar::on_tray_report);
|
||||
g_signals::tray::report_slotcount.connect(this, &bar::on_tray_report);
|
||||
|
||||
// }}}
|
||||
|
||||
|
@ -652,8 +649,8 @@ class bar : public xpp::event::sink<evt::button_press, evt::expose> {
|
|||
m_log.trace("action.start_x = %i", action.start_x);
|
||||
m_log.trace("action.end_x = %i", action.end_x);
|
||||
|
||||
if (!bar_signals::action_click.empty())
|
||||
bar_signals::action_click.emit(action.command);
|
||||
if (!g_signals::bar::action_click.empty())
|
||||
g_signals::bar::action_click.emit(action.command);
|
||||
else
|
||||
m_log.warn("No signal handler's connected to 'action_click'");
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include "components/bar.hpp"
|
||||
#include "components/config.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "components/x11/connection.hpp"
|
||||
#include "components/x11/randr.hpp"
|
||||
#include "components/x11/tray.hpp"
|
||||
|
@ -87,7 +88,7 @@ class controller {
|
|||
}
|
||||
|
||||
m_log.trace("controller: Deconstruct bar instance");
|
||||
bar_signals::action_click.disconnect(this, &controller::on_module_click);
|
||||
g_signals::bar::action_click.disconnect(this, &controller::on_module_click);
|
||||
m_bar.reset();
|
||||
|
||||
m_log.trace("controller: Interrupt X event loop");
|
||||
|
@ -162,7 +163,7 @@ class controller {
|
|||
std::cout << m_bar->settings().wmname << std::endl;
|
||||
return;
|
||||
} else if (!to_stdout) {
|
||||
bar_signals::action_click.connect(this, &controller::on_module_click);
|
||||
g_signals::bar::action_click.connect(this, &controller::on_module_click);
|
||||
}
|
||||
} catch (const std::exception& err) {
|
||||
throw application_error("Failed to setup bar renderer: " + string{err.what()});
|
||||
|
@ -520,13 +521,11 @@ class controller {
|
|||
m_log.trace("controller: Unrecognized input '%s'", input);
|
||||
m_log.trace("controller: Forwarding input to shell");
|
||||
|
||||
auto command = command_util::make_command("/usr/bin/env\nsh\n-c\n"+ input);
|
||||
auto command = command_util::make_command("/usr/bin/env\nsh\n-c\n" + input);
|
||||
|
||||
try {
|
||||
command->exec(false);
|
||||
command->tail([this](std::string output){
|
||||
m_log.trace("> %s", output);
|
||||
});
|
||||
command->tail([this](std::string output) { m_log.trace("> %s", output); });
|
||||
command->wait();
|
||||
} catch (const application_error& err) {
|
||||
m_log.err(err.what());
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "utils/math.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
|
@ -12,20 +13,6 @@ LEMONBUDDY_NS
|
|||
|
||||
DEFINE_ERROR(unrecognized_token);
|
||||
|
||||
namespace parser_signals {
|
||||
delegate::Signal1<alignment> alignment_change;
|
||||
delegate::Signal1<attribute> attribute_set;
|
||||
delegate::Signal1<attribute> attribute_unset;
|
||||
delegate::Signal1<attribute> attribute_toggle;
|
||||
delegate::Signal2<mousebtn, string> action_block_open;
|
||||
delegate::Signal1<mousebtn> action_block_close;
|
||||
delegate::Signal2<gc, color> color_change;
|
||||
delegate::Signal1<int> font_change;
|
||||
delegate::Signal1<int> pixel_offset;
|
||||
delegate::Signal1<uint16_t> ascii_text_write;
|
||||
delegate::Signal1<uint16_t> unicode_text_write;
|
||||
};
|
||||
|
||||
class parser {
|
||||
public:
|
||||
/**
|
||||
|
@ -77,81 +64,81 @@ class parser {
|
|||
switch (tag) {
|
||||
case 'B':
|
||||
// Ignore tag if it occurs again later in the same block
|
||||
if (data.find(" B") == string::npos && !parser_signals::color_change.empty())
|
||||
parser_signals::color_change.emit(gc::BG, parse_color(value, m_bar.background));
|
||||
if (data.find(" B") == string::npos && !g_signals::parser::color_change.empty())
|
||||
g_signals::parser::color_change.emit(gc::BG, parse_color(value, m_bar.background));
|
||||
break;
|
||||
|
||||
case 'F':
|
||||
// Ignore tag if it occurs again later in the same block
|
||||
if (data.find(" F") == string::npos && !parser_signals::color_change.empty())
|
||||
parser_signals::color_change.emit(gc::FG, parse_color(value, m_bar.foreground));
|
||||
if (data.find(" F") == string::npos && !g_signals::parser::color_change.empty())
|
||||
g_signals::parser::color_change.emit(gc::FG, parse_color(value, m_bar.foreground));
|
||||
break;
|
||||
|
||||
case 'U':
|
||||
// Ignore tag if it occurs again later in the same block
|
||||
if (data.find(" U") == string::npos && !parser_signals::color_change.empty()) {
|
||||
parser_signals::color_change.emit(gc::UL, parse_color(value, m_bar.linecolor));
|
||||
parser_signals::color_change.emit(gc::OL, parse_color(value, m_bar.linecolor));
|
||||
if (data.find(" U") == string::npos && !g_signals::parser::color_change.empty()) {
|
||||
g_signals::parser::color_change.emit(gc::UL, parse_color(value, m_bar.linecolor));
|
||||
g_signals::parser::color_change.emit(gc::OL, parse_color(value, m_bar.linecolor));
|
||||
}
|
||||
break;
|
||||
|
||||
case 'R':
|
||||
if (!parser_signals::color_change.empty()) {
|
||||
parser_signals::color_change.emit(gc::BG, m_bar.foreground);
|
||||
parser_signals::color_change.emit(gc::FG, m_bar.background);
|
||||
if (!g_signals::parser::color_change.empty()) {
|
||||
g_signals::parser::color_change.emit(gc::BG, m_bar.foreground);
|
||||
g_signals::parser::color_change.emit(gc::FG, m_bar.background);
|
||||
}
|
||||
break;
|
||||
|
||||
case 'T':
|
||||
if (data.find(" T") == string::npos && !parser_signals::font_change.empty())
|
||||
parser_signals::font_change.emit(parse_fontindex(value));
|
||||
if (data.find(" T") == string::npos && !g_signals::parser::font_change.empty())
|
||||
g_signals::parser::font_change.emit(parse_fontindex(value));
|
||||
break;
|
||||
|
||||
case 'O':
|
||||
if (!parser_signals::pixel_offset.empty())
|
||||
parser_signals::pixel_offset.emit(std::atoi(value.c_str()));
|
||||
if (!g_signals::parser::pixel_offset.empty())
|
||||
g_signals::parser::pixel_offset.emit(std::atoi(value.c_str()));
|
||||
break;
|
||||
|
||||
case 'l':
|
||||
if (!parser_signals::alignment_change.empty())
|
||||
parser_signals::alignment_change.emit(alignment::LEFT);
|
||||
if (!g_signals::parser::alignment_change.empty())
|
||||
g_signals::parser::alignment_change.emit(alignment::LEFT);
|
||||
break;
|
||||
|
||||
case 'c':
|
||||
if (!parser_signals::alignment_change.empty())
|
||||
parser_signals::alignment_change.emit(alignment::CENTER);
|
||||
if (!g_signals::parser::alignment_change.empty())
|
||||
g_signals::parser::alignment_change.emit(alignment::CENTER);
|
||||
break;
|
||||
|
||||
case 'r':
|
||||
if (!parser_signals::alignment_change.empty())
|
||||
parser_signals::alignment_change.emit(alignment::RIGHT);
|
||||
if (!g_signals::parser::alignment_change.empty())
|
||||
g_signals::parser::alignment_change.emit(alignment::RIGHT);
|
||||
break;
|
||||
|
||||
case '+':
|
||||
if (!parser_signals::attribute_set.empty())
|
||||
parser_signals::attribute_set.emit(parse_attr(value[0]));
|
||||
if (!g_signals::parser::attribute_set.empty())
|
||||
g_signals::parser::attribute_set.emit(parse_attr(value[0]));
|
||||
break;
|
||||
|
||||
case '-':
|
||||
if (!parser_signals::attribute_unset.empty())
|
||||
parser_signals::attribute_unset.emit(parse_attr(value[0]));
|
||||
if (!g_signals::parser::attribute_unset.empty())
|
||||
g_signals::parser::attribute_unset.emit(parse_attr(value[0]));
|
||||
break;
|
||||
|
||||
case '!':
|
||||
if (!parser_signals::attribute_toggle.empty())
|
||||
parser_signals::attribute_toggle.emit(parse_attr(value[0]));
|
||||
if (!g_signals::parser::attribute_toggle.empty())
|
||||
g_signals::parser::attribute_toggle.emit(parse_attr(value[0]));
|
||||
break;
|
||||
|
||||
case 'A':
|
||||
if (isdigit(data[0])) {
|
||||
value = parse_action_cmd(data);
|
||||
if (!parser_signals::action_block_open.empty())
|
||||
parser_signals::action_block_open.emit(parse_action_btn(data), value);
|
||||
if (!g_signals::parser::action_block_open.empty())
|
||||
g_signals::parser::action_block_open.emit(parse_action_btn(data), value);
|
||||
m_actions.push_back(data[0] - '0');
|
||||
value += "0::"; // make sure we strip the correct length (btn+wrapping colons)
|
||||
} else {
|
||||
if (!parser_signals::action_block_close.empty())
|
||||
parser_signals::action_block_close.emit(parse_action_btn(data));
|
||||
if (!g_signals::parser::action_block_close.empty())
|
||||
g_signals::parser::action_block_close.emit(parse_action_btn(data));
|
||||
m_actions.pop_back();
|
||||
}
|
||||
break;
|
||||
|
@ -178,31 +165,31 @@ class parser {
|
|||
// size_t n = 0;
|
||||
// while (sequence[n] != '\0' && static_cast<uint8_t>(sequence[n]) < 0x80 && ++n <= next_tag)
|
||||
// ;
|
||||
// parser_signals::ascii_text_write.emit(data.substr(0, n));
|
||||
// g_signals::parser::ascii_text_write.emit(data.substr(0, n));
|
||||
// return data.length();
|
||||
// }
|
||||
|
||||
if (utf[0] < 0x80) {
|
||||
parser_signals::ascii_text_write.emit(utf[0]);
|
||||
g_signals::parser::ascii_text_write.emit(utf[0]);
|
||||
return 1;
|
||||
} else if ((utf[0] & 0xe0) == 0xc0) { // 2 byte utf-8 sequence
|
||||
parser_signals::unicode_text_write.emit((utf[0] & 0x1f) << 6 | (utf[1] & 0x3f));
|
||||
g_signals::parser::unicode_text_write.emit((utf[0] & 0x1f) << 6 | (utf[1] & 0x3f));
|
||||
return 2;
|
||||
} else if ((utf[0] & 0xf0) == 0xe0) { // 3 byte utf-8 sequence
|
||||
parser_signals::unicode_text_write.emit(
|
||||
g_signals::parser::unicode_text_write.emit(
|
||||
(utf[0] & 0xf) << 12 | (utf[1] & 0x3f) << 6 | (utf[2] & 0x3f));
|
||||
return 3;
|
||||
} else if ((utf[0] & 0xf8) == 0xf0) { // 4 byte utf-8 sequence
|
||||
parser_signals::unicode_text_write.emit(0xfffd);
|
||||
g_signals::parser::unicode_text_write.emit(0xfffd);
|
||||
return 4;
|
||||
} else if ((utf[0] & 0xfc) == 0xf8) { // 5 byte utf-8 sequence
|
||||
parser_signals::unicode_text_write.emit(0xfffd);
|
||||
g_signals::parser::unicode_text_write.emit(0xfffd);
|
||||
return 5;
|
||||
} else if ((utf[0] & 0xfe) == 0xfc) { // 6 byte utf-8 sequence
|
||||
parser_signals::unicode_text_write.emit(0xfffd);
|
||||
g_signals::parser::unicode_text_write.emit(0xfffd);
|
||||
return 6;
|
||||
} else { // invalid utf-8 sequence
|
||||
parser_signals::ascii_text_write.emit(utf[0]);
|
||||
g_signals::parser::ascii_text_write.emit(utf[0]);
|
||||
return 1;
|
||||
}
|
||||
} // }}}
|
||||
|
|
44
include/components/signals.hpp
Normal file
44
include/components/signals.hpp
Normal file
|
@ -0,0 +1,44 @@
|
|||
#pragma once
|
||||
|
||||
#include <fastdelegate/fastdelegate.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/types.hpp"
|
||||
|
||||
LEMONBUDDY_NS
|
||||
|
||||
namespace g_signals {
|
||||
/**
|
||||
* Signals used to communicate with the bar window
|
||||
*/
|
||||
namespace bar {
|
||||
static delegate::Signal1<string> action_click;
|
||||
static delegate::Signal1<bool> visibility_change;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals used to communicate with the input parser
|
||||
*/
|
||||
namespace parser {
|
||||
static delegate::Signal1<alignment> alignment_change;
|
||||
static delegate::Signal1<attribute> attribute_set;
|
||||
static delegate::Signal1<attribute> attribute_unset;
|
||||
static delegate::Signal1<attribute> attribute_toggle;
|
||||
static delegate::Signal2<mousebtn, string> action_block_open;
|
||||
static delegate::Signal1<mousebtn> action_block_close;
|
||||
static delegate::Signal2<gc, color> color_change;
|
||||
static delegate::Signal1<int> font_change;
|
||||
static delegate::Signal1<int> pixel_offset;
|
||||
static delegate::Signal1<uint16_t> ascii_text_write;
|
||||
static delegate::Signal1<uint16_t> unicode_text_write;
|
||||
}
|
||||
|
||||
/**
|
||||
* Signals used to communicate with the tray manager
|
||||
*/
|
||||
namespace tray {
|
||||
static delegate::Signal1<uint16_t> report_slotcount;
|
||||
}
|
||||
}
|
||||
|
||||
LEMONBUDDY_NS_END
|
|
@ -2,10 +2,10 @@
|
|||
|
||||
#include <xcb/xcb.h>
|
||||
#include <xcb/xcb_icccm.h>
|
||||
#include <fastdelegate/fastdelegate.hpp>
|
||||
|
||||
#include "common.hpp"
|
||||
#include "components/logger.hpp"
|
||||
#include "components/signals.hpp"
|
||||
#include "components/types.hpp"
|
||||
#include "components/x11/connection.hpp"
|
||||
#include "components/x11/xembed.hpp"
|
||||
|
@ -24,10 +24,6 @@
|
|||
|
||||
LEMONBUDDY_NS
|
||||
|
||||
namespace tray_signals {
|
||||
delegate::Signal1<uint16_t> report_slotcount;
|
||||
};
|
||||
|
||||
// class definition : trayclient {{{
|
||||
|
||||
class trayclient {
|
||||
|
@ -225,8 +221,8 @@ class traymanager
|
|||
}
|
||||
}
|
||||
|
||||
if (!tray_signals::report_slotcount.empty())
|
||||
tray_signals::report_slotcount.emit(mapped_clients);
|
||||
if (!g_signals::tray::report_slotcount.empty())
|
||||
g_signals::tray::report_slotcount.emit(mapped_clients);
|
||||
|
||||
if (!width && m_mapped) {
|
||||
m_connection.unmap_window(m_tray);
|
||||
|
|
Loading…
Reference in a new issue