Created
May 24, 2010 18:30
-
-
Save dangra/412239 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/objects/wibox.c b/objects/wibox.c | |
index b3a06cb..c343a98 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" | |
@@ -430,6 +431,10 @@ wibox_systray_kickout(int phys_screen) | |
static void | |
wibox_systray_refresh(wibox_t *wibox) | |
{ | |
+ bool systray_found = false; | |
+ int phys_screen = wibox->ctx.phys_screen; | |
+ screen_t *screen = &globalconf.screens.tab[phys_screen]; | |
+ | |
if(!wibox->screen) | |
return; | |
@@ -442,7 +447,9 @@ wibox_systray_refresh(wibox_t *wibox) | |
uint32_t config_win_vals[4]; | |
uint32_t config_win_vals_off[2] = { -512, -512 }; | |
xembed_window_t *em; | |
- int phys_screen = wibox->ctx.phys_screen; | |
+ | |
+ systray_found = true; | |
+ systray_register(phys_screen); | |
if(wibox->visible | |
&& systray->widget->isvisible | |
@@ -450,10 +457,10 @@ wibox_systray_refresh(wibox_t *wibox) | |
{ | |
/* Set background of the systray window. */ | |
xcb_change_window_attributes(globalconf.connection, | |
- globalconf.screens.tab[phys_screen].systray.window, | |
+ screen->systray.window, | |
XCB_CW_BACK_PIXEL, config_back); | |
/* Map it. */ | |
- xcb_map_window(globalconf.connection, globalconf.screens.tab[phys_screen].systray.window); | |
+ xcb_map_window(globalconf.connection, screen->systray.window); | |
/* Move it. */ | |
switch(wibox->orientation) | |
{ | |
@@ -477,16 +484,16 @@ wibox_systray_refresh(wibox_t *wibox) | |
break; | |
} | |
/* reparent */ | |
- if(globalconf.screens.tab[phys_screen].systray.parent != wibox->window) | |
+ if(screen->systray.parent != wibox->window) | |
{ | |
xcb_reparent_window(globalconf.connection, | |
- globalconf.screens.tab[phys_screen].systray.window, | |
+ screen->systray.window, | |
wibox->window, | |
config_win_vals[0], config_win_vals[1]); | |
- globalconf.screens.tab[phys_screen].systray.parent = wibox->window; | |
+ screen->systray.parent = wibox->window; | |
} | |
xcb_configure_window(globalconf.connection, | |
- globalconf.screens.tab[phys_screen].systray.window, | |
+ screen->systray.window, | |
XCB_CONFIG_WINDOW_X | |
| XCB_CONFIG_WINDOW_Y | |
| XCB_CONFIG_WINDOW_WIDTH | |
@@ -585,6 +592,9 @@ wibox_systray_refresh(wibox_t *wibox) | |
break; | |
} | |
} | |
+ | |
+ if(!systray_found && screen->systray.registered) | |
+ systray_cleanup(phys_screen); | |
} | |
/** Get a wibox by its window. | |
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..08c2e3a 100644 | |
--- a/systray.c | |
+++ b/systray.c | |
@@ -38,12 +38,35 @@ | |
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.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; | |
xcb_intern_atom_cookie_t atom_systray_q; | |
xcb_intern_atom_reply_t *atom_systray_r; | |
xcb_atom_t atom_systray; | |
+ screen_t *screen = &globalconf.screens.tab[phys_screen]; | |
+ | |
+ /* Set registered even if it fails to don't try again unless forced */ | |
+ if(screen->systray.registered) | |
+ return; | |
+ screen->systray.registered = true; | |
/* Send requests */ | |
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))) | |
@@ -57,13 +80,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; | |
@@ -71,7 +87,7 @@ systray_init(int phys_screen) | |
ev.format = 32; | |
ev.type = MANAGER; | |
ev.data.data32[0] = XCB_CURRENT_TIME; | |
- ev.data.data32[2] = globalconf.screens.tab[phys_screen].systray.window; | |
+ ev.data.data32[2] = screen->systray.window; | |
ev.data.data32[3] = ev.data.data32[4] = 0; | |
if(!(atom_systray_r = xcb_intern_atom_reply(globalconf.connection, atom_systray_q, NULL))) | |
@@ -85,7 +101,7 @@ systray_init(int phys_screen) | |
p_delete(&atom_systray_r); | |
xcb_set_selection_owner(globalconf.connection, | |
- globalconf.screens.tab[phys_screen].systray.window, | |
+ screen->systray.window, | |
atom_systray, | |
XCB_CURRENT_TIME); | |
@@ -100,6 +116,11 @@ systray_cleanup(int phys_screen) | |
{ | |
xcb_intern_atom_reply_t *atom_systray_r; | |
char *atom_name; | |
+ screen_t *screen = &globalconf.screens.tab[phys_screen]; | |
+ | |
+ if(!screen->systray.registered) | |
+ return; | |
+ screen->systray.registered = false; | |
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen)) | |
|| !(atom_systray_r = xcb_intern_atom_reply(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