tray: Load settings from module section

This commit is contained in:
patrick96 2022-09-03 20:56:32 +02:00
parent 03a2e6bb17
commit b72458a6b0
No known key found for this signature in database
GPG Key ID: 521E5E03AEBCA1A7
3 changed files with 12 additions and 19 deletions

View File

@ -72,7 +72,7 @@ class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify
bool running() const;
int get_width() const;
void setup(const string& tray_module_name);
void setup(const config& conf, const string& module_section_name);
void activate();
void deactivate(bool clear_selection = true);
void reconfigure();

View File

@ -19,7 +19,7 @@ namespace modules {
}
void tray_module::start() {
m_tray.setup(name_raw());
m_tray.setup(m_conf, name());
this->static_module<tray_module>::start();
}
@ -34,9 +34,9 @@ namespace modules {
}
/**
* Replace signal with callback passed to tray.
* TODO Replace signal with callback passed to tray.
*/
bool tray_module::on(const signals::ui_tray::tray_width_change& evt) {
bool tray_module::on(const signals::ui_tray::tray_width_change&) {
broadcast();
return true;
}

View File

@ -65,35 +65,28 @@ tray_manager::~tray_manager() {
deactivate();
}
/**
* TODO load settings from module section
*/
void tray_manager::setup(const string& tray_module_name) {
const config& conf = config::make();
auto bs = conf.section();
void tray_manager::setup(const config& conf, const string& section_name) {
unsigned client_height = m_bar_opts.inner_area().height;
auto inner_area = m_bar_opts.inner_area();
unsigned client_height = inner_area.height;
// Add user-defined padding
m_opts.spacing = conf.get<unsigned>(section_name, "tray-padding", 0);
auto maxsize = conf.get<unsigned>(bs, "tray-maxsize", 16);
auto maxsize = conf.get<unsigned>(section_name, "tray-maxsize", 16);
if (client_height > maxsize) {
m_opts.spacing += (client_height - maxsize) / 2;
client_height = maxsize;
}
// Apply user-defined scaling
auto scale = conf.get(bs, "tray-scale", 1.0);
auto scale = conf.get(section_name, "tray-scale", 1.0);
client_height *= scale;
m_opts.client_size = {client_height, client_height};
// Set user-defined foreground and background colors.
// TODO maybe remove
m_opts.background = conf.get(bs, "tray-background", m_bar_opts.background);
m_opts.foreground = conf.get(bs, "tray-foreground", m_bar_opts.foreground);
// Add user-defined padding
m_opts.spacing += conf.get<unsigned>(bs, "tray-padding", 0);
m_opts.background = conf.get(section_name, "tray-background", m_bar_opts.background);
m_opts.foreground = conf.get(section_name, "tray-foreground", m_bar_opts.foreground);
m_opts.selection_owner = m_bar_opts.x_data.window;