refactor: Cleanup

This commit is contained in:
Michael Carlberg 2016-12-26 10:37:14 +01:00
parent baaba4adf9
commit b9f9092bbe
8 changed files with 53 additions and 61 deletions

View File

@ -3,9 +3,6 @@
#include <map>
#include "common.hpp"
#include "components/config.hpp"
#include "components/types.hpp"
#include "config.hpp"
POLYBAR_NS
@ -13,10 +10,6 @@ using std::map;
#define DEFAULT_SPACING -1
#ifndef BUILDER_SPACE_TOKEN
#define BUILDER_SPACE_TOKEN "%__"
#endif
// fwd decl
namespace drawtypes {
class label;
@ -24,12 +17,18 @@ namespace drawtypes {
using icon = label;
using icon_t = label_t;
}
using namespace drawtypes;
enum class alignment : uint8_t;
enum class attribute : uint8_t;
enum class edge : uint8_t;
enum class syntaxtag : uint8_t;
enum class mousebtn : uint8_t;
struct bar_settings;
class builder {
public:
explicit builder(const bar_settings bar) : m_bar(bar) {}
explicit builder(const bar_settings& bar);
string flush();
void append(const string& text);
@ -71,34 +70,17 @@ class builder {
void tag_close(attribute attr);
private:
const bar_settings m_bar;
string m_output{};
const bar_settings& m_bar;
string m_output;
map<syntaxtag, int> m_tags{
// clang-format off
{syntaxtag::A, 0},
{syntaxtag::B, 0},
{syntaxtag::F, 0},
{syntaxtag::T, 0},
{syntaxtag::u, 0},
{syntaxtag::o, 0},
// clang-format on
};
map<syntaxtag, int> m_tags;
map<syntaxtag, string> m_colors;
map<syntaxtag, string> m_colors{
// clang-format off
{syntaxtag::B, ""},
{syntaxtag::F, ""},
{syntaxtag::u, ""},
{syntaxtag::o, ""},
// clang-format on
};
uint8_t m_attributes;
uint8_t m_fontindex;
uint8_t m_attributes{static_cast<uint8_t>(attribute::NONE)};
uint8_t m_fontindex{1};
string m_background{};
string m_foreground{};
string m_background;
string m_foreground;
};
POLYBAR_NS_END

View File

@ -46,9 +46,7 @@ class screen : public xpp::event::sink<evt::randr_screen_change_notify> {
xcb_window_t m_proxy{XCB_NONE};
vector<monitor_t> m_monitors;
struct size m_size {
0U, 0U
};
struct size m_size {0U, 0U};
bool m_sigraised{false};
};

View File

@ -44,8 +44,12 @@ static const int SINK_PRIORITY_TRAY{3};
static const int SINK_PRIORITY_MODULE{4};
#ifdef DEBUG_HINTS
static const int DEBUG_HINTS_OFFSET_X{@DEBUG_HINTS_OFFSET_X@};
static const int DEBUG_HINTS_OFFSET_Y{@DEBUG_HINTS_OFFSET_Y@};
static const int DEBUG_HINTS_OFFSET_X {
@DEBUG_HINTS_OFFSET_X@
};
static const int DEBUG_HINTS_OFFSET_Y {
@DEBUG_HINTS_OFFSET_Y@
};
#endif
static constexpr const char* ALSA_SOUNDCARD{"@SETTING_ALSA_SOUNDCARD@"};

View File

@ -24,22 +24,20 @@ class inotify_watch {
void attach(int mask = IN_MODIFY);
void remove(bool force = false);
bool poll(int wait_ms = 1000);
unique_ptr<inotify_event> get_event();
bool await_match();
bool poll(int wait_ms = 1000) const;
unique_ptr<inotify_event> get_event() const;
bool await_match() const;
const string path() const;
int get_file_descriptor() const;
protected:
string m_path;
int m_fd = -1;
int m_wd = -1;
int m_mask = 0;
int m_fd{-1};
int m_wd{-1};
int m_mask{0};
};
namespace inotify_util {
bool match(const inotify_event* evt, int mask);
template <typename... Args>
decltype(auto) make_watch(Args&&... args) {
return factory_util::unique<inotify_watch>(forward<Args>(args)...);

View File

@ -720,7 +720,7 @@ bool bar::on(const sig_ui::tick&) {
bool bar::on(const sig_ui::dim_window& sig) {
m_opts.dimmed = *sig.data() != 1.0;
wm_util::set_wm_window_opacity(m_connection, m_opts.window, *sig.data() * 0xFFFFFFFF);
set_wm_window_opacity(m_connection, m_opts.window, *sig.data() * 0xFFFFFFFF);
m_connection.flush();
return false;
}

View File

@ -1,7 +1,7 @@
#include <utility>
#include "components/builder.hpp"
#include "components/types.hpp"
#include "drawtypes/label.hpp"
#include "utils/math.hpp"
#include "utils/string.hpp"
@ -9,6 +9,23 @@
POLYBAR_NS
#ifndef BUILDER_SPACE_TOKEN
#define BUILDER_SPACE_TOKEN "%__"
#endif
builder::builder(const bar_settings& bar) : m_bar(bar), m_attributes{static_cast<uint8_t>(attribute::NONE)} {
m_tags[syntaxtag::A] = 0;
m_tags[syntaxtag::B] = 0;
m_tags[syntaxtag::F] = 0;
m_tags[syntaxtag::T] = 0;
m_tags[syntaxtag::u] = 0;
m_tags[syntaxtag::o] = 0;
m_colors[syntaxtag::B] = "";
m_colors[syntaxtag::F] = "";
m_colors[syntaxtag::u] = "";
m_colors[syntaxtag::o] = "";
}
/**
* Flush contents of the builder and return built string
*

View File

@ -74,9 +74,6 @@ namespace modules {
m_icons->add(vec[0], factory_util::shared<label>(vec[1]));
}
}
// Make sure we get notified when root properties change
window{m_connection, m_connection.root()}.ensure_event_mask(XCB_EVENT_MASK_PROPERTY_CHANGE);
}
/**

View File

@ -52,7 +52,7 @@ void inotify_watch::remove(bool force) {
*
* @brief A wait_ms of -1 blocks until an event is fired
*/
bool inotify_watch::poll(int wait_ms) {
bool inotify_watch::poll(int wait_ms) const {
if (m_fd == -1) {
return false;
}
@ -69,7 +69,7 @@ bool inotify_watch::poll(int wait_ms) {
/**
* Get the latest inotify event
*/
unique_ptr<inotify_event> inotify_watch::get_event() {
unique_ptr<inotify_event> inotify_watch::get_event() const {
auto event = factory_util::unique<inotify_event>();
if (m_fd == -1 || m_wd == -1) {
@ -77,8 +77,8 @@ unique_ptr<inotify_event> inotify_watch::get_event() {
}
char buffer[1024];
size_t bytes = read(m_fd, buffer, 1024);
size_t len = 0;
auto bytes = read(m_fd, buffer, 1024);
auto len = 0;
while (len < bytes) {
auto* e = reinterpret_cast<::inotify_event*>(&buffer[len]);
@ -98,7 +98,7 @@ unique_ptr<inotify_event> inotify_watch::get_event() {
/**
* Wait for matching event
*/
bool inotify_watch::await_match() {
bool inotify_watch::await_match() const {
return (get_event()->mask & m_mask) == m_mask;
}
@ -116,8 +116,4 @@ int inotify_watch::get_file_descriptor() const {
return m_fd;
}
bool match(const inotify_event* evt, int mask) {
return (evt->mask & mask) == mask;
}
POLYBAR_NS_END