Skip to content

Instantly share code, notes, and snippets.

@dangra
Created May 21, 2010 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dangra/408472 to your computer and use it in GitHub Desktop.
Save dangra/408472 to your computer and use it in GitHub Desktop.
diff --git a/objects/wibox.c b/objects/wibox.c
index b3a06cb..ec5835b 100644
--- a/objects/wibox.c
+++ b/objects/wibox.c
@@ -21,6 +21,7 @@
#include <xcb/shape.h>
+#include "systray.h"
#include "screen.h"
#include "wibox.h"
#include "objects/client.h"
@@ -443,6 +444,13 @@ wibox_systray_refresh(wibox_t *wibox)
uint32_t config_win_vals_off[2] = { -512, -512 };
xembed_window_t *em;
int phys_screen = wibox->ctx.phys_screen;
+ screen_t screen = globalconf.screens.tab[phys_screen];
+
+ if(!screen.systray.registered)
+ {
+ systray_register(phys_screen);
+ screen.systray.registered = true;
+ }
if(wibox->visible
&& systray->widget->isvisible
diff --git a/screen.h b/screen.h
index 6db22d5..dc4c4b8 100644
--- a/screen.h
+++ b/screen.h
@@ -37,6 +37,7 @@ struct a_screen
xcb_window_t window;
/** Systray window parent */
xcb_window_t parent;
+ bool registered;
} systray;
/** Previously focused client */
client_t *prev_client_focus;
diff --git a/systray.c b/systray.c
index 576c99d..4b902ea 100644
--- a/systray.c
+++ b/systray.c
@@ -38,6 +38,24 @@
void
systray_init(int phys_screen)
{
+ xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
+ screen_t screen = globalconf.screens.tab[phys_screen];
+
+ screen.systray.registered = false;
+ screen.systray.window = xcb_generate_id(globalconf.connection);
+ xcb_create_window(globalconf.connection, xscreen->root_depth,
+ screen.systray.window,
+ xscreen->root,
+ -1, -1, 1, 1, 0,
+ XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
+}
+
+/** Register systray in X.
+ * \param phys_screen Physical screen.
+ */
+void
+systray_register(int phys_screen)
+{
xcb_client_message_event_t ev;
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
char *atom_name;
@@ -57,13 +75,6 @@ systray_init(int phys_screen)
p_delete(&atom_name);
- globalconf.screens.tab[phys_screen].systray.window = xcb_generate_id(globalconf.connection);
- xcb_create_window(globalconf.connection, xscreen->root_depth,
- globalconf.screens.tab[phys_screen].systray.window,
- xscreen->root,
- -1, -1, 1, 1, 0,
- XCB_COPY_FROM_PARENT, xscreen->root_visual, 0, NULL);
-
/* Fill event */
p_clear(&ev, 1);
ev.response_type = XCB_CLIENT_MESSAGE;
@@ -101,6 +112,9 @@ systray_cleanup(int phys_screen)
xcb_intern_atom_reply_t *atom_systray_r;
char *atom_name;
+ if(!globalconf.screens.tab[phys_screen].systray.registered)
+ return;
+
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))
|| !(atom_systray_r = xcb_intern_atom_reply(globalconf.connection,
xcb_intern_atom_unchecked(globalconf.connection,
diff --git a/systray.h b/systray.h
index f877599..6175006 100644
--- a/systray.h
+++ b/systray.h
@@ -26,6 +26,7 @@
#include "common/xembed.h"
void systray_init(int);
+void systray_register(int);
void systray_cleanup(int);
int systray_request_handle(xcb_window_t, int, xembed_info_t *);
bool systray_iskdedockapp(xcb_window_t);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment