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 _GdkDisplaySource GdkDisplaySource;
56 #define DOUBLE_CLICK_TIME 250
57 #define TRIPLE_CLICK_TIME 500
58 #define DOUBLE_CLICK_DIST 5
59 #define TRIPLE_CLICK_DIST 5
63 GdkInputFunction function;
64 GdkInputCondition condition;
65 GdkDestroyNotify notify;
69 struct _GdkDisplaySource
74 GPollFD event_poll_fd;
78 * Private function declarations
81 static gint gdk_event_apply_filters (XEvent *xevent,
84 static gboolean gdk_event_translate (GdkDisplay *display,
87 gboolean return_exposes);
89 static gboolean gdk_event_prepare (GSource *source,
91 static gboolean gdk_event_check (GSource *source);
92 static gboolean gdk_event_dispatch (GSource *source,
96 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
100 static GSource *gdk_display_source_new (GdkDisplay *display);
101 static gboolean gdk_check_xpending (GdkDisplay *display);
103 static void gdk_xsettings_watch_cb (Window window,
107 static void gdk_xsettings_notify_cb (const char *name,
108 XSettingsAction action,
109 XSettingsSetting *setting,
112 /* Private variable declarations
115 static GList *display_sources;
117 static GSourceFuncs event_funcs = {
125 gdk_display_source_new (GdkDisplay *display)
127 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
128 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
130 display_source->display = display;
136 gdk_check_xpending (GdkDisplay *display)
138 return XPending (GDK_DISPLAY_XDISPLAY (display));
141 /*********************************************
142 * Functions for maintaining the event queue *
143 *********************************************/
146 _gdk_x11_events_init_screen (GdkScreen *screen)
148 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
150 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
151 screen_x11->screen_num,
152 gdk_xsettings_notify_cb,
153 gdk_xsettings_watch_cb,
158 _gdk_x11_events_uninit_screen (GdkScreen *screen)
160 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
162 xsettings_client_destroy (screen_x11->xsettings_client);
163 screen_x11->xsettings_client = NULL;
167 _gdk_events_init (GdkDisplay *display)
170 GdkDisplaySource *display_source;
171 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
173 int connection_number = ConnectionNumber (display_x11->xdisplay);
174 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
177 source = display_x11->event_source = gdk_display_source_new (display);
178 display_source = (GdkDisplaySource*) source;
179 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
181 display_source->event_poll_fd.fd = connection_number;
182 display_source->event_poll_fd.events = G_IO_IN;
184 g_source_add_poll (source, &display_source->event_poll_fd);
185 g_source_set_can_recurse (source, TRUE);
186 g_source_attach (source, NULL);
188 display_sources = g_list_prepend (display_sources,display_source);
190 gdk_display_add_client_message_filter (
192 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
193 gdk_wm_protocols_filter,
199 * gdk_events_pending:
201 * Checks if any events are ready to be processed for any display.
203 * Return value: %TRUE if any events are pending.
206 gdk_events_pending (void)
210 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
212 GdkDisplaySource *tmp_source = tmp_list->data;
213 GdkDisplay *display = tmp_source->display;
215 if (_gdk_event_queue_find_first (display))
219 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
221 GdkDisplaySource *tmp_source = tmp_list->data;
222 GdkDisplay *display = tmp_source->display;
224 if (gdk_check_xpending (display))
232 graphics_expose_predicate (Display *display,
236 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
237 (xevent->xany.type == GraphicsExpose ||
238 xevent->xany.type == NoExpose))
245 * gdk_event_get_graphics_expose:
246 * @window: the #GdkWindow to wait for the events for.
248 * Waits for a GraphicsExpose or NoExpose event from the X server.
249 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
250 * GraphicsExpose events are handled before the widget is scrolled.
252 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
253 * NoExpose event was received.
256 gdk_event_get_graphics_expose (GdkWindow *window)
261 g_return_val_if_fail (window != NULL, NULL);
263 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
264 graphics_expose_predicate, (XPointer) window);
266 if (xevent.xany.type == GraphicsExpose)
268 event = _gdk_event_new ();
270 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
274 gdk_event_free (event);
281 gdk_event_apply_filters (XEvent *xevent,
286 GdkFilterReturn result;
292 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
294 tmp_list = tmp_list->next;
295 result = filter->function (xevent, event, filter->data);
296 if (result != GDK_FILTER_CONTINUE)
300 return GDK_FILTER_CONTINUE;
304 * gdk_display_add_client_message_filter:
305 * @display: a #GdkDisplay for which this message filter applies
306 * @message_type: the type of ClientMessage events to receive.
307 * This will be checked against the @message_type field
308 * of the XClientMessage event struct.
309 * @func: the function to call to process the event.
310 * @data: user data to pass to @func.
312 * Adds a filter to be called when X ClientMessage events are received.
316 gdk_display_add_client_message_filter (GdkDisplay *display,
317 GdkAtom message_type,
321 GdkClientFilter *filter;
322 g_return_if_fail (GDK_IS_DISPLAY (display));
323 filter = g_new (GdkClientFilter, 1);
325 filter->type = message_type;
326 filter->function = func;
329 GDK_DISPLAY_X11(display)->client_filters =
330 g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
335 * gdk_add_client_message_filter:
336 * @message_type: the type of ClientMessage events to receive. This will be
337 * checked against the <structfield>message_type</structfield> field of the
338 * XClientMessage event struct.
339 * @func: the function to call to process the event.
340 * @data: user data to pass to @func.
342 * Adds a filter to the default display to be called when X ClientMessage events
343 * are received. See gdk_display_add_client_message_filter().
346 gdk_add_client_message_filter (GdkAtom message_type,
350 gdk_display_add_client_message_filter (gdk_display_get_default (),
351 message_type, func, data);
355 gdk_check_wm_state_changed (GdkWindow *window)
363 gboolean found_sticky, found_maxvert, found_maxhorz;
364 GdkWindowState old_state;
365 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
367 if (GDK_WINDOW_DESTROYED (window) ||
368 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
371 found_sticky = FALSE;
372 found_maxvert = FALSE;
373 found_maxhorz = FALSE;
375 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
376 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
377 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
378 &bytes_after, (guchar **)&atoms);
382 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
383 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
384 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
389 if (atoms[i] == sticky_atom)
391 else if (atoms[i] == maxvert_atom)
392 found_maxvert = TRUE;
393 else if (atoms[i] == maxhorz_atom)
394 found_maxhorz = TRUE;
402 /* For found_sticky to remain TRUE, we have to also be on desktop
410 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window),
411 GDK_WINDOW_XID (window),
412 gdk_x11_get_xatom_by_name_for_display
413 (display, "_NET_WM_DESKTOP"),
414 0, G_MAXLONG, False, XA_CARDINAL, &type,
416 &bytes_after, (guchar **)&desktop);
420 if (*desktop != 0xFFFFFFFF)
421 found_sticky = FALSE;
426 old_state = gdk_window_get_state (window);
428 if (old_state & GDK_WINDOW_STATE_STICKY)
431 gdk_synthesize_window_state (window,
432 GDK_WINDOW_STATE_STICKY,
438 gdk_synthesize_window_state (window,
440 GDK_WINDOW_STATE_STICKY);
443 /* Our "maximized" means both vertical and horizontal; if only one,
444 * we don't expose that via GDK
446 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
448 if (!(found_maxvert && found_maxhorz))
449 gdk_synthesize_window_state (window,
450 GDK_WINDOW_STATE_MAXIMIZED,
455 if (found_maxvert && found_maxhorz)
456 gdk_synthesize_window_state (window,
458 GDK_WINDOW_STATE_MAXIMIZED);
462 #define HAS_FOCUS(window_impl) \
463 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
466 generate_focus_event (GdkWindow *window,
471 event.type = GDK_FOCUS_CHANGE;
472 event.focus_change.window = window;
473 event.focus_change.send_event = FALSE;
474 event.focus_change.in = in;
476 gdk_event_put (&event);
480 gdk_event_translate (GdkDisplay *display,
483 gboolean return_exposes)
487 GdkWindowObject *window_private;
488 GdkWindowImplX11 *window_impl = NULL;
489 static XComposeStatus compose;
494 gint xoffset, yoffset;
495 GdkScreen *screen = NULL;
496 GdkScreenX11 *screen_x11 = NULL;
497 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
501 /* init these, since the done: block uses them */
503 window_private = NULL;
504 event->any.window = NULL;
506 if (_gdk_default_filters)
508 /* Apply global filters */
509 GdkFilterReturn result;
510 result = gdk_event_apply_filters (xevent, event,
511 _gdk_default_filters);
513 if (result != GDK_FILTER_CONTINUE)
515 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
520 /* We handle events with window=None
521 * specially - they are generated by XFree86's XInput under
522 * some circumstances. This handling for obvious reasons
523 * goes before we bother to lookup the event window.
526 if (xevent->xany.window == None)
528 return_val = _gdk_input_window_none_event (event, xevent);
530 if (return_val >= 0) /* was handled */
536 /* Find the GdkWindow that this event occurred in. */
538 window = gdk_window_lookup_for_display (display, xevent->xany.window);
539 window_private = (GdkWindowObject *) window;
543 screen = GDK_WINDOW_SCREEN (window);
544 screen_x11 = GDK_SCREEN_X11 (screen);
549 /* Window may be a pixmap, so check its type.
550 * (This check is probably too expensive unless
551 * GLib short-circuits an exact type match,
552 * which has been proposed)
554 if (GDK_IS_WINDOW (window))
556 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
558 if (xevent->xany.window != GDK_WINDOW_XID (window))
560 g_assert (xevent->xany.window == window_impl->focus_window);
562 switch (xevent->type)
566 xevent->xany.window = GDK_WINDOW_XID (window);
574 g_object_ref (G_OBJECT (window));
577 event->any.window = window;
578 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
580 if (window_private && GDK_WINDOW_DESTROYED (window))
582 if (xevent->type != DestroyNotify)
588 else if (window_private)
590 /* Apply per-window filters */
591 GdkFilterReturn result;
592 result = gdk_event_apply_filters (xevent, event,
593 window_private->filters);
595 if (result != GDK_FILTER_CONTINUE)
597 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
602 if (screen_x11 && screen_x11->wmspec_check_window != None &&
603 xevent->xany.window == screen_x11->wmspec_check_window)
605 if (xevent->type == DestroyNotify)
606 screen_x11->wmspec_check_window = None;
608 /* Eat events on this window unless someone had wrapped
609 * it as a foreign window
619 (xevent->xany.type == MotionNotify ||
620 xevent->xany.type == ButtonRelease))
622 if (_gdk_moveresize_handle_event (xevent))
629 /* We do a "manual" conversion of the XEvent to a
630 * GdkEvent. The structures are mostly the same so
631 * the conversion is fairly straightforward. We also
632 * optionally print debugging info regarding events
640 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
648 switch (xevent->type)
651 if (window_private == NULL)
657 /* Lookup the string corresponding to the given keysym.
660 charcount = XLookupString (&xevent->xkey, buf, 16,
662 event->key.keyval = keysym;
663 event->key.hardware_keycode = xevent->xkey.keycode;
665 if (charcount > 0 && buf[charcount-1] == '\0')
668 buf[charcount] = '\0';
670 #ifdef G_ENABLE_DEBUG
671 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
673 g_message ("key press:\twindow: %ld key: %12s %d",
675 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
678 g_message ("\t\tlength: %4d string: \"%s\"",
681 #endif /* G_ENABLE_DEBUG */
683 event->key.type = GDK_KEY_PRESS;
684 event->key.window = window;
685 event->key.time = xevent->xkey.time;
686 event->key.state = (GdkModifierType) xevent->xkey.state;
687 event->key.string = g_strdup (buf);
688 event->key.length = charcount;
690 /* bits 13 and 14 in the "state" field are the keyboard group */
691 #define KEYBOARD_GROUP_SHIFT 13
692 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
694 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
699 if (window_private == NULL)
705 /* Lookup the string corresponding to the given keysym.
708 /* Emulate detectable auto-repeat by checking to see
709 * if the next event is a key press with the same
710 * keycode and timestamp, and if so, ignoring the event.
713 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
717 XPeekEvent (xevent->xkey.display, &next_event);
719 if (next_event.type == KeyPress &&
720 next_event.xkey.keycode == xevent->xkey.keycode &&
721 next_event.xkey.time == xevent->xkey.time)
725 keysym = GDK_VoidSymbol;
726 charcount = XLookupString (&xevent->xkey, buf, 16,
728 event->key.keyval = keysym;
729 event->key.hardware_keycode = xevent->xkey.keycode;
732 g_message ("key release:\t\twindow: %ld key: %12s %d",
734 XKeysymToString (event->key.keyval),
737 event->key.type = GDK_KEY_RELEASE;
738 event->key.window = window;
739 event->key.time = xevent->xkey.time;
740 event->key.state = (GdkModifierType) xevent->xkey.state;
741 event->key.length = 0;
742 event->key.string = NULL;
744 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
750 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
751 xevent->xbutton.window,
752 xevent->xbutton.x, xevent->xbutton.y,
753 xevent->xbutton.button));
755 if (window_private == NULL ||
756 ((window_private->extension_events != 0) &&
757 display_x11->input_ignore_core))
763 /* If we get a ButtonPress event where the button is 4 or 5,
764 it's a Scroll event */
765 switch (xevent->xbutton.button)
771 event->scroll.type = GDK_SCROLL;
773 if (xevent->xbutton.button == 4)
774 event->scroll.direction = GDK_SCROLL_UP;
775 else if (xevent->xbutton.button == 5)
776 event->scroll.direction = GDK_SCROLL_DOWN;
777 else if (xevent->xbutton.button == 6)
778 event->scroll.direction = GDK_SCROLL_LEFT;
780 event->scroll.direction = GDK_SCROLL_RIGHT;
782 event->scroll.window = window;
783 event->scroll.time = xevent->xbutton.time;
784 event->scroll.x = xevent->xbutton.x + xoffset;
785 event->scroll.y = xevent->xbutton.y + yoffset;
786 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
787 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
788 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
789 event->scroll.device = display->core_pointer;
793 event->button.type = GDK_BUTTON_PRESS;
794 event->button.window = window;
795 event->button.time = xevent->xbutton.time;
796 event->button.x = xevent->xbutton.x + xoffset;
797 event->button.y = xevent->xbutton.y + yoffset;
798 event->button.x_root = (gfloat)xevent->xbutton.x_root;
799 event->button.y_root = (gfloat)xevent->xbutton.y_root;
800 event->button.axes = NULL;
801 event->button.state = (GdkModifierType) xevent->xbutton.state;
802 event->button.button = xevent->xbutton.button;
803 event->button.device = display->core_pointer;
805 _gdk_event_button_generate (display, event);
813 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
814 xevent->xbutton.window,
815 xevent->xbutton.x, xevent->xbutton.y,
816 xevent->xbutton.button));
818 if (window_private == NULL ||
819 ((window_private->extension_events != 0) &&
820 display_x11->input_ignore_core))
826 /* We treat button presses as scroll wheel events, so ignore the release */
827 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
828 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
834 event->button.type = GDK_BUTTON_RELEASE;
835 event->button.window = window;
836 event->button.time = xevent->xbutton.time;
837 event->button.x = xevent->xbutton.x + xoffset;
838 event->button.y = xevent->xbutton.y + yoffset;
839 event->button.x_root = (gfloat)xevent->xbutton.x_root;
840 event->button.y_root = (gfloat)xevent->xbutton.y_root;
841 event->button.axes = NULL;
842 event->button.state = (GdkModifierType) xevent->xbutton.state;
843 event->button.button = xevent->xbutton.button;
844 event->button.device = display->core_pointer;
850 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
851 xevent->xmotion.window,
852 xevent->xmotion.x, xevent->xmotion.y,
853 (xevent->xmotion.is_hint) ? "true" : "false"));
855 if (window_private == NULL ||
856 ((window_private->extension_events != 0) &&
857 display_x11->input_ignore_core))
863 event->motion.type = GDK_MOTION_NOTIFY;
864 event->motion.window = window;
865 event->motion.time = xevent->xmotion.time;
866 event->motion.x = xevent->xmotion.x + xoffset;
867 event->motion.y = xevent->xmotion.y + yoffset;
868 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
869 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
870 event->motion.axes = NULL;
871 event->motion.state = (GdkModifierType) xevent->xmotion.state;
872 event->motion.is_hint = xevent->xmotion.is_hint;
873 event->motion.device = display->core_pointer;
879 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
880 xevent->xcrossing.window,
881 xevent->xcrossing.detail,
882 xevent->xcrossing.subwindow));
884 if (window_private == NULL)
890 /* Handle focusing (in the case where no window manager is running */
892 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
893 xevent->xcrossing.detail != NotifyInferior &&
894 xevent->xcrossing.focus && !window_impl->has_focus)
896 gboolean had_focus = HAS_FOCUS (window_impl);
898 window_impl->has_pointer_focus = TRUE;
900 if (HAS_FOCUS (window_impl) != had_focus)
901 generate_focus_event (window, TRUE);
904 /* Tell XInput stuff about it if appropriate */
905 if (window_private &&
906 !GDK_WINDOW_DESTROYED (window) &&
907 window_private->extension_events != 0)
908 _gdk_input_enter_event (&xevent->xcrossing, window);
910 event->crossing.type = GDK_ENTER_NOTIFY;
911 event->crossing.window = window;
913 /* If the subwindow field of the XEvent is non-NULL, then
914 * lookup the corresponding GdkWindow.
916 if (xevent->xcrossing.subwindow != None)
917 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
919 event->crossing.subwindow = NULL;
921 event->crossing.time = xevent->xcrossing.time;
922 event->crossing.x = xevent->xcrossing.x + xoffset;
923 event->crossing.y = xevent->xcrossing.y + yoffset;
924 event->crossing.x_root = xevent->xcrossing.x_root;
925 event->crossing.y_root = xevent->xcrossing.y_root;
927 /* Translate the crossing mode into Gdk terms.
929 switch (xevent->xcrossing.mode)
932 event->crossing.mode = GDK_CROSSING_NORMAL;
935 event->crossing.mode = GDK_CROSSING_GRAB;
938 event->crossing.mode = GDK_CROSSING_UNGRAB;
942 /* Translate the crossing detail into Gdk terms.
944 switch (xevent->xcrossing.detail)
947 event->crossing.detail = GDK_NOTIFY_INFERIOR;
950 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
953 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
955 case NotifyNonlinear:
956 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
958 case NotifyNonlinearVirtual:
959 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
962 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
966 event->crossing.focus = xevent->xcrossing.focus;
967 event->crossing.state = xevent->xcrossing.state;
973 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
974 xevent->xcrossing.window,
975 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
977 if (window_private == NULL)
983 /* Handle focusing (in the case where no window manager is running */
985 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
986 xevent->xcrossing.detail != NotifyInferior &&
987 xevent->xcrossing.focus && !window_impl->has_focus)
989 gboolean had_focus = HAS_FOCUS (window_impl);
991 window_impl->has_pointer_focus = FALSE;
993 if (HAS_FOCUS (window_impl) != had_focus)
994 generate_focus_event (window, FALSE);
997 event->crossing.type = GDK_LEAVE_NOTIFY;
998 event->crossing.window = window;
1000 /* If the subwindow field of the XEvent is non-NULL, then
1001 * lookup the corresponding GdkWindow.
1003 if (xevent->xcrossing.subwindow != None)
1004 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1006 event->crossing.subwindow = NULL;
1008 event->crossing.time = xevent->xcrossing.time;
1009 event->crossing.x = xevent->xcrossing.x + xoffset;
1010 event->crossing.y = xevent->xcrossing.y + yoffset;
1011 event->crossing.x_root = xevent->xcrossing.x_root;
1012 event->crossing.y_root = xevent->xcrossing.y_root;
1014 /* Translate the crossing mode into Gdk terms.
1016 switch (xevent->xcrossing.mode)
1019 event->crossing.mode = GDK_CROSSING_NORMAL;
1022 event->crossing.mode = GDK_CROSSING_GRAB;
1025 event->crossing.mode = GDK_CROSSING_UNGRAB;
1029 /* Translate the crossing detail into Gdk terms.
1031 switch (xevent->xcrossing.detail)
1033 case NotifyInferior:
1034 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1036 case NotifyAncestor:
1037 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1040 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1042 case NotifyNonlinear:
1043 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1045 case NotifyNonlinearVirtual:
1046 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1049 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1053 event->crossing.focus = xevent->xcrossing.focus;
1054 event->crossing.state = xevent->xcrossing.state;
1058 /* We only care about focus events that indicate that _this_
1059 * window (not a ancestor or child) got or lost the focus
1063 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
1065 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1067 gboolean had_focus = HAS_FOCUS (window_impl);
1069 switch (xevent->xfocus.detail)
1071 case NotifyAncestor:
1072 case NotifyNonlinear:
1074 case NotifyNonlinearVirtual:
1075 window_impl->has_focus = TRUE;
1078 window_impl->has_pointer_focus = TRUE;
1080 case NotifyInferior:
1081 case NotifyPointerRoot:
1082 case NotifyDetailNone:
1086 if (HAS_FOCUS (window_impl) != had_focus)
1087 generate_focus_event (window, TRUE);
1092 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1094 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1096 gboolean had_focus = HAS_FOCUS (window_impl);
1098 switch (xevent->xfocus.detail)
1100 case NotifyAncestor:
1101 case NotifyNonlinear:
1103 case NotifyNonlinearVirtual:
1104 window_impl->has_focus = FALSE;
1107 window_impl->has_pointer_focus = FALSE;
1109 case NotifyInferior:
1110 case NotifyPointerRoot:
1111 case NotifyDetailNone:
1115 if (HAS_FOCUS (window_impl) != had_focus)
1116 generate_focus_event (window, FALSE);
1121 /* gdk_keyboard_grab() causes following events. These events confuse
1122 * the XIM focus, so ignore them.
1124 if (xevent->xfocus.mode == NotifyGrab ||
1125 xevent->xfocus.mode == NotifyUngrab)
1131 g_message ("keymap notify"));
1133 /* Not currently handled */
1139 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1140 xevent->xexpose.window, xevent->xexpose.count,
1141 xevent->xexpose.x, xevent->xexpose.y,
1142 xevent->xexpose.width, xevent->xexpose.height,
1143 event->any.send_event ? " (send)" : ""));
1145 if (window_private == NULL)
1152 GdkRectangle expose_rect;
1154 expose_rect.x = xevent->xexpose.x + xoffset;
1155 expose_rect.y = xevent->xexpose.y + yoffset;
1156 expose_rect.width = xevent->xexpose.width;
1157 expose_rect.height = xevent->xexpose.height;
1161 event->expose.type = GDK_EXPOSE;
1162 event->expose.area = expose_rect;
1163 event->expose.region = gdk_region_rectangle (&expose_rect);
1164 event->expose.window = window;
1165 event->expose.count = xevent->xexpose.count;
1171 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1180 case GraphicsExpose:
1182 GdkRectangle expose_rect;
1185 g_message ("graphics expose:\tdrawable: %ld",
1186 xevent->xgraphicsexpose.drawable));
1188 if (window_private == NULL)
1194 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1195 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1196 expose_rect.width = xevent->xgraphicsexpose.width;
1197 expose_rect.height = xevent->xgraphicsexpose.height;
1201 event->expose.type = GDK_EXPOSE;
1202 event->expose.area = expose_rect;
1203 event->expose.region = gdk_region_rectangle (&expose_rect);
1204 event->expose.window = window;
1205 event->expose.count = xevent->xgraphicsexpose.count;
1211 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1221 g_message ("no expose:\t\tdrawable: %ld",
1222 xevent->xnoexpose.drawable));
1224 event->no_expose.type = GDK_NO_EXPOSE;
1225 event->no_expose.window = window;
1229 case VisibilityNotify:
1230 #ifdef G_ENABLE_DEBUG
1231 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1232 switch (xevent->xvisibility.state)
1234 case VisibilityFullyObscured:
1235 g_message ("visibility notify:\twindow: %ld none",
1236 xevent->xvisibility.window);
1238 case VisibilityPartiallyObscured:
1239 g_message ("visibility notify:\twindow: %ld partial",
1240 xevent->xvisibility.window);
1242 case VisibilityUnobscured:
1243 g_message ("visibility notify:\twindow: %ld full",
1244 xevent->xvisibility.window);
1247 #endif /* G_ENABLE_DEBUG */
1249 if (window_private == NULL)
1255 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1256 event->visibility.window = window;
1258 switch (xevent->xvisibility.state)
1260 case VisibilityFullyObscured:
1261 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1264 case VisibilityPartiallyObscured:
1265 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1268 case VisibilityUnobscured:
1269 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1277 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1278 xevent->xcreatewindow.window,
1279 xevent->xcreatewindow.x,
1280 xevent->xcreatewindow.y,
1281 xevent->xcreatewindow.width,
1282 xevent->xcreatewindow.height,
1283 xevent->xcreatewindow.border_width,
1284 xevent->xcreatewindow.parent,
1285 xevent->xcreatewindow.override_redirect));
1286 /* not really handled */
1291 g_message ("destroy notify:\twindow: %ld",
1292 xevent->xdestroywindow.window));
1294 /* Ignore DestroyNotify from SubstructureNotifyMask */
1295 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1297 event->any.type = GDK_DESTROY;
1298 event->any.window = window;
1300 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1302 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1303 gdk_window_destroy_notify (window);
1312 g_message ("unmap notify:\t\twindow: %ld",
1313 xevent->xmap.window));
1315 event->any.type = GDK_UNMAP;
1316 event->any.window = window;
1318 /* If we are shown (not withdrawn) and get an unmap, it means we
1319 * were iconified in the X sense. If we are withdrawn, and get
1320 * an unmap, it means we hid the window ourselves, so we
1321 * will have already flipped the iconified bit off.
1325 if (GDK_WINDOW_IS_MAPPED (window))
1326 gdk_synthesize_window_state (window,
1328 GDK_WINDOW_STATE_ICONIFIED);
1330 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1337 g_message ("map notify:\t\twindow: %ld",
1338 xevent->xmap.window));
1340 event->any.type = GDK_MAP;
1341 event->any.window = window;
1343 /* Unset iconified if it was set */
1344 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1345 gdk_synthesize_window_state (window,
1346 GDK_WINDOW_STATE_ICONIFIED,
1351 case ReparentNotify:
1353 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1354 xevent->xreparent.window,
1355 xevent->xreparent.x,
1356 xevent->xreparent.y,
1357 xevent->xreparent.parent,
1358 xevent->xreparent.override_redirect));
1360 /* Not currently handled */
1364 case ConfigureNotify:
1366 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1367 xevent->xconfigure.window,
1368 xevent->xconfigure.x,
1369 xevent->xconfigure.y,
1370 xevent->xconfigure.width,
1371 xevent->xconfigure.height,
1372 xevent->xconfigure.border_width,
1373 xevent->xconfigure.above,
1374 xevent->xconfigure.override_redirect,
1377 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1378 ? " (discarding child)"
1379 : xevent->xconfigure.event != xevent->xconfigure.window
1380 ? " (discarding substructure)"
1383 xevent->xconfigure.event == xevent->xconfigure.window &&
1384 !GDK_WINDOW_DESTROYED (window) &&
1385 (window_private->extension_events != 0))
1386 _gdk_input_configure_event (&xevent->xconfigure, window);
1389 xevent->xconfigure.event != xevent->xconfigure.window ||
1390 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1391 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1395 event->configure.type = GDK_CONFIGURE;
1396 event->configure.window = window;
1397 event->configure.width = xevent->xconfigure.width;
1398 event->configure.height = xevent->xconfigure.height;
1400 if (!xevent->xconfigure.send_event &&
1401 !GDK_WINDOW_DESTROYED (window))
1405 Window child_window = 0;
1407 gdk_error_trap_push ();
1408 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1409 GDK_DRAWABLE_XID (window),
1410 screen_x11->xroot_window,
1415 if (!gdk_error_trap_pop ())
1417 event->configure.x = tx;
1418 event->configure.y = ty;
1422 gdk_error_trap_pop ();
1426 event->configure.x = xevent->xconfigure.x;
1427 event->configure.y = xevent->xconfigure.y;
1429 window_private->x = event->configure.x;
1430 window_private->y = event->configure.y;
1431 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1432 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1433 if (window_private->resize_count >= 1)
1435 window_private->resize_count -= 1;
1437 if (window_private->resize_count == 0)
1438 _gdk_moveresize_configure_done (display, window);
1443 case PropertyNotify:
1445 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1446 xevent->xproperty.window,
1447 xevent->xproperty.atom,
1449 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1452 if (window_private == NULL)
1458 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
1459 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1461 /* If window state changed, then synthesize those events. */
1462 gdk_check_wm_state_changed (window);
1465 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1467 event->property.type = GDK_PROPERTY_NOTIFY;
1468 event->property.window = window;
1469 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1470 event->property.time = xevent->xproperty.time;
1471 event->property.state = xevent->xproperty.state;
1478 case SelectionClear:
1480 g_message ("selection clear:\twindow: %ld",
1481 xevent->xproperty.window));
1483 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1485 event->selection.type = GDK_SELECTION_CLEAR;
1486 event->selection.window = window;
1487 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1488 event->selection.time = xevent->xselectionclear.time;
1495 case SelectionRequest:
1497 g_message ("selection request:\twindow: %ld",
1498 xevent->xproperty.window));
1500 event->selection.type = GDK_SELECTION_REQUEST;
1501 event->selection.window = window;
1502 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1503 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1504 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1505 event->selection.requestor = xevent->xselectionrequest.requestor;
1506 event->selection.time = xevent->xselectionrequest.time;
1510 case SelectionNotify:
1512 g_message ("selection notify:\twindow: %ld",
1513 xevent->xproperty.window));
1516 event->selection.type = GDK_SELECTION_NOTIFY;
1517 event->selection.window = window;
1518 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1519 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1520 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1521 event->selection.time = xevent->xselection.time;
1525 case ColormapNotify:
1527 g_message ("colormap notify:\twindow: %ld",
1528 xevent->xcolormap.window));
1530 /* Not currently handled */
1537 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1538 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1541 g_message ("client message:\twindow: %ld",
1542 xevent->xclient.window));
1544 tmp_list = display_x11->client_filters;
1547 GdkClientFilter *filter = tmp_list->data;
1548 if (filter->type == message_type)
1550 result = (*filter->function) (xevent, event, filter->data);
1554 tmp_list = tmp_list->next;
1559 case GDK_FILTER_REMOVE:
1562 case GDK_FILTER_TRANSLATE:
1565 case GDK_FILTER_CONTINUE:
1566 /* Send unknown ClientMessage's on to Gtk for it to use */
1567 if (window_private == NULL)
1573 event->client.type = GDK_CLIENT_EVENT;
1574 event->client.window = window;
1575 event->client.message_type = message_type;
1576 event->client.data_format = xevent->xclient.format;
1577 memcpy(&event->client.data, &xevent->xclient.data,
1578 sizeof(event->client.data));
1588 g_message ("mapping notify"));
1590 /* Let XLib know that there is a new keyboard mapping.
1592 XRefreshKeyboardMapping (&xevent->xmapping);
1593 ++display_x11->keymap_serial;
1599 if (xevent->type == display_x11->xkb_event_type)
1601 XkbEvent *xkb_event = (XkbEvent *)xevent;
1603 switch (xkb_event->any.xkb_type)
1606 ++display_x11->keymap_serial;
1611 case XkbStateNotify:
1612 _gdk_keymap_state_changed (display);
1619 /* something else - (e.g., a Xinput event) */
1621 if (window_private &&
1622 !GDK_WINDOW_DESTROYED (window_private) &&
1623 (window_private->extension_events != 0))
1624 return_val = _gdk_input_other_event(event, xevent, window);
1635 if (event->any.window)
1636 gdk_window_ref (event->any.window);
1637 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1638 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1639 (event->crossing.subwindow != NULL))
1640 gdk_window_ref (event->crossing.subwindow);
1644 /* Mark this event as having no resources to be freed */
1645 event->any.window = NULL;
1646 event->any.type = GDK_NOTHING;
1650 gdk_window_unref (window);
1655 static GdkFilterReturn
1656 gdk_wm_protocols_filter (GdkXEvent *xev,
1660 XEvent *xevent = (XEvent *)xev;
1661 GdkWindow *win = event->any.window;
1662 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1664 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1666 /* The delete window request specifies a window
1667 * to delete. We don't actually destroy the
1668 * window because "it is only a request". (The
1669 * window might contain vital data that the
1670 * program does not want destroyed). Instead
1671 * the event is passed along to the program,
1672 * which should then destroy the window.
1675 g_message ("delete window:\t\twindow: %ld",
1676 xevent->xclient.window));
1678 event->any.type = GDK_DELETE;
1680 return GDK_FILTER_TRANSLATE;
1682 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1684 GdkWindow *win = event->any.window;
1685 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1687 /* There is no way of knowing reliably whether we are viewable so we need
1688 * to trap errors so we don't cause a BadMatch.
1690 gdk_error_trap_push ();
1691 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1694 xevent->xclient.data.l[1]);
1695 XSync (GDK_WINDOW_XDISPLAY (win), False);
1696 gdk_error_trap_pop ();
1698 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"))
1700 XEvent xev = *xevent;
1702 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1703 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1706 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1709 return GDK_FILTER_REMOVE;
1713 _gdk_events_queue (GdkDisplay *display)
1718 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1720 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1722 XNextEvent (xdisplay, &xevent);
1724 switch (xevent.type)
1730 if (XFilterEvent (&xevent, None))
1734 event = _gdk_event_new ();
1736 event->any.type = GDK_NOTHING;
1737 event->any.window = NULL;
1738 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1740 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1742 node = _gdk_event_queue_append (display, event);
1744 if (gdk_event_translate (display, event, &xevent, FALSE))
1746 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1750 _gdk_event_queue_remove_link (display, node);
1751 g_list_free_1 (node);
1752 gdk_event_free (event);
1758 gdk_event_prepare (GSource *source,
1761 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1764 GDK_THREADS_ENTER ();
1767 retval = (_gdk_event_queue_find_first (display) != NULL ||
1768 gdk_check_xpending (display));
1770 GDK_THREADS_LEAVE ();
1776 gdk_event_check (GSource *source)
1778 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
1781 GDK_THREADS_ENTER ();
1783 if (display_source->event_poll_fd.revents & G_IO_IN)
1784 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
1785 gdk_check_xpending (display_source->display));
1789 GDK_THREADS_LEAVE ();
1795 gdk_event_dispatch (GSource *source,
1796 GSourceFunc callback,
1799 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1802 GDK_THREADS_ENTER ();
1804 _gdk_events_queue (display);
1805 event = _gdk_event_unqueue (display);
1809 if (_gdk_event_func)
1810 (*_gdk_event_func) (event, _gdk_event_data);
1812 gdk_event_free (event);
1815 GDK_THREADS_LEAVE ();
1821 * gdk_event_send_client_message_for_display :
1822 * @display : the #GdkDisplay for the window where the message is to be sent.
1823 * @event : the #GdkEvent to send, which should be a #GdkEventClient.
1824 * @xid : the X window to send the X ClientMessage event to.
1826 * Sends an X ClientMessage event to a given window.
1828 * This could be used for communicating between different applications,
1829 * though the amount of data is limited to 20 bytes.
1831 * Returns : non-zero on success.
1834 gdk_event_send_client_message_for_display (GdkDisplay *display,
1840 g_return_val_if_fail(event != NULL, FALSE);
1842 /* Set up our event to send, with the exception of its target window */
1843 sev.xclient.type = ClientMessage;
1844 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
1845 sev.xclient.format = event->client.data_format;
1846 sev.xclient.window = xid;
1847 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1848 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
1850 return _gdk_send_xevent (display, xid, False, NoEventMask, &sev);
1855 /* Sends a ClientMessage to all toplevel client windows */
1857 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
1864 unsigned long nitems, after;
1865 unsigned char *data;
1866 Window *ret_children, ret_root, ret_parent;
1867 unsigned int ret_nchildren;
1868 gboolean send = FALSE;
1869 gboolean found = FALSE;
1870 gboolean result = FALSE;
1873 gdk_error_trap_push ();
1875 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
1876 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1877 0, 0, False, AnyPropertyType,
1878 &type, &format, &nitems, &after, &data) != Success)
1888 /* OK, we're all set, now let's find some windows to send this to */
1889 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
1890 &ret_root, &ret_parent,
1891 &ret_children, &ret_nchildren))
1894 for(i = 0; i < ret_nchildren; i++)
1895 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
1898 XFree (ret_children);
1901 if (send || (!found && (level == 1)))
1903 xev->xclient.window = xid;
1904 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
1907 result = send || found;
1910 gdk_error_trap_pop ();
1916 * gdk_screen_broadcast_client_message:
1917 * @screen : the #GdkScreen where the event will be broadcasted.
1918 * @event : the #GdkEvent.
1920 * Sends an X ClientMessage event to all toplevel windows on @screen.
1922 * Toplevel windows are determined by checking for the WM_STATE property,
1923 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
1924 * If no windows are found with the WM_STATE property set, the message is
1925 * sent to all children of the root window.
1929 gdk_screen_broadcast_client_message (GdkScreen *screen,
1933 GdkWindow *root_window;
1935 g_return_if_fail (event != NULL);
1937 root_window = gdk_screen_get_root_window (screen);
1939 /* Set up our event to send, with the exception of its target window */
1940 sev.xclient.type = ClientMessage;
1941 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
1942 sev.xclient.format = event->client.data_format;
1943 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1944 sev.xclient.message_type =
1945 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
1946 event->client.message_type);
1948 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
1950 GDK_WINDOW_XID (root_window),
1955 *--------------------------------------------------------------
1958 * Flushes the Xlib output buffer and then waits
1959 * until all requests have been received and processed
1960 * by the X server. The only real use for this function
1961 * is in dealing with XShm.
1969 *--------------------------------------------------------------
1975 GSList *tmp_list = _gdk_displays;
1979 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
1980 tmp_list = tmp_list->next;
1985 timestamp_predicate (Display *display,
1989 Window xwindow = GPOINTER_TO_UINT (arg);
1990 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
1992 if (xevent->type == PropertyNotify &&
1993 xevent->xproperty.window == xwindow &&
1994 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display
1995 (gdk_display, "GDK_TIMESTAMP_PROP"))
2002 * gdk_x11_get_server_time:
2003 * @window: a #GdkWindow, used for communication with the server.
2004 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2005 * events mask or a hang will result.
2007 * Routine to get the current X server time stamp.
2009 * Return value: the time stamp.
2012 gdk_x11_get_server_time (GdkWindow *window)
2018 Atom timestamp_prop_atom;
2020 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2021 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2023 xdisplay = GDK_WINDOW_XDISPLAY (window);
2024 xwindow = GDK_WINDOW_XWINDOW (window);
2025 timestamp_prop_atom =
2026 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2027 "GDK_TIMESTAMP_PROP");
2029 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2030 timestamp_prop_atom,
2031 8, PropModeReplace, &c, 1);
2033 XIfEvent (xdisplay, &xevent,
2034 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2036 return xevent.xproperty.time;
2039 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2041 struct _NetWmSupportedAtoms
2048 * gdk_x11_screen_supports_net_wm_hint:
2049 * @screen : the relevant #GdkScreen.
2050 * @property: a property atom.
2052 * This function is specific to the X11 backend of GDK, and indicates
2053 * whether the window manager supports a certain hint from the
2054 * Extended Window Manager Hints Specification. You can find this
2055 * specification on http://www.freedesktop.org.
2057 * When using this function, keep in mind that the window manager
2058 * can change over time; so you shouldn't use this function in
2059 * a way that impacts persistent application state. A common bug
2060 * is that your application can start up before the window manager
2061 * does when the user logs in, and before the window manager starts
2062 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2064 * Return value: %TRUE if the window manager supports @property
2067 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2076 GdkScreenX11 *screen_x11;
2077 NetWmSupportedAtoms *supported_atoms;
2078 GdkDisplay *display;
2080 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2082 screen_x11 = GDK_SCREEN_X11 (screen);
2083 display = screen_x11->display;
2085 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2086 if (!supported_atoms)
2088 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2089 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2092 if (screen_x11->wmspec_check_window != None)
2094 if (supported_atoms->atoms == NULL)
2098 while (i < supported_atoms->n_atoms)
2100 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2109 if (supported_atoms->atoms)
2110 XFree (supported_atoms->atoms);
2112 supported_atoms->atoms = NULL;
2113 supported_atoms->n_atoms = 0;
2115 /* This function is very slow on every call if you are not running a
2116 * spec-supporting WM. For now not optimized, because it isn't in
2117 * any critical code paths, but if you used it somewhere that had to
2118 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2119 * Probably at that point the function should be changed to query
2120 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2123 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2124 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2125 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2126 &nitems, &bytes_after, (guchar **) & xwindow);
2128 if (type != XA_WINDOW)
2131 gdk_error_trap_push ();
2133 /* Find out if this WM goes away, so we can reset everything. */
2134 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2136 gdk_display_sync (screen_x11->display);
2138 if (gdk_error_trap_pop ())
2144 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2145 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2146 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2147 &supported_atoms->n_atoms, &bytes_after,
2148 (guchar **)&supported_atoms->atoms);
2150 if (type != XA_ATOM)
2153 screen_x11->wmspec_check_window = *xwindow;
2156 /* since wmspec_check_window != None this isn't infinite. ;-) */
2157 return gdk_x11_screen_supports_net_wm_hint (screen, property);
2161 * gdk_net_wm_supports:
2162 * @property: a property atom.
2164 * This function is specific to the X11 backend of GDK, and indicates
2165 * whether the window manager for the default screen supports a certain
2166 * hint from the Extended Window Manager Hints Specification. See
2167 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2169 * Return value: %TRUE if the window manager supports @property
2172 gdk_net_wm_supports (GdkAtom property)
2174 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2179 const char *xsettings_name;
2180 const char *gdk_name;
2181 } settings_map[] = {
2182 { "Net/DoubleClickTime", "gtk-double-click-time" },
2183 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2184 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2185 { "Gtk/ColorPalette", "gtk-color-palette" },
2186 { "Gtk/FontName", "gtk-font-name" },
2187 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2188 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2189 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2190 { "Net/CursorBlink", "gtk-cursor-blink" },
2191 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2192 { "Net/ThemeName", "gtk-theme-name" }
2196 gdk_xsettings_notify_cb (const char *name,
2197 XSettingsAction action,
2198 XSettingsSetting *setting,
2202 GdkScreen *screen = data;
2205 new_event.type = GDK_SETTING;
2206 new_event.setting.window = gdk_screen_get_root_window (screen);
2207 new_event.setting.send_event = FALSE;
2208 new_event.setting.name = NULL;
2210 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2211 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2213 new_event.setting.name = (char *)settings_map[i].gdk_name;
2217 if (!new_event.setting.name)
2222 case XSETTINGS_ACTION_NEW:
2223 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2225 case XSETTINGS_ACTION_CHANGED:
2226 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2228 case XSETTINGS_ACTION_DELETED:
2229 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2233 gdk_event_put (&new_event);
2237 check_transform (const gchar *xsettings_name,
2241 if (!g_value_type_transformable (src_type, dest_type))
2243 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2245 g_type_name (src_type),
2246 g_type_name (dest_type));
2254 * gdk_screen_get_setting:
2255 * @screen: the #GdkScreen where the setting is located
2256 * @name: the name of the setting
2257 * @value: location to store the value of the setting
2259 * Retrieves a desktop-wide setting such as double-click time
2260 * for the #GdkScreen @screen.
2262 * FIXME needs a list of valid settings here, or a link to
2265 * Returns : %TRUE if the setting existed and a value was stored
2266 * in @value, %FALSE otherwise.
2269 gdk_screen_get_setting (GdkScreen *screen,
2274 const char *xsettings_name = NULL;
2275 XSettingsResult result;
2276 XSettingsSetting *setting;
2277 GdkScreenX11 *screen_x11;
2278 gboolean success = FALSE;
2280 GValue tmp_val = { 0, };
2282 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2284 screen_x11 = GDK_SCREEN_X11 (screen);
2286 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2287 if (strcmp (settings_map[i].gdk_name, name) == 0)
2289 xsettings_name = settings_map[i].xsettings_name;
2293 if (!xsettings_name)
2296 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2297 xsettings_name, &setting);
2298 if (result != XSETTINGS_SUCCESS)
2301 switch (setting->type)
2303 case XSETTINGS_TYPE_INT:
2304 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2306 g_value_init (&tmp_val, G_TYPE_INT);
2307 g_value_set_int (&tmp_val, setting->data.v_int);
2308 g_value_transform (&tmp_val, value);
2313 case XSETTINGS_TYPE_STRING:
2314 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2316 g_value_init (&tmp_val, G_TYPE_STRING);
2317 g_value_set_string (&tmp_val, setting->data.v_string);
2318 g_value_transform (&tmp_val, value);
2323 case XSETTINGS_TYPE_COLOR:
2324 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2328 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2331 color.red = setting->data.v_color.red;
2332 color.green = setting->data.v_color.green;
2333 color.blue = setting->data.v_color.blue;
2335 g_value_set_boxed (&tmp_val, &color);
2337 g_value_transform (&tmp_val, value);
2344 g_value_unset (&tmp_val);
2346 xsettings_setting_free (setting);
2351 static GdkFilterReturn
2352 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2356 GdkScreenX11 *screen = data;
2358 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2359 return GDK_FILTER_REMOVE;
2361 return GDK_FILTER_CONTINUE;
2365 gdk_xsettings_watch_cb (Window window,
2371 GdkScreen *screen = cb_data;
2372 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
2374 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2379 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2381 g_object_ref (gdkwin);
2383 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2388 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2389 g_object_unref (gdkwin);