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 /* We pretend that the focus moves to the grab
1076 * window, so we pay attention to NotifyGrab
1077 * NotifyUngrab, and ignore NotifyWhileGrabbed
1079 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1080 window_impl->has_focus = TRUE;
1083 /* The X server sends NotifyPointer/NotifyGrab,
1084 * but the pointer focus is ignored while a
1087 if (xevent->xfocus.mode != NotifyGrab)
1088 window_impl->has_pointer_focus = TRUE;
1090 case NotifyInferior:
1091 case NotifyPointerRoot:
1092 case NotifyDetailNone:
1096 if (HAS_FOCUS (window_impl) != had_focus)
1097 generate_focus_event (window, TRUE);
1102 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1104 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1106 gboolean had_focus = HAS_FOCUS (window_impl);
1108 switch (xevent->xfocus.detail)
1110 case NotifyAncestor:
1111 case NotifyNonlinear:
1113 case NotifyNonlinearVirtual:
1114 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1115 window_impl->has_focus = FALSE;
1118 if (xevent->xfocus.mode != NotifyUngrab)
1119 window_impl->has_pointer_focus = FALSE;
1121 case NotifyInferior:
1122 case NotifyPointerRoot:
1123 case NotifyDetailNone:
1127 if (HAS_FOCUS (window_impl) != had_focus)
1128 generate_focus_event (window, FALSE);
1133 /* gdk_keyboard_grab() causes following events. These events confuse
1134 * the XIM focus, so ignore them.
1136 if (xevent->xfocus.mode == NotifyGrab ||
1137 xevent->xfocus.mode == NotifyUngrab)
1143 g_message ("keymap notify"));
1145 /* Not currently handled */
1151 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1152 xevent->xexpose.window, xevent->xexpose.count,
1153 xevent->xexpose.x, xevent->xexpose.y,
1154 xevent->xexpose.width, xevent->xexpose.height,
1155 event->any.send_event ? " (send)" : ""));
1157 if (window_private == NULL)
1164 GdkRectangle expose_rect;
1166 expose_rect.x = xevent->xexpose.x + xoffset;
1167 expose_rect.y = xevent->xexpose.y + yoffset;
1168 expose_rect.width = xevent->xexpose.width;
1169 expose_rect.height = xevent->xexpose.height;
1173 event->expose.type = GDK_EXPOSE;
1174 event->expose.area = expose_rect;
1175 event->expose.region = gdk_region_rectangle (&expose_rect);
1176 event->expose.window = window;
1177 event->expose.count = xevent->xexpose.count;
1183 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1192 case GraphicsExpose:
1194 GdkRectangle expose_rect;
1197 g_message ("graphics expose:\tdrawable: %ld",
1198 xevent->xgraphicsexpose.drawable));
1200 if (window_private == NULL)
1206 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1207 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1208 expose_rect.width = xevent->xgraphicsexpose.width;
1209 expose_rect.height = xevent->xgraphicsexpose.height;
1213 event->expose.type = GDK_EXPOSE;
1214 event->expose.area = expose_rect;
1215 event->expose.region = gdk_region_rectangle (&expose_rect);
1216 event->expose.window = window;
1217 event->expose.count = xevent->xgraphicsexpose.count;
1223 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1233 g_message ("no expose:\t\tdrawable: %ld",
1234 xevent->xnoexpose.drawable));
1236 event->no_expose.type = GDK_NO_EXPOSE;
1237 event->no_expose.window = window;
1241 case VisibilityNotify:
1242 #ifdef G_ENABLE_DEBUG
1243 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1244 switch (xevent->xvisibility.state)
1246 case VisibilityFullyObscured:
1247 g_message ("visibility notify:\twindow: %ld none",
1248 xevent->xvisibility.window);
1250 case VisibilityPartiallyObscured:
1251 g_message ("visibility notify:\twindow: %ld partial",
1252 xevent->xvisibility.window);
1254 case VisibilityUnobscured:
1255 g_message ("visibility notify:\twindow: %ld full",
1256 xevent->xvisibility.window);
1259 #endif /* G_ENABLE_DEBUG */
1261 if (window_private == NULL)
1267 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1268 event->visibility.window = window;
1270 switch (xevent->xvisibility.state)
1272 case VisibilityFullyObscured:
1273 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1276 case VisibilityPartiallyObscured:
1277 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1280 case VisibilityUnobscured:
1281 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1289 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1290 xevent->xcreatewindow.window,
1291 xevent->xcreatewindow.x,
1292 xevent->xcreatewindow.y,
1293 xevent->xcreatewindow.width,
1294 xevent->xcreatewindow.height,
1295 xevent->xcreatewindow.border_width,
1296 xevent->xcreatewindow.parent,
1297 xevent->xcreatewindow.override_redirect));
1298 /* not really handled */
1303 g_message ("destroy notify:\twindow: %ld",
1304 xevent->xdestroywindow.window));
1306 /* Ignore DestroyNotify from SubstructureNotifyMask */
1307 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1309 event->any.type = GDK_DESTROY;
1310 event->any.window = window;
1312 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1314 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1315 gdk_window_destroy_notify (window);
1324 g_message ("unmap notify:\t\twindow: %ld",
1325 xevent->xmap.window));
1327 event->any.type = GDK_UNMAP;
1328 event->any.window = window;
1330 /* If we are shown (not withdrawn) and get an unmap, it means we
1331 * were iconified in the X sense. If we are withdrawn, and get
1332 * an unmap, it means we hid the window ourselves, so we
1333 * will have already flipped the iconified bit off.
1337 if (GDK_WINDOW_IS_MAPPED (window))
1338 gdk_synthesize_window_state (window,
1340 GDK_WINDOW_STATE_ICONIFIED);
1342 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1349 g_message ("map notify:\t\twindow: %ld",
1350 xevent->xmap.window));
1352 event->any.type = GDK_MAP;
1353 event->any.window = window;
1355 /* Unset iconified if it was set */
1356 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1357 gdk_synthesize_window_state (window,
1358 GDK_WINDOW_STATE_ICONIFIED,
1363 case ReparentNotify:
1365 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1366 xevent->xreparent.window,
1367 xevent->xreparent.x,
1368 xevent->xreparent.y,
1369 xevent->xreparent.parent,
1370 xevent->xreparent.override_redirect));
1372 /* Not currently handled */
1376 case ConfigureNotify:
1378 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1379 xevent->xconfigure.window,
1380 xevent->xconfigure.x,
1381 xevent->xconfigure.y,
1382 xevent->xconfigure.width,
1383 xevent->xconfigure.height,
1384 xevent->xconfigure.border_width,
1385 xevent->xconfigure.above,
1386 xevent->xconfigure.override_redirect,
1389 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1390 ? " (discarding child)"
1391 : xevent->xconfigure.event != xevent->xconfigure.window
1392 ? " (discarding substructure)"
1395 xevent->xconfigure.event == xevent->xconfigure.window &&
1396 !GDK_WINDOW_DESTROYED (window) &&
1397 (window_private->extension_events != 0))
1398 _gdk_input_configure_event (&xevent->xconfigure, window);
1401 xevent->xconfigure.event != xevent->xconfigure.window ||
1402 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1403 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1407 event->configure.type = GDK_CONFIGURE;
1408 event->configure.window = window;
1409 event->configure.width = xevent->xconfigure.width;
1410 event->configure.height = xevent->xconfigure.height;
1412 if (!xevent->xconfigure.send_event &&
1413 !GDK_WINDOW_DESTROYED (window))
1417 Window child_window = 0;
1419 gdk_error_trap_push ();
1420 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1421 GDK_DRAWABLE_XID (window),
1422 screen_x11->xroot_window,
1427 if (!gdk_error_trap_pop ())
1429 event->configure.x = tx;
1430 event->configure.y = ty;
1434 gdk_error_trap_pop ();
1438 event->configure.x = xevent->xconfigure.x;
1439 event->configure.y = xevent->xconfigure.y;
1441 window_private->x = event->configure.x;
1442 window_private->y = event->configure.y;
1443 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1444 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1445 if (window_private->resize_count >= 1)
1447 window_private->resize_count -= 1;
1449 if (window_private->resize_count == 0)
1450 _gdk_moveresize_configure_done (display, window);
1455 case PropertyNotify:
1457 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1458 xevent->xproperty.window,
1459 xevent->xproperty.atom,
1461 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1464 if (window_private == NULL)
1470 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
1471 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1473 /* If window state changed, then synthesize those events. */
1474 gdk_check_wm_state_changed (window);
1477 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1479 event->property.type = GDK_PROPERTY_NOTIFY;
1480 event->property.window = window;
1481 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1482 event->property.time = xevent->xproperty.time;
1483 event->property.state = xevent->xproperty.state;
1490 case SelectionClear:
1492 g_message ("selection clear:\twindow: %ld",
1493 xevent->xproperty.window));
1495 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1497 event->selection.type = GDK_SELECTION_CLEAR;
1498 event->selection.window = window;
1499 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1500 event->selection.time = xevent->xselectionclear.time;
1507 case SelectionRequest:
1509 g_message ("selection request:\twindow: %ld",
1510 xevent->xproperty.window));
1512 event->selection.type = GDK_SELECTION_REQUEST;
1513 event->selection.window = window;
1514 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1515 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1516 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1517 event->selection.requestor = xevent->xselectionrequest.requestor;
1518 event->selection.time = xevent->xselectionrequest.time;
1522 case SelectionNotify:
1524 g_message ("selection notify:\twindow: %ld",
1525 xevent->xproperty.window));
1528 event->selection.type = GDK_SELECTION_NOTIFY;
1529 event->selection.window = window;
1530 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1531 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1532 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1533 event->selection.time = xevent->xselection.time;
1537 case ColormapNotify:
1539 g_message ("colormap notify:\twindow: %ld",
1540 xevent->xcolormap.window));
1542 /* Not currently handled */
1549 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1550 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1553 g_message ("client message:\twindow: %ld",
1554 xevent->xclient.window));
1556 tmp_list = display_x11->client_filters;
1559 GdkClientFilter *filter = tmp_list->data;
1560 if (filter->type == message_type)
1562 result = (*filter->function) (xevent, event, filter->data);
1566 tmp_list = tmp_list->next;
1571 case GDK_FILTER_REMOVE:
1574 case GDK_FILTER_TRANSLATE:
1577 case GDK_FILTER_CONTINUE:
1578 /* Send unknown ClientMessage's on to Gtk for it to use */
1579 if (window_private == NULL)
1585 event->client.type = GDK_CLIENT_EVENT;
1586 event->client.window = window;
1587 event->client.message_type = message_type;
1588 event->client.data_format = xevent->xclient.format;
1589 memcpy(&event->client.data, &xevent->xclient.data,
1590 sizeof(event->client.data));
1600 g_message ("mapping notify"));
1602 /* Let XLib know that there is a new keyboard mapping.
1604 XRefreshKeyboardMapping (&xevent->xmapping);
1605 ++display_x11->keymap_serial;
1611 if (xevent->type == display_x11->xkb_event_type)
1613 XkbEvent *xkb_event = (XkbEvent *)xevent;
1615 switch (xkb_event->any.xkb_type)
1618 ++display_x11->keymap_serial;
1623 case XkbStateNotify:
1624 _gdk_keymap_state_changed (display);
1631 /* something else - (e.g., a Xinput event) */
1633 if (window_private &&
1634 !GDK_WINDOW_DESTROYED (window_private) &&
1635 (window_private->extension_events != 0))
1636 return_val = _gdk_input_other_event(event, xevent, window);
1647 if (event->any.window)
1648 gdk_window_ref (event->any.window);
1649 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1650 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1651 (event->crossing.subwindow != NULL))
1652 gdk_window_ref (event->crossing.subwindow);
1656 /* Mark this event as having no resources to be freed */
1657 event->any.window = NULL;
1658 event->any.type = GDK_NOTHING;
1662 gdk_window_unref (window);
1667 static GdkFilterReturn
1668 gdk_wm_protocols_filter (GdkXEvent *xev,
1672 XEvent *xevent = (XEvent *)xev;
1673 GdkWindow *win = event->any.window;
1674 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1676 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1678 /* The delete window request specifies a window
1679 * to delete. We don't actually destroy the
1680 * window because "it is only a request". (The
1681 * window might contain vital data that the
1682 * program does not want destroyed). Instead
1683 * the event is passed along to the program,
1684 * which should then destroy the window.
1687 g_message ("delete window:\t\twindow: %ld",
1688 xevent->xclient.window));
1690 event->any.type = GDK_DELETE;
1692 return GDK_FILTER_TRANSLATE;
1694 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1696 GdkWindow *win = event->any.window;
1697 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1699 /* There is no way of knowing reliably whether we are viewable so we need
1700 * to trap errors so we don't cause a BadMatch.
1702 gdk_error_trap_push ();
1703 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1706 xevent->xclient.data.l[1]);
1707 XSync (GDK_WINDOW_XDISPLAY (win), False);
1708 gdk_error_trap_pop ();
1710 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"))
1712 XEvent xev = *xevent;
1714 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1715 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1718 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1721 return GDK_FILTER_REMOVE;
1725 _gdk_events_queue (GdkDisplay *display)
1730 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1732 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1734 XNextEvent (xdisplay, &xevent);
1736 switch (xevent.type)
1742 if (XFilterEvent (&xevent, None))
1746 event = _gdk_event_new ();
1748 event->any.type = GDK_NOTHING;
1749 event->any.window = NULL;
1750 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1752 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1754 node = _gdk_event_queue_append (display, event);
1756 if (gdk_event_translate (display, event, &xevent, FALSE))
1758 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1762 _gdk_event_queue_remove_link (display, node);
1763 g_list_free_1 (node);
1764 gdk_event_free (event);
1770 gdk_event_prepare (GSource *source,
1773 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1776 GDK_THREADS_ENTER ();
1779 retval = (_gdk_event_queue_find_first (display) != NULL ||
1780 gdk_check_xpending (display));
1782 GDK_THREADS_LEAVE ();
1788 gdk_event_check (GSource *source)
1790 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
1793 GDK_THREADS_ENTER ();
1795 if (display_source->event_poll_fd.revents & G_IO_IN)
1796 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
1797 gdk_check_xpending (display_source->display));
1801 GDK_THREADS_LEAVE ();
1807 gdk_event_dispatch (GSource *source,
1808 GSourceFunc callback,
1811 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1814 GDK_THREADS_ENTER ();
1816 _gdk_events_queue (display);
1817 event = _gdk_event_unqueue (display);
1821 if (_gdk_event_func)
1822 (*_gdk_event_func) (event, _gdk_event_data);
1824 gdk_event_free (event);
1827 GDK_THREADS_LEAVE ();
1833 * gdk_event_send_client_message_for_display :
1834 * @display : the #GdkDisplay for the window where the message is to be sent.
1835 * @event : the #GdkEvent to send, which should be a #GdkEventClient.
1836 * @xid : the X window to send the X ClientMessage event to.
1838 * Sends an X ClientMessage event to a given window.
1840 * This could be used for communicating between different applications,
1841 * though the amount of data is limited to 20 bytes.
1843 * Returns : non-zero on success.
1846 gdk_event_send_client_message_for_display (GdkDisplay *display,
1852 g_return_val_if_fail(event != NULL, FALSE);
1854 /* Set up our event to send, with the exception of its target window */
1855 sev.xclient.type = ClientMessage;
1856 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
1857 sev.xclient.format = event->client.data_format;
1858 sev.xclient.window = xid;
1859 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1860 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
1862 return _gdk_send_xevent (display, xid, False, NoEventMask, &sev);
1867 /* Sends a ClientMessage to all toplevel client windows */
1869 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
1876 unsigned long nitems, after;
1877 unsigned char *data;
1878 Window *ret_children, ret_root, ret_parent;
1879 unsigned int ret_nchildren;
1880 gboolean send = FALSE;
1881 gboolean found = FALSE;
1882 gboolean result = FALSE;
1885 gdk_error_trap_push ();
1887 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
1888 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
1889 0, 0, False, AnyPropertyType,
1890 &type, &format, &nitems, &after, &data) != Success)
1900 /* OK, we're all set, now let's find some windows to send this to */
1901 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
1902 &ret_root, &ret_parent,
1903 &ret_children, &ret_nchildren))
1906 for(i = 0; i < ret_nchildren; i++)
1907 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
1910 XFree (ret_children);
1913 if (send || (!found && (level == 1)))
1915 xev->xclient.window = xid;
1916 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
1919 result = send || found;
1922 gdk_error_trap_pop ();
1928 * gdk_screen_broadcast_client_message:
1929 * @screen : the #GdkScreen where the event will be broadcasted.
1930 * @event : the #GdkEvent.
1932 * Sends an X ClientMessage event to all toplevel windows on @screen.
1934 * Toplevel windows are determined by checking for the WM_STATE property,
1935 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
1936 * If no windows are found with the WM_STATE property set, the message is
1937 * sent to all children of the root window.
1941 gdk_screen_broadcast_client_message (GdkScreen *screen,
1945 GdkWindow *root_window;
1947 g_return_if_fail (event != NULL);
1949 root_window = gdk_screen_get_root_window (screen);
1951 /* Set up our event to send, with the exception of its target window */
1952 sev.xclient.type = ClientMessage;
1953 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
1954 sev.xclient.format = event->client.data_format;
1955 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
1956 sev.xclient.message_type =
1957 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
1958 event->client.message_type);
1960 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
1962 GDK_WINDOW_XID (root_window),
1967 *--------------------------------------------------------------
1970 * Flushes the Xlib output buffer and then waits
1971 * until all requests have been received and processed
1972 * by the X server. The only real use for this function
1973 * is in dealing with XShm.
1981 *--------------------------------------------------------------
1987 GSList *tmp_list = _gdk_displays;
1991 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
1992 tmp_list = tmp_list->next;
1997 timestamp_predicate (Display *display,
2001 Window xwindow = GPOINTER_TO_UINT (arg);
2002 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2004 if (xevent->type == PropertyNotify &&
2005 xevent->xproperty.window == xwindow &&
2006 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display
2007 (gdk_display, "GDK_TIMESTAMP_PROP"))
2014 * gdk_x11_get_server_time:
2015 * @window: a #GdkWindow, used for communication with the server.
2016 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2017 * events mask or a hang will result.
2019 * Routine to get the current X server time stamp.
2021 * Return value: the time stamp.
2024 gdk_x11_get_server_time (GdkWindow *window)
2030 Atom timestamp_prop_atom;
2032 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2033 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2035 xdisplay = GDK_WINDOW_XDISPLAY (window);
2036 xwindow = GDK_WINDOW_XWINDOW (window);
2037 timestamp_prop_atom =
2038 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2039 "GDK_TIMESTAMP_PROP");
2041 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2042 timestamp_prop_atom,
2043 8, PropModeReplace, &c, 1);
2045 XIfEvent (xdisplay, &xevent,
2046 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2048 return xevent.xproperty.time;
2051 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2053 struct _NetWmSupportedAtoms
2060 * gdk_x11_screen_supports_net_wm_hint:
2061 * @screen : the relevant #GdkScreen.
2062 * @property: a property atom.
2064 * This function is specific to the X11 backend of GDK, and indicates
2065 * whether the window manager supports a certain hint from the
2066 * Extended Window Manager Hints Specification. You can find this
2067 * specification on http://www.freedesktop.org.
2069 * When using this function, keep in mind that the window manager
2070 * can change over time; so you shouldn't use this function in
2071 * a way that impacts persistent application state. A common bug
2072 * is that your application can start up before the window manager
2073 * does when the user logs in, and before the window manager starts
2074 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2076 * Return value: %TRUE if the window manager supports @property
2079 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2088 GdkScreenX11 *screen_x11;
2089 NetWmSupportedAtoms *supported_atoms;
2090 GdkDisplay *display;
2092 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2094 screen_x11 = GDK_SCREEN_X11 (screen);
2095 display = screen_x11->display;
2097 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2098 if (!supported_atoms)
2100 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2101 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2104 if (screen_x11->wmspec_check_window != None)
2106 if (supported_atoms->atoms == NULL)
2110 while (i < supported_atoms->n_atoms)
2112 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2121 if (supported_atoms->atoms)
2122 XFree (supported_atoms->atoms);
2124 supported_atoms->atoms = NULL;
2125 supported_atoms->n_atoms = 0;
2127 /* This function is very slow on every call if you are not running a
2128 * spec-supporting WM. For now not optimized, because it isn't in
2129 * any critical code paths, but if you used it somewhere that had to
2130 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2131 * Probably at that point the function should be changed to query
2132 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2135 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2136 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2137 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2138 &nitems, &bytes_after, (guchar **) & xwindow);
2140 if (type != XA_WINDOW)
2143 gdk_error_trap_push ();
2145 /* Find out if this WM goes away, so we can reset everything. */
2146 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2148 gdk_display_sync (screen_x11->display);
2150 if (gdk_error_trap_pop ())
2156 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2157 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2158 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2159 &supported_atoms->n_atoms, &bytes_after,
2160 (guchar **)&supported_atoms->atoms);
2162 if (type != XA_ATOM)
2165 screen_x11->wmspec_check_window = *xwindow;
2168 /* since wmspec_check_window != None this isn't infinite. ;-) */
2169 return gdk_x11_screen_supports_net_wm_hint (screen, property);
2173 * gdk_net_wm_supports:
2174 * @property: a property atom.
2176 * This function is specific to the X11 backend of GDK, and indicates
2177 * whether the window manager for the default screen supports a certain
2178 * hint from the Extended Window Manager Hints Specification. See
2179 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2181 * Return value: %TRUE if the window manager supports @property
2184 gdk_net_wm_supports (GdkAtom property)
2186 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2191 const char *xsettings_name;
2192 const char *gdk_name;
2193 } settings_map[] = {
2194 { "Net/DoubleClickTime", "gtk-double-click-time" },
2195 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2196 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2197 { "Gtk/ColorPalette", "gtk-color-palette" },
2198 { "Gtk/FontName", "gtk-font-name" },
2199 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2200 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2201 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2202 { "Net/CursorBlink", "gtk-cursor-blink" },
2203 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2204 { "Net/ThemeName", "gtk-theme-name" }
2208 gdk_xsettings_notify_cb (const char *name,
2209 XSettingsAction action,
2210 XSettingsSetting *setting,
2214 GdkScreen *screen = data;
2217 new_event.type = GDK_SETTING;
2218 new_event.setting.window = gdk_screen_get_root_window (screen);
2219 new_event.setting.send_event = FALSE;
2220 new_event.setting.name = NULL;
2222 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2223 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2225 new_event.setting.name = (char *)settings_map[i].gdk_name;
2229 if (!new_event.setting.name)
2234 case XSETTINGS_ACTION_NEW:
2235 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2237 case XSETTINGS_ACTION_CHANGED:
2238 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2240 case XSETTINGS_ACTION_DELETED:
2241 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2245 gdk_event_put (&new_event);
2249 check_transform (const gchar *xsettings_name,
2253 if (!g_value_type_transformable (src_type, dest_type))
2255 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2257 g_type_name (src_type),
2258 g_type_name (dest_type));
2266 * gdk_screen_get_setting:
2267 * @screen: the #GdkScreen where the setting is located
2268 * @name: the name of the setting
2269 * @value: location to store the value of the setting
2271 * Retrieves a desktop-wide setting such as double-click time
2272 * for the #GdkScreen @screen.
2274 * FIXME needs a list of valid settings here, or a link to
2277 * Returns : %TRUE if the setting existed and a value was stored
2278 * in @value, %FALSE otherwise.
2281 gdk_screen_get_setting (GdkScreen *screen,
2286 const char *xsettings_name = NULL;
2287 XSettingsResult result;
2288 XSettingsSetting *setting;
2289 GdkScreenX11 *screen_x11;
2290 gboolean success = FALSE;
2292 GValue tmp_val = { 0, };
2294 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2296 screen_x11 = GDK_SCREEN_X11 (screen);
2298 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2299 if (strcmp (settings_map[i].gdk_name, name) == 0)
2301 xsettings_name = settings_map[i].xsettings_name;
2305 if (!xsettings_name)
2308 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2309 xsettings_name, &setting);
2310 if (result != XSETTINGS_SUCCESS)
2313 switch (setting->type)
2315 case XSETTINGS_TYPE_INT:
2316 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2318 g_value_init (&tmp_val, G_TYPE_INT);
2319 g_value_set_int (&tmp_val, setting->data.v_int);
2320 g_value_transform (&tmp_val, value);
2325 case XSETTINGS_TYPE_STRING:
2326 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2328 g_value_init (&tmp_val, G_TYPE_STRING);
2329 g_value_set_string (&tmp_val, setting->data.v_string);
2330 g_value_transform (&tmp_val, value);
2335 case XSETTINGS_TYPE_COLOR:
2336 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2340 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2343 color.red = setting->data.v_color.red;
2344 color.green = setting->data.v_color.green;
2345 color.blue = setting->data.v_color.blue;
2347 g_value_set_boxed (&tmp_val, &color);
2349 g_value_transform (&tmp_val, value);
2356 g_value_unset (&tmp_val);
2358 xsettings_setting_free (setting);
2363 static GdkFilterReturn
2364 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2368 GdkScreenX11 *screen = data;
2370 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2371 return GDK_FILTER_REMOVE;
2373 return GDK_FILTER_CONTINUE;
2377 gdk_xsettings_watch_cb (Window window,
2383 GdkScreen *screen = cb_data;
2384 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
2386 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2391 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2393 g_object_ref (gdkwin);
2395 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2400 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2401 g_object_unref (gdkwin);