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 static void gdk_display_x11_dispose (GObject *object);
67 static void gdk_display_x11_finalize (GObject *object);
70 static void gdk_internal_connection_watch (Display *display,
74 XPointer *watch_data);
75 #endif /* HAVE_X11R6 */
77 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
78 * but including them here has the side-effect of getting them
79 * into the internal Xlib cache
81 static const char *const precache_atoms[] = {
96 "_NET_WM_STATE_STICKY",
97 "_NET_WM_STATE_MAXIMIZED_VERT",
98 "_NET_WM_STATE_MAXIMIZED_HORZ",
99 "_NET_WM_STATE_FULLSCREEN",
100 "_NET_WM_SYNC_REQUEST",
101 "_NET_WM_SYNC_REQUEST_COUNTER",
102 "_NET_WM_WINDOW_TYPE",
103 "_NET_WM_WINDOW_TYPE_NORMAL",
108 G_DEFINE_TYPE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY)
111 _gdk_display_x11_class_init (GdkDisplayX11Class * class)
113 GObjectClass *object_class = G_OBJECT_CLASS (class);
115 object_class->dispose = gdk_display_x11_dispose;
116 object_class->finalize = gdk_display_x11_finalize;
120 _gdk_display_x11_init (GdkDisplayX11 *display)
126 * @display_name: the name of the display to open
127 * @returns: a #GdkDisplay, or %NULL if the display
128 * could not be opened.
135 gdk_display_open (const gchar *display_name)
139 GdkDisplayX11 *display_x11;
143 const char *sm_client_id;
145 XClassHint *class_hint;
148 #if defined(HAVE_XFIXES) || defined(HAVE_SHAPE_EXT)
153 xdisplay = XOpenDisplay (display_name);
157 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
158 display_x11 = GDK_DISPLAY_X11 (display);
160 display_x11->use_xshm = TRUE;
161 display_x11->xdisplay = xdisplay;
164 /* Set up handlers for Xlib internal connections */
165 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
166 #endif /* HAVE_X11R6 */
168 /* initialize the display's screens */
169 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
170 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
171 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
173 /* We need to initialize events after we have the screen
174 * structures in places
176 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
177 _gdk_x11_events_init_screen (display_x11->screens[i]);
179 /*set the default screen */
180 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
182 attr.window_type = GDK_WINDOW_TOPLEVEL;
183 attr.wclass = GDK_INPUT_OUTPUT;
190 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
192 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
193 &attr, GDK_WA_X | GDK_WA_Y);
194 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
196 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
198 display_x11->leader_window_title_set = FALSE;
200 display_x11->have_render = GDK_UNKNOWN;
203 if (XFixesQueryExtension (display_x11->xdisplay,
204 &display_x11->xfixes_event_base,
207 display_x11->have_xfixes = TRUE;
209 gdk_x11_register_standard_event_type (display,
210 display_x11->xfixes_event_base,
215 display_x11->have_xfixes = FALSE;
217 #ifdef HAVE_XCOMPOSITE
218 if (XCompositeQueryExtension (display_x11->xdisplay,
220 display_x11->have_xcomposite = TRUE;
223 display_x11->have_xcomposite = FALSE;
226 if (XDamageQueryExtension (display_x11->xdisplay,
227 &display_x11->xdamage_event_base,
230 display_x11->have_xdamage = TRUE;
232 gdk_x11_register_standard_event_type (display,
233 display_x11->xdamage_event_base,
234 XDamageNumberEvents);
238 display_x11->have_xdamage = FALSE;
240 display_x11->have_shapes = FALSE;
241 display_x11->have_input_shapes = FALSE;
242 #ifdef HAVE_SHAPE_EXT
243 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &ignore, &ignore))
245 display_x11->have_shapes = TRUE;
247 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
248 display_x11->have_input_shapes = (maj == 1 && min >= 1);
253 display_x11->trusted_client = TRUE;
256 int rootx, rooty, winx, winy;
259 gdk_error_trap_push ();
260 XQueryPointer (display_x11->xdisplay,
261 GDK_SCREEN_X11 (display_x11->default_screen)->xroot_window,
262 &root, &child, &rootx, &rooty, &winx, &winy, &xmask);
264 if (G_UNLIKELY (gdk_error_trap_pop () == BadWindow))
266 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));
267 display_x11->trusted_client = FALSE;
271 if (_gdk_synchronize)
272 XSynchronize (display_x11->xdisplay, True);
274 class_hint = XAllocClassHint();
275 class_hint->res_name = g_get_prgname ();
277 class_hint->res_class = (char *)gdk_get_program_class ();
279 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
280 * from argv[0], so we just synthesize an argument array here.
283 argv[0] = g_get_prgname ();
285 XmbSetWMProperties (display_x11->xdisplay,
286 display_x11->leader_window,
287 NULL, NULL, argv, argc, NULL, NULL,
291 sm_client_id = _gdk_get_sm_client_id ();
293 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
296 XChangeProperty (display_x11->xdisplay,
297 display_x11->leader_window,
298 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
299 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
301 /* We don't yet know a valid time. */
302 display_x11->user_time = 0;
306 gint xkb_major = XkbMajorVersion;
307 gint xkb_minor = XkbMinorVersion;
308 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
310 xkb_major = XkbMajorVersion;
311 xkb_minor = XkbMinorVersion;
313 if (XkbQueryExtension (display_x11->xdisplay,
314 NULL, &display_x11->xkb_event_type, NULL,
315 &xkb_major, &xkb_minor))
317 Bool detectable_autorepeat_supported;
319 display_x11->use_xkb = TRUE;
321 XkbSelectEvents (display_x11->xdisplay,
323 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
324 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
326 /* keep this in sync with _gdk_keymap_state_changed() */
327 XkbSelectEventDetails (display_x11->xdisplay,
328 XkbUseCoreKbd, XkbStateNotify,
329 XkbAllStateComponentsMask,
332 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
334 &detectable_autorepeat_supported);
336 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
337 detectable_autorepeat_supported ?
338 "supported" : "not supported"));
340 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
346 display_x11->use_sync = FALSE;
350 int error_base, event_base;
352 if (XSyncQueryExtension (display_x11->xdisplay,
353 &event_base, &error_base) &&
354 XSyncInitialize (display_x11->xdisplay,
356 display_x11->use_sync = TRUE;
360 _gdk_windowing_image_init (display);
361 _gdk_events_init (display);
362 _gdk_input_init (display);
363 _gdk_dnd_init (display);
365 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
366 gdk_display_request_selection_notification (display,
367 GDK_SCREEN_X11 (display_x11->screens[i])->cm_selection_atom);
369 g_signal_emit_by_name (gdk_display_manager_get(),
370 "display_opened", display);
377 * XLib internal connection handling
379 typedef struct _GdkInternalConnection GdkInternalConnection;
381 struct _GdkInternalConnection
389 process_internal_connection (GIOChannel *gioc,
393 GdkInternalConnection *connection = (GdkInternalConnection *)data;
395 GDK_THREADS_ENTER ();
397 XProcessInternalConnection ((Display*)connection->display, connection->fd);
399 GDK_THREADS_LEAVE ();
404 static GdkInternalConnection *
405 gdk_add_connection_handler (Display *display,
408 GIOChannel *io_channel;
409 GdkInternalConnection *connection;
411 connection = g_new (GdkInternalConnection, 1);
414 connection->display = display;
416 io_channel = g_io_channel_unix_new (fd);
418 connection->source = g_io_create_watch (io_channel, G_IO_IN);
419 g_source_set_callback (connection->source,
420 (GSourceFunc)process_internal_connection, connection, NULL);
421 g_source_attach (connection->source, NULL);
423 g_io_channel_unref (io_channel);
429 gdk_remove_connection_handler (GdkInternalConnection *connection)
431 g_source_destroy (connection->source);
436 gdk_internal_connection_watch (Display *display,
440 XPointer *watch_data)
443 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
445 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
447 #endif /* HAVE_X11R6 */
450 * gdk_display_get_name:
451 * @display: a #GdkDisplay
453 * Gets the name of the display.
455 * Returns: a string representing the display name. This string is owned
456 * by GDK and should not be modified or freed.
460 G_CONST_RETURN gchar *
461 gdk_display_get_name (GdkDisplay *display)
463 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
465 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
469 * gdk_display_get_n_screens:
470 * @display: a #GdkDisplay
472 * Gets the number of screen managed by the @display.
474 * Returns: number of screens.
479 gdk_display_get_n_screens (GdkDisplay *display)
481 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
483 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
487 * gdk_display_get_screen:
488 * @display: a #GdkDisplay
489 * @screen_num: the screen number
491 * Returns a screen object for one of the screens of the display.
493 * Returns: the #GdkScreen object
498 gdk_display_get_screen (GdkDisplay *display,
501 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
502 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
504 return GDK_DISPLAY_X11 (display)->screens[screen_num];
508 * gdk_display_get_default_screen:
509 * @display: a #GdkDisplay
511 * Get the default #GdkScreen for @display.
513 * Returns: the default #GdkScreen object for @display
518 gdk_display_get_default_screen (GdkDisplay *display)
520 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
522 return GDK_DISPLAY_X11 (display)->default_screen;
526 _gdk_x11_display_is_root_window (GdkDisplay *display,
529 GdkDisplayX11 *display_x11;
532 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
534 display_x11 = GDK_DISPLAY_X11 (display);
536 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
538 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
544 #define XSERVER_TIME_IS_LATER(time1, time2) \
545 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
546 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
550 * gdk_display_pointer_ungrab:
551 * @display: a #GdkDisplay.
552 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
554 * Release any pointer grab.
559 gdk_display_pointer_ungrab (GdkDisplay *display,
563 GdkDisplayX11 *display_x11;
565 g_return_if_fail (GDK_IS_DISPLAY (display));
567 display_x11 = GDK_DISPLAY_X11 (display);
568 xdisplay = GDK_DISPLAY_XDISPLAY (display);
570 _gdk_input_ungrab_pointer (display, time);
571 XUngrabPointer (xdisplay, time);
574 if (time == GDK_CURRENT_TIME ||
575 display_x11->pointer_xgrab_time == GDK_CURRENT_TIME ||
576 !XSERVER_TIME_IS_LATER (display_x11->pointer_xgrab_time, time))
577 display_x11->pointer_xgrab_window = NULL;
581 * gdk_display_pointer_is_grabbed:
582 * @display: a #GdkDisplay
584 * Test if the pointer is grabbed.
586 * Returns: %TRUE if an active X pointer grab is in effect
591 gdk_display_pointer_is_grabbed (GdkDisplay *display)
593 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
595 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL &&
596 !GDK_DISPLAY_X11 (display)->pointer_xgrab_implicit);
600 * gdk_display_keyboard_ungrab:
601 * @display: a #GdkDisplay.
602 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
604 * Release any keyboard grab
609 gdk_display_keyboard_ungrab (GdkDisplay *display,
613 GdkDisplayX11 *display_x11;
615 g_return_if_fail (GDK_IS_DISPLAY (display));
617 display_x11 = GDK_DISPLAY_X11 (display);
618 xdisplay = GDK_DISPLAY_XDISPLAY (display);
620 XUngrabKeyboard (xdisplay, time);
623 if (time == GDK_CURRENT_TIME ||
624 display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
625 !XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
626 display_x11->keyboard_xgrab_window = NULL;
631 * @display: a #GdkDisplay
633 * Emits a short beep on @display
638 gdk_display_beep (GdkDisplay *display)
640 g_return_if_fail (GDK_IS_DISPLAY (display));
642 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
647 * @display: a #GdkDisplay
649 * Flushes any requests queued for the windowing system and waits until all
650 * requests have been handled. This is often used for making sure that the
651 * display is synchronized with the current state of the program. Calling
652 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
653 * generated from earlier requests are handled before the error trap is
656 * This is most useful for X11. On windowing systems where requests are
657 * handled synchronously, this function will do nothing.
662 gdk_display_sync (GdkDisplay *display)
664 g_return_if_fail (GDK_IS_DISPLAY (display));
666 XSync (GDK_DISPLAY_XDISPLAY (display), False);
671 * @display: a #GdkDisplay
673 * Flushes any requests queued for the windowing system; this happens automatically
674 * when the main loop blocks waiting for new events, but if your application
675 * is drawing without returning control to the main loop, you may need
676 * to call this function explicitely. A common case where this function
677 * needs to be called is when an application is executing drawing commands
678 * from a thread other than the thread where the main loop is running.
680 * This is most useful for X11. On windowing systems where requests are
681 * handled synchronously, this function will do nothing.
686 gdk_display_flush (GdkDisplay *display)
688 g_return_if_fail (GDK_IS_DISPLAY (display));
690 if (!display->closed)
691 XFlush (GDK_DISPLAY_XDISPLAY (display));
695 * gdk_display_get_default_group:
696 * @display: a #GdkDisplay
698 * Returns the default group leader window for all toplevel windows
699 * on @display. This window is implicitly created by GDK.
700 * See gdk_window_set_group().
702 * Return value: The default group leader window for @display
707 gdk_display_get_default_group (GdkDisplay *display)
709 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
711 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
715 * gdk_x11_display_grab:
716 * @display: a #GdkDisplay
718 * Call XGrabServer() on @display.
719 * To ungrab the display again, use gdk_x11_display_ungrab().
721 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
726 gdk_x11_display_grab (GdkDisplay *display)
728 GdkDisplayX11 *display_x11;
730 g_return_if_fail (GDK_IS_DISPLAY (display));
732 display_x11 = GDK_DISPLAY_X11 (display);
734 if (display_x11->grab_count == 0)
735 XGrabServer (display_x11->xdisplay);
736 display_x11->grab_count++;
740 * gdk_x11_display_ungrab:
741 * @display: a #GdkDisplay
743 * Ungrab @display after it has been grabbed with
744 * gdk_x11_display_grab().
749 gdk_x11_display_ungrab (GdkDisplay *display)
751 GdkDisplayX11 *display_x11;
753 g_return_if_fail (GDK_IS_DISPLAY (display));
755 display_x11 = GDK_DISPLAY_X11 (display);;
756 g_return_if_fail (display_x11->grab_count > 0);
758 display_x11->grab_count--;
759 if (display_x11->grab_count == 0)
761 XUngrabServer (display_x11->xdisplay);
762 XFlush (display_x11->xdisplay);
767 gdk_display_x11_dispose (GObject *object)
769 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
772 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
773 _gdk_screen_close (display_x11->screens[i]);
775 _gdk_events_uninit (GDK_DISPLAY_OBJECT (object));
777 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
781 gdk_display_x11_finalize (GObject *object)
783 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
787 if (display_x11->keymap)
788 g_object_unref (display_x11->keymap);
791 if (display_x11->motif_target_lists)
793 for (i = 0; i < display_x11->motif_n_target_lists; i++)
794 g_list_free (display_x11->motif_target_lists[i]);
795 g_free (display_x11->motif_target_lists);
799 g_hash_table_destroy (display_x11->atom_from_virtual);
800 g_hash_table_destroy (display_x11->atom_to_virtual);
803 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
805 /* list of filters for client messages */
806 g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
807 g_list_free (display_x11->client_filters);
809 /* List of event window extraction functions */
810 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
811 g_slist_free (display_x11->event_types);
813 /* input GdkDevice list */
814 /* FIXME need to write finalize fct */
815 g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
816 g_list_free (display_x11->input_devices);
818 /* input GdkWindow list */
819 g_list_foreach (display_x11->input_windows, (GFunc) g_free, NULL);
820 g_list_free (display_x11->input_windows);
822 /* Free all GdkScreens */
823 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
824 g_object_unref (display_x11->screens[i]);
825 g_free (display_x11->screens);
827 g_free (display_x11->startup_notification_id);
830 g_hash_table_destroy (display_x11->xid_ht);
832 XCloseDisplay (display_x11->xdisplay);
834 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
838 * gdk_x11_lookup_xdisplay:
839 * @xdisplay: a pointer to an X Display
841 * Find the #GdkDisplay corresponding to @display, if any exists.
843 * Return value: the #GdkDisplay, if found, otherwise %NULL.
848 gdk_x11_lookup_xdisplay (Display *xdisplay)
852 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
854 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
855 return tmp_list->data;
862 * _gdk_x11_display_screen_for_xrootwin:
863 * @display: a #GdkDisplay
864 * @xrootwin: window ID for one of of the screen's of the display.
866 * Given the root window ID of one of the screen's of a #GdkDisplay,
869 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
872 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
877 for (i = 0; i < ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay); i++)
879 GdkScreen *screen = gdk_display_get_screen (display, i);
880 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
888 * gdk_x11_display_get_xdisplay:
889 * @display: a #GdkDisplay
890 * @returns: an X display.
892 * Returns the X display of a #GdkDisplay.
897 gdk_x11_display_get_xdisplay (GdkDisplay *display)
899 return GDK_DISPLAY_X11 (display)->xdisplay;
903 _gdk_windowing_set_default_display (GdkDisplay *display)
905 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
906 const gchar *startup_id;
914 gdk_display = GDK_DISPLAY_XDISPLAY (display);
916 g_free (display_x11->startup_notification_id);
917 display_x11->startup_notification_id = NULL;
919 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
920 if (startup_id && *startup_id != '\0')
924 if (!g_utf8_validate (startup_id, -1, NULL))
925 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
927 display_x11->startup_notification_id = g_strdup (startup_id);
929 /* Find the launch time from the startup_id, if it's there. Newer spec
930 * states that the startup_id is of the form <unique>_TIME<timestamp>
932 time_str = g_strrstr (startup_id, "_TIME");
933 if (time_str != NULL)
939 /* Skip past the "_TIME" part */
942 retval = strtoul (time_str, &end, 0);
943 if (end != time_str && errno == 0)
944 display_x11->user_time = retval;
947 /* Clear the environment variable so it won't be inherited by
948 * child processes and confuse things.
950 g_unsetenv ("DESKTOP_STARTUP_ID");
952 /* Set the startup id on the leader window so it
953 * applies to all windows we create on this display
955 XChangeProperty (display_x11->xdisplay,
956 display_x11->leader_window,
957 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
958 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
960 (guchar *)startup_id, strlen (startup_id));
965 broadcast_xmessage (GdkDisplay *display,
966 const char *message_type,
967 const char *message_type_begin,
970 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
971 GdkScreen *screen = gdk_display_get_default_screen (display);
972 GdkWindow *root_window = gdk_screen_get_root_window (screen);
973 Window xroot_window = GDK_WINDOW_XID (root_window);
976 Atom type_atom_begin;
979 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
983 XSetWindowAttributes attrs;
985 attrs.override_redirect = True;
986 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
989 XCreateWindow (xdisplay,
995 (Visual *)CopyFromParent,
996 CWOverrideRedirect | CWEventMask,
1000 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
1002 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
1003 message_type_begin);
1006 XClientMessageEvent xclient;
1008 const char *src_end;
1012 memset(&xclient, 0, sizeof (xclient));
1013 xclient.type = ClientMessage;
1014 xclient.message_type = type_atom_begin;
1015 xclient.display =xdisplay;
1016 xclient.window = xwindow;
1020 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
1022 while (src != src_end)
1024 dest = &xclient.data.b[0];
1025 dest_end = dest + 20;
1027 while (dest != dest_end &&
1035 while (dest != dest_end)
1041 XSendEvent (xdisplay,
1045 (XEvent *)&xclient);
1047 xclient.message_type = type_atom;
1051 XDestroyWindow (xdisplay, xwindow);
1056 * gdk_x11_display_broadcast_startup_message:
1057 * @display: a #GdkDisplay
1058 * @message_type: startup notification message type ("new", "change",
1060 * @...: a list of key/value pairs (as strings), terminated by a
1061 * %NULL key. (A %NULL value for a key will cause that key to be
1062 * skipped in the output.)
1064 * Sends a startup notification message of type @message_type to
1067 * This is a convenience function for use by code that implements the
1068 * freedesktop startup notification specification. Applications should
1069 * not normally need to call it directly. See the <ulink
1070 * url="http://standards.freedesktop.org/startup-notification-spec/startup-notification-latest.txt">Startup
1071 * Notification Protocol specification</ulink> for
1072 * definitions of the message types and keys that can be used.
1077 gdk_x11_display_broadcast_startup_message (GdkDisplay *display,
1078 const char *message_type,
1083 const char *key, *value, *p;
1085 message = g_string_new (message_type);
1086 g_string_append_c (message, ':');
1088 va_start (ap, message_type);
1089 while ((key = va_arg (ap, const char *)))
1091 value = va_arg (ap, const char *);
1095 g_string_append_printf (message, " %s=\"", key);
1096 for (p = value; *p; p++)
1103 g_string_append_c (message, '\\');
1107 g_string_append_c (message, *p);
1109 g_string_append_c (message, '\"');
1113 broadcast_xmessage (display,
1114 "_NET_STARTUP_INFO",
1115 "_NET_STARTUP_INFO_BEGIN",
1118 g_string_free (message, TRUE);
1122 * gdk_notify_startup_complete:
1124 * Indicates to the GUI environment that the application has finished
1125 * loading. If the applications opens windows, this function is
1126 * normally called after opening the application's initial set of
1129 * GTK+ will call this function automatically after opening the first
1130 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1131 * to disable that feature.
1136 gdk_notify_startup_complete (void)
1138 GdkDisplay *display;
1139 GdkDisplayX11 *display_x11;
1141 display = gdk_display_get_default ();
1145 display_x11 = GDK_DISPLAY_X11 (display);
1147 if (display_x11->startup_notification_id == NULL)
1150 gdk_notify_startup_complete_with_id (display_x11->startup_notification_id);
1154 * gdk_notify_startup_complete_with_id:
1155 * @startup_id: a startup-notification identifier, for which notification
1156 * process should be completed
1158 * Indicates to the GUI environment that the application has finished
1159 * loading, using a given identifier.
1161 * GTK+ will call this function automatically for #GtkWindow with custom
1162 * startup-notification identifier unless
1163 * gtk_window_set_auto_startup_notification() is called to disable
1169 gdk_notify_startup_complete_with_id (const gchar* startup_id)
1171 GdkDisplay *display;
1173 display = gdk_display_get_default ();
1177 gdk_x11_display_broadcast_startup_message (display, "remove",
1183 * gdk_display_supports_selection_notification:
1184 * @display: a #GdkDisplay
1186 * Returns whether #GdkEventOwnerChange events will be
1187 * sent when the owner of a selection changes.
1189 * Return value: whether #GdkEventOwnerChange events will
1195 gdk_display_supports_selection_notification (GdkDisplay *display)
1197 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1199 return display_x11->have_xfixes;
1203 * gdk_display_request_selection_notification:
1204 * @display: a #GdkDisplay
1205 * @selection: the #GdkAtom naming the selection for which
1206 * ownership change notification is requested
1208 * Request #GdkEventOwnerChange events for ownership changes
1209 * of the selection named by the given atom.
1211 * Return value: whether #GdkEventOwnerChange events will
1217 gdk_display_request_selection_notification (GdkDisplay *display,
1222 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1225 if (display_x11->have_xfixes)
1227 atom = gdk_x11_atom_to_xatom_for_display (display,
1229 XFixesSelectSelectionInput (display_x11->xdisplay,
1230 display_x11->leader_window,
1232 XFixesSetSelectionOwnerNotifyMask |
1233 XFixesSelectionWindowDestroyNotifyMask |
1234 XFixesSelectionClientCloseNotifyMask);
1243 * gdk_display_supports_clipboard_persistence
1244 * @display: a #GdkDisplay
1246 * Returns whether the speicifed display supports clipboard
1247 * persistance; i.e. if it's possible to store the clipboard data after an
1248 * application has quit. On X11 this checks if a clipboard daemon is
1251 * Returns: %TRUE if the display supports clipboard persistance.
1256 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1258 Atom clipboard_manager;
1260 /* It might make sense to cache this */
1261 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1262 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay, clipboard_manager) != None;
1266 * gdk_display_store_clipboard
1267 * @display: a #GdkDisplay
1268 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1269 * @time_: a timestamp
1270 * @targets: an array of targets that should be saved, or %NULL
1271 * if all available targets should be saved.
1272 * @n_targets: length of the @targets array
1274 * Issues a request to the clipboard manager to store the
1275 * clipboard data. On X11, this is a special program that works
1276 * according to the freedesktop clipboard specification, available at
1277 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1278 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1283 gdk_display_store_clipboard (GdkDisplay *display,
1284 GdkWindow *clipboard_window,
1289 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1290 Atom clipboard_manager, save_targets;
1292 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1293 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1295 gdk_error_trap_push ();
1297 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1299 Atom property_name = None;
1305 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1307 xatoms = g_new (Atom, n_targets);
1308 for (i = 0; i < n_targets; i++)
1309 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1311 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1312 property_name, XA_ATOM,
1313 32, PropModeReplace, (guchar *)xatoms, n_targets);
1318 XConvertSelection (display_x11->xdisplay,
1319 clipboard_manager, save_targets, property_name,
1320 GDK_WINDOW_XID (clipboard_window), time_);
1323 gdk_error_trap_pop ();
1328 * gdk_x11_display_get_user_time:
1329 * @display: a #GdkDisplay
1331 * Returns the timestamp of the last user interaction on
1332 * @display. The timestamp is taken from events caused
1333 * by user interaction such as key presses or pointer
1334 * movements. See gdk_x11_window_set_user_time().
1336 * Returns: the timestamp of the last user interaction
1341 gdk_x11_display_get_user_time (GdkDisplay *display)
1343 return GDK_DISPLAY_X11 (display)->user_time;
1347 * gdk_display_supports_shapes:
1348 * @display: a #GdkDisplay
1350 * Returns %TRUE if gdk_window_shape_combine_mask() can
1351 * be used to create shaped windows on @display.
1353 * Returns: %TRUE if shaped windows are supported
1358 gdk_display_supports_shapes (GdkDisplay *display)
1360 return GDK_DISPLAY_X11 (display)->have_shapes;
1364 * gdk_display_supports_input_shapes:
1365 * @display: a #GdkDisplay
1367 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1368 * be used to modify the input shape of windows on @display.
1370 * Returns: %TRUE if windows with modified input shape are supported
1375 gdk_display_supports_input_shapes (GdkDisplay *display)
1377 return GDK_DISPLAY_X11 (display)->have_input_shapes;
1382 * gdk_x11_display_get_startup_notification_id:
1383 * @display: a #GdkDisplay
1385 * Gets the startup notification ID for a display.
1387 * Returns: the startup notification ID for @display
1391 G_CONST_RETURN gchar *
1392 gdk_x11_display_get_startup_notification_id (GdkDisplay *display)
1394 return GDK_DISPLAY_X11 (display)->startup_notification_id;
1398 * gdk_display_supports_composite:
1399 * @display: a #GdkDisplay
1401 * Returns %TRUE if gdk_window_set_composited() can be used
1402 * to redirect drawing on the window using compositing.
1404 * Currently this only works on X11 with XComposite and
1405 * XDamage extensions available.
1407 * Returns: %TRUE if windows may be composited.
1412 gdk_display_supports_composite (GdkDisplay *display)
1414 GdkDisplayX11 *x11_display = GDK_DISPLAY_X11 (display);
1416 return x11_display->have_xcomposite &&
1417 x11_display->have_xdamage &&
1418 x11_display->have_xfixes;
1422 #define __GDK_DISPLAY_X11_C__
1423 #include "gdkaliasdef.c"