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"
42 #include <X11/Xatom.h>
45 #include <X11/XKBlib.h>
49 #include <X11/extensions/Xfixes.h>
52 static void gdk_display_x11_class_init (GdkDisplayX11Class *class);
53 static void gdk_display_x11_dispose (GObject *object);
54 static void gdk_display_x11_finalize (GObject *object);
57 static void gdk_internal_connection_watch (Display *display,
61 XPointer *watch_data);
62 #endif /* HAVE_X11R6 */
64 static gpointer parent_class = NULL;
66 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
67 * but including them here has the side-effect of getting them
68 * into the internal Xlib cache
70 static const char *const precache_atoms[] = {
84 "_NET_WM_STATE_STICKY",
85 "_NET_WM_STATE_MAXIMIZED_VERT",
86 "_NET_WM_STATE_MAXIMIZED_HORZ",
87 "_NET_WM_STATE_FULLSCREEN",
88 "_NET_WM_SYNC_REQUEST",
89 "_NET_WM_SYNC_REQUEST_COUNTER",
90 "_NET_WM_WINDOW_TYPE",
91 "_NET_WM_WINDOW_TYPE_NORMAL",
96 _gdk_display_x11_get_type (void)
98 static GType object_type = 0;
102 static const GTypeInfo object_info =
104 sizeof (GdkDisplayX11Class),
105 (GBaseInitFunc) NULL,
106 (GBaseFinalizeFunc) NULL,
107 (GClassInitFunc) gdk_display_x11_class_init,
108 NULL, /* class_finalize */
109 NULL, /* class_data */
110 sizeof (GdkDisplayX11),
112 (GInstanceInitFunc) NULL,
115 object_type = g_type_register_static (GDK_TYPE_DISPLAY,
124 gdk_display_x11_class_init (GdkDisplayX11Class * class)
126 GObjectClass *object_class = G_OBJECT_CLASS (class);
128 object_class->dispose = gdk_display_x11_dispose;
129 object_class->finalize = gdk_display_x11_finalize;
131 parent_class = g_type_class_peek_parent (class);
137 * @display_name: the name of the display to open
138 * @returns: a #GdkDisplay, or %NULL if the display
139 * could not be opened.
146 gdk_display_open (const gchar *display_name)
150 GdkDisplayX11 *display_x11;
154 const char *sm_client_id;
156 XClassHint *class_hint;
163 xdisplay = XOpenDisplay (display_name);
167 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
168 display_x11 = GDK_DISPLAY_X11 (display);
170 display_x11->use_xshm = TRUE;
171 display_x11->xdisplay = xdisplay;
174 /* Set up handlers for Xlib internal connections */
175 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
176 #endif /* HAVE_X11R6 */
178 /* initialize the display's screens */
179 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
180 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
181 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
183 /* We need to initialize events after we have the screen
184 * structures in places
186 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
187 _gdk_x11_events_init_screen (display_x11->screens[i]);
189 /*set the default screen */
190 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
192 attr.window_type = GDK_WINDOW_TOPLEVEL;
193 attr.wclass = GDK_INPUT_OUTPUT;
200 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
201 &attr, GDK_WA_X | GDK_WA_Y);
202 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
204 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
206 display_x11->leader_window_title_set = FALSE;
208 display_x11->have_render = GDK_UNKNOWN;
209 display_x11->have_render_with_trapezoids = GDK_UNKNOWN;
212 if (XFixesQueryExtension (display_x11->xdisplay,
213 &display_x11->xfixes_event_base,
216 display_x11->have_xfixes = TRUE;
218 gdk_x11_register_standard_event_type (display,
219 display_x11->xfixes_event_base,
224 display_x11->have_xfixes = FALSE;
226 if (_gdk_synchronize)
227 XSynchronize (display_x11->xdisplay, True);
229 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
231 class_hint = XAllocClassHint();
232 class_hint->res_name = g_get_prgname ();
234 class_hint->res_class = (char *)gdk_get_program_class ();
236 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
237 * from argv[0], so we just synthesize an argument array here.
240 argv[0] = g_get_prgname ();
242 XmbSetWMProperties (display_x11->xdisplay,
243 display_x11->leader_window,
244 NULL, NULL, argv, argc, NULL, NULL,
248 sm_client_id = _gdk_get_sm_client_id ();
250 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
253 XChangeProperty (display_x11->xdisplay,
254 display_x11->leader_window,
255 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
256 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
258 /* We don't yet know a valid time. */
259 display_x11->user_time = 0;
263 gint xkb_major = XkbMajorVersion;
264 gint xkb_minor = XkbMinorVersion;
265 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
267 xkb_major = XkbMajorVersion;
268 xkb_minor = XkbMinorVersion;
270 if (XkbQueryExtension (display_x11->xdisplay,
271 NULL, &display_x11->xkb_event_type, NULL,
272 &xkb_major, &xkb_minor))
274 Bool detectable_autorepeat_supported;
276 display_x11->use_xkb = TRUE;
278 XkbSelectEvents (display_x11->xdisplay,
280 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
281 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
283 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
285 &detectable_autorepeat_supported);
287 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
288 detectable_autorepeat_supported ?
289 "supported" : "not supported"));
291 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
297 display_x11->use_sync = FALSE;
301 int error_base, event_base;
303 if (XSyncQueryExtension (display_x11->xdisplay,
304 &event_base, &error_base) &&
305 XSyncInitialize (display_x11->xdisplay,
307 display_x11->use_sync = TRUE;
311 _gdk_windowing_image_init (display);
312 _gdk_events_init (display);
313 _gdk_input_init (display);
314 _gdk_dnd_init (display);
316 g_signal_emit_by_name (gdk_display_manager_get(),
317 "display_opened", display);
324 * XLib internal connection handling
326 typedef struct _GdkInternalConnection GdkInternalConnection;
328 struct _GdkInternalConnection
336 process_internal_connection (GIOChannel *gioc,
340 GdkInternalConnection *connection = (GdkInternalConnection *)data;
342 GDK_THREADS_ENTER ();
344 XProcessInternalConnection ((Display*)connection->display, connection->fd);
346 GDK_THREADS_LEAVE ();
351 static GdkInternalConnection *
352 gdk_add_connection_handler (Display *display,
355 GIOChannel *io_channel;
356 GdkInternalConnection *connection;
358 connection = g_new (GdkInternalConnection, 1);
361 connection->display = display;
363 io_channel = g_io_channel_unix_new (fd);
365 connection->source = g_io_create_watch (io_channel, G_IO_IN);
366 g_source_set_callback (connection->source,
367 (GSourceFunc)process_internal_connection, connection, NULL);
368 g_source_attach (connection->source, NULL);
370 g_io_channel_unref (io_channel);
376 gdk_remove_connection_handler (GdkInternalConnection *connection)
378 g_source_destroy (connection->source);
383 gdk_internal_connection_watch (Display *display,
387 XPointer *watch_data)
390 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
392 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
394 #endif /* HAVE_X11R6 */
397 * gdk_display_get_name:
398 * @display: a #GdkDisplay
400 * Gets the name of the display.
402 * Returns: a string representing the display name. This string is owned
403 * by GDK and should not be modified or freed.
407 G_CONST_RETURN gchar *
408 gdk_display_get_name (GdkDisplay * display)
410 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
412 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
416 * gdk_display_get_n_screens:
417 * @display: a #GdkDisplay
419 * Gets the number of screen managed by the @display.
421 * Returns: number of screens.
426 gdk_display_get_n_screens (GdkDisplay * display)
428 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
430 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
434 * gdk_display_get_screen:
435 * @display: a #GdkDisplay
436 * @screen_num: the screen number
438 * Returns a screen object for one of the screens of the display.
440 * Returns: the #GdkScreen object
445 gdk_display_get_screen (GdkDisplay * display, gint screen_num)
447 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
448 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
450 return GDK_DISPLAY_X11 (display)->screens[screen_num];
454 * gdk_display_get_default_screen:
455 * @display: a #GdkDisplay
457 * Get the default #GdkScreen for @display.
459 * Returns: the default #GdkScreen object for @display
464 gdk_display_get_default_screen (GdkDisplay * display)
466 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
468 return GDK_DISPLAY_X11 (display)->default_screen;
472 _gdk_x11_display_is_root_window (GdkDisplay *display,
475 GdkDisplayX11 *display_x11;
478 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
480 display_x11 = GDK_DISPLAY_X11 (display);
482 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
484 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
491 * gdk_display_pointer_ungrab:
492 * @display: a #GdkDisplay.
493 * @time_: a timestap (e.g. GDK_CURRENT_TIME).
495 * Release any pointer grab.
500 gdk_display_pointer_ungrab (GdkDisplay *display,
505 g_return_if_fail (GDK_IS_DISPLAY (display));
507 xdisplay = GDK_DISPLAY_XDISPLAY (display);
509 _gdk_input_ungrab_pointer (display, time);
510 XUngrabPointer (xdisplay, time);
513 GDK_DISPLAY_X11 (display)->pointer_xgrab_window = NULL;
517 * gdk_display_pointer_is_grabbed:
518 * @display: a #GdkDisplay
520 * Test if the pointer is grabbed.
522 * Returns: %TRUE if an active X pointer grab is in effect
527 gdk_display_pointer_is_grabbed (GdkDisplay * display)
529 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
531 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL);
535 * gdk_display_keyboard_ungrab:
536 * @display: a #GdkDisplay.
537 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
539 * Release any keyboard grab
544 gdk_display_keyboard_ungrab (GdkDisplay *display,
549 g_return_if_fail (GDK_IS_DISPLAY (display));
551 xdisplay = GDK_DISPLAY_XDISPLAY (display);
553 XUngrabKeyboard (xdisplay, time);
556 GDK_DISPLAY_X11 (display)->keyboard_xgrab_window = NULL;
561 * @display: a #GdkDisplay
563 * Emits a short beep on @display
568 gdk_display_beep (GdkDisplay * display)
570 g_return_if_fail (GDK_IS_DISPLAY (display));
572 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
577 * @display: a #GdkDisplay
579 * Flushes any requests queued for the windowing system and waits until all
580 * requests have been handled. This is often used for making sure that the
581 * display is synchronized with the current state of the program. Calling
582 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
583 * generated from earlier requests are handled before the error trap is
586 * This is most useful for X11. On windowing systems where requests are
587 * handled synchronously, this function will do nothing.
592 gdk_display_sync (GdkDisplay * display)
594 g_return_if_fail (GDK_IS_DISPLAY (display));
596 XSync (GDK_DISPLAY_XDISPLAY (display), False);
601 * @display: a #GdkDisplay
603 * Flushes any requests queued for the windowing system; this happens automatically
604 * when the main loop blocks waiting for new events, but if your application
605 * is drawing without returning control to the main loop, you may need
606 * to call this function explicitely. A common case where this function
607 * needs to be called is when an application is executing drawing commands
608 * from a thread other than the thread where the main loop is running.
610 * This is most useful for X11. On windowing systems where requests are
611 * handled synchronously, this function will do nothing.
616 gdk_display_flush (GdkDisplay *display)
618 g_return_if_fail (GDK_IS_DISPLAY (display));
620 if (!display->closed)
621 XFlush (GDK_DISPLAY_XDISPLAY (display));
625 * gdk_display_get_default_group:
626 * @display: a #GdkDisplay
628 * Returns the default group leader window for all toplevel windows
629 * on @display. This window is implicitly created by GDK.
630 * See gdk_window_set_group().
632 * Return value: The default group leader window for @display
636 GdkWindow *gdk_display_get_default_group (GdkDisplay *display)
638 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
640 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
644 * gdk_x11_display_grab:
645 * @display: a #GdkDisplay
647 * Call XGrabServer() on @display.
648 * To ungrab the display again, use gdk_x11_display_ungrab().
650 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
655 gdk_x11_display_grab (GdkDisplay * display)
657 GdkDisplayX11 *display_x11;
659 g_return_if_fail (GDK_IS_DISPLAY (display));
661 display_x11 = GDK_DISPLAY_X11 (display);
663 if (display_x11->grab_count == 0)
664 XGrabServer (display_x11->xdisplay);
665 display_x11->grab_count++;
669 * gdk_x11_display_ungrab:
670 * @display: a #GdkDisplay
672 * Ungrab @display after it has been grabbed with
673 * gdk_x11_display_grab().
678 gdk_x11_display_ungrab (GdkDisplay * display)
680 GdkDisplayX11 *display_x11;
682 g_return_if_fail (GDK_IS_DISPLAY (display));
684 display_x11 = GDK_DISPLAY_X11 (display);;
685 g_return_if_fail (display_x11->grab_count > 0);
687 display_x11->grab_count--;
688 if (display_x11->grab_count == 0)
690 XUngrabServer (display_x11->xdisplay);
691 XFlush (display_x11->xdisplay);
696 gdk_display_x11_dispose (GObject *object)
698 GdkDisplayX11 *display_x11;
701 display_x11 = GDK_DISPLAY_X11 (object);
703 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
704 _gdk_screen_close (display_x11->screens[i]);
706 g_source_destroy (display_x11->event_source);
708 XCloseDisplay (display_x11->xdisplay);
709 display_x11->xdisplay = NULL;
711 G_OBJECT_CLASS (parent_class)->dispose (object);
715 gdk_display_x11_finalize (GObject *object)
717 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
720 /* FIXME need to write GdkKeymap finalize fct
721 g_object_unref (display_x11->keymap);
724 if (display_x11->motif_target_lists)
726 for (i = 0; i < display_x11->motif_n_target_lists; i++)
727 g_list_free (display_x11->motif_target_lists[i]);
728 g_free (display_x11->motif_target_lists);
732 g_hash_table_destroy (display_x11->atom_from_virtual);
733 g_hash_table_destroy (display_x11->atom_to_virtual);
735 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
736 /* list of filters for client messages */
737 g_list_free (display_x11->client_filters);
738 /* List of event window extraction functions */
739 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
740 g_slist_free (display_x11->event_types);
742 g_hash_table_destroy (display_x11->xid_ht);
743 /* input GdkDevice list */
744 /* FIXME need to write finalize fct */
745 for (tmp = display_x11->input_devices; tmp; tmp = tmp->next)
746 g_object_unref (tmp->data);
747 g_list_free (display_x11->input_devices);
748 /* input GdkWindow list */
749 for (tmp = display_x11->input_windows; tmp; tmp = tmp->next)
750 g_object_unref (tmp->data);
751 g_list_free (display_x11->input_windows);
752 /* Free all GdkScreens */
753 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
754 g_object_unref (display_x11->screens[i]);
755 g_free (display_x11->screens);
756 g_free (display_x11->startup_notification_id);
758 G_OBJECT_CLASS (parent_class)->finalize (object);
762 * gdk_x11_lookup_xdisplay:
763 * @xdisplay: a pointer to an X Display
765 * Find the #GdkDisplay corresponding to @display, if any exists.
767 * Return value: the #GdkDisplay, if found, otherwise %NULL.
772 gdk_x11_lookup_xdisplay (Display *xdisplay)
776 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
778 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
779 return tmp_list->data;
786 * _gdk_x11_display_screen_for_xrootwin:
787 * @display: a #Display
788 * @xrootwin: window ID for one of of the screen's of the display.
790 * Given the root window ID of one of the screen's of a #GdkDisplay,
793 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
796 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
801 n_screens = gdk_display_get_n_screens (display);
802 for (i = 0; i < n_screens; i++)
804 GdkScreen *screen = gdk_display_get_screen (display, i);
805 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
813 * gdk_x11_display_get_xdisplay:
814 * @display: a #GdkDisplay
815 * @returns: an X display.
817 * Returns the X display of a #GdkDisplay.
822 gdk_x11_display_get_xdisplay (GdkDisplay *display)
824 return GDK_DISPLAY_X11 (display)->xdisplay;
828 _gdk_windowing_set_default_display (GdkDisplay *display)
830 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
831 const gchar *startup_id;
834 gdk_display = GDK_DISPLAY_XDISPLAY (display);
838 g_free (display_x11->startup_notification_id);
839 display_x11->startup_notification_id = NULL;
841 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
842 if (startup_id && *startup_id != '\0')
844 if (!g_utf8_validate (startup_id, -1, NULL))
845 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
847 display_x11->startup_notification_id = g_strdup (startup_id);
849 /* Clear the environment variable so it won't be inherited by
850 * child processes and confuse things.
852 g_unsetenv ("DESKTOP_STARTUP_ID");
854 /* Set the startup id on the leader window so it
855 * applies to all windows we create on this display
857 XChangeProperty (display_x11->xdisplay,
858 display_x11->leader_window,
859 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
860 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
862 startup_id, strlen (startup_id));
867 escape_for_xmessage (const char *str)
872 retval = g_string_new (NULL);
882 g_string_append_c (retval, '\\');
886 g_string_append_c (retval, *p);
890 return g_string_free (retval, FALSE);
894 broadcast_xmessage (GdkDisplay *display,
895 const char *message_type,
896 const char *message_type_begin,
899 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
900 GdkScreen *screen = gdk_display_get_default_screen (display);
901 GdkWindow *root_window = gdk_screen_get_root_window (screen);
902 Window xroot_window = GDK_WINDOW_XID (root_window);
905 Atom type_atom_begin;
909 XSetWindowAttributes attrs;
911 attrs.override_redirect = True;
912 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
915 XCreateWindow (xdisplay,
921 (Visual *)CopyFromParent,
922 CWOverrideRedirect | CWEventMask,
926 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
928 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
938 xevent.xclient.type = ClientMessage;
939 xevent.xclient.message_type = type_atom_begin;
940 xevent.xclient.display =xdisplay;
941 xevent.xclient.window = xwindow;
942 xevent.xclient.format = 8;
945 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
947 while (src != src_end)
949 dest = &xevent.xclient.data.b[0];
950 dest_end = dest + 20;
952 while (dest != dest_end &&
960 while (dest != dest_end)
966 XSendEvent (xdisplay,
972 xevent.xclient.message_type = type_atom;
976 XDestroyWindow (xdisplay, xwindow);
981 * gdk_notify_startup_complete:
983 * Indicates to the GUI environment that the application has finished
984 * loading. If the applications opens windows, this function is
985 * normally called after opening the application's initial set of
988 * GTK+ will call this function automatically after opening the first
989 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
990 * to disable that feature.
995 gdk_notify_startup_complete (void)
998 GdkDisplayX11 *display_x11;
1002 display = gdk_display_get_default ();
1006 display_x11 = GDK_DISPLAY_X11 (display);
1008 if (display_x11->startup_notification_id == NULL)
1011 escaped_id = escape_for_xmessage (display_x11->startup_notification_id);
1012 message = g_strdup_printf ("remove: ID=%s", escaped_id);
1013 g_free (escaped_id);
1015 broadcast_xmessage (display,
1016 "_NET_STARTUP_INFO",
1017 "_NET_STARTUP_INFO_BEGIN",
1025 * gdk_display_supports_selection_notification:
1026 * @display: a #GdkDisplay
1028 * Returns whether #GdkEventOwnerChange events will be
1029 * sent when the owner of a selection changes.
1031 * Return value: whether #GdkEventOwnerChange events will
1037 gdk_display_supports_selection_notification (GdkDisplay *display)
1039 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1041 return display_x11->have_xfixes;
1045 * gdk_display_request_selection_notification:
1046 * @display: a #GdkDisplay
1047 * @selection: the #GdkAtom naming the selection for which
1048 * ownership change notification is requested
1050 * Request #GdkEventOwnerChange events for ownership changes
1051 * of the selection named by the given atom.
1053 * Return value: whether #GdkEventOwnerChange events will
1058 gboolean gdk_display_request_selection_notification (GdkDisplay *display,
1063 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1066 if (display_x11->have_xfixes)
1068 atom = gdk_x11_atom_to_xatom_for_display (display,
1070 XFixesSelectSelectionInput (display_x11->xdisplay,
1071 display_x11->leader_window,
1073 XFixesSetSelectionOwnerNotifyMask |
1074 XFixesSelectionWindowDestroyNotifyMask |
1075 XFixesSelectionClientCloseNotifyMask);
1084 * gdk_display_supports_clipboard_persistence
1085 * @display: a #GdkDisplay
1087 * Returns whether the speicifed display supports clipboard
1088 * persistance; i.e. if it's possible to store the clipboard data after an
1089 * application has quit. On X11 this checks if a clipboard daemon is
1092 * Returns: %TRUE if the display supports clipboard persistance.
1097 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1099 /* It might make sense to cache this */
1100 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay,
1101 gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER")) != None;
1105 * gdk_display_store_clipboard
1106 * @display: a #GdkDisplay
1107 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1108 * @time_: a timestamp
1109 * @targets: an array of targets that should be saved, or %NULL
1110 * if all available targets should be saved.
1111 * @n_targets: length of the @targets array
1113 * Issues a request to the the clipboard manager to store the
1114 * clipboard data. On X11, this is a special program that works
1115 * according to the freedesktop clipboard specification, available at
1116 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1117 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1122 gdk_display_store_clipboard (GdkDisplay *display,
1123 GdkWindow *clipboard_window,
1128 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1129 Atom clipboard_manager, save_targets;
1131 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1132 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1134 gdk_error_trap_push ();
1136 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1138 Atom property_name = None;
1144 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1146 xatoms = g_new (Atom, n_targets);
1147 for (i = 0; i < n_targets; i++)
1148 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1150 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1151 property_name, XA_ATOM,
1152 32, PropModeReplace, (guchar *)xatoms, n_targets);
1157 XConvertSelection (display_x11->xdisplay,
1158 clipboard_manager, save_targets, property_name,
1159 GDK_WINDOW_XID (clipboard_window), time_);
1162 gdk_error_trap_pop ();
1167 * gdk_x11_display_get_user_time:
1168 * @display: a #GdkDisplay
1170 * Returns the timestamp of the last user interaction on
1171 * @display. The timestamp is taken from events caused
1172 * by user interaction such as key presses or pointer
1173 * movements. See gdk_x11_window_set_user_time().
1175 * Returns: the timestamp of the last user interaction
1180 gdk_x11_display_get_user_time (GdkDisplay *display)
1182 return GDK_DISPLAY_X11 (display)->user_time;