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[] = {
88 "_NET_WM_STATE_STICKY",
89 "_NET_WM_STATE_MAXIMIZED_VERT",
90 "_NET_WM_STATE_MAXIMIZED_HORZ",
91 "_NET_WM_STATE_FULLSCREEN",
92 "_NET_WM_SYNC_REQUEST",
93 "_NET_WM_SYNC_REQUEST_COUNTER",
94 "_NET_WM_WINDOW_TYPE",
95 "_NET_WM_WINDOW_TYPE_NORMAL",
100 G_DEFINE_TYPE (GdkDisplayX11, _gdk_display_x11, GDK_TYPE_DISPLAY)
103 _gdk_display_x11_class_init (GdkDisplayX11Class * class)
105 GObjectClass *object_class = G_OBJECT_CLASS (class);
107 object_class->dispose = gdk_display_x11_dispose;
108 object_class->finalize = gdk_display_x11_finalize;
112 _gdk_display_x11_init (GdkDisplayX11 *display)
118 * @display_name: the name of the display to open
119 * @returns: a #GdkDisplay, or %NULL if the display
120 * could not be opened.
127 gdk_display_open (const gchar *display_name)
131 GdkDisplayX11 *display_x11;
135 const char *sm_client_id;
137 XClassHint *class_hint;
140 #if defined(HAVE_XFIXES) || defined(HAVE_SHAPE_EXT)
145 xdisplay = XOpenDisplay (display_name);
149 display = g_object_new (GDK_TYPE_DISPLAY_X11, NULL);
150 display_x11 = GDK_DISPLAY_X11 (display);
152 display_x11->use_xshm = TRUE;
153 display_x11->xdisplay = xdisplay;
156 /* Set up handlers for Xlib internal connections */
157 XAddConnectionWatch (xdisplay, gdk_internal_connection_watch, NULL);
158 #endif /* HAVE_X11R6 */
160 /* initialize the display's screens */
161 display_x11->screens = g_new (GdkScreen *, ScreenCount (display_x11->xdisplay));
162 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
163 display_x11->screens[i] = _gdk_x11_screen_new (display, i);
165 /* We need to initialize events after we have the screen
166 * structures in places
168 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
169 _gdk_x11_events_init_screen (display_x11->screens[i]);
171 /*set the default screen */
172 display_x11->default_screen = display_x11->screens[DefaultScreen (display_x11->xdisplay)];
174 attr.window_type = GDK_WINDOW_TOPLEVEL;
175 attr.wclass = GDK_INPUT_OUTPUT;
182 _gdk_x11_precache_atoms (display, precache_atoms, G_N_ELEMENTS (precache_atoms));
184 display_x11->leader_gdk_window = gdk_window_new (GDK_SCREEN_X11 (display_x11->default_screen)->root_window,
185 &attr, GDK_WA_X | GDK_WA_Y);
186 (_gdk_x11_window_get_toplevel (display_x11->leader_gdk_window))->is_leader = TRUE;
188 display_x11->leader_window = GDK_WINDOW_XID (display_x11->leader_gdk_window);
190 display_x11->leader_window_title_set = FALSE;
192 display_x11->have_render = GDK_UNKNOWN;
195 if (XFixesQueryExtension (display_x11->xdisplay,
196 &display_x11->xfixes_event_base,
199 display_x11->have_xfixes = TRUE;
201 gdk_x11_register_standard_event_type (display,
202 display_x11->xfixes_event_base,
207 display_x11->have_xfixes = FALSE;
209 display_x11->have_shapes = FALSE;
210 display_x11->have_input_shapes = FALSE;
211 #ifdef HAVE_SHAPE_EXT
212 if (XShapeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &ignore, &ignore))
214 display_x11->have_shapes = TRUE;
216 if (XShapeQueryVersion (GDK_DISPLAY_XDISPLAY (display), &maj, &min))
217 display_x11->have_input_shapes = (maj == 1 && min >= 1);
222 if (_gdk_synchronize)
223 XSynchronize (display_x11->xdisplay, True);
225 class_hint = XAllocClassHint();
226 class_hint->res_name = g_get_prgname ();
228 class_hint->res_class = (char *)gdk_get_program_class ();
230 /* XmbSetWMProperties sets the RESOURCE_NAME environment variable
231 * from argv[0], so we just synthesize an argument array here.
234 argv[0] = g_get_prgname ();
236 XmbSetWMProperties (display_x11->xdisplay,
237 display_x11->leader_window,
238 NULL, NULL, argv, argc, NULL, NULL,
242 sm_client_id = _gdk_get_sm_client_id ();
244 _gdk_windowing_display_set_sm_client_id (display, sm_client_id);
247 XChangeProperty (display_x11->xdisplay,
248 display_x11->leader_window,
249 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PID"),
250 XA_CARDINAL, 32, PropModeReplace, (guchar *) & pid, 1);
252 /* We don't yet know a valid time. */
253 display_x11->user_time = 0;
257 gint xkb_major = XkbMajorVersion;
258 gint xkb_minor = XkbMinorVersion;
259 if (XkbLibraryVersion (&xkb_major, &xkb_minor))
261 xkb_major = XkbMajorVersion;
262 xkb_minor = XkbMinorVersion;
264 if (XkbQueryExtension (display_x11->xdisplay,
265 NULL, &display_x11->xkb_event_type, NULL,
266 &xkb_major, &xkb_minor))
268 Bool detectable_autorepeat_supported;
270 display_x11->use_xkb = TRUE;
272 XkbSelectEvents (display_x11->xdisplay,
274 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask,
275 XkbNewKeyboardNotifyMask | XkbMapNotifyMask | XkbStateNotifyMask);
277 /* keep this in sync with _gdk_keymap_state_changed() */
278 XkbSelectEventDetails (display_x11->xdisplay,
279 XkbUseCoreKbd, XkbStateNotify,
280 XkbGroupLockMask, XkbGroupLockMask);
282 XkbSetDetectableAutoRepeat (display_x11->xdisplay,
284 &detectable_autorepeat_supported);
286 GDK_NOTE (MISC, g_message ("Detectable autorepeat %s.",
287 detectable_autorepeat_supported ?
288 "supported" : "not supported"));
290 display_x11->have_xkb_autorepeat = detectable_autorepeat_supported;
296 display_x11->use_sync = FALSE;
300 int error_base, event_base;
302 if (XSyncQueryExtension (display_x11->xdisplay,
303 &event_base, &error_base) &&
304 XSyncInitialize (display_x11->xdisplay,
306 display_x11->use_sync = TRUE;
310 _gdk_windowing_image_init (display);
311 _gdk_events_init (display);
312 _gdk_input_init (display);
313 _gdk_dnd_init (display);
315 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
316 gdk_display_request_selection_notification (display,
317 GDK_SCREEN_X11 (display_x11->screens[i])->cm_selection_atom);
319 g_signal_emit_by_name (gdk_display_manager_get(),
320 "display_opened", display);
327 * XLib internal connection handling
329 typedef struct _GdkInternalConnection GdkInternalConnection;
331 struct _GdkInternalConnection
339 process_internal_connection (GIOChannel *gioc,
343 GdkInternalConnection *connection = (GdkInternalConnection *)data;
345 GDK_THREADS_ENTER ();
347 XProcessInternalConnection ((Display*)connection->display, connection->fd);
349 GDK_THREADS_LEAVE ();
354 static GdkInternalConnection *
355 gdk_add_connection_handler (Display *display,
358 GIOChannel *io_channel;
359 GdkInternalConnection *connection;
361 connection = g_new (GdkInternalConnection, 1);
364 connection->display = display;
366 io_channel = g_io_channel_unix_new (fd);
368 connection->source = g_io_create_watch (io_channel, G_IO_IN);
369 g_source_set_callback (connection->source,
370 (GSourceFunc)process_internal_connection, connection, NULL);
371 g_source_attach (connection->source, NULL);
373 g_io_channel_unref (io_channel);
379 gdk_remove_connection_handler (GdkInternalConnection *connection)
381 g_source_destroy (connection->source);
386 gdk_internal_connection_watch (Display *display,
390 XPointer *watch_data)
393 *watch_data = (XPointer)gdk_add_connection_handler (display, fd);
395 gdk_remove_connection_handler ((GdkInternalConnection *)*watch_data);
397 #endif /* HAVE_X11R6 */
400 * gdk_display_get_name:
401 * @display: a #GdkDisplay
403 * Gets the name of the display.
405 * Returns: a string representing the display name. This string is owned
406 * by GDK and should not be modified or freed.
410 G_CONST_RETURN gchar *
411 gdk_display_get_name (GdkDisplay *display)
413 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
415 return (gchar *) DisplayString (GDK_DISPLAY_X11 (display)->xdisplay);
419 * gdk_display_get_n_screens:
420 * @display: a #GdkDisplay
422 * Gets the number of screen managed by the @display.
424 * Returns: number of screens.
429 gdk_display_get_n_screens (GdkDisplay *display)
431 g_return_val_if_fail (GDK_IS_DISPLAY (display), 0);
433 return ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay);
437 * gdk_display_get_screen:
438 * @display: a #GdkDisplay
439 * @screen_num: the screen number
441 * Returns a screen object for one of the screens of the display.
443 * Returns: the #GdkScreen object
448 gdk_display_get_screen (GdkDisplay *display,
451 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
452 g_return_val_if_fail (ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay) > screen_num, NULL);
454 return GDK_DISPLAY_X11 (display)->screens[screen_num];
458 * gdk_display_get_default_screen:
459 * @display: a #GdkDisplay
461 * Get the default #GdkScreen for @display.
463 * Returns: the default #GdkScreen object for @display
468 gdk_display_get_default_screen (GdkDisplay *display)
470 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
472 return GDK_DISPLAY_X11 (display)->default_screen;
476 _gdk_x11_display_is_root_window (GdkDisplay *display,
479 GdkDisplayX11 *display_x11;
482 g_return_val_if_fail (GDK_IS_DISPLAY (display), FALSE);
484 display_x11 = GDK_DISPLAY_X11 (display);
486 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
488 if (GDK_SCREEN_XROOTWIN (display_x11->screens[i]) == xroot_window)
494 #define XSERVER_TIME_IS_LATER(time1, time2) \
495 ( (( time1 > time2 ) && ( time1 - time2 < ((guint32)-1)/2 )) || \
496 (( time1 < time2 ) && ( time2 - time1 > ((guint32)-1)/2 )) \
500 * gdk_display_pointer_ungrab:
501 * @display: a #GdkDisplay.
502 * @time_: a timestap (e.g. %GDK_CURRENT_TIME).
504 * Release any pointer grab.
509 gdk_display_pointer_ungrab (GdkDisplay *display,
513 GdkDisplayX11 *display_x11;
515 g_return_if_fail (GDK_IS_DISPLAY (display));
517 display_x11 = GDK_DISPLAY_X11 (display);
518 xdisplay = GDK_DISPLAY_XDISPLAY (display);
520 _gdk_input_ungrab_pointer (display, time);
521 XUngrabPointer (xdisplay, time);
524 if (time == GDK_CURRENT_TIME ||
525 display_x11->pointer_xgrab_time == GDK_CURRENT_TIME ||
526 !XSERVER_TIME_IS_LATER (display_x11->pointer_xgrab_time, time))
527 display_x11->pointer_xgrab_window = NULL;
531 * gdk_display_pointer_is_grabbed:
532 * @display: a #GdkDisplay
534 * Test if the pointer is grabbed.
536 * Returns: %TRUE if an active X pointer grab is in effect
541 gdk_display_pointer_is_grabbed (GdkDisplay *display)
543 g_return_val_if_fail (GDK_IS_DISPLAY (display), TRUE);
545 return (GDK_DISPLAY_X11 (display)->pointer_xgrab_window != NULL &&
546 !GDK_DISPLAY_X11 (display)->pointer_xgrab_implicit);
550 * gdk_display_keyboard_ungrab:
551 * @display: a #GdkDisplay.
552 * @time_: a timestap (e.g #GDK_CURRENT_TIME).
554 * Release any keyboard grab
559 gdk_display_keyboard_ungrab (GdkDisplay *display,
563 GdkDisplayX11 *display_x11;
565 g_return_if_fail (GDK_IS_DISPLAY (display));
567 display_x11 = GDK_DISPLAY_X11 (display);
568 xdisplay = GDK_DISPLAY_XDISPLAY (display);
570 XUngrabKeyboard (xdisplay, time);
573 if (time == GDK_CURRENT_TIME ||
574 display_x11->keyboard_xgrab_time == GDK_CURRENT_TIME ||
575 !XSERVER_TIME_IS_LATER (display_x11->keyboard_xgrab_time, time))
576 display_x11->keyboard_xgrab_window = NULL;
581 * @display: a #GdkDisplay
583 * Emits a short beep on @display
588 gdk_display_beep (GdkDisplay *display)
590 g_return_if_fail (GDK_IS_DISPLAY (display));
592 XBell (GDK_DISPLAY_XDISPLAY (display), 0);
597 * @display: a #GdkDisplay
599 * Flushes any requests queued for the windowing system and waits until all
600 * requests have been handled. This is often used for making sure that the
601 * display is synchronized with the current state of the program. Calling
602 * gdk_display_sync() before gdk_error_trap_pop() makes sure that any errors
603 * generated from earlier requests are handled before the error trap is
606 * This is most useful for X11. On windowing systems where requests are
607 * handled synchronously, this function will do nothing.
612 gdk_display_sync (GdkDisplay *display)
614 g_return_if_fail (GDK_IS_DISPLAY (display));
616 XSync (GDK_DISPLAY_XDISPLAY (display), False);
621 * @display: a #GdkDisplay
623 * Flushes any requests queued for the windowing system; this happens automatically
624 * when the main loop blocks waiting for new events, but if your application
625 * is drawing without returning control to the main loop, you may need
626 * to call this function explicitely. A common case where this function
627 * needs to be called is when an application is executing drawing commands
628 * from a thread other than the thread where the main loop is running.
630 * This is most useful for X11. On windowing systems where requests are
631 * handled synchronously, this function will do nothing.
636 gdk_display_flush (GdkDisplay *display)
638 g_return_if_fail (GDK_IS_DISPLAY (display));
640 if (!display->closed)
641 XFlush (GDK_DISPLAY_XDISPLAY (display));
645 * gdk_display_get_default_group:
646 * @display: a #GdkDisplay
648 * Returns the default group leader window for all toplevel windows
649 * on @display. This window is implicitly created by GDK.
650 * See gdk_window_set_group().
652 * Return value: The default group leader window for @display
657 gdk_display_get_default_group (GdkDisplay *display)
659 g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
661 return GDK_DISPLAY_X11 (display)->leader_gdk_window;
665 * gdk_x11_display_grab:
666 * @display: a #GdkDisplay
668 * Call XGrabServer() on @display.
669 * To ungrab the display again, use gdk_x11_display_ungrab().
671 * gdk_x11_display_grab()/gdk_x11_display_ungrab() calls can be nested.
676 gdk_x11_display_grab (GdkDisplay *display)
678 GdkDisplayX11 *display_x11;
680 g_return_if_fail (GDK_IS_DISPLAY (display));
682 display_x11 = GDK_DISPLAY_X11 (display);
684 if (display_x11->grab_count == 0)
685 XGrabServer (display_x11->xdisplay);
686 display_x11->grab_count++;
690 * gdk_x11_display_ungrab:
691 * @display: a #GdkDisplay
693 * Ungrab @display after it has been grabbed with
694 * gdk_x11_display_grab().
699 gdk_x11_display_ungrab (GdkDisplay *display)
701 GdkDisplayX11 *display_x11;
703 g_return_if_fail (GDK_IS_DISPLAY (display));
705 display_x11 = GDK_DISPLAY_X11 (display);;
706 g_return_if_fail (display_x11->grab_count > 0);
708 display_x11->grab_count--;
709 if (display_x11->grab_count == 0)
711 XUngrabServer (display_x11->xdisplay);
712 XFlush (display_x11->xdisplay);
717 gdk_display_x11_dispose (GObject *object)
719 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
722 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
723 _gdk_screen_close (display_x11->screens[i]);
725 _gdk_events_uninit (GDK_DISPLAY_OBJECT (object));
727 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->dispose (object);
731 gdk_display_x11_finalize (GObject *object)
733 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (object);
737 if (display_x11->keymap)
738 g_object_unref (display_x11->keymap);
741 if (display_x11->motif_target_lists)
743 for (i = 0; i < display_x11->motif_n_target_lists; i++)
744 g_list_free (display_x11->motif_target_lists[i]);
745 g_free (display_x11->motif_target_lists);
749 g_hash_table_destroy (display_x11->atom_from_virtual);
750 g_hash_table_destroy (display_x11->atom_to_virtual);
753 XDestroyWindow (display_x11->xdisplay, display_x11->leader_window);
755 /* list of filters for client messages */
756 g_list_foreach (display_x11->client_filters, (GFunc) g_free, NULL);
757 g_list_free (display_x11->client_filters);
759 /* List of event window extraction functions */
760 g_slist_foreach (display_x11->event_types, (GFunc)g_free, NULL);
761 g_slist_free (display_x11->event_types);
763 /* input GdkDevice list */
764 /* FIXME need to write finalize fct */
765 g_list_foreach (display_x11->input_devices, (GFunc) g_object_unref, NULL);
766 g_list_free (display_x11->input_devices);
768 /* input GdkWindow list */
769 g_list_foreach (display_x11->input_windows, (GFunc) g_object_unref, NULL);
770 g_list_free (display_x11->input_windows);
772 /* Free all GdkScreens */
773 for (i = 0; i < ScreenCount (display_x11->xdisplay); i++)
774 g_object_unref (display_x11->screens[i]);
775 g_free (display_x11->screens);
777 g_free (display_x11->startup_notification_id);
780 g_hash_table_destroy (display_x11->xid_ht);
782 XCloseDisplay (display_x11->xdisplay);
784 G_OBJECT_CLASS (_gdk_display_x11_parent_class)->finalize (object);
788 * gdk_x11_lookup_xdisplay:
789 * @xdisplay: a pointer to an X Display
791 * Find the #GdkDisplay corresponding to @display, if any exists.
793 * Return value: the #GdkDisplay, if found, otherwise %NULL.
798 gdk_x11_lookup_xdisplay (Display *xdisplay)
802 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
804 if (GDK_DISPLAY_XDISPLAY (tmp_list->data) == xdisplay)
805 return tmp_list->data;
812 * _gdk_x11_display_screen_for_xrootwin:
813 * @display: a #GdkDisplay
814 * @xrootwin: window ID for one of of the screen's of the display.
816 * Given the root window ID of one of the screen's of a #GdkDisplay,
819 * Return value: the #GdkScreen corresponding to @xrootwin, or %NULL.
822 _gdk_x11_display_screen_for_xrootwin (GdkDisplay *display,
827 for (i = 0; i < ScreenCount (GDK_DISPLAY_X11 (display)->xdisplay); i++)
829 GdkScreen *screen = gdk_display_get_screen (display, i);
830 if (GDK_SCREEN_XROOTWIN (screen) == xrootwin)
838 * gdk_x11_display_get_xdisplay:
839 * @display: a #GdkDisplay
840 * @returns: an X display.
842 * Returns the X display of a #GdkDisplay.
847 gdk_x11_display_get_xdisplay (GdkDisplay *display)
849 return GDK_DISPLAY_X11 (display)->xdisplay;
853 _gdk_windowing_set_default_display (GdkDisplay *display)
855 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
856 const gchar *startup_id;
864 gdk_display = GDK_DISPLAY_XDISPLAY (display);
866 g_free (display_x11->startup_notification_id);
867 display_x11->startup_notification_id = NULL;
869 startup_id = g_getenv ("DESKTOP_STARTUP_ID");
870 if (startup_id && *startup_id != '\0')
874 if (!g_utf8_validate (startup_id, -1, NULL))
875 g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
877 display_x11->startup_notification_id = g_strdup (startup_id);
879 /* Find the launch time from the startup_id, if it's there. Newer spec
880 * states that the startup_id is of the form <unique>_TIME<timestamp>
882 time_str = g_strrstr (startup_id, "_TIME");
883 if (time_str != NULL)
889 /* Skip past the "_TIME" part */
892 retval = strtoul (time_str, &end, 0);
893 if (end != time_str && errno == 0)
894 display_x11->user_time = retval;
897 /* Clear the environment variable so it won't be inherited by
898 * child processes and confuse things.
900 g_unsetenv ("DESKTOP_STARTUP_ID");
902 /* Set the startup id on the leader window so it
903 * applies to all windows we create on this display
905 XChangeProperty (display_x11->xdisplay,
906 display_x11->leader_window,
907 gdk_x11_get_xatom_by_name_for_display (display, "_NET_STARTUP_ID"),
908 gdk_x11_get_xatom_by_name_for_display (display, "UTF8_STRING"), 8,
910 (guchar *)startup_id, strlen (startup_id));
915 escape_for_xmessage (const char *str)
920 retval = g_string_new (NULL);
930 g_string_append_c (retval, '\\');
934 g_string_append_c (retval, *p);
938 return g_string_free (retval, FALSE);
942 broadcast_xmessage (GdkDisplay *display,
943 const char *message_type,
944 const char *message_type_begin,
947 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
948 GdkScreen *screen = gdk_display_get_default_screen (display);
949 GdkWindow *root_window = gdk_screen_get_root_window (screen);
950 Window xroot_window = GDK_WINDOW_XID (root_window);
953 Atom type_atom_begin;
957 XSetWindowAttributes attrs;
959 attrs.override_redirect = True;
960 attrs.event_mask = PropertyChangeMask | StructureNotifyMask;
963 XCreateWindow (xdisplay,
969 (Visual *)CopyFromParent,
970 CWOverrideRedirect | CWEventMask,
974 type_atom = gdk_x11_get_xatom_by_name_for_display (display,
976 type_atom_begin = gdk_x11_get_xatom_by_name_for_display (display,
986 xevent.xclient.type = ClientMessage;
987 xevent.xclient.message_type = type_atom_begin;
988 xevent.xclient.display =xdisplay;
989 xevent.xclient.window = xwindow;
990 xevent.xclient.format = 8;
993 src_end = message + strlen (message) + 1; /* +1 to include nul byte */
995 while (src != src_end)
997 dest = &xevent.xclient.data.b[0];
998 dest_end = dest + 20;
1000 while (dest != dest_end &&
1008 while (dest != dest_end)
1014 XSendEvent (xdisplay,
1020 xevent.xclient.message_type = type_atom;
1024 XDestroyWindow (xdisplay, xwindow);
1029 * gdk_notify_startup_complete:
1031 * Indicates to the GUI environment that the application has finished
1032 * loading. If the applications opens windows, this function is
1033 * normally called after opening the application's initial set of
1036 * GTK+ will call this function automatically after opening the first
1037 * #GtkWindow unless gtk_window_set_auto_startup_notification() is called
1038 * to disable that feature.
1043 gdk_notify_startup_complete (void)
1045 GdkDisplay *display;
1046 GdkDisplayX11 *display_x11;
1050 display = gdk_display_get_default ();
1054 display_x11 = GDK_DISPLAY_X11 (display);
1056 if (display_x11->startup_notification_id == NULL)
1059 escaped_id = escape_for_xmessage (display_x11->startup_notification_id);
1060 message = g_strdup_printf ("remove: ID=%s", escaped_id);
1061 g_free (escaped_id);
1063 broadcast_xmessage (display,
1064 "_NET_STARTUP_INFO",
1065 "_NET_STARTUP_INFO_BEGIN",
1073 * gdk_display_supports_selection_notification:
1074 * @display: a #GdkDisplay
1076 * Returns whether #GdkEventOwnerChange events will be
1077 * sent when the owner of a selection changes.
1079 * Return value: whether #GdkEventOwnerChange events will
1085 gdk_display_supports_selection_notification (GdkDisplay *display)
1087 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1089 return display_x11->have_xfixes;
1093 * gdk_display_request_selection_notification:
1094 * @display: a #GdkDisplay
1095 * @selection: the #GdkAtom naming the selection for which
1096 * ownership change notification is requested
1098 * Request #GdkEventOwnerChange events for ownership changes
1099 * of the selection named by the given atom.
1101 * Return value: whether #GdkEventOwnerChange events will
1107 gdk_display_request_selection_notification (GdkDisplay *display,
1112 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1115 if (display_x11->have_xfixes)
1117 atom = gdk_x11_atom_to_xatom_for_display (display,
1119 XFixesSelectSelectionInput (display_x11->xdisplay,
1120 display_x11->leader_window,
1122 XFixesSetSelectionOwnerNotifyMask |
1123 XFixesSelectionWindowDestroyNotifyMask |
1124 XFixesSelectionClientCloseNotifyMask);
1133 * gdk_display_supports_clipboard_persistence
1134 * @display: a #GdkDisplay
1136 * Returns whether the speicifed display supports clipboard
1137 * persistance; i.e. if it's possible to store the clipboard data after an
1138 * application has quit. On X11 this checks if a clipboard daemon is
1141 * Returns: %TRUE if the display supports clipboard persistance.
1146 gdk_display_supports_clipboard_persistence (GdkDisplay *display)
1148 Atom clipboard_manager;
1150 /* It might make sense to cache this */
1151 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1152 return XGetSelectionOwner (GDK_DISPLAY_X11 (display)->xdisplay, clipboard_manager) != None;
1156 * gdk_display_store_clipboard
1157 * @display: a #GdkDisplay
1158 * @clipboard_window: a #GdkWindow belonging to the clipboard owner
1159 * @time_: a timestamp
1160 * @targets: an array of targets that should be saved, or %NULL
1161 * if all available targets should be saved.
1162 * @n_targets: length of the @targets array
1164 * Issues a request to the clipboard manager to store the
1165 * clipboard data. On X11, this is a special program that works
1166 * according to the freedesktop clipboard specification, available at
1167 * <ulink url="http://www.freedesktop.org/Standards/clipboard-manager-spec">
1168 * http://www.freedesktop.org/Standards/clipboard-manager-spec</ulink>.
1173 gdk_display_store_clipboard (GdkDisplay *display,
1174 GdkWindow *clipboard_window,
1179 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
1180 Atom clipboard_manager, save_targets;
1182 clipboard_manager = gdk_x11_get_xatom_by_name_for_display (display, "CLIPBOARD_MANAGER");
1183 save_targets = gdk_x11_get_xatom_by_name_for_display (display, "SAVE_TARGETS");
1185 gdk_error_trap_push ();
1187 if (XGetSelectionOwner (display_x11->xdisplay, clipboard_manager) != None)
1189 Atom property_name = None;
1195 property_name = gdk_x11_atom_to_xatom_for_display (display, _gdk_selection_property);
1197 xatoms = g_new (Atom, n_targets);
1198 for (i = 0; i < n_targets; i++)
1199 xatoms[i] = gdk_x11_atom_to_xatom_for_display (display, targets[i]);
1201 XChangeProperty (display_x11->xdisplay, GDK_WINDOW_XID (clipboard_window),
1202 property_name, XA_ATOM,
1203 32, PropModeReplace, (guchar *)xatoms, n_targets);
1208 XConvertSelection (display_x11->xdisplay,
1209 clipboard_manager, save_targets, property_name,
1210 GDK_WINDOW_XID (clipboard_window), time_);
1213 gdk_error_trap_pop ();
1218 * gdk_x11_display_get_user_time:
1219 * @display: a #GdkDisplay
1221 * Returns the timestamp of the last user interaction on
1222 * @display. The timestamp is taken from events caused
1223 * by user interaction such as key presses or pointer
1224 * movements. See gdk_x11_window_set_user_time().
1226 * Returns: the timestamp of the last user interaction
1231 gdk_x11_display_get_user_time (GdkDisplay *display)
1233 return GDK_DISPLAY_X11 (display)->user_time;
1237 * gdk_display_supports_shapes:
1238 * @display: a #GdkDisplay
1240 * Returns %TRUE if gdk_window_shape_combine_mask() can
1241 * be used to create shaped windows on @display.
1243 * Returns: %TRUE if shaped windows are supported
1248 gdk_display_supports_shapes (GdkDisplay *display)
1250 return GDK_DISPLAY_X11 (display)->have_shapes;
1254 * gdk_display_supports_input_shapes:
1255 * @display: a #GdkDisplay
1257 * Returns %TRUE if gdk_window_input_shape_combine_mask() can
1258 * be used to modify the input shape of windows on @display.
1260 * Returns: %TRUE if windows with modified input shape are supported
1265 gdk_display_supports_input_shapes (GdkDisplay *display)
1267 return GDK_DISPLAY_X11 (display)->have_input_shapes;
1271 #define __GDK_DISPLAY_X11_C__
1272 #include "gdkaliasdef.c"