1 /* GDK - The GIMP Drawing Kit
4 * Copyright 2001 Sun Microsystems Inc.
5 * Copyright (C) 2004 Nokia Corporation
7 * Erwann Chenede <erwann.chenede@sun.com>
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Library General Public
11 * License as published by the Free Software Foundation; either
12 * version 2 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Library General Public License for more details.
19 * You should have received a copy of the GNU Library General Public
20 * License along with this library; if not, write to the
21 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 * Boston, MA 02111-1307, USA.
34 #include "gdkdisplay.h"
35 #include "gdkdisplay-x11.h"
36 #include "gdkscreen.h"
37 #include "gdkscreen-x11.h"
38 #include "gdkinternals.h"
39 #include "gdkinputprivate.h"
40 #include "xsettings-client.h"
43 #include <X11/Xatom.h>
46 #include <X11/XKBlib.h>
50 #include <X11/extensions/Xfixes.h>
54 #include <X11/extensions/shape.h>
57 #ifdef HAVE_XCOMPOSITE
58 #include <X11/extensions/Xcomposite.h>
62 #include <X11/extensions/Xdamage.h>
66 #include <X11/extensions/Xrandr.h>
70 static void gdk_display_x11_dispose (GObject *object);
71 static void gdk_display_x11_finalize (GObject *object);
74 static void gdk_internal_connection_watch (Display *display,
78 XPointer *watch_data);
79 #endif /* HAVE_X11R6 */
81 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
82 * but including them here has the side-effect of getting them
83 * into the internal Xlib cache
85 static const char *const precache_atoms[] = {
96 "_NET_CURRENT_DESKTOP",
107 "_NET_WM_STATE_ABOVE",
108 "_NET_WM_STATE_BELOW",
109 "_NET_WM_STATE_FULLSCREEN",
110 "_NET_WM_STATE_MODAL",
111 "_NET_WM_STATE_MAXIMIZED_VERT",
112 "_NET_WM_STATE_MAXIMIZED_HORZ",
113 "_NET_WM_STATE_SKIP_TASKBAR",
114 "_NET_WM_STATE_SKIP_PAGER",
115 "_NET_WM_STATE_STICKY",
116 "_NET_WM_SYNC_REQUEST",
117 "_NET_WM_SYNC_REQUEST_COUNTER",
118 "_NET_WM_WINDOW_TYPE",
119 "_NET_WM_WINDOW_TYPE_NORMAL",
124 G_DEFINE_TYPE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY)
127 _gdk_display_x11_class_init (GdkDisplayX11Class * class)
129 GObjectClass *object_class = G_OBJECT_CLASS (class);
131 object_class->dispose = gdk_display_x11_dispose;
132 object_class->finalize = gdk_display_x11_finalize;
136 _gdk_display_x11_init (GdkDisplayX11 *display)
142 * @display_name: the name of the display to open
143 * @returns: a #GdkDisplay, or %NULL if the display
144 * could not be opened.
151 gdk_display_open (const gchar *display_name)
155 GdkDisplayX11 *display_x11;
159 const char *sm_client_id;
161 XClassHint *class_hint;
164 #if defined(HAVE_XFIXES) || defined(HAVE_SHAPE_EXT)
169 xdisplay = XOpenDisplay (display_name);
173 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
174 display_x11 = GDK_DISPLAY_X11 (display);
176 display_x11->use_xshm = TRUE;
177 display_x11->xdisplay = xdisplay;
180 /* Set up handlers for Xlib internal connections */
181 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
182 #endif /* HAVE_X11R6 */
184 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
186 /* RandR must be initialized before we initialize the screens */
187 display_x11->have_randr13 = FALSE;
189 if (XRRQueryExtension (display_x11->xdisplay,
190 &display_x11->xrandr_event_base, &ignore))
194 XRRQueryVersion (display_x11->xdisplay, &major, &minor);
196 if ((major == 1 && minor >= 3) || major > 1)
197 display_x11->have_randr13 = TRUE;
199 gdk_x11_register_standard_event_type (display, display_x11->xrandr_event_base, RRNumberEvents);
203 /* initialize the display's screens */
204 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
205 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
206 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
208 /* We need to initialize events after we have the screen
209 * structures in places
211 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
212 _gdk_x11_events_init_screen (display_x11->screens[i]);
214 /*set the default screen */
215 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
217 attr.window_type = GDK_WINDOW_TOPLEVEL;
218 attr.wclass = GDK_INPUT_OUTPUT;
225 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
226 &attr, GDK_WA_X | GDK_WA_Y);
227 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
229 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
231 display_x11->leader_window_title_set = FALSE;
233 display_x11->have_render = GDK_UNKNOWN;
236 if (XFixesQueryExtension (display_x11->xdisplay,
237 &display_x11->xfixes_event_base,
240 display_x11->have_xfixes = TRUE;
242 gdk_x11_register_standard_event_type (display,
243 display_x11->xfixes_event_base,
248 display_x11->have_xfixes = FALSE;
250 #ifdef HAVE_XCOMPOSITE
251 if (XCompositeQueryExtension (display_x11->xdisplay,
256 XCompositeQueryVersion (display_x11->xdisplay, &major, &minor);
258 /* Prior to Composite version 0.4, composited windows clipped their
259 * parents, so you had to use IncludeInferiors to draw to the parent
260 * This isn't useful for our purposes, so require 0.4
262 display_x11->have_xcomposite = major > 0 || (major == 0 && minor >= 4);
266 display_x11->have_xcomposite = FALSE;
269 if (XDamageQueryExtension (display_x11->xdisplay,
270 &display_x11->xdamage_event_base,
273 display_x11->have_xdamage = TRUE;
275 gdk_x11_register_standard_event_type (display,
276 display_x11->xdamage_event_base,
277 XDamageNumberEvents);
281 display_x11->have_xdamage = FALSE;
283 display_x11->have_shapes = FALSE;
284 display_x11->have_input_shapes = FALSE;
285 #ifdef HAVE_SHAPE_EXT
286 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &ignore, &ignore))
288 display_x11->have_shapes = TRUE;
290 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
291 display_x11->have_input_shapes = (maj == 1 && min >= 1);
296 display_x11->trusted_client = TRUE;
299 int rootx, rooty, winx, winy;
302 gdk_error_trap_push ();
303 XQueryPointer (display_x11->xdisplay,
304 GDK_SCREEN_X11 (display_x11->default_screen)->xroot_window,
305 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
307 if (G_UNLIKELY (gdk_error_trap_pop () == BadWindow))
309 g_warning ("Connection to display %s appears to be untrusted. Pointer and keyboard grabs and inter-client communication may not work as expected.", gdk_display_get_name (display));
310 display_x11->trusted_client = FALSE;
314 if (_gdk_synchronize)
315 XSynchronize (display_x11->xdisplay, True);
317 class_hint = XAllocClassHint();
318 class_hint->res_name = g_get_prgname ();
320 class_hint->res_class = (char *)gdk_get_program_class ();
322 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
323 * from argv[0], so we just synthesize an argument array here.
326 argv[0] = g_get_prgname ();
328 XmbSetWMProperties (display_x11->xdisplay,
329 display_x11->leader_window,
330 NULL, NULL, argv, argc, NULL, NULL,
334 sm_client_id = _gdk_get_sm_client_id ();
336 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
339 XChangeProperty (display_x11->xdisplay,
340 display_x11->leader_window,
341 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
342 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
344 /* We don't yet know a valid time. */
345 display_x11->user_time = 0;
349 gint xkb_major = XkbMajorVersion;
350 gint xkb_minor = XkbMinorVersion;
351 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
353 xkb_major = XkbMajorVersion;
354 xkb_minor = XkbMinorVersion;
356 if (XkbQueryExtension (display_x11->xdisplay,
357 NULL, &display_x11->xkb_event_type, NULL,
358 &xkb_major, &xkb_minor))
360 Bool detectable_autorepeat_supported;
362 display_x11->use_xkb = TRUE;
364 XkbSelectEvents (display_x11->xdisplay,
366 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
367 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
369 /* keep this in sync with _gdk_keymap_state_changed() */
370 XkbSelectEventDetails (display_x11->xdisplay,
371 XkbUseCoreKbd, XkbStateNotify,
372 XkbAllStateComponentsMask,
373 XkbGroupLockMask|XkbModifierLockMask);
375 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
377 &detectable_autorepeat_supported);
379 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
380 detectable_autorepeat_supported ?
381 "supported" : "not supported"));
383 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
389 display_x11->use_sync = FALSE;
393 int error_base, event_base;
395 if (XSyncQueryExtension (display_x11->xdisplay,
396 &event_base, &error_base) &&
397 XSyncInitialize (display_x11->xdisplay,
399 display_x11->use_sync = TRUE;
403 _gdk_windowing_image_init (display);
404 _gdk_events_init (display);
405 _gdk_input_init (display);
406 _gdk_dnd_init (display);
408 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
409 gdk_display_request_selection_notification (display,
410 GDK_SCREEN_X11 (display_x11->screens[i])->cm_selection_atom);
412 g_signal_emit_by_name (gdk_display_manager_get(),
413 "display_opened", display);
420 * XLib internal connection handling
422 typedef struct _GdkInternalConnection GdkInternalConnection;
424 struct _GdkInternalConnection
432 process_internal_connection (GIOChannel *gioc,
436 GdkInternalConnection *connection = (GdkInternalConnection *)data;
438 GDK_THREADS_ENTER ();
440 XProcessInternalConnection ((Display*)connection->display, connection->fd);
442 GDK_THREADS_LEAVE ();
447 static GdkInternalConnection *
448 gdk_add_connection_handler (Display *display,
451 GIOChannel *io_channel;
452 GdkInternalConnection *connection;
454 connection = g_new (GdkInternalConnection, 1);
457 connection->display = display;
459 io_channel = g_io_channel_unix_new (fd);
461 connection->source = g_io_create_watch (io_channel, G_IO_IN);
462 g_source_set_callback (connection->source,
463 (GSourceFunc)process_internal_connection, connection, NULL);
464 g_source_attach (connection->source, NULL);
466 g_io_channel_unref (io_channel);
472 gdk_remove_connection_handler (GdkInternalConnection *connection)
474 g_source_destroy (connection->source);
479 gdk_internal_connection_watch (Display *display,
483 XPointer *watch_data)
486 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
488 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
490 #endif /* HAVE_X11R6 */
493 * gdk_display_get_name:
494 * @display: a #GdkDisplay
496 * Gets the name of the display.
498 * Returns: a string representing the display name. This string is owned
499 * by GDK and should not be modified or freed.
503 G_CONST_RETURN gchar *
504 gdk_display_get_name (GdkDisplay *display)
506 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
508 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
512 * gdk_display_get_n_screens:
513 * @display: a #GdkDisplay
515 * Gets the number of screen managed by the @display.
517 * Returns: number of screens.
522 gdk_display_get_n_screens (GdkDisplay *display)
524 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
526 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
530 * gdk_display_get_screen:
531 * @display: a #GdkDisplay
532 * @screen_num: the screen number
534 * Returns a screen object for one of the screens of the display.
536 * Returns: the #GdkScreen object
541 gdk_display_get_screen (GdkDisplay *display,
544 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
545 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
547 return GDK_DISPLAY_X11 (display)->screens[screen_num];
551 * gdk_display_get_default_screen:
552 * @display: a #GdkDisplay
554 * Get the default #GdkScreen for @display.
556 * Returns: the default #GdkScreen object for @display
561 gdk_display_get_default_screen (GdkDisplay *display)
563 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
565 return GDK_DISPLAY_X11 (display)->default_screen;
569 _gdk_x11_display_is_root_window (GdkDisplay *display,
572 GdkDisplayX11 *display_x11;
575 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
577 display_x11 = GDK_DISPLAY_X11 (display);
579 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
581 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
587 #define XSERVER_TIME_IS_LATER(time1, time2) \
588 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
589 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
593 * gdk_display_pointer_ungrab:
594 * @display: a #GdkDisplay.
595 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
597 * Release any pointer grab.
602 gdk_display_pointer_ungrab (GdkDisplay *display,
606 GdkDisplayX11 *display_x11;
608 g_return_if_fail (GDK_IS_DISPLAY (display));
610 display_x11 = GDK_DISPLAY_X11 (display);
611 xdisplay = GDK_DISPLAY_XDISPLAY (display);
613 _gdk_input_ungrab_pointer (display, time);
614 XUngrabPointer (xdisplay, time);
617 if (time == GDK_CURRENT_TIME ||
618 display_x11->pointer_xgrab_time == GDK_CURRENT_TIME ||
619 !XSERVER_TIME_IS_LATER (display_x11->pointer_xgrab_time, time))
620 display_x11->pointer_xgrab_window = NULL;
624 * gdk_display_pointer_is_grabbed:
625 * @display: a #GdkDisplay
627 * Test if the pointer is grabbed.
629 * Returns: %TRUE if an active X pointer grab is in effect
634 gdk_display_pointer_is_grabbed (GdkDisplay *display)
636 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
638 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL &&
639 !GDK_DISPLAY_X11 (display)->pointer_xgrab_implicit);
643 * gdk_display_keyboard_ungrab:
644 * @display: a #GdkDisplay.
645 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
647 * Release any keyboard grab
652 gdk_display_keyboard_ungrab (GdkDisplay *display,
656 GdkDisplayX11 *display_x11;
658 g_return_if_fail (GDK_IS_DISPLAY (display));
660 display_x11 = GDK_DISPLAY_X11 (display);
661 xdisplay = GDK_DISPLAY_XDISPLAY (display);
663 XUngrabKeyboard (xdisplay, time);
666 if (time == GDK_CURRENT_TIME ||
667 display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
668 !XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
669 display_x11->keyboard_xgrab_window = NULL;
674 * @display: a #GdkDisplay
676 * Emits a short beep on @display
681 gdk_display_beep (GdkDisplay *display)
683 g_return_if_fail (GDK_IS_DISPLAY (display));
685 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
690 * @display: a #GdkDisplay
692 * Flushes any requests queued for the windowing system and waits until all
693 * requests have been handled. This is often used for making sure that the
694 * display is synchronized with the current state of the program. Calling
695 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
696 * generated from earlier requests are handled before the error trap is
699 * This is most useful for X11. On windowing systems where requests are
700 * handled synchronously, this function will do nothing.
705 gdk_display_sync (GdkDisplay *display)
707 g_return_if_fail (GDK_IS_DISPLAY (display));
709 XSync (GDK_DISPLAY_XDISPLAY (display), False);
714 * @display: a #GdkDisplay
716 * Flushes any requests queued for the windowing system; this happens automatically
717 * when the main loop blocks waiting for new events, but if your application
718 * is drawing without returning control to the main loop, you may need
719 * to call this function explicitely. A common case where this function
720 * needs to be called is when an application is executing drawing commands
721 * from a thread other than the thread where the main loop is running.
723 * This is most useful for X11. On windowing systems where requests are
724 * handled synchronously, this function will do nothing.
729 gdk_display_flush (GdkDisplay *display)
731 g_return_if_fail (GDK_IS_DISPLAY (display));
733 if (!display->closed)
734 XFlush (GDK_DISPLAY_XDISPLAY (display));
738 * gdk_display_get_default_group:
739 * @display: a #GdkDisplay
741 * Returns the default group leader window for all toplevel windows
742 * on @display. This window is implicitly created by GDK.
743 * See gdk_window_set_group().
745 * Return value: The default group leader window for @display
750 gdk_display_get_default_group (GdkDisplay *display)
752 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
754 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
758 * gdk_x11_display_grab:
759 * @display: a #GdkDisplay
761 * Call XGrabServer() on @display.
762 * To ungrab the display again, use gdk_x11_display_ungrab().
764 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
769 gdk_x11_display_grab (GdkDisplay *display)
771 GdkDisplayX11 *display_x11;
773 g_return_if_fail (GDK_IS_DISPLAY (display));
775 display_x11 = GDK_DISPLAY_X11 (display);
777 if (display_x11->grab_count == 0)
778 XGrabServer (display_x11->xdisplay);
779 display_x11->grab_count++;
783 * gdk_x11_display_ungrab:
784 * @display: a #GdkDisplay
786 * Ungrab @display after it has been grabbed with
787 * gdk_x11_display_grab().
792 gdk_x11_display_ungrab (GdkDisplay *display)
794 GdkDisplayX11 *display_x11;
796 g_return_if_fail (GDK_IS_DISPLAY (display));
798 display_x11 = GDK_DISPLAY_X11 (display);;
799 g_return_if_fail (display_x11->grab_count > 0);
801 display_x11->grab_count--;
802 if (display_x11->grab_count == 0)
804 XUngrabServer (display_x11->xdisplay);
805 XFlush (display_x11->xdisplay);
810 gdk_display_x11_dispose (GObject *object)
812 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
815 g_list_foreach (display_x11->input_devices, (GFunc) g_object_run_dispose, NULL);
817 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
818 _gdk_screen_close (display_x11->screens[i]);
820 _gdk_events_uninit (GDK_DISPLAY_OBJECT (object));
822 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
826 gdk_display_x11_finalize (GObject *object)
828 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
832 if (display_x11->keymap)
833 g_object_unref (display_x11->keymap);
836 if (display_x11->motif_target_lists)
838 for (i = 0; i < display_x11->motif_n_target_lists; i++)
839 g_list_free (display_x11->motif_target_lists[i]);
840 g_free (display_x11->motif_target_lists);
843 _gdk_x11_cursor_display_finalize (GDK_DISPLAY_OBJECT(display_x11));
846 g_hash_table_destroy (display_x11->atom_from_virtual);
847 g_hash_table_destroy (display_x11->atom_to_virtual);
850 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
852 /* list of filters for client messages */
853 g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
854 g_list_free (display_x11->client_filters);
856 /* List of event window extraction functions */
857 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
858 g_slist_free (display_x11->event_types);
860 /* input GdkDevice list */
861 g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
862 g_list_free (display_x11->input_devices);
864 /* input GdkWindow list */
865 g_list_foreach (display_x11->input_windows, (GFunc) g_free, NULL);
866 g_list_free (display_x11->input_windows);
868 /* Free all GdkScreens */
869 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
870 g_object_unref (display_x11->screens[i]);
871 g_free (display_x11->screens);
873 g_free (display_x11->startup_notification_id);
876 g_hash_table_destroy (display_x11->xid_ht);
878 XCloseDisplay (display_x11->xdisplay);
880 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
884 * gdk_x11_lookup_xdisplay:
885 * @xdisplay: a pointer to an X Display
887 * Find the #GdkDisplay corresponding to @display, if any exists.
889 * Return value: the #GdkDisplay, if found, otherwise %NULL.
894 gdk_x11_lookup_xdisplay (Display *xdisplay)
898 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
900 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
901 return tmp_list->data;
908 * _gdk_x11_display_screen_for_xrootwin:
909 * @display: a #GdkDisplay
910 * @xrootwin: window ID for one of of the screen's of the display.
912 * Given the root window ID of one of the screen's of a #GdkDisplay,
915 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
918 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
923 for (i = 0; i < ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay); i++)
925 GdkScreen *screen = gdk_display_get_screen (display, i);
926 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
934 * gdk_x11_display_get_xdisplay:
935 * @display: a #GdkDisplay
936 * @returns: an X display.
938 * Returns the X display of a #GdkDisplay.
943 gdk_x11_display_get_xdisplay (GdkDisplay *display)
945 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
946 return GDK_DISPLAY_X11 (display)->xdisplay;
950 _gdk_windowing_set_default_display (GdkDisplay *display)
952 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
953 const gchar *startup_id;
961 gdk_display = GDK_DISPLAY_XDISPLAY (display);
963 g_free (display_x11->startup_notification_id);
964 display_x11->startup_notification_id = NULL;
966 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
967 if (startup_id && *startup_id != '\0')
971 if (!g_utf8_validate (startup_id, -1, NULL))
972 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
974 display_x11->startup_notification_id = g_strdup (startup_id);
976 /* Find the launch time from the startup_id, if it's there. Newer spec
977 * states that the startup_id is of the form <unique>_TIME<timestamp>
979 time_str = g_strrstr (startup_id, "_TIME");
980 if (time_str != NULL)
986 /* Skip past the "_TIME" part */
989 retval = strtoul (time_str, &end, 0);
990 if (end != time_str && errno == 0)
991 display_x11->user_time = retval;
994 /* Clear the environment variable so it won't be inherited by
995 * child processes and confuse things.
997 g_unsetenv ("DESKTOP_STARTUP_ID");
999 /* Set the startup id on the leader window so it
1000 * applies to all windows we create on this display
1002 XChangeProperty (display_x11->xdisplay,
1003 display_x11->leader_window,
1004 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
1005 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
1007 (guchar *)startup_id, strlen (startup_id));
1012 broadcast_xmessage (GdkDisplay *display,
1013 const char *message_type,
1014 const char *message_type_begin,
1015 const char *message)
1017 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1018 GdkScreen *screen = gdk_display_get_default_screen (display);
1019 GdkWindow *root_window = gdk_screen_get_root_window (screen);
1020 Window xroot_window = GDK_WINDOW_XID (root_window);
1023 Atom type_atom_begin;
1026 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
1030 XSetWindowAttributes attrs;
1032 attrs.override_redirect = True;
1033 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
1036 XCreateWindow (xdisplay,
1042 (Visual *)CopyFromParent,
1043 CWOverrideRedirect | CWEventMask,
1047 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
1049 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
1050 message_type_begin);
1053 XClientMessageEvent xclient;
1055 const char *src_end;
1059 memset(&xclient, 0, sizeof (xclient));
1060 xclient.type = ClientMessage;
1061 xclient.message_type = type_atom_begin;
1062 xclient.display =xdisplay;
1063 xclient.window = xwindow;
1067 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
1069 while (src != src_end)
1071 dest = &xclient.data.b[0];
1072 dest_end = dest + 20;
1074 while (dest != dest_end &&
1082 while (dest != dest_end)
1088 XSendEvent (xdisplay,
1092 (XEvent *)&xclient);
1094 xclient.message_type = type_atom;
1098 XDestroyWindow (xdisplay, xwindow);
1103 * gdk_x11_display_broadcast_startup_message:
1104 * @display: a #GdkDisplay
1105 * @message_type: startup notification message type ("new", "change",
1107 * @...: a list of key/value pairs (as strings), terminated by a
1108 * %NULL key. (A %NULL value for a key will cause that key to be
1109 * skipped in the output.)
1111 * Sends a startup notification message of type @message_type to
1114 * This is a convenience function for use by code that implements the
1115 * freedesktop startup notification specification. Applications should
1116 * not normally need to call it directly. See the <ulink
1117 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
1118 * Notification Protocol specification</ulink> for
1119 * definitions of the message types and keys that can be used.
1124 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
1125 const char *message_type,
1130 const char *key, *value, *p;
1132 message = g_string_new (message_type);
1133 g_string_append_c (message, ':');
1135 va_start (ap, message_type);
1136 while ((key = va_arg (ap, const char *)))
1138 value = va_arg (ap, const char *);
1142 g_string_append_printf (message, " %s=\"", key);
1143 for (p = value; *p; p++)
1150 g_string_append_c (message, '\\');
1154 g_string_append_c (message, *p);
1156 g_string_append_c (message, '\"');
1160 broadcast_xmessage (display,
1161 "_NET_STARTUP_INFO",
1162 "_NET_STARTUP_INFO_BEGIN",
1165 g_string_free (message, TRUE);
1169 * gdk_notify_startup_complete:
1171 * Indicates to the GUI environment that the application has finished
1172 * loading. If the applications opens windows, this function is
1173 * normally called after opening the application's initial set of
1176 * GTK+ will call this function automatically after opening the first
1177 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1178 * to disable that feature.
1183 gdk_notify_startup_complete (void)
1185 GdkDisplay *display;
1186 GdkDisplayX11 *display_x11;
1188 display = gdk_display_get_default ();
1192 display_x11 = GDK_DISPLAY_X11 (display);
1194 if (display_x11->startup_notification_id == NULL)
1197 gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
1201 * gdk_notify_startup_complete_with_id:
1202 * @startup_id: a startup-notification identifier, for which notification
1203 * process should be completed
1205 * Indicates to the GUI environment that the application has finished
1206 * loading, using a given identifier.
1208 * GTK+ will call this function automatically for #GtkWindow with custom
1209 * startup-notification identifier unless
1210 * gtk_window_set_auto_startup_notification() is called to disable
1216 gdk_notify_startup_complete_with_id (const gchar* startup_id)
1218 GdkDisplay *display;
1220 display = gdk_display_get_default ();
1224 gdk_x11_display_broadcast_startup_message (display, "remove",
1230 * gdk_display_supports_selection_notification:
1231 * @display: a #GdkDisplay
1233 * Returns whether #GdkEventOwnerChange events will be
1234 * sent when the owner of a selection changes.
1236 * Return value: whether #GdkEventOwnerChange events will
1242 gdk_display_supports_selection_notification (GdkDisplay *display)
1244 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1246 return display_x11->have_xfixes;
1250 * gdk_display_request_selection_notification:
1251 * @display: a #GdkDisplay
1252 * @selection: the #GdkAtom naming the selection for which
1253 * ownership change notification is requested
1255 * Request #GdkEventOwnerChange events for ownership changes
1256 * of the selection named by the given atom.
1258 * Return value: whether #GdkEventOwnerChange events will
1264 gdk_display_request_selection_notification (GdkDisplay *display,
1269 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1272 if (display_x11->have_xfixes)
1274 atom = gdk_x11_atom_to_xatom_for_display (display,
1276 XFixesSelectSelectionInput (display_x11->xdisplay,
1277 display_x11->leader_window,
1279 XFixesSetSelectionOwnerNotifyMask |
1280 XFixesSelectionWindowDestroyNotifyMask |
1281 XFixesSelectionClientCloseNotifyMask);
1290 * gdk_display_supports_clipboard_persistence
1291 * @display: a #GdkDisplay
1293 * Returns whether the speicifed display supports clipboard
1294 * persistance; i.e. if it's possible to store the clipboard data after an
1295 * application has quit. On X11 this checks if a clipboard daemon is
1298 * Returns: %TRUE if the display supports clipboard persistance.
1303 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1305 Atom clipboard_manager;
1307 /* It might make sense to cache this */
1308 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1309 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay, clipboard_manager) != None;
1313 * gdk_display_store_clipboard
1314 * @display: a #GdkDisplay
1315 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1316 * @time_: a timestamp
1317 * @targets: an array of targets that should be saved, or %NULL
1318 * if all available targets should be saved.
1319 * @n_targets: length of the @targets array
1321 * Issues a request to the clipboard manager to store the
1322 * clipboard data. On X11, this is a special program that works
1323 * according to the freedesktop clipboard specification, available at
1324 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1325 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1330 gdk_display_store_clipboard (GdkDisplay *display,
1331 GdkWindow *clipboard_window,
1333 const GdkAtom *targets,
1336 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1337 Atom clipboard_manager, save_targets;
1339 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1340 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1342 gdk_error_trap_push ();
1344 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1346 Atom property_name = None;
1352 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1354 xatoms = g_new (Atom, n_targets);
1355 for (i = 0; i < n_targets; i++)
1356 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1358 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1359 property_name, XA_ATOM,
1360 32, PropModeReplace, (guchar *)xatoms, n_targets);
1365 XConvertSelection (display_x11->xdisplay,
1366 clipboard_manager, save_targets, property_name,
1367 GDK_WINDOW_XID (clipboard_window), time_);
1370 gdk_error_trap_pop ();
1375 * gdk_x11_display_get_user_time:
1376 * @display: a #GdkDisplay
1378 * Returns the timestamp of the last user interaction on
1379 * @display. The timestamp is taken from events caused
1380 * by user interaction such as key presses or pointer
1381 * movements. See gdk_x11_window_set_user_time().
1383 * Returns: the timestamp of the last user interaction
1388 gdk_x11_display_get_user_time (GdkDisplay *display)
1390 return GDK_DISPLAY_X11 (display)->user_time;
1394 * gdk_display_supports_shapes:
1395 * @display: a #GdkDisplay
1397 * Returns %TRUE if gdk_window_shape_combine_mask() can
1398 * be used to create shaped windows on @display.
1400 * Returns: %TRUE if shaped windows are supported
1405 gdk_display_supports_shapes (GdkDisplay *display)
1407 return GDK_DISPLAY_X11 (display)->have_shapes;
1411 * gdk_display_supports_input_shapes:
1412 * @display: a #GdkDisplay
1414 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1415 * be used to modify the input shape of windows on @display.
1417 * Returns: %TRUE if windows with modified input shape are supported
1422 gdk_display_supports_input_shapes (GdkDisplay *display)
1424 return GDK_DISPLAY_X11 (display)->have_input_shapes;
1429 * gdk_x11_display_get_startup_notification_id:
1430 * @display: a #GdkDisplay
1432 * Gets the startup notification ID for a display.
1434 * Returns: the startup notification ID for @display
1438 G_CONST_RETURN gchar *
1439 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
1441 return GDK_DISPLAY_X11 (display)->startup_notification_id;
1445 * gdk_display_supports_composite:
1446 * @display: a #GdkDisplay
1448 * Returns %TRUE if gdk_window_set_composited() can be used
1449 * to redirect drawing on the window using compositing.
1451 * Currently this only works on X11 with XComposite and
1452 * XDamage extensions available.
1454 * Returns: %TRUE if windows may be composited.
1459 gdk_display_supports_composite (GdkDisplay *display)
1461 GdkDisplayX11 *x11_display = GDK_DISPLAY_X11 (display);
1463 return x11_display->have_xcomposite &&
1464 x11_display->have_xdamage &&
1465 x11_display->have_xfixes;
1469 #define __GDK_DISPLAY_X11_C__
1470 #include "gdkaliasdef.c"