From 1aeac226a6a8268b15d1d5529bb020c3eb0ed76c Mon Sep 17 00:00:00 2001
From: patrick96
Date: Thu, 23 Mar 2023 22:27:11 +0100
Subject: [PATCH] Delete tray client pixmap and gc in destructor
---
include/x11/tray_client.hpp | 3 +++
src/x11/tray_client.cpp | 27 +++++++++++++++++----------
2 files changed, 20 insertions(+), 10 deletions(-)
diff --git a/include/x11/tray_client.hpp b/include/x11/tray_client.hpp
index 61722a63..38a8d638 100644
--- a/include/x11/tray_client.hpp
+++ b/include/x11/tray_client.hpp
@@ -124,6 +124,9 @@ class client : public non_copyable_mixin, public non_movable_mixin {
shared_ptr m_bg_slice;
unique_ptr m_context;
unique_ptr m_surface;
+ xcb_gcontext_t m_gc{XCB_NONE};
+
+ xcb_pixmap_t m_pixmap{XCB_NONE};
};
} // namespace tray
diff --git a/src/x11/tray_client.cpp b/src/x11/tray_client.cpp
index df64953f..57e3ba78 100644
--- a/src/x11/tray_client.cpp
+++ b/src/x11/tray_client.cpp
@@ -3,6 +3,7 @@
#include
#include
#include
+#include "xpp/pixmap.hpp"
#include "utils/memory.hpp"
#include "x11/connection.hpp"
@@ -65,35 +66,34 @@ client::client(
<< cw_flush(true);
// clang-format on
- // TODO destroy in destructor
- xcb_pixmap_t pixmap = m_connection.generate_id();
-
try {
- m_connection.create_pixmap_checked(client_depth, pixmap, m_wrapper, s.w, s.h);
+ m_pixmap = m_connection.generate_id();
+ m_connection.create_pixmap_checked(client_depth, m_pixmap, m_wrapper, s.w, s.h);
} catch (const std::exception& err) {
+ m_pixmap = XCB_NONE;
// TODO in case of error, fall back to desired_background
m_log.err("Failed to create pixmap for tray background (err: %s)", err.what());
throw;
}
try {
- m_connection.change_window_attributes_checked(m_wrapper, XCB_CW_BACK_PIXMAP, &pixmap);
+ m_connection.change_window_attributes_checked(m_wrapper, XCB_CW_BACK_PIXMAP, &m_pixmap);
} catch (const std::exception& err) {
// TODO in case of error, fall back to desired_background
m_log.err("Failed to set tray window back pixmap (%s)", err.what());
throw;
}
- // TODO destroy in destructor
- xcb_gcontext_t gc = m_connection.generate_id();
try {
+ m_gc = m_connection.generate_id();
xcb_params_gc_t params{};
uint32_t mask = 0;
XCB_AUX_ADD_PARAM(&mask, ¶ms, graphics_exposures, 1);
std::array values{};
connection::pack_values(mask, ¶ms, values);
- m_connection.create_gc_checked(gc, pixmap, mask, values.data());
+ m_connection.create_gc_checked(m_gc, m_pixmap, mask, values.data());
} catch (const std::exception& err) {
+ m_gc = XCB_NONE;
m_log.err("Failed to create gcontext for tray background (err: %s)", err.what());
throw;
}
@@ -104,7 +104,7 @@ client::client(
throw std::runtime_error("Failed to get root visual for tray background");
}
- m_surface = make_unique(m_connection, pixmap, visual, s.w, s.h);
+ m_surface = make_unique(m_connection, m_pixmap, visual, s.w, s.h);
m_context = make_unique(*m_surface, m_log);
observe_background();
@@ -118,6 +118,14 @@ client::~client() {
if (m_wrapper != XCB_NONE) {
m_connection.destroy_window(m_wrapper);
}
+
+ if (m_gc != XCB_NONE) {
+ m_connection.free_gc(m_gc);
+ }
+
+ if (m_pixmap != XCB_NONE) {
+ m_connection.free_pixmap(m_pixmap);
+ }
}
string client::name() const {
@@ -317,7 +325,6 @@ void client::set_position(int x, int y) {
connection::pack_values(configure_mask, &configure_params, configure_values);
m_connection.configure_window_checked(client_window(), configure_mask, configure_values.data());
- // TODO
xcb_size_hints_t size_hints{};
xcb_icccm_size_hints_set_size(&size_hints, false, m_size.w, m_size.h);
xcb_icccm_set_wm_size_hints(m_connection, client_window(), XCB_ATOM_WM_NORMAL_HINTS, &size_hints);