From 81d1f74b7b39446710c4a5665043a9de058f6d08 Mon Sep 17 00:00:00 2001 From: patrick96 Date: Mon, 4 Apr 2022 21:06:17 +0200 Subject: [PATCH] Move client configuration into tray_client --- include/x11/tray_client.hpp | 9 ++++++- src/x11/tray_client.cpp | 50 +++++++++++++++++++++++++++++-------- src/x11/tray_manager.cpp | 35 ++++++-------------------- 3 files changed, 55 insertions(+), 39 deletions(-) diff --git a/include/x11/tray_client.hpp b/include/x11/tray_client.hpp index 33a3807b..f1edcb14 100644 --- a/include/x11/tray_client.hpp +++ b/include/x11/tray_client.hpp @@ -23,6 +23,9 @@ class tray_client : public non_copyable_mixin { unsigned int height() const; void clear_window() const; + void update_client_attributes() const; + void reparent() const; + bool match(const xcb_window_t& win) const; bool mapped() const; void mapped(bool state); @@ -34,9 +37,13 @@ class tray_client : public non_copyable_mixin { bool is_xembed_supported() const; const xembed::info& get_xembed() const; + void notify_xembed() const; + + void add_to_save_set() const; + void ensure_state() const; void reconfigure(int x, int y) const; - void configure_notify(int x, int y) const; + void configure_notify() const; protected: const logger& m_log; diff --git a/src/x11/tray_client.cpp b/src/x11/tray_client.cpp index a11ef96e..d2f89af8 100644 --- a/src/x11/tray_client.cpp +++ b/src/x11/tray_client.cpp @@ -84,6 +84,25 @@ void tray_client::clear_window() const { m_connection.clear_area_checked(1, client(), 0, 0, width(), height()); } +void tray_client::update_client_attributes() const { + uint32_t configure_mask = 0; + std::array configure_values{}; + xcb_params_cw_t configure_params{}; + + XCB_AUX_ADD_PARAM( + &configure_mask, &configure_params, event_mask, XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY); + + connection::pack_values(configure_mask, &configure_params, configure_values); + + m_log.trace("tray(%s): Update client window", m_connection.id(client())); + m_connection.change_window_attributes_checked(client(), configure_mask, configure_values.data()); +} + +void tray_client::reparent() const { + m_log.trace("tray(%s): Reparent client", m_connection.id(client())); + m_connection.reparent_window_checked(client(), embedder(), 0, 0); +} + /** * Is this the client for the given client window */ @@ -125,11 +144,22 @@ const xembed::info& tray_client::get_xembed() const { return m_xembed; } +void tray_client::notify_xembed() const { + if (is_xembed_supported()) { + m_log.trace("tray(%s): Send embbeded notification to client", m_connection.id(client())); + xembed::notify_embedded(m_connection, client(), embedder(), m_xembed.get_version()); + } +} + +void tray_client::add_to_save_set() const { + m_log.trace("tray(%s): Add client window to the save set", m_connection.id(client())); + m_connection.change_save_set_checked(XCB_SET_MODE_INSERT, client()); +} + /** * Make sure that the window mapping state is correct */ void tray_client::ensure_state() const { - // TODO correctly map/unmap wrapper bool should_be_mapped = true; if (is_xembed_supported()) { @@ -137,11 +167,13 @@ void tray_client::ensure_state() const { } if (!mapped() && should_be_mapped) { + m_log.trace("tray(%s): Map client", m_connection.id(client())); m_connection.map_window_checked(embedder()); m_connection.map_window_checked(client()); } else if (mapped() && !should_be_mapped) { - m_connection.unmap_window_checked(embedder()); + m_log.trace("tray(%s): Unmap client", m_connection.id(client())); m_connection.unmap_window_checked(client()); + m_connection.unmap_window_checked(embedder()); } } @@ -151,7 +183,6 @@ void tray_client::ensure_state() const { void tray_client::reconfigure(int x, int y) const { m_log.trace("tray(%s): moving to (%d, %d)", m_connection.id(client()), x, y); - // TODO correctly reconfigure wrapper + client uint32_t configure_mask = 0; std::array configure_values{}; xcb_params_configure_window_t configure_params{}; @@ -175,22 +206,21 @@ void tray_client::reconfigure(int x, int y) const { /** * Respond to client resize/move requests */ -void tray_client::configure_notify(int x, int y) const { - // TODO remove x and y position. The position will always be (0,0) +void tray_client::configure_notify() const { xcb_configure_notify_event_t notify; notify.response_type = XCB_CONFIGURE_NOTIFY; - notify.event = m_client; - notify.window = m_client; + notify.event = client(); + notify.window = client(); notify.override_redirect = false; notify.above_sibling = 0; - notify.x = x; - notify.y = y; + notify.x = 0; + notify.y = 0; notify.width = m_size.w; notify.height = m_size.h; notify.border_width = 0; unsigned int mask{XCB_EVENT_MASK_STRUCTURE_NOTIFY}; - m_connection.send_event_checked(false, m_client, mask, reinterpret_cast(¬ify)); + m_connection.send_event_checked(false, client(), mask, reinterpret_cast(¬ify)); } POLYBAR_NS_END diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp index 82122ef5..a6904de1 100644 --- a/src/x11/tray_manager.cpp +++ b/src/x11/tray_manager.cpp @@ -714,36 +714,15 @@ void tray_manager::process_docking_request(xcb_window_t win) { client.get_xembed().get_flags(), client.get_xembed().is_mapped() ? "true" : "false"); } - const uint32_t mask = XCB_CW_EVENT_MASK; - const uint32_t value = XCB_EVENT_MASK_PROPERTY_CHANGE | XCB_EVENT_MASK_STRUCTURE_NOTIFY; + client.update_client_attributes(); - m_log.trace("tray: Update client window"); - m_connection.change_window_attributes_checked(client.client(), mask, &value); + client.reparent(); - m_log.trace("tray: Configure client size"); - client.reconfigure(0, 0); + client.add_to_save_set(); - // TODO put this into tray_client class - m_log.trace("tray: Reparent client"); - m_connection.reparent_window_checked( - client.client(), client.embedder(), calculate_client_x(client.client()), calculate_client_y()); + client.notify_xembed(); - m_log.trace("tray: Add client window to the save set"); - // TODO move this into tray_client - m_connection.change_save_set_checked(XCB_SET_MODE_INSERT, client.client()); - - if (client.is_xembed_supported()) { - m_log.trace("tray: Send embbeded notification to client"); - // TODO move this into tray_client - xembed::notify_embedded(m_connection, client.client(), client.embedder(), client.get_xembed().get_version()); - } - - if (!client.is_xembed_supported() || client.get_xembed().is_mapped()) { - m_log.trace("tray: Map client"); - // TODO move this into tray_client - m_connection.map_window_checked(client.client()); - m_connection.map_window_checked(client.embedder()); - } + client.ensure_state(); m_clients.emplace_back(std::move(client)); } catch (const std::exception& err) { @@ -918,7 +897,7 @@ void tray_manager::handle(const evt::configure_request& evt) { if (m_activated && is_embedded(evt->window)) { try { m_log.trace("tray: Client configure request %s", m_connection.id(evt->window)); - find_client(evt->window)->configure_notify(calculate_client_x(evt->window), calculate_client_y()); + find_client(evt->window)->configure_notify(); } catch (const xpp::x::error::window& err) { m_log.err("Failed to reconfigure tray client, removing... (%s)", err.what()); remove_client(evt->window); @@ -933,7 +912,7 @@ void tray_manager::handle(const evt::resize_request& evt) { if (m_activated && is_embedded(evt->window)) { try { m_log.trace("tray: Received resize_request for client %s", m_connection.id(evt->window)); - find_client(evt->window)->configure_notify(calculate_client_x(evt->window), calculate_client_y()); + find_client(evt->window)->configure_notify(); } catch (const xpp::x::error::window& err) { m_log.err("Failed to reconfigure tray client, removing... (%s)", err.what()); remove_client(evt->window);