wip(systray): Add module base

This commit is contained in:
Michael Carlberg 2017-01-01 21:28:28 +01:00
parent 6341c7ab25
commit e0688307f3
4 changed files with 120 additions and 0 deletions

View File

@ -15,6 +15,9 @@
#include "modules/menu.hpp" #include "modules/menu.hpp"
#include "modules/meta/base.hpp" #include "modules/meta/base.hpp"
#include "modules/script.hpp" #include "modules/script.hpp"
#if DEBUG
#include "modules/systray.hpp"
#endif
#include "modules/tailscript.hpp" #include "modules/tailscript.hpp"
#include "modules/temperature.hpp" #include "modules/temperature.hpp"
#include "modules/text.hpp" #include "modules/text.hpp"
@ -75,6 +78,10 @@ namespace {
return new volume_module(bar, move(module_name)); return new volume_module(bar, move(module_name));
} else if (name == "internal/network") { } else if (name == "internal/network") {
return new network_module(bar, move(module_name)); return new network_module(bar, move(module_name));
#if DEBUG
} else if (name == "internal/systray") {
return new systray_module(bar, move(module_name));
#endif
} else if (name == "internal/temperature") { } else if (name == "internal/temperature") {
return new temperature_module(bar, move(module_name)); return new temperature_module(bar, move(module_name));
} else if (name == "internal/xbacklight") { } else if (name == "internal/xbacklight") {

View File

@ -0,0 +1,40 @@
#if DEBUG
#pragma once
#include "modules/meta/static_module.hpp"
#include "modules/meta/input_handler.hpp"
POLYBAR_NS
class connection;
namespace modules {
/**
* Module used to display information about the
* currently active X window.
*/
class systray_module : public static_module<systray_module>, public input_handler {
public:
explicit systray_module(const bar_settings&, string);
void update();
bool build(builder* builder, const string& tag) const;
protected:
bool input(string&& cmd);
private:
static constexpr const char* EVENT_TOGGLE{"systray-toggle"};
static constexpr const char* TAG_LABEL_TOGGLE{"<label-toggle>"};
static constexpr const char* TAG_TRAY_CLIENTS{"<tray-clients>"};
connection& m_connection;
label_t m_label;
bool m_hidden{false};
};
}
POLYBAR_NS_END
#endif

View File

@ -25,6 +25,8 @@
#define TRAY_WM_NAME "Polybar tray window" #define TRAY_WM_NAME "Polybar tray window"
#define TRAY_WM_CLASS "tray\0Polybar" #define TRAY_WM_CLASS "tray\0Polybar"
#define TRAY_PLACEHOLDER "<placeholder-systray>"
POLYBAR_NS POLYBAR_NS
namespace chrono = std::chrono; namespace chrono = std::chrono;

71
src/modules/systray.cpp Normal file
View File

@ -0,0 +1,71 @@
#if DEBUG
#include "modules/systray.hpp"
#include "drawtypes/label.hpp"
#include "x11/connection.hpp"
#include "x11/tray_manager.hpp"
#include "modules/meta/base.inl"
POLYBAR_NS
namespace modules {
template class module<systray_module>;
/**
* Construct module
*/
systray_module::systray_module(const bar_settings& bar, string name_)
: static_module<systray_module>(bar, move(name_)), m_connection(connection::make()) {
// Add formats and elements
m_formatter->add(DEFAULT_FORMAT, TAG_LABEL_TOGGLE, {TAG_LABEL_TOGGLE, TAG_TRAY_CLIENTS});
if (m_formatter->has(TAG_LABEL_TOGGLE)) {
m_label = load_label(m_conf, name(), TAG_LABEL_TOGGLE);
}
}
/**
* Update
*/
void systray_module::update() {
if (m_label) {
m_label->reset_tokens();
m_label->replace_token("%title%", "");
}
broadcast();
}
/**
* Build output
*/
bool systray_module::build(builder* builder, const string& tag) const {
if (tag == TAG_LABEL_TOGGLE) {
builder->cmd(mousebtn::LEFT, EVENT_TOGGLE);
builder->node(m_label);
builder->cmd_close();
} else if (tag == TAG_TRAY_CLIENTS && !m_hidden) {
builder->append(TRAY_PLACEHOLDER);
} else {
return false;
}
return true;
}
/**
* Handle input event
*/
bool systray_module::input(string&& cmd) {
if (cmd.find(EVENT_TOGGLE) != 0) {
return false;
}
m_hidden = !m_hidden;
broadcast();
return true;
}
}
POLYBAR_NS_END
#endif