From 03a2e6bb171a53d300618c1b2dc2e1b082a9bd1c Mon Sep 17 00:00:00 2001
From: patrick96
Date: Sun, 28 Aug 2022 15:29:36 +0200
Subject: [PATCH] tray: Read width directly from tray_manager
---
include/events/signal.hpp | 2 +-
include/modules/tray.hpp | 2 --
include/x11/tray_manager.hpp | 15 ++++++++-------
src/modules/tray.cpp | 6 ++++--
src/x11/tray_client.cpp | 4 ++--
src/x11/tray_manager.cpp | 19 ++++++++++++++-----
6 files changed, 29 insertions(+), 19 deletions(-)
diff --git a/include/events/signal.hpp b/include/events/signal.hpp
index 364aef8d..a91d8505 100644
--- a/include/events/signal.hpp
+++ b/include/events/signal.hpp
@@ -101,7 +101,7 @@ namespace signals {
} // namespace ui
namespace ui_tray {
- struct tray_width_change : public detail::value_signal {
+ struct tray_width_change : public detail::base_signal {
using base_type::base_type;
};
struct tray_pos_change : public detail::value_signal {
diff --git a/include/modules/tray.hpp b/include/modules/tray.hpp
index 99f9ca9e..dbf621f4 100644
--- a/include/modules/tray.hpp
+++ b/include/modules/tray.hpp
@@ -27,8 +27,6 @@ namespace modules {
static constexpr const char* TAG_TRAY{""};
tray_manager m_tray;
-
- int m_width{0};
};
} // namespace modules
POLYBAR_NS_END
diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp
index 54d6947e..f6b2946e 100644
--- a/include/x11/tray_manager.hpp
+++ b/include/x11/tray_manager.hpp
@@ -56,12 +56,11 @@ struct tray_settings {
xcb_window_t selection_owner{XCB_NONE};
};
-class tray_manager
- : public xpp::event::sink,
- public signal_receiver {
+class tray_manager : public xpp::event::sink,
+ public signal_receiver {
public:
using make_type = unique_ptr;
static make_type make(const bar_settings& bar_opts);
@@ -71,10 +70,10 @@ class tray_manager
~tray_manager();
bool running() const;
+ int get_width() const;
void setup(const string& tray_module_name);
void activate();
- void activate_delayed(chrono::duration delay = 1s);
void deactivate(bool clear_selection = true);
void reconfigure();
@@ -108,6 +107,8 @@ class tray_manager
int calculate_client_y();
+ void update_width(unsigned new_width);
+
bool is_embedded(const xcb_window_t& win) const;
tray_client* find_client(const xcb_window_t& win);
void remove_client(const tray_client& client, bool reconfigure = true);
diff --git a/src/modules/tray.cpp b/src/modules/tray.cpp
index d333c4c1..3691268f 100644
--- a/src/modules/tray.cpp
+++ b/src/modules/tray.cpp
@@ -26,15 +26,17 @@ namespace modules {
bool tray_module::build(builder* builder, const string& tag) const {
if (tag == TAG_TRAY) {
builder->control(tags::controltag::t);
- extent_val offset_extent = {extent_type::PIXEL, static_cast(m_width)};
+ extent_val offset_extent = {extent_type::PIXEL, static_cast(m_tray.get_width())};
builder->offset(offset_extent);
return true;
}
return false;
}
+ /**
+ * Replace signal with callback passed to tray.
+ */
bool tray_module::on(const signals::ui_tray::tray_width_change& evt) {
- m_width = evt.cast();
broadcast();
return true;
}
diff --git a/src/x11/tray_client.cpp b/src/x11/tray_client.cpp
index 89854c2c..290aa69e 100644
--- a/src/x11/tray_client.cpp
+++ b/src/x11/tray_client.cpp
@@ -195,8 +195,8 @@ void tray_client::ensure_state() const {
should_be_mapped = false;
}
- m_log.trace(
- "tray(%s): ensure_state (mapped=%i, should_be_mapped=%i)", m_connection.id(client()), mapped(), should_be_mapped);
+ m_log.trace("tray(%s): ensure_state (hidden=%i, mapped=%i, should_be_mapped=%i)", m_connection.id(client()), m_hidden,
+ mapped(), should_be_mapped);
if (should_be_mapped) {
m_log.trace("tray(%s): Map client", m_connection.id(client()));
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index f890ec24..053b7442 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -111,6 +111,10 @@ bool tray_manager::running() const {
return m_activated;
}
+int tray_manager::get_width() const {
+ return m_tray_width;
+}
+
/**
* Activate systray management
*/
@@ -212,7 +216,14 @@ void tray_manager::reconfigure() {
*/
void tray_manager::reconfigure_window() {
m_log.trace("tray: Reconfigure window (hidden=%i, clients=%i)", static_cast(m_hidden), m_clients.size());
- m_tray_width = calculate_w();
+ update_width(calculate_w());
+}
+
+void tray_manager::update_width(unsigned new_width) {
+ if (m_tray_width != new_width) {
+ m_tray_width = new_width;
+ m_sig.emit(signals::ui_tray::tray_width_change{});
+ }
}
/**
@@ -235,8 +246,6 @@ void tray_manager::reconfigure_clients() {
remove_client(*it, false);
}
}
-
- m_sig.emit(signals::ui_tray::tray_width_change{m_tray_width});
}
/**
@@ -691,7 +700,7 @@ void tray_manager::handle(const evt::map_notify& evt) {
m_log.trace("tray: Received map_notify");
m_log.trace("tray: Update container mapped flag");
redraw_window();
- } else if (is_embedded(evt->window)) {
+ } else if (is_embedded(evt->window)) { // TODO FIXME evt->window points to the wrapper window
m_log.trace("tray: Received map_notify");
m_log.trace("tray: Set client mapped");
auto client = find_client(evt->window);
@@ -707,7 +716,7 @@ void tray_manager::handle(const evt::map_notify& evt) {
* Event callback : XCB_UNMAP_NOTIFY
*/
void tray_manager::handle(const evt::unmap_notify& evt) {
- if (m_activated && is_embedded(evt->window)) {
+ if (m_activated && is_embedded(evt->window)) { // TODO FIXME evt->window points to the wrapper window
m_log.trace("tray: Received unmap_notify");
m_log.trace("tray: Set client unmapped");
auto client = find_client(evt->window);