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 /* Keep a flag to avoid extra notifies that we don't need
152 screen_x11->xsettings_in_init = TRUE;
153 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
154 screen_x11->screen_num,
155 gdk_xsettings_notify_cb,
156 gdk_xsettings_watch_cb,
158 screen_x11->xsettings_in_init = FALSE;
162 _gdk_x11_events_uninit_screen (GdkScreen *screen)
164 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
166 xsettings_client_destroy (screen_x11->xsettings_client);
167 screen_x11->xsettings_client = NULL;
171 _gdk_events_init (GdkDisplay *display)
174 GdkDisplaySource *display_source;
175 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
177 int connection_number = ConnectionNumber (display_x11->xdisplay);
178 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
181 source = display_x11->event_source = gdk_display_source_new (display);
182 display_source = (GdkDisplaySource*) source;
183 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
185 display_source->event_poll_fd.fd = connection_number;
186 display_source->event_poll_fd.events = G_IO_IN;
188 g_source_add_poll (source, &display_source->event_poll_fd);
189 g_source_set_can_recurse (source, TRUE);
190 g_source_attach (source, NULL);
192 display_sources = g_list_prepend (display_sources,display_source);
194 gdk_display_add_client_message_filter (
196 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
197 gdk_wm_protocols_filter,
203 * gdk_events_pending:
205 * Checks if any events are ready to be processed for any display.
207 * Return value: %TRUE if any events are pending.
210 gdk_events_pending (void)
214 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
216 GdkDisplaySource *tmp_source = tmp_list->data;
217 GdkDisplay *display = tmp_source->display;
219 if (_gdk_event_queue_find_first (display))
223 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
225 GdkDisplaySource *tmp_source = tmp_list->data;
226 GdkDisplay *display = tmp_source->display;
228 if (gdk_check_xpending (display))
236 graphics_expose_predicate (Display *display,
240 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
241 (xevent->xany.type == GraphicsExpose ||
242 xevent->xany.type == NoExpose))
249 * gdk_event_get_graphics_expose:
250 * @window: the #GdkWindow to wait for the events for.
252 * Waits for a GraphicsExpose or NoExpose event from the X server.
253 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
254 * GraphicsExpose events are handled before the widget is scrolled.
256 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
257 * NoExpose event was received.
260 gdk_event_get_graphics_expose (GdkWindow *window)
265 g_return_val_if_fail (window != NULL, NULL);
267 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
268 graphics_expose_predicate, (XPointer) window);
270 if (xevent.xany.type == GraphicsExpose)
272 event = gdk_event_new (GDK_NOTHING);
274 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
278 gdk_event_free (event);
285 gdk_event_apply_filters (XEvent *xevent,
290 GdkFilterReturn result;
296 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
298 tmp_list = tmp_list->next;
299 result = filter->function (xevent, event, filter->data);
300 if (result != GDK_FILTER_CONTINUE)
304 return GDK_FILTER_CONTINUE;
308 * gdk_display_add_client_message_filter:
309 * @display: a #GdkDisplay for which this message filter applies
310 * @message_type: the type of ClientMessage events to receive.
311 * This will be checked against the @message_type field
312 * of the XClientMessage event struct.
313 * @func: the function to call to process the event.
314 * @data: user data to pass to @func.
316 * Adds a filter to be called when X ClientMessage events are received.
321 gdk_display_add_client_message_filter (GdkDisplay *display,
322 GdkAtom message_type,
326 GdkClientFilter *filter;
327 g_return_if_fail (GDK_IS_DISPLAY (display));
328 filter = g_new (GdkClientFilter, 1);
330 filter->type = message_type;
331 filter->function = func;
334 GDK_DISPLAY_X11(display)->client_filters =
335 g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
340 * gdk_add_client_message_filter:
341 * @message_type: the type of ClientMessage events to receive. This will be
342 * checked against the <structfield>message_type</structfield> field of the
343 * XClientMessage event struct.
344 * @func: the function to call to process the event.
345 * @data: user data to pass to @func.
347 * Adds a filter to the default display to be called when X ClientMessage events
348 * are received. See gdk_display_add_client_message_filter().
351 gdk_add_client_message_filter (GdkAtom message_type,
355 gdk_display_add_client_message_filter (gdk_display_get_default (),
356 message_type, func, data);
360 gdk_check_wm_state_changed (GdkWindow *window)
368 gboolean found_sticky, found_maxvert, found_maxhorz, found_fullscreen;
369 GdkWindowState old_state;
370 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
372 if (GDK_WINDOW_DESTROYED (window) ||
373 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
376 found_sticky = FALSE;
377 found_maxvert = FALSE;
378 found_maxhorz = FALSE;
379 found_fullscreen = FALSE;
381 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
382 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
383 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
384 &bytes_after, (guchar **)&atoms);
388 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
389 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
390 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
391 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
396 if (atoms[i] == sticky_atom)
398 else if (atoms[i] == maxvert_atom)
399 found_maxvert = TRUE;
400 else if (atoms[i] == maxhorz_atom)
401 found_maxhorz = TRUE;
402 else if (atoms[i] == fullscreen_atom)
403 found_fullscreen = TRUE;
411 /* For found_sticky to remain TRUE, we have to also be on desktop
419 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window),
420 GDK_WINDOW_XID (window),
421 gdk_x11_get_xatom_by_name_for_display
422 (display, "_NET_WM_DESKTOP"),
423 0, G_MAXLONG, False, XA_CARDINAL, &type,
425 &bytes_after, (guchar **)&desktop);
429 if (*desktop != 0xFFFFFFFF)
430 found_sticky = FALSE;
435 old_state = gdk_window_get_state (window);
437 if (old_state & GDK_WINDOW_STATE_STICKY)
440 gdk_synthesize_window_state (window,
441 GDK_WINDOW_STATE_STICKY,
447 gdk_synthesize_window_state (window,
449 GDK_WINDOW_STATE_STICKY);
452 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
454 if (!found_fullscreen)
455 gdk_synthesize_window_state (window,
456 GDK_WINDOW_STATE_FULLSCREEN,
461 if (found_fullscreen)
462 gdk_synthesize_window_state (window,
464 GDK_WINDOW_STATE_FULLSCREEN);
467 /* Our "maximized" means both vertical and horizontal; if only one,
468 * we don't expose that via GDK
470 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
472 if (!(found_maxvert && found_maxhorz))
473 gdk_synthesize_window_state (window,
474 GDK_WINDOW_STATE_MAXIMIZED,
479 if (found_maxvert && found_maxhorz)
480 gdk_synthesize_window_state (window,
482 GDK_WINDOW_STATE_MAXIMIZED);
486 #define HAS_FOCUS(window_impl) \
487 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
490 generate_focus_event (GdkWindow *window,
495 event.type = GDK_FOCUS_CHANGE;
496 event.focus_change.window = window;
497 event.focus_change.send_event = FALSE;
498 event.focus_change.in = in;
500 gdk_event_put (&event);
504 set_screen_from_root (GdkDisplay *display,
510 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
513 gdk_event_set_screen (event, screen);
517 translate_key_event (GdkDisplay *display,
521 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
525 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
526 event->key.time = xevent->xkey.time;
528 event->key.state = (GdkModifierType) xevent->xkey.state;
529 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
530 event->key.hardware_keycode = xevent->xkey.keycode;
532 event->key.keyval = GDK_VoidSymbol;
534 gdk_keymap_translate_keyboard_state (keymap,
535 event->key.hardware_keycode,
541 /* Fill in event->string crudely, since various programs
544 event->key.string = NULL;
546 if (event->key.keyval != GDK_VoidSymbol)
547 c = gdk_keyval_to_unicode (event->key.keyval);
554 /* Apply the control key - Taken from Xlib
556 if (event->key.state & GDK_CONTROL_MASK)
558 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
561 event->key.string = g_memdup ("\0\0", 2);
562 event->key.length = 1;
566 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
567 else if (c == '8') c = '\177';
568 else if (c == '/') c = '_' & 0x1F;
571 len = g_unichar_to_utf8 (c, buf);
574 event->key.string = g_locale_from_utf8 (buf, len,
575 NULL, &bytes_written,
577 if (event->key.string)
578 event->key.length = bytes_written;
580 else if (event->key.keyval == GDK_Escape)
582 event->key.length = 1;
583 event->key.string = g_strdup ("\033");
585 else if (event->key.keyval == GDK_Return ||
586 event->key.keyval == GDK_KP_Enter)
588 event->key.length = 1;
589 event->key.string = g_strdup ("\r");
592 if (!event->key.string)
594 event->key.length = 0;
595 event->key.string = g_strdup ("");
599 #ifdef G_ENABLE_DEBUG
600 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
602 g_message ("%s:\t\twindow: %ld key: %12s %d",
603 event->type == GDK_KEY_PRESS ? "key press " : "key release",
605 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
608 if (event->key.length > 0)
609 g_message ("\t\tlength: %4d string: \"%s\"",
610 event->key.length, buf);
612 #endif /* G_ENABLE_DEBUG */
615 /* Return the window this has to do with, if any, rather
616 * than the frame or root window that was selecting
620 get_real_window (XEvent *event)
625 return event->xcreatewindow.window;
628 return event->xdestroywindow.window;
631 return event->xunmap.window;
634 return event->xmap.window;
637 return event->xmaprequest.window;
640 return event->xreparent.window;
642 case ConfigureNotify:
643 return event->xconfigure.window;
645 case ConfigureRequest:
646 return event->xconfigurerequest.window;
649 return event->xgravity.window;
651 case CirculateNotify:
652 return event->xcirculate.window;
654 case CirculateRequest:
655 return event->xcirculaterequest.window;
658 return event->xany.window;
662 #ifdef G_ENABLE_DEBUG
663 static const char notify_modes[][18] = {
670 static const char notify_details[][22] = {
675 "NotifyNonlinearVirtual",
683 gdk_event_translate (GdkDisplay *display,
686 gboolean return_exposes)
690 GdkWindowObject *window_private;
691 GdkWindowImplX11 *window_impl = NULL;
693 gint xoffset, yoffset;
694 GdkScreen *screen = NULL;
695 GdkScreenX11 *screen_x11 = NULL;
696 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
701 /* init these, since the done: block uses them */
703 window_private = NULL;
704 event->any.window = NULL;
706 if (_gdk_default_filters)
708 /* Apply global filters */
709 GdkFilterReturn result;
710 result = gdk_event_apply_filters (xevent, event,
711 _gdk_default_filters);
713 if (result != GDK_FILTER_CONTINUE)
715 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
720 /* We handle events with window=None
721 * specially - they are generated by XFree86's XInput under
722 * some circumstances. This handling for obvious reasons
723 * goes before we bother to lookup the event window.
726 if (xevent->xany.window == None)
728 return_val = _gdk_input_window_none_event (event, xevent);
730 if (return_val >= 0) /* was handled */
736 /* Find the GdkWindow that this event relates to.
737 * Basically this means substructure events
738 * are reported same as structure events
740 xwindow = get_real_window (xevent);
742 window = gdk_window_lookup_for_display (display, xwindow);
743 window_private = (GdkWindowObject *) window;
747 screen = GDK_WINDOW_SCREEN (window);
748 screen_x11 = GDK_SCREEN_X11 (screen);
753 /* Window may be a pixmap, so check its type.
754 * (This check is probably too expensive unless
755 * GLib short-circuits an exact type match,
756 * which has been proposed)
758 if (GDK_IS_WINDOW (window))
760 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
762 /* Move key events on focus window to the real toplevel, and
763 * filter out all other events on focus window
765 if (xwindow == window_impl->focus_window)
767 switch (xevent->type)
771 xwindow = GDK_WINDOW_XID (window);
772 xevent->xany.window = xwindow;
780 g_object_ref (window);
783 event->any.window = window;
784 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
786 if (window_private && GDK_WINDOW_DESTROYED (window))
788 if (xevent->type != DestroyNotify)
794 else if (window_private)
796 /* Apply per-window filters */
797 GdkFilterReturn result;
798 result = gdk_event_apply_filters (xevent, event,
799 window_private->filters);
801 if (result != GDK_FILTER_CONTINUE)
803 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
808 if (screen_x11 && screen_x11->wmspec_check_window != None &&
809 xwindow == screen_x11->wmspec_check_window)
811 if (xevent->type == DestroyNotify)
813 screen_x11->wmspec_check_window = None;
814 g_free (screen_x11->window_manager_name);
815 screen_x11->window_manager_name = g_strdup ("unknown");
817 /* careful, reentrancy */
818 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
821 /* Eat events on this window unless someone had wrapped
822 * it as a foreign window
832 (xevent->xany.type == MotionNotify ||
833 xevent->xany.type == ButtonRelease))
835 if (_gdk_moveresize_handle_event (xevent))
842 /* We do a "manual" conversion of the XEvent to a
843 * GdkEvent. The structures are mostly the same so
844 * the conversion is fairly straightforward. We also
845 * optionally print debugging info regarding events
853 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
861 switch (xevent->type)
864 if (window_private == NULL)
869 translate_key_event (display, event, xevent);
873 if (window_private == NULL)
879 /* Emulate detectable auto-repeat by checking to see
880 * if the next event is a key press with the same
881 * keycode and timestamp, and if so, ignoring the event.
884 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
888 XPeekEvent (xevent->xkey.display, &next_event);
890 if (next_event.type == KeyPress &&
891 next_event.xkey.keycode == xevent->xkey.keycode &&
892 next_event.xkey.time == xevent->xkey.time)
899 translate_key_event (display, event, xevent);
904 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
905 xevent->xbutton.window,
906 xevent->xbutton.x, xevent->xbutton.y,
907 xevent->xbutton.button));
909 if (window_private == NULL ||
910 ((window_private->extension_events != 0) &&
911 display_x11->input_ignore_core))
917 /* If we get a ButtonPress event where the button is 4 or 5,
918 it's a Scroll event */
919 switch (xevent->xbutton.button)
925 event->scroll.type = GDK_SCROLL;
927 if (xevent->xbutton.button == 4)
928 event->scroll.direction = GDK_SCROLL_UP;
929 else if (xevent->xbutton.button == 5)
930 event->scroll.direction = GDK_SCROLL_DOWN;
931 else if (xevent->xbutton.button == 6)
932 event->scroll.direction = GDK_SCROLL_LEFT;
934 event->scroll.direction = GDK_SCROLL_RIGHT;
936 event->scroll.window = window;
937 event->scroll.time = xevent->xbutton.time;
938 event->scroll.x = xevent->xbutton.x + xoffset;
939 event->scroll.y = xevent->xbutton.y + yoffset;
940 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
941 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
942 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
943 event->scroll.device = display->core_pointer;
945 set_screen_from_root (display, event, xevent->xbutton.root);
950 event->button.type = GDK_BUTTON_PRESS;
951 event->button.window = window;
952 event->button.time = xevent->xbutton.time;
953 event->button.x = xevent->xbutton.x + xoffset;
954 event->button.y = xevent->xbutton.y + yoffset;
955 event->button.x_root = (gfloat)xevent->xbutton.x_root;
956 event->button.y_root = (gfloat)xevent->xbutton.y_root;
957 event->button.axes = NULL;
958 event->button.state = (GdkModifierType) xevent->xbutton.state;
959 event->button.button = xevent->xbutton.button;
960 event->button.device = display->core_pointer;
962 set_screen_from_root (display, event, xevent->xbutton.root);
964 _gdk_event_button_generate (display, event);
972 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
973 xevent->xbutton.window,
974 xevent->xbutton.x, xevent->xbutton.y,
975 xevent->xbutton.button));
977 if (window_private == NULL ||
978 ((window_private->extension_events != 0) &&
979 display_x11->input_ignore_core))
985 /* We treat button presses as scroll wheel events, so ignore the release */
986 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
987 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
993 event->button.type = GDK_BUTTON_RELEASE;
994 event->button.window = window;
995 event->button.time = xevent->xbutton.time;
996 event->button.x = xevent->xbutton.x + xoffset;
997 event->button.y = xevent->xbutton.y + yoffset;
998 event->button.x_root = (gfloat)xevent->xbutton.x_root;
999 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1000 event->button.axes = NULL;
1001 event->button.state = (GdkModifierType) xevent->xbutton.state;
1002 event->button.button = xevent->xbutton.button;
1003 event->button.device = display->core_pointer;
1005 set_screen_from_root (display, event, xevent->xbutton.root);
1011 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1012 xevent->xmotion.window,
1013 xevent->xmotion.x, xevent->xmotion.y,
1014 (xevent->xmotion.is_hint) ? "true" : "false"));
1016 if (window_private == NULL ||
1017 ((window_private->extension_events != 0) &&
1018 display_x11->input_ignore_core))
1024 event->motion.type = GDK_MOTION_NOTIFY;
1025 event->motion.window = window;
1026 event->motion.time = xevent->xmotion.time;
1027 event->motion.x = xevent->xmotion.x + xoffset;
1028 event->motion.y = xevent->xmotion.y + yoffset;
1029 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1030 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1031 event->motion.axes = NULL;
1032 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1033 event->motion.is_hint = xevent->xmotion.is_hint;
1034 event->motion.device = display->core_pointer;
1036 set_screen_from_root (display, event, xevent->xmotion.root);
1042 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1043 xevent->xcrossing.window,
1044 xevent->xcrossing.detail,
1045 xevent->xcrossing.subwindow));
1047 if (window_private == NULL)
1053 /* Handle focusing (in the case where no window manager is running */
1055 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1056 xevent->xcrossing.detail != NotifyInferior &&
1057 xevent->xcrossing.focus && !window_impl->has_focus_window)
1059 gboolean had_focus = HAS_FOCUS (window_impl);
1061 window_impl->has_pointer_focus = TRUE;
1063 if (HAS_FOCUS (window_impl) != had_focus)
1064 generate_focus_event (window, TRUE);
1067 /* Tell XInput stuff about it if appropriate */
1068 if (window_private &&
1069 !GDK_WINDOW_DESTROYED (window) &&
1070 window_private->extension_events != 0)
1071 _gdk_input_enter_event (&xevent->xcrossing, window);
1073 event->crossing.type = GDK_ENTER_NOTIFY;
1074 event->crossing.window = window;
1076 /* If the subwindow field of the XEvent is non-NULL, then
1077 * lookup the corresponding GdkWindow.
1079 if (xevent->xcrossing.subwindow != None)
1080 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1082 event->crossing.subwindow = NULL;
1084 event->crossing.time = xevent->xcrossing.time;
1085 event->crossing.x = xevent->xcrossing.x + xoffset;
1086 event->crossing.y = xevent->xcrossing.y + yoffset;
1087 event->crossing.x_root = xevent->xcrossing.x_root;
1088 event->crossing.y_root = xevent->xcrossing.y_root;
1090 set_screen_from_root (display, event, xevent->xcrossing.root);
1092 /* Translate the crossing mode into Gdk terms.
1094 switch (xevent->xcrossing.mode)
1097 event->crossing.mode = GDK_CROSSING_NORMAL;
1100 event->crossing.mode = GDK_CROSSING_GRAB;
1103 event->crossing.mode = GDK_CROSSING_UNGRAB;
1107 /* Translate the crossing detail into Gdk terms.
1109 switch (xevent->xcrossing.detail)
1111 case NotifyInferior:
1112 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1114 case NotifyAncestor:
1115 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1118 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1120 case NotifyNonlinear:
1121 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1123 case NotifyNonlinearVirtual:
1124 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1127 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1131 event->crossing.focus = xevent->xcrossing.focus;
1132 event->crossing.state = xevent->xcrossing.state;
1138 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1139 xevent->xcrossing.window,
1140 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1142 if (window_private == NULL)
1148 /* Handle focusing (in the case where no window manager is running */
1150 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1151 xevent->xcrossing.detail != NotifyInferior &&
1152 xevent->xcrossing.focus && !window_impl->has_focus_window)
1154 gboolean had_focus = HAS_FOCUS (window_impl);
1156 window_impl->has_pointer_focus = FALSE;
1158 if (HAS_FOCUS (window_impl) != had_focus)
1159 generate_focus_event (window, FALSE);
1162 event->crossing.type = GDK_LEAVE_NOTIFY;
1163 event->crossing.window = window;
1165 /* If the subwindow field of the XEvent is non-NULL, then
1166 * lookup the corresponding GdkWindow.
1168 if (xevent->xcrossing.subwindow != None)
1169 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1171 event->crossing.subwindow = NULL;
1173 event->crossing.time = xevent->xcrossing.time;
1174 event->crossing.x = xevent->xcrossing.x + xoffset;
1175 event->crossing.y = xevent->xcrossing.y + yoffset;
1176 event->crossing.x_root = xevent->xcrossing.x_root;
1177 event->crossing.y_root = xevent->xcrossing.y_root;
1179 set_screen_from_root (display, event, xevent->xcrossing.root);
1181 /* Translate the crossing mode into Gdk terms.
1183 switch (xevent->xcrossing.mode)
1186 event->crossing.mode = GDK_CROSSING_NORMAL;
1189 event->crossing.mode = GDK_CROSSING_GRAB;
1192 event->crossing.mode = GDK_CROSSING_UNGRAB;
1196 /* Translate the crossing detail into Gdk terms.
1198 switch (xevent->xcrossing.detail)
1200 case NotifyInferior:
1201 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1203 case NotifyAncestor:
1204 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1207 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1209 case NotifyNonlinear:
1210 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1212 case NotifyNonlinearVirtual:
1213 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1216 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1220 event->crossing.focus = xevent->xcrossing.focus;
1221 event->crossing.state = xevent->xcrossing.state;
1225 /* We only care about focus events that indicate that _this_
1226 * window (not a ancestor or child) got or lost the focus
1230 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1231 xevent->xfocus.window,
1232 notify_details[xevent->xfocus.detail],
1233 notify_modes[xevent->xfocus.mode]));
1235 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1237 gboolean had_focus = HAS_FOCUS (window_impl);
1239 switch (xevent->xfocus.detail)
1241 case NotifyAncestor:
1242 case NotifyNonlinear:
1244 case NotifyNonlinearVirtual:
1245 /* We pretend that the focus moves to the grab
1246 * window, so we pay attention to NotifyGrab
1247 * NotifyUngrab, and ignore NotifyWhileGrabbed
1249 window_impl->has_focus_window = TRUE;
1250 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1251 window_impl->has_focus = TRUE;
1254 /* The X server sends NotifyPointer/NotifyGrab,
1255 * but the pointer focus is ignored while a
1258 if (xevent->xfocus.mode != NotifyGrab)
1259 window_impl->has_pointer_focus = TRUE;
1261 case NotifyInferior:
1262 case NotifyPointerRoot:
1263 case NotifyDetailNone:
1267 if (HAS_FOCUS (window_impl) != had_focus)
1268 generate_focus_event (window, TRUE);
1273 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1274 xevent->xfocus.window,
1275 notify_details[xevent->xfocus.detail],
1276 notify_modes[xevent->xfocus.mode]));
1278 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1280 gboolean had_focus = HAS_FOCUS (window_impl);
1282 switch (xevent->xfocus.detail)
1284 case NotifyAncestor:
1285 case NotifyNonlinear:
1287 case NotifyNonlinearVirtual:
1288 window_impl->has_focus_window = FALSE;
1289 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1290 window_impl->has_focus = FALSE;
1293 if (xevent->xfocus.mode != NotifyUngrab)
1294 window_impl->has_pointer_focus = FALSE;
1296 case NotifyInferior:
1297 case NotifyPointerRoot:
1298 case NotifyDetailNone:
1302 if (HAS_FOCUS (window_impl) != had_focus)
1303 generate_focus_event (window, FALSE);
1308 /* gdk_keyboard_grab() causes following events. These events confuse
1309 * the XIM focus, so ignore them.
1311 if (xevent->xfocus.mode == NotifyGrab ||
1312 xevent->xfocus.mode == NotifyUngrab)
1318 g_message ("keymap notify"));
1320 /* Not currently handled */
1326 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1327 xevent->xexpose.window, xevent->xexpose.count,
1328 xevent->xexpose.x, xevent->xexpose.y,
1329 xevent->xexpose.width, xevent->xexpose.height,
1330 event->any.send_event ? " (send)" : ""));
1332 if (window_private == NULL)
1339 GdkRectangle expose_rect;
1341 expose_rect.x = xevent->xexpose.x + xoffset;
1342 expose_rect.y = xevent->xexpose.y + yoffset;
1343 expose_rect.width = xevent->xexpose.width;
1344 expose_rect.height = xevent->xexpose.height;
1348 event->expose.type = GDK_EXPOSE;
1349 event->expose.area = expose_rect;
1350 event->expose.region = gdk_region_rectangle (&expose_rect);
1351 event->expose.window = window;
1352 event->expose.count = xevent->xexpose.count;
1358 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1367 case GraphicsExpose:
1369 GdkRectangle expose_rect;
1372 g_message ("graphics expose:\tdrawable: %ld",
1373 xevent->xgraphicsexpose.drawable));
1375 if (window_private == NULL)
1381 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1382 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1383 expose_rect.width = xevent->xgraphicsexpose.width;
1384 expose_rect.height = xevent->xgraphicsexpose.height;
1388 event->expose.type = GDK_EXPOSE;
1389 event->expose.area = expose_rect;
1390 event->expose.region = gdk_region_rectangle (&expose_rect);
1391 event->expose.window = window;
1392 event->expose.count = xevent->xgraphicsexpose.count;
1398 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1408 g_message ("no expose:\t\tdrawable: %ld",
1409 xevent->xnoexpose.drawable));
1411 event->no_expose.type = GDK_NO_EXPOSE;
1412 event->no_expose.window = window;
1416 case VisibilityNotify:
1417 #ifdef G_ENABLE_DEBUG
1418 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1419 switch (xevent->xvisibility.state)
1421 case VisibilityFullyObscured:
1422 g_message ("visibility notify:\twindow: %ld none",
1423 xevent->xvisibility.window);
1425 case VisibilityPartiallyObscured:
1426 g_message ("visibility notify:\twindow: %ld partial",
1427 xevent->xvisibility.window);
1429 case VisibilityUnobscured:
1430 g_message ("visibility notify:\twindow: %ld full",
1431 xevent->xvisibility.window);
1434 #endif /* G_ENABLE_DEBUG */
1436 if (window_private == NULL)
1442 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1443 event->visibility.window = window;
1445 switch (xevent->xvisibility.state)
1447 case VisibilityFullyObscured:
1448 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1451 case VisibilityPartiallyObscured:
1452 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1455 case VisibilityUnobscured:
1456 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1464 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1465 xevent->xcreatewindow.window,
1466 xevent->xcreatewindow.x,
1467 xevent->xcreatewindow.y,
1468 xevent->xcreatewindow.width,
1469 xevent->xcreatewindow.height,
1470 xevent->xcreatewindow.border_width,
1471 xevent->xcreatewindow.parent,
1472 xevent->xcreatewindow.override_redirect));
1473 /* not really handled */
1478 g_message ("destroy notify:\twindow: %ld",
1479 xevent->xdestroywindow.window));
1481 /* Ignore DestroyNotify from SubstructureNotifyMask */
1482 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1484 event->any.type = GDK_DESTROY;
1485 event->any.window = window;
1487 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1489 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1490 gdk_window_destroy_notify (window);
1499 g_message ("unmap notify:\t\twindow: %ld",
1500 xevent->xmap.window));
1502 event->any.type = GDK_UNMAP;
1503 event->any.window = window;
1505 /* If we are shown (not withdrawn) and get an unmap, it means we
1506 * were iconified in the X sense. If we are withdrawn, and get
1507 * an unmap, it means we hid the window ourselves, so we
1508 * will have already flipped the iconified bit off.
1512 if (GDK_WINDOW_IS_MAPPED (window))
1513 gdk_synthesize_window_state (window,
1515 GDK_WINDOW_STATE_ICONIFIED);
1517 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1524 g_message ("map notify:\t\twindow: %ld",
1525 xevent->xmap.window));
1527 event->any.type = GDK_MAP;
1528 event->any.window = window;
1530 /* Unset iconified if it was set */
1531 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1532 gdk_synthesize_window_state (window,
1533 GDK_WINDOW_STATE_ICONIFIED,
1538 case ReparentNotify:
1540 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1541 xevent->xreparent.window,
1542 xevent->xreparent.x,
1543 xevent->xreparent.y,
1544 xevent->xreparent.parent,
1545 xevent->xreparent.override_redirect));
1547 /* Not currently handled */
1551 case ConfigureNotify:
1553 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1554 xevent->xconfigure.window,
1555 xevent->xconfigure.x,
1556 xevent->xconfigure.y,
1557 xevent->xconfigure.width,
1558 xevent->xconfigure.height,
1559 xevent->xconfigure.border_width,
1560 xevent->xconfigure.above,
1561 xevent->xconfigure.override_redirect,
1564 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1565 ? " (discarding child)"
1566 : xevent->xconfigure.event != xevent->xconfigure.window
1567 ? " (discarding substructure)"
1569 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1570 _gdk_x11_screen_size_changed (screen, xevent);
1573 xevent->xconfigure.event == xevent->xconfigure.window &&
1574 !GDK_WINDOW_DESTROYED (window) &&
1575 (window_private->extension_events != 0))
1576 _gdk_input_configure_event (&xevent->xconfigure, window);
1579 xevent->xconfigure.event != xevent->xconfigure.window ||
1580 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1581 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1585 event->configure.type = GDK_CONFIGURE;
1586 event->configure.window = window;
1587 event->configure.width = xevent->xconfigure.width;
1588 event->configure.height = xevent->xconfigure.height;
1590 if (!xevent->xconfigure.send_event &&
1591 !GDK_WINDOW_DESTROYED (window))
1595 Window child_window = 0;
1597 gdk_error_trap_push ();
1598 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1599 GDK_DRAWABLE_XID (window),
1600 screen_x11->xroot_window,
1605 if (!gdk_error_trap_pop ())
1607 event->configure.x = tx;
1608 event->configure.y = ty;
1612 gdk_error_trap_pop ();
1616 event->configure.x = xevent->xconfigure.x;
1617 event->configure.y = xevent->xconfigure.y;
1619 window_private->x = event->configure.x;
1620 window_private->y = event->configure.y;
1621 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1622 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1623 if (window_private->resize_count >= 1)
1625 window_private->resize_count -= 1;
1627 if (window_private->resize_count == 0)
1628 _gdk_moveresize_configure_done (display, window);
1633 case PropertyNotify:
1635 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1636 xevent->xproperty.window,
1637 xevent->xproperty.atom,
1639 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1642 if (window_private == NULL)
1648 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE") ||
1649 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1651 /* If window state changed, then synthesize those events. */
1652 gdk_check_wm_state_changed (window);
1655 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1657 event->property.type = GDK_PROPERTY_NOTIFY;
1658 event->property.window = window;
1659 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1660 event->property.time = xevent->xproperty.time;
1661 event->property.state = xevent->xproperty.state;
1668 case SelectionClear:
1670 g_message ("selection clear:\twindow: %ld",
1671 xevent->xproperty.window));
1673 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1675 event->selection.type = GDK_SELECTION_CLEAR;
1676 event->selection.window = window;
1677 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1678 event->selection.time = xevent->xselectionclear.time;
1685 case SelectionRequest:
1687 g_message ("selection request:\twindow: %ld",
1688 xevent->xproperty.window));
1690 event->selection.type = GDK_SELECTION_REQUEST;
1691 event->selection.window = window;
1692 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1693 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1694 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1695 event->selection.requestor = xevent->xselectionrequest.requestor;
1696 event->selection.time = xevent->xselectionrequest.time;
1700 case SelectionNotify:
1702 g_message ("selection notify:\twindow: %ld",
1703 xevent->xproperty.window));
1706 event->selection.type = GDK_SELECTION_NOTIFY;
1707 event->selection.window = window;
1708 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1709 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1710 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1711 event->selection.time = xevent->xselection.time;
1715 case ColormapNotify:
1717 g_message ("colormap notify:\twindow: %ld",
1718 xevent->xcolormap.window));
1720 /* Not currently handled */
1727 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1728 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1731 g_message ("client message:\twindow: %ld",
1732 xevent->xclient.window));
1734 tmp_list = display_x11->client_filters;
1737 GdkClientFilter *filter = tmp_list->data;
1738 if (filter->type == message_type)
1740 result = (*filter->function) (xevent, event, filter->data);
1744 tmp_list = tmp_list->next;
1749 case GDK_FILTER_REMOVE:
1752 case GDK_FILTER_TRANSLATE:
1755 case GDK_FILTER_CONTINUE:
1756 /* Send unknown ClientMessage's on to Gtk for it to use */
1757 if (window_private == NULL)
1763 event->client.type = GDK_CLIENT_EVENT;
1764 event->client.window = window;
1765 event->client.message_type = message_type;
1766 event->client.data_format = xevent->xclient.format;
1767 memcpy(&event->client.data, &xevent->xclient.data,
1768 sizeof(event->client.data));
1778 g_message ("mapping notify"));
1780 /* Let XLib know that there is a new keyboard mapping.
1782 XRefreshKeyboardMapping (&xevent->xmapping);
1783 _gdk_keymap_keys_changed (display);
1789 if (xevent->type == display_x11->xkb_event_type)
1791 XkbEvent *xkb_event = (XkbEvent *)xevent;
1793 switch (xkb_event->any.xkb_type)
1796 _gdk_keymap_keys_changed (display);
1801 case XkbStateNotify:
1802 _gdk_keymap_state_changed (display);
1809 /* something else - (e.g., a Xinput event) */
1811 if (window_private &&
1812 !GDK_WINDOW_DESTROYED (window_private) &&
1813 (window_private->extension_events != 0))
1814 return_val = _gdk_input_other_event(event, xevent, window);
1825 if (event->any.window)
1826 g_object_ref (event->any.window);
1827 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1828 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1829 (event->crossing.subwindow != NULL))
1830 g_object_ref (event->crossing.subwindow);
1834 /* Mark this event as having no resources to be freed */
1835 event->any.window = NULL;
1836 event->any.type = GDK_NOTHING;
1840 g_object_unref (window);
1845 static GdkFilterReturn
1846 gdk_wm_protocols_filter (GdkXEvent *xev,
1850 XEvent *xevent = (XEvent *)xev;
1851 GdkWindow *win = event->any.window;
1852 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1854 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1856 /* The delete window request specifies a window
1857 * to delete. We don't actually destroy the
1858 * window because "it is only a request". (The
1859 * window might contain vital data that the
1860 * program does not want destroyed). Instead
1861 * the event is passed along to the program,
1862 * which should then destroy the window.
1865 g_message ("delete window:\t\twindow: %ld",
1866 xevent->xclient.window));
1868 event->any.type = GDK_DELETE;
1870 return GDK_FILTER_TRANSLATE;
1872 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1874 GdkWindow *win = event->any.window;
1875 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1877 /* There is no way of knowing reliably whether we are viewable so we need
1878 * to trap errors so we don't cause a BadMatch.
1880 gdk_error_trap_push ();
1881 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1884 xevent->xclient.data.l[1]);
1885 XSync (GDK_WINDOW_XDISPLAY (win), False);
1886 gdk_error_trap_pop ();
1888 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING"))
1890 XEvent xev = *xevent;
1892 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1893 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1896 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1899 return GDK_FILTER_REMOVE;
1903 _gdk_events_queue (GdkDisplay *display)
1908 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1910 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1912 XNextEvent (xdisplay, &xevent);
1914 switch (xevent.type)
1920 if (XFilterEvent (&xevent, None))
1924 event = gdk_event_new (GDK_NOTHING);
1926 event->any.window = NULL;
1927 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1929 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1931 node = _gdk_event_queue_append (display, event);
1933 if (gdk_event_translate (display, event, &xevent, FALSE))
1935 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1939 _gdk_event_queue_remove_link (display, node);
1940 g_list_free_1 (node);
1941 gdk_event_free (event);
1947 gdk_event_prepare (GSource *source,
1950 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1953 GDK_THREADS_ENTER ();
1956 retval = (_gdk_event_queue_find_first (display) != NULL ||
1957 gdk_check_xpending (display));
1959 GDK_THREADS_LEAVE ();
1965 gdk_event_check (GSource *source)
1967 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
1970 GDK_THREADS_ENTER ();
1972 if (display_source->event_poll_fd.revents & G_IO_IN)
1973 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
1974 gdk_check_xpending (display_source->display));
1978 GDK_THREADS_LEAVE ();
1984 gdk_event_dispatch (GSource *source,
1985 GSourceFunc callback,
1988 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1991 GDK_THREADS_ENTER ();
1993 _gdk_events_queue (display);
1994 event = _gdk_event_unqueue (display);
1998 if (_gdk_event_func)
1999 (*_gdk_event_func) (event, _gdk_event_data);
2001 gdk_event_free (event);
2004 GDK_THREADS_LEAVE ();
2010 * gdk_event_send_client_message_for_display:
2011 * @display: the #GdkDisplay for the window where the message is to be sent.
2012 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2013 * @winid: the window to send the X ClientMessage event to.
2015 * Sends an X ClientMessage event to a given window.
2017 * This could be used for communicating between different applications,
2018 * though the amount of data is limited to 20 bytes.
2020 * Returns: non-zero on success.
2025 gdk_event_send_client_message_for_display (GdkDisplay *display,
2027 GdkNativeWindow winid)
2031 g_return_val_if_fail(event != NULL, FALSE);
2033 /* Set up our event to send, with the exception of its target window */
2034 sev.xclient.type = ClientMessage;
2035 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2036 sev.xclient.format = event->client.data_format;
2037 sev.xclient.window = winid;
2038 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2039 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2041 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2046 /* Sends a ClientMessage to all toplevel client windows */
2048 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2055 unsigned long nitems, after;
2056 unsigned char *data;
2057 Window *ret_children, ret_root, ret_parent;
2058 unsigned int ret_nchildren;
2059 gboolean send = FALSE;
2060 gboolean found = FALSE;
2061 gboolean result = FALSE;
2064 gdk_error_trap_push ();
2066 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2067 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
2068 0, 0, False, AnyPropertyType,
2069 &type, &format, &nitems, &after, &data) != Success)
2079 /* OK, we're all set, now let's find some windows to send this to */
2080 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2081 &ret_root, &ret_parent,
2082 &ret_children, &ret_nchildren))
2085 for(i = 0; i < ret_nchildren; i++)
2086 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2089 XFree (ret_children);
2092 if (send || (!found && (level == 1)))
2094 xev->xclient.window = xid;
2095 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2098 result = send || found;
2101 gdk_error_trap_pop ();
2107 * gdk_screen_broadcast_client_message:
2108 * @screen: the #GdkScreen where the event will be broadcasted.
2109 * @event: the #GdkEvent.
2111 * Sends an X ClientMessage event to all toplevel windows on @screen.
2113 * Toplevel windows are determined by checking for the WM_STATE property,
2114 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2115 * If no windows are found with the WM_STATE property set, the message is
2116 * sent to all children of the root window.
2122 gdk_screen_broadcast_client_message (GdkScreen *screen,
2126 GdkWindow *root_window;
2128 g_return_if_fail (event != NULL);
2130 root_window = gdk_screen_get_root_window (screen);
2132 /* Set up our event to send, with the exception of its target window */
2133 sev.xclient.type = ClientMessage;
2134 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2135 sev.xclient.format = event->client.data_format;
2136 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2137 sev.xclient.message_type =
2138 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2139 event->client.message_type);
2141 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2143 GDK_WINDOW_XID (root_window),
2148 *--------------------------------------------------------------
2151 * Flushes the Xlib output buffer and then waits
2152 * until all requests have been received and processed
2153 * by the X server. The only real use for this function
2154 * is in dealing with XShm.
2162 *--------------------------------------------------------------
2168 GSList *tmp_list = _gdk_displays;
2172 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2173 tmp_list = tmp_list->next;
2178 timestamp_predicate (Display *display,
2182 Window xwindow = GPOINTER_TO_UINT (arg);
2183 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2185 if (xevent->type == PropertyNotify &&
2186 xevent->xproperty.window == xwindow &&
2187 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display
2188 (gdk_display, "GDK_TIMESTAMP_PROP"))
2195 * gdk_x11_get_server_time:
2196 * @window: a #GdkWindow, used for communication with the server.
2197 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2198 * events mask or a hang will result.
2200 * Routine to get the current X server time stamp.
2202 * Return value: the time stamp.
2205 gdk_x11_get_server_time (GdkWindow *window)
2211 Atom timestamp_prop_atom;
2213 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2214 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2216 xdisplay = GDK_WINDOW_XDISPLAY (window);
2217 xwindow = GDK_WINDOW_XWINDOW (window);
2218 timestamp_prop_atom =
2219 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2220 "GDK_TIMESTAMP_PROP");
2222 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2223 timestamp_prop_atom,
2224 8, PropModeReplace, &c, 1);
2226 XIfEvent (xdisplay, &xevent,
2227 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2229 return xevent.xproperty.time;
2233 fetch_net_wm_check_window (GdkScreen *screen)
2235 GdkScreenX11 *screen_x11;
2236 GdkDisplay *display;
2243 /* This function is very slow on every call if you are not running a
2244 * spec-supporting WM. For now not optimized, because it isn't in
2245 * any critical code paths, but if you used it somewhere that had to
2246 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2247 * Probably at that point the function should be changed to query
2248 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2251 screen_x11 = GDK_SCREEN_X11 (screen);
2252 display = screen_x11->display;
2254 if (screen_x11->wmspec_check_window != None)
2255 return; /* already have it */
2257 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2258 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2259 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2260 &n_items, &bytes_after, (guchar **) & xwindow);
2262 if (type != XA_WINDOW)
2265 gdk_error_trap_push ();
2267 /* Find out if this WM goes away, so we can reset everything. */
2268 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2270 screen_x11->wmspec_check_window = *xwindow;
2273 screen_x11->need_refetch_net_supported = TRUE;
2274 screen_x11->need_refetch_wm_name = TRUE;
2276 /* Careful, reentrancy */
2277 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2281 * gdk_x11_screen_get_window_manager_name:
2282 * @screen: a #GdkScreen
2284 * Returns the name of the window manager for @screen.
2286 * Return value: the name of the window manager screen @screen, or
2287 * "unknown" if the window manager is unknown. The string is owned by GDK
2288 * and should not be freed.
2293 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2295 GdkScreenX11 *screen_x11;
2297 screen_x11 = GDK_SCREEN_X11 (screen);
2299 fetch_net_wm_check_window (screen);
2301 if (screen_x11->need_refetch_wm_name)
2303 /* Get the name of the window manager */
2304 screen_x11->need_refetch_wm_name = FALSE;
2306 g_free (screen_x11->window_manager_name);
2307 screen_x11->window_manager_name = g_strdup ("unknown");
2309 if (screen_x11->wmspec_check_window != None)
2319 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2320 screen_x11->wmspec_check_window,
2321 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2323 0, G_MAXLONG, False,
2324 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2327 &n_items, &bytes_after,
2330 gdk_display_sync (screen_x11->display);
2332 gdk_error_trap_pop ();
2336 g_free (screen_x11->window_manager_name);
2337 screen_x11->window_manager_name = g_strdup (name);
2343 return GDK_SCREEN_X11 (screen)->window_manager_name;
2346 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2348 struct _NetWmSupportedAtoms
2355 * gdk_x11_screen_supports_net_wm_hint:
2356 * @screen: the relevant #GdkScreen.
2357 * @property: a property atom.
2359 * This function is specific to the X11 backend of GDK, and indicates
2360 * whether the window manager supports a certain hint from the
2361 * Extended Window Manager Hints Specification. You can find this
2363 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2365 * When using this function, keep in mind that the window manager
2366 * can change over time; so you shouldn't use this function in
2367 * a way that impacts persistent application state. A common bug
2368 * is that your application can start up before the window manager
2369 * does when the user logs in, and before the window manager starts
2370 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2371 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2372 * a window manager change.
2374 * Return value: %TRUE if the window manager supports @property
2379 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2383 GdkScreenX11 *screen_x11;
2384 NetWmSupportedAtoms *supported_atoms;
2385 GdkDisplay *display;
2387 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2389 screen_x11 = GDK_SCREEN_X11 (screen);
2390 display = screen_x11->display;
2392 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2393 if (!supported_atoms)
2395 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2396 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2399 fetch_net_wm_check_window (screen);
2401 if (screen_x11->wmspec_check_window == None)
2404 if (screen_x11->need_refetch_net_supported)
2406 /* WM has changed since we last got the supported list,
2413 screen_x11->need_refetch_net_supported = FALSE;
2415 if (supported_atoms->atoms)
2416 XFree (supported_atoms->atoms);
2418 supported_atoms->atoms = NULL;
2419 supported_atoms->n_atoms = 0;
2421 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2422 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2423 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2424 &supported_atoms->n_atoms, &bytes_after,
2425 (guchar **)&supported_atoms->atoms);
2427 if (type != XA_ATOM)
2431 if (supported_atoms->atoms == NULL)
2435 while (i < supported_atoms->n_atoms)
2437 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2447 * gdk_net_wm_supports:
2448 * @property: a property atom.
2450 * This function is specific to the X11 backend of GDK, and indicates
2451 * whether the window manager for the default screen supports a certain
2452 * hint from the Extended Window Manager Hints Specification. See
2453 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2455 * Return value: %TRUE if the window manager supports @property
2458 gdk_net_wm_supports (GdkAtom property)
2460 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2465 const char *xsettings_name;
2466 const char *gdk_name;
2467 } settings_map[] = {
2468 { "Net/DoubleClickTime", "gtk-double-click-time" },
2469 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2470 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2471 { "Gtk/ColorPalette", "gtk-color-palette" },
2472 { "Gtk/FontName", "gtk-font-name" },
2473 { "Gtk/IconSizes", "gtk-icon-sizes" },
2474 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2475 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2476 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2477 { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
2478 { "Gtk/IMStatusStyle", "gtk-im-status-style" },
2479 { "Net/CursorBlink", "gtk-cursor-blink" },
2480 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2481 { "Net/ThemeName", "gtk-theme-name" }
2485 gdk_xsettings_notify_cb (const char *name,
2486 XSettingsAction action,
2487 XSettingsSetting *setting,
2491 GdkScreen *screen = data;
2492 GdkScreenX11 *screen_x11 = data;
2495 if (screen_x11->xsettings_in_init)
2498 new_event.type = GDK_SETTING;
2499 new_event.setting.window = gdk_screen_get_root_window (screen);
2500 new_event.setting.send_event = FALSE;
2501 new_event.setting.name = NULL;
2503 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2504 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2506 new_event.setting.name = (char *)settings_map[i].gdk_name;
2511 if (!new_event.setting.name)
2516 case XSETTINGS_ACTION_NEW:
2517 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2519 case XSETTINGS_ACTION_CHANGED:
2520 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2522 case XSETTINGS_ACTION_DELETED:
2523 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2527 gdk_event_put (&new_event);
2531 check_transform (const gchar *xsettings_name,
2535 if (!g_value_type_transformable (src_type, dest_type))
2537 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2539 g_type_name (src_type),
2540 g_type_name (dest_type));
2548 * gdk_screen_get_setting:
2549 * @screen: the #GdkScreen where the setting is located
2550 * @name: the name of the setting
2551 * @value: location to store the value of the setting
2553 * Retrieves a desktop-wide setting such as double-click time
2554 * for the #GdkScreen @screen.
2556 * FIXME needs a list of valid settings here, or a link to
2559 * Returns: %TRUE if the setting existed and a value was stored
2560 * in @value, %FALSE otherwise.
2565 gdk_screen_get_setting (GdkScreen *screen,
2570 const char *xsettings_name = NULL;
2571 XSettingsResult result;
2572 XSettingsSetting *setting;
2573 GdkScreenX11 *screen_x11;
2574 gboolean success = FALSE;
2576 GValue tmp_val = { 0, };
2578 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2580 screen_x11 = GDK_SCREEN_X11 (screen);
2582 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2583 if (strcmp (settings_map[i].gdk_name, name) == 0)
2585 xsettings_name = settings_map[i].xsettings_name;
2589 if (!xsettings_name)
2592 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2593 xsettings_name, &setting);
2594 if (result != XSETTINGS_SUCCESS)
2597 switch (setting->type)
2599 case XSETTINGS_TYPE_INT:
2600 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2602 g_value_init (&tmp_val, G_TYPE_INT);
2603 g_value_set_int (&tmp_val, setting->data.v_int);
2604 g_value_transform (&tmp_val, value);
2609 case XSETTINGS_TYPE_STRING:
2610 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2612 g_value_init (&tmp_val, G_TYPE_STRING);
2613 g_value_set_string (&tmp_val, setting->data.v_string);
2614 g_value_transform (&tmp_val, value);
2619 case XSETTINGS_TYPE_COLOR:
2620 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2624 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2627 color.red = setting->data.v_color.red;
2628 color.green = setting->data.v_color.green;
2629 color.blue = setting->data.v_color.blue;
2631 g_value_set_boxed (&tmp_val, &color);
2633 g_value_transform (&tmp_val, value);
2640 g_value_unset (&tmp_val);
2642 xsettings_setting_free (setting);
2647 static GdkFilterReturn
2648 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2652 GdkScreenX11 *screen = data;
2654 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2655 return GDK_FILTER_REMOVE;
2657 return GDK_FILTER_CONTINUE;
2661 gdk_xsettings_watch_cb (Window window,
2667 GdkScreen *screen = cb_data;
2669 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2674 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2676 g_object_ref (gdkwin);
2678 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2683 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2684 g_object_unref (gdkwin);