Systray: Fix systray at reloading or for manage already running tray icon

This commit is contained in:
Martin Duquesnoy 2010-07-31 14:28:04 +02:00
parent 3b81cacaac
commit 2292ab97d1
7 changed files with 39 additions and 43 deletions

View File

@ -562,9 +562,10 @@ propertynotify(XPropertyEvent *ev)
{
case XA_WM_TRANSIENT_FOR:
XGetTransientForHint(dpy, c->win, &trans);
if((c->flags & TileFlag || c->flags & MaxFlag))
if(((c->flags & HintFlag && (client_gb_win(trans) != NULL)))
|| (!(c->flags & HintFlag && (client_gb_win(trans) != NULL))))
if(!(c->flags & FreeFlag) && client_gb_win(trans) != NULL)
/* f(((c->flags & HintFlag && (client_gb_win(trans) != NULL)))
|| (!(c->flags & HintFlag && (client_gb_win(trans) != NULL))))*/
arrange(c->screen, True);
break;
case XA_WM_NORMAL_HINTS:

View File

@ -46,6 +46,8 @@ ewmh_init_hints(void)
char root_name[] = WMFS_VERSION;
char class[] = "wmfs", st[64];
long pid = (long)getpid();
char systray_atom[48];
s = screen_count();
net_atom = emalloc(net_last + s, sizeof(Atom));
@ -79,7 +81,12 @@ ewmh_init_hints(void)
net_atom[net_wm_state_demands_attention] = ATOM("_NET_WM_STATE_DEMANDS_ATTENTION");
net_atom[net_wm_system_tray_opcode] = ATOM("_NET_SYSTEM_TRAY_OPCODE");
net_atom[net_system_tray_message_data] = ATOM("_NET_SYSTEM_TRAY_MESSAGE_DATA");
net_atom[net_system_tray_s] = ATOM("_NET_SYSTEM_TRAY_S");
net_atom[net_system_tray_visual] = ATOM("_NET_SYSTEM_TRAY_VISUAL");
snprintf(systray_atom, sizeof(systray_atom), "_NET_SYSTEM_TRAY_S%d", 0/*SCREEN*/);
net_atom[net_system_tray_s] = ATOM(systray_atom);
net_atom[net_system_tray_orientation] = ATOM("_NET_SYSTEM_TRAY_ORIENTATION");
net_atom[xembed] = ATOM("_XEMBED");
net_atom[xembedinfo] = ATOM("_XEMBED_INFO");
net_atom[manager] = ATOM("MANAGER");
@ -152,7 +159,7 @@ ewmh_send_message(Window d, Window w, char *atom, long d0, long d1, long d2, lon
e.data.l[3] = d3;
e.data.l[4] = d4;
XSendEvent(dpy, d, False, (d4) ? (SubstructureRedirectMask | SubstructureNotifyMask) : NoEventMask, (XEvent*)&e);
XSendEvent(dpy, d, False, StructureNotifyMask, (XEvent*)&e);
XSync(dpy, False);
return;

View File

@ -71,7 +71,7 @@ init(void)
init_root();
screen_init_geo();
infobar_init();
systray_init();
systray_acquire();
init_status();
ewmh_update_current_tag_prop();
grabkeys();

View File

@ -129,6 +129,8 @@ enum
net_wm_system_tray_opcode,
net_system_tray_message_data,
net_system_tray_s,
net_system_tray_visual,
net_system_tray_orientation,
xembed,
xembedinfo,
manager,

View File

@ -36,32 +36,17 @@
Bool
systray_acquire(void)
{
char systray_atom[32];
if(!conf.systray.active)
return False;
snprintf(systray_atom, sizeof(systray_atom), "_NET_SYSTEM_TRAY_S%u", SCREEN);
trayatom = XInternAtom(dpy, systray_atom, False);
XSetSelectionOwner(dpy, ATOM(systray_atom), traywin, CurrentTime);
if(XGetSelectionOwner(dpy, trayatom) != traywin)
return False;
ewmh_send_message(ROOT, ROOT, "MANAGER", CurrentTime, trayatom, traywin, 0, 0);
return True;
}
void
systray_init(void)
{
XSetWindowAttributes wattr;
if(!conf.systray.active)
return;
if(!conf.systray.active || traywin)
return False;
if(XGetSelectionOwner(dpy, net_atom[net_system_tray_s]) != None)
{
warnx("Can't initialize system tray: owned by another process");
return False;
}
/* Init traywin window */
wattr.event_mask = ButtonPressMask | ExposureMask;
@ -69,18 +54,27 @@ systray_init(void)
wattr.background_pixmap = ParentRelative;
wattr.background_pixel = conf.colors.bar;
traywin = XCreateSimpleWindow(dpy, infobar[conf.systray.screen].bar->win, 0, 0, 1, 1, 0, 0, conf.colors.bar);
traywin = XCreateSimpleWindow(dpy, ROOT, -1, -1, 1, 1, 0, 0, conf.colors.bar);
XChangeWindowAttributes(dpy, traywin, CWEventMask | CWOverrideRedirect | CWBackPixel, &wattr);
XSelectInput(dpy, traywin, KeyPressMask | ButtonPressMask);
XMapRaised(dpy, traywin);
/* Select tray */
if(!systray_acquire())
warnx("Can't initialize system tray: owned by another process");
XSetSelectionOwner(dpy, net_atom[net_system_tray_s], traywin, CurrentTime);
return;
if(XGetSelectionOwner(dpy, net_atom[net_system_tray_s]) != traywin)
{
systray_freeicons();
warnx("System tray: can't get systray manager");
return False;
}
ewmh_send_message(ROOT, ROOT, "MANAGER", CurrentTime, net_atom[net_system_tray_s], traywin, 0, 0);
XSync(dpy, False);
return True;
}
void
@ -171,7 +165,7 @@ systray_freeicons(void)
IFREE(i);
}
XSetSelectionOwner(dpy, trayatom, None, CurrentTime);
XSetSelectionOwner(dpy, net_atom[net_system_tray_s], None, CurrentTime);
XDestroyWindow(dpy, traywin);
XSync(dpy, 0);

View File

@ -221,13 +221,6 @@ scan(void)
if(!wa.override_redirect && wa.map_state == IsViewable)
{
if(ewmh_get_xembed_state(w[i]))
{
systray_add(w[i]);
systray_update();
}
if(XGetWindowProperty(dpy, w[i], ATOM("_WMFS_TAG"), 0, 32,
False, XA_CARDINAL, &rt, &rf, &ir, &il, &ret) == Success && ret)
{

View File

@ -346,7 +346,6 @@ void statustext_handle(int sc, char *str);
/* systray.c */
Bool systray_acquire(void);
void systray_init(void);
void systray_add(Window win);
void systray_del(Systray *s);
void systray_state(Systray *s);