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>
53 static void gdk_display_x11_class_init (GdkDisplayX11Class *class);
54 static void gdk_display_x11_dispose (GObject *object);
55 static void gdk_display_x11_finalize (GObject *object);
58 static void gdk_internal_connection_watch (Display *display,
62 XPointer *watch_data);
63 #endif /* HAVE_X11R6 */
65 static gpointer parent_class = NULL;
67 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
68 * but including them here has the side-effect of getting them
69 * into the internal Xlib cache
71 static const char *const precache_atoms[] = {
85 "_NET_WM_STATE_STICKY",
86 "_NET_WM_STATE_MAXIMIZED_VERT",
87 "_NET_WM_STATE_MAXIMIZED_HORZ",
88 "_NET_WM_STATE_FULLSCREEN",
89 "_NET_WM_SYNC_REQUEST",
90 "_NET_WM_SYNC_REQUEST_COUNTER",
91 "_NET_WM_WINDOW_TYPE",
92 "_NET_WM_WINDOW_TYPE_NORMAL",
98 _gdk_display_x11_get_type (void)
100 static GType object_type = 0;
104 static const GTypeInfo object_info =
106 sizeof (GdkDisplayX11Class),
107 (GBaseInitFunc) NULL,
108 (GBaseFinalizeFunc) NULL,
109 (GClassInitFunc) gdk_display_x11_class_init,
110 NULL, /* class_finalize */
111 NULL, /* class_data */
112 sizeof (GdkDisplayX11),
114 (GInstanceInitFunc) NULL,
117 object_type = g_type_register_static (GDK_TYPE_DISPLAY,
126 gdk_display_x11_class_init (GdkDisplayX11Class * class)
128 GObjectClass *object_class = G_OBJECT_CLASS (class);
130 object_class->dispose = gdk_display_x11_dispose;
131 object_class->finalize = gdk_display_x11_finalize;
133 parent_class = g_type_class_peek_parent (class);
139 * @display_name: the name of the display to open
140 * @returns: a #GdkDisplay, or %NULL if the display
141 * could not be opened.
148 gdk_display_open (const gchar *display_name)
152 GdkDisplayX11 *display_x11;
156 const char *sm_client_id;
158 XClassHint *class_hint;
165 xdisplay = XOpenDisplay (display_name);
169 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
170 display_x11 = GDK_DISPLAY_X11 (display);
172 display_x11->use_xshm = TRUE;
173 display_x11->xdisplay = xdisplay;
176 /* Set up handlers for Xlib internal connections */
177 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
178 #endif /* HAVE_X11R6 */
180 /* initialize the display's screens */
181 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
182 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
183 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
185 /* We need to initialize events after we have the screen
186 * structures in places
188 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
189 _gdk_x11_events_init_screen (display_x11->screens[i]);
191 /*set the default screen */
192 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
194 attr.window_type = GDK_WINDOW_TOPLEVEL;
195 attr.wclass = GDK_INPUT_OUTPUT;
202 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
203 &attr, GDK_WA_X | GDK_WA_Y);
204 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
206 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
208 display_x11->leader_window_title_set = FALSE;
210 display_x11->have_render = GDK_UNKNOWN;
211 display_x11->have_render_with_trapezoids = GDK_UNKNOWN;
214 if (XFixesQueryExtension (display_x11->xdisplay,
215 &display_x11->xfixes_event_base,
218 display_x11->have_xfixes = TRUE;
220 gdk_x11_register_standard_event_type (display,
221 display_x11->xfixes_event_base,
226 display_x11->have_xfixes = FALSE;
228 if (_gdk_synchronize)
229 XSynchronize (display_x11->xdisplay, True);
231 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
233 class_hint = XAllocClassHint();
234 class_hint->res_name = g_get_prgname ();
236 class_hint->res_class = (char *)gdk_get_program_class ();
238 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
239 * from argv[0], so we just synthesize an argument array here.
242 argv[0] = g_get_prgname ();
244 XmbSetWMProperties (display_x11->xdisplay,
245 display_x11->leader_window,
246 NULL, NULL, argv, argc, NULL, NULL,
250 sm_client_id = _gdk_get_sm_client_id ();
252 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
255 XChangeProperty (display_x11->xdisplay,
256 display_x11->leader_window,
257 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
258 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
260 /* We don't yet know a valid time. */
261 display_x11->user_time = 0;
265 gint xkb_major = XkbMajorVersion;
266 gint xkb_minor = XkbMinorVersion;
267 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
269 xkb_major = XkbMajorVersion;
270 xkb_minor = XkbMinorVersion;
272 if (XkbQueryExtension (display_x11->xdisplay,
273 NULL, &display_x11->xkb_event_type, NULL,
274 &xkb_major, &xkb_minor))
276 Bool detectable_autorepeat_supported;
278 display_x11->use_xkb = TRUE;
280 XkbSelectEvents (display_x11->xdisplay,
282 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
283 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
285 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
287 &detectable_autorepeat_supported);
289 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
290 detectable_autorepeat_supported ?
291 "supported" : "not supported"));
293 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
299 display_x11->use_sync = FALSE;
303 int error_base, event_base;
305 if (XSyncQueryExtension (display_x11->xdisplay,
306 &event_base, &error_base) &&
307 XSyncInitialize (display_x11->xdisplay,
309 display_x11->use_sync = TRUE;
313 _gdk_windowing_image_init (display);
314 _gdk_events_init (display);
315 _gdk_input_init (display);
316 _gdk_dnd_init (display);
318 g_signal_emit_by_name (gdk_display_manager_get(),
319 "display_opened", display);
326 * XLib internal connection handling
328 typedef struct _GdkInternalConnection GdkInternalConnection;
330 struct _GdkInternalConnection
338 process_internal_connection (GIOChannel *gioc,
342 GdkInternalConnection *connection = (GdkInternalConnection *)data;
344 GDK_THREADS_ENTER ();
346 XProcessInternalConnection ((Display*)connection->display, connection->fd);
348 GDK_THREADS_LEAVE ();
353 static GdkInternalConnection *
354 gdk_add_connection_handler (Display *display,
357 GIOChannel *io_channel;
358 GdkInternalConnection *connection;
360 connection = g_new (GdkInternalConnection, 1);
363 connection->display = display;
365 io_channel = g_io_channel_unix_new (fd);
367 connection->source = g_io_create_watch (io_channel, G_IO_IN);
368 g_source_set_callback (connection->source,
369 (GSourceFunc)process_internal_connection, connection, NULL);
370 g_source_attach (connection->source, NULL);
372 g_io_channel_unref (io_channel);
378 gdk_remove_connection_handler (GdkInternalConnection *connection)
380 g_source_destroy (connection->source);
385 gdk_internal_connection_watch (Display *display,
389 XPointer *watch_data)
392 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
394 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
396 #endif /* HAVE_X11R6 */
399 * gdk_display_get_name:
400 * @display: a #GdkDisplay
402 * Gets the name of the display.
404 * Returns: a string representing the display name. This string is owned
405 * by GDK and should not be modified or freed.
409 G_CONST_RETURN gchar *
410 gdk_display_get_name (GdkDisplay * display)
412 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
414 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
418 * gdk_display_get_n_screens:
419 * @display: a #GdkDisplay
421 * Gets the number of screen managed by the @display.
423 * Returns: number of screens.
428 gdk_display_get_n_screens (GdkDisplay * display)
430 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
432 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
436 * gdk_display_get_screen:
437 * @display: a #GdkDisplay
438 * @screen_num: the screen number
440 * Returns a screen object for one of the screens of the display.
442 * Returns: the #GdkScreen object
447 gdk_display_get_screen (GdkDisplay * display, gint screen_num)
449 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
450 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
452 return GDK_DISPLAY_X11 (display)->screens[screen_num];
456 * gdk_display_get_default_screen:
457 * @display: a #GdkDisplay
459 * Get the default #GdkScreen for @display.
461 * Returns: the default #GdkScreen object for @display
466 gdk_display_get_default_screen (GdkDisplay * display)
468 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
470 return GDK_DISPLAY_X11 (display)->default_screen;
474 _gdk_x11_display_is_root_window (GdkDisplay *display,
477 GdkDisplayX11 *display_x11;
480 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
482 display_x11 = GDK_DISPLAY_X11 (display);
484 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
486 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
493 * gdk_display_pointer_ungrab:
494 * @display: a #GdkDisplay.
495 * @time_: a timestap (e.g. GDK_CURRENT_TIME).
497 * Release any pointer grab.
502 gdk_display_pointer_ungrab (GdkDisplay *display,
507 g_return_if_fail (GDK_IS_DISPLAY (display));
509 xdisplay = GDK_DISPLAY_XDISPLAY (display);
511 _gdk_input_ungrab_pointer (display, time);
512 XUngrabPointer (xdisplay, time);
515 GDK_DISPLAY_X11 (display)->pointer_xgrab_window = NULL;
519 * gdk_display_pointer_is_grabbed:
520 * @display: a #GdkDisplay
522 * Test if the pointer is grabbed.
524 * Returns: %TRUE if an active X pointer grab is in effect
529 gdk_display_pointer_is_grabbed (GdkDisplay * display)
531 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
533 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL);
537 * gdk_display_keyboard_ungrab:
538 * @display: a #GdkDisplay.
539 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
541 * Release any keyboard grab
546 gdk_display_keyboard_ungrab (GdkDisplay *display,
551 g_return_if_fail (GDK_IS_DISPLAY (display));
553 xdisplay = GDK_DISPLAY_XDISPLAY (display);
555 XUngrabKeyboard (xdisplay, time);
558 GDK_DISPLAY_X11 (display)->keyboard_xgrab_window = NULL;
563 * @display: a #GdkDisplay
565 * Emits a short beep on @display
570 gdk_display_beep (GdkDisplay * display)
572 g_return_if_fail (GDK_IS_DISPLAY (display));
574 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
579 * @display: a #GdkDisplay
581 * Flushes any requests queued for the windowing system and waits until all
582 * requests have been handled. This is often used for making sure that the
583 * display is synchronized with the current state of the program. Calling
584 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
585 * generated from earlier requests are handled before the error trap is
588 * This is most useful for X11. On windowing systems where requests are
589 * handled synchronously, this function will do nothing.
594 gdk_display_sync (GdkDisplay * display)
596 g_return_if_fail (GDK_IS_DISPLAY (display));
598 XSync (GDK_DISPLAY_XDISPLAY (display), False);
603 * @display: a #GdkDisplay
605 * Flushes any requests queued for the windowing system; this happens automatically
606 * when the main loop blocks waiting for new events, but if your application
607 * is drawing without returning control to the main loop, you may need
608 * to call this function explicitely. A common case where this function
609 * needs to be called is when an application is executing drawing commands
610 * from a thread other than the thread where the main loop is running.
612 * This is most useful for X11. On windowing systems where requests are
613 * handled synchronously, this function will do nothing.
618 gdk_display_flush (GdkDisplay *display)
620 g_return_if_fail (GDK_IS_DISPLAY (display));
622 if (!display->closed)
623 XFlush (GDK_DISPLAY_XDISPLAY (display));
627 * gdk_display_get_default_group:
628 * @display: a #GdkDisplay
630 * Returns the default group leader window for all toplevel windows
631 * on @display. This window is implicitly created by GDK.
632 * See gdk_window_set_group().
634 * Return value: The default group leader window for @display
638 GdkWindow *gdk_display_get_default_group (GdkDisplay *display)
640 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
642 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
646 * gdk_x11_display_grab:
647 * @display: a #GdkDisplay
649 * Call XGrabServer() on @display.
650 * To ungrab the display again, use gdk_x11_display_ungrab().
652 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
657 gdk_x11_display_grab (GdkDisplay * display)
659 GdkDisplayX11 *display_x11;
661 g_return_if_fail (GDK_IS_DISPLAY (display));
663 display_x11 = GDK_DISPLAY_X11 (display);
665 if (display_x11->grab_count == 0)
666 XGrabServer (display_x11->xdisplay);
667 display_x11->grab_count++;
671 * gdk_x11_display_ungrab:
672 * @display: a #GdkDisplay
674 * Ungrab @display after it has been grabbed with
675 * gdk_x11_display_grab().
680 gdk_x11_display_ungrab (GdkDisplay * display)
682 GdkDisplayX11 *display_x11;
684 g_return_if_fail (GDK_IS_DISPLAY (display));
686 display_x11 = GDK_DISPLAY_X11 (display);;
687 g_return_if_fail (display_x11->grab_count > 0);
689 display_x11->grab_count--;
690 if (display_x11->grab_count == 0)
692 XUngrabServer (display_x11->xdisplay);
693 XFlush (display_x11->xdisplay);
698 gdk_display_x11_dispose (GObject *object)
700 GdkDisplayX11 *display_x11;
703 display_x11 = GDK_DISPLAY_X11 (object);
705 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
706 _gdk_screen_close (display_x11->screens[i]);
708 g_source_destroy (display_x11->event_source);
710 XCloseDisplay (display_x11->xdisplay);
711 display_x11->xdisplay = NULL;
713 G_OBJECT_CLASS (parent_class)->dispose (object);
717 gdk_display_x11_finalize (GObject *object)
719 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
722 /* FIXME need to write GdkKeymap finalize fct
723 g_object_unref (display_x11->keymap);
726 if (display_x11->motif_target_lists)
728 for (i = 0; i < display_x11->motif_n_target_lists; i++)
729 g_list_free (display_x11->motif_target_lists[i]);
730 g_free (display_x11->motif_target_lists);
734 g_hash_table_destroy (display_x11->atom_from_virtual);
735 g_hash_table_destroy (display_x11->atom_to_virtual);
737 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
738 /* list of filters for client messages */
739 g_list_free (display_x11->client_filters);
740 /* List of event window extraction functions */
741 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
742 g_slist_free (display_x11->event_types);
744 g_hash_table_destroy (display_x11->xid_ht);
745 /* input GdkDevice list */
746 /* FIXME need to write finalize fct */
747 for (tmp = display_x11->input_devices; tmp; tmp = tmp->next)
748 g_object_unref (tmp->data);
749 g_list_free (display_x11->input_devices);
750 /* input GdkWindow list */
751 for (tmp = display_x11->input_windows; tmp; tmp = tmp->next)
752 g_object_unref (tmp->data);
753 g_list_free (display_x11->input_windows);
754 /* Free all GdkScreens */
755 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
756 g_object_unref (display_x11->screens[i]);
757 g_free (display_x11->screens);
758 g_free (display_x11->startup_notification_id);
760 G_OBJECT_CLASS (parent_class)->finalize (object);
764 * gdk_x11_lookup_xdisplay:
765 * @xdisplay: a pointer to an X Display
767 * Find the #GdkDisplay corresponding to @display, if any exists.
769 * Return value: the #GdkDisplay, if found, otherwise %NULL.
774 gdk_x11_lookup_xdisplay (Display *xdisplay)
778 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
780 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
781 return tmp_list->data;
788 * _gdk_x11_display_screen_for_xrootwin:
789 * @display: a #Display
790 * @xrootwin: window ID for one of of the screen's of the display.
792 * Given the root window ID of one of the screen's of a #GdkDisplay,
795 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
798 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
803 n_screens = gdk_display_get_n_screens (display);
804 for (i = 0; i < n_screens; i++)
806 GdkScreen *screen = gdk_display_get_screen (display, i);
807 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
815 * gdk_x11_display_get_xdisplay:
816 * @display: a #GdkDisplay
817 * @returns: an X display.
819 * Returns the X display of a #GdkDisplay.
824 gdk_x11_display_get_xdisplay (GdkDisplay *display)
826 return GDK_DISPLAY_X11 (display)->xdisplay;
830 _gdk_windowing_set_default_display (GdkDisplay *display)
832 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
833 const gchar *startup_id;
836 gdk_display = GDK_DISPLAY_XDISPLAY (display);
840 g_free (display_x11->startup_notification_id);
841 display_x11->startup_notification_id = NULL;
843 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
844 if (startup_id && *startup_id != '\0')
848 if (!g_utf8_validate (startup_id, -1, NULL))
849 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
851 display_x11->startup_notification_id = g_strdup (startup_id);
853 /* Find the launch time from the startup_id, if it's there. Newer spec
854 * states that the startup_id is of the form <unique>_TIME<timestamp>
856 time_str = g_strrstr (startup_id, "_TIME");
857 if (time_str != NULL)
863 /* Skip past the "_TIME" part */
866 retval = strtoul (time_str, &end, 0);
867 if (end != time_str && errno == 0)
868 display_x11->user_time = retval;
871 /* Clear the environment variable so it won't be inherited by
872 * child processes and confuse things.
874 g_unsetenv ("DESKTOP_STARTUP_ID");
876 /* Set the startup id on the leader window so it
877 * applies to all windows we create on this display
879 XChangeProperty (display_x11->xdisplay,
880 display_x11->leader_window,
881 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
882 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
884 startup_id, strlen (startup_id));
889 escape_for_xmessage (const char *str)
894 retval = g_string_new (NULL);
904 g_string_append_c (retval, '\\');
908 g_string_append_c (retval, *p);
912 return g_string_free (retval, FALSE);
916 broadcast_xmessage (GdkDisplay *display,
917 const char *message_type,
918 const char *message_type_begin,
921 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
922 GdkScreen *screen = gdk_display_get_default_screen (display);
923 GdkWindow *root_window = gdk_screen_get_root_window (screen);
924 Window xroot_window = GDK_WINDOW_XID (root_window);
927 Atom type_atom_begin;
931 XSetWindowAttributes attrs;
933 attrs.override_redirect = True;
934 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
937 XCreateWindow (xdisplay,
943 (Visual *)CopyFromParent,
944 CWOverrideRedirect | CWEventMask,
948 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
950 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
960 xevent.xclient.type = ClientMessage;
961 xevent.xclient.message_type = type_atom_begin;
962 xevent.xclient.display =xdisplay;
963 xevent.xclient.window = xwindow;
964 xevent.xclient.format = 8;
967 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
969 while (src != src_end)
971 dest = &xevent.xclient.data.b[0];
972 dest_end = dest + 20;
974 while (dest != dest_end &&
982 while (dest != dest_end)
988 XSendEvent (xdisplay,
994 xevent.xclient.message_type = type_atom;
998 XDestroyWindow (xdisplay, xwindow);
1003 * gdk_notify_startup_complete:
1005 * Indicates to the GUI environment that the application has finished
1006 * loading. If the applications opens windows, this function is
1007 * normally called after opening the application's initial set of
1010 * GTK+ will call this function automatically after opening the first
1011 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1012 * to disable that feature.
1017 gdk_notify_startup_complete (void)
1019 GdkDisplay *display;
1020 GdkDisplayX11 *display_x11;
1024 display = gdk_display_get_default ();
1028 display_x11 = GDK_DISPLAY_X11 (display);
1030 if (display_x11->startup_notification_id == NULL)
1033 escaped_id = escape_for_xmessage (display_x11->startup_notification_id);
1034 message = g_strdup_printf ("remove: ID=%s", escaped_id);
1035 g_free (escaped_id);
1037 broadcast_xmessage (display,
1038 "_NET_STARTUP_INFO",
1039 "_NET_STARTUP_INFO_BEGIN",
1047 * gdk_display_supports_selection_notification:
1048 * @display: a #GdkDisplay
1050 * Returns whether #GdkEventOwnerChange events will be
1051 * sent when the owner of a selection changes.
1053 * Return value: whether #GdkEventOwnerChange events will
1059 gdk_display_supports_selection_notification (GdkDisplay *display)
1061 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1063 return display_x11->have_xfixes;
1067 * gdk_display_request_selection_notification:
1068 * @display: a #GdkDisplay
1069 * @selection: the #GdkAtom naming the selection for which
1070 * ownership change notification is requested
1072 * Request #GdkEventOwnerChange events for ownership changes
1073 * of the selection named by the given atom.
1075 * Return value: whether #GdkEventOwnerChange events will
1080 gboolean gdk_display_request_selection_notification (GdkDisplay *display,
1085 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1088 if (display_x11->have_xfixes)
1090 atom = gdk_x11_atom_to_xatom_for_display (display,
1092 XFixesSelectSelectionInput (display_x11->xdisplay,
1093 display_x11->leader_window,
1095 XFixesSetSelectionOwnerNotifyMask |
1096 XFixesSelectionWindowDestroyNotifyMask |
1097 XFixesSelectionClientCloseNotifyMask);
1106 * gdk_display_supports_clipboard_persistence
1107 * @display: a #GdkDisplay
1109 * Returns whether the speicifed display supports clipboard
1110 * persistance; i.e. if it's possible to store the clipboard data after an
1111 * application has quit. On X11 this checks if a clipboard daemon is
1114 * Returns: %TRUE if the display supports clipboard persistance.
1119 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1121 /* It might make sense to cache this */
1122 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay,
1123 gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER")) != None;
1127 * gdk_display_store_clipboard
1128 * @display: a #GdkDisplay
1129 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1130 * @time_: a timestamp
1131 * @targets: an array of targets that should be saved, or %NULL
1132 * if all available targets should be saved.
1133 * @n_targets: length of the @targets array
1135 * Issues a request to the clipboard manager to store the
1136 * clipboard data. On X11, this is a special program that works
1137 * according to the freedesktop clipboard specification, available at
1138 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1139 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1144 gdk_display_store_clipboard (GdkDisplay *display,
1145 GdkWindow *clipboard_window,
1150 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1151 Atom clipboard_manager, save_targets;
1153 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1154 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1156 gdk_error_trap_push ();
1158 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1160 Atom property_name = None;
1166 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1168 xatoms = g_new (Atom, n_targets);
1169 for (i = 0; i < n_targets; i++)
1170 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1172 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1173 property_name, XA_ATOM,
1174 32, PropModeReplace, (guchar *)xatoms, n_targets);
1179 XConvertSelection (display_x11->xdisplay,
1180 clipboard_manager, save_targets, property_name,
1181 GDK_WINDOW_XID (clipboard_window), time_);
1184 gdk_error_trap_pop ();
1189 * gdk_x11_display_get_user_time:
1190 * @display: a #GdkDisplay
1192 * Returns the timestamp of the last user interaction on
1193 * @display. The timestamp is taken from events caused
1194 * by user interaction such as key presses or pointer
1195 * movements. See gdk_x11_window_set_user_time().
1197 * Returns: the timestamp of the last user interaction
1202 gdk_x11_display_get_user_time (GdkDisplay *display)
1204 return GDK_DISPLAY_X11 (display)->user_time;
1207 #define __GDK_DISPLAY_X11_C__
1208 #include "gdkaliasdef.c"