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

refactor: Fwd declare drawtypes

Ref #164
This commit is contained in:
Michael Carlberg 2016-11-19 15:49:03 +01:00
parent 38f9ba81cd
commit 88c8bbd940
32 changed files with 110 additions and 84 deletions

View file

@ -4,7 +4,6 @@
#include "components/config.hpp"
#include "components/types.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp"
POLYBAR_NS
@ -14,6 +13,14 @@ POLYBAR_NS
#define BUILDER_SPACE_TOKEN "%__"
#endif
// fwd decl
namespace drawtypes {
class label;
using label_t = shared_ptr<label>;
using icon = label;
using icon_t = label_t;
}
using namespace drawtypes;
class builder {

View file

@ -2,9 +2,6 @@
#include "components/config.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -2,14 +2,7 @@
#include "common.hpp"
#include "config.hpp"
#include "drawtypes/animation.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
#include "utils/file.hpp"
#include "utils/inotify.hpp"
#include "utils/string.hpp"
POLYBAR_NS

View file

@ -1,7 +1,5 @@
#pragma once
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
#include "modules/meta.hpp"
#include "utils/bspwm.hpp"

View file

@ -4,8 +4,6 @@
POLYBAR_NS
using namespace drawtypes;
namespace modules {
class counter_module : public timer_module<counter_module> {
public:

View file

@ -3,9 +3,6 @@
#include <istream>
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -2,9 +2,6 @@
#include "components/config.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -4,8 +4,6 @@
#include "components/config.hpp"
#include "config.hpp"
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
#include "modules/meta.hpp"
#include "utils/i3.hpp"
#include "utils/io.hpp"
@ -31,9 +29,7 @@ namespace modules {
i3_workspace(int index_, i3_flag flag_, label_t&& label_)
: index(index_), flag(flag_), label(forward<decltype(label_)>(label_)) {}
operator bool() {
return label && *label;
}
operator bool();
};
using i3_workspace_t = unique_ptr<i3_workspace>;

View file

@ -3,8 +3,6 @@
#include <istream>
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -1,6 +1,5 @@
#pragma once
#include "drawtypes/label.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -20,6 +20,22 @@ POLYBAR_NS
#define CONST_MOD(name) static_cast<name const&>(*this)
#define CAST_MOD(name) static_cast<name*>(this)
// fwd decl
namespace drawtypes {
class label;
using label_t = shared_ptr<label>;
class ramp;
using ramp_t = shared_ptr<ramp>;
class progressbar;
using progressbar_t = shared_ptr<progressbar>;
class animation;
using animation_t = shared_ptr<animation>;
using icon = label;
using icon_t = label_t;
class iconset;
using iconset_t = shared_ptr<iconset>;
}
namespace modules {
using namespace drawtypes;
@ -81,8 +97,7 @@ namespace modules {
class module_formatter {
public:
explicit module_formatter(const config& conf, string modname)
: m_conf(conf), m_modname(modname) {}
explicit module_formatter(const config& conf, string modname) : m_conf(conf), m_modname(modname) {}
void add(string name, string fallback, vector<string>&& tags, vector<string>&& whitelist = {}) {
auto format = make_unique<module_format>();
@ -495,8 +510,7 @@ namespace modules {
}
} catch (const system_error& e) {
watches.clear();
this->m_log.err(
"%s: Error while creating inotify watch (what: %s)", CONST_MOD(Impl).name(), e.what());
this->m_log.err("%s: Error while creating inotify watch (what: %s)", CONST_MOD(Impl).name(), e.what());
CAST_MOD(Impl)->sleep(0.1s);
return;
}

View file

@ -3,9 +3,6 @@
#include <csignal>
#include "adapters/mpd.hpp"
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "modules/meta.hpp"
#include "utils/threading.hpp"

View file

@ -2,10 +2,6 @@
#include "adapters/net.hpp"
#include "components/config.hpp"
#include "drawtypes/animation.hpp"
#include "drawtypes/animation.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -3,8 +3,6 @@
#include <istream>
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -3,9 +3,6 @@
#include "adapters/alsa.hpp"
#include "components/config.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -5,9 +5,6 @@
#include "x11/randr.hpp"
#include "x11/xutils.hpp"
#include "config.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/meta.hpp"
POLYBAR_NS

View file

@ -3,7 +3,6 @@
#include <bitset>
#include "components/config.hpp"
#include "drawtypes/label.hpp"
#include "modules/meta.hpp"
#include "x11/connection.hpp"
#include "x11/ewmh.hpp"

View file

@ -1,4 +1,6 @@
#include "components/builder.hpp"
#include "drawtypes/label.hpp"
#include "utils/math.hpp"
#include "utils/string.hpp"

View file

@ -1,4 +1,7 @@
#include "modules/backlight.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/file.hpp"
POLYBAR_NS

View file

@ -1,4 +1,9 @@
#include "modules/battery.hpp"
#include "drawtypes/animation.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/file.hpp"
#include "utils/math.hpp"
POLYBAR_NS

View file

@ -2,6 +2,9 @@
#include "modules/bspwm.hpp"
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
POLYBAR_NS
namespace modules {
@ -31,14 +34,14 @@ namespace modules {
m_statelabels.insert(
make_pair(state_ws::WORKSPACE_EMPTY, load_optional_label(m_conf, name(), "label-empty", DEFAULT_WS_LABEL)));
m_statelabels.insert(make_pair(state_ws::WORKSPACE_DIMMED, load_optional_label(m_conf, name(), "label-dimmed")));
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")));
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")));
}
if (m_formatter->has(TAG_LABEL_MODE)) {
@ -257,20 +260,20 @@ namespace modules {
if (!m_monitors.back()->focused) {
label->replace_defined_values(m_statelabels.find(state_ws::WORKSPACE_DIMMED)->second);
switch (workspace_flag) {
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;
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;
}
}

View file

@ -1,4 +1,7 @@
#include "modules/cpu.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/math.hpp"
POLYBAR_NS
@ -7,8 +10,7 @@ namespace modules {
void cpu_module::setup() {
m_interval = chrono::duration<double>(m_conf.get<float>(name(), "interval", 1));
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL,
{TAG_LABEL, TAG_BAR_LOAD, TAG_RAMP_LOAD, TAG_RAMP_LOAD_PER_CORE});
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL, {TAG_LABEL, TAG_BAR_LOAD, TAG_RAMP_LOAD, TAG_RAMP_LOAD_PER_CORE});
if (m_formatter->has(TAG_BAR_LOAD))
m_barload = load_progressbar(m_bar, m_conf, name(), TAG_BAR_LOAD);
@ -92,8 +94,8 @@ namespace modules {
m_cputimes.back()->nice = std::stoull(values[2].c_str(), 0, 10);
m_cputimes.back()->system = std::stoull(values[3].c_str(), 0, 10);
m_cputimes.back()->idle = std::stoull(values[4].c_str(), 0, 10);
m_cputimes.back()->total = m_cputimes.back()->user + m_cputimes.back()->nice +
m_cputimes.back()->system + m_cputimes.back()->idle;
m_cputimes.back()->total =
m_cputimes.back()->user + m_cputimes.back()->nice + m_cputimes.back()->system + m_cputimes.back()->idle;
}
} catch (const std::ios_base::failure& e) {
m_log.err("Failed to read CPU values (what: %s)", e.what());

View file

@ -1,5 +1,8 @@
#include <sys/statvfs.h>
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "modules/fs.hpp"
#include "utils/math.hpp"
#include "utils/mtab.hpp"

View file

@ -2,9 +2,16 @@
#include "modules/i3.hpp"
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
POLYBAR_NS
namespace modules {
i3_workspace::operator bool() {
return label && *label;
}
void i3_module::setup() { // {{{
// Load configuration values
GET_CONFIG_VALUE(name(), m_click, "enable-click");

View file

@ -1,4 +1,6 @@
#include "modules/memory.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
POLYBAR_NS
@ -60,8 +62,8 @@ namespace modules {
m_label->reset_tokens();
auto replace_unit = [](label_t& label, string token, float value, string unit) {
auto formatted = string_util::from_stream(
stringstream() << std::setprecision(2) << std::fixed << value << " " << unit);
auto formatted =
string_util::from_stream(stringstream() << std::setprecision(2) << std::fixed << value << " " << unit);
label->replace_token(token, formatted);
};

View file

@ -1,4 +1,6 @@
#include "modules/menu.hpp"
#include "drawtypes/label.hpp"
#include "utils/scope.hpp"
POLYBAR_NS

View file

@ -1,5 +1,9 @@
#include "modules/mpd.hpp"
#include "drawtypes/iconset.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
POLYBAR_NS
using namespace mpd;
@ -14,9 +18,9 @@ namespace modules {
// Add formats and elements {{{
m_formatter->add(FORMAT_ONLINE, TAG_LABEL_SONG,
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM,
TAG_ICON_REPEAT, TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY,
TAG_ICON_PAUSE, TAG_ICON_NEXT, TAG_ICON_SEEKB, TAG_ICON_SEEKF});
{TAG_BAR_PROGRESS, TAG_TOGGLE, TAG_LABEL_SONG, TAG_LABEL_TIME, TAG_ICON_RANDOM, TAG_ICON_REPEAT,
TAG_ICON_REPEAT_ONE, TAG_ICON_PREV, TAG_ICON_STOP, TAG_ICON_PLAY, TAG_ICON_PAUSE, TAG_ICON_NEXT,
TAG_ICON_SEEKB, TAG_ICON_SEEKF});
m_formatter->add(FORMAT_OFFLINE, "", {TAG_LABEL_OFFLINE});
@ -199,11 +203,9 @@ namespace modules {
}
if (m_icons->has("random"))
m_icons->get("random")->m_foreground =
m_status && m_status->random() ? m_toggle_on_color : m_toggle_off_color;
m_icons->get("random")->m_foreground = m_status && m_status->random() ? m_toggle_on_color : m_toggle_off_color;
if (m_icons->has("repeat"))
m_icons->get("repeat")->m_foreground =
m_status && m_status->repeat() ? m_toggle_on_color : m_toggle_off_color;
m_icons->get("repeat")->m_foreground = m_status && m_status->repeat() ? m_toggle_on_color : m_toggle_off_color;
if (m_icons->has("repeat_one"))
m_icons->get("repeat_one")->m_foreground =
m_status && m_status->single() ? m_toggle_on_color : m_toggle_off_color;

View file

@ -1,5 +1,9 @@
#include "modules/network.hpp"
#include "drawtypes/animation.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/ramp.hpp"
POLYBAR_NS
namespace modules {

View file

@ -1,4 +1,7 @@
#include "modules/temperature.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/file.hpp"
#include "utils/math.hpp"

View file

@ -1,4 +1,8 @@
#include "modules/volume.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/math.hpp"
POLYBAR_NS

View file

@ -1,4 +1,8 @@
#include "modules/xbacklight.hpp"
#include "drawtypes/label.hpp"
#include "drawtypes/progressbar.hpp"
#include "drawtypes/ramp.hpp"
#include "utils/math.hpp"
#include "x11/graphics.hpp"

View file

@ -1,4 +1,6 @@
#include "modules/xwindow.hpp"
#include "drawtypes/label.hpp"
#include "x11/atoms.hpp"
#include "x11/graphics.hpp"