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; bool running() const;
int get_width() 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 activate();
void deactivate(bool clear_selection = true); void deactivate(bool clear_selection = true);
void reconfigure(); void reconfigure();

View File

@ -19,7 +19,7 @@ namespace modules {
} }
void tray_module::start() { void tray_module::start() {
m_tray.setup(name_raw()); m_tray.setup(m_conf, name());
this->static_module<tray_module>::start(); 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(); broadcast();
return true; return true;
} }

View File

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