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 is_parent_of (GdkWindow *parent,
882 w = gdk_window_get_parent (w);
889 gdk_event_translate (GdkDisplay *display,
892 gboolean return_exposes)
896 GdkWindowObject *window_private;
897 GdkWindow *filter_window;
898 GdkWindowImplX11 *window_impl = NULL;
900 GdkScreen *screen = NULL;
901 GdkScreenX11 *screen_x11 = NULL;
902 GdkToplevelX11 *toplevel = NULL;
903 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
904 Window xwindow, filter_xwindow;
908 /* init these, since the done: block uses them */
910 window_private = NULL;
911 event->any.window = NULL;
913 if (_gdk_default_filters)
915 /* Apply global filters */
916 GdkFilterReturn result;
917 result = gdk_event_apply_filters (xevent, event,
918 _gdk_default_filters);
920 if (result != GDK_FILTER_CONTINUE)
922 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
927 /* Find the GdkWindow that this event relates to.
928 * Basically this means substructure events
929 * are reported same as structure events
931 get_real_window (display, xevent, &xwindow, &filter_xwindow);
933 window = gdk_window_lookup_for_display (display, xwindow);
934 /* We may receive events such as NoExpose/GraphicsExpose
935 * and ShmCompletion for pixmaps
937 if (window && !GDK_IS_WINDOW (window))
939 window_private = (GdkWindowObject *) window;
941 /* We always run the filters for the window where the event
942 * is delivered, not the window that it relates to
944 if (filter_xwindow == xwindow)
945 filter_window = window;
948 filter_window = gdk_window_lookup_for_display (display, filter_xwindow);
949 if (filter_window && !GDK_IS_WINDOW (filter_window))
950 filter_window = NULL;
955 screen = GDK_WINDOW_SCREEN (window);
956 screen_x11 = GDK_SCREEN_X11 (screen);
957 toplevel = _gdk_x11_window_get_toplevel (window);
962 /* Apply keyboard grabs to non-native windows */
963 if (/* Is key event */
964 (xevent->type == KeyPress || xevent->type == KeyRelease) &&
965 /* And we have a grab */
966 display->keyboard_grab.window != NULL &&
968 /* The window is not a descendant of the grabbed window */
969 !is_parent_of ((GdkWindow *)display->keyboard_grab.window, window) ||
970 /* Or owner event is false */
971 !display->keyboard_grab.owner_events
975 /* Report key event against grab window */
976 window = display->keyboard_grab.window;;
977 window_private = (GdkWindowObject *) window;
980 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
982 /* Move key events on focus window to the real toplevel, and
983 * filter out all other events on focus window
985 if (toplevel && xwindow == toplevel->focus_window)
987 switch (xevent->type)
991 xwindow = GDK_WINDOW_XID (window);
992 xevent->xany.window = xwindow;
999 g_object_ref (window);
1002 event->any.window = window;
1003 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
1005 if (window_private && GDK_WINDOW_DESTROYED (window))
1007 if (xevent->type != DestroyNotify)
1013 else if (filter_window)
1015 /* Apply per-window filters */
1016 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
1017 GdkFilterReturn result;
1019 if (filter_private->filters)
1021 g_object_ref (filter_window);
1023 result = gdk_event_apply_filters (xevent, event,
1024 filter_private->filters);
1026 g_object_unref (filter_window);
1028 if (result != GDK_FILTER_CONTINUE)
1030 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
1036 if (screen_x11 && screen_x11->wmspec_check_window != None &&
1037 xwindow == screen_x11->wmspec_check_window)
1039 if (xevent->type == DestroyNotify)
1041 screen_x11->wmspec_check_window = None;
1042 g_free (screen_x11->window_manager_name);
1043 screen_x11->window_manager_name = g_strdup ("unknown");
1045 /* careful, reentrancy */
1046 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
1049 /* Eat events on this window unless someone had wrapped
1050 * it as a foreign window
1060 (xevent->xany.type == MotionNotify ||
1061 xevent->xany.type == ButtonRelease))
1063 if (_gdk_moveresize_handle_event (xevent))
1070 /* We do a "manual" conversion of the XEvent to a
1071 * GdkEvent. The structures are mostly the same so
1072 * the conversion is fairly straightforward. We also
1073 * optionally print debugging info regarding events
1079 switch (xevent->type)
1082 if (window_private == NULL)
1087 translate_key_event (display, event, xevent);
1088 set_user_time (window, event);
1092 if (window_private == NULL)
1098 /* Emulate detectable auto-repeat by checking to see
1099 * if the next event is a key press with the same
1100 * keycode and timestamp, and if so, ignoring the event.
1103 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
1107 XPeekEvent (xevent->xkey.display, &next_event);
1109 if (next_event.type == KeyPress &&
1110 next_event.xkey.keycode == xevent->xkey.keycode &&
1111 next_event.xkey.time == xevent->xkey.time)
1118 translate_key_event (display, event, xevent);
1123 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1124 xevent->xbutton.window,
1125 xevent->xbutton.x, xevent->xbutton.y,
1126 xevent->xbutton.button));
1128 if (window_private == NULL)
1134 /* If we get a ButtonPress event where the button is 4 or 5,
1135 it's a Scroll event */
1136 switch (xevent->xbutton.button)
1142 event->scroll.type = GDK_SCROLL;
1144 if (xevent->xbutton.button == 4)
1145 event->scroll.direction = GDK_SCROLL_UP;
1146 else if (xevent->xbutton.button == 5)
1147 event->scroll.direction = GDK_SCROLL_DOWN;
1148 else if (xevent->xbutton.button == 6)
1149 event->scroll.direction = GDK_SCROLL_LEFT;
1151 event->scroll.direction = GDK_SCROLL_RIGHT;
1153 event->scroll.window = window;
1154 event->scroll.time = xevent->xbutton.time;
1155 event->scroll.x = xevent->xbutton.x;
1156 event->scroll.y = xevent->xbutton.y;
1157 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
1158 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
1159 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
1160 event->scroll.device = display->core_pointer;
1162 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1171 event->button.type = GDK_BUTTON_PRESS;
1172 event->button.window = window;
1173 event->button.time = xevent->xbutton.time;
1174 event->button.x = xevent->xbutton.x;
1175 event->button.y = xevent->xbutton.y;
1176 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1177 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1178 event->button.axes = NULL;
1179 event->button.state = (GdkModifierType) xevent->xbutton.state;
1180 event->button.button = xevent->xbutton.button;
1181 event->button.device = display->core_pointer;
1183 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1191 set_user_time (window, event);
1197 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1198 xevent->xbutton.window,
1199 xevent->xbutton.x, xevent->xbutton.y,
1200 xevent->xbutton.button));
1202 if (window_private == NULL)
1208 /* We treat button presses as scroll wheel events, so ignore the release */
1209 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1210 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1216 event->button.type = GDK_BUTTON_RELEASE;
1217 event->button.window = window;
1218 event->button.time = xevent->xbutton.time;
1219 event->button.x = xevent->xbutton.x;
1220 event->button.y = xevent->xbutton.y;
1221 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1222 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1223 event->button.axes = NULL;
1224 event->button.state = (GdkModifierType) xevent->xbutton.state;
1225 event->button.button = xevent->xbutton.button;
1226 event->button.device = display->core_pointer;
1228 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1235 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1236 xevent->xmotion.window,
1237 xevent->xmotion.x, xevent->xmotion.y,
1238 (xevent->xmotion.is_hint) ? "true" : "false"));
1240 if (window_private == NULL)
1246 event->motion.type = GDK_MOTION_NOTIFY;
1247 event->motion.window = window;
1248 event->motion.time = xevent->xmotion.time;
1249 event->motion.x = xevent->xmotion.x;
1250 event->motion.y = xevent->xmotion.y;
1251 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1252 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1253 event->motion.axes = NULL;
1254 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1255 event->motion.is_hint = xevent->xmotion.is_hint;
1256 event->motion.device = display->core_pointer;
1258 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1268 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1269 xevent->xcrossing.window,
1270 xevent->xcrossing.detail,
1271 xevent->xcrossing.subwindow));
1273 if (window_private == NULL)
1279 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1285 /* Handle focusing (in the case where no window manager is running */
1286 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1288 toplevel->has_pointer = TRUE;
1290 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1292 gboolean had_focus = HAS_FOCUS (toplevel);
1294 toplevel->has_pointer_focus = TRUE;
1296 if (HAS_FOCUS (toplevel) != had_focus)
1297 generate_focus_event (window, TRUE);
1301 event->crossing.type = GDK_ENTER_NOTIFY;
1302 event->crossing.window = window;
1304 /* If the subwindow field of the XEvent is non-NULL, then
1305 * lookup the corresponding GdkWindow.
1307 if (xevent->xcrossing.subwindow != None)
1308 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1310 event->crossing.subwindow = NULL;
1312 event->crossing.time = xevent->xcrossing.time;
1313 event->crossing.x = xevent->xcrossing.x;
1314 event->crossing.y = xevent->xcrossing.y;
1315 event->crossing.x_root = xevent->xcrossing.x_root;
1316 event->crossing.y_root = xevent->xcrossing.y_root;
1318 /* Translate the crossing mode into Gdk terms.
1320 switch (xevent->xcrossing.mode)
1323 event->crossing.mode = GDK_CROSSING_NORMAL;
1326 event->crossing.mode = GDK_CROSSING_GRAB;
1329 event->crossing.mode = GDK_CROSSING_UNGRAB;
1333 /* Translate the crossing detail into Gdk terms.
1335 switch (xevent->xcrossing.detail)
1337 case NotifyInferior:
1338 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1340 case NotifyAncestor:
1341 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1344 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1346 case NotifyNonlinear:
1347 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1349 case NotifyNonlinearVirtual:
1350 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1353 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1357 event->crossing.focus = xevent->xcrossing.focus;
1358 event->crossing.state = xevent->xcrossing.state;
1364 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1365 xevent->xcrossing.window,
1366 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1368 if (window_private == NULL)
1374 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1380 /* Handle focusing (in the case where no window manager is running */
1381 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1383 toplevel->has_pointer = FALSE;
1385 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1387 gboolean had_focus = HAS_FOCUS (toplevel);
1389 toplevel->has_pointer_focus = FALSE;
1391 if (HAS_FOCUS (toplevel) != had_focus)
1392 generate_focus_event (window, FALSE);
1396 event->crossing.type = GDK_LEAVE_NOTIFY;
1397 event->crossing.window = window;
1399 /* If the subwindow field of the XEvent is non-NULL, then
1400 * lookup the corresponding GdkWindow.
1402 if (xevent->xcrossing.subwindow != None)
1403 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1405 event->crossing.subwindow = NULL;
1407 event->crossing.time = xevent->xcrossing.time;
1408 event->crossing.x = xevent->xcrossing.x;
1409 event->crossing.y = xevent->xcrossing.y;
1410 event->crossing.x_root = xevent->xcrossing.x_root;
1411 event->crossing.y_root = xevent->xcrossing.y_root;
1413 /* Translate the crossing mode into Gdk terms.
1415 switch (xevent->xcrossing.mode)
1418 event->crossing.mode = GDK_CROSSING_NORMAL;
1421 event->crossing.mode = GDK_CROSSING_GRAB;
1424 event->crossing.mode = GDK_CROSSING_UNGRAB;
1428 /* Translate the crossing detail into Gdk terms.
1430 switch (xevent->xcrossing.detail)
1432 case NotifyInferior:
1433 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1435 case NotifyAncestor:
1436 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1439 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1441 case NotifyNonlinear:
1442 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1444 case NotifyNonlinearVirtual:
1445 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1448 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1452 event->crossing.focus = xevent->xcrossing.focus;
1453 event->crossing.state = xevent->xcrossing.state;
1457 /* We only care about focus events that indicate that _this_
1458 * window (not a ancestor or child) got or lost the focus
1462 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1463 xevent->xfocus.window,
1464 notify_details[xevent->xfocus.detail],
1465 notify_modes[xevent->xfocus.mode]));
1469 gboolean had_focus = HAS_FOCUS (toplevel);
1471 switch (xevent->xfocus.detail)
1473 case NotifyAncestor:
1475 /* When the focus moves from an ancestor of the window to
1476 * the window or a descendent of the window, *and* the
1477 * pointer is inside the window, then we were previously
1478 * receiving keystroke events in the has_pointer_focus
1479 * case and are now receiving them in the
1480 * has_focus_window case.
1482 if (toplevel->has_pointer &&
1483 xevent->xfocus.mode != NotifyGrab &&
1484 xevent->xfocus.mode != NotifyUngrab)
1485 toplevel->has_pointer_focus = FALSE;
1488 case NotifyNonlinear:
1489 case NotifyNonlinearVirtual:
1490 if (xevent->xfocus.mode != NotifyGrab &&
1491 xevent->xfocus.mode != NotifyUngrab)
1492 toplevel->has_focus_window = TRUE;
1493 /* We pretend that the focus moves to the grab
1494 * window, so we pay attention to NotifyGrab
1495 * NotifyUngrab, and ignore NotifyWhileGrabbed
1497 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1498 toplevel->has_focus = TRUE;
1501 /* The X server sends NotifyPointer/NotifyGrab,
1502 * but the pointer focus is ignored while a
1505 if (xevent->xfocus.mode != NotifyGrab &&
1506 xevent->xfocus.mode != NotifyUngrab)
1507 toplevel->has_pointer_focus = TRUE;
1509 case NotifyInferior:
1510 case NotifyPointerRoot:
1511 case NotifyDetailNone:
1515 if (HAS_FOCUS (toplevel) != had_focus)
1516 generate_focus_event (window, TRUE);
1521 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1522 xevent->xfocus.window,
1523 notify_details[xevent->xfocus.detail],
1524 notify_modes[xevent->xfocus.mode]));
1528 gboolean had_focus = HAS_FOCUS (toplevel);
1530 switch (xevent->xfocus.detail)
1532 case NotifyAncestor:
1534 /* When the focus moves from the window or a descendent
1535 * of the window to an ancestor of the window, *and* the
1536 * pointer is inside the window, then we were previously
1537 * receiving keystroke events in the has_focus_window
1538 * case and are now receiving them in the
1539 * has_pointer_focus case.
1541 if (toplevel->has_pointer &&
1542 xevent->xfocus.mode != NotifyGrab &&
1543 xevent->xfocus.mode != NotifyUngrab)
1544 toplevel->has_pointer_focus = TRUE;
1547 case NotifyNonlinear:
1548 case NotifyNonlinearVirtual:
1549 if (xevent->xfocus.mode != NotifyGrab &&
1550 xevent->xfocus.mode != NotifyUngrab)
1551 toplevel->has_focus_window = FALSE;
1552 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1553 toplevel->has_focus = FALSE;
1556 if (xevent->xfocus.mode != NotifyGrab &&
1557 xevent->xfocus.mode != NotifyUngrab)
1558 toplevel->has_pointer_focus = FALSE;
1560 case NotifyInferior:
1561 case NotifyPointerRoot:
1562 case NotifyDetailNone:
1566 if (HAS_FOCUS (toplevel) != had_focus)
1567 generate_focus_event (window, FALSE);
1572 /* gdk_keyboard_grab() causes following events. These events confuse
1573 * the XIM focus, so ignore them.
1575 if (xevent->xfocus.mode == NotifyGrab ||
1576 xevent->xfocus.mode == NotifyUngrab)
1582 g_message ("keymap notify"));
1584 /* Not currently handled */
1590 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1591 xevent->xexpose.window, xevent->xexpose.count,
1592 xevent->xexpose.x, xevent->xexpose.y,
1593 xevent->xexpose.width, xevent->xexpose.height,
1594 event->any.send_event ? " (send)" : ""));
1596 if (window_private == NULL)
1603 GdkRectangle expose_rect;
1605 expose_rect.x = xevent->xexpose.x;
1606 expose_rect.y = xevent->xexpose.y;
1607 expose_rect.width = xevent->xexpose.width;
1608 expose_rect.height = xevent->xexpose.height;
1612 event->expose.type = GDK_EXPOSE;
1613 event->expose.area = expose_rect;
1614 event->expose.region = gdk_region_rectangle (&expose_rect);
1615 event->expose.window = window;
1616 event->expose.count = xevent->xexpose.count;
1622 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1631 case GraphicsExpose:
1633 GdkRectangle expose_rect;
1636 g_message ("graphics expose:\tdrawable: %ld",
1637 xevent->xgraphicsexpose.drawable));
1639 if (window_private == NULL)
1645 expose_rect.x = xevent->xgraphicsexpose.x;
1646 expose_rect.y = xevent->xgraphicsexpose.y;
1647 expose_rect.width = xevent->xgraphicsexpose.width;
1648 expose_rect.height = xevent->xgraphicsexpose.height;
1652 event->expose.type = GDK_EXPOSE;
1653 event->expose.area = expose_rect;
1654 event->expose.region = gdk_region_rectangle (&expose_rect);
1655 event->expose.window = window;
1656 event->expose.count = xevent->xgraphicsexpose.count;
1662 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1672 g_message ("no expose:\t\tdrawable: %ld",
1673 xevent->xnoexpose.drawable));
1675 event->no_expose.type = GDK_NO_EXPOSE;
1676 event->no_expose.window = window;
1680 case VisibilityNotify:
1681 #ifdef G_ENABLE_DEBUG
1682 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1683 switch (xevent->xvisibility.state)
1685 case VisibilityFullyObscured:
1686 g_message ("visibility notify:\twindow: %ld none",
1687 xevent->xvisibility.window);
1689 case VisibilityPartiallyObscured:
1690 g_message ("visibility notify:\twindow: %ld partial",
1691 xevent->xvisibility.window);
1693 case VisibilityUnobscured:
1694 g_message ("visibility notify:\twindow: %ld full",
1695 xevent->xvisibility.window);
1698 #endif /* G_ENABLE_DEBUG */
1700 if (window_private == NULL)
1706 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1707 event->visibility.window = window;
1709 switch (xevent->xvisibility.state)
1711 case VisibilityFullyObscured:
1712 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1715 case VisibilityPartiallyObscured:
1716 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1719 case VisibilityUnobscured:
1720 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1728 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1729 xevent->xcreatewindow.window,
1730 xevent->xcreatewindow.x,
1731 xevent->xcreatewindow.y,
1732 xevent->xcreatewindow.width,
1733 xevent->xcreatewindow.height,
1734 xevent->xcreatewindow.border_width,
1735 xevent->xcreatewindow.parent,
1736 xevent->xcreatewindow.override_redirect));
1737 /* not really handled */
1742 g_message ("destroy notify:\twindow: %ld",
1743 xevent->xdestroywindow.window));
1745 /* Ignore DestroyNotify from SubstructureNotifyMask */
1746 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1748 event->any.type = GDK_DESTROY;
1749 event->any.window = window;
1751 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1753 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1754 gdk_window_destroy_notify (window);
1763 g_message ("unmap notify:\t\twindow: %ld",
1764 xevent->xmap.window));
1766 event->any.type = GDK_UNMAP;
1767 event->any.window = window;
1769 /* If we are shown (not withdrawn) and get an unmap, it means we
1770 * were iconified in the X sense. If we are withdrawn, and get
1771 * an unmap, it means we hid the window ourselves, so we
1772 * will have already flipped the iconified bit off.
1776 if (GDK_WINDOW_IS_MAPPED (window))
1777 gdk_synthesize_window_state (window,
1779 GDK_WINDOW_STATE_ICONIFIED);
1781 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1788 g_message ("map notify:\t\twindow: %ld",
1789 xevent->xmap.window));
1791 event->any.type = GDK_MAP;
1792 event->any.window = window;
1794 /* Unset iconified if it was set */
1795 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1796 gdk_synthesize_window_state (window,
1797 GDK_WINDOW_STATE_ICONIFIED,
1802 case ReparentNotify:
1804 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1805 xevent->xreparent.window,
1806 xevent->xreparent.x,
1807 xevent->xreparent.y,
1808 xevent->xreparent.parent,
1809 xevent->xreparent.override_redirect));
1811 /* Not currently handled */
1815 case ConfigureNotify:
1817 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1818 xevent->xconfigure.window,
1819 xevent->xconfigure.x,
1820 xevent->xconfigure.y,
1821 xevent->xconfigure.width,
1822 xevent->xconfigure.height,
1823 xevent->xconfigure.border_width,
1824 xevent->xconfigure.above,
1825 xevent->xconfigure.override_redirect,
1828 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1829 ? " (discarding child)"
1830 : xevent->xconfigure.event != xevent->xconfigure.window
1831 ? " (discarding substructure)"
1833 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1835 window_private->width = xevent->xconfigure.width;
1836 window_private->height = xevent->xconfigure.height;
1838 _gdk_window_update_size (window);
1839 _gdk_x11_drawable_update_size (window_private->impl);
1840 _gdk_x11_screen_size_changed (screen, xevent);
1844 xevent->xconfigure.event == xevent->xconfigure.window &&
1845 !GDK_WINDOW_DESTROYED (window) &&
1846 window_private->input_window != NULL)
1847 _gdk_input_configure_event (&xevent->xconfigure, window);
1850 if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
1852 toplevel->current_counter_value = toplevel->pending_counter_value;
1853 XSyncIntToValue (&toplevel->pending_counter_value, 0);
1858 xevent->xconfigure.event != xevent->xconfigure.window ||
1859 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1860 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1864 event->configure.type = GDK_CONFIGURE;
1865 event->configure.window = window;
1866 event->configure.width = xevent->xconfigure.width;
1867 event->configure.height = xevent->xconfigure.height;
1869 if (!xevent->xconfigure.send_event &&
1870 !xevent->xconfigure.override_redirect &&
1871 !GDK_WINDOW_DESTROYED (window))
1875 Window child_window = 0;
1877 gdk_error_trap_push ();
1878 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1879 GDK_DRAWABLE_XID (window),
1880 screen_x11->xroot_window,
1885 event->configure.x = tx;
1886 event->configure.y = ty;
1888 gdk_error_trap_pop ();
1892 event->configure.x = xevent->xconfigure.x;
1893 event->configure.y = xevent->xconfigure.y;
1895 window_private->x = event->configure.x;
1896 window_private->y = event->configure.y;
1897 window_private->width = xevent->xconfigure.width;
1898 window_private->height = xevent->xconfigure.height;
1900 _gdk_window_update_size (window);
1901 _gdk_x11_drawable_update_size (window_private->impl);
1903 if (window_private->resize_count >= 1)
1905 window_private->resize_count -= 1;
1907 if (window_private->resize_count == 0)
1908 _gdk_moveresize_configure_done (display, window);
1913 case PropertyNotify:
1915 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1916 xevent->xproperty.window,
1917 xevent->xproperty.atom,
1919 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1922 if (window_private == NULL)
1928 /* We compare with the serial of the last time we mapped the
1929 * window to avoid refetching properties that we set ourselves
1932 xevent->xproperty.serial >= toplevel->map_serial)
1934 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1935 gdk_check_wm_state_changed (window);
1937 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1938 gdk_check_wm_desktop_changed (window);
1941 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1943 event->property.type = GDK_PROPERTY_NOTIFY;
1944 event->property.window = window;
1945 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1946 event->property.time = xevent->xproperty.time;
1947 event->property.state = xevent->xproperty.state;
1954 case SelectionClear:
1956 g_message ("selection clear:\twindow: %ld",
1957 xevent->xproperty.window));
1959 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1961 event->selection.type = GDK_SELECTION_CLEAR;
1962 event->selection.window = window;
1963 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1964 event->selection.time = xevent->xselectionclear.time;
1971 case SelectionRequest:
1973 g_message ("selection request:\twindow: %ld",
1974 xevent->xproperty.window));
1976 event->selection.type = GDK_SELECTION_REQUEST;
1977 event->selection.window = window;
1978 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1979 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1980 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1981 event->selection.requestor = xevent->xselectionrequest.requestor;
1982 event->selection.time = xevent->xselectionrequest.time;
1986 case SelectionNotify:
1988 g_message ("selection notify:\twindow: %ld",
1989 xevent->xproperty.window));
1992 event->selection.type = GDK_SELECTION_NOTIFY;
1993 event->selection.window = window;
1994 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1995 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1996 if (xevent->xselection.property == None)
1997 event->selection.property = GDK_NONE;
1999 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
2000 event->selection.time = xevent->xselection.time;
2004 case ColormapNotify:
2006 g_message ("colormap notify:\twindow: %ld",
2007 xevent->xcolormap.window));
2009 /* Not currently handled */
2016 GdkFilterReturn result = GDK_FILTER_CONTINUE;
2017 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
2020 g_message ("client message:\twindow: %ld",
2021 xevent->xclient.window));
2023 tmp_list = display_x11->client_filters;
2026 GdkClientFilter *filter = tmp_list->data;
2027 tmp_list = tmp_list->next;
2029 if (filter->type == message_type)
2031 result = (*filter->function) (xevent, event, filter->data);
2032 if (result != GDK_FILTER_CONTINUE)
2039 case GDK_FILTER_REMOVE:
2042 case GDK_FILTER_TRANSLATE:
2045 case GDK_FILTER_CONTINUE:
2046 /* Send unknown ClientMessage's on to Gtk for it to use */
2047 if (window_private == NULL)
2053 event->client.type = GDK_CLIENT_EVENT;
2054 event->client.window = window;
2055 event->client.message_type = message_type;
2056 event->client.data_format = xevent->xclient.format;
2057 memcpy(&event->client.data, &xevent->xclient.data,
2058 sizeof(event->client.data));
2068 g_message ("mapping notify"));
2070 /* Let XLib know that there is a new keyboard mapping.
2072 XRefreshKeyboardMapping (&xevent->xmapping);
2073 _gdk_keymap_keys_changed (display);
2079 if (xevent->type == display_x11->xkb_event_type)
2081 XkbEvent *xkb_event = (XkbEvent *)xevent;
2083 switch (xkb_event->any.xkb_type)
2085 case XkbNewKeyboardNotify:
2087 _gdk_keymap_keys_changed (display);
2092 case XkbStateNotify:
2093 _gdk_keymap_state_changed (display, xevent);
2100 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
2102 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
2104 _gdk_x11_screen_process_owner_change (screen, xevent);
2106 event->owner_change.type = GDK_OWNER_CHANGE;
2107 event->owner_change.window = window;
2108 event->owner_change.owner = selection_notify->owner;
2109 event->owner_change.reason = selection_notify->subtype;
2110 event->owner_change.selection =
2111 gdk_x11_xatom_to_atom_for_display (display,
2112 selection_notify->selection);
2113 event->owner_change.time = selection_notify->timestamp;
2114 event->owner_change.selection_time = selection_notify->selection_timestamp;
2121 if (xevent->type - display_x11->xrandr_event_base == RRScreenChangeNotify ||
2122 xevent->type - display_x11->xrandr_event_base == RRNotify)
2125 _gdk_x11_screen_size_changed (screen, xevent);
2129 #if defined(HAVE_XCOMPOSITE) && defined (HAVE_XDAMAGE) && defined (HAVE_XFIXES)
2130 if (display_x11->have_xdamage && window_private && window_private->composited &&
2131 xevent->type == display_x11->xdamage_event_base + XDamageNotify &&
2132 ((XDamageNotifyEvent *) xevent)->damage == window_impl->damage)
2134 XDamageNotifyEvent *damage_event = (XDamageNotifyEvent *) xevent;
2135 XserverRegion repair;
2138 rect.x = window_private->x + damage_event->area.x;
2139 rect.y = window_private->y + damage_event->area.y;
2140 rect.width = damage_event->area.width;
2141 rect.height = damage_event->area.height;
2143 repair = XFixesCreateRegion (display_x11->xdisplay,
2144 &damage_event->area, 1);
2145 XDamageSubtract (display_x11->xdisplay,
2146 window_impl->damage,
2148 XFixesDestroyRegion (display_x11->xdisplay, repair);
2150 if (window_private->parent != NULL)
2151 _gdk_window_process_expose (GDK_WINDOW (window_private->parent),
2152 damage_event->serial, &rect);
2159 /* something else - (e.g., a Xinput event) */
2161 if (window_private &&
2162 !GDK_WINDOW_DESTROYED (window_private) &&
2163 window_private->input_window)
2164 return_val = _gdk_input_other_event (event, xevent, window);
2175 if (event->any.window)
2176 g_object_ref (event->any.window);
2177 if (((event->any.type == GDK_ENTER_NOTIFY) ||
2178 (event->any.type == GDK_LEAVE_NOTIFY)) &&
2179 (event->crossing.subwindow != NULL))
2180 g_object_ref (event->crossing.subwindow);
2184 /* Mark this event as having no resources to be freed */
2185 event->any.window = NULL;
2186 event->any.type = GDK_NOTHING;
2190 g_object_unref (window);
2195 static GdkFilterReturn
2196 gdk_wm_protocols_filter (GdkXEvent *xev,
2200 XEvent *xevent = (XEvent *)xev;
2201 GdkWindow *win = event->any.window;
2202 GdkDisplay *display;
2206 return GDK_FILTER_REMOVE;
2208 display = GDK_WINDOW_DISPLAY (win);
2209 atom = (Atom)xevent->xclient.data.l[0];
2211 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
2213 /* The delete window request specifies a window
2214 * to delete. We don't actually destroy the
2215 * window because "it is only a request". (The
2216 * window might contain vital data that the
2217 * program does not want destroyed). Instead
2218 * the event is passed along to the program,
2219 * which should then destroy the window.
2222 g_message ("delete window:\t\twindow: %ld",
2223 xevent->xclient.window));
2225 event->any.type = GDK_DELETE;
2227 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
2229 return GDK_FILTER_TRANSLATE;
2231 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
2233 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2234 GdkWindowObject *private = (GdkWindowObject *)win;
2236 /* There is no way of knowing reliably whether we are viewable;
2237 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2239 if (toplevel && private->accept_focus)
2240 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
2242 xevent->xclient.data.l[1]);
2244 return GDK_FILTER_REMOVE;
2246 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
2247 !_gdk_x11_display_is_root_window (display,
2248 xevent->xclient.window))
2250 XClientMessageEvent xclient = xevent->xclient;
2252 xclient.window = GDK_WINDOW_XROOTWIN (win);
2253 XSendEvent (GDK_WINDOW_XDISPLAY (win),
2256 SubstructureRedirectMask | SubstructureNotifyMask, (XEvent *)&xclient);
2258 return GDK_FILTER_REMOVE;
2260 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
2261 GDK_DISPLAY_X11 (display)->use_sync)
2263 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2267 XSyncIntsToValue (&toplevel->pending_counter_value,
2268 xevent->xclient.data.l[2],
2269 xevent->xclient.data.l[3]);
2272 return GDK_FILTER_REMOVE;
2275 return GDK_FILTER_CONTINUE;
2279 _gdk_events_queue (GdkDisplay *display)
2284 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2286 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
2288 XNextEvent (xdisplay, &xevent);
2290 switch (xevent.type)
2296 if (XFilterEvent (&xevent, None))
2300 event = gdk_event_new (GDK_NOTHING);
2302 event->any.window = NULL;
2303 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
2305 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2307 node = _gdk_event_queue_append (display, event);
2309 if (gdk_event_translate (display, event, &xevent, FALSE))
2311 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2312 _gdk_windowing_got_event (display, node, event, xevent.xany.serial);
2316 _gdk_event_queue_remove_link (display, node);
2317 g_list_free_1 (node);
2318 gdk_event_free (event);
2324 gdk_event_prepare (GSource *source,
2327 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2330 GDK_THREADS_ENTER ();
2333 retval = (_gdk_event_queue_find_first (display) != NULL ||
2334 gdk_check_xpending (display));
2336 GDK_THREADS_LEAVE ();
2342 gdk_event_check (GSource *source)
2344 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2347 GDK_THREADS_ENTER ();
2349 if (display_source->event_poll_fd.revents & G_IO_IN)
2350 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2351 gdk_check_xpending (display_source->display));
2355 GDK_THREADS_LEAVE ();
2361 gdk_event_dispatch (GSource *source,
2362 GSourceFunc callback,
2365 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2368 GDK_THREADS_ENTER ();
2370 _gdk_events_queue (display);
2371 event = _gdk_event_unqueue (display);
2375 if (_gdk_event_func)
2376 (*_gdk_event_func) (event, _gdk_event_data);
2378 gdk_event_free (event);
2381 GDK_THREADS_LEAVE ();
2387 * gdk_event_send_client_message_for_display:
2388 * @display: the #GdkDisplay for the window where the message is to be sent.
2389 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2390 * @winid: the window to send the client message to.
2392 * On X11, sends an X ClientMessage event to a given window. On
2393 * Windows, sends a message registered with the name
2394 * GDK_WIN32_CLIENT_MESSAGE.
2396 * This could be used for communicating between different
2397 * applications, though the amount of data is limited to 20 bytes on
2398 * X11, and to just four bytes on Windows.
2400 * Returns: non-zero on success.
2405 gdk_event_send_client_message_for_display (GdkDisplay *display,
2407 GdkNativeWindow winid)
2411 g_return_val_if_fail(event != NULL, FALSE);
2413 /* Set up our event to send, with the exception of its target window */
2414 sev.xclient.type = ClientMessage;
2415 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2416 sev.xclient.format = event->client.data_format;
2417 sev.xclient.window = winid;
2418 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2419 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2421 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2426 /* Sends a ClientMessage to all toplevel client windows */
2428 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2435 unsigned long nitems, after;
2436 unsigned char *data;
2437 Window *ret_children, ret_root, ret_parent;
2438 unsigned int ret_nchildren;
2439 gboolean send = FALSE;
2440 gboolean found = FALSE;
2441 gboolean result = FALSE;
2444 gdk_error_trap_push ();
2446 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2447 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
2448 0, 0, False, AnyPropertyType,
2449 &type, &format, &nitems, &after, &data) != Success)
2459 /* OK, we're all set, now let's find some windows to send this to */
2460 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2461 &ret_root, &ret_parent,
2462 &ret_children, &ret_nchildren))
2465 for(i = 0; i < ret_nchildren; i++)
2466 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2469 XFree (ret_children);
2472 if (send || (!found && (level == 1)))
2474 xev->xclient.window = xid;
2475 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2478 result = send || found;
2481 gdk_error_trap_pop ();
2487 * gdk_screen_broadcast_client_message:
2488 * @screen: the #GdkScreen where the event will be broadcasted.
2489 * @event: the #GdkEvent.
2491 * On X11, sends an X ClientMessage event to all toplevel windows on
2494 * Toplevel windows are determined by checking for the WM_STATE property,
2495 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2496 * If no windows are found with the WM_STATE property set, the message is
2497 * sent to all children of the root window.
2499 * On Windows, broadcasts a message registered with the name
2500 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
2501 * data is limited to one long, i.e. four bytes.
2507 gdk_screen_broadcast_client_message (GdkScreen *screen,
2511 GdkWindow *root_window;
2513 g_return_if_fail (event != NULL);
2515 root_window = gdk_screen_get_root_window (screen);
2517 /* Set up our event to send, with the exception of its target window */
2518 sev.xclient.type = ClientMessage;
2519 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2520 sev.xclient.format = event->client.data_format;
2521 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2522 sev.xclient.message_type =
2523 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2524 event->client.message_type);
2526 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2528 GDK_WINDOW_XID (root_window),
2533 *--------------------------------------------------------------
2536 * Flushes the Xlib output buffer and then waits
2537 * until all requests have been received and processed
2538 * by the X server. The only real use for this function
2539 * is in dealing with XShm.
2547 *--------------------------------------------------------------
2553 GSList *tmp_list = _gdk_displays;
2557 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2558 tmp_list = tmp_list->next;
2563 timestamp_predicate (Display *display,
2567 Window xwindow = GPOINTER_TO_UINT (arg);
2568 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2570 if (xevent->type == PropertyNotify &&
2571 xevent->xproperty.window == xwindow &&
2572 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2573 "GDK_TIMESTAMP_PROP"))
2580 * gdk_x11_get_server_time:
2581 * @window: a #GdkWindow, used for communication with the server.
2582 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2583 * events mask or a hang will result.
2585 * Routine to get the current X server time stamp.
2587 * Return value: the time stamp.
2590 gdk_x11_get_server_time (GdkWindow *window)
2596 Atom timestamp_prop_atom;
2598 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2599 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2601 xdisplay = GDK_WINDOW_XDISPLAY (window);
2602 xwindow = GDK_WINDOW_XWINDOW (window);
2603 timestamp_prop_atom =
2604 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2605 "GDK_TIMESTAMP_PROP");
2607 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2608 timestamp_prop_atom,
2609 8, PropModeReplace, &c, 1);
2611 XIfEvent (xdisplay, &xevent,
2612 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2614 return xevent.xproperty.time;
2618 fetch_net_wm_check_window (GdkScreen *screen)
2620 GdkScreenX11 *screen_x11;
2621 GdkDisplay *display;
2630 screen_x11 = GDK_SCREEN_X11 (screen);
2631 display = screen_x11->display;
2633 g_return_if_fail (GDK_DISPLAY_X11 (display)->trusted_client);
2635 g_get_current_time (&tv);
2637 if (ABS (tv.tv_sec - screen_x11->last_wmspec_check_time) < 15)
2638 return; /* we've checked recently */
2640 screen_x11->last_wmspec_check_time = tv.tv_sec;
2643 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2644 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2645 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2646 &n_items, &bytes_after, &data);
2648 if (type != XA_WINDOW)
2655 xwindow = (Window *)data;
2657 if (screen_x11->wmspec_check_window == *xwindow)
2663 gdk_error_trap_push ();
2665 /* Find out if this WM goes away, so we can reset everything. */
2666 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2667 gdk_display_sync (display);
2669 if (gdk_error_trap_pop () == Success)
2671 screen_x11->wmspec_check_window = *xwindow;
2672 screen_x11->need_refetch_net_supported = TRUE;
2673 screen_x11->need_refetch_wm_name = TRUE;
2675 /* Careful, reentrancy */
2676 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2683 * gdk_x11_screen_get_window_manager_name:
2684 * @screen: a #GdkScreen
2686 * Returns the name of the window manager for @screen.
2688 * Return value: the name of the window manager screen @screen, or
2689 * "unknown" if the window manager is unknown. The string is owned by GDK
2690 * and should not be freed.
2695 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2697 GdkScreenX11 *screen_x11;
2699 screen_x11 = GDK_SCREEN_X11 (screen);
2701 if (!G_LIKELY (GDK_DISPLAY_X11 (screen_x11->display)->trusted_client))
2702 return screen_x11->window_manager_name;
2704 fetch_net_wm_check_window (screen);
2706 if (screen_x11->need_refetch_wm_name)
2708 /* Get the name of the window manager */
2709 screen_x11->need_refetch_wm_name = FALSE;
2711 g_free (screen_x11->window_manager_name);
2712 screen_x11->window_manager_name = g_strdup ("unknown");
2714 if (screen_x11->wmspec_check_window != None)
2724 gdk_error_trap_push ();
2726 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2727 screen_x11->wmspec_check_window,
2728 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2730 0, G_MAXLONG, False,
2731 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2734 &n_items, &bytes_after,
2737 gdk_display_sync (screen_x11->display);
2739 gdk_error_trap_pop ();
2743 g_free (screen_x11->window_manager_name);
2744 screen_x11->window_manager_name = g_strdup (name);
2750 return GDK_SCREEN_X11 (screen)->window_manager_name;
2753 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2755 struct _NetWmSupportedAtoms
2762 cleanup_atoms(gpointer data)
2764 NetWmSupportedAtoms *supported_atoms = data;
2765 if (supported_atoms->atoms)
2766 XFree (supported_atoms->atoms);
2767 g_free (supported_atoms);
2771 * gdk_x11_screen_supports_net_wm_hint:
2772 * @screen: the relevant #GdkScreen.
2773 * @property: a property atom.
2775 * This function is specific to the X11 backend of GDK, and indicates
2776 * whether the window manager supports a certain hint from the
2777 * Extended Window Manager Hints Specification. You can find this
2779 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2781 * When using this function, keep in mind that the window manager
2782 * can change over time; so you shouldn't use this function in
2783 * a way that impacts persistent application state. A common bug
2784 * is that your application can start up before the window manager
2785 * does when the user logs in, and before the window manager starts
2786 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2787 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2788 * a window manager change.
2790 * Return value: %TRUE if the window manager supports @property
2795 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2799 GdkScreenX11 *screen_x11;
2800 NetWmSupportedAtoms *supported_atoms;
2801 GdkDisplay *display;
2803 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2805 screen_x11 = GDK_SCREEN_X11 (screen);
2806 display = screen_x11->display;
2808 if (!G_LIKELY (GDK_DISPLAY_X11 (display)->trusted_client))
2811 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2812 if (!supported_atoms)
2814 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2815 g_object_set_data_full (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms, cleanup_atoms);
2818 fetch_net_wm_check_window (screen);
2820 if (screen_x11->wmspec_check_window == None)
2823 if (screen_x11->need_refetch_net_supported)
2825 /* WM has changed since we last got the supported list,
2832 screen_x11->need_refetch_net_supported = FALSE;
2834 if (supported_atoms->atoms)
2835 XFree (supported_atoms->atoms);
2837 supported_atoms->atoms = NULL;
2838 supported_atoms->n_atoms = 0;
2840 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2841 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2842 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2843 &supported_atoms->n_atoms, &bytes_after,
2844 (guchar **)&supported_atoms->atoms);
2846 if (type != XA_ATOM)
2850 if (supported_atoms->atoms == NULL)
2854 while (i < supported_atoms->n_atoms)
2856 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2866 * gdk_net_wm_supports:
2867 * @property: a property atom.
2869 * This function is specific to the X11 backend of GDK, and indicates
2870 * whether the window manager for the default screen supports a certain
2871 * hint from the Extended Window Manager Hints Specification. See
2872 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2874 * Return value: %TRUE if the window manager supports @property
2877 gdk_net_wm_supports (GdkAtom property)
2879 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2884 gdk_xsettings_notify_cb (const char *name,
2885 XSettingsAction action,
2886 XSettingsSetting *setting,
2890 GdkScreen *screen = data;
2891 GdkScreenX11 *screen_x11 = data;
2894 if (screen_x11->xsettings_in_init)
2897 new_event.type = GDK_SETTING;
2898 new_event.setting.window = gdk_screen_get_root_window (screen);
2899 new_event.setting.send_event = FALSE;
2900 new_event.setting.name = NULL;
2902 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS() ; i++)
2903 if (strcmp (GDK_SETTINGS_X_NAME (i), name) == 0)
2905 new_event.setting.name = (char*) GDK_SETTINGS_GDK_NAME (i);
2909 if (!new_event.setting.name)
2914 case XSETTINGS_ACTION_NEW:
2915 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2917 case XSETTINGS_ACTION_CHANGED:
2918 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2920 case XSETTINGS_ACTION_DELETED:
2921 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2925 gdk_event_put (&new_event);
2929 check_transform (const gchar *xsettings_name,
2933 if (!g_value_type_transformable (src_type, dest_type))
2935 g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
2937 g_type_name (src_type),
2938 g_type_name (dest_type));
2946 * gdk_screen_get_setting:
2947 * @screen: the #GdkScreen where the setting is located
2948 * @name: the name of the setting
2949 * @value: location to store the value of the setting
2951 * Retrieves a desktop-wide setting such as double-click time
2952 * for the #GdkScreen @screen.
2954 * FIXME needs a list of valid settings here, or a link to
2957 * Returns: %TRUE if the setting existed and a value was stored
2958 * in @value, %FALSE otherwise.
2963 gdk_screen_get_setting (GdkScreen *screen,
2968 const char *xsettings_name = NULL;
2969 XSettingsResult result;
2970 XSettingsSetting *setting = NULL;
2971 GdkScreenX11 *screen_x11;
2972 gboolean success = FALSE;
2974 GValue tmp_val = { 0, };
2976 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2978 screen_x11 = GDK_SCREEN_X11 (screen);
2980 for (i = 0; i < GDK_SETTINGS_N_ELEMENTS(); i++)
2981 if (strcmp (GDK_SETTINGS_GDK_NAME (i), name) == 0)
2983 xsettings_name = GDK_SETTINGS_X_NAME (i);
2987 if (!xsettings_name)
2990 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2991 xsettings_name, &setting);
2992 if (result != XSETTINGS_SUCCESS)
2995 switch (setting->type)
2997 case XSETTINGS_TYPE_INT:
2998 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
3000 g_value_init (&tmp_val, G_TYPE_INT);
3001 g_value_set_int (&tmp_val, setting->data.v_int);
3002 g_value_transform (&tmp_val, value);
3007 case XSETTINGS_TYPE_STRING:
3008 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
3010 g_value_init (&tmp_val, G_TYPE_STRING);
3011 g_value_set_string (&tmp_val, setting->data.v_string);
3012 g_value_transform (&tmp_val, value);
3017 case XSETTINGS_TYPE_COLOR:
3018 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
3022 g_value_init (&tmp_val, GDK_TYPE_COLOR);
3025 color.red = setting->data.v_color.red;
3026 color.green = setting->data.v_color.green;
3027 color.blue = setting->data.v_color.blue;
3029 g_value_set_boxed (&tmp_val, &color);
3031 g_value_transform (&tmp_val, value);
3038 g_value_unset (&tmp_val);
3042 xsettings_setting_free (setting);
3047 return _gdk_x11_get_xft_setting (screen, name, value);
3050 static GdkFilterReturn
3051 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
3055 GdkScreenX11 *screen = data;
3057 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
3058 return GDK_FILTER_REMOVE;
3060 return GDK_FILTER_CONTINUE;
3064 gdk_xsettings_watch_cb (Window window,
3070 GdkScreen *screen = cb_data;
3072 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
3077 g_object_ref (gdkwin);
3080 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
3082 /* gdk_window_foreign_new_for_display() can fail and return NULL if the
3083 * window has already been destroyed.
3089 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3095 /* gdkwin should not be NULL here, since if starting the watch succeeded
3096 * we have a reference on the window. It might mean that the caller didn't
3097 * remove the watch when it got a DestroyNotify event. Or maybe the
3098 * caller ignored the return value when starting the watch failed.
3100 g_warning ("gdk_xsettings_watch_cb(): Couldn't find window to unwatch");
3104 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3105 g_object_unref (gdkwin);
3112 _gdk_windowing_event_data_copy (const GdkEvent *src,
3118 _gdk_windowing_event_data_free (GdkEvent *event)
3122 #define __GDK_EVENTS_X11_C__
3123 #include "gdkaliasdef.c"