Register systray only if systray widgets are attached. (FS#503)

Signed-off-by: Daniel Graña <dangra@gmail.com>
Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Daniel Graña 2010-05-21 16:18:12 -03:00 committed by Uli Schlachter
parent 72261c9750
commit f47b816996
6 changed files with 62 additions and 7 deletions

View File

@ -22,6 +22,7 @@
#ifndef AWESOME_EVENT_H #ifndef AWESOME_EVENT_H
#define AWESOME_EVENT_H #define AWESOME_EVENT_H
#include "systray.h"
#include "objects/wibox.h" #include "objects/wibox.h"
#include "objects/client.h" #include "objects/client.h"
@ -30,6 +31,7 @@ awesome_refresh(void)
{ {
banning_refresh(); banning_refresh();
wibox_refresh(); wibox_refresh();
systray_refresh();
stack_refresh(); stack_refresh();
return xcb_flush(globalconf.connection); return xcb_flush(globalconf.connection);
} }

View File

@ -412,6 +412,8 @@ wibox_map(wibox_t *wibox)
static void static void
wibox_systray_refresh(wibox_t *wibox) wibox_systray_refresh(wibox_t *wibox)
{ {
wibox->has_systray = false;
if(!wibox->screen) if(!wibox->screen)
return; return;
@ -426,6 +428,8 @@ wibox_systray_refresh(wibox_t *wibox)
xembed_window_t *em; xembed_window_t *em;
int phys_screen = wibox->ctx.phys_screen; int phys_screen = wibox->ctx.phys_screen;
wibox->has_systray = true;
if(wibox->visible if(wibox->visible
&& systray->widget->isvisible && systray->widget->isvisible
&& systray->geometry.width) && systray->geometry.width)

View File

@ -65,6 +65,8 @@ struct wibox_t
/** The window's content and border */ /** The window's content and border */
image_t *bounding; image_t *bounding;
} shape; } shape;
/** Has wibox an attached systray **/
bool has_systray;
}; };
void wibox_unref_simplified(wibox_t **); void wibox_unref_simplified(wibox_t **);

View File

@ -40,6 +40,7 @@ struct a_screen
xcb_window_t window; xcb_window_t window;
/** Systray window parent */ /** Systray window parent */
xcb_window_t parent; xcb_window_t parent;
bool registered;
} systray; } systray;
/** Previously focused client */ /** Previously focused client */
client_t *prev_client_focus; client_t *prev_client_focus;

View File

@ -27,6 +27,8 @@
#include "systray.h" #include "systray.h"
#include "xwindow.h" #include "xwindow.h"
#include "objects/widget.h" #include "objects/widget.h"
#include "objects/wibox.h"
#include "common/array.h"
#include "common/atoms.h" #include "common/atoms.h"
#include "common/xutil.h" #include "common/xutil.h"
@ -37,6 +39,46 @@
*/ */
void void
systray_init(int phys_screen) systray_init(int phys_screen)
{
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
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);
}
/** Refresh all systrays registrations per physical screen
*/
void
systray_refresh()
{
bool has_systray;
int nscreen = xcb_setup_roots_length(xcb_get_setup(globalconf.connection));
for(int phys_screen = 0; phys_screen < nscreen; phys_screen++)
{
has_systray = false;
foreach(w, globalconf.wiboxes)
if(phys_screen == (*w)->ctx.phys_screen)
has_systray |= (*w)->has_systray;
if(has_systray)
systray_register(phys_screen);
else
systray_cleanup(phys_screen);
}
}
/** Register systray in X.
* \param phys_screen Physical screen.
*/
void
systray_register(int phys_screen)
{ {
xcb_client_message_event_t ev; xcb_client_message_event_t ev;
xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen); xcb_screen_t *xscreen = xutil_screen_get(globalconf.connection, phys_screen);
@ -45,6 +87,11 @@ systray_init(int phys_screen)
xcb_intern_atom_reply_t *atom_systray_r; xcb_intern_atom_reply_t *atom_systray_r;
xcb_atom_t atom_systray; xcb_atom_t atom_systray;
/* Set registered even if it fails to don't try again unless forced */
if(globalconf.screens.tab[phys_screen].systray.registered)
return;
globalconf.screens.tab[phys_screen].systray.registered = true;
/* Send requests */ /* Send requests */
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))) if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen)))
{ {
@ -57,13 +104,6 @@ systray_init(int phys_screen)
p_delete(&atom_name); 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 */ /* Fill event */
p_clear(&ev, 1); p_clear(&ev, 1);
ev.response_type = XCB_CLIENT_MESSAGE; ev.response_type = XCB_CLIENT_MESSAGE;
@ -101,6 +141,10 @@ systray_cleanup(int phys_screen)
xcb_intern_atom_reply_t *atom_systray_r; xcb_intern_atom_reply_t *atom_systray_r;
char *atom_name; char *atom_name;
if(!globalconf.screens.tab[phys_screen].systray.registered)
return;
globalconf.screens.tab[phys_screen].systray.registered = false;
if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen)) if(!(atom_name = xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", phys_screen))
|| !(atom_systray_r = xcb_intern_atom_reply(globalconf.connection, || !(atom_systray_r = xcb_intern_atom_reply(globalconf.connection,
xcb_intern_atom_unchecked(globalconf.connection, xcb_intern_atom_unchecked(globalconf.connection,

View File

@ -26,6 +26,8 @@
#include "common/xembed.h" #include "common/xembed.h"
void systray_init(int); void systray_init(int);
void systray_refresh(void);
void systray_register(int);
void systray_cleanup(int); void systray_cleanup(int);
int systray_request_handle(xcb_window_t, int, xembed_info_t *); int systray_request_handle(xcb_window_t, int, xembed_info_t *);
bool systray_iskdedockapp(xcb_window_t); bool systray_iskdedockapp(xcb_window_t);