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"
35 #include "gdkkeysyms.h"
37 #include "xsettings-client.h"
46 #include "gdkinputprivate.h"
49 #include <X11/XKBlib.h>
52 #include <X11/Xatom.h>
54 typedef struct _GdkIOClosure GdkIOClosure;
55 typedef struct _GdkDisplaySource GdkDisplaySource;
57 #define DOUBLE_CLICK_TIME 250
58 #define TRIPLE_CLICK_TIME 500
59 #define DOUBLE_CLICK_DIST 5
60 #define TRIPLE_CLICK_DIST 5
64 GdkInputFunction function;
65 GdkInputCondition condition;
66 GdkDestroyNotify notify;
70 struct _GdkDisplaySource
75 GPollFD event_poll_fd;
79 * Private function declarations
82 static gint gdk_event_apply_filters (XEvent *xevent,
85 static gboolean gdk_event_translate (GdkDisplay *display,
88 gboolean return_exposes);
90 static gboolean gdk_event_prepare (GSource *source,
92 static gboolean gdk_event_check (GSource *source);
93 static gboolean gdk_event_dispatch (GSource *source,
97 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
101 static GSource *gdk_display_source_new (GdkDisplay *display);
102 static gboolean gdk_check_xpending (GdkDisplay *display);
104 static void gdk_xsettings_watch_cb (Window window,
108 static void gdk_xsettings_notify_cb (const char *name,
109 XSettingsAction action,
110 XSettingsSetting *setting,
113 /* Private variable declarations
116 static GList *display_sources;
118 static GSourceFuncs event_funcs = {
126 gdk_display_source_new (GdkDisplay *display)
128 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
129 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
131 display_source->display = display;
137 gdk_check_xpending (GdkDisplay *display)
139 return XPending (GDK_DISPLAY_XDISPLAY (display));
142 /*********************************************
143 * Functions for maintaining the event queue *
144 *********************************************/
147 _gdk_x11_events_init_screen (GdkScreen *screen)
149 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
151 /* Keep a flag to avoid extra notifies that we don't need
153 screen_x11->xsettings_in_init = TRUE;
154 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
155 screen_x11->screen_num,
156 gdk_xsettings_notify_cb,
157 gdk_xsettings_watch_cb,
159 screen_x11->xsettings_in_init = FALSE;
163 _gdk_x11_events_uninit_screen (GdkScreen *screen)
165 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
167 xsettings_client_destroy (screen_x11->xsettings_client);
168 screen_x11->xsettings_client = NULL;
172 _gdk_events_init (GdkDisplay *display)
175 GdkDisplaySource *display_source;
176 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
178 int connection_number = ConnectionNumber (display_x11->xdisplay);
179 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
182 source = display_x11->event_source = gdk_display_source_new (display);
183 display_source = (GdkDisplaySource*) source;
184 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
186 display_source->event_poll_fd.fd = connection_number;
187 display_source->event_poll_fd.events = G_IO_IN;
189 g_source_add_poll (source, &display_source->event_poll_fd);
190 g_source_set_can_recurse (source, TRUE);
191 g_source_attach (source, NULL);
193 display_sources = g_list_prepend (display_sources,display_source);
195 gdk_display_add_client_message_filter (
197 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
198 gdk_wm_protocols_filter,
204 * gdk_events_pending:
206 * Checks if any events are ready to be processed for any display.
208 * Return value: %TRUE if any events are pending.
211 gdk_events_pending (void)
215 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
217 GdkDisplaySource *tmp_source = tmp_list->data;
218 GdkDisplay *display = tmp_source->display;
220 if (_gdk_event_queue_find_first (display))
224 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
226 GdkDisplaySource *tmp_source = tmp_list->data;
227 GdkDisplay *display = tmp_source->display;
229 if (gdk_check_xpending (display))
237 graphics_expose_predicate (Display *display,
241 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
242 (xevent->xany.type == GraphicsExpose ||
243 xevent->xany.type == NoExpose))
250 * gdk_event_get_graphics_expose:
251 * @window: the #GdkWindow to wait for the events for.
253 * Waits for a GraphicsExpose or NoExpose event from the X server.
254 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
255 * GraphicsExpose events are handled before the widget is scrolled.
257 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
258 * NoExpose event was received.
261 gdk_event_get_graphics_expose (GdkWindow *window)
266 g_return_val_if_fail (window != NULL, NULL);
268 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
269 graphics_expose_predicate, (XPointer) window);
271 if (xevent.xany.type == GraphicsExpose)
273 event = gdk_event_new (GDK_NOTHING);
275 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
279 gdk_event_free (event);
286 gdk_event_apply_filters (XEvent *xevent,
291 GdkFilterReturn result;
297 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
299 tmp_list = tmp_list->next;
300 result = filter->function (xevent, event, filter->data);
301 if (result != GDK_FILTER_CONTINUE)
305 return GDK_FILTER_CONTINUE;
309 * gdk_display_add_client_message_filter:
310 * @display: a #GdkDisplay for which this message filter applies
311 * @message_type: the type of ClientMessage events to receive.
312 * This will be checked against the @message_type field
313 * of the XClientMessage event struct.
314 * @func: the function to call to process the event.
315 * @data: user data to pass to @func.
317 * Adds a filter to be called when X ClientMessage events are received.
322 gdk_display_add_client_message_filter (GdkDisplay *display,
323 GdkAtom message_type,
327 GdkClientFilter *filter;
328 g_return_if_fail (GDK_IS_DISPLAY (display));
329 filter = g_new (GdkClientFilter, 1);
331 filter->type = message_type;
332 filter->function = func;
335 GDK_DISPLAY_X11(display)->client_filters =
336 g_list_prepend (GDK_DISPLAY_X11 (display)->client_filters,
341 * gdk_add_client_message_filter:
342 * @message_type: the type of ClientMessage events to receive. This will be
343 * checked against the <structfield>message_type</structfield> field of the
344 * XClientMessage event struct.
345 * @func: the function to call to process the event.
346 * @data: user data to pass to @func.
348 * Adds a filter to the default display to be called when X ClientMessage events
349 * are received. See gdk_display_add_client_message_filter().
352 gdk_add_client_message_filter (GdkAtom message_type,
356 gdk_display_add_client_message_filter (gdk_display_get_default (),
357 message_type, func, data);
361 do_net_wm_state_changes (GdkWindow *window)
363 GdkWindowObject *window_private = (GdkWindowObject *)window;
364 GdkWindowImplX11 *window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
365 GdkWindowState old_state;
367 if (GDK_WINDOW_DESTROYED (window) ||
368 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
371 old_state = gdk_window_get_state (window);
373 /* For found_sticky to remain TRUE, we have to also be on desktop
376 if (old_state & GDK_WINDOW_STATE_STICKY)
378 if (!(window_impl->have_sticky && window_impl->on_all_desktops))
379 gdk_synthesize_window_state (window,
380 GDK_WINDOW_STATE_STICKY,
385 if (window_impl->have_sticky && window_impl->on_all_desktops)
386 gdk_synthesize_window_state (window,
388 GDK_WINDOW_STATE_STICKY);
391 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
393 if (!window_impl->have_fullscreen)
394 gdk_synthesize_window_state (window,
395 GDK_WINDOW_STATE_FULLSCREEN,
400 if (window_impl->have_fullscreen)
401 gdk_synthesize_window_state (window,
403 GDK_WINDOW_STATE_FULLSCREEN);
406 /* Our "maximized" means both vertical and horizontal; if only one,
407 * we don't expose that via GDK
409 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
411 if (!(window_impl->have_maxvert && window_impl->have_maxhorz))
412 gdk_synthesize_window_state (window,
413 GDK_WINDOW_STATE_MAXIMIZED,
418 if (window_impl->have_maxvert && window_impl->have_maxhorz)
419 gdk_synthesize_window_state (window,
421 GDK_WINDOW_STATE_MAXIMIZED);
426 gdk_check_wm_desktop_changed (GdkWindow *window)
428 GdkWindowObject *window_private = (GdkWindowObject *)window;
429 GdkWindowImplX11 *window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
430 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
437 if (window_impl->have_sticky)
441 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
442 GDK_WINDOW_XID (window),
443 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
444 0, G_MAXLONG, False, XA_CARDINAL, &type,
446 &bytes_after, (guchar **)&desktop);
450 window_impl->on_all_desktops = (*desktop == 0xFFFFFFFF);
454 window_impl->on_all_desktops = FALSE;
456 do_net_wm_state_changes (window);
461 gdk_check_wm_state_changed (GdkWindow *window)
463 GdkWindowObject *window_private = (GdkWindowObject *)window;
464 GdkWindowImplX11 *window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
465 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
474 gboolean had_sticky = window_impl->have_sticky;
476 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
477 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
478 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
479 &bytes_after, (guchar **)&atoms);
483 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
484 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
485 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
486 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
491 if (atoms[i] == sticky_atom)
492 window_impl->have_sticky = TRUE;
493 else if (atoms[i] == maxvert_atom)
494 window_impl->have_maxvert = TRUE;
495 else if (atoms[i] == maxhorz_atom)
496 window_impl->have_maxhorz = TRUE;
497 else if (atoms[i] == fullscreen_atom)
498 window_impl->have_fullscreen = TRUE;
506 /* When have_sticky is turned on, we have to check the DESKTOP property
509 if (window_impl->have_sticky && !had_sticky)
510 gdk_check_wm_desktop_changed (window);
512 do_net_wm_state_changes (window);
515 #define HAS_FOCUS(window_impl) \
516 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
519 generate_focus_event (GdkWindow *window,
524 event.type = GDK_FOCUS_CHANGE;
525 event.focus_change.window = window;
526 event.focus_change.send_event = FALSE;
527 event.focus_change.in = in;
529 gdk_event_put (&event);
533 set_screen_from_root (GdkDisplay *display,
539 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
542 gdk_event_set_screen (event, screen);
546 translate_key_event (GdkDisplay *display,
550 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
554 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
555 event->key.time = xevent->xkey.time;
557 event->key.state = (GdkModifierType) xevent->xkey.state;
558 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
559 event->key.hardware_keycode = xevent->xkey.keycode;
561 event->key.keyval = GDK_VoidSymbol;
563 gdk_keymap_translate_keyboard_state (keymap,
564 event->key.hardware_keycode,
570 /* Fill in event->string crudely, since various programs
573 event->key.string = NULL;
575 if (event->key.keyval != GDK_VoidSymbol)
576 c = gdk_keyval_to_unicode (event->key.keyval);
583 /* Apply the control key - Taken from Xlib
585 if (event->key.state & GDK_CONTROL_MASK)
587 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
590 event->key.string = g_memdup ("\0\0", 2);
591 event->key.length = 1;
595 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
596 else if (c == '8') c = '\177';
597 else if (c == '/') c = '_' & 0x1F;
600 len = g_unichar_to_utf8 (c, buf);
603 event->key.string = g_locale_from_utf8 (buf, len,
604 NULL, &bytes_written,
606 if (event->key.string)
607 event->key.length = bytes_written;
609 else if (event->key.keyval == GDK_Escape)
611 event->key.length = 1;
612 event->key.string = g_strdup ("\033");
614 else if (event->key.keyval == GDK_Return ||
615 event->key.keyval == GDK_KP_Enter)
617 event->key.length = 1;
618 event->key.string = g_strdup ("\r");
621 if (!event->key.string)
623 event->key.length = 0;
624 event->key.string = g_strdup ("");
628 #ifdef G_ENABLE_DEBUG
629 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
631 g_message ("%s:\t\twindow: %ld key: %12s %d",
632 event->type == GDK_KEY_PRESS ? "key press " : "key release",
634 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
637 if (event->key.length > 0)
638 g_message ("\t\tlength: %4d string: \"%s\"",
639 event->key.length, buf);
641 #endif /* G_ENABLE_DEBUG */
645 /* Return the window this has to do with, if any, rather
646 * than the frame or root window that was selecting
650 get_real_window (XEvent *event)
655 return event->xcreatewindow.window;
658 return event->xdestroywindow.window;
661 return event->xunmap.window;
664 return event->xmap.window;
667 return event->xmaprequest.window;
670 return event->xreparent.window;
672 case ConfigureNotify:
673 return event->xconfigure.window;
675 case ConfigureRequest:
676 return event->xconfigurerequest.window;
679 return event->xgravity.window;
681 case CirculateNotify:
682 return event->xcirculate.window;
684 case CirculateRequest:
685 return event->xcirculaterequest.window;
688 return event->xany.window;
692 #ifdef G_ENABLE_DEBUG
693 static const char notify_modes[][18] = {
700 static const char notify_details[][22] = {
705 "NotifyNonlinearVirtual",
713 gdk_event_translate (GdkDisplay *display,
716 gboolean return_exposes)
720 GdkWindowObject *window_private;
721 GdkWindow *filter_window;
722 GdkWindowImplX11 *window_impl = NULL;
724 gint xoffset, yoffset;
725 GdkScreen *screen = NULL;
726 GdkScreenX11 *screen_x11 = NULL;
727 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
732 /* init these, since the done: block uses them */
734 window_private = NULL;
735 event->any.window = NULL;
737 if (_gdk_default_filters)
739 /* Apply global filters */
740 GdkFilterReturn result;
741 result = gdk_event_apply_filters (xevent, event,
742 _gdk_default_filters);
744 if (result != GDK_FILTER_CONTINUE)
746 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
751 /* Find the GdkWindow that this event relates to.
752 * Basically this means substructure events
753 * are reported same as structure events
755 xwindow = get_real_window (xevent);
757 window = gdk_window_lookup_for_display (display, xwindow);
758 window_private = (GdkWindowObject *) window;
760 /* We always run the filters for the window where the event
761 * is delivered, not the window that it relates to
763 if (xevent->xany.window == xwindow)
764 filter_window = window;
766 filter_window = gdk_window_lookup_for_display (display, xevent->xany.window);
770 screen = GDK_WINDOW_SCREEN (window);
771 screen_x11 = GDK_SCREEN_X11 (screen);
776 /* Window may be a pixmap, so check its type.
777 * (This check is probably too expensive unless
778 * GLib short-circuits an exact type match,
779 * which has been proposed)
781 if (GDK_IS_WINDOW (window))
783 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
785 /* Move key events on focus window to the real toplevel, and
786 * filter out all other events on focus window
788 if (xwindow == window_impl->focus_window)
790 switch (xevent->type)
794 xwindow = GDK_WINDOW_XID (window);
795 xevent->xany.window = xwindow;
803 g_object_ref (window);
806 event->any.window = window;
807 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
809 if (window_private && GDK_WINDOW_DESTROYED (window))
811 if (xevent->type != DestroyNotify)
817 else if (filter_window)
819 /* Apply per-window filters */
820 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
821 GdkFilterReturn result;
823 if (filter_private->filters)
825 g_object_ref (filter_window);
827 result = gdk_event_apply_filters (xevent, event,
828 filter_private->filters);
830 g_object_unref (filter_window);
832 if (result != GDK_FILTER_CONTINUE)
834 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
840 if (screen_x11 && screen_x11->wmspec_check_window != None &&
841 xwindow == screen_x11->wmspec_check_window)
843 if (xevent->type == DestroyNotify)
845 screen_x11->wmspec_check_window = None;
846 g_free (screen_x11->window_manager_name);
847 screen_x11->window_manager_name = g_strdup ("unknown");
849 /* careful, reentrancy */
850 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
853 /* Eat events on this window unless someone had wrapped
854 * it as a foreign window
864 (xevent->xany.type == MotionNotify ||
865 xevent->xany.type == ButtonRelease))
867 if (_gdk_moveresize_handle_event (xevent))
874 /* We do a "manual" conversion of the XEvent to a
875 * GdkEvent. The structures are mostly the same so
876 * the conversion is fairly straightforward. We also
877 * optionally print debugging info regarding events
885 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
893 switch (xevent->type)
896 if (window_private == NULL)
901 translate_key_event (display, event, xevent);
905 if (window_private == NULL)
911 /* Emulate detectable auto-repeat by checking to see
912 * if the next event is a key press with the same
913 * keycode and timestamp, and if so, ignoring the event.
916 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
920 XPeekEvent (xevent->xkey.display, &next_event);
922 if (next_event.type == KeyPress &&
923 next_event.xkey.keycode == xevent->xkey.keycode &&
924 next_event.xkey.time == xevent->xkey.time)
931 translate_key_event (display, event, xevent);
936 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
937 xevent->xbutton.window,
938 xevent->xbutton.x, xevent->xbutton.y,
939 xevent->xbutton.button));
941 if (window_private == NULL ||
942 ((window_private->extension_events != 0) &&
943 display_x11->input_ignore_core))
949 /* If we get a ButtonPress event where the button is 4 or 5,
950 it's a Scroll event */
951 switch (xevent->xbutton.button)
957 event->scroll.type = GDK_SCROLL;
959 if (xevent->xbutton.button == 4)
960 event->scroll.direction = GDK_SCROLL_UP;
961 else if (xevent->xbutton.button == 5)
962 event->scroll.direction = GDK_SCROLL_DOWN;
963 else if (xevent->xbutton.button == 6)
964 event->scroll.direction = GDK_SCROLL_LEFT;
966 event->scroll.direction = GDK_SCROLL_RIGHT;
968 event->scroll.window = window;
969 event->scroll.time = xevent->xbutton.time;
970 event->scroll.x = xevent->xbutton.x + xoffset;
971 event->scroll.y = xevent->xbutton.y + yoffset;
972 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
973 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
974 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
975 event->scroll.device = display->core_pointer;
977 set_screen_from_root (display, event, xevent->xbutton.root);
982 event->button.type = GDK_BUTTON_PRESS;
983 event->button.window = window;
984 event->button.time = xevent->xbutton.time;
985 event->button.x = xevent->xbutton.x + xoffset;
986 event->button.y = xevent->xbutton.y + yoffset;
987 event->button.x_root = (gfloat)xevent->xbutton.x_root;
988 event->button.y_root = (gfloat)xevent->xbutton.y_root;
989 event->button.axes = NULL;
990 event->button.state = (GdkModifierType) xevent->xbutton.state;
991 event->button.button = xevent->xbutton.button;
992 event->button.device = display->core_pointer;
994 set_screen_from_root (display, event, xevent->xbutton.root);
996 _gdk_event_button_generate (display, event);
1004 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1005 xevent->xbutton.window,
1006 xevent->xbutton.x, xevent->xbutton.y,
1007 xevent->xbutton.button));
1009 if (window_private == NULL ||
1010 ((window_private->extension_events != 0) &&
1011 display_x11->input_ignore_core))
1017 /* We treat button presses as scroll wheel events, so ignore the release */
1018 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1019 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1025 event->button.type = GDK_BUTTON_RELEASE;
1026 event->button.window = window;
1027 event->button.time = xevent->xbutton.time;
1028 event->button.x = xevent->xbutton.x + xoffset;
1029 event->button.y = xevent->xbutton.y + yoffset;
1030 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1031 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1032 event->button.axes = NULL;
1033 event->button.state = (GdkModifierType) xevent->xbutton.state;
1034 event->button.button = xevent->xbutton.button;
1035 event->button.device = display->core_pointer;
1037 set_screen_from_root (display, event, xevent->xbutton.root);
1043 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1044 xevent->xmotion.window,
1045 xevent->xmotion.x, xevent->xmotion.y,
1046 (xevent->xmotion.is_hint) ? "true" : "false"));
1048 if (window_private == NULL ||
1049 ((window_private->extension_events != 0) &&
1050 display_x11->input_ignore_core))
1056 event->motion.type = GDK_MOTION_NOTIFY;
1057 event->motion.window = window;
1058 event->motion.time = xevent->xmotion.time;
1059 event->motion.x = xevent->xmotion.x + xoffset;
1060 event->motion.y = xevent->xmotion.y + yoffset;
1061 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1062 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1063 event->motion.axes = NULL;
1064 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1065 event->motion.is_hint = xevent->xmotion.is_hint;
1066 event->motion.device = display->core_pointer;
1068 set_screen_from_root (display, event, xevent->xmotion.root);
1074 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1075 xevent->xcrossing.window,
1076 xevent->xcrossing.detail,
1077 xevent->xcrossing.subwindow));
1079 if (window_private == NULL)
1085 /* Handle focusing (in the case where no window manager is running */
1087 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1088 xevent->xcrossing.detail != NotifyInferior &&
1089 xevent->xcrossing.focus && !window_impl->has_focus_window)
1091 gboolean had_focus = HAS_FOCUS (window_impl);
1093 window_impl->has_pointer_focus = TRUE;
1095 if (HAS_FOCUS (window_impl) != had_focus)
1096 generate_focus_event (window, TRUE);
1099 /* Tell XInput stuff about it if appropriate */
1100 if (window_private &&
1101 !GDK_WINDOW_DESTROYED (window) &&
1102 window_private->extension_events != 0)
1103 _gdk_input_enter_event (&xevent->xcrossing, window);
1105 event->crossing.type = GDK_ENTER_NOTIFY;
1106 event->crossing.window = window;
1108 /* If the subwindow field of the XEvent is non-NULL, then
1109 * lookup the corresponding GdkWindow.
1111 if (xevent->xcrossing.subwindow != None)
1112 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1114 event->crossing.subwindow = NULL;
1116 event->crossing.time = xevent->xcrossing.time;
1117 event->crossing.x = xevent->xcrossing.x + xoffset;
1118 event->crossing.y = xevent->xcrossing.y + yoffset;
1119 event->crossing.x_root = xevent->xcrossing.x_root;
1120 event->crossing.y_root = xevent->xcrossing.y_root;
1122 set_screen_from_root (display, event, xevent->xcrossing.root);
1124 /* Translate the crossing mode into Gdk terms.
1126 switch (xevent->xcrossing.mode)
1129 event->crossing.mode = GDK_CROSSING_NORMAL;
1132 event->crossing.mode = GDK_CROSSING_GRAB;
1135 event->crossing.mode = GDK_CROSSING_UNGRAB;
1139 /* Translate the crossing detail into Gdk terms.
1141 switch (xevent->xcrossing.detail)
1143 case NotifyInferior:
1144 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1146 case NotifyAncestor:
1147 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1150 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1152 case NotifyNonlinear:
1153 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1155 case NotifyNonlinearVirtual:
1156 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1159 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1163 event->crossing.focus = xevent->xcrossing.focus;
1164 event->crossing.state = xevent->xcrossing.state;
1170 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1171 xevent->xcrossing.window,
1172 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1174 if (window_private == NULL)
1180 /* Handle focusing (in the case where no window manager is running */
1182 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
1183 xevent->xcrossing.detail != NotifyInferior &&
1184 xevent->xcrossing.focus && !window_impl->has_focus_window)
1186 gboolean had_focus = HAS_FOCUS (window_impl);
1188 window_impl->has_pointer_focus = FALSE;
1190 if (HAS_FOCUS (window_impl) != had_focus)
1191 generate_focus_event (window, FALSE);
1194 event->crossing.type = GDK_LEAVE_NOTIFY;
1195 event->crossing.window = window;
1197 /* If the subwindow field of the XEvent is non-NULL, then
1198 * lookup the corresponding GdkWindow.
1200 if (xevent->xcrossing.subwindow != None)
1201 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1203 event->crossing.subwindow = NULL;
1205 event->crossing.time = xevent->xcrossing.time;
1206 event->crossing.x = xevent->xcrossing.x + xoffset;
1207 event->crossing.y = xevent->xcrossing.y + yoffset;
1208 event->crossing.x_root = xevent->xcrossing.x_root;
1209 event->crossing.y_root = xevent->xcrossing.y_root;
1211 set_screen_from_root (display, event, xevent->xcrossing.root);
1213 /* Translate the crossing mode into Gdk terms.
1215 switch (xevent->xcrossing.mode)
1218 event->crossing.mode = GDK_CROSSING_NORMAL;
1221 event->crossing.mode = GDK_CROSSING_GRAB;
1224 event->crossing.mode = GDK_CROSSING_UNGRAB;
1228 /* Translate the crossing detail into Gdk terms.
1230 switch (xevent->xcrossing.detail)
1232 case NotifyInferior:
1233 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1235 case NotifyAncestor:
1236 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1239 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1241 case NotifyNonlinear:
1242 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1244 case NotifyNonlinearVirtual:
1245 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1248 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1252 event->crossing.focus = xevent->xcrossing.focus;
1253 event->crossing.state = xevent->xcrossing.state;
1257 /* We only care about focus events that indicate that _this_
1258 * window (not a ancestor or child) got or lost the focus
1262 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1263 xevent->xfocus.window,
1264 notify_details[xevent->xfocus.detail],
1265 notify_modes[xevent->xfocus.mode]));
1267 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1269 gboolean had_focus = HAS_FOCUS (window_impl);
1271 switch (xevent->xfocus.detail)
1273 case NotifyAncestor:
1274 case NotifyNonlinear:
1276 case NotifyNonlinearVirtual:
1277 window_impl->has_focus_window = TRUE;
1278 /* We pretend that the focus moves to the grab
1279 * window, so we pay attention to NotifyGrab
1280 * NotifyUngrab, and ignore NotifyWhileGrabbed
1282 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1283 window_impl->has_focus = TRUE;
1286 /* The X server sends NotifyPointer/NotifyGrab,
1287 * but the pointer focus is ignored while a
1290 if (xevent->xfocus.mode != NotifyGrab)
1291 window_impl->has_pointer_focus = TRUE;
1293 case NotifyInferior:
1294 case NotifyPointerRoot:
1295 case NotifyDetailNone:
1299 if (HAS_FOCUS (window_impl) != had_focus)
1300 generate_focus_event (window, TRUE);
1305 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1306 xevent->xfocus.window,
1307 notify_details[xevent->xfocus.detail],
1308 notify_modes[xevent->xfocus.mode]));
1310 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1312 gboolean had_focus = HAS_FOCUS (window_impl);
1314 switch (xevent->xfocus.detail)
1316 case NotifyAncestor:
1317 case NotifyNonlinear:
1319 case NotifyNonlinearVirtual:
1320 window_impl->has_focus_window = FALSE;
1321 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1322 window_impl->has_focus = FALSE;
1325 if (xevent->xfocus.mode != NotifyUngrab)
1326 window_impl->has_pointer_focus = FALSE;
1328 case NotifyInferior:
1329 case NotifyPointerRoot:
1330 case NotifyDetailNone:
1334 if (HAS_FOCUS (window_impl) != had_focus)
1335 generate_focus_event (window, FALSE);
1340 /* gdk_keyboard_grab() causes following events. These events confuse
1341 * the XIM focus, so ignore them.
1343 if (xevent->xfocus.mode == NotifyGrab ||
1344 xevent->xfocus.mode == NotifyUngrab)
1350 g_message ("keymap notify"));
1352 /* Not currently handled */
1358 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1359 xevent->xexpose.window, xevent->xexpose.count,
1360 xevent->xexpose.x, xevent->xexpose.y,
1361 xevent->xexpose.width, xevent->xexpose.height,
1362 event->any.send_event ? " (send)" : ""));
1364 if (window_private == NULL)
1371 GdkRectangle expose_rect;
1373 expose_rect.x = xevent->xexpose.x + xoffset;
1374 expose_rect.y = xevent->xexpose.y + yoffset;
1375 expose_rect.width = xevent->xexpose.width;
1376 expose_rect.height = xevent->xexpose.height;
1380 event->expose.type = GDK_EXPOSE;
1381 event->expose.area = expose_rect;
1382 event->expose.region = gdk_region_rectangle (&expose_rect);
1383 event->expose.window = window;
1384 event->expose.count = xevent->xexpose.count;
1390 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1399 case GraphicsExpose:
1401 GdkRectangle expose_rect;
1404 g_message ("graphics expose:\tdrawable: %ld",
1405 xevent->xgraphicsexpose.drawable));
1407 if (window_private == NULL)
1413 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1414 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1415 expose_rect.width = xevent->xgraphicsexpose.width;
1416 expose_rect.height = xevent->xgraphicsexpose.height;
1420 event->expose.type = GDK_EXPOSE;
1421 event->expose.area = expose_rect;
1422 event->expose.region = gdk_region_rectangle (&expose_rect);
1423 event->expose.window = window;
1424 event->expose.count = xevent->xgraphicsexpose.count;
1430 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1440 g_message ("no expose:\t\tdrawable: %ld",
1441 xevent->xnoexpose.drawable));
1443 event->no_expose.type = GDK_NO_EXPOSE;
1444 event->no_expose.window = window;
1448 case VisibilityNotify:
1449 #ifdef G_ENABLE_DEBUG
1450 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1451 switch (xevent->xvisibility.state)
1453 case VisibilityFullyObscured:
1454 g_message ("visibility notify:\twindow: %ld none",
1455 xevent->xvisibility.window);
1457 case VisibilityPartiallyObscured:
1458 g_message ("visibility notify:\twindow: %ld partial",
1459 xevent->xvisibility.window);
1461 case VisibilityUnobscured:
1462 g_message ("visibility notify:\twindow: %ld full",
1463 xevent->xvisibility.window);
1466 #endif /* G_ENABLE_DEBUG */
1468 if (window_private == NULL)
1474 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1475 event->visibility.window = window;
1477 switch (xevent->xvisibility.state)
1479 case VisibilityFullyObscured:
1480 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1483 case VisibilityPartiallyObscured:
1484 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1487 case VisibilityUnobscured:
1488 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1496 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1497 xevent->xcreatewindow.window,
1498 xevent->xcreatewindow.x,
1499 xevent->xcreatewindow.y,
1500 xevent->xcreatewindow.width,
1501 xevent->xcreatewindow.height,
1502 xevent->xcreatewindow.border_width,
1503 xevent->xcreatewindow.parent,
1504 xevent->xcreatewindow.override_redirect));
1505 /* not really handled */
1510 g_message ("destroy notify:\twindow: %ld",
1511 xevent->xdestroywindow.window));
1513 /* Ignore DestroyNotify from SubstructureNotifyMask */
1514 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1516 event->any.type = GDK_DESTROY;
1517 event->any.window = window;
1519 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1521 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1522 gdk_window_destroy_notify (window);
1531 g_message ("unmap notify:\t\twindow: %ld",
1532 xevent->xmap.window));
1534 event->any.type = GDK_UNMAP;
1535 event->any.window = window;
1537 /* If we are shown (not withdrawn) and get an unmap, it means we
1538 * were iconified in the X sense. If we are withdrawn, and get
1539 * an unmap, it means we hid the window ourselves, so we
1540 * will have already flipped the iconified bit off.
1544 if (GDK_WINDOW_IS_MAPPED (window))
1545 gdk_synthesize_window_state (window,
1547 GDK_WINDOW_STATE_ICONIFIED);
1549 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1556 g_message ("map notify:\t\twindow: %ld",
1557 xevent->xmap.window));
1559 event->any.type = GDK_MAP;
1560 event->any.window = window;
1562 /* Unset iconified if it was set */
1563 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1564 gdk_synthesize_window_state (window,
1565 GDK_WINDOW_STATE_ICONIFIED,
1570 case ReparentNotify:
1572 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1573 xevent->xreparent.window,
1574 xevent->xreparent.x,
1575 xevent->xreparent.y,
1576 xevent->xreparent.parent,
1577 xevent->xreparent.override_redirect));
1579 /* Not currently handled */
1583 case ConfigureNotify:
1585 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1586 xevent->xconfigure.window,
1587 xevent->xconfigure.x,
1588 xevent->xconfigure.y,
1589 xevent->xconfigure.width,
1590 xevent->xconfigure.height,
1591 xevent->xconfigure.border_width,
1592 xevent->xconfigure.above,
1593 xevent->xconfigure.override_redirect,
1596 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1597 ? " (discarding child)"
1598 : xevent->xconfigure.event != xevent->xconfigure.window
1599 ? " (discarding substructure)"
1601 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1602 _gdk_x11_screen_size_changed (screen, xevent);
1605 xevent->xconfigure.event == xevent->xconfigure.window &&
1606 !GDK_WINDOW_DESTROYED (window) &&
1607 (window_private->extension_events != 0))
1608 _gdk_input_configure_event (&xevent->xconfigure, window);
1611 xevent->xconfigure.event != xevent->xconfigure.window ||
1612 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1613 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1617 event->configure.type = GDK_CONFIGURE;
1618 event->configure.window = window;
1619 event->configure.width = xevent->xconfigure.width;
1620 event->configure.height = xevent->xconfigure.height;
1622 if (!xevent->xconfigure.send_event &&
1623 !xevent->xconfigure.override_redirect &&
1624 !GDK_WINDOW_DESTROYED (window))
1628 Window child_window = 0;
1630 gdk_error_trap_push ();
1631 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1632 GDK_DRAWABLE_XID (window),
1633 screen_x11->xroot_window,
1638 event->configure.x = tx;
1639 event->configure.y = ty;
1641 gdk_error_trap_pop ();
1645 event->configure.x = xevent->xconfigure.x;
1646 event->configure.y = xevent->xconfigure.y;
1648 window_private->x = event->configure.x;
1649 window_private->y = event->configure.y;
1650 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1651 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1652 if (window_private->resize_count >= 1)
1654 window_private->resize_count -= 1;
1656 if (window_private->resize_count == 0)
1657 _gdk_moveresize_configure_done (display, window);
1662 case PropertyNotify:
1664 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1665 xevent->xproperty.window,
1666 xevent->xproperty.atom,
1668 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1671 if (window_private == NULL)
1677 /* We compare with the serial of the last time we mapped the
1678 * window to avoid refetching properties that we set ourselves
1680 if (xevent->xproperty.serial >= GDK_WINDOW_IMPL_X11 (window_private->impl)->map_serial)
1682 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1683 gdk_check_wm_state_changed (window);
1685 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1686 gdk_check_wm_desktop_changed (window);
1689 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1691 event->property.type = GDK_PROPERTY_NOTIFY;
1692 event->property.window = window;
1693 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1694 event->property.time = xevent->xproperty.time;
1695 event->property.state = xevent->xproperty.state;
1702 case SelectionClear:
1704 g_message ("selection clear:\twindow: %ld",
1705 xevent->xproperty.window));
1707 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1709 event->selection.type = GDK_SELECTION_CLEAR;
1710 event->selection.window = window;
1711 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1712 event->selection.time = xevent->xselectionclear.time;
1719 case SelectionRequest:
1721 g_message ("selection request:\twindow: %ld",
1722 xevent->xproperty.window));
1724 event->selection.type = GDK_SELECTION_REQUEST;
1725 event->selection.window = window;
1726 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1727 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1728 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1729 event->selection.requestor = xevent->xselectionrequest.requestor;
1730 event->selection.time = xevent->xselectionrequest.time;
1734 case SelectionNotify:
1736 g_message ("selection notify:\twindow: %ld",
1737 xevent->xproperty.window));
1740 event->selection.type = GDK_SELECTION_NOTIFY;
1741 event->selection.window = window;
1742 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1743 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1744 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1745 event->selection.time = xevent->xselection.time;
1749 case ColormapNotify:
1751 g_message ("colormap notify:\twindow: %ld",
1752 xevent->xcolormap.window));
1754 /* Not currently handled */
1761 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1762 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1765 g_message ("client message:\twindow: %ld",
1766 xevent->xclient.window));
1768 tmp_list = display_x11->client_filters;
1771 GdkClientFilter *filter = tmp_list->data;
1772 if (filter->type == message_type)
1774 result = (*filter->function) (xevent, event, filter->data);
1778 tmp_list = tmp_list->next;
1783 case GDK_FILTER_REMOVE:
1786 case GDK_FILTER_TRANSLATE:
1789 case GDK_FILTER_CONTINUE:
1790 /* Send unknown ClientMessage's on to Gtk for it to use */
1791 if (window_private == NULL)
1797 event->client.type = GDK_CLIENT_EVENT;
1798 event->client.window = window;
1799 event->client.message_type = message_type;
1800 event->client.data_format = xevent->xclient.format;
1801 memcpy(&event->client.data, &xevent->xclient.data,
1802 sizeof(event->client.data));
1812 g_message ("mapping notify"));
1814 /* Let XLib know that there is a new keyboard mapping.
1816 XRefreshKeyboardMapping (&xevent->xmapping);
1817 _gdk_keymap_keys_changed (display);
1823 if (xevent->type == display_x11->xkb_event_type)
1825 XkbEvent *xkb_event = (XkbEvent *)xevent;
1827 switch (xkb_event->any.xkb_type)
1829 case XkbNewKeyboardNotify:
1831 _gdk_keymap_keys_changed (display);
1836 case XkbStateNotify:
1837 _gdk_keymap_state_changed (display);
1844 /* something else - (e.g., a Xinput event) */
1846 if (window_private &&
1847 !GDK_WINDOW_DESTROYED (window_private) &&
1848 (window_private->extension_events != 0))
1849 return_val = _gdk_input_other_event(event, xevent, window);
1860 if (event->any.window)
1861 g_object_ref (event->any.window);
1862 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1863 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1864 (event->crossing.subwindow != NULL))
1865 g_object_ref (event->crossing.subwindow);
1869 /* Mark this event as having no resources to be freed */
1870 event->any.window = NULL;
1871 event->any.type = GDK_NOTHING;
1875 g_object_unref (window);
1880 static GdkFilterReturn
1881 gdk_wm_protocols_filter (GdkXEvent *xev,
1885 XEvent *xevent = (XEvent *)xev;
1886 GdkWindow *win = event->any.window;
1887 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
1889 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
1891 /* The delete window request specifies a window
1892 * to delete. We don't actually destroy the
1893 * window because "it is only a request". (The
1894 * window might contain vital data that the
1895 * program does not want destroyed). Instead
1896 * the event is passed along to the program,
1897 * which should then destroy the window.
1900 g_message ("delete window:\t\twindow: %ld",
1901 xevent->xclient.window));
1903 event->any.type = GDK_DELETE;
1905 return GDK_FILTER_TRANSLATE;
1907 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
1909 GdkWindow *win = event->any.window;
1910 GdkWindowImplX11 *impl = GDK_WINDOW_IMPL_X11 (((GdkWindowObject *)win)->impl);
1912 /* There is no way of knowing reliably whether we are viewable;
1913 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
1915 _gdk_x11_set_input_focus_safe (display, impl->focus_window,
1917 xevent->xclient.data.l[1]);
1919 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
1920 !_gdk_x11_display_is_root_window (display,
1921 xevent->xclient.window))
1923 XEvent xev = *xevent;
1925 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
1926 XSendEvent (GDK_WINDOW_XDISPLAY (win),
1929 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1932 return GDK_FILTER_REMOVE;
1936 _gdk_events_queue (GdkDisplay *display)
1941 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
1943 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
1945 XNextEvent (xdisplay, &xevent);
1947 switch (xevent.type)
1953 if (XFilterEvent (&xevent, None))
1957 event = gdk_event_new (GDK_NOTHING);
1959 event->any.window = NULL;
1960 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1962 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1964 node = _gdk_event_queue_append (display, event);
1966 if (gdk_event_translate (display, event, &xevent, FALSE))
1968 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1972 _gdk_event_queue_remove_link (display, node);
1973 g_list_free_1 (node);
1974 gdk_event_free (event);
1980 gdk_event_prepare (GSource *source,
1983 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
1986 GDK_THREADS_ENTER ();
1989 retval = (_gdk_event_queue_find_first (display) != NULL ||
1990 gdk_check_xpending (display));
1992 GDK_THREADS_LEAVE ();
1998 gdk_event_check (GSource *source)
2000 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2003 GDK_THREADS_ENTER ();
2005 if (display_source->event_poll_fd.revents & G_IO_IN)
2006 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2007 gdk_check_xpending (display_source->display));
2011 GDK_THREADS_LEAVE ();
2017 gdk_event_dispatch (GSource *source,
2018 GSourceFunc callback,
2021 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2024 GDK_THREADS_ENTER ();
2026 _gdk_events_queue (display);
2027 event = _gdk_event_unqueue (display);
2031 if (_gdk_event_func)
2032 (*_gdk_event_func) (event, _gdk_event_data);
2034 gdk_event_free (event);
2037 GDK_THREADS_LEAVE ();
2043 * gdk_event_send_client_message_for_display:
2044 * @display: the #GdkDisplay for the window where the message is to be sent.
2045 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2046 * @winid: the window to send the X ClientMessage event to.
2048 * Sends an X ClientMessage event to a given window.
2050 * This could be used for communicating between different applications,
2051 * though the amount of data is limited to 20 bytes.
2053 * Returns: non-zero on success.
2058 gdk_event_send_client_message_for_display (GdkDisplay *display,
2060 GdkNativeWindow winid)
2064 g_return_val_if_fail(event != NULL, FALSE);
2066 /* Set up our event to send, with the exception of its target window */
2067 sev.xclient.type = ClientMessage;
2068 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2069 sev.xclient.format = event->client.data_format;
2070 sev.xclient.window = winid;
2071 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2072 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2074 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2079 /* Sends a ClientMessage to all toplevel client windows */
2081 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2088 unsigned long nitems, after;
2089 unsigned char *data;
2090 Window *ret_children, ret_root, ret_parent;
2091 unsigned int ret_nchildren;
2092 gboolean send = FALSE;
2093 gboolean found = FALSE;
2094 gboolean result = FALSE;
2097 gdk_error_trap_push ();
2099 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2100 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
2101 0, 0, False, AnyPropertyType,
2102 &type, &format, &nitems, &after, &data) != Success)
2112 /* OK, we're all set, now let's find some windows to send this to */
2113 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2114 &ret_root, &ret_parent,
2115 &ret_children, &ret_nchildren))
2118 for(i = 0; i < ret_nchildren; i++)
2119 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2122 XFree (ret_children);
2125 if (send || (!found && (level == 1)))
2127 xev->xclient.window = xid;
2128 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2131 result = send || found;
2134 gdk_error_trap_pop ();
2140 * gdk_screen_broadcast_client_message:
2141 * @screen: the #GdkScreen where the event will be broadcasted.
2142 * @event: the #GdkEvent.
2144 * Sends an X ClientMessage event to all toplevel windows on @screen.
2146 * Toplevel windows are determined by checking for the WM_STATE property,
2147 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2148 * If no windows are found with the WM_STATE property set, the message is
2149 * sent to all children of the root window.
2155 gdk_screen_broadcast_client_message (GdkScreen *screen,
2159 GdkWindow *root_window;
2161 g_return_if_fail (event != NULL);
2163 root_window = gdk_screen_get_root_window (screen);
2165 /* Set up our event to send, with the exception of its target window */
2166 sev.xclient.type = ClientMessage;
2167 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2168 sev.xclient.format = event->client.data_format;
2169 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2170 sev.xclient.message_type =
2171 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2172 event->client.message_type);
2174 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2176 GDK_WINDOW_XID (root_window),
2181 *--------------------------------------------------------------
2184 * Flushes the Xlib output buffer and then waits
2185 * until all requests have been received and processed
2186 * by the X server. The only real use for this function
2187 * is in dealing with XShm.
2195 *--------------------------------------------------------------
2201 GSList *tmp_list = _gdk_displays;
2205 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2206 tmp_list = tmp_list->next;
2211 timestamp_predicate (Display *display,
2215 Window xwindow = GPOINTER_TO_UINT (arg);
2216 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2218 if (xevent->type == PropertyNotify &&
2219 xevent->xproperty.window == xwindow &&
2220 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2221 "GDK_TIMESTAMP_PROP"))
2228 * gdk_x11_get_server_time:
2229 * @window: a #GdkWindow, used for communication with the server.
2230 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2231 * events mask or a hang will result.
2233 * Routine to get the current X server time stamp.
2235 * Return value: the time stamp.
2238 gdk_x11_get_server_time (GdkWindow *window)
2244 Atom timestamp_prop_atom;
2246 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2247 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2249 xdisplay = GDK_WINDOW_XDISPLAY (window);
2250 xwindow = GDK_WINDOW_XWINDOW (window);
2251 timestamp_prop_atom =
2252 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2253 "GDK_TIMESTAMP_PROP");
2255 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2256 timestamp_prop_atom,
2257 8, PropModeReplace, &c, 1);
2259 XIfEvent (xdisplay, &xevent,
2260 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2262 return xevent.xproperty.time;
2266 fetch_net_wm_check_window (GdkScreen *screen)
2268 GdkScreenX11 *screen_x11;
2269 GdkDisplay *display;
2276 /* This function is very slow on every call if you are not running a
2277 * spec-supporting WM. For now not optimized, because it isn't in
2278 * any critical code paths, but if you used it somewhere that had to
2279 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2280 * Probably at that point the function should be changed to query
2281 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2284 screen_x11 = GDK_SCREEN_X11 (screen);
2285 display = screen_x11->display;
2287 if (screen_x11->wmspec_check_window != None)
2288 return; /* already have it */
2290 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2291 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2292 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2293 &n_items, &bytes_after, (guchar **) & xwindow);
2295 if (type != XA_WINDOW)
2298 gdk_error_trap_push ();
2300 /* Find out if this WM goes away, so we can reset everything. */
2301 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2303 screen_x11->wmspec_check_window = *xwindow;
2306 screen_x11->need_refetch_net_supported = TRUE;
2307 screen_x11->need_refetch_wm_name = TRUE;
2309 /* Careful, reentrancy */
2310 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2314 * gdk_x11_screen_get_window_manager_name:
2315 * @screen: a #GdkScreen
2317 * Returns the name of the window manager for @screen.
2319 * Return value: the name of the window manager screen @screen, or
2320 * "unknown" if the window manager is unknown. The string is owned by GDK
2321 * and should not be freed.
2326 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2328 GdkScreenX11 *screen_x11;
2330 screen_x11 = GDK_SCREEN_X11 (screen);
2332 fetch_net_wm_check_window (screen);
2334 if (screen_x11->need_refetch_wm_name)
2336 /* Get the name of the window manager */
2337 screen_x11->need_refetch_wm_name = FALSE;
2339 g_free (screen_x11->window_manager_name);
2340 screen_x11->window_manager_name = g_strdup ("unknown");
2342 if (screen_x11->wmspec_check_window != None)
2352 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2353 screen_x11->wmspec_check_window,
2354 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2356 0, G_MAXLONG, False,
2357 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2360 &n_items, &bytes_after,
2363 gdk_display_sync (screen_x11->display);
2365 gdk_error_trap_pop ();
2369 g_free (screen_x11->window_manager_name);
2370 screen_x11->window_manager_name = g_strdup (name);
2376 return GDK_SCREEN_X11 (screen)->window_manager_name;
2379 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2381 struct _NetWmSupportedAtoms
2388 * gdk_x11_screen_supports_net_wm_hint:
2389 * @screen: the relevant #GdkScreen.
2390 * @property: a property atom.
2392 * This function is specific to the X11 backend of GDK, and indicates
2393 * whether the window manager supports a certain hint from the
2394 * Extended Window Manager Hints Specification. You can find this
2396 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2398 * When using this function, keep in mind that the window manager
2399 * can change over time; so you shouldn't use this function in
2400 * a way that impacts persistent application state. A common bug
2401 * is that your application can start up before the window manager
2402 * does when the user logs in, and before the window manager starts
2403 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2404 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2405 * a window manager change.
2407 * Return value: %TRUE if the window manager supports @property
2412 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2416 GdkScreenX11 *screen_x11;
2417 NetWmSupportedAtoms *supported_atoms;
2418 GdkDisplay *display;
2420 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2422 screen_x11 = GDK_SCREEN_X11 (screen);
2423 display = screen_x11->display;
2425 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2426 if (!supported_atoms)
2428 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2429 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2432 fetch_net_wm_check_window (screen);
2434 if (screen_x11->wmspec_check_window == None)
2437 if (screen_x11->need_refetch_net_supported)
2439 /* WM has changed since we last got the supported list,
2446 screen_x11->need_refetch_net_supported = FALSE;
2448 if (supported_atoms->atoms)
2449 XFree (supported_atoms->atoms);
2451 supported_atoms->atoms = NULL;
2452 supported_atoms->n_atoms = 0;
2454 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2455 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2456 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2457 &supported_atoms->n_atoms, &bytes_after,
2458 (guchar **)&supported_atoms->atoms);
2460 if (type != XA_ATOM)
2464 if (supported_atoms->atoms == NULL)
2468 while (i < supported_atoms->n_atoms)
2470 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2480 * gdk_net_wm_supports:
2481 * @property: a property atom.
2483 * This function is specific to the X11 backend of GDK, and indicates
2484 * whether the window manager for the default screen supports a certain
2485 * hint from the Extended Window Manager Hints Specification. See
2486 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2488 * Return value: %TRUE if the window manager supports @property
2491 gdk_net_wm_supports (GdkAtom property)
2493 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2498 const char *xsettings_name;
2499 const char *gdk_name;
2500 } settings_map[] = {
2501 { "Net/DoubleClickTime", "gtk-double-click-time" },
2502 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2503 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2504 { "Gtk/ColorPalette", "gtk-color-palette" },
2505 { "Gtk/FontName", "gtk-font-name" },
2506 { "Gtk/IconSizes", "gtk-icon-sizes" },
2507 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2508 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2509 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2510 { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
2511 { "Gtk/IMStatusStyle", "gtk-im-status-style" },
2512 { "Net/CursorBlink", "gtk-cursor-blink" },
2513 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2514 { "Net/ThemeName", "gtk-theme-name" },
2515 { "Net/IconThemeName", "gtk-icon-theme-name" },
2519 gdk_xsettings_notify_cb (const char *name,
2520 XSettingsAction action,
2521 XSettingsSetting *setting,
2525 GdkScreen *screen = data;
2526 GdkScreenX11 *screen_x11 = data;
2529 if (screen_x11->xsettings_in_init)
2532 new_event.type = GDK_SETTING;
2533 new_event.setting.window = gdk_screen_get_root_window (screen);
2534 new_event.setting.send_event = FALSE;
2535 new_event.setting.name = NULL;
2537 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2538 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2540 new_event.setting.name = (char *)settings_map[i].gdk_name;
2545 if (!new_event.setting.name)
2550 case XSETTINGS_ACTION_NEW:
2551 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2553 case XSETTINGS_ACTION_CHANGED:
2554 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2556 case XSETTINGS_ACTION_DELETED:
2557 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2561 gdk_event_put (&new_event);
2565 check_transform (const gchar *xsettings_name,
2569 if (!g_value_type_transformable (src_type, dest_type))
2571 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2573 g_type_name (src_type),
2574 g_type_name (dest_type));
2582 * gdk_screen_get_setting:
2583 * @screen: the #GdkScreen where the setting is located
2584 * @name: the name of the setting
2585 * @value: location to store the value of the setting
2587 * Retrieves a desktop-wide setting such as double-click time
2588 * for the #GdkScreen @screen.
2590 * FIXME needs a list of valid settings here, or a link to
2593 * Returns: %TRUE if the setting existed and a value was stored
2594 * in @value, %FALSE otherwise.
2599 gdk_screen_get_setting (GdkScreen *screen,
2604 const char *xsettings_name = NULL;
2605 XSettingsResult result;
2606 XSettingsSetting *setting;
2607 GdkScreenX11 *screen_x11;
2608 gboolean success = FALSE;
2610 GValue tmp_val = { 0, };
2612 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2614 screen_x11 = GDK_SCREEN_X11 (screen);
2616 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2617 if (strcmp (settings_map[i].gdk_name, name) == 0)
2619 xsettings_name = settings_map[i].xsettings_name;
2623 if (!xsettings_name)
2626 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2627 xsettings_name, &setting);
2628 if (result != XSETTINGS_SUCCESS)
2631 switch (setting->type)
2633 case XSETTINGS_TYPE_INT:
2634 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2636 g_value_init (&tmp_val, G_TYPE_INT);
2637 g_value_set_int (&tmp_val, setting->data.v_int);
2638 g_value_transform (&tmp_val, value);
2643 case XSETTINGS_TYPE_STRING:
2644 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2646 g_value_init (&tmp_val, G_TYPE_STRING);
2647 g_value_set_string (&tmp_val, setting->data.v_string);
2648 g_value_transform (&tmp_val, value);
2653 case XSETTINGS_TYPE_COLOR:
2654 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2658 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2661 color.red = setting->data.v_color.red;
2662 color.green = setting->data.v_color.green;
2663 color.blue = setting->data.v_color.blue;
2665 g_value_set_boxed (&tmp_val, &color);
2667 g_value_transform (&tmp_val, value);
2674 g_value_unset (&tmp_val);
2676 xsettings_setting_free (setting);
2681 static GdkFilterReturn
2682 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2686 GdkScreenX11 *screen = data;
2688 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2689 return GDK_FILTER_REMOVE;
2691 return GDK_FILTER_CONTINUE;
2695 gdk_xsettings_watch_cb (Window window,
2701 GdkScreen *screen = cb_data;
2703 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2708 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2710 g_object_ref (gdkwin);
2712 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2717 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2718 g_object_unref (gdkwin);