all repos — tint2 @ 78bc3304484e978ef2aff7a419fb4b1401ee8f43

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

systray: Break embedding into 2 steps
o9000 o9000
commit

78bc3304484e978ef2aff7a419fb4b1401ee8f43

parent

3805adc9f36a2a91f83caf70eb713562d40a4b77

3 files changed, 81 insertions(+), 49 deletions(-)

jump to
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -632,7 +632,7 @@ error = FALSE;

XErrorHandler old = XSetErrorHandler(window_error_handler); if (systray_profile) fprintf(stderr, "XSelectInput(server.dsp, traywin->win, StructureNotifyMask)\n"); - XSelectInput(server.dsp, traywin->win, SubstructureNotifyMask | StructureNotifyMask | PropertyChangeMask); + XSelectInput(server.dsp, traywin->win, SubstructureNotifyMask | StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask); XWithdrawWindow(server.dsp, traywin->win, server.screen); XReparentWindow(server.dsp, traywin->win, traywin->parent, 0, 0);

@@ -640,7 +640,56 @@ if (systray_profile)

fprintf(stderr, "XMoveResizeWindow(server.dsp, traywin->win = %ld, 0, 0, traywin->width = %d, traywin->height = %d)\n", traywin->win, traywin->width, traywin->height); XMoveResizeWindow(server.dsp, traywin->win, 0, 0, traywin->width, traywin->height); - // Embed into parent + XSync(server.dsp, False); + XSetErrorHandler(old); + if (error != FALSE) { + fprintf(stderr, RED "systray %d: cannot embed icon for window %lu (%s) parent %lu pid %d\n" RESET, __LINE__, traywin->win, traywin->name, traywin->parent, traywin->pid); + remove_icon(traywin); + return FALSE; + } + + traywin->reparented = 1; + + if (systray_profile) + fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); + + return TRUE; +} + +gboolean is_embedded(TrayWindow *traywin) +{ + Atom acttype; + int actfmt; + unsigned long nbitem, bytes; + unsigned long *data = 0; + int ret; + + if (systray_profile) + fprintf(stderr, "XGetWindowProperty(server.dsp, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data)\n"); + ret = XGetWindowProperty(server.dsp, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, (unsigned char**)&data); + if (ret == Success) { + if (data) { + if (nbitem >= 2) { + int hide = ((data[1] & XEMBED_MAPPED) == 0); + if (hide) { + XFree(data); + return FALSE; + } else { + XFree(data); + return TRUE; + } + } + XFree(data); + } + } + return FALSE; +} + +gboolean request_embed_icon(TrayWindow *traywin) +{ + if (traywin->embed_requested) + return TRUE; + { XEvent e; e.xclient.type = ClientMessage;

@@ -657,21 +706,10 @@ e.xclient.data.l[4] = 0;

if (systray_profile) fprintf(stderr, "XSendEvent(server.dsp, traywin->win, False, 0xFFFFFF, &e)\n"); XSendEvent(server.dsp, traywin->win, False, NoEventMask, &e); - } - - XSync(server.dsp, False); - XSetErrorHandler(old); - if (error != FALSE) { - fprintf(stderr, RED "systray %d: cannot embed icon for window %lu (%s) parent %lu pid %d\n" RESET, __LINE__, traywin->win, traywin->name, traywin->parent, traywin->pid); - remove_icon(traywin); - return FALSE; + XSync(server.dsp, False); } - traywin->reparented = 1; - - if (systray_profile) - fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); - + traywin->embed_requested = 1; return TRUE; }

@@ -682,45 +720,14 @@ if (systray_profile)

fprintf(stderr, "[%f] %s:%d win = %lu (%s)\n", profiling_get_time(), __FUNCTION__, __LINE__, traywin->win, traywin->name); if (traywin->embedded) return TRUE; + if (!is_embedded(traywin)) + return FALSE; Panel* panel = systray.area.panel; XSync(server.dsp, False); error = FALSE; XErrorHandler old = XSetErrorHandler(window_error_handler); - - if (0) { - Atom acttype; - int actfmt; - unsigned long nbitem, bytes; - unsigned char *data = 0; - int ret; - - if (systray_profile) - fprintf(stderr, "XGetWindowProperty(server.dsp, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data)\n"); - ret = XGetWindowProperty(server.dsp, traywin->win, server.atom._XEMBED_INFO, 0, 2, False, server.atom._XEMBED_INFO, &acttype, &actfmt, &nbitem, &bytes, &data); - if (ret == Success) { - if (data) { - if (nbitem >= 2) { - int hide = ((data[1] & XEMBED_MAPPED) == 0); - if (hide) { - // In theory we have to check the embedding with this and remove icons that refuse embedding. - // In practice we have no idea when the other application processes the event and accepts the embed so we cannot check without a race. - // Race can be triggered with PyGtk(2) apps. - //fprintf(stderr, RED "tint2: window refused embedding\n" RESET); - //remove_icon(traywin); - //XFree(data); - //return FALSE; - } - } - XFree(data); - } - } else { - fprintf(stderr, RED "tint2 : xembed error\n" RESET); - remove_icon(traywin); - return FALSE; - } - } // Redirect rendering when using compositing if (systray_composited) {
M src/systray/systraybar.hsrc/systray/systraybar.h

@@ -50,6 +50,7 @@ int chrono;

struct timespec time_last_render; int num_fast_renders; int reparented; + int embed_requested; int embedded; int bad_size_counter; timeout* resize_timeout;

@@ -91,11 +92,13 @@ void net_message(XClientMessageEvent *e);

gboolean add_icon(Window id); gboolean reparent_icon(TrayWindow *traywin); +gboolean is_embedded(TrayWindow *traywin); gboolean embed_icon(TrayWindow *traywin); void remove_icon(TrayWindow *traywin); void refresh_systray_icons(); void systray_render_icon(void *t); +gboolean request_embed_icon(TrayWindow *traywin); void systray_reconfigure_event(TrayWindow *traywin, XEvent *e); void systray_destroy_event(TrayWindow *traywin); void kde_update_icons();
M src/tint.csrc/tint.c

@@ -1279,10 +1279,28 @@ event_expose(&e);

break; case PropertyNotify: + for (it = systray.list_icons; it ; it = g_slist_next(it)) { + TrayWindow *traywin = (TrayWindow*)it->data; + if (traywin->win == e.xany.window && e.xproperty.atom == server.atom._XEMBED_INFO) { + fprintf(stderr, "PropertyNotify\n"); + if (is_embedded(traywin)) + embed_icon(traywin); + break; + } + } event_property_notify(&e); break; case ConfigureNotify: + for (it = systray.list_icons; it ; it = g_slist_next(it)) { + TrayWindow *traywin = (TrayWindow*)it->data; + if (traywin->win == e.xany.window) { + fprintf(stderr, "ConfigureNotify\n"); + if (is_embedded(traywin)) + embed_icon(traywin); + break; + } + } event_configure_notify(&e); break;

@@ -1291,6 +1309,7 @@ // 'win' is a trayer icon

for (it = systray.list_icons; it ; it = g_slist_next(it)) { TrayWindow *traywin = (TrayWindow*)it->data; if (traywin->win == e.xany.window) { + fprintf(stderr, "ConfigureRequest\n"); systray_reconfigure_event(traywin, &e); break; }

@@ -1306,8 +1325,11 @@ break;

for (it = systray.list_icons; it; it = g_slist_next(it)) { TrayWindow *traywin = (TrayWindow*)it->data; if (traywin->win == e.xreparent.window) { + fprintf(stderr, "ReparentNotify\n"); if (traywin->parent == e.xreparent.parent) { - embed_icon(traywin); + request_embed_icon(traywin); + if (is_embedded(traywin)) + embed_icon(traywin); } else { remove_icon(traywin); }