1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include "gdkprivate-x11.h"
29 #include "gdkinternals.h"
31 #include "gdkscreen-x11.h"
32 #include "gdkdisplay-x11.h"
34 #include "gdkkeysyms.h"
36 #include "xsettings-client.h"
45 #include "gdkinputprivate.h"
48 #include <X11/XKBlib.h>
51 #include <X11/Xatom.h>
53 typedef struct _GdkIOClosure GdkIOClosure;
54 typedef struct _GdkEventPrivate GdkEventPrivate;
55 typedef struct _GdkDisplaySource GdkDisplaySource;
57 #define DOUBLE_CLICK_TIME 250
58 #define TRIPLE_CLICK_TIME 500
59 #define DOUBLE_CLICK_DIST 5
60 #define TRIPLE_CLICK_DIST 5
64 /* Following flag is set for events on the event queue during
65 * translation and cleared afterwards.
67 GDK_EVENT_PENDING = 1 << 0
72 GdkInputFunction function;
73 GdkInputCondition condition;
74 GdkDestroyNotify notify;
78 struct _GdkEventPrivate
84 struct _GdkDisplaySource
89 GPollFD event_poll_fd;
93 * Private function declarations
96 static gint gdk_event_apply_filters (XEvent *xevent,
99 static gboolean gdk_event_translate (GdkDisplay *display,
102 gboolean return_exposes);
104 static gboolean gdk_event_prepare (GSource *source,
106 static gboolean gdk_event_check (GSource *source);
107 static gboolean gdk_event_dispatch (GSource *source,
108 GSourceFunc callback,
111 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
115 static GSource *gdk_display_source_new (GdkDisplay *display);
116 static gboolean gdk_check_xpending (GdkDisplay *display);
118 static void gdk_xsettings_watch_cb (Window window,
122 static void gdk_xsettings_notify_cb (const char *name,
123 XSettingsAction action,
124 XSettingsSetting *setting,
127 /* Private variable declarations
130 static GList *display_sources;
132 static GSourceFuncs event_funcs = {
140 gdk_display_source_new (GdkDisplay *display)
142 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
143 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
145 display_source->display = display;
151 gdk_check_xpending (GdkDisplay *display)
153 return XPending (GDK_DISPLAY_XDISPLAY (display));
156 /*********************************************
157 * Functions for maintaining the event queue *
158 *********************************************/
161 _gdk_x11_events_init_screen (GdkScreen *screen)
163 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
165 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
166 screen_x11->screen_num,
167 gdk_xsettings_notify_cb,
168 gdk_xsettings_watch_cb,
173 _gdk_events_init (GdkDisplay *display)
176 GdkDisplaySource *display_source;
177 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
179 int connection_number = ConnectionNumber (display_x11->xdisplay);
180 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
183 source = gdk_display_source_new (display);
184 display_source = (GdkDisplaySource*) source;
185 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
187 display_source->event_poll_fd.fd = connection_number;
188 display_source->event_poll_fd.events = G_IO_IN;
190 g_source_add_poll (source, &display_source->event_poll_fd);
191 g_source_set_can_recurse (source, TRUE);
192 g_source_attach (source, NULL);
194 display_sources = g_list_prepend (display_sources,display_source);
196 gdk_display_add_client_message_filter (
198 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
199 gdk_wm_protocols_filter,
202 _gdk_x11_events_init_screen (display_x11->default_screen);
207 * gdk_events_pending:
209 * Checks if any events are ready to be processed for any display.
211 * Return value: %TRUE if any events are pending.
214 gdk_events_pending (void)
218 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
220 GdkDisplaySource *tmp_source = tmp_list->data;
221 GdkDisplay *display = tmp_source->display;
223 if (_gdk_event_queue_find_first (display))
227 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
229 GdkDisplaySource *tmp_source = tmp_list->data;
230 GdkDisplay *display = tmp_source->display;
232 if (gdk_check_xpending (display))
240 graphics_expose_predicate (Display *display,
244 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
245 (xevent->xany.type == GraphicsExpose ||
246 xevent->xany.type == NoExpose))
253 * gdk_event_get_graphics_expose:
254 * @window: the #GdkWindow to wait for the events for.
256 * Waits for a GraphicsExpose or NoExpose event from the X server.
257 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
258 * GraphicsExpose events are handled before the widget is scrolled.
260 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
261 * NoExpose event was received.
264 gdk_event_get_graphics_expose (GdkWindow *window)
269 g_return_val_if_fail (window != NULL, NULL);
271 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
272 graphics_expose_predicate, (XPointer) window);
274 if (xevent.xany.type == GraphicsExpose)
276 event = _gdk_event_new ();
278 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
282 gdk_event_free (event);
289 gdk_event_apply_filters (XEvent *xevent,
294 GdkFilterReturn result;
300 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
302 tmp_list = tmp_list->next;
303 result = filter->function (xevent, event, filter->data);
304 if (result != GDK_FILTER_CONTINUE)
308 return GDK_FILTER_CONTINUE;
312 * gdk_display_add_client_message_filter:
313 * @display: a #GdkDisplay for which this message filter applies
314 * @message_type: the type of ClientMessage events to receive.
315 * This will be checked against the @message_type field
316 * of the XClientMessage event struct.
317 * @func: the function to call to process the event.
318 * @data: user data to pass to @func.
320 * Adds a filter to be called when X ClientMessage events are received.
324 gdk_display_add_client_message_filter (GdkDisplay *display,
325 GdkAtom message_type,
329 GdkClientFilter *filter;
330 g_return_if_fail (GDK_IS_DISPLAY (display));
331 filter = g_new (GdkClientFilter, 1);
333 filter->type = message_type;
334 filter->function = func;
337 GDK_DISPLAY_X11(display)->client_filters =
338 g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
343 * gdk_add_client_message_filter:
344 * @message_type: the type of ClientMessage events to receive. This will be
345 * checked against the <structfield>message_type</structfield> field of the
346 * XClientMessage event struct.
347 * @func: the function to call to process the event.
348 * @data: user data to pass to @func.
350 * Adds a filter to the default display to be called when X ClientMessage events
351 * are received. See gdk_display_add_client_message_filter().
354 gdk_add_client_message_filter (GdkAtom message_type,
358 gdk_display_add_client_message_filter (gdk_get_default_display (),
359 message_type, func, data);
363 gdk_check_wm_state_changed (GdkWindow *window)
371 gboolean found_sticky, found_maxvert, found_maxhorz;
372 GdkWindowState old_state;
373 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
375 if (GDK_WINDOW_DESTROYED (window))
378 found_sticky = FALSE;
379 found_maxvert = FALSE;
380 found_maxhorz = FALSE;
382 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
383 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
384 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
385 &bytes_after, (guchar **)&atoms);
389 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
390 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
391 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
396 if (atoms[i] == sticky_atom)
398 else if (atoms[i] == maxvert_atom)
399 found_maxvert = TRUE;
400 else if (atoms[i] == maxhorz_atom)
401 found_maxhorz = TRUE;
409 /* For found_sticky to remain TRUE, we have to also be on desktop
417 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window),
418 GDK_WINDOW_XID (window),
419 gdk_x11_get_xatom_by_name_for_display
420 (display, "_NET_WM_DESKTOP"),
421 0, G_MAXLONG, False, XA_CARDINAL, &type,
423 &bytes_after, (guchar **)&desktop);
427 if (*desktop != 0xFFFFFFFF)
428 found_sticky = FALSE;
433 old_state = gdk_window_get_state (window);
435 if (old_state & GDK_WINDOW_STATE_STICKY)
438 gdk_synthesize_window_state (window,
439 GDK_WINDOW_STATE_STICKY,
445 gdk_synthesize_window_state (window,
447 GDK_WINDOW_STATE_STICKY);
450 /* Our "maximized" means both vertical and horizontal; if only one,
451 * we don't expose that via GDK
453 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
455 if (!(found_maxvert && found_maxhorz))
456 gdk_synthesize_window_state (window,
457 GDK_WINDOW_STATE_MAXIMIZED,
462 if (found_maxvert && found_maxhorz)
463 gdk_synthesize_window_state (window,
465 GDK_WINDOW_STATE_MAXIMIZED);
469 #define HAS_FOCUS(window_impl) \
470 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
473 generate_focus_event (GdkWindow *window,
478 event.type = GDK_FOCUS_CHANGE;
479 event.focus_change.window = window;
480 event.focus_change.send_event = FALSE;
481 event.focus_change.in = in;
483 gdk_event_put (&event);
487 gdk_event_translate (GdkDisplay *display,
490 gboolean return_exposes)
494 GdkWindowObject *window_private;
495 GdkWindowImplX11 *window_impl = NULL;
496 static XComposeStatus compose;
501 gint xoffset, yoffset;
502 GdkScreen *screen = NULL;
503 GdkScreenX11 *screen_x11 = NULL;
504 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
508 /* init these, since the done: block uses them */
510 window_private = NULL;
511 event->any.window = NULL;
513 if (_gdk_default_filters)
515 /* Apply global filters */
516 GdkFilterReturn result;
517 result = gdk_event_apply_filters (xevent, event,
518 _gdk_default_filters);
520 if (result != GDK_FILTER_CONTINUE)
522 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
527 /* We handle events with window=None
528 * specially - they are generated by XFree86's XInput under
529 * some circumstances. This handling for obvious reasons
530 * goes before we bother to lookup the event window.
533 if (xevent->xany.window == None)
535 return_val = _gdk_input_window_none_event (event, xevent);
537 if (return_val >= 0) /* was handled */
543 /* Find the GdkWindow that this event occurred in. */
545 window = gdk_window_lookup_for_display (display, xevent->xany.window);
546 window_private = (GdkWindowObject *) window;
550 screen = GDK_WINDOW_SCREEN (window);
551 screen_x11 = GDK_SCREEN_X11 (screen);
556 /* Window may be a pixmap, so check its type.
557 * (This check is probably too expensive unless
558 * GLib short-circuits an exact type match,
559 * which has been proposed)
561 if (GDK_IS_WINDOW (window))
563 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
565 if (xevent->xany.window != GDK_WINDOW_XID (window))
567 g_assert (xevent->xany.window == window_impl->focus_window);
569 switch (xevent->type)
573 xevent->xany.window = GDK_WINDOW_XID (window);
581 g_object_ref (G_OBJECT (window));
584 event->any.window = window;
585 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
587 if (window_private && GDK_WINDOW_DESTROYED (window))
589 if (xevent->type != DestroyNotify)
595 else if (window_private)
597 /* Apply per-window filters */
598 GdkFilterReturn result;
599 result = gdk_event_apply_filters (xevent, event,
600 window_private->filters);
602 if (result != GDK_FILTER_CONTINUE)
604 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
609 if (screen_x11 && screen_x11->wmspec_check_window != None &&
610 xevent->xany.window == screen_x11->wmspec_check_window)
612 if (xevent->type == DestroyNotify)
613 screen_x11->wmspec_check_window = None;
615 /* Eat events on this window unless someone had wrapped
616 * it as a foreign window
626 (xevent->xany.type == MotionNotify ||
627 xevent->xany.type == ButtonRelease))
629 if (_gdk_moveresize_handle_event (xevent))
636 /* We do a "manual" conversion of the XEvent to a
637 * GdkEvent. The structures are mostly the same so
638 * the conversion is fairly straightforward. We also
639 * optionally print debugging info regarding events
647 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
655 switch (xevent->type)
658 if (window_private == NULL)
664 /* Lookup the string corresponding to the given keysym.
667 charcount = XLookupString (&xevent->xkey, buf, 16,
669 event->key.keyval = keysym;
670 event->key.hardware_keycode = xevent->xkey.keycode;
672 if (charcount > 0 && buf[charcount-1] == '\0')
675 buf[charcount] = '\0';
677 #ifdef G_ENABLE_DEBUG
678 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
680 g_message ("key press:\twindow: %ld key: %12s %d",
682 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
685 g_message ("\t\tlength: %4d string: \"%s\"",
688 #endif /* G_ENABLE_DEBUG */
690 event->key.type = GDK_KEY_PRESS;
691 event->key.window = window;
692 event->key.time = xevent->xkey.time;
693 event->key.state = (GdkModifierType) xevent->xkey.state;
694 event->key.string = g_strdup (buf);
695 event->key.length = charcount;
697 /* bits 13 and 14 in the "state" field are the keyboard group */
698 #define KEYBOARD_GROUP_SHIFT 13
699 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
701 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
706 if (window_private == NULL)
712 /* Lookup the string corresponding to the given keysym.
715 /* Emulate detectable auto-repeat by checking to see
716 * if the next event is a key press with the same
717 * keycode and timestamp, and if so, ignoring the event.
720 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
724 XPeekEvent (xevent->xkey.display, &next_event);
726 if (next_event.type == KeyPress &&
727 next_event.xkey.keycode == xevent->xkey.keycode &&
728 next_event.xkey.time == xevent->xkey.time)
732 keysym = GDK_VoidSymbol;
733 charcount = XLookupString (&xevent->xkey, buf, 16,
735 event->key.keyval = keysym;
738 g_message ("key release:\t\twindow: %ld key: %12s %d",
740 XKeysymToString (event->key.keyval),
743 event->key.type = GDK_KEY_RELEASE;
744 event->key.window = window;
745 event->key.time = xevent->xkey.time;
746 event->key.state = (GdkModifierType) xevent->xkey.state;
747 event->key.length = 0;
748 event->key.string = NULL;
750 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
756 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
757 xevent->xbutton.window,
758 xevent->xbutton.x, xevent->xbutton.y,
759 xevent->xbutton.button));
761 if (window_private == NULL ||
762 ((window_private->extension_events != 0) &&
763 display_x11->input_ignore_core))
769 /* If we get a ButtonPress event where the button is 4 or 5,
770 it's a Scroll event */
771 switch (xevent->xbutton.button)
777 event->scroll.type = GDK_SCROLL;
779 if (xevent->xbutton.button == 4)
780 event->scroll.direction = GDK_SCROLL_UP;
781 else if (xevent->xbutton.button == 5)
782 event->scroll.direction = GDK_SCROLL_DOWN;
783 else if (xevent->xbutton.button == 6)
784 event->scroll.direction = GDK_SCROLL_LEFT;
786 event->scroll.direction = GDK_SCROLL_RIGHT;
788 event->scroll.window = window;
789 event->scroll.time = xevent->xbutton.time;
790 event->scroll.x = xevent->xbutton.x + xoffset;
791 event->scroll.y = xevent->xbutton.y + yoffset;
792 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
793 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
794 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
795 event->scroll.device = _gdk_core_pointer;
799 event->button.type = GDK_BUTTON_PRESS;
800 event->button.window = window;
801 event->button.time = xevent->xbutton.time;
802 event->button.x = xevent->xbutton.x + xoffset;
803 event->button.y = xevent->xbutton.y + yoffset;
804 event->button.x_root = (gfloat)xevent->xbutton.x_root;
805 event->button.y_root = (gfloat)xevent->xbutton.y_root;
806 event->button.axes = NULL;
807 event->button.state = (GdkModifierType) xevent->xbutton.state;
808 event->button.button = xevent->xbutton.button;
809 event->button.device = _gdk_core_pointer;
811 _gdk_event_button_generate (display, event);
819 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
820 xevent->xbutton.window,
821 xevent->xbutton.x, xevent->xbutton.y,
822 xevent->xbutton.button));
824 if (window_private == NULL ||
825 ((window_private->extension_events != 0) &&
826 display_x11->input_ignore_core))
832 /* We treat button presses as scroll wheel events, so ignore the release */
833 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
834 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
840 event->button.type = GDK_BUTTON_RELEASE;
841 event->button.window = window;
842 event->button.time = xevent->xbutton.time;
843 event->button.x = xevent->xbutton.x + xoffset;
844 event->button.y = xevent->xbutton.y + yoffset;
845 event->button.x_root = (gfloat)xevent->xbutton.x_root;
846 event->button.y_root = (gfloat)xevent->xbutton.y_root;
847 event->button.axes = NULL;
848 event->button.state = (GdkModifierType) xevent->xbutton.state;
849 event->button.button = xevent->xbutton.button;
850 event->button.device = _gdk_core_pointer;
856 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
857 xevent->xmotion.window,
858 xevent->xmotion.x, xevent->xmotion.y,
859 (xevent->xmotion.is_hint) ? "true" : "false"));
861 if (window_private == NULL ||
862 ((window_private->extension_events != 0) &&
863 display_x11->input_ignore_core))
869 event->motion.type = GDK_MOTION_NOTIFY;
870 event->motion.window = window;
871 event->motion.time = xevent->xmotion.time;
872 event->motion.x = xevent->xmotion.x + xoffset;
873 event->motion.y = xevent->xmotion.y + yoffset;
874 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
875 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
876 event->motion.axes = NULL;
877 event->motion.state = (GdkModifierType) xevent->xmotion.state;
878 event->motion.is_hint = xevent->xmotion.is_hint;
879 event->motion.device = _gdk_core_pointer;
885 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
886 xevent->xcrossing.window,
887 xevent->xcrossing.detail,
888 xevent->xcrossing.subwindow));
890 if (window_private == NULL)
896 /* Handle focusing (in the case where no window manager is running */
898 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
899 xevent->xcrossing.detail != NotifyInferior &&
900 xevent->xcrossing.focus && !window_impl->has_focus)
902 gboolean had_focus = HAS_FOCUS (window_impl);
904 window_impl->has_pointer_focus = TRUE;
906 if (HAS_FOCUS (window_impl) != had_focus)
907 generate_focus_event (window, TRUE);
910 /* Tell XInput stuff about it if appropriate */
911 if (window_private &&
912 !GDK_WINDOW_DESTROYED (window) &&
913 window_private->extension_events != 0)
914 _gdk_input_enter_event (&xevent->xcrossing, window);
916 event->crossing.type = GDK_ENTER_NOTIFY;
917 event->crossing.window = window;
919 /* If the subwindow field of the XEvent is non-NULL, then
920 * lookup the corresponding GdkWindow.
922 if (xevent->xcrossing.subwindow != None)
923 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
925 event->crossing.subwindow = NULL;
927 event->crossing.time = xevent->xcrossing.time;
928 event->crossing.x = xevent->xcrossing.x + xoffset;
929 event->crossing.y = xevent->xcrossing.y + yoffset;
930 event->crossing.x_root = xevent->xcrossing.x_root;
931 event->crossing.y_root = xevent->xcrossing.y_root;
933 /* Translate the crossing mode into Gdk terms.
935 switch (xevent->xcrossing.mode)
938 event->crossing.mode = GDK_CROSSING_NORMAL;
941 event->crossing.mode = GDK_CROSSING_GRAB;
944 event->crossing.mode = GDK_CROSSING_UNGRAB;
948 /* Translate the crossing detail into Gdk terms.
950 switch (xevent->xcrossing.detail)
953 event->crossing.detail = GDK_NOTIFY_INFERIOR;
956 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
959 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
961 case NotifyNonlinear:
962 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
964 case NotifyNonlinearVirtual:
965 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
968 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
972 event->crossing.focus = xevent->xcrossing.focus;
973 event->crossing.state = xevent->xcrossing.state;
979 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
980 xevent->xcrossing.window,
981 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
983 if (window_private == NULL)
989 /* Handle focusing (in the case where no window manager is running */
991 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
992 xevent->xcrossing.detail != NotifyInferior &&
993 xevent->xcrossing.focus && !window_impl->has_focus)
995 gboolean had_focus = HAS_FOCUS (window_impl);
997 window_impl->has_pointer_focus = FALSE;
999 if (HAS_FOCUS (window_impl) != had_focus)
1000 generate_focus_event (window, FALSE);
1003 event->crossing.type = GDK_LEAVE_NOTIFY;
1004 event->crossing.window = window;
1006 /* If the subwindow field of the XEvent is non-NULL, then
1007 * lookup the corresponding GdkWindow.
1009 if (xevent->xcrossing.subwindow != None)
1010 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1012 event->crossing.subwindow = NULL;
1014 event->crossing.time = xevent->xcrossing.time;
1015 event->crossing.x = xevent->xcrossing.x + xoffset;
1016 event->crossing.y = xevent->xcrossing.y + yoffset;
1017 event->crossing.x_root = xevent->xcrossing.x_root;
1018 event->crossing.y_root = xevent->xcrossing.y_root;
1020 /* Translate the crossing mode into Gdk terms.
1022 switch (xevent->xcrossing.mode)
1025 event->crossing.mode = GDK_CROSSING_NORMAL;
1028 event->crossing.mode = GDK_CROSSING_GRAB;
1031 event->crossing.mode = GDK_CROSSING_UNGRAB;
1035 /* Translate the crossing detail into Gdk terms.
1037 switch (xevent->xcrossing.detail)
1039 case NotifyInferior:
1040 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1042 case NotifyAncestor:
1043 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1046 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1048 case NotifyNonlinear:
1049 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1051 case NotifyNonlinearVirtual:
1052 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1055 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1059 event->crossing.focus = xevent->xcrossing.focus;
1060 event->crossing.state = xevent->xcrossing.state;
1064 /* We only care about focus events that indicate that _this_
1065 * window (not a ancestor or child) got or lost the focus
1069 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
1071 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1073 gboolean had_focus = HAS_FOCUS (window_impl);
1075 switch (xevent->xfocus.detail)
1077 case NotifyAncestor:
1078 case NotifyNonlinear:
1080 case NotifyNonlinearVirtual:
1081 window_impl->has_focus = TRUE;
1084 window_impl->has_pointer_focus = TRUE;
1086 case NotifyInferior:
1087 case NotifyPointerRoot:
1088 case NotifyDetailNone:
1092 if (HAS_FOCUS (window_impl) != had_focus)
1093 generate_focus_event (window, TRUE);
1098 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1100 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1102 gboolean had_focus = HAS_FOCUS (window_impl);
1104 switch (xevent->xfocus.detail)
1106 case NotifyAncestor:
1107 case NotifyNonlinear:
1109 case NotifyNonlinearVirtual:
1110 window_impl->has_focus = FALSE;
1113 window_impl->has_pointer_focus = FALSE;
1115 case NotifyInferior:
1116 case NotifyPointerRoot:
1117 case NotifyDetailNone:
1121 if (HAS_FOCUS (window_impl) != had_focus)
1122 generate_focus_event (window, FALSE);
1127 /* gdk_keyboard_grab() causes following events. These events confuse
1128 * the XIM focus, so ignore them.
1130 if (xevent->xfocus.mode == NotifyGrab ||
1131 xevent->xfocus.mode == NotifyUngrab)
1137 g_message ("keymap notify"));
1139 /* Not currently handled */
1145 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1146 xevent->xexpose.window, xevent->xexpose.count,
1147 xevent->xexpose.x, xevent->xexpose.y,
1148 xevent->xexpose.width, xevent->xexpose.height,
1149 event->any.send_event ? " (send)" : ""));
1151 if (window_private == NULL)
1158 GdkRectangle expose_rect;
1160 expose_rect.x = xevent->xexpose.x + xoffset;
1161 expose_rect.y = xevent->xexpose.y + yoffset;
1162 expose_rect.width = xevent->xexpose.width;
1163 expose_rect.height = xevent->xexpose.height;
1167 event->expose.type = GDK_EXPOSE;
1168 event->expose.area = expose_rect;
1169 event->expose.region = gdk_region_rectangle (&expose_rect);
1170 event->expose.window = window;
1171 event->expose.count = xevent->xexpose.count;
1177 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1186 case GraphicsExpose:
1188 GdkRectangle expose_rect;
1191 g_message ("graphics expose:\tdrawable: %ld",
1192 xevent->xgraphicsexpose.drawable));
1194 if (window_private == NULL)
1200 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1201 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1202 expose_rect.width = xevent->xgraphicsexpose.width;
1203 expose_rect.height = xevent->xgraphicsexpose.height;
1207 event->expose.type = GDK_EXPOSE;
1208 event->expose.area = expose_rect;
1209 event->expose.region = gdk_region_rectangle (&expose_rect);
1210 event->expose.window = window;
1211 event->expose.count = xevent->xgraphicsexpose.count;
1217 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1227 g_message ("no expose:\t\tdrawable: %ld",
1228 xevent->xnoexpose.drawable));
1230 event->no_expose.type = GDK_NO_EXPOSE;
1231 event->no_expose.window = window;
1235 case VisibilityNotify:
1236 #ifdef G_ENABLE_DEBUG
1237 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1238 switch (xevent->xvisibility.state)
1240 case VisibilityFullyObscured:
1241 g_message ("visibility notify:\twindow: %ld none",
1242 xevent->xvisibility.window);
1244 case VisibilityPartiallyObscured:
1245 g_message ("visibility notify:\twindow: %ld partial",
1246 xevent->xvisibility.window);
1248 case VisibilityUnobscured:
1249 g_message ("visibility notify:\twindow: %ld full",
1250 xevent->xvisibility.window);
1253 #endif /* G_ENABLE_DEBUG */
1255 if (window_private == NULL)
1261 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1262 event->visibility.window = window;
1264 switch (xevent->xvisibility.state)
1266 case VisibilityFullyObscured:
1267 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1270 case VisibilityPartiallyObscured:
1271 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1274 case VisibilityUnobscured:
1275 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1283 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1284 xevent->xcreatewindow.window,
1285 xevent->xcreatewindow.x,
1286 xevent->xcreatewindow.y,
1287 xevent->xcreatewindow.width,
1288 xevent->xcreatewindow.height,
1289 xevent->xcreatewindow.border_width,
1290 xevent->xcreatewindow.parent,
1291 xevent->xcreatewindow.override_redirect));
1292 /* not really handled */
1297 g_message ("destroy notify:\twindow: %ld",
1298 xevent->xdestroywindow.window));
1300 /* Ignore DestroyNotify from SubstructureNotifyMask */
1301 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1303 event->any.type = GDK_DESTROY;
1304 event->any.window = window;
1306 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1308 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1309 gdk_window_destroy_notify (window);
1318 g_message ("unmap notify:\t\twindow: %ld",
1319 xevent->xmap.window));
1321 event->any.type = GDK_UNMAP;
1322 event->any.window = window;
1324 /* If we are shown (not withdrawn) and get an unmap, it means we
1325 * were iconified in the X sense. If we are withdrawn, and get
1326 * an unmap, it means we hid the window ourselves, so we
1327 * will have already flipped the iconified bit off.
1331 if (GDK_WINDOW_IS_MAPPED (window))
1332 gdk_synthesize_window_state (window,
1334 GDK_WINDOW_STATE_ICONIFIED);
1336 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1343 g_message ("map notify:\t\twindow: %ld",
1344 xevent->xmap.window));
1346 event->any.type = GDK_MAP;
1347 event->any.window = window;
1349 /* Unset iconified if it was set */
1350 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1351 gdk_synthesize_window_state (window,
1352 GDK_WINDOW_STATE_ICONIFIED,
1357 case ReparentNotify:
1359 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1360 xevent->xreparent.window,
1361 xevent->xreparent.x,
1362 xevent->xreparent.y,
1363 xevent->xreparent.parent,
1364 xevent->xreparent.override_redirect));
1366 /* Not currently handled */
1370 case ConfigureNotify:
1372 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1373 xevent->xconfigure.window,
1374 xevent->xconfigure.x,
1375 xevent->xconfigure.y,
1376 xevent->xconfigure.width,
1377 xevent->xconfigure.height,
1378 xevent->xconfigure.border_width,
1379 xevent->xconfigure.above,
1380 xevent->xconfigure.override_redirect,
1383 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1384 ? " (discarding child)"
1387 !GDK_WINDOW_DESTROYED (window) &&
1388 (window_private->extension_events != 0))
1389 _gdk_input_configure_event (&xevent->xconfigure, window);
1392 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1393 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1397 event->configure.type = GDK_CONFIGURE;
1398 event->configure.window = window;
1399 event->configure.width = xevent->xconfigure.width;
1400 event->configure.height = xevent->xconfigure.height;
1402 if (!xevent->xconfigure.send_event &&
1403 !GDK_WINDOW_DESTROYED (window))
1407 Window child_window = 0;
1409 gdk_error_trap_push ();
1410 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1411 GDK_DRAWABLE_XID (window),
1412 screen_x11->xroot_window,
1417 if (!gdk_error_trap_pop ())
1419 event->configure.x = tx;
1420 event->configure.y = ty;
1424 gdk_error_trap_pop ();
1428 event->configure.x = xevent->xconfigure.x;
1429 event->configure.y = xevent->xconfigure.y;
1431 window_private->x = event->configure.x;
1432 window_private->y = event->configure.y;
1433 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1434 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1435 if (window_private->resize_count >= 1)
1437 window_private->resize_count -= 1;
1439 if (window_private->resize_count == 0)
1440 _gdk_moveresize_configure_done (display, window);
1445 case PropertyNotify:
1447 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1448 xevent->xproperty.window,
1449 xevent->xproperty.atom,
1451 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1454 if (window_private == NULL)
1460 event->property.type = GDK_PROPERTY_NOTIFY;
1461 event->property.window = window;
1462 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1463 event->property.time = xevent->xproperty.time;
1464 event->property.state = xevent->xproperty.state;
1466 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
1467 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1469 /* If window state changed, then synthesize those events. */
1470 gdk_check_wm_state_changed (event->property.window);
1475 case SelectionClear:
1477 g_message ("selection clear:\twindow: %ld",
1478 xevent->xproperty.window));
1480 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1482 event->selection.type = GDK_SELECTION_CLEAR;
1483 event->selection.window = window;
1484 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1485 event->selection.time = xevent->xselectionclear.time;
1492 case SelectionRequest:
1494 g_message ("selection request:\twindow: %ld",
1495 xevent->xproperty.window));
1497 event->selection.type = GDK_SELECTION_REQUEST;
1498 event->selection.window = window;
1499 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1500 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1501 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1502 event->selection.requestor = xevent->xselectionrequest.requestor;
1503 event->selection.time = xevent->xselectionrequest.time;
1507 case SelectionNotify:
1509 g_message ("selection notify:\twindow: %ld",
1510 xevent->xproperty.window));
1513 event->selection.type = GDK_SELECTION_NOTIFY;
1514 event->selection.window = window;
1515 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1516 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1517 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1518 event->selection.time = xevent->xselection.time;
1522 case ColormapNotify:
1524 g_message ("colormap notify:\twindow: %ld",
1525 xevent->xcolormap.window));
1527 /* Not currently handled */
1534 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1535 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1538 g_message ("client message:\twindow: %ld",
1539 xevent->xclient.window));
1541 tmp_list = display_x11->client_filters;
1544 GdkClientFilter *filter = tmp_list->data;
1545 if (filter->type == message_type)
1547 result = (*filter->function) (xevent, event, filter->data);
1551 tmp_list = tmp_list->next;
1556 case GDK_FILTER_REMOVE:
1559 case GDK_FILTER_TRANSLATE:
1562 case GDK_FILTER_CONTINUE:
1563 /* Send unknown ClientMessage's on to Gtk for it to use */
1564 if (window_private == NULL)
1570 event->client.type = GDK_CLIENT_EVENT;
1571 event->client.window = window;
1572 event->client.message_type = message_type;
1573 event->client.data_format = xevent->xclient.format;
1574 memcpy(&event->client.data, &xevent->xclient.data,
1575 sizeof(event->client.data));
1585 g_message ("mapping notify"));
1587 /* Let XLib know that there is a new keyboard mapping.
1589 XRefreshKeyboardMapping (&xevent->xmapping);
1590 ++display_x11->keymap_serial;
1596 if (xevent->type == display_x11->xkb_event_type)
1598 XkbEvent *xkb_event = (XkbEvent *)xevent;
1600 switch (xkb_event->any.xkb_type)
1603 ++display_x11->keymap_serial;
1608 case XkbStateNotify:
1609 _gdk_keymap_state_changed (display);
1616 /* something else - (e.g., a Xinput event) */
1618 if (window_private &&
1619 !GDK_WINDOW_DESTROYED (window_private) &&
1620 (window_private->extension_events != 0))
1621 return_val = _gdk_input_other_event(event, xevent, window);
1632 if (event->any.window)
1633 gdk_window_ref (event->any.window);
1634 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1635 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1636 (event->crossing.subwindow != NULL))
1637 gdk_window_ref (event->crossing.subwindow);
1641 /* Mark this event as having no resources to be freed */
1642 event->any.window = NULL;
1643 event->any.type = GDK_NOTHING;
1647 gdk_window_unref (window);
1652 static GdkFilterReturn
1653 gdk_wm_protocols_filter (GdkXEvent *xev,
1657 XEvent *xevent = (XEvent *)xev;
1658 GdkWindow *win = event->any.window;
1659 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1661 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1663 /* The delete window request specifies a window
1664 * to delete. We don't actually destroy the
1665 * window because "it is only a request". (The
1666 * window might contain vital data that the
1667 * program does not want destroyed). Instead
1668 * the event is passed along to the program,
1669 * which should then destroy the window.
1672 g_message ("delete window:\t\twindow: %ld",
1673 xevent->xclient.window));
1675 event->any.type = GDK_DELETE;
1677 return GDK_FILTER_TRANSLATE;
1679 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1681 GdkWindow *win = event->any.window;
1682 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1684 /* There is no way of knowing reliably whether we are viewable so we need
1685 * to trap errors so we don't cause a BadMatch.
1687 gdk_error_trap_push ();
1688 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1691 xevent->xclient.data.l[1]);
1692 XSync (GDK_WINDOW_XDISPLAY (win), False);
1693 gdk_error_trap_pop ();
1695 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"))
1697 XEvent xev = *xevent;
1699 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1700 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1703 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1706 return GDK_FILTER_REMOVE;
1710 _gdk_events_queue (GdkDisplay *display)
1715 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1717 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1719 XNextEvent (xdisplay, &xevent);
1721 switch (xevent.type)
1727 if (XFilterEvent (&xevent, None))
1731 event = _gdk_event_new ();
1733 event->any.type = GDK_NOTHING;
1734 event->any.window = NULL;
1735 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1737 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1739 node = _gdk_event_queue_append (display, event);
1741 if (gdk_event_translate (display, event, &xevent, FALSE))
1743 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1747 _gdk_event_queue_remove_link (display, node);
1748 g_list_free_1 (node);
1749 gdk_event_free (event);
1755 gdk_event_prepare (GSource *source,
1758 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1761 GDK_THREADS_ENTER ();
1764 retval = (_gdk_event_queue_find_first (display) != NULL ||
1765 gdk_check_xpending (display));
1767 GDK_THREADS_LEAVE ();
1773 gdk_event_check (GSource *source)
1775 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
1778 GDK_THREADS_ENTER ();
1780 if (display_source->event_poll_fd.revents & G_IO_IN)
1781 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
1782 gdk_check_xpending (display_source->display));
1786 GDK_THREADS_LEAVE ();
1792 gdk_event_dispatch (GSource *source,
1793 GSourceFunc callback,
1796 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1799 GDK_THREADS_ENTER ();
1801 _gdk_events_queue (display);
1802 event = _gdk_event_unqueue (display);
1806 if (_gdk_event_func)
1807 (*_gdk_event_func) (event, _gdk_event_data);
1809 gdk_event_free (event);
1812 GDK_THREADS_LEAVE ();
1818 * gdk_event_send_client_message:
1819 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
1820 * @xid: the window to send the X ClientMessage event to.
1822 * Sends an X ClientMessage event to a given window (which must be
1823 * on the default #GdkDisplay.)
1824 * This could be used for communicating between different applications,
1825 * though the amount of data is limited to 20 bytes.
1827 * Return value: non-zero on success.
1830 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1832 g_return_val_if_fail (event != NULL, FALSE);
1834 return gdk_event_send_client_message_for_display (gdk_get_default_display (),
1839 * gdk_event_send_client_message_for_display :
1840 * @display : the #GdkDisplay for the window where the message is to be sent.
1841 * @event : the #GdkEvent to send, which should be a #GdkEventClient.
1842 * @xid : the X window to send the X ClientMessage event to.
1844 * Sends an X ClientMessage event to a given window.
1846 * This could be used for communicating between different applications,
1847 * though the amount of data is limited to 20 bytes.
1849 * Returns : non-zero on success.
1852 gdk_event_send_client_message_for_display (GdkDisplay *display,
1858 g_return_val_if_fail(event != NULL, FALSE);
1860 /* Set up our event to send, with the exception of its target window */
1861 sev.xclient.type = ClientMessage;
1862 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
1863 sev.xclient.format = event->client.data_format;
1864 sev.xclient.window = xid;
1865 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1866 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
1868 return _gdk_send_xevent (display, xid, False, NoEventMask, &sev);
1873 /* Sends a ClientMessage to all toplevel client windows */
1875 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
1882 unsigned long nitems, after;
1883 unsigned char *data;
1884 Window *ret_children, ret_root, ret_parent;
1885 unsigned int ret_nchildren;
1886 gboolean send = FALSE;
1887 gboolean found = FALSE;
1888 gboolean result = FALSE;
1891 gdk_error_trap_push ();
1893 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
1894 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1895 0, 0, False, AnyPropertyType,
1896 &type, &format, &nitems, &after, &data) != Success)
1906 /* OK, we're all set, now let's find some windows to send this to */
1907 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
1908 &ret_root, &ret_parent,
1909 &ret_children, &ret_nchildren))
1912 for(i = 0; i < ret_nchildren; i++)
1913 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
1916 XFree (ret_children);
1919 if (send || (!found && (level == 1)))
1921 xev->xclient.window = xid;
1922 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
1925 result = send || found;
1928 gdk_error_trap_pop ();
1934 * gdk_event_send_clientmessage_toall:
1935 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
1937 * Sends an X ClientMessage event to all toplevel windows on the default
1940 * Toplevel windows are determined by checking for the WM_STATE property, as
1941 * described in the Inter-Client Communication Conventions Manual (ICCCM).
1942 * If no windows are found with the WM_STATE property set, the message is sent
1943 * to all children of the root window.
1946 gdk_event_send_clientmessage_toall (GdkEvent *event)
1948 g_return_if_fail (event != NULL);
1950 gdk_screen_broadcast_client_message (gdk_get_default_screen (), event);
1954 * gdk_screen_broadcast_client_message:
1955 * @screen : the #GdkScreen where the event will be broadcasted.
1956 * @event : the #GdkEvent.
1958 * Sends an X ClientMessage event to all toplevel windows on @screen.
1960 * Toplevel windows are determined by checking for the WM_STATE property,
1961 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
1962 * If no windows are found with the WM_STATE property set, the message is
1963 * sent to all children of the root window.
1967 gdk_screen_broadcast_client_message (GdkScreen *screen,
1971 GdkWindow *root_window;
1973 g_return_if_fail (event != NULL);
1975 root_window = gdk_screen_get_root_window (screen);
1977 /* Set up our event to send, with the exception of its target window */
1978 sev.xclient.type = ClientMessage;
1979 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
1980 sev.xclient.format = event->client.data_format;
1981 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1982 sev.xclient.message_type =
1983 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
1984 event->client.message_type);
1986 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
1988 GDK_WINDOW_XID (root_window),
1993 *--------------------------------------------------------------
1996 * Flushes the Xlib output buffer and then waits
1997 * until all requests have been received and processed
1998 * by the X server. The only real use for this function
1999 * is in dealing with XShm.
2007 *--------------------------------------------------------------
2013 GSList *tmp_list = _gdk_displays;
2017 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2018 tmp_list = tmp_list->next;
2023 timestamp_predicate (Display *display,
2027 Window xwindow = GPOINTER_TO_UINT (arg);
2028 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2030 if (xevent->type == PropertyNotify &&
2031 xevent->xproperty.window == xwindow &&
2032 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display
2033 (gdk_display, "GDK_TIMESTAMP_PROP"))
2040 * gdk_x11_get_server_time:
2041 * @window: a #GdkWindow, used for communication with the server.
2042 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2043 * events mask or a hang will result.
2045 * Routine to get the current X server time stamp.
2047 * Return value: the time stamp.
2050 gdk_x11_get_server_time (GdkWindow *window)
2056 Atom timestamp_prop_atom;
2058 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2059 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2061 xdisplay = GDK_WINDOW_XDISPLAY (window);
2062 xwindow = GDK_WINDOW_XWINDOW (window);
2063 timestamp_prop_atom =
2064 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2065 "GDK_TIMESTAMP_PROP");
2067 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2068 timestamp_prop_atom,
2069 8, PropModeReplace, &c, 1);
2071 XIfEvent (xdisplay, &xevent,
2072 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2074 return xevent.xproperty.time;
2077 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2079 struct _NetWmSupportedAtoms
2086 * gdk_x11_screen_supports_net_wm_hint:
2087 * @screen : the relevant #GdkScreen.
2088 * @property: a property atom.
2090 * This function is specific to the X11 backend of GDK, and indicates
2091 * whether the window manager supports a certain hint from the
2092 * Extended Window Manager Hints Specification. You can find this
2093 * specification on http://www.freedesktop.org.
2095 * When using this function, keep in mind that the window manager
2096 * can change over time; so you shouldn't use this function in
2097 * a way that impacts persistent application state. A common bug
2098 * is that your application can start up before the window manager
2099 * does when the user logs in, and before the window manager starts
2100 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2102 * Return value: %TRUE if the window manager supports @property
2105 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2114 GdkScreenX11 *screen_x11;
2115 NetWmSupportedAtoms *supported_atoms;
2116 GdkDisplay *display;
2118 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2120 screen_x11 = GDK_SCREEN_X11 (screen);
2121 display = screen_x11->display;
2123 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2124 if (!supported_atoms)
2126 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2127 g_object_set_data (G_OBJECT (screen), "net-wm-supported-atoms", supported_atoms);
2130 if (screen_x11->wmspec_check_window != None)
2132 if (supported_atoms->atoms == NULL)
2136 while (i < supported_atoms->n_atoms)
2138 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2147 if (supported_atoms->atoms)
2148 XFree (supported_atoms->atoms);
2150 supported_atoms->atoms = NULL;
2151 supported_atoms->n_atoms = 0;
2153 /* This function is very slow on every call if you are not running a
2154 * spec-supporting WM. For now not optimized, because it isn't in
2155 * any critical code paths, but if you used it somewhere that had to
2156 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2157 * Probably at that point the function should be changed to query
2158 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2161 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2162 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2163 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2164 &nitems, &bytes_after, (guchar **) & xwindow);
2166 if (type != XA_WINDOW)
2169 gdk_error_trap_push ();
2171 /* Find out if this WM goes away, so we can reset everything. */
2172 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2174 gdk_display_sync (screen_x11->display);
2176 if (gdk_error_trap_pop ())
2182 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2183 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2184 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2185 &supported_atoms->n_atoms, &bytes_after,
2186 (guchar **)&supported_atoms->atoms);
2188 if (type != XA_ATOM)
2191 screen_x11->wmspec_check_window = *xwindow;
2194 /* since wmspec_check_window != None this isn't infinite. ;-) */
2195 return gdk_x11_screen_supports_net_wm_hint (screen, property);
2199 * gdk_net_wm_supports:
2200 * @property: a property atom.
2202 * This function is specific to the X11 backend of GDK, and indicates
2203 * whether the window manager for the default screen supports a certain
2204 * hint from the Extended Window Manager Hints Specification. See
2205 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2207 * Return value: %TRUE if the window manager supports @property
2210 gdk_net_wm_supports (GdkAtom property)
2212 return gdk_x11_screen_supports_net_wm_hint (gdk_get_default_screen (), property);
2217 const char *xsettings_name;
2218 const char *gdk_name;
2219 } settings_map[] = {
2220 { "Net/DoubleClickTime", "gtk-double-click-time" },
2221 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2222 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2223 { "Gtk/ColorPalette", "gtk-color-palette" },
2224 { "Gtk/FontName", "gtk-font-name" },
2225 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2226 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2227 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2228 { "Net/CursorBlink", "gtk-cursor-blink" },
2229 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2230 { "Net/ThemeName", "gtk-theme-name" }
2234 gdk_xsettings_notify_cb (const char *name,
2235 XSettingsAction action,
2236 XSettingsSetting *setting,
2240 GdkScreen *screen = data;
2243 new_event.type = GDK_SETTING;
2244 new_event.setting.window = gdk_screen_get_root_window (screen);
2245 new_event.setting.send_event = FALSE;
2246 new_event.setting.name = NULL;
2248 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2249 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2251 new_event.setting.name = g_strdup (settings_map[i].gdk_name);
2255 if (!new_event.setting.name)
2260 case XSETTINGS_ACTION_NEW:
2261 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2263 case XSETTINGS_ACTION_CHANGED:
2264 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2266 case XSETTINGS_ACTION_DELETED:
2267 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2271 gdk_event_put (&new_event);
2275 check_transform (const gchar *xsettings_name,
2279 if (!g_value_type_transformable (src_type, dest_type))
2281 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2283 g_type_name (src_type),
2284 g_type_name (dest_type));
2293 * @name: the name of the setting.
2294 * @value: location to store the value of the setting.
2296 * Obtains a desktop-wide setting, such as the double-click time,
2297 * for the default screen. See gdk_screen_get_setting().
2299 * Returns : %TRUE if the setting existed and a value was stored
2300 * in @value, %FALSE otherwise.
2303 gdk_setting_get (const gchar *name,
2306 return gdk_screen_get_setting (gdk_get_default_screen (), name, value);
2310 * gdk_screen_get_setting:
2311 * @screen: the #GdkScreen where the setting is located
2312 * @name: the name of the setting
2313 * @value: location to store the value of the setting
2315 * Retrieves a desktop-wide setting such as double-click time
2316 * for the #GdkScreen @screen.
2318 * FIXME needs a list of valid settings here, or a link to
2321 * Returns : %TRUE if the setting existed and a value was stored
2322 * in @value, %FALSE otherwise.
2325 gdk_screen_get_setting (GdkScreen *screen,
2330 const char *xsettings_name = NULL;
2331 XSettingsResult result;
2332 XSettingsSetting *setting;
2333 GdkScreenX11 *screen_x11;
2334 gboolean success = FALSE;
2336 GValue tmp_val = { 0, };
2338 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2340 screen_x11 = GDK_SCREEN_X11 (screen);
2342 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2343 if (strcmp (settings_map[i].gdk_name, name) == 0)
2345 xsettings_name = settings_map[i].xsettings_name;
2349 if (!xsettings_name)
2352 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2353 xsettings_name, &setting);
2354 if (result != XSETTINGS_SUCCESS)
2357 switch (setting->type)
2359 case XSETTINGS_TYPE_INT:
2360 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2362 g_value_init (&tmp_val, G_TYPE_INT);
2363 g_value_set_int (&tmp_val, setting->data.v_int);
2364 g_value_transform (&tmp_val, value);
2369 case XSETTINGS_TYPE_STRING:
2370 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2372 g_value_init (&tmp_val, G_TYPE_STRING);
2373 g_value_set_string (&tmp_val, setting->data.v_string);
2374 g_value_transform (&tmp_val, value);
2379 case XSETTINGS_TYPE_COLOR:
2380 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2384 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2387 color.red = setting->data.v_color.red;
2388 color.green = setting->data.v_color.green;
2389 color.blue = setting->data.v_color.blue;
2391 g_value_set_boxed (&tmp_val, &color);
2393 g_value_transform (&tmp_val, value);
2400 g_value_unset (&tmp_val);
2402 xsettings_setting_free (setting);
2407 static GdkFilterReturn
2408 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2412 GdkScreenX11 *screen = data;
2414 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2415 return GDK_FILTER_REMOVE;
2417 return GDK_FILTER_CONTINUE;
2421 gdk_xsettings_watch_cb (Window window,
2427 GdkScreen *screen = cb_data;
2429 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2432 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2434 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);