From 0face4fea7882e74791fae653dd7e1716373c1b7 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 20 Aug 2014 11:47:47 +0200 Subject: [PATCH] systray: Only register/unregister when needed Signed-off-by: Uli Schlachter --- globalconf.h | 2 ++ systray.c | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/globalconf.h b/globalconf.h index 61d8bf3b..945c008a 100644 --- a/globalconf.h +++ b/globalconf.h @@ -121,6 +121,8 @@ typedef struct xcb_window_t window; /** Atom for _NET_SYSTEM_TRAY_%d */ xcb_atom_t atom; + /** Do we own the systray selection? */ + bool registered; /** Systray window parent */ drawin_t *parent; } systray; diff --git a/systray.c b/systray.c index dfe6f4a2..86ffe9e6 100644 --- a/systray.c +++ b/systray.c @@ -74,6 +74,11 @@ systray_register(void) xcb_client_message_event_t ev; xcb_screen_t *xscreen = globalconf.screen; + if(globalconf.systray.registered) + return; + + globalconf.systray.registered = true; + /* Fill event */ p_clear(&ev, 1); ev.response_type = XCB_CLIENT_MESSAGE; @@ -98,6 +103,11 @@ systray_register(void) void systray_cleanup(void) { + if(!globalconf.systray.registered) + return; + + globalconf.systray.registered = false; + xcb_set_selection_owner(globalconf.connection, XCB_NONE, globalconf.systray.atom, @@ -297,9 +307,7 @@ systray_update(int base_size, bool horizontal, bool reverse, int spacing) int luaA_systray(lua_State *L) { - - if(globalconf.systray.parent == NULL) - systray_register(); + systray_register(); if(lua_gettop(L) != 0) {