From d730f2302726ad7c9200bbeba805fa3d4ff73df1 Mon Sep 17 00:00:00 2001 From: o9000 Date: Thu, 16 Jul 2015 09:02:13 +0200 Subject: [PATCH] systray: Trigger icon resize only when necessary --- src/systray/systraybar.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index d44e9b9..d93b330 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -234,13 +234,32 @@ void on_change_systray (void *obj) } // position and size the icon window - if (systray_profile) - fprintf(stderr, "XMoveResizeWindow(server.dsp, traywin->parent = %ld, traywin->x = %d, traywin->y = %d, traywin->width = %d, traywin->height = %d)\n", traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); - XMoveResizeWindow(server.dsp, traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); - if (traywin->reparented) { + unsigned int border_width; + int xpos, ypos; + unsigned int width, height, depth; + Window root; + if (!XGetGeometry(server.dsp, traywin->parent, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { + fprintf(stderr, RED "Couldn't get geometry of window!\n" RESET); + } + if (width != traywin->width || height != traywin->height || xpos != traywin->x || ypos != traywin->y) { 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); + fprintf(stderr, "XMoveResizeWindow(server.dsp, traywin->parent = %ld, traywin->x = %d, traywin->y = %d, traywin->width = %d, traywin->height = %d)\n", traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); + XMoveResizeWindow(server.dsp, traywin->parent, traywin->x, traywin->y, traywin->width, traywin->height); + } + + if (traywin->reparented) { + unsigned int border_width; + int xpos, ypos; + unsigned int width, height, depth; + Window root; + if (!XGetGeometry(server.dsp, traywin->win, &root, &xpos, &ypos, &width, &height, &border_width, &depth)) { + fprintf(stderr, RED "Couldn't get geometry of window!\n" RESET); + } + if (width != traywin->width || height != traywin->height || xpos != 0 || ypos != 0) { + 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); + } } } refresh_systray = 1;