From 78a969ea0c97e21901f12d5603e6be53fbbb0355 Mon Sep 17 00:00:00 2001 From: gambas Date: Tue, 12 May 2020 09:43:47 +0200 Subject: [PATCH] X11Systray.Show() now takes the icon background color as second optional argument. [GB.DESKTOP.X11] * NEW: X11Systray.Show() now takes the icon background color as second optional argument. The default color is black. --- gb.desktop.x11/src/c_x11systray.c | 6 +++--- gb.desktop.x11/src/systray/embed.c | 7 ++++--- gb.desktop.x11/src/systray/systray.c | 14 ++++++++++++-- gb.desktop.x11/src/systray/systray.h | 2 +- gb.desktop.x11/src/systray/tray.h | 1 + 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/gb.desktop.x11/src/c_x11systray.c b/gb.desktop.x11/src/c_x11systray.c index dbb4ac51b..15577ad21 100644 --- a/gb.desktop.x11/src/c_x11systray.c +++ b/gb.desktop.x11/src/c_x11systray.c @@ -47,10 +47,10 @@ void SYSTRAY_raise_arrange(void) //--------------------------------------------------------------------------- -BEGIN_METHOD(X11Systray_Show, GB_INTEGER window) +BEGIN_METHOD(X11Systray_Show, GB_INTEGER window; GB_INTEGER background) X11_init(); - SYSTRAY_init(X11_display, VARG(window)); + SYSTRAY_init(X11_display, VARG(window), VARGOPT(background, 0)); END_METHOD @@ -178,7 +178,7 @@ GB_DESC X11SystrayDesc[] = { GB_DECLARE_VIRTUAL("X11Systray"), - GB_STATIC_METHOD("Show", NULL, X11Systray_Show, "(Window)i"), + GB_STATIC_METHOD("Show", NULL, X11Systray_Show, "(Window)i[(Background)i]"), GB_STATIC_PROPERTY_READ("Count", "i", X11Systray_Count), GB_STATIC_METHOD("_get", "X11SystrayIcon", X11Systray_get, "(Index)i"), GB_STATIC_METHOD("Refresh", NULL, X11Systray_Refresh, NULL), diff --git a/gb.desktop.x11/src/systray/embed.c b/gb.desktop.x11/src/systray/embed.c index f52afa3cd..d2833bc21 100644 --- a/gb.desktop.x11/src/systray/embed.c +++ b/gb.desktop.x11/src/systray/embed.c @@ -65,8 +65,6 @@ int embedder_embed(struct TrayIcon *ti) { int rc; - //XSetWindowAttributes xswa; - /* If the icon is being embedded as hidden, * we just start listening for property changes * to track _XEMBED mapped state */ @@ -93,6 +91,8 @@ int embedder_embed(struct TrayIcon *ti) //xswa.win_gravity = settings.bit_gravity; //XChangeWindowAttributes(tray_data.dpy, ti->mid_parent, CWWinGravity, &xswa); + XSetWindowBackground(tray_data.dpy, ti->wid, tray_data.bg); + //XSetWindowBackgroundPixmap(tray_data.dpy, ti->mid_parent, ParentRelative); //if (!x11_ok() || ti->mid_parent == None) RETURN_STATUS(FAILURE); @@ -111,7 +111,8 @@ int embedder_embed(struct TrayIcon *ti) break; } - XSetWindowBackgroundPixmap(tray_data.dpy, ti->wid, ParentRelative); + //XSetWindowBackgroundPixmap(tray_data.dpy, ti->wid, ParentRelative); + /* 4. Show mid-parent */ //XMapWindow(tray_data.dpy, ti->mid_parent); diff --git a/gb.desktop.x11/src/systray/systray.c b/gb.desktop.x11/src/systray/systray.c index 3192ae8b7..ab31de43d 100644 --- a/gb.desktop.x11/src/systray/systray.c +++ b/gb.desktop.x11/src/systray/systray.c @@ -773,7 +773,7 @@ int SYSTRAY_event_filter(XEvent *e) destroy_notify(ev.xdestroywindow); break; case ClientMessage: - LOG_TRACE(("ClientMessage(from 0x%x?)\n", ev.xclient.window)); + PRINT_LOG(("ClientMessage(from 0x%x?)\n", ev.xclient.window)); if (client_message(ev.xclient)) return 1; break; @@ -896,8 +896,10 @@ int remote_main(int argc, char **argv) #endif /* main() */ -void SYSTRAY_init(Display *display, Window window) +void SYSTRAY_init(Display *display, Window window, uint bg) { + XWindowAttributes xwa; + XColor color; /* Read settings */ tray_init(); @@ -921,6 +923,14 @@ void SYSTRAY_init(Display *display, Window window) else LOG_TRACE(("Opened dpy %p\n", tray_data.dpy));*/ tray_data.dpy = display; + + color.red = ((bg >> 16) & 0xFF) << 8; + color.green = ((bg >> 8) & 0xFF) << 8; + color.blue = (bg & 0xFF) << 8; + XGetWindowAttributes(tray_data.dpy, window, &xwa); + XAllocColor(display, DefaultColormapOfScreen(xwa.screen), &color); + + tray_data.bg = color.pixel; #ifdef ENABLE_GRACEFUL_EXIT_HACK if ((async_dpy = XOpenDisplay(settings.display_str)) == NULL) diff --git a/gb.desktop.x11/src/systray/systray.h b/gb.desktop.x11/src/systray/systray.h index b6fa06cc4..94c1c433f 100644 --- a/gb.desktop.x11/src/systray/systray.h +++ b/gb.desktop.x11/src/systray/systray.h @@ -35,7 +35,7 @@ typedef //#define DEBUG -void SYSTRAY_init(Display *display, Window window); +void SYSTRAY_init(Display *display, Window window, uint bg); void SYSTRAY_exit(); int SYSTRAY_event_filter(XEvent *ev); int SYSTRAY_get_count(); diff --git a/gb.desktop.x11/src/systray/tray.h b/gb.desktop.x11/src/systray/tray.h index 0772a49fb..3845f2045 100644 --- a/gb.desktop.x11/src/systray/tray.h +++ b/gb.desktop.x11/src/systray/tray.h @@ -79,6 +79,7 @@ struct TrayData { Window tray; /* ID of tray window */ Window hint_win; /* ID of icon window */ Display *dpy; /* Display pointer */ + unsigned long bg; // background color XSizeHints xsh; /* Size & position of the tray window */ XSizeHints root_wnd; /* Size & position :) of the root window */ Window old_selection_owner; /* Old owner of tray selection */