tray: Read width directly from tray_manager

This commit is contained in:
patrick96 2022-08-28 15:29:36 +02:00
parent ffcdf7d690
commit 03a2e6bb17
No known key found for this signature in database
GPG Key ID: 521E5E03AEBCA1A7
6 changed files with 29 additions and 19 deletions

View File

@ -101,7 +101,7 @@ namespace signals {
} // namespace ui
namespace ui_tray {
struct tray_width_change : public detail::value_signal<tray_width_change, unsigned int> {
struct tray_width_change : public detail::base_signal<tray_width_change> {
using base_type::base_type;
};
struct tray_pos_change : public detail::value_signal<tray_pos_change, int> {

View File

@ -27,8 +27,6 @@ namespace modules {
static constexpr const char* TAG_TRAY{"<tray>"};
tray_manager m_tray;
int m_width{0};
};
} // namespace modules
POLYBAR_NS_END

View File

@ -56,12 +56,11 @@ struct tray_settings {
xcb_window_t selection_owner{XCB_NONE};
};
class tray_manager
: public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message, evt::configure_request,
evt::resize_request, evt::selection_clear, evt::property_notify, evt::reparent_notify, evt::destroy_notify,
evt::map_notify, evt::unmap_notify>,
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::update_background,
signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility> {
class tray_manager : public xpp::event::sink<evt::expose, evt::visibility_notify, evt::client_message,
evt::configure_request, evt::resize_request, evt::selection_clear, evt::property_notify,
evt::reparent_notify, evt::destroy_notify, evt::map_notify, evt::unmap_notify>,
public signal_receiver<SIGN_PRIORITY_TRAY, signals::ui::update_background,
signals::ui_tray::tray_pos_change, signals::ui_tray::tray_visibility> {
public:
using make_type = unique_ptr<tray_manager>;
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<double, std::milli> 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);

View File

@ -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<float>(m_width)};
extent_val offset_extent = {extent_type::PIXEL, static_cast<float>(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;
}

View File

@ -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()));

View File

@ -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<bool>(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);