From 86f2baa5500c2f74f910286924e56584f4ef3669 Mon Sep 17 00:00:00 2001 From: raffael0 <43984260+raffael0@users.noreply.github.com> Date: Wed, 15 Jun 2022 11:09:13 +0200 Subject: [PATCH] tray: remove tray-position = adaptive (#2726) The tray is automatically started if there is a tray module. In addition, `tray-position` and the tray module conflict. Ref #2689 --- include/components/bar.hpp | 2 +- include/components/controller.hpp | 1 + include/x11/tray_manager.hpp | 7 +++--- src/components/bar.cpp | 13 +++++----- src/components/controller.cpp | 9 ++++++- src/x11/tray_manager.cpp | 41 +++++++++++++++++-------------- 6 files changed, 43 insertions(+), 30 deletions(-) diff --git a/include/components/bar.hpp b/include/components/bar.hpp index f35648de..60331e54 100644 --- a/include/components/bar.hpp +++ b/include/components/bar.hpp @@ -43,7 +43,7 @@ class bar : public xpp::event::sink m_bar; bool m_has_ipc; + string m_tray_module_name; /** * @brief Async handle to notify the eventloop diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp index 471b233e..2c230cc1 100644 --- a/include/x11/tray_manager.hpp +++ b/include/x11/tray_manager.hpp @@ -39,8 +39,10 @@ class connection; class background_manager; class bg_slice; +enum class tray_postition { NONE = 0, LEFT, CENTER, RIGHT, MODULE }; + struct tray_settings { - alignment align{alignment::NONE}; + tray_postition tray_position{tray_postition::NONE}; bool running{false}; int rel_x{0}; int rel_y{0}; @@ -61,7 +63,6 @@ struct tray_settings { rgba foreground{}; bool transparent{false}; bool detached{false}; - bool adaptive{false}; }; class tray_manager : public xpp::event::sink delay = 1s); void deactivate(bool clear_selection = true); diff --git a/src/components/bar.cpp b/src/components/bar.cpp index 04633556..b3f9695d 100644 --- a/src/components/bar.cpp +++ b/src/components/bar.cpp @@ -388,13 +388,14 @@ void bar::parse(string&& data, bool force) { auto rect = m_opts.inner_area(); - if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots && !m_tray->settings().adaptive) { - auto trayalign = m_tray->settings().align; + if (m_tray && !m_tray->settings().detached && m_tray->settings().configured_slots && + m_tray->settings().tray_position != tray_postition::MODULE) { + auto tray_pos = m_tray->settings().tray_position; auto traywidth = m_tray->settings().configured_w; - if (trayalign == alignment::LEFT) { + if (tray_pos == tray_postition::LEFT) { rect.x += traywidth; rect.width -= traywidth; - } else if (trayalign == alignment::RIGHT) { + } else if (tray_pos == tray_postition::RIGHT) { rect.width -= traywidth; } } @@ -872,7 +873,7 @@ void bar::handle(const evt::configure_notify&) { m_sig.emit(signals::ui::update_geometry{}); } -void bar::start() { +void bar::start(const string& tray_module_name) { m_log.trace("bar: Create renderer"); m_renderer = renderer::make(m_opts, *m_action_ctxt); m_opts.window = m_renderer->window(); @@ -900,7 +901,7 @@ void bar::start() { m_renderer->end(); m_log.trace("bar: Setup tray manager"); - m_tray->setup(); + m_tray->setup(tray_module_name); broadcast_visibility(); } diff --git a/src/components/controller.cpp b/src/components/controller.cpp index 77681e1c..96b7b51d 100644 --- a/src/components/controller.cpp +++ b/src/components/controller.cpp @@ -267,7 +267,7 @@ void controller::read_events(bool confwatch) { } if (!m_writeback) { - m_bar->start(); + m_bar->start(m_tray_module_name); } /* @@ -593,6 +593,13 @@ size_t controller::setup_modules(alignment align) { try { auto type = m_conf.get("module/" + module_name, "type"); + if (type == tray_module::TYPE) { + if (!m_tray_module_name.empty()) { + throw module_error("Multiple trays defined. Using tray `" + m_tray_module_name + "`"); + } + m_tray_module_name = module_name; + } + if (type == ipc_module::TYPE && !m_has_ipc) { throw application_error("Inter-process messaging needs to be enabled"); } diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 6d270563..a466bd41 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -67,25 +67,26 @@ tray_manager::~tray_manager() { deactivate(); } -void tray_manager::setup() { +void tray_manager::setup(const string& tray_module_name) { const config& conf = config::make(); auto bs = conf.section(); - string position; + string position = conf.get(bs, "tray-position", "none"s); - try { - position = conf.get(bs, "tray-position"); - } catch (const key_error& err) { - return m_log.info("Disabling tray manager (reason: missing `tray-position`)"); + if (!position.empty() && position != "none" && !tray_module_name.empty()) { + m_log.warn( + "The tray position is manually defined (`tray-position`) and also set by the tray module (%s). `tray-position` " + "will be ignored", + tray_module_name); } - if (position == "left") { - m_opts.align = alignment::LEFT; + if (!tray_module_name.empty()) { + m_opts.tray_position = tray_postition::MODULE; + } else if (position == "left") { + m_opts.tray_position = tray_postition::LEFT; } else if (position == "right") { - m_opts.align = alignment::RIGHT; + m_opts.tray_position = tray_postition::RIGHT; } else if (position == "center") { - m_opts.align = alignment::CENTER; - } else if (position == "adaptive") { - m_opts.adaptive = true; + m_opts.tray_position = tray_postition::CENTER; } else if (position != "none") { return m_log.err("Disabling tray manager (reason: Invalid position \"" + position + "\")"); } else { @@ -119,18 +120,20 @@ void tray_manager::setup() { auto inner_area = m_bar_opts.inner_area(true); - switch (m_opts.align) { - case alignment::NONE: + switch (m_opts.tray_position) { + case tray_postition::NONE: break; - case alignment::LEFT: + case tray_postition::LEFT: m_opts.orig_x = inner_area.x; break; - case alignment::CENTER: + case tray_postition::CENTER: m_opts.orig_x = inner_area.x + inner_area.width / 2 - m_opts.width / 2; break; - case alignment::RIGHT: + case tray_postition::RIGHT: m_opts.orig_x = inner_area.x + inner_area.width; break; + case tray_postition::MODULE: + break; } if (conf.has(bs, "tray-transparent")) { @@ -801,9 +804,9 @@ void tray_manager::process_docking_request(xcb_window_t win) { */ int tray_manager::calculate_x(unsigned int width) const { auto x = m_opts.orig_x; - if (m_opts.align == alignment::RIGHT) { + if (m_opts.tray_position == tray_postition::RIGHT) { x -= ((m_opts.width + m_opts.spacing) * m_clients.size() + m_opts.spacing); - } else if (m_opts.align == alignment::CENTER) { + } else if (m_opts.tray_position == tray_postition::CENTER) { x -= (width / 2) - (m_opts.width / 2); } return x;