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>
58 static void gdk_display_x11_dispose (GObject *object);
59 static void gdk_display_x11_finalize (GObject *object);
62 static void gdk_internal_connection_watch (Display *display,
66 XPointer *watch_data);
67 #endif /* HAVE_X11R6 */
69 /* Note that we never *directly* use WM_LOCALE_NAME, WM_PROTOCOLS,
70 * but including them here has the side-effect of getting them
71 * into the internal Xlib cache
73 static const char *const precache_atoms[] = {
87 "_NET_WM_STATE_STICKY",
88 "_NET_WM_STATE_MAXIMIZED_VERT",
89 "_NET_WM_STATE_MAXIMIZED_HORZ",
90 "_NET_WM_STATE_FULLSCREEN",
91 "_NET_WM_SYNC_REQUEST",
92 "_NET_WM_SYNC_REQUEST_COUNTER",
93 "_NET_WM_WINDOW_TYPE",
94 "_NET_WM_WINDOW_TYPE_NORMAL",
99 G_DEFINE_TYPE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY);
102 _gdk_display_x11_class_init (GdkDisplayX11Class * class)
104 GObjectClass *object_class = G_OBJECT_CLASS (class);
106 object_class->dispose = gdk_display_x11_dispose;
107 object_class->finalize = gdk_display_x11_finalize;
111 _gdk_display_x11_init (GdkDisplayX11 *display)
117 * @display_name: the name of the display to open
118 * @returns: a #GdkDisplay, or %NULL if the display
119 * could not be opened.
126 gdk_display_open (const gchar *display_name)
130 GdkDisplayX11 *display_x11;
134 const char *sm_client_id;
136 XClassHint *class_hint;
139 #if defined(HAVE_XFIXES) || defined(HAVE_SHAPE_EXT)
144 xdisplay = XOpenDisplay (display_name);
148 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
149 display_x11 = GDK_DISPLAY_X11 (display);
151 display_x11->use_xshm = TRUE;
152 display_x11->xdisplay = xdisplay;
155 /* Set up handlers for Xlib internal connections */
156 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
157 #endif /* HAVE_X11R6 */
159 /* initialize the display's screens */
160 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
161 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
162 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
164 /* We need to initialize events after we have the screen
165 * structures in places
167 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
168 _gdk_x11_events_init_screen (display_x11->screens[i]);
170 /*set the default screen */
171 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
173 attr.window_type = GDK_WINDOW_TOPLEVEL;
174 attr.wclass = GDK_INPUT_OUTPUT;
181 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
183 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
184 &attr, GDK_WA_X | GDK_WA_Y);
185 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
187 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
189 display_x11->leader_window_title_set = FALSE;
191 display_x11->have_render = GDK_UNKNOWN;
194 if (XFixesQueryExtension (display_x11->xdisplay,
195 &display_x11->xfixes_event_base,
198 display_x11->have_xfixes = TRUE;
200 gdk_x11_register_standard_event_type (display,
201 display_x11->xfixes_event_base,
206 display_x11->have_xfixes = FALSE;
208 display_x11->have_shapes = FALSE;
209 display_x11->have_input_shapes = FALSE;
210 #ifdef HAVE_SHAPE_EXT
211 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &ignore, &ignore))
213 display_x11->have_shapes = TRUE;
215 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
216 display_x11->have_input_shapes = (maj == 1 && min >= 1);
221 if (_gdk_synchronize)
222 XSynchronize (display_x11->xdisplay, True);
224 class_hint = XAllocClassHint();
225 class_hint->res_name = g_get_prgname ();
227 class_hint->res_class = (char *)gdk_get_program_class ();
229 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
230 * from argv[0], so we just synthesize an argument array here.
233 argv[0] = g_get_prgname ();
235 XmbSetWMProperties (display_x11->xdisplay,
236 display_x11->leader_window,
237 NULL, NULL, argv, argc, NULL, NULL,
241 sm_client_id = _gdk_get_sm_client_id ();
243 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
246 XChangeProperty (display_x11->xdisplay,
247 display_x11->leader_window,
248 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
249 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
251 /* We don't yet know a valid time. */
252 display_x11->user_time = 0;
256 gint xkb_major = XkbMajorVersion;
257 gint xkb_minor = XkbMinorVersion;
258 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
260 xkb_major = XkbMajorVersion;
261 xkb_minor = XkbMinorVersion;
263 if (XkbQueryExtension (display_x11->xdisplay,
264 NULL, &display_x11->xkb_event_type, NULL,
265 &xkb_major, &xkb_minor))
267 Bool detectable_autorepeat_supported;
269 display_x11->use_xkb = TRUE;
271 XkbSelectEvents (display_x11->xdisplay,
273 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
274 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
276 /* keep this in sync with _gdk_keymap_state_changed() */
277 XkbSelectEventDetails (display_x11->xdisplay,
278 XkbUseCoreKbd, XkbStateNotify,
279 XkbGroupLockMask, XkbGroupLockMask);
281 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
283 &detectable_autorepeat_supported);
285 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
286 detectable_autorepeat_supported ?
287 "supported" : "not supported"));
289 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
295 display_x11->use_sync = FALSE;
299 int error_base, event_base;
301 if (XSyncQueryExtension (display_x11->xdisplay,
302 &event_base, &error_base) &&
303 XSyncInitialize (display_x11->xdisplay,
305 display_x11->use_sync = TRUE;
309 _gdk_windowing_image_init (display);
310 _gdk_events_init (display);
311 _gdk_input_init (display);
312 _gdk_dnd_init (display);
314 g_signal_emit_by_name (gdk_display_manager_get(),
315 "display_opened", display);
322 * XLib internal connection handling
324 typedef struct _GdkInternalConnection GdkInternalConnection;
326 struct _GdkInternalConnection
334 process_internal_connection (GIOChannel *gioc,
338 GdkInternalConnection *connection = (GdkInternalConnection *)data;
340 GDK_THREADS_ENTER ();
342 XProcessInternalConnection ((Display*)connection->display, connection->fd);
344 GDK_THREADS_LEAVE ();
349 static GdkInternalConnection *
350 gdk_add_connection_handler (Display *display,
353 GIOChannel *io_channel;
354 GdkInternalConnection *connection;
356 connection = g_new (GdkInternalConnection, 1);
359 connection->display = display;
361 io_channel = g_io_channel_unix_new (fd);
363 connection->source = g_io_create_watch (io_channel, G_IO_IN);
364 g_source_set_callback (connection->source,
365 (GSourceFunc)process_internal_connection, connection, NULL);
366 g_source_attach (connection->source, NULL);
368 g_io_channel_unref (io_channel);
374 gdk_remove_connection_handler (GdkInternalConnection *connection)
376 g_source_destroy (connection->source);
381 gdk_internal_connection_watch (Display *display,
385 XPointer *watch_data)
388 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
390 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
392 #endif /* HAVE_X11R6 */
395 * gdk_display_get_name:
396 * @display: a #GdkDisplay
398 * Gets the name of the display.
400 * Returns: a string representing the display name. This string is owned
401 * by GDK and should not be modified or freed.
405 G_CONST_RETURN gchar *
406 gdk_display_get_name (GdkDisplay * display)
408 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
410 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
414 * gdk_display_get_n_screens:
415 * @display: a #GdkDisplay
417 * Gets the number of screen managed by the @display.
419 * Returns: number of screens.
424 gdk_display_get_n_screens (GdkDisplay * display)
426 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
428 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
432 * gdk_display_get_screen:
433 * @display: a #GdkDisplay
434 * @screen_num: the screen number
436 * Returns a screen object for one of the screens of the display.
438 * Returns: the #GdkScreen object
443 gdk_display_get_screen (GdkDisplay * display, gint screen_num)
445 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
446 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
448 return GDK_DISPLAY_X11 (display)->screens[screen_num];
452 * gdk_display_get_default_screen:
453 * @display: a #GdkDisplay
455 * Get the default #GdkScreen for @display.
457 * Returns: the default #GdkScreen object for @display
462 gdk_display_get_default_screen (GdkDisplay * display)
464 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
466 return GDK_DISPLAY_X11 (display)->default_screen;
470 _gdk_x11_display_is_root_window (GdkDisplay *display,
473 GdkDisplayX11 *display_x11;
476 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
478 display_x11 = GDK_DISPLAY_X11 (display);
480 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
482 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
488 #define XSERVER_TIME_IS_LATER(time1, time2) \
489 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
490 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
494 * gdk_display_pointer_ungrab:
495 * @display: a #GdkDisplay.
496 * @time_: a timestap (e.g. GDK_CURRENT_TIME).
498 * Release any pointer grab.
503 gdk_display_pointer_ungrab (GdkDisplay *display,
507 GdkDisplayX11 *display_x11;
509 g_return_if_fail (GDK_IS_DISPLAY (display));
511 display_x11 = GDK_DISPLAY_X11 (display);
512 xdisplay = GDK_DISPLAY_XDISPLAY (display);
514 _gdk_input_ungrab_pointer (display, time);
515 XUngrabPointer (xdisplay, time);
518 if (time == GDK_CURRENT_TIME ||
519 display_x11->pointer_xgrab_time == GDK_CURRENT_TIME ||
520 !XSERVER_TIME_IS_LATER (display_x11->pointer_xgrab_time, time))
521 display_x11->pointer_xgrab_window = NULL;
525 * gdk_display_pointer_is_grabbed:
526 * @display: a #GdkDisplay
528 * Test if the pointer is grabbed.
530 * Returns: %TRUE if an active X pointer grab is in effect
535 gdk_display_pointer_is_grabbed (GdkDisplay * display)
537 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
539 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL &&
540 !GDK_DISPLAY_X11 (display)->pointer_xgrab_implicit);
544 * gdk_display_keyboard_ungrab:
545 * @display: a #GdkDisplay.
546 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
548 * Release any keyboard grab
553 gdk_display_keyboard_ungrab (GdkDisplay *display,
557 GdkDisplayX11 *display_x11;
559 g_return_if_fail (GDK_IS_DISPLAY (display));
561 display_x11 = GDK_DISPLAY_X11 (display);
562 xdisplay = GDK_DISPLAY_XDISPLAY (display);
564 XUngrabKeyboard (xdisplay, time);
567 if (time == GDK_CURRENT_TIME ||
568 display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
569 !XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
570 display_x11->keyboard_xgrab_window = NULL;
575 * @display: a #GdkDisplay
577 * Emits a short beep on @display
582 gdk_display_beep (GdkDisplay * display)
584 g_return_if_fail (GDK_IS_DISPLAY (display));
586 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
591 * @display: a #GdkDisplay
593 * Flushes any requests queued for the windowing system and waits until all
594 * requests have been handled. This is often used for making sure that the
595 * display is synchronized with the current state of the program. Calling
596 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
597 * generated from earlier requests are handled before the error trap is
600 * This is most useful for X11. On windowing systems where requests are
601 * handled synchronously, this function will do nothing.
606 gdk_display_sync (GdkDisplay * display)
608 g_return_if_fail (GDK_IS_DISPLAY (display));
610 XSync (GDK_DISPLAY_XDISPLAY (display), False);
615 * @display: a #GdkDisplay
617 * Flushes any requests queued for the windowing system; this happens automatically
618 * when the main loop blocks waiting for new events, but if your application
619 * is drawing without returning control to the main loop, you may need
620 * to call this function explicitely. A common case where this function
621 * needs to be called is when an application is executing drawing commands
622 * from a thread other than the thread where the main loop is running.
624 * This is most useful for X11. On windowing systems where requests are
625 * handled synchronously, this function will do nothing.
630 gdk_display_flush (GdkDisplay *display)
632 g_return_if_fail (GDK_IS_DISPLAY (display));
634 if (!display->closed)
635 XFlush (GDK_DISPLAY_XDISPLAY (display));
639 * gdk_display_get_default_group:
640 * @display: a #GdkDisplay
642 * Returns the default group leader window for all toplevel windows
643 * on @display. This window is implicitly created by GDK.
644 * See gdk_window_set_group().
646 * Return value: The default group leader window for @display
650 GdkWindow *gdk_display_get_default_group (GdkDisplay *display)
652 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
654 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
658 * gdk_x11_display_grab:
659 * @display: a #GdkDisplay
661 * Call XGrabServer() on @display.
662 * To ungrab the display again, use gdk_x11_display_ungrab().
664 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
669 gdk_x11_display_grab (GdkDisplay * display)
671 GdkDisplayX11 *display_x11;
673 g_return_if_fail (GDK_IS_DISPLAY (display));
675 display_x11 = GDK_DISPLAY_X11 (display);
677 if (display_x11->grab_count == 0)
678 XGrabServer (display_x11->xdisplay);
679 display_x11->grab_count++;
683 * gdk_x11_display_ungrab:
684 * @display: a #GdkDisplay
686 * Ungrab @display after it has been grabbed with
687 * gdk_x11_display_grab().
692 gdk_x11_display_ungrab (GdkDisplay * display)
694 GdkDisplayX11 *display_x11;
696 g_return_if_fail (GDK_IS_DISPLAY (display));
698 display_x11 = GDK_DISPLAY_X11 (display);;
699 g_return_if_fail (display_x11->grab_count > 0);
701 display_x11->grab_count--;
702 if (display_x11->grab_count == 0)
704 XUngrabServer (display_x11->xdisplay);
705 XFlush (display_x11->xdisplay);
710 gdk_display_x11_dispose (GObject *object)
712 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
716 n_screens = ScreenCount (display_x11->xdisplay);
718 for (i = 0; i < n_screens; i++)
719 _gdk_screen_close (display_x11->screens[i]);
721 _gdk_events_uninit (GDK_DISPLAY_OBJECT (object));
723 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
727 gdk_display_x11_finalize (GObject *object)
729 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
734 if (display_x11->keymap)
735 g_object_unref (display_x11->keymap);
738 if (display_x11->motif_target_lists)
740 for (i = 0; i < display_x11->motif_n_target_lists; i++)
741 g_list_free (display_x11->motif_target_lists[i]);
742 g_free (display_x11->motif_target_lists);
746 g_hash_table_destroy (display_x11->atom_from_virtual);
747 g_hash_table_destroy (display_x11->atom_to_virtual);
750 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
752 /* list of filters for client messages */
753 g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
754 g_list_free (display_x11->client_filters);
756 /* List of event window extraction functions */
757 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
758 g_slist_free (display_x11->event_types);
760 /* input GdkDevice list */
761 /* FIXME need to write finalize fct */
762 g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
763 g_list_free (display_x11->input_devices);
765 /* input GdkWindow list */
766 g_list_foreach (display_x11->input_windows, (GFunc) g_object_unref, NULL);
767 g_list_free (display_x11->input_windows);
769 /* Free all GdkScreens */
770 n_screens = ScreenCount (display_x11->xdisplay);
771 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
772 g_object_unref (display_x11->screens[i]);
773 g_free (display_x11->screens);
775 g_free (display_x11->startup_notification_id);
778 g_hash_table_destroy (display_x11->xid_ht);
780 XCloseDisplay (display_x11->xdisplay);
782 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
786 * gdk_x11_lookup_xdisplay:
787 * @xdisplay: a pointer to an X Display
789 * Find the #GdkDisplay corresponding to @display, if any exists.
791 * Return value: the #GdkDisplay, if found, otherwise %NULL.
796 gdk_x11_lookup_xdisplay (Display *xdisplay)
800 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
802 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
803 return tmp_list->data;
810 * _gdk_x11_display_screen_for_xrootwin:
811 * @display: a #Display
812 * @xrootwin: window ID for one of of the screen's of the display.
814 * Given the root window ID of one of the screen's of a #GdkDisplay,
817 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
820 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
825 n_screens = gdk_display_get_n_screens (display);
826 for (i = 0; i < n_screens; i++)
828 GdkScreen *screen = gdk_display_get_screen (display, i);
829 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
837 * gdk_x11_display_get_xdisplay:
838 * @display: a #GdkDisplay
839 * @returns: an X display.
841 * Returns the X display of a #GdkDisplay.
846 gdk_x11_display_get_xdisplay (GdkDisplay *display)
848 return GDK_DISPLAY_X11 (display)->xdisplay;
852 _gdk_windowing_set_default_display (GdkDisplay *display)
854 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
855 const gchar *startup_id;
863 gdk_display = GDK_DISPLAY_XDISPLAY (display);
865 g_free (display_x11->startup_notification_id);
866 display_x11->startup_notification_id = NULL;
868 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
869 if (startup_id && *startup_id != '\0')
873 if (!g_utf8_validate (startup_id, -1, NULL))
874 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
876 display_x11->startup_notification_id = g_strdup (startup_id);
878 /* Find the launch time from the startup_id, if it's there. Newer spec
879 * states that the startup_id is of the form <unique>_TIME<timestamp>
881 time_str = g_strrstr (startup_id, "_TIME");
882 if (time_str != NULL)
888 /* Skip past the "_TIME" part */
891 retval = strtoul (time_str, &end, 0);
892 if (end != time_str && errno == 0)
893 display_x11->user_time = retval;
896 /* Clear the environment variable so it won't be inherited by
897 * child processes and confuse things.
899 g_unsetenv ("DESKTOP_STARTUP_ID");
901 /* Set the startup id on the leader window so it
902 * applies to all windows we create on this display
904 XChangeProperty (display_x11->xdisplay,
905 display_x11->leader_window,
906 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
907 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
909 (guchar *)startup_id, strlen (startup_id));
914 escape_for_xmessage (const char *str)
919 retval = g_string_new (NULL);
929 g_string_append_c (retval, '\\');
933 g_string_append_c (retval, *p);
937 return g_string_free (retval, FALSE);
941 broadcast_xmessage (GdkDisplay *display,
942 const char *message_type,
943 const char *message_type_begin,
946 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
947 GdkScreen *screen = gdk_display_get_default_screen (display);
948 GdkWindow *root_window = gdk_screen_get_root_window (screen);
949 Window xroot_window = GDK_WINDOW_XID (root_window);
952 Atom type_atom_begin;
956 XSetWindowAttributes attrs;
958 attrs.override_redirect = True;
959 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
962 XCreateWindow (xdisplay,
968 (Visual *)CopyFromParent,
969 CWOverrideRedirect | CWEventMask,
973 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
975 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
985 xevent.xclient.type = ClientMessage;
986 xevent.xclient.message_type = type_atom_begin;
987 xevent.xclient.display =xdisplay;
988 xevent.xclient.window = xwindow;
989 xevent.xclient.format = 8;
992 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
994 while (src != src_end)
996 dest = &xevent.xclient.data.b[0];
997 dest_end = dest + 20;
999 while (dest != dest_end &&
1007 while (dest != dest_end)
1013 XSendEvent (xdisplay,
1019 xevent.xclient.message_type = type_atom;
1023 XDestroyWindow (xdisplay, xwindow);
1028 * gdk_notify_startup_complete:
1030 * Indicates to the GUI environment that the application has finished
1031 * loading. If the applications opens windows, this function is
1032 * normally called after opening the application's initial set of
1035 * GTK+ will call this function automatically after opening the first
1036 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1037 * to disable that feature.
1042 gdk_notify_startup_complete (void)
1044 GdkDisplay *display;
1045 GdkDisplayX11 *display_x11;
1049 display = gdk_display_get_default ();
1053 display_x11 = GDK_DISPLAY_X11 (display);
1055 if (display_x11->startup_notification_id == NULL)
1058 escaped_id = escape_for_xmessage (display_x11->startup_notification_id);
1059 message = g_strdup_printf ("remove: ID=%s", escaped_id);
1060 g_free (escaped_id);
1062 broadcast_xmessage (display,
1063 "_NET_STARTUP_INFO",
1064 "_NET_STARTUP_INFO_BEGIN",
1072 * gdk_display_supports_selection_notification:
1073 * @display: a #GdkDisplay
1075 * Returns whether #GdkEventOwnerChange events will be
1076 * sent when the owner of a selection changes.
1078 * Return value: whether #GdkEventOwnerChange events will
1084 gdk_display_supports_selection_notification (GdkDisplay *display)
1086 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1088 return display_x11->have_xfixes;
1092 * gdk_display_request_selection_notification:
1093 * @display: a #GdkDisplay
1094 * @selection: the #GdkAtom naming the selection for which
1095 * ownership change notification is requested
1097 * Request #GdkEventOwnerChange events for ownership changes
1098 * of the selection named by the given atom.
1100 * Return value: whether #GdkEventOwnerChange events will
1105 gboolean gdk_display_request_selection_notification (GdkDisplay *display,
1110 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1113 if (display_x11->have_xfixes)
1115 atom = gdk_x11_atom_to_xatom_for_display (display,
1117 XFixesSelectSelectionInput (display_x11->xdisplay,
1118 display_x11->leader_window,
1120 XFixesSetSelectionOwnerNotifyMask |
1121 XFixesSelectionWindowDestroyNotifyMask |
1122 XFixesSelectionClientCloseNotifyMask);
1131 * gdk_display_supports_clipboard_persistence
1132 * @display: a #GdkDisplay
1134 * Returns whether the speicifed display supports clipboard
1135 * persistance; i.e. if it's possible to store the clipboard data after an
1136 * application has quit. On X11 this checks if a clipboard daemon is
1139 * Returns: %TRUE if the display supports clipboard persistance.
1144 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1146 /* It might make sense to cache this */
1147 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay,
1148 gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER")) != None;
1152 * gdk_display_store_clipboard
1153 * @display: a #GdkDisplay
1154 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1155 * @time_: a timestamp
1156 * @targets: an array of targets that should be saved, or %NULL
1157 * if all available targets should be saved.
1158 * @n_targets: length of the @targets array
1160 * Issues a request to the clipboard manager to store the
1161 * clipboard data. On X11, this is a special program that works
1162 * according to the freedesktop clipboard specification, available at
1163 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1164 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1169 gdk_display_store_clipboard (GdkDisplay *display,
1170 GdkWindow *clipboard_window,
1175 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1176 Atom clipboard_manager, save_targets;
1178 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1179 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1181 gdk_error_trap_push ();
1183 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1185 Atom property_name = None;
1191 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1193 xatoms = g_new (Atom, n_targets);
1194 for (i = 0; i < n_targets; i++)
1195 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1197 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1198 property_name, XA_ATOM,
1199 32, PropModeReplace, (guchar *)xatoms, n_targets);
1204 XConvertSelection (display_x11->xdisplay,
1205 clipboard_manager, save_targets, property_name,
1206 GDK_WINDOW_XID (clipboard_window), time_);
1209 gdk_error_trap_pop ();
1214 * gdk_x11_display_get_user_time:
1215 * @display: a #GdkDisplay
1217 * Returns the timestamp of the last user interaction on
1218 * @display. The timestamp is taken from events caused
1219 * by user interaction such as key presses or pointer
1220 * movements. See gdk_x11_window_set_user_time().
1222 * Returns: the timestamp of the last user interaction
1227 gdk_x11_display_get_user_time (GdkDisplay *display)
1229 return GDK_DISPLAY_X11 (display)->user_time;
1233 * gdk_display_supports_shapes:
1234 * @display: a #GdkDisplay
1236 * Returns %TRUE if gdk_window_shape_combine_mask() can
1237 * be used to create shaped windows on @display.
1239 * Returns: %TRUE if shaped windows are supported
1244 gdk_display_supports_shapes (GdkDisplay *display)
1246 return GDK_DISPLAY_X11 (display)->have_shapes;
1250 * gdk_display_supports_input_shapes:
1251 * @display: a #GdkDisplay
1253 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1254 * be used to modify the input shape of windows on @display.
1256 * Returns: %TRUE if windows with modified input shape are supported
1261 gdk_display_supports_input_shapes (GdkDisplay *display)
1263 return GDK_DISPLAY_X11 (display)->have_input_shapes;
1267 #define __GDK_DISPLAY_X11_C__
1268 #include "gdkaliasdef.c"