1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-2007 Peter Mattis, Spencer Kimball,
3 * Josh MacDonald, Ryan Lortie
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
22 * Modified by the GTK+ Team and others 1997-2007. See the AUTHORS
23 * file for a list of people on the GTK+ Team. See the ChangeLog
24 * files for a list of changes. These files are distributed with
25 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
31 #include "gdkprivate-x11.h"
32 #include "gdkinternals.h"
34 #include "gdkscreen-x11.h"
35 #include "gdkdisplay-x11.h"
38 #include "gdkkeysyms.h"
40 #include "xsettings-client.h"
44 #include "gdkinputprivate.h"
45 #include "gdksettings.c"
50 #include <X11/XKBlib.h>
54 #include <X11/extensions/sync.h>
58 #include <X11/extensions/Xfixes.h>
62 #include <X11/extensions/Xrandr.h>
65 #include <X11/Xatom.h>
67 typedef struct _GdkIOClosure GdkIOClosure;
68 typedef struct _GdkDisplaySource GdkDisplaySource;
69 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
73 GdkInputFunction function;
74 GdkInputCondition condition;
75 GDestroyNotify notify;
79 struct _GdkDisplaySource
84 GPollFD event_poll_fd;
87 struct _GdkEventTypeX11
94 * Private function declarations
97 static gint gdk_event_apply_filters (XEvent *xevent,
100 static gboolean gdk_event_translate (GdkDisplay *display,
103 gboolean return_exposes);
105 static gboolean gdk_event_prepare (GSource *source,
107 static gboolean gdk_event_check (GSource *source);
108 static gboolean gdk_event_dispatch (GSource *source,
109 GSourceFunc callback,
112 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
116 static GSource *gdk_display_source_new (GdkDisplay *display);
117 static gboolean gdk_check_xpending (GdkDisplay *display);
119 static Bool gdk_xsettings_watch_cb (Window window,
123 static void gdk_xsettings_notify_cb (const char *name,
124 XSettingsAction action,
125 XSettingsSetting *setting,
128 /* Private variable declarations
131 static GList *display_sources;
133 static GSourceFuncs event_funcs = {
141 gdk_display_source_new (GdkDisplay *display)
143 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
144 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
146 display_source->display = display;
152 gdk_check_xpending (GdkDisplay *display)
154 return XPending (GDK_DISPLAY_XDISPLAY (display));
157 /*********************************************
158 * Functions for maintaining the event queue *
159 *********************************************/
162 refcounted_grab_server (Display *xdisplay)
164 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
166 gdk_x11_display_grab (display);
170 refcounted_ungrab_server (Display *xdisplay)
172 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
174 gdk_x11_display_ungrab (display);
178 _gdk_x11_events_init_screen (GdkScreen *screen)
180 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
182 /* Keep a flag to avoid extra notifies that we don't need
184 screen_x11->xsettings_in_init = TRUE;
185 screen_x11->xsettings_client = xsettings_client_new_with_grab_funcs (screen_x11->xdisplay,
186 screen_x11->screen_num,
187 gdk_xsettings_notify_cb,
188 gdk_xsettings_watch_cb,
190 refcounted_grab_server,
191 refcounted_ungrab_server);
192 screen_x11->xsettings_in_init = FALSE;
196 _gdk_x11_events_uninit_screen (GdkScreen *screen)
198 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
200 if (screen_x11->xsettings_client)
202 xsettings_client_destroy (screen_x11->xsettings_client);
203 screen_x11->xsettings_client = NULL;
208 _gdk_events_init (GdkDisplay *display)
211 GdkDisplaySource *display_source;
212 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
214 int connection_number = ConnectionNumber (display_x11->xdisplay);
215 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
218 source = display_x11->event_source = gdk_display_source_new (display);
219 display_source = (GdkDisplaySource*) source;
220 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
222 display_source->event_poll_fd.fd = connection_number;
223 display_source->event_poll_fd.events = G_IO_IN;
225 g_source_add_poll (source, &display_source->event_poll_fd);
226 g_source_set_can_recurse (source, TRUE);
227 g_source_attach (source, NULL);
229 display_sources = g_list_prepend (display_sources,display_source);
231 gdk_display_add_client_message_filter (display,
232 gdk_atom_intern_static_string ("WM_PROTOCOLS"),
233 gdk_wm_protocols_filter,
238 _gdk_events_uninit (GdkDisplay *display)
240 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
242 if (display_x11->event_source)
244 display_sources = g_list_remove (display_sources,
245 display_x11->event_source);
246 g_source_destroy (display_x11->event_source);
247 g_source_unref (display_x11->event_source);
248 display_x11->event_source = NULL;
253 * gdk_events_pending:
255 * Checks if any events are ready to be processed for any display.
257 * Return value: %TRUE if any events are pending.
260 gdk_events_pending (void)
264 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
266 GdkDisplaySource *tmp_source = tmp_list->data;
267 GdkDisplay *display = tmp_source->display;
269 if (_gdk_event_queue_find_first (display))
273 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
275 GdkDisplaySource *tmp_source = tmp_list->data;
276 GdkDisplay *display = tmp_source->display;
278 if (gdk_check_xpending (display))
286 graphics_expose_predicate (Display *display,
290 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
291 (xevent->xany.type == GraphicsExpose ||
292 xevent->xany.type == NoExpose))
299 * gdk_event_get_graphics_expose:
300 * @window: the #GdkWindow to wait for the events for.
302 * Waits for a GraphicsExpose or NoExpose event from the X server.
303 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
304 * GraphicsExpose events are handled before the widget is scrolled.
306 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
307 * NoExpose event was received.
310 gdk_event_get_graphics_expose (GdkWindow *window)
315 g_return_val_if_fail (window != NULL, NULL);
317 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
318 graphics_expose_predicate, (XPointer) window);
320 if (xevent.xany.type == GraphicsExpose)
322 event = gdk_event_new (GDK_NOTHING);
324 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
328 gdk_event_free (event);
335 gdk_event_apply_filters (XEvent *xevent,
340 GdkFilterReturn result;
346 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
348 tmp_list = tmp_list->next;
349 result = filter->function (xevent, event, filter->data);
350 if (result != GDK_FILTER_CONTINUE)
354 return GDK_FILTER_CONTINUE;
358 * gdk_display_add_client_message_filter:
359 * @display: a #GdkDisplay for which this message filter applies
360 * @message_type: the type of ClientMessage events to receive.
361 * This will be checked against the @message_type field
362 * of the XClientMessage event struct.
363 * @func: the function to call to process the event.
364 * @data: user data to pass to @func.
366 * Adds a filter to be called when X ClientMessage events are received.
367 * See gdk_window_add_filter() if you are interested in filtering other
373 gdk_display_add_client_message_filter (GdkDisplay *display,
374 GdkAtom message_type,
378 GdkClientFilter *filter;
379 g_return_if_fail (GDK_IS_DISPLAY (display));
380 filter = g_new (GdkClientFilter, 1);
382 filter->type = message_type;
383 filter->function = func;
386 GDK_DISPLAY_X11(display)->client_filters =
387 g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
392 * gdk_add_client_message_filter:
393 * @message_type: the type of ClientMessage events to receive. This will be
394 * checked against the <structfield>message_type</structfield> field of the
395 * XClientMessage event struct.
396 * @func: the function to call to process the event.
397 * @data: user data to pass to @func.
399 * Adds a filter to the default display to be called when X ClientMessage events
400 * are received. See gdk_display_add_client_message_filter().
403 gdk_add_client_message_filter (GdkAtom message_type,
407 gdk_display_add_client_message_filter (gdk_display_get_default (),
408 message_type, func, data);
412 do_net_wm_state_changes (GdkWindow *window)
414 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
415 GdkWindowState old_state;
417 if (GDK_WINDOW_DESTROYED (window) ||
418 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
421 old_state = gdk_window_get_state (window);
423 /* For found_sticky to remain TRUE, we have to also be on desktop
426 if (old_state & GDK_WINDOW_STATE_STICKY)
428 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
429 gdk_synthesize_window_state (window,
430 GDK_WINDOW_STATE_STICKY,
435 if (toplevel->have_sticky || toplevel->on_all_desktops)
436 gdk_synthesize_window_state (window,
438 GDK_WINDOW_STATE_STICKY);
441 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
443 if (!toplevel->have_fullscreen)
444 gdk_synthesize_window_state (window,
445 GDK_WINDOW_STATE_FULLSCREEN,
450 if (toplevel->have_fullscreen)
451 gdk_synthesize_window_state (window,
453 GDK_WINDOW_STATE_FULLSCREEN);
456 /* Our "maximized" means both vertical and horizontal; if only one,
457 * we don't expose that via GDK
459 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
461 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
462 gdk_synthesize_window_state (window,
463 GDK_WINDOW_STATE_MAXIMIZED,
468 if (toplevel->have_maxvert && toplevel->have_maxhorz)
469 gdk_synthesize_window_state (window,
471 GDK_WINDOW_STATE_MAXIMIZED);
476 gdk_check_wm_desktop_changed (GdkWindow *window)
478 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
479 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
489 gdk_error_trap_push ();
490 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
491 GDK_WINDOW_XID (window),
492 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
493 0, G_MAXLONG, False, XA_CARDINAL, &type,
495 &bytes_after, &data);
496 gdk_error_trap_pop ();
500 desktop = (gulong *)data;
501 toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
505 toplevel->on_all_desktops = FALSE;
507 do_net_wm_state_changes (window);
511 gdk_check_wm_state_changed (GdkWindow *window)
513 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
514 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
524 gboolean had_sticky = toplevel->have_sticky;
526 toplevel->have_sticky = FALSE;
527 toplevel->have_maxvert = FALSE;
528 toplevel->have_maxhorz = FALSE;
529 toplevel->have_fullscreen = FALSE;
532 gdk_error_trap_push ();
533 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
534 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
535 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
536 &bytes_after, &data);
537 gdk_error_trap_pop ();
541 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
542 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
543 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
544 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
546 atoms = (Atom *)data;
551 if (atoms[i] == sticky_atom)
552 toplevel->have_sticky = TRUE;
553 else if (atoms[i] == maxvert_atom)
554 toplevel->have_maxvert = TRUE;
555 else if (atoms[i] == maxhorz_atom)
556 toplevel->have_maxhorz = TRUE;
557 else if (atoms[i] == fullscreen_atom)
558 toplevel->have_fullscreen = TRUE;
566 /* When have_sticky is turned on, we have to check the DESKTOP property
569 if (toplevel->have_sticky && !had_sticky)
570 gdk_check_wm_desktop_changed (window);
572 do_net_wm_state_changes (window);
575 #define HAS_FOCUS(toplevel) \
576 ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
579 generate_focus_event (GdkWindow *window,
584 event.type = GDK_FOCUS_CHANGE;
585 event.focus_change.window = window;
586 event.focus_change.send_event = FALSE;
587 event.focus_change.in = in;
589 gdk_event_put (&event);
593 set_screen_from_root (GdkDisplay *display,
599 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
603 gdk_event_set_screen (event, screen);
612 translate_key_event (GdkDisplay *display,
616 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
620 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
621 event->key.time = xevent->xkey.time;
623 event->key.state = (GdkModifierType) xevent->xkey.state;
624 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
625 event->key.hardware_keycode = xevent->xkey.keycode;
627 event->key.keyval = GDK_VoidSymbol;
629 gdk_keymap_translate_keyboard_state (keymap,
630 event->key.hardware_keycode,
636 _gdk_keymap_add_virtual_modifiers (keymap, &event->key.state);
637 event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
639 /* Fill in event->string crudely, since various programs
642 event->key.string = NULL;
644 if (event->key.keyval != GDK_VoidSymbol)
645 c = gdk_keyval_to_unicode (event->key.keyval);
652 /* Apply the control key - Taken from Xlib
654 if (event->key.state & GDK_CONTROL_MASK)
656 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
659 event->key.string = g_memdup ("\0\0", 2);
660 event->key.length = 1;
664 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
665 else if (c == '8') c = '\177';
666 else if (c == '/') c = '_' & 0x1F;
669 len = g_unichar_to_utf8 (c, buf);
672 event->key.string = g_locale_from_utf8 (buf, len,
673 NULL, &bytes_written,
675 if (event->key.string)
676 event->key.length = bytes_written;
678 else if (event->key.keyval == GDK_Escape)
680 event->key.length = 1;
681 event->key.string = g_strdup ("\033");
683 else if (event->key.keyval == GDK_Return ||
684 event->key.keyval == GDK_KP_Enter)
686 event->key.length = 1;
687 event->key.string = g_strdup ("\r");
690 if (!event->key.string)
692 event->key.length = 0;
693 event->key.string = g_strdup ("");
697 #ifdef G_ENABLE_DEBUG
698 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
700 g_message ("%s:\t\twindow: %ld key: %12s %d",
701 event->type == GDK_KEY_PRESS ? "key press " : "key release",
703 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
706 if (event->key.length > 0)
707 g_message ("\t\tlength: %4d string: \"%s\"",
708 event->key.length, buf);
710 #endif /* G_ENABLE_DEBUG */
715 * gdk_x11_register_standard_event_type:
716 * @display: a #GdkDisplay
717 * @event_base: first event type code to register
718 * @n_events: number of event type codes to register
720 * Registers interest in receiving extension events with type codes
721 * between @event_base and <literal>event_base + n_events - 1</literal>.
722 * The registered events must have the window field in the same place
723 * as core X events (this is not the case for e.g. XKB extension events).
725 * If an event type is registered, events of this type will go through
726 * global and window-specific filters (see gdk_window_add_filter()).
727 * Unregistered events will only go through global filters.
728 * GDK may register the events of some X extensions on its own.
730 * This function should only be needed in unusual circumstances, e.g.
731 * when filtering XInput extension events on the root window.
736 gdk_x11_register_standard_event_type (GdkDisplay *display,
740 GdkEventTypeX11 *event_type;
741 GdkDisplayX11 *display_x11;
743 display_x11 = GDK_DISPLAY_X11 (display);
744 event_type = g_new (GdkEventTypeX11, 1);
746 event_type->base = event_base;
747 event_type->n_events = n_events;
749 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
752 /* Return the window this has to do with, if any, rather
753 * than the frame or root window that was selecting
757 get_real_window (GdkDisplay *display,
759 Window *event_window,
760 Window *filter_window)
762 /* Core events all have an event->xany.window field, but that's
763 * not true for extension events
765 if (event->type >= KeyPress &&
766 event->type <= MappingNotify)
768 *filter_window = event->xany.window;
772 *event_window = event->xcreatewindow.window;
775 *event_window = event->xdestroywindow.window;
778 *event_window = event->xunmap.window;
781 *event_window = event->xmap.window;
784 *event_window = event->xmaprequest.window;
787 *event_window = event->xreparent.window;
789 case ConfigureNotify:
790 *event_window = event->xconfigure.window;
792 case ConfigureRequest:
793 *event_window = event->xconfigurerequest.window;
796 *event_window = event->xgravity.window;
798 case CirculateNotify:
799 *event_window = event->xcirculate.window;
801 case CirculateRequest:
802 *event_window = event->xcirculaterequest.window;
805 *event_window = event->xany.window;
810 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
813 for (tmp_list = display_x11->event_types;
815 tmp_list = tmp_list->next)
817 GdkEventTypeX11 *event_type = tmp_list->data;
819 if (event->type >= event_type->base &&
820 event->type < event_type->base + event_type->n_events)
822 *event_window = event->xany.window;
823 *filter_window = event->xany.window;
828 *event_window = None;
829 *filter_window = None;
833 #ifdef G_ENABLE_DEBUG
834 static const char notify_modes[][19] = {
841 static const char notify_details[][23] = {
846 "NotifyNonlinearVirtual",
854 set_user_time (GdkWindow *window,
857 g_return_if_fail (event != NULL);
859 window = gdk_window_get_toplevel (event->client.window);
860 g_return_if_fail (GDK_IS_WINDOW (window));
862 /* If an event doesn't have a valid timestamp, we shouldn't use it
863 * to update the latest user interaction time.
865 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
866 gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
867 gdk_event_get_time (event));
871 gdk_event_translate (GdkDisplay *display,
874 gboolean return_exposes)
878 GdkWindowObject *window_private;
879 GdkWindow *filter_window;
880 GdkWindowImplX11 *window_impl = NULL;
882 gint xoffset, yoffset;
883 GdkScreen *screen = NULL;
884 GdkScreenX11 *screen_x11 = NULL;
885 GdkToplevelX11 *toplevel = NULL;
886 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
887 Window xwindow, filter_xwindow;
891 /* init these, since the done: block uses them */
893 window_private = NULL;
894 event->any.window = NULL;
896 if (_gdk_default_filters)
898 /* Apply global filters */
899 GdkFilterReturn result;
900 result = gdk_event_apply_filters (xevent, event,
901 _gdk_default_filters);
903 if (result != GDK_FILTER_CONTINUE)
905 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
910 /* Find the GdkWindow that this event relates to.
911 * Basically this means substructure events
912 * are reported same as structure events
914 get_real_window (display, xevent, &xwindow, &filter_xwindow);
916 window = gdk_window_lookup_for_display (display, xwindow);
917 /* We may receive events such as NoExpose/GraphicsExpose
918 * and ShmCompletion for pixmaps
920 if (window && !GDK_IS_WINDOW (window))
922 window_private = (GdkWindowObject *) window;
924 /* We always run the filters for the window where the event
925 * is delivered, not the window that it relates to
927 if (filter_xwindow == xwindow)
928 filter_window = window;
931 filter_window = gdk_window_lookup_for_display (display, filter_xwindow);
932 if (filter_window && !GDK_IS_WINDOW (filter_window))
933 filter_window = NULL;
938 screen = GDK_WINDOW_SCREEN (window);
939 screen_x11 = GDK_SCREEN_X11 (screen);
940 toplevel = _gdk_x11_window_get_toplevel (window);
945 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
947 /* Move key events on focus window to the real toplevel, and
948 * filter out all other events on focus window
950 if (toplevel && xwindow == toplevel->focus_window)
952 switch (xevent->type)
956 xwindow = GDK_WINDOW_XID (window);
957 xevent->xany.window = xwindow;
964 g_object_ref (window);
967 event->any.window = window;
968 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
970 if (window_private && GDK_WINDOW_DESTROYED (window))
972 if (xevent->type != DestroyNotify)
978 else if (filter_window)
980 /* Apply per-window filters */
981 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
982 GdkFilterReturn result;
984 if (filter_private->filters)
986 g_object_ref (filter_window);
988 result = gdk_event_apply_filters (xevent, event,
989 filter_private->filters);
991 g_object_unref (filter_window);
993 if (result != GDK_FILTER_CONTINUE)
995 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
1001 if (screen_x11 && screen_x11->wmspec_check_window != None &&
1002 xwindow == screen_x11->wmspec_check_window)
1004 if (xevent->type == DestroyNotify)
1006 screen_x11->wmspec_check_window = None;
1007 g_free (screen_x11->window_manager_name);
1008 screen_x11->window_manager_name = g_strdup ("unknown");
1010 /* careful, reentrancy */
1011 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
1014 /* Eat events on this window unless someone had wrapped
1015 * it as a foreign window
1025 (xevent->xany.type == MotionNotify ||
1026 xevent->xany.type == ButtonRelease))
1028 if (_gdk_moveresize_handle_event (xevent))
1035 /* We do a "manual" conversion of the XEvent to a
1036 * GdkEvent. The structures are mostly the same so
1037 * the conversion is fairly straightforward. We also
1038 * optionally print debugging info regarding events
1046 _gdk_x11_window_get_offsets (window, &xoffset, &yoffset);
1054 switch (xevent->type)
1057 if (window_private == NULL)
1062 translate_key_event (display, event, xevent);
1063 set_user_time (window, event);
1067 if (window_private == NULL)
1073 /* Emulate detectable auto-repeat by checking to see
1074 * if the next event is a key press with the same
1075 * keycode and timestamp, and if so, ignoring the event.
1078 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
1082 XPeekEvent (xevent->xkey.display, &next_event);
1084 if (next_event.type == KeyPress &&
1085 next_event.xkey.keycode == xevent->xkey.keycode &&
1086 next_event.xkey.time == xevent->xkey.time)
1093 translate_key_event (display, event, xevent);
1098 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1099 xevent->xbutton.window,
1100 xevent->xbutton.x, xevent->xbutton.y,
1101 xevent->xbutton.button));
1103 if (window_private == NULL ||
1104 ((window_private->extension_events != 0) &&
1105 display_x11->input_ignore_core))
1111 /* If we get a ButtonPress event where the button is 4 or 5,
1112 it's a Scroll event */
1113 switch (xevent->xbutton.button)
1119 event->scroll.type = GDK_SCROLL;
1121 if (xevent->xbutton.button == 4)
1122 event->scroll.direction = GDK_SCROLL_UP;
1123 else if (xevent->xbutton.button == 5)
1124 event->scroll.direction = GDK_SCROLL_DOWN;
1125 else if (xevent->xbutton.button == 6)
1126 event->scroll.direction = GDK_SCROLL_LEFT;
1128 event->scroll.direction = GDK_SCROLL_RIGHT;
1130 event->scroll.window = window;
1131 event->scroll.time = xevent->xbutton.time;
1132 event->scroll.x = xevent->xbutton.x + xoffset;
1133 event->scroll.y = xevent->xbutton.y + yoffset;
1134 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
1135 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
1136 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
1137 event->scroll.device = display->core_pointer;
1139 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1148 event->button.type = GDK_BUTTON_PRESS;
1149 event->button.window = window;
1150 event->button.time = xevent->xbutton.time;
1151 event->button.x = xevent->xbutton.x + xoffset;
1152 event->button.y = xevent->xbutton.y + yoffset;
1153 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1154 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1155 event->button.axes = NULL;
1156 event->button.state = (GdkModifierType) xevent->xbutton.state;
1157 event->button.button = xevent->xbutton.button;
1158 event->button.device = display->core_pointer;
1160 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1166 _gdk_event_button_generate (display, event);
1170 set_user_time (window, event);
1172 _gdk_xgrab_check_button_event (window, xevent);
1177 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1178 xevent->xbutton.window,
1179 xevent->xbutton.x, xevent->xbutton.y,
1180 xevent->xbutton.button));
1182 if (window_private == NULL ||
1183 ((window_private->extension_events != 0) &&
1184 display_x11->input_ignore_core))
1190 /* We treat button presses as scroll wheel events, so ignore the release */
1191 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1192 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1198 event->button.type = GDK_BUTTON_RELEASE;
1199 event->button.window = window;
1200 event->button.time = xevent->xbutton.time;
1201 event->button.x = xevent->xbutton.x + xoffset;
1202 event->button.y = xevent->xbutton.y + yoffset;
1203 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1204 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1205 event->button.axes = NULL;
1206 event->button.state = (GdkModifierType) xevent->xbutton.state;
1207 event->button.button = xevent->xbutton.button;
1208 event->button.device = display->core_pointer;
1210 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1216 _gdk_xgrab_check_button_event (window, xevent);
1221 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1222 xevent->xmotion.window,
1223 xevent->xmotion.x, xevent->xmotion.y,
1224 (xevent->xmotion.is_hint) ? "true" : "false"));
1226 if (window_private == NULL ||
1227 ((window_private->extension_events != 0) &&
1228 display_x11->input_ignore_core))
1234 event->motion.type = GDK_MOTION_NOTIFY;
1235 event->motion.window = window;
1236 event->motion.time = xevent->xmotion.time;
1237 event->motion.x = xevent->xmotion.x + xoffset;
1238 event->motion.y = xevent->xmotion.y + yoffset;
1239 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1240 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1241 event->motion.axes = NULL;
1242 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1243 event->motion.is_hint = xevent->xmotion.is_hint;
1244 event->motion.device = display->core_pointer;
1246 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1256 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1257 xevent->xcrossing.window,
1258 xevent->xcrossing.detail,
1259 xevent->xcrossing.subwindow));
1261 if (window_private == NULL)
1267 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1273 /* Handle focusing (in the case where no window manager is running */
1274 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1276 toplevel->has_pointer = TRUE;
1278 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1280 gboolean had_focus = HAS_FOCUS (toplevel);
1282 toplevel->has_pointer_focus = TRUE;
1284 if (HAS_FOCUS (toplevel) != had_focus)
1285 generate_focus_event (window, TRUE);
1289 /* Tell XInput stuff about it if appropriate */
1290 if (window_private &&
1291 !GDK_WINDOW_DESTROYED (window) &&
1292 window_private->extension_events != 0)
1293 _gdk_input_enter_event (&xevent->xcrossing, window);
1295 event->crossing.type = GDK_ENTER_NOTIFY;
1296 event->crossing.window = window;
1298 /* If the subwindow field of the XEvent is non-NULL, then
1299 * lookup the corresponding GdkWindow.
1301 if (xevent->xcrossing.subwindow != None)
1302 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1304 event->crossing.subwindow = NULL;
1306 event->crossing.time = xevent->xcrossing.time;
1307 event->crossing.x = xevent->xcrossing.x + xoffset;
1308 event->crossing.y = xevent->xcrossing.y + yoffset;
1309 event->crossing.x_root = xevent->xcrossing.x_root;
1310 event->crossing.y_root = xevent->xcrossing.y_root;
1312 /* Translate the crossing mode into Gdk terms.
1314 switch (xevent->xcrossing.mode)
1317 event->crossing.mode = GDK_CROSSING_NORMAL;
1320 event->crossing.mode = GDK_CROSSING_GRAB;
1323 event->crossing.mode = GDK_CROSSING_UNGRAB;
1327 /* Translate the crossing detail into Gdk terms.
1329 switch (xevent->xcrossing.detail)
1331 case NotifyInferior:
1332 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1334 case NotifyAncestor:
1335 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1338 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1340 case NotifyNonlinear:
1341 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1343 case NotifyNonlinearVirtual:
1344 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1347 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1351 event->crossing.focus = xevent->xcrossing.focus;
1352 event->crossing.state = xevent->xcrossing.state;
1358 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1359 xevent->xcrossing.window,
1360 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1362 if (window_private == NULL)
1368 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1374 /* Handle focusing (in the case where no window manager is running */
1375 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1377 toplevel->has_pointer = FALSE;
1379 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1381 gboolean had_focus = HAS_FOCUS (toplevel);
1383 toplevel->has_pointer_focus = FALSE;
1385 if (HAS_FOCUS (toplevel) != had_focus)
1386 generate_focus_event (window, FALSE);
1390 event->crossing.type = GDK_LEAVE_NOTIFY;
1391 event->crossing.window = window;
1393 /* If the subwindow field of the XEvent is non-NULL, then
1394 * lookup the corresponding GdkWindow.
1396 if (xevent->xcrossing.subwindow != None)
1397 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1399 event->crossing.subwindow = NULL;
1401 event->crossing.time = xevent->xcrossing.time;
1402 event->crossing.x = xevent->xcrossing.x + xoffset;
1403 event->crossing.y = xevent->xcrossing.y + yoffset;
1404 event->crossing.x_root = xevent->xcrossing.x_root;
1405 event->crossing.y_root = xevent->xcrossing.y_root;
1407 /* Translate the crossing mode into Gdk terms.
1409 switch (xevent->xcrossing.mode)
1412 event->crossing.mode = GDK_CROSSING_NORMAL;
1415 event->crossing.mode = GDK_CROSSING_GRAB;
1418 event->crossing.mode = GDK_CROSSING_UNGRAB;
1422 /* Translate the crossing detail into Gdk terms.
1424 switch (xevent->xcrossing.detail)
1426 case NotifyInferior:
1427 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1429 case NotifyAncestor:
1430 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1433 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1435 case NotifyNonlinear:
1436 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1438 case NotifyNonlinearVirtual:
1439 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1442 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1446 event->crossing.focus = xevent->xcrossing.focus;
1447 event->crossing.state = xevent->xcrossing.state;
1451 /* We only care about focus events that indicate that _this_
1452 * window (not a ancestor or child) got or lost the focus
1456 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1457 xevent->xfocus.window,
1458 notify_details[xevent->xfocus.detail],
1459 notify_modes[xevent->xfocus.mode]));
1463 gboolean had_focus = HAS_FOCUS (toplevel);
1465 switch (xevent->xfocus.detail)
1467 case NotifyAncestor:
1469 /* When the focus moves from an ancestor of the window to
1470 * the window or a descendent of the window, *and* the
1471 * pointer is inside the window, then we were previously
1472 * receiving keystroke events in the has_pointer_focus
1473 * case and are now receiving them in the
1474 * has_focus_window case.
1476 if (toplevel->has_pointer &&
1477 xevent->xfocus.mode != NotifyGrab &&
1478 xevent->xfocus.mode != NotifyUngrab)
1479 toplevel->has_pointer_focus = FALSE;
1482 case NotifyNonlinear:
1483 case NotifyNonlinearVirtual:
1484 if (xevent->xfocus.mode != NotifyGrab &&
1485 xevent->xfocus.mode != NotifyUngrab)
1486 toplevel->has_focus_window = TRUE;
1487 /* We pretend that the focus moves to the grab
1488 * window, so we pay attention to NotifyGrab
1489 * NotifyUngrab, and ignore NotifyWhileGrabbed
1491 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1492 toplevel->has_focus = TRUE;
1495 /* The X server sends NotifyPointer/NotifyGrab,
1496 * but the pointer focus is ignored while a
1499 if (xevent->xfocus.mode != NotifyGrab &&
1500 xevent->xfocus.mode != NotifyUngrab)
1501 toplevel->has_pointer_focus = TRUE;
1503 case NotifyInferior:
1504 case NotifyPointerRoot:
1505 case NotifyDetailNone:
1509 if (HAS_FOCUS (toplevel) != had_focus)
1510 generate_focus_event (window, TRUE);
1515 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1516 xevent->xfocus.window,
1517 notify_details[xevent->xfocus.detail],
1518 notify_modes[xevent->xfocus.mode]));
1522 gboolean had_focus = HAS_FOCUS (toplevel);
1524 switch (xevent->xfocus.detail)
1526 case NotifyAncestor:
1528 /* When the focus moves from the window or a descendent
1529 * of the window to an ancestor of the window, *and* the
1530 * pointer is inside the window, then we were previously
1531 * receiving keystroke events in the has_focus_window
1532 * case and are now receiving them in the
1533 * has_pointer_focus case.
1535 if (toplevel->has_pointer &&
1536 xevent->xfocus.mode != NotifyGrab &&
1537 xevent->xfocus.mode != NotifyUngrab)
1538 toplevel->has_pointer_focus = TRUE;
1541 case NotifyNonlinear:
1542 case NotifyNonlinearVirtual:
1543 if (xevent->xfocus.mode != NotifyGrab &&
1544 xevent->xfocus.mode != NotifyUngrab)
1545 toplevel->has_focus_window = FALSE;
1546 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1547 toplevel->has_focus = FALSE;
1550 if (xevent->xfocus.mode != NotifyGrab &&
1551 xevent->xfocus.mode != NotifyUngrab)
1552 toplevel->has_pointer_focus = FALSE;
1554 case NotifyInferior:
1555 case NotifyPointerRoot:
1556 case NotifyDetailNone:
1560 if (HAS_FOCUS (toplevel) != had_focus)
1561 generate_focus_event (window, FALSE);
1566 /* gdk_keyboard_grab() causes following events. These events confuse
1567 * the XIM focus, so ignore them.
1569 if (xevent->xfocus.mode == NotifyGrab ||
1570 xevent->xfocus.mode == NotifyUngrab)
1576 g_message ("keymap notify"));
1578 /* Not currently handled */
1584 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1585 xevent->xexpose.window, xevent->xexpose.count,
1586 xevent->xexpose.x, xevent->xexpose.y,
1587 xevent->xexpose.width, xevent->xexpose.height,
1588 event->any.send_event ? " (send)" : ""));
1590 if (window_private == NULL)
1597 GdkRectangle expose_rect;
1599 expose_rect.x = xevent->xexpose.x + xoffset;
1600 expose_rect.y = xevent->xexpose.y + yoffset;
1601 expose_rect.width = xevent->xexpose.width;
1602 expose_rect.height = xevent->xexpose.height;
1606 event->expose.type = GDK_EXPOSE;
1607 event->expose.area = expose_rect;
1608 event->expose.region = gdk_region_rectangle (&expose_rect);
1609 event->expose.window = window;
1610 event->expose.count = xevent->xexpose.count;
1616 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1625 case GraphicsExpose:
1627 GdkRectangle expose_rect;
1630 g_message ("graphics expose:\tdrawable: %ld",
1631 xevent->xgraphicsexpose.drawable));
1633 if (window_private == NULL)
1639 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1640 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1641 expose_rect.width = xevent->xgraphicsexpose.width;
1642 expose_rect.height = xevent->xgraphicsexpose.height;
1646 event->expose.type = GDK_EXPOSE;
1647 event->expose.area = expose_rect;
1648 event->expose.region = gdk_region_rectangle (&expose_rect);
1649 event->expose.window = window;
1650 event->expose.count = xevent->xgraphicsexpose.count;
1656 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1666 g_message ("no expose:\t\tdrawable: %ld",
1667 xevent->xnoexpose.drawable));
1669 event->no_expose.type = GDK_NO_EXPOSE;
1670 event->no_expose.window = window;
1674 case VisibilityNotify:
1675 #ifdef G_ENABLE_DEBUG
1676 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1677 switch (xevent->xvisibility.state)
1679 case VisibilityFullyObscured:
1680 g_message ("visibility notify:\twindow: %ld none",
1681 xevent->xvisibility.window);
1683 case VisibilityPartiallyObscured:
1684 g_message ("visibility notify:\twindow: %ld partial",
1685 xevent->xvisibility.window);
1687 case VisibilityUnobscured:
1688 g_message ("visibility notify:\twindow: %ld full",
1689 xevent->xvisibility.window);
1692 #endif /* G_ENABLE_DEBUG */
1694 if (window_private == NULL)
1700 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1701 event->visibility.window = window;
1703 switch (xevent->xvisibility.state)
1705 case VisibilityFullyObscured:
1706 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1709 case VisibilityPartiallyObscured:
1710 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1713 case VisibilityUnobscured:
1714 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1722 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1723 xevent->xcreatewindow.window,
1724 xevent->xcreatewindow.x,
1725 xevent->xcreatewindow.y,
1726 xevent->xcreatewindow.width,
1727 xevent->xcreatewindow.height,
1728 xevent->xcreatewindow.border_width,
1729 xevent->xcreatewindow.parent,
1730 xevent->xcreatewindow.override_redirect));
1731 /* not really handled */
1736 g_message ("destroy notify:\twindow: %ld",
1737 xevent->xdestroywindow.window));
1739 /* Ignore DestroyNotify from SubstructureNotifyMask */
1740 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1742 event->any.type = GDK_DESTROY;
1743 event->any.window = window;
1745 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1747 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1748 gdk_window_destroy_notify (window);
1757 g_message ("unmap notify:\t\twindow: %ld",
1758 xevent->xmap.window));
1760 event->any.type = GDK_UNMAP;
1761 event->any.window = window;
1763 /* If we are shown (not withdrawn) and get an unmap, it means we
1764 * were iconified in the X sense. If we are withdrawn, and get
1765 * an unmap, it means we hid the window ourselves, so we
1766 * will have already flipped the iconified bit off.
1770 if (GDK_WINDOW_IS_MAPPED (window))
1771 gdk_synthesize_window_state (window,
1773 GDK_WINDOW_STATE_ICONIFIED);
1775 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1782 g_message ("map notify:\t\twindow: %ld",
1783 xevent->xmap.window));
1785 event->any.type = GDK_MAP;
1786 event->any.window = window;
1788 /* Unset iconified if it was set */
1789 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1790 gdk_synthesize_window_state (window,
1791 GDK_WINDOW_STATE_ICONIFIED,
1796 case ReparentNotify:
1798 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1799 xevent->xreparent.window,
1800 xevent->xreparent.x,
1801 xevent->xreparent.y,
1802 xevent->xreparent.parent,
1803 xevent->xreparent.override_redirect));
1805 /* Not currently handled */
1809 case ConfigureNotify:
1811 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1812 xevent->xconfigure.window,
1813 xevent->xconfigure.x,
1814 xevent->xconfigure.y,
1815 xevent->xconfigure.width,
1816 xevent->xconfigure.height,
1817 xevent->xconfigure.border_width,
1818 xevent->xconfigure.above,
1819 xevent->xconfigure.override_redirect,
1822 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1823 ? " (discarding child)"
1824 : xevent->xconfigure.event != xevent->xconfigure.window
1825 ? " (discarding substructure)"
1827 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1829 window_impl->width = xevent->xconfigure.width;
1830 window_impl->height = xevent->xconfigure.height;
1832 _gdk_x11_drawable_update_size (window_private->impl);
1833 _gdk_x11_screen_size_changed (screen, xevent);
1837 xevent->xconfigure.event == xevent->xconfigure.window &&
1838 !GDK_WINDOW_DESTROYED (window) &&
1839 (window_private->extension_events != 0))
1840 _gdk_input_configure_event (&xevent->xconfigure, window);
1843 if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
1845 toplevel->current_counter_value = toplevel->pending_counter_value;
1846 XSyncIntToValue (&toplevel->pending_counter_value, 0);
1851 xevent->xconfigure.event != xevent->xconfigure.window ||
1852 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1853 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1857 event->configure.type = GDK_CONFIGURE;
1858 event->configure.window = window;
1859 event->configure.width = xevent->xconfigure.width;
1860 event->configure.height = xevent->xconfigure.height;
1862 if (!xevent->xconfigure.send_event &&
1863 !xevent->xconfigure.override_redirect &&
1864 !GDK_WINDOW_DESTROYED (window))
1868 Window child_window = 0;
1870 gdk_error_trap_push ();
1871 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1872 GDK_DRAWABLE_XID (window),
1873 screen_x11->xroot_window,
1878 event->configure.x = tx;
1879 event->configure.y = ty;
1881 gdk_error_trap_pop ();
1885 event->configure.x = xevent->xconfigure.x;
1886 event->configure.y = xevent->xconfigure.y;
1888 window_private->x = event->configure.x;
1889 window_private->y = event->configure.y;
1890 window_impl->width = xevent->xconfigure.width;
1891 window_impl->height = xevent->xconfigure.height;
1893 _gdk_x11_drawable_update_size (window_private->impl);
1895 if (window_private->resize_count >= 1)
1897 window_private->resize_count -= 1;
1899 if (window_private->resize_count == 0)
1900 _gdk_moveresize_configure_done (display, window);
1905 case PropertyNotify:
1907 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1908 xevent->xproperty.window,
1909 xevent->xproperty.atom,
1911 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1914 if (window_private == NULL)
1920 /* We compare with the serial of the last time we mapped the
1921 * window to avoid refetching properties that we set ourselves
1924 xevent->xproperty.serial >= toplevel->map_serial)
1926 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1927 gdk_check_wm_state_changed (window);
1929 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1930 gdk_check_wm_desktop_changed (window);
1933 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1935 event->property.type = GDK_PROPERTY_NOTIFY;
1936 event->property.window = window;
1937 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1938 event->property.time = xevent->xproperty.time;
1939 event->property.state = xevent->xproperty.state;
1946 case SelectionClear:
1948 g_message ("selection clear:\twindow: %ld",
1949 xevent->xproperty.window));
1951 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1953 event->selection.type = GDK_SELECTION_CLEAR;
1954 event->selection.window = window;
1955 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1956 event->selection.time = xevent->xselectionclear.time;
1963 case SelectionRequest:
1965 g_message ("selection request:\twindow: %ld",
1966 xevent->xproperty.window));
1968 event->selection.type = GDK_SELECTION_REQUEST;
1969 event->selection.window = window;
1970 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1971 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1972 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1973 event->selection.requestor = xevent->xselectionrequest.requestor;
1974 event->selection.time = xevent->xselectionrequest.time;
1978 case SelectionNotify:
1980 g_message ("selection notify:\twindow: %ld",
1981 xevent->xproperty.window));
1984 event->selection.type = GDK_SELECTION_NOTIFY;
1985 event->selection.window = window;
1986 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1987 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1988 if (xevent->xselection.property == None)
1989 event->selection.property = GDK_NONE;
1991 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1992 event->selection.time = xevent->xselection.time;
1996 case ColormapNotify:
1998 g_message ("colormap notify:\twindow: %ld",
1999 xevent->xcolormap.window));
2001 /* Not currently handled */
2008 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2009 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
2012 g_message ("client message:\twindow: %ld",
2013 xevent->xclient.window));
2015 tmp_list = display_x11->client_filters;
2018 GdkClientFilter *filter = tmp_list->data;
2019 tmp_list = tmp_list->next;
2021 if (filter->type == message_type)
2023 result = (*filter->function) (xevent, event, filter->data);
2024 if (result != GDK_FILTER_CONTINUE)
2031 case GDK_FILTER_REMOVE:
2034 case GDK_FILTER_TRANSLATE:
2037 case GDK_FILTER_CONTINUE:
2038 /* Send unknown ClientMessage's on to Gtk for it to use */
2039 if (window_private == NULL)
2045 event->client.type = GDK_CLIENT_EVENT;
2046 event->client.window = window;
2047 event->client.message_type = message_type;
2048 event->client.data_format = xevent->xclient.format;
2049 memcpy(&event->client.data, &xevent->xclient.data,
2050 sizeof(event->client.data));
2060 g_message ("mapping notify"));
2062 /* Let XLib know that there is a new keyboard mapping.
2064 XRefreshKeyboardMapping (&xevent->xmapping);
2065 _gdk_keymap_keys_changed (display);
2071 if (xevent->type == display_x11->xkb_event_type)
2073 XkbEvent *xkb_event = (XkbEvent *)xevent;
2075 switch (xkb_event->any.xkb_type)
2077 case XkbNewKeyboardNotify:
2079 _gdk_keymap_keys_changed (display);
2084 case XkbStateNotify:
2085 _gdk_keymap_state_changed (display, xevent);
2092 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
2094 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
2096 _gdk_x11_screen_process_owner_change (screen, xevent);
2098 event->owner_change.type = GDK_OWNER_CHANGE;
2099 event->owner_change.window = window;
2100 event->owner_change.owner = selection_notify->owner;
2101 event->owner_change.reason = selection_notify->subtype;
2102 event->owner_change.selection =
2103 gdk_x11_xatom_to_atom_for_display (display,
2104 selection_notify->selection);
2105 event->owner_change.time = selection_notify->timestamp;
2106 event->owner_change.selection_time = selection_notify->selection_timestamp;
2113 if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
2114 xevent->type - display_x11->xrandr_event_base == RRNotify)
2117 _gdk_x11_screen_size_changed (screen, xevent);
2121 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
2122 if (display_x11->have_xdamage && window_private && window_private->composited &&
2123 xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
2124 ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
2126 XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
2127 XserverRegion repair;
2130 rect.x = window_private->x + damage_event->area.x;
2131 rect.y = window_private->y + damage_event->area.y;
2132 rect.width = damage_event->area.width;
2133 rect.height = damage_event->area.height;
2135 repair = XFixesCreateRegion (display_x11->xdisplay,
2136 &damage_event->area, 1);
2137 XDamageSubtract (display_x11->xdisplay,
2138 window_impl->damage,
2140 XFixesDestroyRegion (display_x11->xdisplay, repair);
2142 if (window_private->parent != NULL)
2143 _gdk_window_process_expose (GDK_WINDOW (window_private->parent),
2144 damage_event->serial, &rect);
2151 /* something else - (e.g., a Xinput event) */
2153 if (window_private &&
2154 !GDK_WINDOW_DESTROYED (window_private) &&
2155 (window_private->extension_events != 0))
2156 return_val = _gdk_input_other_event(event, xevent, window);
2167 if (event->any.window)
2168 g_object_ref (event->any.window);
2169 if (((event->any.type == GDK_ENTER_NOTIFY) ||
2170 (event->any.type == GDK_LEAVE_NOTIFY)) &&
2171 (event->crossing.subwindow != NULL))
2172 g_object_ref (event->crossing.subwindow);
2176 /* Mark this event as having no resources to be freed */
2177 event->any.window = NULL;
2178 event->any.type = GDK_NOTHING;
2182 g_object_unref (window);
2187 static GdkFilterReturn
2188 gdk_wm_protocols_filter (GdkXEvent *xev,
2192 XEvent *xevent = (XEvent *)xev;
2193 GdkWindow *win = event->any.window;
2194 GdkDisplay *display;
2198 return GDK_FILTER_REMOVE;
2200 display = GDK_WINDOW_DISPLAY (win);
2201 atom = (Atom)xevent->xclient.data.l[0];
2203 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
2205 /* The delete window request specifies a window
2206 * to delete. We don't actually destroy the
2207 * window because "it is only a request". (The
2208 * window might contain vital data that the
2209 * program does not want destroyed). Instead
2210 * the event is passed along to the program,
2211 * which should then destroy the window.
2214 g_message ("delete window:\t\twindow: %ld",
2215 xevent->xclient.window));
2217 event->any.type = GDK_DELETE;
2219 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
2221 return GDK_FILTER_TRANSLATE;
2223 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
2225 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2226 GdkWindowObject *private = (GdkWindowObject *)win;
2228 /* There is no way of knowing reliably whether we are viewable;
2229 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2231 if (toplevel && private->accept_focus)
2232 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
2234 xevent->xclient.data.l[1]);
2236 return GDK_FILTER_REMOVE;
2238 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
2239 !_gdk_x11_display_is_root_window (display,
2240 xevent->xclient.window))
2242 XClientMessageEvent xclient = xevent->xclient;
2244 xclient.window = GDK_WINDOW_XROOTWIN (win);
2245 XSendEvent (GDK_WINDOW_XDISPLAY (win),
2248 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
2250 return GDK_FILTER_REMOVE;
2252 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
2253 GDK_DISPLAY_X11 (display)->use_sync)
2255 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2259 XSyncIntsToValue (&toplevel->pending_counter_value,
2260 xevent->xclient.data.l[2],
2261 xevent->xclient.data.l[3]);
2264 return GDK_FILTER_REMOVE;
2267 return GDK_FILTER_CONTINUE;
2271 _gdk_events_queue (GdkDisplay *display)
2276 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2278 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
2280 XNextEvent (xdisplay, &xevent);
2282 switch (xevent.type)
2288 if (XFilterEvent (&xevent, None))
2292 event = gdk_event_new (GDK_NOTHING);
2294 event->any.window = NULL;
2295 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
2297 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2299 node = _gdk_event_queue_append (display, event);
2301 if (gdk_event_translate (display, event, &xevent, FALSE))
2303 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2307 _gdk_event_queue_remove_link (display, node);
2308 g_list_free_1 (node);
2309 gdk_event_free (event);
2315 gdk_event_prepare (GSource *source,
2318 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2321 GDK_THREADS_ENTER ();
2324 retval = (_gdk_event_queue_find_first (display) != NULL ||
2325 gdk_check_xpending (display));
2327 GDK_THREADS_LEAVE ();
2333 gdk_event_check (GSource *source)
2335 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2338 GDK_THREADS_ENTER ();
2340 if (display_source->event_poll_fd.revents & G_IO_IN)
2341 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2342 gdk_check_xpending (display_source->display));
2346 GDK_THREADS_LEAVE ();
2352 gdk_event_dispatch (GSource *source,
2353 GSourceFunc callback,
2356 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2359 GDK_THREADS_ENTER ();
2361 _gdk_events_queue (display);
2362 event = _gdk_event_unqueue (display);
2366 if (_gdk_event_func)
2367 (*_gdk_event_func) (event, _gdk_event_data);
2369 gdk_event_free (event);
2372 GDK_THREADS_LEAVE ();
2378 * gdk_event_send_client_message_for_display:
2379 * @display: the #GdkDisplay for the window where the message is to be sent.
2380 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2381 * @winid: the window to send the client message to.
2383 * On X11, sends an X ClientMessage event to a given window. On
2384 * Windows, sends a message registered with the name
2385 * GDK_WIN32_CLIENT_MESSAGE.
2387 * This could be used for communicating between different
2388 * applications, though the amount of data is limited to 20 bytes on
2389 * X11, and to just four bytes on Windows.
2391 * Returns: non-zero on success.
2396 gdk_event_send_client_message_for_display (GdkDisplay *display,
2398 GdkNativeWindow winid)
2402 g_return_val_if_fail(event != NULL, FALSE);
2404 /* Set up our event to send, with the exception of its target window */
2405 sev.xclient.type = ClientMessage;
2406 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2407 sev.xclient.format = event->client.data_format;
2408 sev.xclient.window = winid;
2409 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2410 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2412 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2417 /* Sends a ClientMessage to all toplevel client windows */
2419 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2426 unsigned long nitems, after;
2427 unsigned char *data;
2428 Window *ret_children, ret_root, ret_parent;
2429 unsigned int ret_nchildren;
2430 gboolean send = FALSE;
2431 gboolean found = FALSE;
2432 gboolean result = FALSE;
2435 gdk_error_trap_push ();
2437 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2438 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
2439 0, 0, False, AnyPropertyType,
2440 &type, &format, &nitems, &after, &data) != Success)
2450 /* OK, we're all set, now let's find some windows to send this to */
2451 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2452 &ret_root, &ret_parent,
2453 &ret_children, &ret_nchildren))
2456 for(i = 0; i < ret_nchildren; i++)
2457 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2460 XFree (ret_children);
2463 if (send || (!found && (level == 1)))
2465 xev->xclient.window = xid;
2466 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2469 result = send || found;
2472 gdk_error_trap_pop ();
2478 * gdk_screen_broadcast_client_message:
2479 * @screen: the #GdkScreen where the event will be broadcasted.
2480 * @event: the #GdkEvent.
2482 * On X11, sends an X ClientMessage event to all toplevel windows on
2485 * Toplevel windows are determined by checking for the WM_STATE property,
2486 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2487 * If no windows are found with the WM_STATE property set, the message is
2488 * sent to all children of the root window.
2490 * On Windows, broadcasts a message registered with the name
2491 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
2492 * data is limited to one long, i.e. four bytes.
2498 gdk_screen_broadcast_client_message (GdkScreen *screen,
2502 GdkWindow *root_window;
2504 g_return_if_fail (event != NULL);
2506 root_window = gdk_screen_get_root_window (screen);
2508 /* Set up our event to send, with the exception of its target window */
2509 sev.xclient.type = ClientMessage;
2510 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2511 sev.xclient.format = event->client.data_format;
2512 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2513 sev.xclient.message_type =
2514 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2515 event->client.message_type);
2517 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2519 GDK_WINDOW_XID (root_window),
2524 *--------------------------------------------------------------
2527 * Flushes the Xlib output buffer and then waits
2528 * until all requests have been received and processed
2529 * by the X server. The only real use for this function
2530 * is in dealing with XShm.
2538 *--------------------------------------------------------------
2544 GSList *tmp_list = _gdk_displays;
2548 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2549 tmp_list = tmp_list->next;
2554 timestamp_predicate (Display *display,
2558 Window xwindow = GPOINTER_TO_UINT (arg);
2559 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2561 if (xevent->type == PropertyNotify &&
2562 xevent->xproperty.window == xwindow &&
2563 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2564 "GDK_TIMESTAMP_PROP"))
2571 * gdk_x11_get_server_time:
2572 * @window: a #GdkWindow, used for communication with the server.
2573 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2574 * events mask or a hang will result.
2576 * Routine to get the current X server time stamp.
2578 * Return value: the time stamp.
2581 gdk_x11_get_server_time (GdkWindow *window)
2587 Atom timestamp_prop_atom;
2589 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2590 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2592 xdisplay = GDK_WINDOW_XDISPLAY (window);
2593 xwindow = GDK_WINDOW_XWINDOW (window);
2594 timestamp_prop_atom =
2595 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2596 "GDK_TIMESTAMP_PROP");
2598 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2599 timestamp_prop_atom,
2600 8, PropModeReplace, &c, 1);
2602 XIfEvent (xdisplay, &xevent,
2603 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2605 return xevent.xproperty.time;
2609 fetch_net_wm_check_window (GdkScreen *screen)
2611 GdkScreenX11 *screen_x11;
2612 GdkDisplay *display;
2621 screen_x11 = GDK_SCREEN_X11 (screen);
2622 display = screen_x11->display;
2624 g_return_if_fail (GDK_DISPLAY_X11 (display)->trusted_client);
2626 g_get_current_time (&tv);
2628 if (ABS (tv.tv_sec - screen_x11->last_wmspec_check_time) < 15)
2629 return; /* we've checked recently */
2631 screen_x11->last_wmspec_check_time = tv.tv_sec;
2634 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2635 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2636 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2637 &n_items, &bytes_after, &data);
2639 if (type != XA_WINDOW)
2646 xwindow = (Window *)data;
2648 if (screen_x11->wmspec_check_window == *xwindow)
2654 gdk_error_trap_push ();
2656 /* Find out if this WM goes away, so we can reset everything. */
2657 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2658 gdk_display_sync (display);
2660 if (gdk_error_trap_pop () == Success)
2662 screen_x11->wmspec_check_window = *xwindow;
2663 screen_x11->need_refetch_net_supported = TRUE;
2664 screen_x11->need_refetch_wm_name = TRUE;
2666 /* Careful, reentrancy */
2667 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2674 * gdk_x11_screen_get_window_manager_name:
2675 * @screen: a #GdkScreen
2677 * Returns the name of the window manager for @screen.
2679 * Return value: the name of the window manager screen @screen, or
2680 * "unknown" if the window manager is unknown. The string is owned by GDK
2681 * and should not be freed.
2686 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2688 GdkScreenX11 *screen_x11;
2690 screen_x11 = GDK_SCREEN_X11 (screen);
2692 if (!G_LIKELY (GDK_DISPLAY_X11 (screen_x11->display)->trusted_client))
2693 return screen_x11->window_manager_name;
2695 fetch_net_wm_check_window (screen);
2697 if (screen_x11->need_refetch_wm_name)
2699 /* Get the name of the window manager */
2700 screen_x11->need_refetch_wm_name = FALSE;
2702 g_free (screen_x11->window_manager_name);
2703 screen_x11->window_manager_name = g_strdup ("unknown");
2705 if (screen_x11->wmspec_check_window != None)
2715 gdk_error_trap_push ();
2717 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2718 screen_x11->wmspec_check_window,
2719 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2721 0, G_MAXLONG, False,
2722 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2725 &n_items, &bytes_after,
2728 gdk_display_sync (screen_x11->display);
2730 gdk_error_trap_pop ();
2734 g_free (screen_x11->window_manager_name);
2735 screen_x11->window_manager_name = g_strdup (name);
2741 return GDK_SCREEN_X11 (screen)->window_manager_name;
2744 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2746 struct _NetWmSupportedAtoms
2753 cleanup_atoms(gpointer data)
2755 NetWmSupportedAtoms *supported_atoms = data;
2756 if (supported_atoms->atoms)
2757 XFree (supported_atoms->atoms);
2758 g_free (supported_atoms);
2762 * gdk_x11_screen_supports_net_wm_hint:
2763 * @screen: the relevant #GdkScreen.
2764 * @property: a property atom.
2766 * This function is specific to the X11 backend of GDK, and indicates
2767 * whether the window manager supports a certain hint from the
2768 * Extended Window Manager Hints Specification. You can find this
2770 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2772 * When using this function, keep in mind that the window manager
2773 * can change over time; so you shouldn't use this function in
2774 * a way that impacts persistent application state. A common bug
2775 * is that your application can start up before the window manager
2776 * does when the user logs in, and before the window manager starts
2777 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2778 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2779 * a window manager change.
2781 * Return value: %TRUE if the window manager supports @property
2786 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2790 GdkScreenX11 *screen_x11;
2791 NetWmSupportedAtoms *supported_atoms;
2792 GdkDisplay *display;
2794 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2796 screen_x11 = GDK_SCREEN_X11 (screen);
2797 display = screen_x11->display;
2799 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
2802 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2803 if (!supported_atoms)
2805 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2806 g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms);
2809 fetch_net_wm_check_window (screen);
2811 if (screen_x11->wmspec_check_window == None)
2814 if (screen_x11->need_refetch_net_supported)
2816 /* WM has changed since we last got the supported list,
2823 screen_x11->need_refetch_net_supported = FALSE;
2825 if (supported_atoms->atoms)
2826 XFree (supported_atoms->atoms);
2828 supported_atoms->atoms = NULL;
2829 supported_atoms->n_atoms = 0;
2831 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2832 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2833 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2834 &supported_atoms->n_atoms, &bytes_after,
2835 (guchar **)&supported_atoms->atoms);
2837 if (type != XA_ATOM)
2841 if (supported_atoms->atoms == NULL)
2845 while (i < supported_atoms->n_atoms)
2847 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2857 * gdk_net_wm_supports:
2858 * @property: a property atom.
2860 * This function is specific to the X11 backend of GDK, and indicates
2861 * whether the window manager for the default screen supports a certain
2862 * hint from the Extended Window Manager Hints Specification. See
2863 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2865 * Return value: %TRUE if the window manager supports @property
2868 gdk_net_wm_supports (GdkAtom property)
2870 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2875 gdk_xsettings_notify_cb (const char *name,
2876 XSettingsAction action,
2877 XSettingsSetting *setting,
2881 GdkScreen *screen = data;
2882 GdkScreenX11 *screen_x11 = data;
2885 if (screen_x11->xsettings_in_init)
2888 new_event.type = GDK_SETTING;
2889 new_event.setting.window = gdk_screen_get_root_window (screen);
2890 new_event.setting.send_event = FALSE;
2891 new_event.setting.name = NULL;
2893 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS() ; i++)
2894 if (strcmp (GDK_SETTINGS_X_NAME (i), name) == 0)
2896 new_event.setting.name = (char*) GDK_SETTINGS_GDK_NAME (i);
2900 if (!new_event.setting.name)
2905 case XSETTINGS_ACTION_NEW:
2906 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2908 case XSETTINGS_ACTION_CHANGED:
2909 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2911 case XSETTINGS_ACTION_DELETED:
2912 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2916 gdk_event_put (&new_event);
2920 check_transform (const gchar *xsettings_name,
2924 if (!g_value_type_transformable (src_type, dest_type))
2926 g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
2928 g_type_name (src_type),
2929 g_type_name (dest_type));
2937 * gdk_screen_get_setting:
2938 * @screen: the #GdkScreen where the setting is located
2939 * @name: the name of the setting
2940 * @value: location to store the value of the setting
2942 * Retrieves a desktop-wide setting such as double-click time
2943 * for the #GdkScreen @screen.
2945 * FIXME needs a list of valid settings here, or a link to
2948 * Returns: %TRUE if the setting existed and a value was stored
2949 * in @value, %FALSE otherwise.
2954 gdk_screen_get_setting (GdkScreen *screen,
2959 const char *xsettings_name = NULL;
2960 XSettingsResult result;
2961 XSettingsSetting *setting = NULL;
2962 GdkScreenX11 *screen_x11;
2963 gboolean success = FALSE;
2965 GValue tmp_val = { 0, };
2967 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2969 screen_x11 = GDK_SCREEN_X11 (screen);
2971 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS(); i++)
2972 if (strcmp (GDK_SETTINGS_GDK_NAME (i), name) == 0)
2974 xsettings_name = GDK_SETTINGS_X_NAME (i);
2978 if (!xsettings_name)
2981 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2982 xsettings_name, &setting);
2983 if (result != XSETTINGS_SUCCESS)
2986 switch (setting->type)
2988 case XSETTINGS_TYPE_INT:
2989 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2991 g_value_init (&tmp_val, G_TYPE_INT);
2992 g_value_set_int (&tmp_val, setting->data.v_int);
2993 g_value_transform (&tmp_val, value);
2998 case XSETTINGS_TYPE_STRING:
2999 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
3001 g_value_init (&tmp_val, G_TYPE_STRING);
3002 g_value_set_string (&tmp_val, setting->data.v_string);
3003 g_value_transform (&tmp_val, value);
3008 case XSETTINGS_TYPE_COLOR:
3009 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
3013 g_value_init (&tmp_val, GDK_TYPE_COLOR);
3016 color.red = setting->data.v_color.red;
3017 color.green = setting->data.v_color.green;
3018 color.blue = setting->data.v_color.blue;
3020 g_value_set_boxed (&tmp_val, &color);
3022 g_value_transform (&tmp_val, value);
3029 g_value_unset (&tmp_val);
3033 xsettings_setting_free (setting);
3038 return _gdk_x11_get_xft_setting (screen, name, value);
3041 static GdkFilterReturn
3042 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
3046 GdkScreenX11 *screen = data;
3048 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
3049 return GDK_FILTER_REMOVE;
3051 return GDK_FILTER_CONTINUE;
3055 gdk_xsettings_watch_cb (Window window,
3061 GdkScreen *screen = cb_data;
3063 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
3068 g_object_ref (gdkwin);
3071 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
3073 /* gdk_window_foreign_new_for_display() can fail and return NULL if the
3074 * window has already been destroyed.
3080 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3086 /* gdkwin should not be NULL here, since if starting the watch succeeded
3087 * we have a reference on the window. It might mean that the caller didn't
3088 * remove the watch when it got a DestroyNotify event. Or maybe the
3089 * caller ignored the return value when starting the watch failed.
3091 g_warning ("gdk_xsettings_watch_cb(): Couldn't find window to unwatch");
3095 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3096 g_object_unref (gdkwin);
3103 _gdk_windowing_event_data_copy (const GdkEvent *src,
3109 _gdk_windowing_event_data_free (GdkEvent *event)
3113 #define __GDK_EVENTS_X11_C__
3114 #include "gdkaliasdef.c"