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_x11_events_uninit_screen (GdkScreen *screen)
175 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
177 xsettings_client_destroy (screen_x11->xsettings_client);
178 screen_x11->xsettings_client = NULL;
182 _gdk_events_init (GdkDisplay *display)
185 GdkDisplaySource *display_source;
186 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
188 int connection_number = ConnectionNumber (display_x11->xdisplay);
189 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
192 source = display_x11->event_source = gdk_display_source_new (display);
193 display_source = (GdkDisplaySource*) source;
194 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
196 display_source->event_poll_fd.fd = connection_number;
197 display_source->event_poll_fd.events = G_IO_IN;
199 g_source_add_poll (source, &display_source->event_poll_fd);
200 g_source_set_can_recurse (source, TRUE);
201 g_source_attach (source, NULL);
203 display_sources = g_list_prepend (display_sources,display_source);
205 gdk_display_add_client_message_filter (
207 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
208 gdk_wm_protocols_filter,
214 * gdk_events_pending:
216 * Checks if any events are ready to be processed for any display.
218 * Return value: %TRUE if any events are pending.
221 gdk_events_pending (void)
225 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
227 GdkDisplaySource *tmp_source = tmp_list->data;
228 GdkDisplay *display = tmp_source->display;
230 if (_gdk_event_queue_find_first (display))
234 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
236 GdkDisplaySource *tmp_source = tmp_list->data;
237 GdkDisplay *display = tmp_source->display;
239 if (gdk_check_xpending (display))
247 graphics_expose_predicate (Display *display,
251 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
252 (xevent->xany.type == GraphicsExpose ||
253 xevent->xany.type == NoExpose))
260 * gdk_event_get_graphics_expose:
261 * @window: the #GdkWindow to wait for the events for.
263 * Waits for a GraphicsExpose or NoExpose event from the X server.
264 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
265 * GraphicsExpose events are handled before the widget is scrolled.
267 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
268 * NoExpose event was received.
271 gdk_event_get_graphics_expose (GdkWindow *window)
276 g_return_val_if_fail (window != NULL, NULL);
278 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
279 graphics_expose_predicate, (XPointer) window);
281 if (xevent.xany.type == GraphicsExpose)
283 event = _gdk_event_new ();
285 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
289 gdk_event_free (event);
296 gdk_event_apply_filters (XEvent *xevent,
301 GdkFilterReturn result;
307 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
309 tmp_list = tmp_list->next;
310 result = filter->function (xevent, event, filter->data);
311 if (result != GDK_FILTER_CONTINUE)
315 return GDK_FILTER_CONTINUE;
319 * gdk_display_add_client_message_filter:
320 * @display: a #GdkDisplay for which this message filter applies
321 * @message_type: the type of ClientMessage events to receive.
322 * This will be checked against the @message_type field
323 * of the XClientMessage event struct.
324 * @func: the function to call to process the event.
325 * @data: user data to pass to @func.
327 * Adds a filter to be called when X ClientMessage events are received.
331 gdk_display_add_client_message_filter (GdkDisplay *display,
332 GdkAtom message_type,
336 GdkClientFilter *filter;
337 g_return_if_fail (GDK_IS_DISPLAY (display));
338 filter = g_new (GdkClientFilter, 1);
340 filter->type = message_type;
341 filter->function = func;
344 GDK_DISPLAY_X11(display)->client_filters =
345 g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
350 * gdk_add_client_message_filter:
351 * @message_type: the type of ClientMessage events to receive. This will be
352 * checked against the <structfield>message_type</structfield> field of the
353 * XClientMessage event struct.
354 * @func: the function to call to process the event.
355 * @data: user data to pass to @func.
357 * Adds a filter to the default display to be called when X ClientMessage events
358 * are received. See gdk_display_add_client_message_filter().
361 gdk_add_client_message_filter (GdkAtom message_type,
365 gdk_display_add_client_message_filter (gdk_display_get_default (),
366 message_type, func, data);
370 gdk_check_wm_state_changed (GdkWindow *window)
378 gboolean found_sticky, found_maxvert, found_maxhorz;
379 GdkWindowState old_state;
380 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
382 if (GDK_WINDOW_DESTROYED (window) ||
383 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
386 found_sticky = FALSE;
387 found_maxvert = FALSE;
388 found_maxhorz = FALSE;
390 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
391 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
392 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
393 &bytes_after, (guchar **)&atoms);
397 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
398 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
399 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
404 if (atoms[i] == sticky_atom)
406 else if (atoms[i] == maxvert_atom)
407 found_maxvert = TRUE;
408 else if (atoms[i] == maxhorz_atom)
409 found_maxhorz = TRUE;
417 /* For found_sticky to remain TRUE, we have to also be on desktop
425 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window),
426 GDK_WINDOW_XID (window),
427 gdk_x11_get_xatom_by_name_for_display
428 (display, "_NET_WM_DESKTOP"),
429 0, G_MAXLONG, False, XA_CARDINAL, &type,
431 &bytes_after, (guchar **)&desktop);
435 if (*desktop != 0xFFFFFFFF)
436 found_sticky = FALSE;
441 old_state = gdk_window_get_state (window);
443 if (old_state & GDK_WINDOW_STATE_STICKY)
446 gdk_synthesize_window_state (window,
447 GDK_WINDOW_STATE_STICKY,
453 gdk_synthesize_window_state (window,
455 GDK_WINDOW_STATE_STICKY);
458 /* Our "maximized" means both vertical and horizontal; if only one,
459 * we don't expose that via GDK
461 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
463 if (!(found_maxvert && found_maxhorz))
464 gdk_synthesize_window_state (window,
465 GDK_WINDOW_STATE_MAXIMIZED,
470 if (found_maxvert && found_maxhorz)
471 gdk_synthesize_window_state (window,
473 GDK_WINDOW_STATE_MAXIMIZED);
477 #define HAS_FOCUS(window_impl) \
478 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
481 generate_focus_event (GdkWindow *window,
486 event.type = GDK_FOCUS_CHANGE;
487 event.focus_change.window = window;
488 event.focus_change.send_event = FALSE;
489 event.focus_change.in = in;
491 gdk_event_put (&event);
495 gdk_event_translate (GdkDisplay *display,
498 gboolean return_exposes)
502 GdkWindowObject *window_private;
503 GdkWindowImplX11 *window_impl = NULL;
504 static XComposeStatus compose;
509 gint xoffset, yoffset;
510 GdkScreen *screen = NULL;
511 GdkScreenX11 *screen_x11 = NULL;
512 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
516 /* init these, since the done: block uses them */
518 window_private = NULL;
519 event->any.window = NULL;
521 if (_gdk_default_filters)
523 /* Apply global filters */
524 GdkFilterReturn result;
525 result = gdk_event_apply_filters (xevent, event,
526 _gdk_default_filters);
528 if (result != GDK_FILTER_CONTINUE)
530 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
535 /* We handle events with window=None
536 * specially - they are generated by XFree86's XInput under
537 * some circumstances. This handling for obvious reasons
538 * goes before we bother to lookup the event window.
541 if (xevent->xany.window == None)
543 return_val = _gdk_input_window_none_event (event, xevent);
545 if (return_val >= 0) /* was handled */
551 /* Find the GdkWindow that this event occurred in. */
553 window = gdk_window_lookup_for_display (display, xevent->xany.window);
554 window_private = (GdkWindowObject *) window;
558 screen = GDK_WINDOW_SCREEN (window);
559 screen_x11 = GDK_SCREEN_X11 (screen);
564 /* Window may be a pixmap, so check its type.
565 * (This check is probably too expensive unless
566 * GLib short-circuits an exact type match,
567 * which has been proposed)
569 if (GDK_IS_WINDOW (window))
571 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
573 if (xevent->xany.window != GDK_WINDOW_XID (window))
575 g_assert (xevent->xany.window == window_impl->focus_window);
577 switch (xevent->type)
581 xevent->xany.window = GDK_WINDOW_XID (window);
589 g_object_ref (G_OBJECT (window));
592 event->any.window = window;
593 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
595 if (window_private && GDK_WINDOW_DESTROYED (window))
597 if (xevent->type != DestroyNotify)
603 else if (window_private)
605 /* Apply per-window filters */
606 GdkFilterReturn result;
607 result = gdk_event_apply_filters (xevent, event,
608 window_private->filters);
610 if (result != GDK_FILTER_CONTINUE)
612 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
617 if (screen_x11 && screen_x11->wmspec_check_window != None &&
618 xevent->xany.window == screen_x11->wmspec_check_window)
620 if (xevent->type == DestroyNotify)
621 screen_x11->wmspec_check_window = None;
623 /* Eat events on this window unless someone had wrapped
624 * it as a foreign window
634 (xevent->xany.type == MotionNotify ||
635 xevent->xany.type == ButtonRelease))
637 if (_gdk_moveresize_handle_event (xevent))
644 /* We do a "manual" conversion of the XEvent to a
645 * GdkEvent. The structures are mostly the same so
646 * the conversion is fairly straightforward. We also
647 * optionally print debugging info regarding events
655 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
663 switch (xevent->type)
666 if (window_private == NULL)
672 /* Lookup the string corresponding to the given keysym.
675 charcount = XLookupString (&xevent->xkey, buf, 16,
677 event->key.keyval = keysym;
678 event->key.hardware_keycode = xevent->xkey.keycode;
680 if (charcount > 0 && buf[charcount-1] == '\0')
683 buf[charcount] = '\0';
685 #ifdef G_ENABLE_DEBUG
686 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
688 g_message ("key press:\twindow: %ld key: %12s %d",
690 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
693 g_message ("\t\tlength: %4d string: \"%s\"",
696 #endif /* G_ENABLE_DEBUG */
698 event->key.type = GDK_KEY_PRESS;
699 event->key.window = window;
700 event->key.time = xevent->xkey.time;
701 event->key.state = (GdkModifierType) xevent->xkey.state;
702 event->key.string = g_strdup (buf);
703 event->key.length = charcount;
705 /* bits 13 and 14 in the "state" field are the keyboard group */
706 #define KEYBOARD_GROUP_SHIFT 13
707 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
709 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
714 if (window_private == NULL)
720 /* Lookup the string corresponding to the given keysym.
723 /* Emulate detectable auto-repeat by checking to see
724 * if the next event is a key press with the same
725 * keycode and timestamp, and if so, ignoring the event.
728 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
732 XPeekEvent (xevent->xkey.display, &next_event);
734 if (next_event.type == KeyPress &&
735 next_event.xkey.keycode == xevent->xkey.keycode &&
736 next_event.xkey.time == xevent->xkey.time)
740 keysym = GDK_VoidSymbol;
741 charcount = XLookupString (&xevent->xkey, buf, 16,
743 event->key.keyval = keysym;
744 event->key.hardware_keycode = xevent->xkey.keycode;
747 g_message ("key release:\t\twindow: %ld key: %12s %d",
749 XKeysymToString (event->key.keyval),
752 event->key.type = GDK_KEY_RELEASE;
753 event->key.window = window;
754 event->key.time = xevent->xkey.time;
755 event->key.state = (GdkModifierType) xevent->xkey.state;
756 event->key.length = 0;
757 event->key.string = NULL;
759 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
765 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
766 xevent->xbutton.window,
767 xevent->xbutton.x, xevent->xbutton.y,
768 xevent->xbutton.button));
770 if (window_private == NULL ||
771 ((window_private->extension_events != 0) &&
772 display_x11->input_ignore_core))
778 /* If we get a ButtonPress event where the button is 4 or 5,
779 it's a Scroll event */
780 switch (xevent->xbutton.button)
786 event->scroll.type = GDK_SCROLL;
788 if (xevent->xbutton.button == 4)
789 event->scroll.direction = GDK_SCROLL_UP;
790 else if (xevent->xbutton.button == 5)
791 event->scroll.direction = GDK_SCROLL_DOWN;
792 else if (xevent->xbutton.button == 6)
793 event->scroll.direction = GDK_SCROLL_LEFT;
795 event->scroll.direction = GDK_SCROLL_RIGHT;
797 event->scroll.window = window;
798 event->scroll.time = xevent->xbutton.time;
799 event->scroll.x = xevent->xbutton.x + xoffset;
800 event->scroll.y = xevent->xbutton.y + yoffset;
801 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
802 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
803 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
804 event->scroll.device = display->core_pointer;
808 event->button.type = GDK_BUTTON_PRESS;
809 event->button.window = window;
810 event->button.time = xevent->xbutton.time;
811 event->button.x = xevent->xbutton.x + xoffset;
812 event->button.y = xevent->xbutton.y + yoffset;
813 event->button.x_root = (gfloat)xevent->xbutton.x_root;
814 event->button.y_root = (gfloat)xevent->xbutton.y_root;
815 event->button.axes = NULL;
816 event->button.state = (GdkModifierType) xevent->xbutton.state;
817 event->button.button = xevent->xbutton.button;
818 event->button.device = display->core_pointer;
820 _gdk_event_button_generate (display, event);
828 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
829 xevent->xbutton.window,
830 xevent->xbutton.x, xevent->xbutton.y,
831 xevent->xbutton.button));
833 if (window_private == NULL ||
834 ((window_private->extension_events != 0) &&
835 display_x11->input_ignore_core))
841 /* We treat button presses as scroll wheel events, so ignore the release */
842 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
843 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
849 event->button.type = GDK_BUTTON_RELEASE;
850 event->button.window = window;
851 event->button.time = xevent->xbutton.time;
852 event->button.x = xevent->xbutton.x + xoffset;
853 event->button.y = xevent->xbutton.y + yoffset;
854 event->button.x_root = (gfloat)xevent->xbutton.x_root;
855 event->button.y_root = (gfloat)xevent->xbutton.y_root;
856 event->button.axes = NULL;
857 event->button.state = (GdkModifierType) xevent->xbutton.state;
858 event->button.button = xevent->xbutton.button;
859 event->button.device = display->core_pointer;
865 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
866 xevent->xmotion.window,
867 xevent->xmotion.x, xevent->xmotion.y,
868 (xevent->xmotion.is_hint) ? "true" : "false"));
870 if (window_private == NULL ||
871 ((window_private->extension_events != 0) &&
872 display_x11->input_ignore_core))
878 event->motion.type = GDK_MOTION_NOTIFY;
879 event->motion.window = window;
880 event->motion.time = xevent->xmotion.time;
881 event->motion.x = xevent->xmotion.x + xoffset;
882 event->motion.y = xevent->xmotion.y + yoffset;
883 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
884 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
885 event->motion.axes = NULL;
886 event->motion.state = (GdkModifierType) xevent->xmotion.state;
887 event->motion.is_hint = xevent->xmotion.is_hint;
888 event->motion.device = display->core_pointer;
894 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
895 xevent->xcrossing.window,
896 xevent->xcrossing.detail,
897 xevent->xcrossing.subwindow));
899 if (window_private == NULL)
905 /* Handle focusing (in the case where no window manager is running */
907 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
908 xevent->xcrossing.detail != NotifyInferior &&
909 xevent->xcrossing.focus && !window_impl->has_focus)
911 gboolean had_focus = HAS_FOCUS (window_impl);
913 window_impl->has_pointer_focus = TRUE;
915 if (HAS_FOCUS (window_impl) != had_focus)
916 generate_focus_event (window, TRUE);
919 /* Tell XInput stuff about it if appropriate */
920 if (window_private &&
921 !GDK_WINDOW_DESTROYED (window) &&
922 window_private->extension_events != 0)
923 _gdk_input_enter_event (&xevent->xcrossing, window);
925 event->crossing.type = GDK_ENTER_NOTIFY;
926 event->crossing.window = window;
928 /* If the subwindow field of the XEvent is non-NULL, then
929 * lookup the corresponding GdkWindow.
931 if (xevent->xcrossing.subwindow != None)
932 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
934 event->crossing.subwindow = NULL;
936 event->crossing.time = xevent->xcrossing.time;
937 event->crossing.x = xevent->xcrossing.x + xoffset;
938 event->crossing.y = xevent->xcrossing.y + yoffset;
939 event->crossing.x_root = xevent->xcrossing.x_root;
940 event->crossing.y_root = xevent->xcrossing.y_root;
942 /* Translate the crossing mode into Gdk terms.
944 switch (xevent->xcrossing.mode)
947 event->crossing.mode = GDK_CROSSING_NORMAL;
950 event->crossing.mode = GDK_CROSSING_GRAB;
953 event->crossing.mode = GDK_CROSSING_UNGRAB;
957 /* Translate the crossing detail into Gdk terms.
959 switch (xevent->xcrossing.detail)
962 event->crossing.detail = GDK_NOTIFY_INFERIOR;
965 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
968 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
970 case NotifyNonlinear:
971 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
973 case NotifyNonlinearVirtual:
974 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
977 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
981 event->crossing.focus = xevent->xcrossing.focus;
982 event->crossing.state = xevent->xcrossing.state;
988 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
989 xevent->xcrossing.window,
990 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
992 if (window_private == NULL)
998 /* Handle focusing (in the case where no window manager is running */
1000 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1001 xevent->xcrossing.detail != NotifyInferior &&
1002 xevent->xcrossing.focus && !window_impl->has_focus)
1004 gboolean had_focus = HAS_FOCUS (window_impl);
1006 window_impl->has_pointer_focus = FALSE;
1008 if (HAS_FOCUS (window_impl) != had_focus)
1009 generate_focus_event (window, FALSE);
1012 event->crossing.type = GDK_LEAVE_NOTIFY;
1013 event->crossing.window = window;
1015 /* If the subwindow field of the XEvent is non-NULL, then
1016 * lookup the corresponding GdkWindow.
1018 if (xevent->xcrossing.subwindow != None)
1019 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1021 event->crossing.subwindow = NULL;
1023 event->crossing.time = xevent->xcrossing.time;
1024 event->crossing.x = xevent->xcrossing.x + xoffset;
1025 event->crossing.y = xevent->xcrossing.y + yoffset;
1026 event->crossing.x_root = xevent->xcrossing.x_root;
1027 event->crossing.y_root = xevent->xcrossing.y_root;
1029 /* Translate the crossing mode into Gdk terms.
1031 switch (xevent->xcrossing.mode)
1034 event->crossing.mode = GDK_CROSSING_NORMAL;
1037 event->crossing.mode = GDK_CROSSING_GRAB;
1040 event->crossing.mode = GDK_CROSSING_UNGRAB;
1044 /* Translate the crossing detail into Gdk terms.
1046 switch (xevent->xcrossing.detail)
1048 case NotifyInferior:
1049 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1051 case NotifyAncestor:
1052 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1055 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1057 case NotifyNonlinear:
1058 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1060 case NotifyNonlinearVirtual:
1061 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1064 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1068 event->crossing.focus = xevent->xcrossing.focus;
1069 event->crossing.state = xevent->xcrossing.state;
1073 /* We only care about focus events that indicate that _this_
1074 * window (not a ancestor or child) got or lost the focus
1078 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
1080 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1082 gboolean had_focus = HAS_FOCUS (window_impl);
1084 switch (xevent->xfocus.detail)
1086 case NotifyAncestor:
1087 case NotifyNonlinear:
1089 case NotifyNonlinearVirtual:
1090 window_impl->has_focus = TRUE;
1093 window_impl->has_pointer_focus = TRUE;
1095 case NotifyInferior:
1096 case NotifyPointerRoot:
1097 case NotifyDetailNone:
1101 if (HAS_FOCUS (window_impl) != had_focus)
1102 generate_focus_event (window, TRUE);
1107 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1109 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1111 gboolean had_focus = HAS_FOCUS (window_impl);
1113 switch (xevent->xfocus.detail)
1115 case NotifyAncestor:
1116 case NotifyNonlinear:
1118 case NotifyNonlinearVirtual:
1119 window_impl->has_focus = FALSE;
1122 window_impl->has_pointer_focus = FALSE;
1124 case NotifyInferior:
1125 case NotifyPointerRoot:
1126 case NotifyDetailNone:
1130 if (HAS_FOCUS (window_impl) != had_focus)
1131 generate_focus_event (window, FALSE);
1136 /* gdk_keyboard_grab() causes following events. These events confuse
1137 * the XIM focus, so ignore them.
1139 if (xevent->xfocus.mode == NotifyGrab ||
1140 xevent->xfocus.mode == NotifyUngrab)
1146 g_message ("keymap notify"));
1148 /* Not currently handled */
1154 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1155 xevent->xexpose.window, xevent->xexpose.count,
1156 xevent->xexpose.x, xevent->xexpose.y,
1157 xevent->xexpose.width, xevent->xexpose.height,
1158 event->any.send_event ? " (send)" : ""));
1160 if (window_private == NULL)
1167 GdkRectangle expose_rect;
1169 expose_rect.x = xevent->xexpose.x + xoffset;
1170 expose_rect.y = xevent->xexpose.y + yoffset;
1171 expose_rect.width = xevent->xexpose.width;
1172 expose_rect.height = xevent->xexpose.height;
1176 event->expose.type = GDK_EXPOSE;
1177 event->expose.area = expose_rect;
1178 event->expose.region = gdk_region_rectangle (&expose_rect);
1179 event->expose.window = window;
1180 event->expose.count = xevent->xexpose.count;
1186 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1195 case GraphicsExpose:
1197 GdkRectangle expose_rect;
1200 g_message ("graphics expose:\tdrawable: %ld",
1201 xevent->xgraphicsexpose.drawable));
1203 if (window_private == NULL)
1209 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1210 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1211 expose_rect.width = xevent->xgraphicsexpose.width;
1212 expose_rect.height = xevent->xgraphicsexpose.height;
1216 event->expose.type = GDK_EXPOSE;
1217 event->expose.area = expose_rect;
1218 event->expose.region = gdk_region_rectangle (&expose_rect);
1219 event->expose.window = window;
1220 event->expose.count = xevent->xgraphicsexpose.count;
1226 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1236 g_message ("no expose:\t\tdrawable: %ld",
1237 xevent->xnoexpose.drawable));
1239 event->no_expose.type = GDK_NO_EXPOSE;
1240 event->no_expose.window = window;
1244 case VisibilityNotify:
1245 #ifdef G_ENABLE_DEBUG
1246 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1247 switch (xevent->xvisibility.state)
1249 case VisibilityFullyObscured:
1250 g_message ("visibility notify:\twindow: %ld none",
1251 xevent->xvisibility.window);
1253 case VisibilityPartiallyObscured:
1254 g_message ("visibility notify:\twindow: %ld partial",
1255 xevent->xvisibility.window);
1257 case VisibilityUnobscured:
1258 g_message ("visibility notify:\twindow: %ld full",
1259 xevent->xvisibility.window);
1262 #endif /* G_ENABLE_DEBUG */
1264 if (window_private == NULL)
1270 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1271 event->visibility.window = window;
1273 switch (xevent->xvisibility.state)
1275 case VisibilityFullyObscured:
1276 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1279 case VisibilityPartiallyObscured:
1280 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1283 case VisibilityUnobscured:
1284 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1292 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1293 xevent->xcreatewindow.window,
1294 xevent->xcreatewindow.x,
1295 xevent->xcreatewindow.y,
1296 xevent->xcreatewindow.width,
1297 xevent->xcreatewindow.height,
1298 xevent->xcreatewindow.border_width,
1299 xevent->xcreatewindow.parent,
1300 xevent->xcreatewindow.override_redirect));
1301 /* not really handled */
1306 g_message ("destroy notify:\twindow: %ld",
1307 xevent->xdestroywindow.window));
1309 /* Ignore DestroyNotify from SubstructureNotifyMask */
1310 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1312 event->any.type = GDK_DESTROY;
1313 event->any.window = window;
1315 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1317 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1318 gdk_window_destroy_notify (window);
1327 g_message ("unmap notify:\t\twindow: %ld",
1328 xevent->xmap.window));
1330 event->any.type = GDK_UNMAP;
1331 event->any.window = window;
1333 /* If we are shown (not withdrawn) and get an unmap, it means we
1334 * were iconified in the X sense. If we are withdrawn, and get
1335 * an unmap, it means we hid the window ourselves, so we
1336 * will have already flipped the iconified bit off.
1340 if (GDK_WINDOW_IS_MAPPED (window))
1341 gdk_synthesize_window_state (window,
1343 GDK_WINDOW_STATE_ICONIFIED);
1345 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1352 g_message ("map notify:\t\twindow: %ld",
1353 xevent->xmap.window));
1355 event->any.type = GDK_MAP;
1356 event->any.window = window;
1358 /* Unset iconified if it was set */
1359 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1360 gdk_synthesize_window_state (window,
1361 GDK_WINDOW_STATE_ICONIFIED,
1366 case ReparentNotify:
1368 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1369 xevent->xreparent.window,
1370 xevent->xreparent.x,
1371 xevent->xreparent.y,
1372 xevent->xreparent.parent,
1373 xevent->xreparent.override_redirect));
1375 /* Not currently handled */
1379 case ConfigureNotify:
1381 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1382 xevent->xconfigure.window,
1383 xevent->xconfigure.x,
1384 xevent->xconfigure.y,
1385 xevent->xconfigure.width,
1386 xevent->xconfigure.height,
1387 xevent->xconfigure.border_width,
1388 xevent->xconfigure.above,
1389 xevent->xconfigure.override_redirect,
1392 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1393 ? " (discarding child)"
1394 : xevent->xconfigure.event != xevent->xconfigure.window
1395 ? " (discarding substructure)"
1398 xevent->xconfigure.event == xevent->xconfigure.window &&
1399 !GDK_WINDOW_DESTROYED (window) &&
1400 (window_private->extension_events != 0))
1401 _gdk_input_configure_event (&xevent->xconfigure, window);
1404 xevent->xconfigure.event != xevent->xconfigure.window ||
1405 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1406 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1410 event->configure.type = GDK_CONFIGURE;
1411 event->configure.window = window;
1412 event->configure.width = xevent->xconfigure.width;
1413 event->configure.height = xevent->xconfigure.height;
1415 if (!xevent->xconfigure.send_event &&
1416 !GDK_WINDOW_DESTROYED (window))
1420 Window child_window = 0;
1422 gdk_error_trap_push ();
1423 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1424 GDK_DRAWABLE_XID (window),
1425 screen_x11->xroot_window,
1430 if (!gdk_error_trap_pop ())
1432 event->configure.x = tx;
1433 event->configure.y = ty;
1437 gdk_error_trap_pop ();
1441 event->configure.x = xevent->xconfigure.x;
1442 event->configure.y = xevent->xconfigure.y;
1444 window_private->x = event->configure.x;
1445 window_private->y = event->configure.y;
1446 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1447 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1448 if (window_private->resize_count >= 1)
1450 window_private->resize_count -= 1;
1452 if (window_private->resize_count == 0)
1453 _gdk_moveresize_configure_done (display, window);
1458 case PropertyNotify:
1460 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1461 xevent->xproperty.window,
1462 xevent->xproperty.atom,
1464 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1467 if (window_private == NULL)
1473 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
1474 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1476 /* If window state changed, then synthesize those events. */
1477 gdk_check_wm_state_changed (window);
1480 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1482 event->property.type = GDK_PROPERTY_NOTIFY;
1483 event->property.window = window;
1484 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1485 event->property.time = xevent->xproperty.time;
1486 event->property.state = xevent->xproperty.state;
1493 case SelectionClear:
1495 g_message ("selection clear:\twindow: %ld",
1496 xevent->xproperty.window));
1498 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1500 event->selection.type = GDK_SELECTION_CLEAR;
1501 event->selection.window = window;
1502 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1503 event->selection.time = xevent->xselectionclear.time;
1510 case SelectionRequest:
1512 g_message ("selection request:\twindow: %ld",
1513 xevent->xproperty.window));
1515 event->selection.type = GDK_SELECTION_REQUEST;
1516 event->selection.window = window;
1517 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1518 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1519 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1520 event->selection.requestor = xevent->xselectionrequest.requestor;
1521 event->selection.time = xevent->xselectionrequest.time;
1525 case SelectionNotify:
1527 g_message ("selection notify:\twindow: %ld",
1528 xevent->xproperty.window));
1531 event->selection.type = GDK_SELECTION_NOTIFY;
1532 event->selection.window = window;
1533 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1534 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1535 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1536 event->selection.time = xevent->xselection.time;
1540 case ColormapNotify:
1542 g_message ("colormap notify:\twindow: %ld",
1543 xevent->xcolormap.window));
1545 /* Not currently handled */
1552 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1553 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1556 g_message ("client message:\twindow: %ld",
1557 xevent->xclient.window));
1559 tmp_list = display_x11->client_filters;
1562 GdkClientFilter *filter = tmp_list->data;
1563 if (filter->type == message_type)
1565 result = (*filter->function) (xevent, event, filter->data);
1569 tmp_list = tmp_list->next;
1574 case GDK_FILTER_REMOVE:
1577 case GDK_FILTER_TRANSLATE:
1580 case GDK_FILTER_CONTINUE:
1581 /* Send unknown ClientMessage's on to Gtk for it to use */
1582 if (window_private == NULL)
1588 event->client.type = GDK_CLIENT_EVENT;
1589 event->client.window = window;
1590 event->client.message_type = message_type;
1591 event->client.data_format = xevent->xclient.format;
1592 memcpy(&event->client.data, &xevent->xclient.data,
1593 sizeof(event->client.data));
1603 g_message ("mapping notify"));
1605 /* Let XLib know that there is a new keyboard mapping.
1607 XRefreshKeyboardMapping (&xevent->xmapping);
1608 ++display_x11->keymap_serial;
1614 if (xevent->type == display_x11->xkb_event_type)
1616 XkbEvent *xkb_event = (XkbEvent *)xevent;
1618 switch (xkb_event->any.xkb_type)
1621 ++display_x11->keymap_serial;
1626 case XkbStateNotify:
1627 _gdk_keymap_state_changed (display);
1634 /* something else - (e.g., a Xinput event) */
1636 if (window_private &&
1637 !GDK_WINDOW_DESTROYED (window_private) &&
1638 (window_private->extension_events != 0))
1639 return_val = _gdk_input_other_event(event, xevent, window);
1650 if (event->any.window)
1651 gdk_window_ref (event->any.window);
1652 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1653 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1654 (event->crossing.subwindow != NULL))
1655 gdk_window_ref (event->crossing.subwindow);
1659 /* Mark this event as having no resources to be freed */
1660 event->any.window = NULL;
1661 event->any.type = GDK_NOTHING;
1665 gdk_window_unref (window);
1670 static GdkFilterReturn
1671 gdk_wm_protocols_filter (GdkXEvent *xev,
1675 XEvent *xevent = (XEvent *)xev;
1676 GdkWindow *win = event->any.window;
1677 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1679 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1681 /* The delete window request specifies a window
1682 * to delete. We don't actually destroy the
1683 * window because "it is only a request". (The
1684 * window might contain vital data that the
1685 * program does not want destroyed). Instead
1686 * the event is passed along to the program,
1687 * which should then destroy the window.
1690 g_message ("delete window:\t\twindow: %ld",
1691 xevent->xclient.window));
1693 event->any.type = GDK_DELETE;
1695 return GDK_FILTER_TRANSLATE;
1697 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1699 GdkWindow *win = event->any.window;
1700 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1702 /* There is no way of knowing reliably whether we are viewable so we need
1703 * to trap errors so we don't cause a BadMatch.
1705 gdk_error_trap_push ();
1706 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1709 xevent->xclient.data.l[1]);
1710 XSync (GDK_WINDOW_XDISPLAY (win), False);
1711 gdk_error_trap_pop ();
1713 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"))
1715 XEvent xev = *xevent;
1717 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1718 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1721 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1724 return GDK_FILTER_REMOVE;
1728 _gdk_events_queue (GdkDisplay *display)
1733 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1735 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1737 XNextEvent (xdisplay, &xevent);
1739 switch (xevent.type)
1745 if (XFilterEvent (&xevent, None))
1749 event = _gdk_event_new ();
1751 event->any.type = GDK_NOTHING;
1752 event->any.window = NULL;
1753 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1755 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1757 node = _gdk_event_queue_append (display, event);
1759 if (gdk_event_translate (display, event, &xevent, FALSE))
1761 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1765 _gdk_event_queue_remove_link (display, node);
1766 g_list_free_1 (node);
1767 gdk_event_free (event);
1773 gdk_event_prepare (GSource *source,
1776 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1779 GDK_THREADS_ENTER ();
1782 retval = (_gdk_event_queue_find_first (display) != NULL ||
1783 gdk_check_xpending (display));
1785 GDK_THREADS_LEAVE ();
1791 gdk_event_check (GSource *source)
1793 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
1796 GDK_THREADS_ENTER ();
1798 if (display_source->event_poll_fd.revents & G_IO_IN)
1799 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
1800 gdk_check_xpending (display_source->display));
1804 GDK_THREADS_LEAVE ();
1810 gdk_event_dispatch (GSource *source,
1811 GSourceFunc callback,
1814 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1817 GDK_THREADS_ENTER ();
1819 _gdk_events_queue (display);
1820 event = _gdk_event_unqueue (display);
1824 if (_gdk_event_func)
1825 (*_gdk_event_func) (event, _gdk_event_data);
1827 gdk_event_free (event);
1830 GDK_THREADS_LEAVE ();
1836 * gdk_event_send_client_message_for_display :
1837 * @display : the #GdkDisplay for the window where the message is to be sent.
1838 * @event : the #GdkEvent to send, which should be a #GdkEventClient.
1839 * @xid : the X window to send the X ClientMessage event to.
1841 * Sends an X ClientMessage event to a given window.
1843 * This could be used for communicating between different applications,
1844 * though the amount of data is limited to 20 bytes.
1846 * Returns : non-zero on success.
1849 gdk_event_send_client_message_for_display (GdkDisplay *display,
1855 g_return_val_if_fail(event != NULL, FALSE);
1857 /* Set up our event to send, with the exception of its target window */
1858 sev.xclient.type = ClientMessage;
1859 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
1860 sev.xclient.format = event->client.data_format;
1861 sev.xclient.window = xid;
1862 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1863 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
1865 return _gdk_send_xevent (display, xid, False, NoEventMask, &sev);
1870 /* Sends a ClientMessage to all toplevel client windows */
1872 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
1879 unsigned long nitems, after;
1880 unsigned char *data;
1881 Window *ret_children, ret_root, ret_parent;
1882 unsigned int ret_nchildren;
1883 gboolean send = FALSE;
1884 gboolean found = FALSE;
1885 gboolean result = FALSE;
1888 gdk_error_trap_push ();
1890 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
1891 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1892 0, 0, False, AnyPropertyType,
1893 &type, &format, &nitems, &after, &data) != Success)
1903 /* OK, we're all set, now let's find some windows to send this to */
1904 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
1905 &ret_root, &ret_parent,
1906 &ret_children, &ret_nchildren))
1909 for(i = 0; i < ret_nchildren; i++)
1910 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
1913 XFree (ret_children);
1916 if (send || (!found && (level == 1)))
1918 xev->xclient.window = xid;
1919 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
1922 result = send || found;
1925 gdk_error_trap_pop ();
1931 * gdk_screen_broadcast_client_message:
1932 * @screen : the #GdkScreen where the event will be broadcasted.
1933 * @event : the #GdkEvent.
1935 * Sends an X ClientMessage event to all toplevel windows on @screen.
1937 * Toplevel windows are determined by checking for the WM_STATE property,
1938 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
1939 * If no windows are found with the WM_STATE property set, the message is
1940 * sent to all children of the root window.
1944 gdk_screen_broadcast_client_message (GdkScreen *screen,
1948 GdkWindow *root_window;
1950 g_return_if_fail (event != NULL);
1952 root_window = gdk_screen_get_root_window (screen);
1954 /* Set up our event to send, with the exception of its target window */
1955 sev.xclient.type = ClientMessage;
1956 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
1957 sev.xclient.format = event->client.data_format;
1958 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1959 sev.xclient.message_type =
1960 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
1961 event->client.message_type);
1963 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
1965 GDK_WINDOW_XID (root_window),
1970 *--------------------------------------------------------------
1973 * Flushes the Xlib output buffer and then waits
1974 * until all requests have been received and processed
1975 * by the X server. The only real use for this function
1976 * is in dealing with XShm.
1984 *--------------------------------------------------------------
1990 GSList *tmp_list = _gdk_displays;
1994 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
1995 tmp_list = tmp_list->next;
2000 timestamp_predicate (Display *display,
2004 Window xwindow = GPOINTER_TO_UINT (arg);
2005 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2007 if (xevent->type == PropertyNotify &&
2008 xevent->xproperty.window == xwindow &&
2009 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display
2010 (gdk_display, "GDK_TIMESTAMP_PROP"))
2017 * gdk_x11_get_server_time:
2018 * @window: a #GdkWindow, used for communication with the server.
2019 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2020 * events mask or a hang will result.
2022 * Routine to get the current X server time stamp.
2024 * Return value: the time stamp.
2027 gdk_x11_get_server_time (GdkWindow *window)
2033 Atom timestamp_prop_atom;
2035 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2036 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2038 xdisplay = GDK_WINDOW_XDISPLAY (window);
2039 xwindow = GDK_WINDOW_XWINDOW (window);
2040 timestamp_prop_atom =
2041 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2042 "GDK_TIMESTAMP_PROP");
2044 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2045 timestamp_prop_atom,
2046 8, PropModeReplace, &c, 1);
2048 XIfEvent (xdisplay, &xevent,
2049 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2051 return xevent.xproperty.time;
2054 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2056 struct _NetWmSupportedAtoms
2063 * gdk_x11_screen_supports_net_wm_hint:
2064 * @screen : the relevant #GdkScreen.
2065 * @property: a property atom.
2067 * This function is specific to the X11 backend of GDK, and indicates
2068 * whether the window manager supports a certain hint from the
2069 * Extended Window Manager Hints Specification. You can find this
2070 * specification on http://www.freedesktop.org.
2072 * When using this function, keep in mind that the window manager
2073 * can change over time; so you shouldn't use this function in
2074 * a way that impacts persistent application state. A common bug
2075 * is that your application can start up before the window manager
2076 * does when the user logs in, and before the window manager starts
2077 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2079 * Return value: %TRUE if the window manager supports @property
2082 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2091 GdkScreenX11 *screen_x11;
2092 NetWmSupportedAtoms *supported_atoms;
2093 GdkDisplay *display;
2095 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2097 screen_x11 = GDK_SCREEN_X11 (screen);
2098 display = screen_x11->display;
2100 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2101 if (!supported_atoms)
2103 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2104 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2107 if (screen_x11->wmspec_check_window != None)
2109 if (supported_atoms->atoms == NULL)
2113 while (i < supported_atoms->n_atoms)
2115 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2124 if (supported_atoms->atoms)
2125 XFree (supported_atoms->atoms);
2127 supported_atoms->atoms = NULL;
2128 supported_atoms->n_atoms = 0;
2130 /* This function is very slow on every call if you are not running a
2131 * spec-supporting WM. For now not optimized, because it isn't in
2132 * any critical code paths, but if you used it somewhere that had to
2133 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2134 * Probably at that point the function should be changed to query
2135 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2138 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2139 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2140 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2141 &nitems, &bytes_after, (guchar **) & xwindow);
2143 if (type != XA_WINDOW)
2146 gdk_error_trap_push ();
2148 /* Find out if this WM goes away, so we can reset everything. */
2149 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2151 gdk_display_sync (screen_x11->display);
2153 if (gdk_error_trap_pop ())
2159 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2160 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2161 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2162 &supported_atoms->n_atoms, &bytes_after,
2163 (guchar **)&supported_atoms->atoms);
2165 if (type != XA_ATOM)
2168 screen_x11->wmspec_check_window = *xwindow;
2171 /* since wmspec_check_window != None this isn't infinite. ;-) */
2172 return gdk_x11_screen_supports_net_wm_hint (screen, property);
2176 * gdk_net_wm_supports:
2177 * @property: a property atom.
2179 * This function is specific to the X11 backend of GDK, and indicates
2180 * whether the window manager for the default screen supports a certain
2181 * hint from the Extended Window Manager Hints Specification. See
2182 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2184 * Return value: %TRUE if the window manager supports @property
2187 gdk_net_wm_supports (GdkAtom property)
2189 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2194 const char *xsettings_name;
2195 const char *gdk_name;
2196 } settings_map[] = {
2197 { "Net/DoubleClickTime", "gtk-double-click-time" },
2198 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2199 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2200 { "Gtk/ColorPalette", "gtk-color-palette" },
2201 { "Gtk/FontName", "gtk-font-name" },
2202 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2203 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2204 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2205 { "Net/CursorBlink", "gtk-cursor-blink" },
2206 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2207 { "Net/ThemeName", "gtk-theme-name" }
2211 gdk_xsettings_notify_cb (const char *name,
2212 XSettingsAction action,
2213 XSettingsSetting *setting,
2217 GdkScreen *screen = data;
2220 new_event.type = GDK_SETTING;
2221 new_event.setting.window = gdk_screen_get_root_window (screen);
2222 new_event.setting.send_event = FALSE;
2223 new_event.setting.name = NULL;
2225 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2226 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2228 new_event.setting.name = (char *)settings_map[i].gdk_name;
2232 if (!new_event.setting.name)
2237 case XSETTINGS_ACTION_NEW:
2238 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2240 case XSETTINGS_ACTION_CHANGED:
2241 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2243 case XSETTINGS_ACTION_DELETED:
2244 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2248 gdk_event_put (&new_event);
2252 check_transform (const gchar *xsettings_name,
2256 if (!g_value_type_transformable (src_type, dest_type))
2258 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2260 g_type_name (src_type),
2261 g_type_name (dest_type));
2269 * gdk_screen_get_setting:
2270 * @screen: the #GdkScreen where the setting is located
2271 * @name: the name of the setting
2272 * @value: location to store the value of the setting
2274 * Retrieves a desktop-wide setting such as double-click time
2275 * for the #GdkScreen @screen.
2277 * FIXME needs a list of valid settings here, or a link to
2280 * Returns : %TRUE if the setting existed and a value was stored
2281 * in @value, %FALSE otherwise.
2284 gdk_screen_get_setting (GdkScreen *screen,
2289 const char *xsettings_name = NULL;
2290 XSettingsResult result;
2291 XSettingsSetting *setting;
2292 GdkScreenX11 *screen_x11;
2293 gboolean success = FALSE;
2295 GValue tmp_val = { 0, };
2297 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2299 screen_x11 = GDK_SCREEN_X11 (screen);
2301 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2302 if (strcmp (settings_map[i].gdk_name, name) == 0)
2304 xsettings_name = settings_map[i].xsettings_name;
2308 if (!xsettings_name)
2311 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2312 xsettings_name, &setting);
2313 if (result != XSETTINGS_SUCCESS)
2316 switch (setting->type)
2318 case XSETTINGS_TYPE_INT:
2319 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2321 g_value_init (&tmp_val, G_TYPE_INT);
2322 g_value_set_int (&tmp_val, setting->data.v_int);
2323 g_value_transform (&tmp_val, value);
2328 case XSETTINGS_TYPE_STRING:
2329 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2331 g_value_init (&tmp_val, G_TYPE_STRING);
2332 g_value_set_string (&tmp_val, setting->data.v_string);
2333 g_value_transform (&tmp_val, value);
2338 case XSETTINGS_TYPE_COLOR:
2339 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2343 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2346 color.red = setting->data.v_color.red;
2347 color.green = setting->data.v_color.green;
2348 color.blue = setting->data.v_color.blue;
2350 g_value_set_boxed (&tmp_val, &color);
2352 g_value_transform (&tmp_val, value);
2359 g_value_unset (&tmp_val);
2361 xsettings_setting_free (setting);
2366 static GdkFilterReturn
2367 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2371 GdkScreenX11 *screen = data;
2373 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2374 return GDK_FILTER_REMOVE;
2376 return GDK_FILTER_CONTINUE;
2380 gdk_xsettings_watch_cb (Window window,
2386 GdkScreen *screen = cb_data;
2387 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
2389 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2394 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2396 g_object_ref (gdkwin);
2398 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2403 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2404 g_object_unref (gdkwin);