4 * Copyright 2001 Sun Microsystems Inc.
6 * Erwann Chenede <erwann.chenede@sun.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
26 #include "gdkscreen-x11.h"
28 #include "gdkscreen.h"
29 #include "gdkdisplay.h"
30 #include "gdkdisplay-x11.h"
38 #include <X11/Xatom.h>
40 #ifdef HAVE_SOLARIS_XINERAMA
41 #include <X11/extensions/xinerama.h>
43 #ifdef HAVE_XFREE_XINERAMA
44 #include <X11/extensions/Xinerama.h>
48 #include <X11/extensions/Xrandr.h>
52 #include <X11/extensions/Xfixes.h>
55 #include "gdksettings.c"
57 static void gdk_screen_x11_dispose (GObject *object);
58 static void gdk_screen_x11_finalize (GObject *object);
59 static void init_randr_support (GdkScreen *screen);
60 static void deinit_multihead (GdkScreen *screen);
64 WINDOW_MANAGER_CHANGED,
68 static guint signals[LAST_SIGNAL] = { 0 };
70 G_DEFINE_TYPE (GdkScreenX11, _gdk_screen_x11, GDK_TYPE_SCREEN)
72 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
74 struct _NetWmSupportedAtoms
82 GdkRectangle geometry;
91 _gdk_screen_x11_class_init (GdkScreenX11Class *klass)
93 GObjectClass *object_class = G_OBJECT_CLASS (klass);
95 object_class->dispose = gdk_screen_x11_dispose;
96 object_class->finalize = gdk_screen_x11_finalize;
98 signals[WINDOW_MANAGER_CHANGED] =
99 g_signal_new (g_intern_static_string ("window_manager_changed"),
100 G_OBJECT_CLASS_TYPE (object_class),
102 G_STRUCT_OFFSET (GdkScreenX11Class, window_manager_changed),
104 g_cclosure_marshal_VOID__VOID,
110 _gdk_screen_x11_init (GdkScreenX11 *screen)
115 * gdk_screen_get_display:
116 * @screen: a #GdkScreen
118 * Gets the display to which the @screen belongs.
120 * Returns: (transfer none): the display to which @screen belongs
125 gdk_screen_get_display (GdkScreen *screen)
127 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
129 return GDK_SCREEN_X11 (screen)->display;
132 * gdk_screen_get_width:
133 * @screen: a #GdkScreen
135 * Gets the width of @screen in pixels
137 * Returns: the width of @screen in pixels.
142 gdk_screen_get_width (GdkScreen *screen)
144 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
146 return WidthOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
150 * gdk_screen_get_height:
151 * @screen: a #GdkScreen
153 * Gets the height of @screen in pixels
155 * Returns: the height of @screen in pixels.
160 gdk_screen_get_height (GdkScreen *screen)
162 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
164 return HeightOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
168 * gdk_screen_get_width_mm:
169 * @screen: a #GdkScreen
171 * Gets the width of @screen in millimeters.
172 * Note that on some X servers this value will not be correct.
174 * Returns: the width of @screen in millimeters.
179 gdk_screen_get_width_mm (GdkScreen *screen)
181 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
183 return WidthMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
187 * gdk_screen_get_height_mm:
188 * @screen: a #GdkScreen
190 * Returns the height of @screen in millimeters.
191 * Note that on some X servers this value will not be correct.
193 * Returns: the heigth of @screen in millimeters.
198 gdk_screen_get_height_mm (GdkScreen *screen)
200 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
202 return HeightMMOfScreen (GDK_SCREEN_X11 (screen)->xscreen);
206 * gdk_screen_get_number:
207 * @screen: a #GdkScreen
209 * Gets the index of @screen among the screens in the display
210 * to which it belongs. (See gdk_screen_get_display())
217 gdk_screen_get_number (GdkScreen *screen)
219 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
221 return GDK_SCREEN_X11 (screen)->screen_num;
225 * gdk_screen_get_root_window:
226 * @screen: a #GdkScreen
228 * Gets the root window of @screen.
230 * Returns: (transfer none): the root window
235 gdk_screen_get_root_window (GdkScreen *screen)
237 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
239 return GDK_SCREEN_X11 (screen)->root_window;
243 _gdk_screen_x11_events_uninit (GdkScreen *screen)
245 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
247 if (screen_x11->xsettings_client)
249 xsettings_client_destroy (screen_x11->xsettings_client);
250 screen_x11->xsettings_client = NULL;
255 gdk_screen_x11_dispose (GObject *object)
257 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
260 for (i = 0; i < 32; ++i)
262 if (screen_x11->subwindow_gcs[i])
264 XFreeGC (screen_x11->xdisplay, screen_x11->subwindow_gcs[i]);
265 screen_x11->subwindow_gcs[i] = 0;
269 _gdk_screen_x11_events_uninit (GDK_SCREEN (object));
271 if (screen_x11->root_window)
272 _gdk_window_destroy (screen_x11->root_window, TRUE);
274 G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->dispose (object);
276 screen_x11->xdisplay = NULL;
277 screen_x11->xscreen = NULL;
278 screen_x11->screen_num = -1;
279 screen_x11->xroot_window = None;
280 screen_x11->wmspec_check_window = None;
284 gdk_screen_x11_finalize (GObject *object)
286 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (object);
289 if (screen_x11->root_window)
290 g_object_unref (screen_x11->root_window);
293 for (i = 0; i < screen_x11->nvisuals; i++)
294 g_object_unref (screen_x11->visuals[i]);
295 g_free (screen_x11->visuals);
296 g_hash_table_destroy (screen_x11->visual_hash);
298 g_free (screen_x11->window_manager_name);
300 deinit_multihead (GDK_SCREEN (object));
302 G_OBJECT_CLASS (_gdk_screen_x11_parent_class)->finalize (object);
306 * gdk_screen_get_n_monitors:
307 * @screen: a #GdkScreen
309 * Returns the number of monitors which @screen consists of.
311 * Returns: number of monitors which @screen consists of
316 gdk_screen_get_n_monitors (GdkScreen *screen)
318 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
320 return GDK_SCREEN_X11 (screen)->n_monitors;
324 * gdk_screen_get_primary_monitor:
325 * @screen: a #GdkScreen.
327 * Gets the primary monitor for @screen. The primary monitor
328 * is considered the monitor where the 'main desktop' lives.
329 * While normal application windows typically allow the window
330 * manager to place the windows, specialized desktop applications
331 * such as panels should place themselves on the primary monitor.
333 * If no primary monitor is configured by the user, the return value
334 * will be 0, defaulting to the first monitor.
336 * Returns: An integer index for the primary monitor, or 0 if none is configured.
341 gdk_screen_get_primary_monitor (GdkScreen *screen)
343 g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
345 return GDK_SCREEN_X11 (screen)->primary_monitor;
349 * gdk_screen_get_monitor_width_mm:
350 * @screen: a #GdkScreen
351 * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
353 * Gets the width in millimeters of the specified monitor, if available.
355 * Returns: the width of the monitor, or -1 if not available
360 gdk_screen_get_monitor_width_mm (GdkScreen *screen,
363 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
365 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
366 g_return_val_if_fail (monitor_num >= 0, -1);
367 g_return_val_if_fail (monitor_num < screen_x11->n_monitors, -1);
369 return screen_x11->monitors[monitor_num].width_mm;
373 * gdk_screen_get_monitor_height_mm:
374 * @screen: a #GdkScreen
375 * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
377 * Gets the height in millimeters of the specified monitor.
379 * Returns: the height of the monitor, or -1 if not available
384 gdk_screen_get_monitor_height_mm (GdkScreen *screen,
387 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
389 g_return_val_if_fail (GDK_IS_SCREEN (screen), -1);
390 g_return_val_if_fail (monitor_num >= 0, -1);
391 g_return_val_if_fail (monitor_num < screen_x11->n_monitors, -1);
393 return screen_x11->monitors[monitor_num].height_mm;
397 * gdk_screen_get_monitor_plug_name:
398 * @screen: a #GdkScreen
399 * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
401 * Returns the output name of the specified monitor.
402 * Usually something like VGA, DVI, or TV, not the actual
403 * product name of the display device.
405 * Returns: a newly-allocated string containing the name of the monitor,
406 * or %NULL if the name cannot be determined
411 gdk_screen_get_monitor_plug_name (GdkScreen *screen,
414 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
416 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
417 g_return_val_if_fail (monitor_num >= 0, NULL);
418 g_return_val_if_fail (monitor_num < screen_x11->n_monitors, NULL);
420 return g_strdup (screen_x11->monitors[monitor_num].output_name);
424 * gdk_x11_screen_get_monitor_output:
425 * @screen: a #GdkScreen
426 * @monitor_num: number of the monitor, between 0 and gdk_screen_get_n_monitors (screen)
428 * Gets the XID of the specified output/monitor.
429 * If the X server does not support version 1.2 of the RANDR
430 * extension, 0 is returned.
432 * Returns: the XID of the monitor
437 gdk_x11_screen_get_monitor_output (GdkScreen *screen,
440 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
442 g_return_val_if_fail (GDK_IS_SCREEN (screen), None);
443 g_return_val_if_fail (monitor_num >= 0, None);
444 g_return_val_if_fail (monitor_num < screen_x11->n_monitors, None);
446 return screen_x11->monitors[monitor_num].output;
450 * gdk_screen_get_monitor_geometry:
451 * @screen: a #GdkScreen
452 * @monitor_num: the monitor number, between 0 and gdk_screen_get_n_monitors (screen)
453 * @dest: (out) (allow-none): a #GdkRectangle to be filled with the monitor geometry
455 * Retrieves the #GdkRectangle representing the size and position of
456 * the individual monitor within the entire screen area.
458 * Note that the size of the entire screen area can be retrieved via
459 * gdk_screen_get_width() and gdk_screen_get_height().
464 gdk_screen_get_monitor_geometry (GdkScreen *screen,
468 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
470 g_return_if_fail (GDK_IS_SCREEN (screen));
471 g_return_if_fail (monitor_num >= 0);
472 g_return_if_fail (monitor_num < screen_x11->n_monitors);
475 *dest = screen_x11->monitors[monitor_num].geometry;
479 * gdk_screen_get_rgba_visual:
480 * @screen: a #GdkScreen
482 * Gets a visual to use for creating windows with an alpha channel.
483 * The windowing system on which GTK+ is running
484 * may not support this capability, in which case %NULL will
485 * be returned. Even if a non-%NULL value is returned, its
486 * possible that the window's alpha channel won't be honored
487 * when displaying the window on the screen: in particular, for
488 * X an appropriate windowing manager and compositing manager
489 * must be running to provide appropriate display.
491 * This functionality is not implemented in the Windows backend.
493 * For setting an overall opacity for a top-level window, see
494 * gdk_window_set_opacity().
496 * Return value: (transfer none): a visual to use for windows with an
497 * alpha channel or %NULL if the capability is not available.
502 gdk_screen_get_rgba_visual (GdkScreen *screen)
504 GdkScreenX11 *screen_x11;
506 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
508 screen_x11 = GDK_SCREEN_X11 (screen);
510 return screen_x11->rgba_visual;
514 * gdk_x11_screen_get_xscreen:
515 * @screen: a #GdkScreen.
516 * @returns: (transfer none): an Xlib <type>Screen*</type>
518 * Returns the screen of a #GdkScreen.
523 gdk_x11_screen_get_xscreen (GdkScreen *screen)
525 return GDK_SCREEN_X11 (screen)->xscreen;
529 * gdk_x11_screen_get_screen_number:
530 * @screen: a #GdkScreen.
531 * @returns: the position of @screen among the screens of
534 * Returns the index of a #GdkScreen.
539 gdk_x11_screen_get_screen_number (GdkScreen *screen)
541 return GDK_SCREEN_X11 (screen)->screen_num;
545 check_is_composited (GdkDisplay *display,
546 GdkScreenX11 *screen_x11)
548 Atom xselection = gdk_x11_atom_to_xatom_for_display (display, screen_x11->cm_selection_atom);
551 xwindow = XGetSelectionOwner (GDK_DISPLAY_XDISPLAY (display), xselection);
553 return xwindow != None;
557 make_cm_atom (int screen_number)
559 gchar *name = g_strdup_printf ("_NET_WM_CM_S%d", screen_number);
560 GdkAtom atom = gdk_atom_intern (name, FALSE);
566 init_monitor_geometry (GdkX11Monitor *monitor,
567 int x, int y, int width, int height)
569 monitor->geometry.x = x;
570 monitor->geometry.y = y;
571 monitor->geometry.width = width;
572 monitor->geometry.height = height;
574 monitor->output = None;
575 monitor->width_mm = -1;
576 monitor->height_mm = -1;
577 monitor->output_name = NULL;
578 monitor->manufacturer = NULL;
582 init_fake_xinerama (GdkScreen *screen)
584 #ifdef G_ENABLE_DEBUG
585 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
586 XSetWindowAttributes atts;
590 if (!(_gdk_debug_flags & GDK_DEBUG_XINERAMA))
593 /* Fake Xinerama mode by splitting the screen into 4 monitors.
594 * Also draw a little cross to make the monitor boundaries visible.
596 w = WidthOfScreen (screen_x11->xscreen);
597 h = HeightOfScreen (screen_x11->xscreen);
599 screen_x11->n_monitors = 4;
600 screen_x11->monitors = g_new0 (GdkX11Monitor, 4);
601 init_monitor_geometry (&screen_x11->monitors[0], 0, 0, w / 2, h / 2);
602 init_monitor_geometry (&screen_x11->monitors[1], w / 2, 0, w / 2, h / 2);
603 init_monitor_geometry (&screen_x11->monitors[2], 0, h / 2, w / 2, h / 2);
604 init_monitor_geometry (&screen_x11->monitors[3], w / 2, h / 2, w / 2, h / 2);
606 atts.override_redirect = 1;
607 atts.background_pixel = WhitePixel(GDK_SCREEN_XDISPLAY (screen),
608 screen_x11->screen_num);
609 win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen),
610 screen_x11->xroot_window, 0, h / 2, w, 1, 0,
611 DefaultDepth(GDK_SCREEN_XDISPLAY (screen),
612 screen_x11->screen_num),
614 DefaultVisual(GDK_SCREEN_XDISPLAY (screen),
615 screen_x11->screen_num),
616 CWOverrideRedirect|CWBackPixel,
618 XMapRaised(GDK_SCREEN_XDISPLAY (screen), win);
619 win = XCreateWindow(GDK_SCREEN_XDISPLAY (screen),
620 screen_x11->xroot_window, w/2 , 0, 1, h, 0,
621 DefaultDepth(GDK_SCREEN_XDISPLAY (screen),
622 screen_x11->screen_num),
624 DefaultVisual(GDK_SCREEN_XDISPLAY (screen),
625 screen_x11->screen_num),
626 CWOverrideRedirect|CWBackPixel,
628 XMapRaised(GDK_SCREEN_XDISPLAY (screen), win);
636 free_monitors (GdkX11Monitor *monitors,
641 for (i = 0; i < n_monitors; ++i)
643 g_free (monitors[i].output_name);
644 g_free (monitors[i].manufacturer);
652 monitor_compare_function (GdkX11Monitor *monitor1,
653 GdkX11Monitor *monitor2)
655 /* Sort the leftmost/topmost monitors first.
656 * For "cloned" monitors, sort the bigger ones first
657 * (giving preference to taller monitors over wider
661 if (monitor1->geometry.x != monitor2->geometry.x)
662 return monitor1->geometry.x - monitor2->geometry.x;
664 if (monitor1->geometry.y != monitor2->geometry.y)
665 return monitor1->geometry.y - monitor2->geometry.y;
667 if (monitor1->geometry.height != monitor2->geometry.height)
668 return - (monitor1->geometry.height - monitor2->geometry.height);
670 if (monitor1->geometry.width != monitor2->geometry.width)
671 return - (monitor1->geometry.width - monitor2->geometry.width);
678 init_randr13 (GdkScreen *screen)
681 GdkDisplay *display = gdk_screen_get_display (screen);
682 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
683 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
684 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
685 XRRScreenResources *resources;
686 RROutput primary_output;
687 RROutput first_output = None;
690 gboolean randr12_compat = FALSE;
692 if (!display_x11->have_randr13)
695 resources = XRRGetScreenResourcesCurrent (screen_x11->xdisplay,
696 screen_x11->xroot_window);
700 monitors = g_array_sized_new (FALSE, TRUE, sizeof (GdkX11Monitor),
703 for (i = 0; i < resources->noutput; ++i)
705 XRROutputInfo *output =
706 XRRGetOutputInfo (dpy, resources, resources->outputs[i]);
708 /* Non RandR1.2 X driver have output name "default" */
709 randr12_compat |= !g_strcmp0 (output->name, "default");
711 if (output->connection == RR_Disconnected)
713 XRRFreeOutputInfo (output);
719 GdkX11Monitor monitor;
720 XRRCrtcInfo *crtc = XRRGetCrtcInfo (dpy, resources, output->crtc);
722 monitor.geometry.x = crtc->x;
723 monitor.geometry.y = crtc->y;
724 monitor.geometry.width = crtc->width;
725 monitor.geometry.height = crtc->height;
727 monitor.output = resources->outputs[i];
728 monitor.width_mm = output->mm_width;
729 monitor.height_mm = output->mm_height;
730 monitor.output_name = g_strdup (output->name);
731 /* FIXME: need EDID parser */
732 monitor.manufacturer = NULL;
734 g_array_append_val (monitors, monitor);
736 XRRFreeCrtcInfo (crtc);
739 XRRFreeOutputInfo (output);
742 if (resources->noutput > 0)
743 first_output = resources->outputs[0];
745 XRRFreeScreenResources (resources);
747 /* non RandR 1.2 X driver doesn't return any usable multihead data */
750 guint n_monitors = monitors->len;
752 free_monitors ((GdkX11Monitor *)g_array_free (monitors, FALSE),
758 g_array_sort (monitors,
759 (GCompareFunc) monitor_compare_function);
760 screen_x11->n_monitors = monitors->len;
761 screen_x11->monitors = (GdkX11Monitor *)g_array_free (monitors, FALSE);
763 screen_x11->primary_monitor = 0;
765 primary_output = XRRGetOutputPrimary (screen_x11->xdisplay,
766 screen_x11->xroot_window);
768 for (i = 0; i < screen_x11->n_monitors; ++i)
770 if (screen_x11->monitors[i].output == primary_output)
772 screen_x11->primary_monitor = i;
776 /* No RandR1.3+ available or no primary set, fall back to prefer LVDS as primary if present */
777 if (primary_output == None &&
778 g_ascii_strncasecmp (screen_x11->monitors[i].output_name, "LVDS", 4) == 0)
780 screen_x11->primary_monitor = i;
784 /* No primary specified and no LVDS found */
785 if (screen_x11->monitors[i].output == first_output)
786 screen_x11->primary_monitor = i;
789 return screen_x11->n_monitors > 0;
796 init_solaris_xinerama (GdkScreen *screen)
798 #ifdef HAVE_SOLARIS_XINERAMA
799 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
800 int screen_no = gdk_screen_get_number (screen);
801 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
802 XRectangle monitors[MAXFRAMEBUFFERS];
803 unsigned char hints[16];
808 if (!XineramaGetState (dpy, screen_no))
811 result = XineramaGetInfo (dpy, screen_no, monitors, hints, &n_monitors);
813 /* Yes I know it should be Success but the current implementation
814 * returns the num of monitor
821 screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
822 screen_x11->n_monitors = n_monitors;
824 for (i = 0; i < n_monitors; i++)
826 init_monitor_geometry (&screen_x11->monitors[i],
827 monitors[i].x, monitors[i].y,
828 monitors[i].width, monitors[i].height);
831 screen_x11->primary_monitor = 0;
834 #endif /* HAVE_SOLARIS_XINERAMA */
840 init_xfree_xinerama (GdkScreen *screen)
842 #ifdef HAVE_XFREE_XINERAMA
843 Display *dpy = GDK_SCREEN_XDISPLAY (screen);
844 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
845 XineramaScreenInfo *monitors;
848 if (!XineramaIsActive (dpy))
851 monitors = XineramaQueryScreens (dpy, &n_monitors);
853 if (n_monitors <= 0 || monitors == NULL)
855 /* If Xinerama doesn't think we have any monitors, try acting as
856 * though we had no Xinerama. If the "no monitors" condition
857 * is because XRandR 1.2 is currently switching between CRTCs,
858 * we'll be notified again when we have our monitor back,
859 * and can go back into Xinerama-ish mode at that point.
867 screen_x11->n_monitors = n_monitors;
868 screen_x11->monitors = g_new0 (GdkX11Monitor, n_monitors);
870 for (i = 0; i < n_monitors; ++i)
872 init_monitor_geometry (&screen_x11->monitors[i],
873 monitors[i].x_org, monitors[i].y_org,
874 monitors[i].width, monitors[i].height);
879 screen_x11->primary_monitor = 0;
882 #endif /* HAVE_XFREE_XINERAMA */
888 deinit_multihead (GdkScreen *screen)
890 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
892 free_monitors (screen_x11->monitors, screen_x11->n_monitors);
894 screen_x11->n_monitors = 0;
895 screen_x11->monitors = NULL;
899 compare_monitor (GdkX11Monitor *m1,
902 if (m1->geometry.x != m2->geometry.x ||
903 m1->geometry.y != m2->geometry.y ||
904 m1->geometry.width != m2->geometry.width ||
905 m1->geometry.height != m2->geometry.height)
908 if (m1->width_mm != m2->width_mm ||
909 m1->height_mm != m2->height_mm)
912 if (g_strcmp0 (m1->output_name, m2->output_name) != 0)
915 if (g_strcmp0 (m1->manufacturer, m2->manufacturer) != 0)
922 compare_monitors (GdkX11Monitor *monitors1, gint n_monitors1,
923 GdkX11Monitor *monitors2, gint n_monitors2)
927 if (n_monitors1 != n_monitors2)
930 for (i = 0; i < n_monitors1; i++)
932 if (!compare_monitor (monitors1 + i, monitors2 + i))
940 init_multihead (GdkScreen *screen)
942 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
943 int opcode, firstevent, firsterror;
945 /* There are four different implementations of multihead support:
947 * 1. Fake Xinerama for debugging purposes
949 * 3. Solaris Xinerama
950 * 4. XFree86/Xorg Xinerama
952 * We use them in that order.
954 if (init_fake_xinerama (screen))
957 if (init_randr13 (screen))
960 if (XQueryExtension (GDK_SCREEN_XDISPLAY (screen), "XINERAMA",
961 &opcode, &firstevent, &firsterror))
963 if (init_solaris_xinerama (screen))
966 if (init_xfree_xinerama (screen))
970 /* No multihead support of any kind for this screen */
971 screen_x11->n_monitors = 1;
972 screen_x11->monitors = g_new0 (GdkX11Monitor, 1);
973 screen_x11->primary_monitor = 0;
975 init_monitor_geometry (screen_x11->monitors, 0, 0,
976 WidthOfScreen (screen_x11->xscreen),
977 HeightOfScreen (screen_x11->xscreen));
981 _gdk_x11_screen_new (GdkDisplay *display,
985 GdkScreenX11 *screen_x11;
986 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
988 screen = g_object_new (GDK_TYPE_SCREEN_X11, NULL);
990 screen_x11 = GDK_SCREEN_X11 (screen);
991 screen_x11->display = display;
992 screen_x11->xdisplay = display_x11->xdisplay;
993 screen_x11->xscreen = ScreenOfDisplay (display_x11->xdisplay, screen_number);
994 screen_x11->screen_num = screen_number;
995 screen_x11->xroot_window = RootWindow (display_x11->xdisplay,screen_number);
996 screen_x11->wmspec_check_window = None;
997 /* we want this to be always non-null */
998 screen_x11->window_manager_name = g_strdup ("unknown");
1000 init_multihead (screen);
1001 init_randr_support (screen);
1003 _gdk_visual_init (screen);
1004 _gdk_windowing_window_init (screen);
1010 * It is important that we first request the selection
1011 * notification, and then setup the initial state of
1012 * is_composited to avoid a race condition here.
1015 _gdk_x11_screen_setup (GdkScreen *screen)
1017 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1019 screen_x11->cm_selection_atom = make_cm_atom (screen_x11->screen_num);
1020 gdk_display_request_selection_notification (screen_x11->display,
1021 screen_x11->cm_selection_atom);
1022 screen_x11->is_composited = check_is_composited (screen_x11->display, screen_x11);
1026 * gdk_screen_is_composited:
1027 * @screen: a #GdkScreen
1029 * Returns whether windows with an RGBA visual can reasonably
1030 * be expected to have their alpha channel drawn correctly on
1033 * On X11 this function returns whether a compositing manager is
1034 * compositing @screen.
1036 * Return value: Whether windows with RGBA visuals can reasonably be
1037 * expected to have their alpha channels drawn correctly on the screen.
1042 gdk_screen_is_composited (GdkScreen *screen)
1044 GdkScreenX11 *screen_x11;
1046 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1048 screen_x11 = GDK_SCREEN_X11 (screen);
1050 return screen_x11->is_composited;
1054 init_randr_support (GdkScreen * screen)
1056 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1058 XSelectInput (GDK_SCREEN_XDISPLAY (screen),
1059 screen_x11->xroot_window,
1060 StructureNotifyMask);
1063 XRRSelectInput (GDK_SCREEN_XDISPLAY (screen),
1064 screen_x11->xroot_window,
1065 RRScreenChangeNotifyMask |
1066 RRCrtcChangeNotifyMask |
1067 RROutputPropertyNotifyMask);
1072 process_monitors_change (GdkScreen *screen)
1074 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1076 GdkX11Monitor *monitors;
1079 n_monitors = screen_x11->n_monitors;
1080 monitors = screen_x11->monitors;
1082 screen_x11->n_monitors = 0;
1083 screen_x11->monitors = NULL;
1085 init_multihead (screen);
1087 changed = !compare_monitors (monitors, n_monitors,
1088 screen_x11->monitors, screen_x11->n_monitors);
1090 free_monitors (monitors, n_monitors);
1093 g_signal_emit_by_name (screen, "monitors-changed");
1097 _gdk_x11_screen_size_changed (GdkScreen *screen,
1102 GdkDisplayX11 *display_x11;
1105 width = gdk_screen_get_width (screen);
1106 height = gdk_screen_get_height (screen);
1109 display_x11 = GDK_DISPLAY_X11 (gdk_screen_get_display (screen));
1111 if (display_x11->have_randr13 && event->type == ConfigureNotify)
1113 g_signal_emit_by_name (screen, "monitors-changed");
1117 XRRUpdateConfiguration (event);
1119 if (event->type == ConfigureNotify)
1121 XConfigureEvent *rcevent = (XConfigureEvent *) event;
1122 Screen *xscreen = gdk_x11_screen_get_xscreen (screen);
1124 xscreen->width = rcevent->width;
1125 xscreen->height = rcevent->height;
1131 process_monitors_change (screen);
1133 if (width != gdk_screen_get_width (screen) ||
1134 height != gdk_screen_get_height (screen))
1135 g_signal_emit_by_name (screen, "size-changed");
1139 _gdk_x11_screen_window_manager_changed (GdkScreen *screen)
1141 g_signal_emit (screen, signals[WINDOW_MANAGER_CHANGED], 0);
1145 _gdk_x11_screen_process_owner_change (GdkScreen *screen,
1149 XFixesSelectionNotifyEvent *selection_event = (XFixesSelectionNotifyEvent *)event;
1150 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1151 Atom xcm_selection_atom = gdk_x11_atom_to_xatom_for_display (screen_x11->display,
1152 screen_x11->cm_selection_atom);
1154 if (selection_event->selection == xcm_selection_atom)
1156 gboolean composited = selection_event->owner != None;
1158 if (composited != screen_x11->is_composited)
1160 screen_x11->is_composited = composited;
1162 g_signal_emit_by_name (screen, "composited-changed");
1169 * _gdk_windowing_substitute_screen_number:
1170 * @display_name: The name of a display, in the form used by
1171 * gdk_display_open (). If %NULL a default value
1172 * will be used. On X11, this is derived from the DISPLAY
1173 * environment variable.
1174 * @screen_number: The number of a screen within the display
1175 * referred to by @display_name.
1177 * Modifies a @display_name to make @screen_number the default
1178 * screen when the display is opened.
1180 * Return value: a newly allocated string holding the resulting
1181 * display name. Free with g_free().
1184 _gdk_windowing_substitute_screen_number (const gchar *display_name,
1191 display_name = getenv ("DISPLAY");
1196 str = g_string_new (display_name);
1198 p = strrchr (str->str, '.');
1199 if (p && p > strchr (str->str, ':'))
1200 g_string_truncate (str, p - str->str);
1202 g_string_append_printf (str, ".%d", screen_number);
1204 return g_string_free (str, FALSE);
1208 * gdk_screen_make_display_name:
1209 * @screen: a #GdkScreen
1211 * Determines the name to pass to gdk_display_open() to get
1212 * a #GdkDisplay with this screen as the default screen.
1214 * Return value: a newly allocated string, free with g_free()
1219 gdk_screen_make_display_name (GdkScreen *screen)
1221 const gchar *old_display;
1223 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1225 old_display = gdk_display_get_name (gdk_screen_get_display (screen));
1227 return _gdk_windowing_substitute_screen_number (old_display,
1228 gdk_screen_get_number (screen));
1232 * gdk_screen_get_active_window:
1233 * @screen: a #GdkScreen
1235 * Returns the screen's currently active window.
1237 * On X11, this is done by inspecting the _NET_ACTIVE_WINDOW property
1238 * on the root window, as described in the <ulink
1239 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
1240 * Manager Hints</ulink>. If there is no currently currently active
1241 * window, or the window manager does not support the
1242 * _NET_ACTIVE_WINDOW hint, this function returns %NULL.
1244 * On other platforms, this function may return %NULL, depending on whether
1245 * it is implementable on that platform.
1247 * The returned window should be unrefed using g_object_unref() when
1250 * Return value: (transfer full): the currently active window, or %NULL.
1255 gdk_screen_get_active_window (GdkScreen *screen)
1257 GdkScreenX11 *screen_x11;
1258 GdkWindow *ret = NULL;
1261 gulong nitems_return;
1262 gulong bytes_after_return;
1263 guchar *data = NULL;
1265 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1267 if (!gdk_x11_screen_supports_net_wm_hint (screen,
1268 gdk_atom_intern_static_string ("_NET_ACTIVE_WINDOW")))
1271 screen_x11 = GDK_SCREEN_X11 (screen);
1273 if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
1274 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1275 "_NET_ACTIVE_WINDOW"),
1276 0, 1, False, XA_WINDOW, &type_return,
1277 &format_return, &nitems_return,
1278 &bytes_after_return, &data)
1281 if ((type_return == XA_WINDOW) && (format_return == 32) && (data))
1283 GdkNativeWindow window = *(GdkNativeWindow *) data;
1287 ret = gdk_window_foreign_new_for_display (screen_x11->display,
1288 *(GdkNativeWindow *) data);
1300 * gdk_screen_get_window_stack:
1301 * @screen: a #GdkScreen
1303 * Returns a #GList of #GdkWindow<!-- -->s representing the current
1306 * On X11, this is done by inspecting the _NET_CLIENT_LIST_STACKING
1307 * property on the root window, as described in the <ulink
1308 * url="http://www.freedesktop.org/Standards/wm-spec">Extended Window
1309 * Manager Hints</ulink>. If the window manager does not support the
1310 * _NET_CLIENT_LIST_STACKING hint, this function returns %NULL.
1312 * On other platforms, this function may return %NULL, depending on whether
1313 * it is implementable on that platform.
1315 * The returned list is newly allocated and owns references to the
1316 * windows it contains, so it should be freed using g_list_free() and
1317 * its windows unrefed using g_object_unref() when no longer needed.
1319 * Return value: (transfer full) (element-type GdkWindow):
1320 * a list of #GdkWindow<!-- -->s for the current window stack,
1326 gdk_screen_get_window_stack (GdkScreen *screen)
1328 GdkScreenX11 *screen_x11;
1332 gulong nitems_return;
1333 gulong bytes_after_return;
1334 guchar *data = NULL;
1336 g_return_val_if_fail (GDK_IS_SCREEN (screen), NULL);
1338 if (!gdk_x11_screen_supports_net_wm_hint (screen,
1339 gdk_atom_intern_static_string ("_NET_CLIENT_LIST_STACKING")))
1342 screen_x11 = GDK_SCREEN_X11 (screen);
1344 if (XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
1345 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1346 "_NET_CLIENT_LIST_STACKING"),
1347 0, G_MAXLONG, False, XA_WINDOW, &type_return,
1348 &format_return, &nitems_return,
1349 &bytes_after_return, &data)
1352 if ((type_return == XA_WINDOW) && (format_return == 32) &&
1353 (data) && (nitems_return > 0))
1355 gulong *stack = (gulong *) data;
1359 for (i = 0; i < nitems_return; i++)
1361 win = gdk_window_foreign_new_for_display (screen_x11->display,
1362 (GdkNativeWindow)stack[i]);
1365 ret = g_list_append (ret, win);
1376 /* Sends a ClientMessage to all toplevel client windows */
1378 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
1385 unsigned long nitems, after;
1386 unsigned char *data;
1387 Window *ret_children, ret_root, ret_parent;
1388 unsigned int ret_nchildren;
1389 gboolean send = FALSE;
1390 gboolean found = FALSE;
1391 gboolean result = FALSE;
1394 gdk_error_trap_push ();
1396 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
1397 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
1398 0, 0, False, AnyPropertyType,
1399 &type, &format, &nitems, &after, &data) != Success)
1409 /* OK, we're all set, now let's find some windows to send this to */
1410 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
1411 &ret_root, &ret_parent,
1412 &ret_children, &ret_nchildren))
1415 for(i = 0; i < ret_nchildren; i++)
1416 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
1419 XFree (ret_children);
1422 if (send || (!found && (level == 1)))
1424 xev->xclient.window = xid;
1425 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
1428 result = send || found;
1431 gdk_error_trap_pop_ignored ();
1437 * gdk_screen_broadcast_client_message:
1438 * @screen: the #GdkScreen where the event will be broadcasted.
1439 * @event: the #GdkEvent.
1441 * On X11, sends an X ClientMessage event to all toplevel windows on
1444 * Toplevel windows are determined by checking for the WM_STATE property,
1445 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
1446 * If no windows are found with the WM_STATE property set, the message is
1447 * sent to all children of the root window.
1449 * On Windows, broadcasts a message registered with the name
1450 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
1451 * data is limited to one long, i.e. four bytes.
1457 gdk_screen_broadcast_client_message (GdkScreen *screen,
1461 GdkWindow *root_window;
1463 g_return_if_fail (event != NULL);
1465 root_window = gdk_screen_get_root_window (screen);
1467 /* Set up our event to send, with the exception of its target window */
1468 sev.xclient.type = ClientMessage;
1469 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
1470 sev.xclient.format = event->client.data_format;
1471 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1472 sev.xclient.message_type =
1473 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
1474 event->client.message_type);
1476 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
1478 GDK_WINDOW_XID (root_window),
1483 check_transform (const gchar *xsettings_name,
1487 if (!g_value_type_transformable (src_type, dest_type))
1489 g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
1491 g_type_name (src_type),
1492 g_type_name (dest_type));
1500 * gdk_screen_get_setting:
1501 * @screen: the #GdkScreen where the setting is located
1502 * @name: the name of the setting
1503 * @value: location to store the value of the setting
1505 * Retrieves a desktop-wide setting such as double-click time
1506 * for the #GdkScreen @screen.
1508 * FIXME needs a list of valid settings here, or a link to
1511 * Returns: %TRUE if the setting existed and a value was stored
1512 * in @value, %FALSE otherwise.
1517 gdk_screen_get_setting (GdkScreen *screen,
1522 const char *xsettings_name = NULL;
1523 XSettingsResult result;
1524 XSettingsSetting *setting = NULL;
1525 GdkScreenX11 *screen_x11;
1526 gboolean success = FALSE;
1528 GValue tmp_val = { 0, };
1530 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1532 screen_x11 = GDK_SCREEN_X11 (screen);
1534 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS(); i++)
1535 if (strcmp (GDK_SETTINGS_GDK_NAME (i), name) == 0)
1537 xsettings_name = GDK_SETTINGS_X_NAME (i);
1541 if (!xsettings_name)
1544 result = xsettings_client_get_setting (screen_x11->xsettings_client,
1545 xsettings_name, &setting);
1546 if (result != XSETTINGS_SUCCESS)
1549 switch (setting->type)
1551 case XSETTINGS_TYPE_INT:
1552 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
1554 g_value_init (&tmp_val, G_TYPE_INT);
1555 g_value_set_int (&tmp_val, setting->data.v_int);
1556 g_value_transform (&tmp_val, value);
1561 case XSETTINGS_TYPE_STRING:
1562 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
1564 g_value_init (&tmp_val, G_TYPE_STRING);
1565 g_value_set_string (&tmp_val, setting->data.v_string);
1566 g_value_transform (&tmp_val, value);
1571 case XSETTINGS_TYPE_COLOR:
1572 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
1576 g_value_init (&tmp_val, GDK_TYPE_COLOR);
1579 color.red = setting->data.v_color.red;
1580 color.green = setting->data.v_color.green;
1581 color.blue = setting->data.v_color.blue;
1583 g_value_set_boxed (&tmp_val, &color);
1585 g_value_transform (&tmp_val, value);
1592 g_value_unset (&tmp_val);
1596 xsettings_setting_free (setting);
1601 return _gdk_x11_get_xft_setting (screen, name, value);
1605 cleanup_atoms(gpointer data)
1607 NetWmSupportedAtoms *supported_atoms = data;
1608 if (supported_atoms->atoms)
1609 XFree (supported_atoms->atoms);
1610 g_free (supported_atoms);
1614 fetch_net_wm_check_window (GdkScreen *screen)
1616 GdkScreenX11 *screen_x11;
1617 GdkDisplay *display;
1627 screen_x11 = GDK_SCREEN_X11 (screen);
1628 display = screen_x11->display;
1630 g_return_if_fail (GDK_DISPLAY_X11 (display)->trusted_client);
1632 g_get_current_time (&tv);
1634 if (ABS (tv.tv_sec - screen_x11->last_wmspec_check_time) < 15)
1635 return; /* we've checked recently */
1637 screen_x11->last_wmspec_check_time = tv.tv_sec;
1640 XGetWindowProperty (screen_x11->xdisplay, screen_x11->xroot_window,
1641 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
1642 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
1643 &n_items, &bytes_after, &data);
1645 if (type != XA_WINDOW)
1652 xwindow = (Window *)data;
1654 if (screen_x11->wmspec_check_window == *xwindow)
1660 gdk_error_trap_push ();
1662 /* Find out if this WM goes away, so we can reset everything. */
1663 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
1665 error = gdk_error_trap_pop ();
1668 screen_x11->wmspec_check_window = *xwindow;
1669 screen_x11->need_refetch_net_supported = TRUE;
1670 screen_x11->need_refetch_wm_name = TRUE;
1672 /* Careful, reentrancy */
1673 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
1675 else if (error == BadWindow)
1677 /* Leftover property, try again immediately, new wm may be starting up */
1678 screen_x11->last_wmspec_check_time = 0;
1685 * gdk_x11_screen_supports_net_wm_hint:
1686 * @screen: the relevant #GdkScreen.
1687 * @property: a property atom.
1689 * This function is specific to the X11 backend of GDK, and indicates
1690 * whether the window manager supports a certain hint from the
1691 * Extended Window Manager Hints Specification. You can find this
1693 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
1695 * When using this function, keep in mind that the window manager
1696 * can change over time; so you shouldn't use this function in
1697 * a way that impacts persistent application state. A common bug
1698 * is that your application can start up before the window manager
1699 * does when the user logs in, and before the window manager starts
1700 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
1701 * You can monitor the window_manager_changed signal on #GdkScreen to detect
1702 * a window manager change.
1704 * Return value: %TRUE if the window manager supports @property
1709 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
1713 GdkScreenX11 *screen_x11;
1714 NetWmSupportedAtoms *supported_atoms;
1715 GdkDisplay *display;
1717 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
1719 screen_x11 = GDK_SCREEN_X11 (screen);
1720 display = screen_x11->display;
1722 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
1725 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
1726 if (!supported_atoms)
1728 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
1729 g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms);
1732 fetch_net_wm_check_window (screen);
1734 if (screen_x11->wmspec_check_window == None)
1737 if (screen_x11->need_refetch_net_supported)
1739 /* WM has changed since we last got the supported list,
1746 screen_x11->need_refetch_net_supported = FALSE;
1748 if (supported_atoms->atoms)
1749 XFree (supported_atoms->atoms);
1751 supported_atoms->atoms = NULL;
1752 supported_atoms->n_atoms = 0;
1754 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
1755 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
1756 0, G_MAXLONG, False, XA_ATOM, &type, &format,
1757 &supported_atoms->n_atoms, &bytes_after,
1758 (guchar **)&supported_atoms->atoms);
1760 if (type != XA_ATOM)
1764 if (supported_atoms->atoms == NULL)
1768 while (i < supported_atoms->n_atoms)
1770 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
1780 * gdk_net_wm_supports:
1781 * @property: a property atom.
1783 * This function is specific to the X11 backend of GDK, and indicates
1784 * whether the window manager for the default screen supports a certain
1785 * hint from the Extended Window Manager Hints Specification. See
1786 * gdk_x11_screen_supports_net_wm_hint() for complete details.
1788 * Return value: %TRUE if the window manager supports @property
1791 gdk_net_wm_supports (GdkAtom property)
1793 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
1797 refcounted_grab_server (Display *xdisplay)
1799 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
1801 gdk_x11_display_grab (display);
1805 refcounted_ungrab_server (Display *xdisplay)
1807 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
1809 gdk_x11_display_ungrab (display);
1812 static GdkFilterReturn
1813 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
1817 GdkScreenX11 *screen = data;
1819 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
1820 return GDK_FILTER_REMOVE;
1822 return GDK_FILTER_CONTINUE;
1826 gdk_xsettings_watch_cb (Window window,
1832 GdkScreen *screen = cb_data;
1834 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
1839 g_object_ref (gdkwin);
1842 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
1844 /* gdk_window_foreign_new_for_display() can fail and return NULL if the
1845 * window has already been destroyed.
1851 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
1857 /* gdkwin should not be NULL here, since if starting the watch succeeded
1858 * we have a reference on the window. It might mean that the caller didn't
1859 * remove the watch when it got a DestroyNotify event. Or maybe the
1860 * caller ignored the return value when starting the watch failed.
1862 g_warning ("gdk_xsettings_watch_cb(): Couldn't find window to unwatch");
1866 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
1867 g_object_unref (gdkwin);
1874 gdk_xsettings_notify_cb (const char *name,
1875 XSettingsAction action,
1876 XSettingsSetting *setting,
1880 GdkScreen *screen = data;
1881 GdkScreenX11 *screen_x11 = data;
1884 if (screen_x11->xsettings_in_init)
1887 new_event.type = GDK_SETTING;
1888 new_event.setting.window = gdk_screen_get_root_window (screen);
1889 new_event.setting.send_event = FALSE;
1890 new_event.setting.name = NULL;
1892 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS() ; i++)
1893 if (strcmp (GDK_SETTINGS_X_NAME (i), name) == 0)
1895 new_event.setting.name = (char*) GDK_SETTINGS_GDK_NAME (i);
1899 if (!new_event.setting.name)
1904 case XSETTINGS_ACTION_NEW:
1905 new_event.setting.action = GDK_SETTING_ACTION_NEW;
1907 case XSETTINGS_ACTION_CHANGED:
1908 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
1910 case XSETTINGS_ACTION_DELETED:
1911 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
1915 gdk_event_put (&new_event);
1919 _gdk_screen_x11_events_init (GdkScreen *screen)
1921 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
1923 /* Keep a flag to avoid extra notifies that we don't need
1925 screen_x11->xsettings_in_init = TRUE;
1926 screen_x11->xsettings_client = xsettings_client_new_with_grab_funcs (screen_x11->xdisplay,
1927 screen_x11->screen_num,
1928 gdk_xsettings_notify_cb,
1929 gdk_xsettings_watch_cb,
1931 refcounted_grab_server,
1932 refcounted_ungrab_server);
1933 screen_x11->xsettings_in_init = FALSE;
1937 * gdk_x11_screen_get_window_manager_name:
1938 * @screen: a #GdkScreen
1940 * Returns the name of the window manager for @screen.
1942 * Return value: the name of the window manager screen @screen, or
1943 * "unknown" if the window manager is unknown. The string is owned by GDK
1944 * and should not be freed.
1949 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
1951 GdkScreenX11 *screen_x11;
1953 screen_x11 = GDK_SCREEN_X11 (screen);
1955 if (!G_LIKELY (GDK_DISPLAY_X11 (screen_x11->display)->trusted_client))
1956 return screen_x11->window_manager_name;
1958 fetch_net_wm_check_window (screen);
1960 if (screen_x11->need_refetch_wm_name)
1962 /* Get the name of the window manager */
1963 screen_x11->need_refetch_wm_name = FALSE;
1965 g_free (screen_x11->window_manager_name);
1966 screen_x11->window_manager_name = g_strdup ("unknown");
1968 if (screen_x11->wmspec_check_window != None)
1978 gdk_error_trap_push ();
1980 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
1981 screen_x11->wmspec_check_window,
1982 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1984 0, G_MAXLONG, False,
1985 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
1988 &n_items, &bytes_after,
1991 gdk_error_trap_pop_ignored ();
1995 g_free (screen_x11->window_manager_name);
1996 screen_x11->window_manager_name = g_strdup (name);
2002 return GDK_SCREEN_X11 (screen)->window_manager_name;