1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-25 13:55:47 -05:00

refactor: Cleanup

This commit is contained in:
Michael Carlberg 2016-12-27 04:58:41 +01:00
parent f101a303bd
commit 18cf9df86c
10 changed files with 48 additions and 38 deletions

View file

@ -7,6 +7,7 @@
#include "events/signal_fwd.hpp"
#include "events/signal_receiver.hpp"
#include "events/types.hpp"
#include "utils/file.hpp"
#include "x11/types.hpp"
#include "x11/events.hpp"
@ -83,10 +84,7 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
unique_ptr<inotify_watch> m_confwatch;
unique_ptr<command> m_command;
unique_ptr<file_descriptor> m_fdevent_rd;
unique_ptr<file_descriptor> m_fdevent_wr;
thread m_event_thread;
array<unique_ptr<file_descriptor>, 2> m_queuefd{};
/**
* @brief Controls weather the output gets printed to stdout
@ -133,6 +131,11 @@ class controller : public signal_receiver<SIGN_PRIORITY_CONTROLLER, sig_ev::exit
* @brief Input data
*/
string m_inputdata;
/**
* @brief Thread for the eventqueue loop
*/
thread m_event_thread;
};
POLYBAR_NS_END

View file

@ -5,7 +5,7 @@
#include "events/signal_emitter.hpp"
#include "events/signal_fwd.hpp"
#include "x11/events.hpp"
#include "x11/extensions/fwd.hpp"
#include "x11/extensions/randr.hpp"
#include "x11/types.hpp"
#include "x11/window.hpp"

View file

@ -1,13 +1,18 @@
#pragma once
#include <xcb/xcb.h>
#include <string>
#include <unordered_map>
#include "common.hpp"
#include "x11/extensions/randr.hpp"
POLYBAR_NS
// fwd
struct randr_output;
using monitor_t = shared_ptr<randr_output>;
struct enum_hash {
template <typename T>
inline typename std::enable_if<std::is_enum<T>::value, size_t>::type operator()(T const value) const {

View file

@ -74,8 +74,8 @@ namespace color_util {
}
inline string parse_hex(string hex) {
if (hex.substr(0, 1) != "#")
hex = "#" + hex;
if (hex[0] != '#')
hex.insert(0, 1, '#');
if (hex.length() == 4)
hex = {'#', hex[1], hex[1], hex[2], hex[2], hex[3], hex[3]};
if (hex.length() == 7)

View file

@ -3,9 +3,11 @@
#include <map>
#include <X11/Xft/Xft.h>
#include <unordered_map>
#include "common.hpp"
#include "utils/color.hpp"
#include "utils/concurrency.hpp"
POLYBAR_NS
@ -30,8 +32,10 @@ class color {
string m_source;
};
extern color g_colorempty;
extern color g_colorblack;
extern color g_colorwhite;
extern mutex_wrapper<std::unordered_map<string, color>> g_colorstore;
extern const color& g_colorempty;
extern const color& g_colorblack;
extern const color& g_colorwhite;
POLYBAR_NS_END

View file

@ -6,7 +6,6 @@
#include "common.hpp"
#include "components/screen.hpp"
#include "utils/file.hpp"
#include "x11/events.hpp"
#include "x11/extensions/all.hpp"
#include "x11/registry.hpp"

View file

@ -25,7 +25,7 @@
POLYBAR_NS
int g_eventpipe[2]{0, 0};
array<int, 2> g_eventpipe{{-1, -1}};
sig_atomic_t g_reload{0};
sig_atomic_t g_terminate{0};
@ -61,13 +61,13 @@ controller::controller(connection& conn, signal_emitter& emitter, const logger&
m_swallow_limit = m_conf.deprecated("settings", "eventqueue-swallow", "throttle-output", m_swallow_limit);
m_swallow_update = m_conf.deprecated("settings", "eventqueue-swallow-time", "throttle-output-for", m_swallow_update);
if (pipe(g_eventpipe) != 0) {
if (pipe(g_eventpipe.data()) == 0) {
m_queuefd[PIPE_READ] = make_unique<file_descriptor>(g_eventpipe[PIPE_READ]);
m_queuefd[PIPE_WRITE] = make_unique<file_descriptor>(g_eventpipe[PIPE_WRITE]);
} else {
throw system_error("Failed to create event channel pipes");
}
m_fdevent_rd = file_util::make_file_descriptor(g_eventpipe[PIPE_READ]);
m_fdevent_wr = file_util::make_file_descriptor(g_eventpipe[PIPE_WRITE]);
m_log.trace("controller: Install signal handler");
struct sigaction act {};
memset(&act, 0, sizeof(act));
@ -234,13 +234,13 @@ bool controller::enqueue(string&& input_data) {
void controller::read_events() {
m_log.info("Entering event loop (thread-id=%lu)", this_thread::get_id());
int fd_connection{m_connection.get_file_descriptor()};
int fd_confwatch{0};
int fd_ipc{0};
int fd_connection{-1};
int fd_confwatch{-1};
int fd_ipc{-1};
vector<int> fds;
fds.emplace_back(*m_fdevent_rd);
fds.emplace_back(fd_connection);
fds.emplace_back(*m_queuefd[PIPE_READ]);
fds.emplace_back(fd_connection = m_connection.get_file_descriptor());
if (m_confwatch) {
m_log.trace("controller: Attach config watch");
@ -271,9 +271,9 @@ void controller::read_events() {
}
// Process event on the internal fd
if (m_fdevent_rd && FD_ISSET(*m_fdevent_rd, &readfds)) {
if (m_queuefd[PIPE_READ] && FD_ISSET(static_cast<int>(*m_queuefd[PIPE_READ]), &readfds)) {
char buffer[BUFSIZ]{'\0'};
if (read(*m_fdevent_rd, &buffer, BUFSIZ) == -1) {
if (read(static_cast<int>(*m_queuefd[PIPE_READ]), &buffer, BUFSIZ) == -1) {
m_log.err("Failed to read from eventpipe (err: %s)", strerror(errno));
}
}
@ -454,6 +454,7 @@ bool controller::on(const sig_ev::update&) {
block_contents += margin_left;
}
block_contents.reserve(module_contents.size());
block_contents += module_contents;
}

View file

@ -142,7 +142,6 @@ namespace modules {
m_log.warn("%s: Reconnecting to socket...", name());
m_subscriber = bspwm_util::make_subscriber();
}
return m_subscriber->peek(1);
}

View file

@ -78,7 +78,7 @@ namespace modules {
format->bg = m_conf.get(m_modname, name + "-background", ""s);
format->ul = m_conf.get(m_modname, name + "-underline", ""s);
format->ol = m_conf.get(m_modname, name + "-overline", ""s);
format->spacing = m_conf.get(m_modname, name + "-spacing", 0_z);
format->spacing = m_conf.get(m_modname, name + "-spacing", 1_z);
format->padding = m_conf.get(m_modname, name + "-padding", 0_z);
format->margin = m_conf.get(m_modname, name + "-margin", 0_z);
format->offset = m_conf.get(m_modname, name + "-offset", 0_z);

View file

@ -1,5 +1,4 @@
#include <iomanip>
#include <unordered_map>
#include <utility>
#include "errors.hpp"
@ -9,11 +8,11 @@
POLYBAR_NS
std::unordered_map<string, color> g_colorstore;
mutex_wrapper<std::unordered_map<string, color>> g_colorstore;
color g_colorempty{"#00000000"};
color g_colorblack{"#ff000000"};
color g_colorwhite{"#ffffffff"};
const color& g_colorempty{"#00000000"};
const color& g_colorblack{"#ff000000"};
const color& g_colorwhite{"#ffffffff"};
color::color(string hex) : m_source(hex) {
if (hex.empty()) {
@ -59,16 +58,16 @@ color::operator uint32_t() const {
const color& color::parse(string input, const color& fallback) {
if (input.empty()) {
throw application_error("Cannot parse empty color");
}
auto it = g_colorstore.find(input);
if (it != g_colorstore.end()) {
return it->second;
} else if ((input = color_util::parse_hex(input)).empty()) {
} else if ((input = color_util::parse_hex(move(input))).empty()) {
return fallback;
}
g_colorstore.emplace_hint(it, input, color{input});
return g_colorstore.at(input);
std::lock_guard<decltype(g_colorstore)> guard(g_colorstore);
auto it = g_colorstore.find(input);
if (it == g_colorstore.end()) {
it = g_colorstore.emplace_hint(it, make_pair(input, color{input}));
}
return it->second;
}
const color& color::parse(string input) {