xpra icon
Bug tracker and wiki

SystemTray: systray-check.c

File systray-check.c, 1.6 KB (added by Antoine Martin, 6 months ago)

from https://wiki.gnome.org/Initiatives/StatusIconMigration/Guidelines/TraySupportCheck (because it may disappear?)

Line 
1/* Written by Patrick Griffis <[email protected]> SPDX License: CC0-1.0 */
2
3#ifdef GDK_WINDOWING_X11
4/* Note you will have to link to xlib in this case */
5#include <gdk/gdkx.h>
6#endif
7
8#ifdef GDK_WINDOWING_WIN32
9#include <gdk/win32/gdkwin32.h>
10#endif
11
12#ifdef GDK_WINDOWING_QUARTZ
13#include <gdk/quartz/gdkquartz.h>
14#endif
15
16
17gboolean
18tray_icon_supported (GtkWindow *window)
19{
20#if defined(GDK_WINDOWING_X11) || defined(GDK_WINDOWING_WIN32) || defined(GDK_WINDOWING_QUARTZ)
21    GdkScreen *screen = gtk_window_get_screen (window);
22    GdkDisplay *display = gdk_screen_get_display (screen);
23#endif
24
25#ifdef GDK_WINDOWING_X11
26    if (GDK_IS_X11_DISPLAY (display))
27      {
28        int screen_number = gdk_screen_get_number (screen);
29        char *selection_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d", screen_number);
30
31        Display *xdisplay = gdk_x11_display_get_xdisplay (display);
32        Atom selection_atom = gdk_x11_get_xatom_by_name_for_display (display, selection_name);
33        Window tray_window = None;   
34
35        gdk_x11_display_grab (display);
36        tray_window = XGetSelectionOwner (xdisplay, selection_atom);
37        gdk_x11_display_ungrab (display);
38
39        XFlush (xdisplay);
40        g_free (selection_name);
41
42        return (tray_window != None);
43
44      }
45#endif
46
47/* Windows and OSX always have tray support */
48#ifdef GDK_WINDOWING_WIN32
49    if (GDK_IS_WIN32_DISPLAY (display))
50        return TRUE;
51#endif
52
53#ifdef GDK_WINDOWING_QUARTZ
54    if (GDK_IS_QUARTZ_DISPLAY (display))
55        return TRUE;
56#endif
57
58    /* Wayland, Broadway, and Mir never do. */
59    return FALSE;
60}