From ab2b5f603c94a5d297744f2f51450f75c3dda662 Mon Sep 17 00:00:00 2001
From: patrick96
Date: Mon, 7 Mar 2022 01:24:15 +0100
Subject: [PATCH] Use bar window depth for tray pixmap
---
include/x11/tray_manager.hpp | 4 ++--
src/components/bar.cpp | 4 ++--
src/x11/tray_manager.cpp | 37 +++++++++++++++++++-----------------
3 files changed, 24 insertions(+), 21 deletions(-)
diff --git a/include/x11/tray_manager.hpp b/include/x11/tray_manager.hpp
index 452f5f3c..19e5043a 100644
--- a/include/x11/tray_manager.hpp
+++ b/include/x11/tray_manager.hpp
@@ -95,10 +95,10 @@ class tray_manager : public xpp::event::sink {
public:
using make_type = unique_ptr;
- static make_type make(const bar_settings& settings);
+ static make_type make(const bar_settings& bar_opts);
explicit tray_manager(connection& conn, signal_emitter& emitter, const logger& logger, background_manager& back,
- const bar_settings& settings);
+ const bar_settings& bar_opts);
~tray_manager();
diff --git a/src/components/bar.cpp b/src/components/bar.cpp
index fada7501..7a6cb86a 100644
--- a/src/components/bar.cpp
+++ b/src/components/bar.cpp
@@ -61,8 +61,8 @@ bar::make_type bar::make(loop& loop, bool only_initialize_values) {
* TODO: Break out all tray handling
*/
bar::bar(connection& conn, signal_emitter& emitter, const config& config, const logger& logger, loop& loop,
- unique_ptr&& screen, unique_ptr&& dispatch, unique_ptr&& action_ctxt,
- bool only_initialize_values)
+ unique_ptr&& screen, unique_ptr&& dispatch,
+ unique_ptr&& action_ctxt, bool only_initialize_values)
: m_connection(conn)
, m_sig(emitter)
, m_conf(config)
diff --git a/src/x11/tray_manager.cpp b/src/x11/tray_manager.cpp
index 1ba0dcef..40f42e9e 100644
--- a/src/x11/tray_manager.cpp
+++ b/src/x11/tray_manager.cpp
@@ -48,14 +48,14 @@ POLYBAR_NS
/**
* Create instance
*/
-tray_manager::make_type tray_manager::make(const bar_settings& settings) {
+tray_manager::make_type tray_manager::make(const bar_settings& bar_opts) {
return std::make_unique(
- connection::make(), signal_emitter::make(), logger::make(), background_manager::make(), settings);
+ connection::make(), signal_emitter::make(), logger::make(), background_manager::make(), bar_opts);
}
tray_manager::tray_manager(connection& conn, signal_emitter& emitter, const logger& logger, background_manager& back,
- const bar_settings& settings)
- : m_connection(conn), m_sig(emitter), m_log(logger), m_background_manager(back), m_bar_opts(settings) {
+ const bar_settings& bar_opts)
+ : m_connection(conn), m_sig(emitter), m_log(logger), m_background_manager(back), m_bar_opts(bar_opts) {
m_connection.attach_sink(this, SINK_PRIORITY_TRAY);
}
@@ -248,19 +248,22 @@ void tray_manager::deactivate(bool clear_selection) {
if (m_tray) {
m_log.trace("tray: Destroy window");
m_connection.destroy_window(m_tray);
- }
- m_context.reset();
- m_surface.reset();
- if (m_pixmap) {
- m_connection.free_pixmap(m_pixmap);
- }
- if (m_gc) {
- m_connection.free_gc(m_gc);
+ m_tray = 0;
+ }
+
+ m_context.reset();
+ m_surface.reset();
+
+ if (m_pixmap) {
+ m_connection.free_pixmap(m_pixmap);
+ m_pixmap = 0;
+ }
+
+ if (m_gc) {
+ m_connection.free_gc(m_gc);
+ m_gc = 0;
}
- m_tray = 0;
- m_pixmap = 0;
- m_gc = 0;
m_opts.win_size.w = 0;
m_opts.num_clients = 0;
m_acquired_selection = false;
@@ -516,9 +519,9 @@ void tray_manager::create_bg() {
if (!m_pixmap) {
try {
+ auto depth = m_connection.get_geometry(m_bar_opts.window)->depth;
m_pixmap = m_connection.generate_id();
- // TODO get depth from bar window
- m_connection.create_pixmap_checked(32, m_pixmap, m_tray, w, h);
+ m_connection.create_pixmap_checked(depth, m_pixmap, m_tray, w, h);
} catch (const exception& err) {
return m_log.err("Failed to create pixmap for tray background (err: %s)", err.what());
}