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,
118 g_intern_static_string ("GdkDisplayX11"),
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;
213 if (XFixesQueryExtension (display_x11->xdisplay,
214 &display_x11->xfixes_event_base,
217 display_x11->have_xfixes = TRUE;
219 gdk_x11_register_standard_event_type (display,
220 display_x11->xfixes_event_base,
225 display_x11->have_xfixes = FALSE;
227 if (_gdk_synchronize)
228 XSynchronize (display_x11->xdisplay, True);
230 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
232 class_hint = XAllocClassHint();
233 class_hint->res_name = g_get_prgname ();
235 class_hint->res_class = (char *)gdk_get_program_class ();
237 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
238 * from argv[0], so we just synthesize an argument array here.
241 argv[0] = g_get_prgname ();
243 XmbSetWMProperties (display_x11->xdisplay,
244 display_x11->leader_window,
245 NULL, NULL, argv, argc, NULL, NULL,
249 sm_client_id = _gdk_get_sm_client_id ();
251 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
254 XChangeProperty (display_x11->xdisplay,
255 display_x11->leader_window,
256 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
257 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
259 /* We don't yet know a valid time. */
260 display_x11->user_time = 0;
264 gint xkb_major = XkbMajorVersion;
265 gint xkb_minor = XkbMinorVersion;
266 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
268 xkb_major = XkbMajorVersion;
269 xkb_minor = XkbMinorVersion;
271 if (XkbQueryExtension (display_x11->xdisplay,
272 NULL, &display_x11->xkb_event_type, NULL,
273 &xkb_major, &xkb_minor))
275 Bool detectable_autorepeat_supported;
277 display_x11->use_xkb = TRUE;
279 XkbSelectEvents (display_x11->xdisplay,
281 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
282 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
284 /* keep this in sync with _gdk_keymap_state_changed() */
285 XkbSelectEventDetails (display_x11->xdisplay,
286 XkbUseCoreKbd, XkbStateNotify,
287 XkbGroupLockMask, XkbGroupLockMask);
289 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
291 &detectable_autorepeat_supported);
293 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
294 detectable_autorepeat_supported ?
295 "supported" : "not supported"));
297 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
303 display_x11->use_sync = FALSE;
307 int error_base, event_base;
309 if (XSyncQueryExtension (display_x11->xdisplay,
310 &event_base, &error_base) &&
311 XSyncInitialize (display_x11->xdisplay,
313 display_x11->use_sync = TRUE;
317 _gdk_windowing_image_init (display);
318 _gdk_events_init (display);
319 _gdk_input_init (display);
320 _gdk_dnd_init (display);
322 g_signal_emit_by_name (gdk_display_manager_get(),
323 "display_opened", display);
330 * XLib internal connection handling
332 typedef struct _GdkInternalConnection GdkInternalConnection;
334 struct _GdkInternalConnection
342 process_internal_connection (GIOChannel *gioc,
346 GdkInternalConnection *connection = (GdkInternalConnection *)data;
348 GDK_THREADS_ENTER ();
350 XProcessInternalConnection ((Display*)connection->display, connection->fd);
352 GDK_THREADS_LEAVE ();
357 static GdkInternalConnection *
358 gdk_add_connection_handler (Display *display,
361 GIOChannel *io_channel;
362 GdkInternalConnection *connection;
364 connection = g_new (GdkInternalConnection, 1);
367 connection->display = display;
369 io_channel = g_io_channel_unix_new (fd);
371 connection->source = g_io_create_watch (io_channel, G_IO_IN);
372 g_source_set_callback (connection->source,
373 (GSourceFunc)process_internal_connection, connection, NULL);
374 g_source_attach (connection->source, NULL);
376 g_io_channel_unref (io_channel);
382 gdk_remove_connection_handler (GdkInternalConnection *connection)
384 g_source_destroy (connection->source);
389 gdk_internal_connection_watch (Display *display,
393 XPointer *watch_data)
396 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
398 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
400 #endif /* HAVE_X11R6 */
403 * gdk_display_get_name:
404 * @display: a #GdkDisplay
406 * Gets the name of the display.
408 * Returns: a string representing the display name. This string is owned
409 * by GDK and should not be modified or freed.
413 G_CONST_RETURN gchar *
414 gdk_display_get_name (GdkDisplay * display)
416 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
418 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
422 * gdk_display_get_n_screens:
423 * @display: a #GdkDisplay
425 * Gets the number of screen managed by the @display.
427 * Returns: number of screens.
432 gdk_display_get_n_screens (GdkDisplay * display)
434 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
436 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
440 * gdk_display_get_screen:
441 * @display: a #GdkDisplay
442 * @screen_num: the screen number
444 * Returns a screen object for one of the screens of the display.
446 * Returns: the #GdkScreen object
451 gdk_display_get_screen (GdkDisplay * display, gint screen_num)
453 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
454 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
456 return GDK_DISPLAY_X11 (display)->screens[screen_num];
460 * gdk_display_get_default_screen:
461 * @display: a #GdkDisplay
463 * Get the default #GdkScreen for @display.
465 * Returns: the default #GdkScreen object for @display
470 gdk_display_get_default_screen (GdkDisplay * display)
472 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
474 return GDK_DISPLAY_X11 (display)->default_screen;
478 _gdk_x11_display_is_root_window (GdkDisplay *display,
481 GdkDisplayX11 *display_x11;
484 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
486 display_x11 = GDK_DISPLAY_X11 (display);
488 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
490 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
496 #define XSERVER_TIME_IS_LATER(time1, time2) \
497 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
498 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
502 * gdk_display_pointer_ungrab:
503 * @display: a #GdkDisplay.
504 * @time_: a timestap (e.g. GDK_CURRENT_TIME).
506 * Release any pointer grab.
511 gdk_display_pointer_ungrab (GdkDisplay *display,
515 GdkDisplayX11 *display_x11;
517 g_return_if_fail (GDK_IS_DISPLAY (display));
519 display_x11 = GDK_DISPLAY_X11 (display);
520 xdisplay = GDK_DISPLAY_XDISPLAY (display);
522 _gdk_input_ungrab_pointer (display, time);
523 XUngrabPointer (xdisplay, time);
526 if (time == GDK_CURRENT_TIME ||
527 display_x11->pointer_xgrab_time == GDK_CURRENT_TIME ||
528 !XSERVER_TIME_IS_LATER (display_x11->pointer_xgrab_time, time))
529 display_x11->pointer_xgrab_window = NULL;
533 * gdk_display_pointer_is_grabbed:
534 * @display: a #GdkDisplay
536 * Test if the pointer is grabbed.
538 * Returns: %TRUE if an active X pointer grab is in effect
543 gdk_display_pointer_is_grabbed (GdkDisplay * display)
545 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
547 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL &&
548 !GDK_DISPLAY_X11 (display)->pointer_xgrab_implicit);
552 * gdk_display_keyboard_ungrab:
553 * @display: a #GdkDisplay.
554 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
556 * Release any keyboard grab
561 gdk_display_keyboard_ungrab (GdkDisplay *display,
565 GdkDisplayX11 *display_x11;
567 g_return_if_fail (GDK_IS_DISPLAY (display));
569 display_x11 = GDK_DISPLAY_X11 (display);
570 xdisplay = GDK_DISPLAY_XDISPLAY (display);
572 XUngrabKeyboard (xdisplay, time);
575 if (time == GDK_CURRENT_TIME ||
576 display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
577 !XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
578 display_x11->keyboard_xgrab_window = NULL;
583 * @display: a #GdkDisplay
585 * Emits a short beep on @display
590 gdk_display_beep (GdkDisplay * display)
592 g_return_if_fail (GDK_IS_DISPLAY (display));
594 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
599 * @display: a #GdkDisplay
601 * Flushes any requests queued for the windowing system and waits until all
602 * requests have been handled. This is often used for making sure that the
603 * display is synchronized with the current state of the program. Calling
604 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
605 * generated from earlier requests are handled before the error trap is
608 * This is most useful for X11. On windowing systems where requests are
609 * handled synchronously, this function will do nothing.
614 gdk_display_sync (GdkDisplay * display)
616 g_return_if_fail (GDK_IS_DISPLAY (display));
618 XSync (GDK_DISPLAY_XDISPLAY (display), False);
623 * @display: a #GdkDisplay
625 * Flushes any requests queued for the windowing system; this happens automatically
626 * when the main loop blocks waiting for new events, but if your application
627 * is drawing without returning control to the main loop, you may need
628 * to call this function explicitely. A common case where this function
629 * needs to be called is when an application is executing drawing commands
630 * from a thread other than the thread where the main loop is running.
632 * This is most useful for X11. On windowing systems where requests are
633 * handled synchronously, this function will do nothing.
638 gdk_display_flush (GdkDisplay *display)
640 g_return_if_fail (GDK_IS_DISPLAY (display));
642 if (!display->closed)
643 XFlush (GDK_DISPLAY_XDISPLAY (display));
647 * gdk_display_get_default_group:
648 * @display: a #GdkDisplay
650 * Returns the default group leader window for all toplevel windows
651 * on @display. This window is implicitly created by GDK.
652 * See gdk_window_set_group().
654 * Return value: The default group leader window for @display
658 GdkWindow *gdk_display_get_default_group (GdkDisplay *display)
660 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
662 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
666 * gdk_x11_display_grab:
667 * @display: a #GdkDisplay
669 * Call XGrabServer() on @display.
670 * To ungrab the display again, use gdk_x11_display_ungrab().
672 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
677 gdk_x11_display_grab (GdkDisplay * display)
679 GdkDisplayX11 *display_x11;
681 g_return_if_fail (GDK_IS_DISPLAY (display));
683 display_x11 = GDK_DISPLAY_X11 (display);
685 if (display_x11->grab_count == 0)
686 XGrabServer (display_x11->xdisplay);
687 display_x11->grab_count++;
691 * gdk_x11_display_ungrab:
692 * @display: a #GdkDisplay
694 * Ungrab @display after it has been grabbed with
695 * gdk_x11_display_grab().
700 gdk_x11_display_ungrab (GdkDisplay * display)
702 GdkDisplayX11 *display_x11;
704 g_return_if_fail (GDK_IS_DISPLAY (display));
706 display_x11 = GDK_DISPLAY_X11 (display);;
707 g_return_if_fail (display_x11->grab_count > 0);
709 display_x11->grab_count--;
710 if (display_x11->grab_count == 0)
712 XUngrabServer (display_x11->xdisplay);
713 XFlush (display_x11->xdisplay);
718 gdk_display_x11_dispose (GObject *object)
720 GdkDisplayX11 *display_x11;
723 display_x11 = GDK_DISPLAY_X11 (object);
725 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
726 _gdk_screen_close (display_x11->screens[i]);
728 g_source_destroy (display_x11->event_source);
730 XCloseDisplay (display_x11->xdisplay);
731 display_x11->xdisplay = NULL;
733 G_OBJECT_CLASS (parent_class)->dispose (object);
737 gdk_display_x11_finalize (GObject *object)
739 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
742 /* FIXME need to write GdkKeymap finalize fct
743 g_object_unref (display_x11->keymap);
746 if (display_x11->motif_target_lists)
748 for (i = 0; i < display_x11->motif_n_target_lists; i++)
749 g_list_free (display_x11->motif_target_lists[i]);
750 g_free (display_x11->motif_target_lists);
754 g_hash_table_destroy (display_x11->atom_from_virtual);
755 g_hash_table_destroy (display_x11->atom_to_virtual);
757 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
758 /* list of filters for client messages */
759 g_list_free (display_x11->client_filters);
760 /* List of event window extraction functions */
761 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
762 g_slist_free (display_x11->event_types);
764 g_hash_table_destroy (display_x11->xid_ht);
765 /* input GdkDevice list */
766 /* FIXME need to write finalize fct */
767 for (tmp = display_x11->input_devices; tmp; tmp = tmp->next)
768 g_object_unref (tmp->data);
769 g_list_free (display_x11->input_devices);
770 /* input GdkWindow list */
771 for (tmp = display_x11->input_windows; tmp; tmp = tmp->next)
772 g_object_unref (tmp->data);
773 g_list_free (display_x11->input_windows);
774 /* Free all GdkScreens */
775 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
776 g_object_unref (display_x11->screens[i]);
777 g_free (display_x11->screens);
778 g_free (display_x11->startup_notification_id);
780 G_OBJECT_CLASS (parent_class)->finalize (object);
784 * gdk_x11_lookup_xdisplay:
785 * @xdisplay: a pointer to an X Display
787 * Find the #GdkDisplay corresponding to @display, if any exists.
789 * Return value: the #GdkDisplay, if found, otherwise %NULL.
794 gdk_x11_lookup_xdisplay (Display *xdisplay)
798 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
800 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
801 return tmp_list->data;
808 * _gdk_x11_display_screen_for_xrootwin:
809 * @display: a #Display
810 * @xrootwin: window ID for one of of the screen's of the display.
812 * Given the root window ID of one of the screen's of a #GdkDisplay,
815 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
818 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
823 n_screens = gdk_display_get_n_screens (display);
824 for (i = 0; i < n_screens; i++)
826 GdkScreen *screen = gdk_display_get_screen (display, i);
827 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
835 * gdk_x11_display_get_xdisplay:
836 * @display: a #GdkDisplay
837 * @returns: an X display.
839 * Returns the X display of a #GdkDisplay.
844 gdk_x11_display_get_xdisplay (GdkDisplay *display)
846 return GDK_DISPLAY_X11 (display)->xdisplay;
850 _gdk_windowing_set_default_display (GdkDisplay *display)
852 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
853 const gchar *startup_id;
856 gdk_display = GDK_DISPLAY_XDISPLAY (display);
860 g_free (display_x11->startup_notification_id);
861 display_x11->startup_notification_id = NULL;
863 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
864 if (startup_id && *startup_id != '\0')
868 if (!g_utf8_validate (startup_id, -1, NULL))
869 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
871 display_x11->startup_notification_id = g_strdup (startup_id);
873 /* Find the launch time from the startup_id, if it's there. Newer spec
874 * states that the startup_id is of the form <unique>_TIME<timestamp>
876 time_str = g_strrstr (startup_id, "_TIME");
877 if (time_str != NULL)
883 /* Skip past the "_TIME" part */
886 retval = strtoul (time_str, &end, 0);
887 if (end != time_str && errno == 0)
888 display_x11->user_time = retval;
891 /* Clear the environment variable so it won't be inherited by
892 * child processes and confuse things.
894 g_unsetenv ("DESKTOP_STARTUP_ID");
896 /* Set the startup id on the leader window so it
897 * applies to all windows we create on this display
899 XChangeProperty (display_x11->xdisplay,
900 display_x11->leader_window,
901 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
902 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
904 (guchar *)startup_id, strlen (startup_id));
909 escape_for_xmessage (const char *str)
914 retval = g_string_new (NULL);
924 g_string_append_c (retval, '\\');
928 g_string_append_c (retval, *p);
932 return g_string_free (retval, FALSE);
936 broadcast_xmessage (GdkDisplay *display,
937 const char *message_type,
938 const char *message_type_begin,
941 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
942 GdkScreen *screen = gdk_display_get_default_screen (display);
943 GdkWindow *root_window = gdk_screen_get_root_window (screen);
944 Window xroot_window = GDK_WINDOW_XID (root_window);
947 Atom type_atom_begin;
951 XSetWindowAttributes attrs;
953 attrs.override_redirect = True;
954 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
957 XCreateWindow (xdisplay,
963 (Visual *)CopyFromParent,
964 CWOverrideRedirect | CWEventMask,
968 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
970 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
980 xevent.xclient.type = ClientMessage;
981 xevent.xclient.message_type = type_atom_begin;
982 xevent.xclient.display =xdisplay;
983 xevent.xclient.window = xwindow;
984 xevent.xclient.format = 8;
987 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
989 while (src != src_end)
991 dest = &xevent.xclient.data.b[0];
992 dest_end = dest + 20;
994 while (dest != dest_end &&
1002 while (dest != dest_end)
1008 XSendEvent (xdisplay,
1014 xevent.xclient.message_type = type_atom;
1018 XDestroyWindow (xdisplay, xwindow);
1023 * gdk_notify_startup_complete:
1025 * Indicates to the GUI environment that the application has finished
1026 * loading. If the applications opens windows, this function is
1027 * normally called after opening the application's initial set of
1030 * GTK+ will call this function automatically after opening the first
1031 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1032 * to disable that feature.
1037 gdk_notify_startup_complete (void)
1039 GdkDisplay *display;
1040 GdkDisplayX11 *display_x11;
1044 display = gdk_display_get_default ();
1048 display_x11 = GDK_DISPLAY_X11 (display);
1050 if (display_x11->startup_notification_id == NULL)
1053 escaped_id = escape_for_xmessage (display_x11->startup_notification_id);
1054 message = g_strdup_printf ("remove: ID=%s", escaped_id);
1055 g_free (escaped_id);
1057 broadcast_xmessage (display,
1058 "_NET_STARTUP_INFO",
1059 "_NET_STARTUP_INFO_BEGIN",
1067 * gdk_display_supports_selection_notification:
1068 * @display: a #GdkDisplay
1070 * Returns whether #GdkEventOwnerChange events will be
1071 * sent when the owner of a selection changes.
1073 * Return value: whether #GdkEventOwnerChange events will
1079 gdk_display_supports_selection_notification (GdkDisplay *display)
1081 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1083 return display_x11->have_xfixes;
1087 * gdk_display_request_selection_notification:
1088 * @display: a #GdkDisplay
1089 * @selection: the #GdkAtom naming the selection for which
1090 * ownership change notification is requested
1092 * Request #GdkEventOwnerChange events for ownership changes
1093 * of the selection named by the given atom.
1095 * Return value: whether #GdkEventOwnerChange events will
1100 gboolean gdk_display_request_selection_notification (GdkDisplay *display,
1105 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1108 if (display_x11->have_xfixes)
1110 atom = gdk_x11_atom_to_xatom_for_display (display,
1112 XFixesSelectSelectionInput (display_x11->xdisplay,
1113 display_x11->leader_window,
1115 XFixesSetSelectionOwnerNotifyMask |
1116 XFixesSelectionWindowDestroyNotifyMask |
1117 XFixesSelectionClientCloseNotifyMask);
1126 * gdk_display_supports_clipboard_persistence
1127 * @display: a #GdkDisplay
1129 * Returns whether the speicifed display supports clipboard
1130 * persistance; i.e. if it's possible to store the clipboard data after an
1131 * application has quit. On X11 this checks if a clipboard daemon is
1134 * Returns: %TRUE if the display supports clipboard persistance.
1139 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1141 /* It might make sense to cache this */
1142 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay,
1143 gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER")) != None;
1147 * gdk_display_store_clipboard
1148 * @display: a #GdkDisplay
1149 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1150 * @time_: a timestamp
1151 * @targets: an array of targets that should be saved, or %NULL
1152 * if all available targets should be saved.
1153 * @n_targets: length of the @targets array
1155 * Issues a request to the clipboard manager to store the
1156 * clipboard data. On X11, this is a special program that works
1157 * according to the freedesktop clipboard specification, available at
1158 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1159 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1164 gdk_display_store_clipboard (GdkDisplay *display,
1165 GdkWindow *clipboard_window,
1170 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1171 Atom clipboard_manager, save_targets;
1173 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1174 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1176 gdk_error_trap_push ();
1178 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1180 Atom property_name = None;
1186 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1188 xatoms = g_new (Atom, n_targets);
1189 for (i = 0; i < n_targets; i++)
1190 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1192 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1193 property_name, XA_ATOM,
1194 32, PropModeReplace, (guchar *)xatoms, n_targets);
1199 XConvertSelection (display_x11->xdisplay,
1200 clipboard_manager, save_targets, property_name,
1201 GDK_WINDOW_XID (clipboard_window), time_);
1204 gdk_error_trap_pop ();
1209 * gdk_x11_display_get_user_time:
1210 * @display: a #GdkDisplay
1212 * Returns the timestamp of the last user interaction on
1213 * @display. The timestamp is taken from events caused
1214 * by user interaction such as key presses or pointer
1215 * movements. See gdk_x11_window_set_user_time().
1217 * Returns: the timestamp of the last user interaction
1222 gdk_x11_display_get_user_time (GdkDisplay *display)
1224 return GDK_DISPLAY_X11 (display)->user_time;
1227 #define __GDK_DISPLAY_X11_C__
1228 #include "gdkaliasdef.c"