Incorporate Reviews

This commit is contained in:
patrick96 2019-08-06 19:35:07 +02:00 committed by Patrick Ziegler
parent 57d364a2fc
commit 211b0bbfd8
11 changed files with 55 additions and 71 deletions

View File

@ -13,7 +13,7 @@ using std::map;
namespace drawtypes {
class label;
using label_t = shared_ptr<label>;
}
} // namespace drawtypes
using namespace drawtypes;
class builder {

View File

@ -29,12 +29,12 @@ class parser {
void codeblock(string&& data, const bar_settings& bar);
size_t text(string&& data);
unsigned int parse_color(const string& s, unsigned int fallback = 0);
int parse_fontindex(const string& s);
attribute parse_attr(const char attr);
static unsigned int parse_color(const string& s, unsigned int fallback = 0);
static int parse_fontindex(const string& s);
static attribute parse_attr(const char attr);
mousebtn parse_action_btn(const string& data);
string parse_action_cmd(string&& data);
controltag parse_control(const string& data);
static string parse_action_cmd(string&& data);
static controltag parse_control(const string& data);
private:
signal_emitter& m_sig;

View File

@ -1,7 +1,7 @@
#pragma once
#include <bitset>
#include <cairo/cairo.h>
#include <bitset>
#include <memory>
#include "cairo/fwd.hpp"
@ -41,8 +41,8 @@ class renderer
using make_type = unique_ptr<renderer>;
static make_type make(const bar_settings& bar);
explicit renderer(
connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar, background_manager& background_manager);
explicit renderer(connection& conn, signal_emitter& sig, const config&, const logger& logger, const bar_settings& bar,
background_manager& background_manager);
~renderer();
xcb_window_t window() const;

View File

@ -48,7 +48,7 @@ enum class syntaxtag {
*/
enum class controltag {
NONE = 0,
R, // Reset all open tags (B, F, T, o, u). Used at module edges
R, // Reset all open tags (B, F, T, o, u). Used at module edges
};
enum class mousebtn { NONE = 0, LEFT, MIDDLE, RIGHT, SCROLL_UP, SCROLL_DOWN, DOUBLE_LEFT, DOUBLE_MIDDLE, DOUBLE_RIGHT };

View File

@ -9,13 +9,6 @@
POLYBAR_NS
// fwd
enum class mousebtn;
enum class syntaxtag;
enum class controltag;
enum class alignment;
enum class attribute;
namespace signals {
namespace detail {
class signal {
@ -55,7 +48,7 @@ namespace signals {
private:
void* m_ptr;
};
}
} // namespace detail
namespace eventqueue {
struct start : public detail::base_signal<start> {
@ -76,7 +69,7 @@ namespace signals {
struct check_state : public detail::base_signal<check_state> {
using base_type::base_type;
};
}
} // namespace eventqueue
namespace ipc {
struct command : public detail::value_signal<command, string> {
@ -88,7 +81,7 @@ namespace signals {
struct action : public detail::value_signal<action, string> {
using base_type::base_type;
};
}
} // namespace ipc
namespace ui {
struct ready : public detail::base_signal<ready> {
@ -129,13 +122,13 @@ namespace signals {
struct update_geometry : public detail::base_signal<update_geometry> {
using base_type::base_type;
};
}
} // namespace ui
namespace ui_tray {
struct mapped_clients : public detail::value_signal<mapped_clients, unsigned int> {
using base_type::base_type;
};
}
} // namespace ui_tray
namespace parser {
struct change_background : public detail::value_signal<change_background, unsigned int> {
@ -183,7 +176,7 @@ namespace signals {
struct control : public detail::value_signal<control, controltag> {
using base_type::base_type;
};
}
}
} // namespace parser
} // namespace signals
POLYBAR_NS_END

View File

@ -21,12 +21,12 @@ namespace signals {
struct notify_change;
struct notify_forcechange;
struct check_state;
}
} // namespace eventqueue
namespace ipc {
struct command;
struct hook;
struct action;
}
} // namespace ipc
namespace ui {
struct ready;
struct changed;
@ -40,7 +40,7 @@ namespace signals {
struct request_snapshot;
struct update_background;
struct update_geometry;
}
} // namespace ui
namespace ui_tray {
struct mapped_clients;
}
@ -60,7 +60,7 @@ namespace signals {
struct action_end;
struct text;
struct control;
}
}
} // namespace parser
} // namespace signals
POLYBAR_NS_END

View File

@ -1,9 +1,9 @@
#include "modules/meta/base.hpp"
#include "components/builder.hpp"
#include "components/config.hpp"
#include "components/logger.hpp"
#include "events/signal.hpp"
#include "events/signal_emitter.hpp"
#include "modules/meta/base.hpp"
POLYBAR_NS
@ -178,6 +178,6 @@ namespace modules {
}
// }}}
}
} // namespace modules
POLYBAR_NS_END

View File

@ -3,7 +3,6 @@
#include "components/builder.hpp"
#include "drawtypes/label.hpp"
#include "utils/color.hpp"
#include "utils/math.hpp"
#include "utils/string.hpp"
#include "utils/time.hpp"
POLYBAR_NS
@ -425,7 +424,7 @@ void builder::control(controltag tag) {
break;
}
if(!str.empty()) {
if (!str.empty()) {
tag_open(syntaxtag::P, str);
}
}
@ -488,8 +487,7 @@ string builder::get_label_text(const label_t& label) {
if (maxlen > 0 && string_util::char_len(text) > maxlen) {
if (label->m_ellipsis) {
text = string_util::utf8_truncate(std::move(text), maxlen - 3) + "...";
}
else {
} else {
text = string_util::utf8_truncate(std::move(text), maxlen);
}
}

View File

@ -7,8 +7,6 @@
#include "settings.hpp"
#include "utils/color.hpp"
#include "utils/factory.hpp"
#include "utils/file.hpp"
#include "utils/math.hpp"
#include "utils/memory.hpp"
#include "utils/string.hpp"
@ -160,32 +158,31 @@ void parser::codeblock(string&& data, const bar_settings& bar) {
m_sig.emit(attribute_toggle{parse_attr(value[0])});
break;
case 'A':
{
bool has_btn_id = (data[0] != ':');
if (isdigit(data[0]) || !has_btn_id) {
value = parse_action_cmd(data.substr(has_btn_id ? 1 : 0));
mousebtn btn = parse_action_btn(data);
m_actions.push_back(static_cast<int>(btn));
case 'A': {
bool has_btn_id = (data[0] != ':');
if (isdigit(data[0]) || !has_btn_id) {
value = parse_action_cmd(data.substr(has_btn_id ? 1 : 0));
mousebtn btn = parse_action_btn(data);
m_actions.push_back(static_cast<int>(btn));
// Unescape colons inside command before sending it to the renderer
auto cmd = string_util::replace_all(value, "\\:", ":");
m_sig.emit(action_begin{action{btn, cmd}});
// Unescape colons inside command before sending it to the renderer
auto cmd = string_util::replace_all(value, "\\:", ":");
m_sig.emit(action_begin{action{btn, cmd}});
/*
* make sure value has the same length as the inside of the action
* tag which is btn_id + ':' + value + ':'
*/
if (has_btn_id) {
value += "0";
}
value += "::";
} else if (!m_actions.empty()) {
m_sig.emit(action_end{parse_action_btn(value)});
m_actions.pop_back();
/*
* make sure value has the same length as the inside of the action
* tag which is btn_id + ':' + value + ':'
*/
if (has_btn_id) {
value += "0";
}
break;
value += "::";
} else if (!m_actions.empty()) {
m_sig.emit(action_end{parse_action_btn(value)});
m_actions.pop_back();
}
break;
}
// Internal Polybar control tags
case 'P':
@ -298,11 +295,11 @@ string parser::parse_action_cmd(string&& data) {
}
controltag parser::parse_control(const string& data) {
if(data.length() != 1) {
if (data.length() != 1) {
return controltag::NONE;
}
switch(data[0]) {
switch (data[0]) {
case 'R':
return controltag::R;
break;

View File

@ -5,12 +5,10 @@
#include "events/signal_emitter.hpp"
#include "events/signal_receiver.hpp"
#include "utils/factory.hpp"
#include "utils/file.hpp"
#include "utils/math.hpp"
#include "x11/atoms.hpp"
#include "x11/background_manager.hpp"
#include "x11/connection.hpp"
#include "x11/extensions/all.hpp"
#include "x11/winspec.hpp"
POLYBAR_NS
@ -35,15 +33,14 @@ renderer::make_type renderer::make(const bar_settings& bar) {
/**
* Construct renderer instance
*/
renderer::renderer(
connection& conn, signal_emitter& sig, const config& conf, const logger& logger, const bar_settings& bar, background_manager& background)
renderer::renderer(connection& conn, signal_emitter& sig, const config& conf, const logger& logger,
const bar_settings& bar, background_manager& background)
: m_connection(conn)
, m_sig(sig)
, m_conf(conf)
, m_log(logger)
, m_bar(forward<const bar_settings&>(bar))
, m_rect(m_bar.inner_area()) {
m_sig.attach(this);
m_log.trace("renderer: Get TrueColor visual");
{
@ -301,13 +298,12 @@ void renderer::end() {
fill_background();
}
// For pseudo-transparency, capture the contents of the rendered bar and
// composite it against the desktop wallpaper. This way transparent parts of
// the bar will be filled by the wallpaper creating illusion of transparency.
if (m_pseudo_transparency) {
cairo_pattern_t* barcontents{};
m_context->pop(&barcontents); // corresponding push is in renderer::begin
m_context->pop(&barcontents); // corresponding push is in renderer::begin
auto root_bg = m_background->get_surface();
if (root_bg != nullptr) {
@ -449,7 +445,7 @@ double renderer::block_x(alignment a) const {
* So we can just subtract the tray_width = m_rect.x - border_left from the base_pos to correct for the tray being
* placed on the left
*/
if(m_rect.x > border_left) {
if (m_rect.x > border_left) {
base_pos -= m_rect.x - border_left;
}
@ -831,7 +827,7 @@ bool renderer::on(const signals::parser::text& evt) {
bool renderer::on(const signals::parser::control& evt) {
auto ctrl = evt.cast();
switch(ctrl) {
switch (ctrl) {
case controltag::R:
m_bg = m_bar.background;
m_fg = m_bar.foreground;

View File

@ -51,6 +51,6 @@ namespace modules {
return m_builder->flush();
}
}
} // namespace modules
POLYBAR_NS_END