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/.
30 #include "gdkprivate-x11.h"
31 #include "gdkinternals.h"
33 #include "gdkscreen-x11.h"
34 #include "gdkdisplay-x11.h"
37 #include "gdkkeysyms.h"
39 #include "xsettings-client.h"
43 #include "gdkinputprivate.h"
48 #include <X11/XKBlib.h>
52 #include <X11/extensions/sync.h>
56 #include <X11/extensions/Xfixes.h>
59 #include <X11/Xatom.h>
61 typedef struct _GdkIOClosure GdkIOClosure;
62 typedef struct _GdkDisplaySource GdkDisplaySource;
63 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
67 GdkInputFunction function;
68 GdkInputCondition condition;
69 GdkDestroyNotify notify;
73 struct _GdkDisplaySource
78 GPollFD event_poll_fd;
81 struct _GdkEventTypeX11
88 * Private function declarations
91 static gint gdk_event_apply_filters (XEvent *xevent,
94 static gboolean gdk_event_translate (GdkDisplay *display,
97 gboolean return_exposes);
99 static gboolean gdk_event_prepare (GSource *source,
101 static gboolean gdk_event_check (GSource *source);
102 static gboolean gdk_event_dispatch (GSource *source,
103 GSourceFunc callback,
106 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
110 static GSource *gdk_display_source_new (GdkDisplay *display);
111 static gboolean gdk_check_xpending (GdkDisplay *display);
113 static void gdk_xsettings_watch_cb (Window window,
117 static void gdk_xsettings_notify_cb (const char *name,
118 XSettingsAction action,
119 XSettingsSetting *setting,
122 /* Private variable declarations
125 static GList *display_sources;
127 static GSourceFuncs event_funcs = {
135 gdk_display_source_new (GdkDisplay *display)
137 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
138 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
140 display_source->display = display;
146 gdk_check_xpending (GdkDisplay *display)
148 return XPending (GDK_DISPLAY_XDISPLAY (display));
151 /*********************************************
152 * Functions for maintaining the event queue *
153 *********************************************/
156 refcounted_grab_server (Display *xdisplay)
158 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
160 gdk_x11_display_grab (display);
164 refcounted_ungrab_server (Display *xdisplay)
166 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
168 gdk_x11_display_ungrab (display);
172 _gdk_x11_events_init_screen (GdkScreen *screen)
174 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
176 /* Keep a flag to avoid extra notifies that we don't need
178 screen_x11->xsettings_in_init = TRUE;
179 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
180 screen_x11->screen_num,
181 gdk_xsettings_notify_cb,
182 gdk_xsettings_watch_cb,
184 xsettings_client_set_grab_func (screen_x11->xsettings_client,
185 refcounted_grab_server);
186 xsettings_client_set_ungrab_func (screen_x11->xsettings_client,
187 refcounted_ungrab_server);
188 screen_x11->xsettings_in_init = FALSE;
192 _gdk_x11_events_uninit_screen (GdkScreen *screen)
194 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
196 xsettings_client_destroy (screen_x11->xsettings_client);
197 screen_x11->xsettings_client = NULL;
201 _gdk_events_init (GdkDisplay *display)
204 GdkDisplaySource *display_source;
205 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
207 int connection_number = ConnectionNumber (display_x11->xdisplay);
208 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
211 source = display_x11->event_source = gdk_display_source_new (display);
212 display_source = (GdkDisplaySource*) source;
213 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
215 display_source->event_poll_fd.fd = connection_number;
216 display_source->event_poll_fd.events = G_IO_IN;
218 g_source_add_poll (source, &display_source->event_poll_fd);
219 g_source_set_can_recurse (source, TRUE);
220 g_source_attach (source, NULL);
222 display_sources = g_list_prepend (display_sources,display_source);
224 gdk_display_add_client_message_filter (display,
225 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
226 gdk_wm_protocols_filter,
232 * gdk_events_pending:
234 * Checks if any events are ready to be processed for any display.
236 * Return value: %TRUE if any events are pending.
239 gdk_events_pending (void)
243 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
245 GdkDisplaySource *tmp_source = tmp_list->data;
246 GdkDisplay *display = tmp_source->display;
248 if (_gdk_event_queue_find_first (display))
252 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
254 GdkDisplaySource *tmp_source = tmp_list->data;
255 GdkDisplay *display = tmp_source->display;
257 if (gdk_check_xpending (display))
265 graphics_expose_predicate (Display *display,
269 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
270 (xevent->xany.type == GraphicsExpose ||
271 xevent->xany.type == NoExpose))
278 * gdk_event_get_graphics_expose:
279 * @window: the #GdkWindow to wait for the events for.
281 * Waits for a GraphicsExpose or NoExpose event from the X server.
282 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
283 * GraphicsExpose events are handled before the widget is scrolled.
285 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
286 * NoExpose event was received.
289 gdk_event_get_graphics_expose (GdkWindow *window)
294 g_return_val_if_fail (window != NULL, NULL);
296 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
297 graphics_expose_predicate, (XPointer) window);
299 if (xevent.xany.type == GraphicsExpose)
301 event = gdk_event_new (GDK_NOTHING);
303 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
307 gdk_event_free (event);
314 gdk_event_apply_filters (XEvent *xevent,
319 GdkFilterReturn result;
325 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
327 tmp_list = tmp_list->next;
328 result = filter->function (xevent, event, filter->data);
329 if (result != GDK_FILTER_CONTINUE)
333 return GDK_FILTER_CONTINUE;
337 * gdk_display_add_client_message_filter:
338 * @display: a #GdkDisplay for which this message filter applies
339 * @message_type: the type of ClientMessage events to receive.
340 * This will be checked against the @message_type field
341 * of the XClientMessage event struct.
342 * @func: the function to call to process the event.
343 * @data: user data to pass to @func.
345 * Adds a filter to be called when X ClientMessage events are received.
350 gdk_display_add_client_message_filter (GdkDisplay *display,
351 GdkAtom message_type,
355 GdkClientFilter *filter;
356 g_return_if_fail (GDK_IS_DISPLAY (display));
357 filter = g_new (GdkClientFilter, 1);
359 filter->type = message_type;
360 filter->function = func;
363 GDK_DISPLAY_X11(display)->client_filters =
364 g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
369 * gdk_add_client_message_filter:
370 * @message_type: the type of ClientMessage events to receive. This will be
371 * checked against the <structfield>message_type</structfield> field of the
372 * XClientMessage event struct.
373 * @func: the function to call to process the event.
374 * @data: user data to pass to @func.
376 * Adds a filter to the default display to be called when X ClientMessage events
377 * are received. See gdk_display_add_client_message_filter().
380 gdk_add_client_message_filter (GdkAtom message_type,
384 gdk_display_add_client_message_filter (gdk_display_get_default (),
385 message_type, func, data);
389 do_net_wm_state_changes (GdkWindow *window)
391 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
392 GdkWindowState old_state;
394 if (GDK_WINDOW_DESTROYED (window) ||
395 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
398 old_state = gdk_window_get_state (window);
400 /* For found_sticky to remain TRUE, we have to also be on desktop
403 if (old_state & GDK_WINDOW_STATE_STICKY)
405 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
406 gdk_synthesize_window_state (window,
407 GDK_WINDOW_STATE_STICKY,
412 if (toplevel->have_sticky && toplevel->on_all_desktops)
413 gdk_synthesize_window_state (window,
415 GDK_WINDOW_STATE_STICKY);
418 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
420 if (!toplevel->have_fullscreen)
421 gdk_synthesize_window_state (window,
422 GDK_WINDOW_STATE_FULLSCREEN,
427 if (toplevel->have_fullscreen)
428 gdk_synthesize_window_state (window,
430 GDK_WINDOW_STATE_FULLSCREEN);
433 /* Our "maximized" means both vertical and horizontal; if only one,
434 * we don't expose that via GDK
436 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
438 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
439 gdk_synthesize_window_state (window,
440 GDK_WINDOW_STATE_MAXIMIZED,
445 if (toplevel->have_maxvert && toplevel->have_maxhorz)
446 gdk_synthesize_window_state (window,
448 GDK_WINDOW_STATE_MAXIMIZED);
453 gdk_check_wm_desktop_changed (GdkWindow *window)
455 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
456 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
463 if (toplevel->have_sticky)
469 gdk_error_trap_push ();
470 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
471 GDK_WINDOW_XID (window),
472 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
473 0, G_MAXLONG, False, XA_CARDINAL, &type,
475 &bytes_after, &data);
476 gdk_error_trap_pop ();
480 desktop = (gulong *)data;
481 toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
485 toplevel->on_all_desktops = FALSE;
487 do_net_wm_state_changes (window);
492 gdk_check_wm_state_changed (GdkWindow *window)
494 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
495 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
505 gboolean had_sticky = toplevel->have_sticky;
507 toplevel->have_sticky = FALSE;
508 toplevel->have_maxvert = FALSE;
509 toplevel->have_maxhorz = FALSE;
510 toplevel->have_fullscreen = FALSE;
513 gdk_error_trap_push ();
514 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
515 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
516 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
517 &bytes_after, &data);
518 gdk_error_trap_pop ();
522 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
523 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
524 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
525 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
527 atoms = (Atom *)data;
532 if (atoms[i] == sticky_atom)
533 toplevel->have_sticky = TRUE;
534 else if (atoms[i] == maxvert_atom)
535 toplevel->have_maxvert = TRUE;
536 else if (atoms[i] == maxhorz_atom)
537 toplevel->have_maxhorz = TRUE;
538 else if (atoms[i] == fullscreen_atom)
539 toplevel->have_fullscreen = TRUE;
547 /* When have_sticky is turned on, we have to check the DESKTOP property
550 if (toplevel->have_sticky && !had_sticky)
551 gdk_check_wm_desktop_changed (window);
553 do_net_wm_state_changes (window);
556 #define HAS_FOCUS(toplevel) \
557 ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
560 generate_focus_event (GdkWindow *window,
565 event.type = GDK_FOCUS_CHANGE;
566 event.focus_change.window = window;
567 event.focus_change.send_event = FALSE;
568 event.focus_change.in = in;
570 gdk_event_put (&event);
574 set_screen_from_root (GdkDisplay *display,
580 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
583 gdk_event_set_screen (event, screen);
587 translate_key_event (GdkDisplay *display,
591 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
595 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
596 event->key.time = xevent->xkey.time;
598 event->key.state = (GdkModifierType) xevent->xkey.state;
599 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
600 event->key.hardware_keycode = xevent->xkey.keycode;
602 event->key.keyval = GDK_VoidSymbol;
604 gdk_keymap_translate_keyboard_state (keymap,
605 event->key.hardware_keycode,
611 /* Fill in event->string crudely, since various programs
614 event->key.string = NULL;
616 if (event->key.keyval != GDK_VoidSymbol)
617 c = gdk_keyval_to_unicode (event->key.keyval);
624 /* Apply the control key - Taken from Xlib
626 if (event->key.state & GDK_CONTROL_MASK)
628 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
631 event->key.string = g_memdup ("\0\0", 2);
632 event->key.length = 1;
636 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
637 else if (c == '8') c = '\177';
638 else if (c == '/') c = '_' & 0x1F;
641 len = g_unichar_to_utf8 (c, buf);
644 event->key.string = g_locale_from_utf8 (buf, len,
645 NULL, &bytes_written,
647 if (event->key.string)
648 event->key.length = bytes_written;
650 else if (event->key.keyval == GDK_Escape)
652 event->key.length = 1;
653 event->key.string = g_strdup ("\033");
655 else if (event->key.keyval == GDK_Return ||
656 event->key.keyval == GDK_KP_Enter)
658 event->key.length = 1;
659 event->key.string = g_strdup ("\r");
662 if (!event->key.string)
664 event->key.length = 0;
665 event->key.string = g_strdup ("");
669 #ifdef G_ENABLE_DEBUG
670 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
672 g_message ("%s:\t\twindow: %ld key: %12s %d",
673 event->type == GDK_KEY_PRESS ? "key press " : "key release",
675 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
678 if (event->key.length > 0)
679 g_message ("\t\tlength: %4d string: \"%s\"",
680 event->key.length, buf);
682 #endif /* G_ENABLE_DEBUG */
687 * gdk_x11_register_standard_event_type:
688 * @display: a #GdkDisplay
689 * @event_base: first event type code to register
690 * @n_events: number of event type codes to register
692 * Registers interest in receiving extension events with type codes
693 * between @event_base and <literal>event_base + n_events - 1</literal>.
694 * The registered events must have the window field in the same place
695 * as core X events (this is not the case for e.g. XKB extension events).
697 * If an event type is registered, events of this type will go through
698 * global and window-specific filters (see gdk_window_add_filter()).
699 * Unregistered events will only go through global filters.
700 * GDK may register the events of some X extensions on its own.
702 * This function should only be needed in unusual circumstances, e.g.
703 * when filtering XInput extension events on the root window.
708 gdk_x11_register_standard_event_type (GdkDisplay *display,
712 GdkEventTypeX11 *event_type;
713 GdkDisplayX11 *display_x11;
715 display_x11 = GDK_DISPLAY_X11 (display);
716 event_type = g_new (GdkEventTypeX11, 1);
718 event_type->base = event_base;
719 event_type->n_events = n_events;
721 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
724 /* Return the window this has to do with, if any, rather
725 * than the frame or root window that was selecting
729 get_real_window (GdkDisplay *display,
731 Window *event_window,
732 Window *filter_window)
734 /* Core events all have an event->xany.window field, but that's
735 * not true for extension events
737 if (event->type >= KeyPress &&
738 event->type <= MappingNotify)
740 *filter_window = event->xany.window;
744 *event_window = event->xcreatewindow.window;
747 *event_window = event->xdestroywindow.window;
750 *event_window = event->xunmap.window;
753 *event_window = event->xmap.window;
756 *event_window = event->xmaprequest.window;
759 *event_window = event->xreparent.window;
761 case ConfigureNotify:
762 *event_window = event->xconfigure.window;
764 case ConfigureRequest:
765 *event_window = event->xconfigurerequest.window;
768 *event_window = event->xgravity.window;
770 case CirculateNotify:
771 *event_window = event->xcirculate.window;
773 case CirculateRequest:
774 *event_window = event->xcirculaterequest.window;
777 *event_window = event->xany.window;
782 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
785 for (tmp_list = display_x11->event_types;
787 tmp_list = tmp_list->next)
789 GdkEventTypeX11 *event_type = tmp_list->data;
791 if (event->type >= event_type->base &&
792 event->type < event_type->base + event_type->n_events)
794 *event_window = event->xany.window;
795 *filter_window = event->xany.window;
800 *event_window = None;
801 *filter_window = None;
805 #ifdef G_ENABLE_DEBUG
806 static const char notify_modes[][19] = {
813 static const char notify_details[][23] = {
818 "NotifyNonlinearVirtual",
826 set_user_time (GdkWindow *window,
829 g_return_if_fail (event != NULL);
831 window = gdk_window_get_toplevel (event->client.window);
832 g_return_if_fail (GDK_IS_WINDOW (window));
834 /* If an event doesn't have a valid timestamp, we shouldn't use it
835 * to update the latest user interaction time.
837 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
838 gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
839 gdk_event_get_time (event));
843 gdk_event_translate (GdkDisplay *display,
846 gboolean return_exposes)
850 GdkWindowObject *window_private;
851 GdkWindow *filter_window;
852 GdkWindowImplX11 *window_impl = NULL;
854 gint xoffset, yoffset;
855 GdkScreen *screen = NULL;
856 GdkScreenX11 *screen_x11 = NULL;
857 GdkToplevelX11 *toplevel = NULL;
858 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
859 Window xwindow, filter_xwindow;
863 /* init these, since the done: block uses them */
865 window_private = NULL;
866 event->any.window = NULL;
868 if (_gdk_default_filters)
870 /* Apply global filters */
871 GdkFilterReturn result;
872 result = gdk_event_apply_filters (xevent, event,
873 _gdk_default_filters);
875 if (result != GDK_FILTER_CONTINUE)
877 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
882 /* Find the GdkWindow that this event relates to.
883 * Basically this means substructure events
884 * are reported same as structure events
886 get_real_window (display, xevent, &xwindow, &filter_xwindow);
888 window = gdk_window_lookup_for_display (display, xwindow);
889 /* We may receive events such as NoExpose/GraphicsExpose
890 * and ShmCompletion for pixmaps
892 if (window && !GDK_IS_WINDOW (window))
894 window_private = (GdkWindowObject *) window;
896 /* We always run the filters for the window where the event
897 * is delivered, not the window that it relates to
899 if (filter_xwindow == xwindow)
900 filter_window = window;
903 filter_window = gdk_window_lookup_for_display (display, filter_xwindow);
904 if (filter_window && !GDK_IS_WINDOW (filter_window))
905 filter_window = NULL;
910 screen = GDK_WINDOW_SCREEN (window);
911 screen_x11 = GDK_SCREEN_X11 (screen);
912 toplevel = _gdk_x11_window_get_toplevel (window);
917 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
919 /* Move key events on focus window to the real toplevel, and
920 * filter out all other events on focus window
922 if (toplevel && xwindow == toplevel->focus_window)
924 switch (xevent->type)
928 xwindow = GDK_WINDOW_XID (window);
929 xevent->xany.window = xwindow;
936 g_object_ref (window);
939 event->any.window = window;
940 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
942 if (window_private && GDK_WINDOW_DESTROYED (window))
944 if (xevent->type != DestroyNotify)
950 else if (filter_window)
952 /* Apply per-window filters */
953 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
954 GdkFilterReturn result;
956 if (filter_private->filters)
958 g_object_ref (filter_window);
960 result = gdk_event_apply_filters (xevent, event,
961 filter_private->filters);
963 g_object_unref (filter_window);
965 if (result != GDK_FILTER_CONTINUE)
967 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
973 if (screen_x11 && screen_x11->wmspec_check_window != None &&
974 xwindow == screen_x11->wmspec_check_window)
976 if (xevent->type == DestroyNotify)
978 screen_x11->wmspec_check_window = None;
979 g_free (screen_x11->window_manager_name);
980 screen_x11->window_manager_name = g_strdup ("unknown");
982 /* careful, reentrancy */
983 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
986 /* Eat events on this window unless someone had wrapped
987 * it as a foreign window
997 (xevent->xany.type == MotionNotify ||
998 xevent->xany.type == ButtonRelease))
1000 if (_gdk_moveresize_handle_event (xevent))
1007 /* We do a "manual" conversion of the XEvent to a
1008 * GdkEvent. The structures are mostly the same so
1009 * the conversion is fairly straightforward. We also
1010 * optionally print debugging info regarding events
1018 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
1026 switch (xevent->type)
1029 if (window_private == NULL)
1034 translate_key_event (display, event, xevent);
1035 set_user_time (window, event);
1039 if (window_private == NULL)
1045 /* Emulate detectable auto-repeat by checking to see
1046 * if the next event is a key press with the same
1047 * keycode and timestamp, and if so, ignoring the event.
1050 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
1054 XPeekEvent (xevent->xkey.display, &next_event);
1056 if (next_event.type == KeyPress &&
1057 next_event.xkey.keycode == xevent->xkey.keycode &&
1058 next_event.xkey.time == xevent->xkey.time)
1065 translate_key_event (display, event, xevent);
1070 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1071 xevent->xbutton.window,
1072 xevent->xbutton.x, xevent->xbutton.y,
1073 xevent->xbutton.button));
1075 if (window_private == NULL ||
1076 ((window_private->extension_events != 0) &&
1077 display_x11->input_ignore_core))
1083 /* If we get a ButtonPress event where the button is 4 or 5,
1084 it's a Scroll event */
1085 switch (xevent->xbutton.button)
1091 event->scroll.type = GDK_SCROLL;
1093 if (xevent->xbutton.button == 4)
1094 event->scroll.direction = GDK_SCROLL_UP;
1095 else if (xevent->xbutton.button == 5)
1096 event->scroll.direction = GDK_SCROLL_DOWN;
1097 else if (xevent->xbutton.button == 6)
1098 event->scroll.direction = GDK_SCROLL_LEFT;
1100 event->scroll.direction = GDK_SCROLL_RIGHT;
1102 event->scroll.window = window;
1103 event->scroll.time = xevent->xbutton.time;
1104 event->scroll.x = xevent->xbutton.x + xoffset;
1105 event->scroll.y = xevent->xbutton.y + yoffset;
1106 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
1107 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
1108 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
1109 event->scroll.device = display->core_pointer;
1111 set_screen_from_root (display, event, xevent->xbutton.root);
1116 event->button.type = GDK_BUTTON_PRESS;
1117 event->button.window = window;
1118 event->button.time = xevent->xbutton.time;
1119 event->button.x = xevent->xbutton.x + xoffset;
1120 event->button.y = xevent->xbutton.y + yoffset;
1121 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1122 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1123 event->button.axes = NULL;
1124 event->button.state = (GdkModifierType) xevent->xbutton.state;
1125 event->button.button = xevent->xbutton.button;
1126 event->button.device = display->core_pointer;
1128 set_screen_from_root (display, event, xevent->xbutton.root);
1130 _gdk_event_button_generate (display, event);
1134 set_user_time (window, event);
1139 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1140 xevent->xbutton.window,
1141 xevent->xbutton.x, xevent->xbutton.y,
1142 xevent->xbutton.button));
1144 if (window_private == NULL ||
1145 ((window_private->extension_events != 0) &&
1146 display_x11->input_ignore_core))
1152 /* We treat button presses as scroll wheel events, so ignore the release */
1153 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1154 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1160 event->button.type = GDK_BUTTON_RELEASE;
1161 event->button.window = window;
1162 event->button.time = xevent->xbutton.time;
1163 event->button.x = xevent->xbutton.x + xoffset;
1164 event->button.y = xevent->xbutton.y + yoffset;
1165 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1166 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1167 event->button.axes = NULL;
1168 event->button.state = (GdkModifierType) xevent->xbutton.state;
1169 event->button.button = xevent->xbutton.button;
1170 event->button.device = display->core_pointer;
1172 set_screen_from_root (display, event, xevent->xbutton.root);
1178 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1179 xevent->xmotion.window,
1180 xevent->xmotion.x, xevent->xmotion.y,
1181 (xevent->xmotion.is_hint) ? "true" : "false"));
1183 if (window_private == NULL ||
1184 ((window_private->extension_events != 0) &&
1185 display_x11->input_ignore_core))
1191 event->motion.type = GDK_MOTION_NOTIFY;
1192 event->motion.window = window;
1193 event->motion.time = xevent->xmotion.time;
1194 event->motion.x = xevent->xmotion.x + xoffset;
1195 event->motion.y = xevent->xmotion.y + yoffset;
1196 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1197 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1198 event->motion.axes = NULL;
1199 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1200 event->motion.is_hint = xevent->xmotion.is_hint;
1201 event->motion.device = display->core_pointer;
1203 set_screen_from_root (display, event, xevent->xmotion.root);
1209 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1210 xevent->xcrossing.window,
1211 xevent->xcrossing.detail,
1212 xevent->xcrossing.subwindow));
1214 if (window_private == NULL)
1220 /* Handle focusing (in the case where no window manager is running */
1221 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1223 toplevel->has_pointer = TRUE;
1225 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1227 gboolean had_focus = HAS_FOCUS (toplevel);
1229 toplevel->has_pointer_focus = TRUE;
1231 if (HAS_FOCUS (toplevel) != had_focus)
1232 generate_focus_event (window, TRUE);
1236 /* Tell XInput stuff about it if appropriate */
1237 if (window_private &&
1238 !GDK_WINDOW_DESTROYED (window) &&
1239 window_private->extension_events != 0)
1240 _gdk_input_enter_event (&xevent->xcrossing, window);
1242 event->crossing.type = GDK_ENTER_NOTIFY;
1243 event->crossing.window = window;
1245 /* If the subwindow field of the XEvent is non-NULL, then
1246 * lookup the corresponding GdkWindow.
1248 if (xevent->xcrossing.subwindow != None)
1249 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1251 event->crossing.subwindow = NULL;
1253 event->crossing.time = xevent->xcrossing.time;
1254 event->crossing.x = xevent->xcrossing.x + xoffset;
1255 event->crossing.y = xevent->xcrossing.y + yoffset;
1256 event->crossing.x_root = xevent->xcrossing.x_root;
1257 event->crossing.y_root = xevent->xcrossing.y_root;
1259 set_screen_from_root (display, event, xevent->xcrossing.root);
1261 /* Translate the crossing mode into Gdk terms.
1263 switch (xevent->xcrossing.mode)
1266 event->crossing.mode = GDK_CROSSING_NORMAL;
1269 event->crossing.mode = GDK_CROSSING_GRAB;
1272 event->crossing.mode = GDK_CROSSING_UNGRAB;
1276 /* Translate the crossing detail into Gdk terms.
1278 switch (xevent->xcrossing.detail)
1280 case NotifyInferior:
1281 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1283 case NotifyAncestor:
1284 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1287 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1289 case NotifyNonlinear:
1290 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1292 case NotifyNonlinearVirtual:
1293 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1296 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1300 event->crossing.focus = xevent->xcrossing.focus;
1301 event->crossing.state = xevent->xcrossing.state;
1307 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1308 xevent->xcrossing.window,
1309 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1311 if (window_private == NULL)
1317 /* Handle focusing (in the case where no window manager is running */
1318 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1320 toplevel->has_pointer = FALSE;
1322 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1324 gboolean had_focus = HAS_FOCUS (toplevel);
1326 toplevel->has_pointer_focus = FALSE;
1328 if (HAS_FOCUS (toplevel) != had_focus)
1329 generate_focus_event (window, FALSE);
1333 event->crossing.type = GDK_LEAVE_NOTIFY;
1334 event->crossing.window = window;
1336 /* If the subwindow field of the XEvent is non-NULL, then
1337 * lookup the corresponding GdkWindow.
1339 if (xevent->xcrossing.subwindow != None)
1340 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1342 event->crossing.subwindow = NULL;
1344 event->crossing.time = xevent->xcrossing.time;
1345 event->crossing.x = xevent->xcrossing.x + xoffset;
1346 event->crossing.y = xevent->xcrossing.y + yoffset;
1347 event->crossing.x_root = xevent->xcrossing.x_root;
1348 event->crossing.y_root = xevent->xcrossing.y_root;
1350 set_screen_from_root (display, event, xevent->xcrossing.root);
1352 /* Translate the crossing mode into Gdk terms.
1354 switch (xevent->xcrossing.mode)
1357 event->crossing.mode = GDK_CROSSING_NORMAL;
1360 event->crossing.mode = GDK_CROSSING_GRAB;
1363 event->crossing.mode = GDK_CROSSING_UNGRAB;
1367 /* Translate the crossing detail into Gdk terms.
1369 switch (xevent->xcrossing.detail)
1371 case NotifyInferior:
1372 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1374 case NotifyAncestor:
1375 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1378 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1380 case NotifyNonlinear:
1381 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1383 case NotifyNonlinearVirtual:
1384 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1387 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1391 event->crossing.focus = xevent->xcrossing.focus;
1392 event->crossing.state = xevent->xcrossing.state;
1396 /* We only care about focus events that indicate that _this_
1397 * window (not a ancestor or child) got or lost the focus
1401 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1402 xevent->xfocus.window,
1403 notify_details[xevent->xfocus.detail],
1404 notify_modes[xevent->xfocus.mode]));
1408 gboolean had_focus = HAS_FOCUS (toplevel);
1410 switch (xevent->xfocus.detail)
1412 case NotifyAncestor:
1414 /* When the focus moves from an ancestor of the window to
1415 * the window or a descendent of the window, *and* the
1416 * pointer is inside the window, then we were previously
1417 * receiving keystroke events in the has_pointer_focus
1418 * case and are now receiving them in the
1419 * has_focus_window case.
1421 if (toplevel->has_pointer &&
1422 xevent->xfocus.mode != NotifyGrab &&
1423 xevent->xfocus.mode != NotifyUngrab)
1424 toplevel->has_pointer_focus = FALSE;
1427 case NotifyNonlinear:
1428 case NotifyNonlinearVirtual:
1429 if (xevent->xfocus.mode != NotifyGrab &&
1430 xevent->xfocus.mode != NotifyUngrab)
1431 toplevel->has_focus_window = TRUE;
1432 /* We pretend that the focus moves to the grab
1433 * window, so we pay attention to NotifyGrab
1434 * NotifyUngrab, and ignore NotifyWhileGrabbed
1436 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1437 toplevel->has_focus = TRUE;
1440 /* The X server sends NotifyPointer/NotifyGrab,
1441 * but the pointer focus is ignored while a
1444 if (xevent->xfocus.mode != NotifyGrab &&
1445 xevent->xfocus.mode != NotifyUngrab)
1446 toplevel->has_pointer_focus = TRUE;
1448 case NotifyInferior:
1449 case NotifyPointerRoot:
1450 case NotifyDetailNone:
1454 if (HAS_FOCUS (toplevel) != had_focus)
1455 generate_focus_event (window, TRUE);
1460 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1461 xevent->xfocus.window,
1462 notify_details[xevent->xfocus.detail],
1463 notify_modes[xevent->xfocus.mode]));
1467 gboolean had_focus = HAS_FOCUS (toplevel);
1469 switch (xevent->xfocus.detail)
1471 case NotifyAncestor:
1473 /* When the focus moves from the window or a descendent
1474 * of the window to an ancestor of the window, *and* the
1475 * pointer is inside the window, then we were previously
1476 * receiving keystroke events in the has_focus_window
1477 * case and are now receiving them in the
1478 * has_pointer_focus case.
1480 if (toplevel->has_pointer &&
1481 xevent->xfocus.mode != NotifyGrab &&
1482 xevent->xfocus.mode != NotifyUngrab)
1483 toplevel->has_pointer_focus = TRUE;
1486 case NotifyNonlinear:
1487 case NotifyNonlinearVirtual:
1488 if (xevent->xfocus.mode != NotifyGrab &&
1489 xevent->xfocus.mode != NotifyUngrab)
1490 toplevel->has_focus_window = FALSE;
1491 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1492 toplevel->has_focus = FALSE;
1495 if (xevent->xfocus.mode != NotifyGrab &&
1496 xevent->xfocus.mode != NotifyUngrab)
1497 toplevel->has_pointer_focus = FALSE;
1499 case NotifyInferior:
1500 case NotifyPointerRoot:
1501 case NotifyDetailNone:
1505 if (HAS_FOCUS (toplevel) != had_focus)
1506 generate_focus_event (window, FALSE);
1511 /* gdk_keyboard_grab() causes following events. These events confuse
1512 * the XIM focus, so ignore them.
1514 if (xevent->xfocus.mode == NotifyGrab ||
1515 xevent->xfocus.mode == NotifyUngrab)
1521 g_message ("keymap notify"));
1523 /* Not currently handled */
1529 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1530 xevent->xexpose.window, xevent->xexpose.count,
1531 xevent->xexpose.x, xevent->xexpose.y,
1532 xevent->xexpose.width, xevent->xexpose.height,
1533 event->any.send_event ? " (send)" : ""));
1535 if (window_private == NULL)
1542 GdkRectangle expose_rect;
1544 expose_rect.x = xevent->xexpose.x + xoffset;
1545 expose_rect.y = xevent->xexpose.y + yoffset;
1546 expose_rect.width = xevent->xexpose.width;
1547 expose_rect.height = xevent->xexpose.height;
1551 event->expose.type = GDK_EXPOSE;
1552 event->expose.area = expose_rect;
1553 event->expose.region = gdk_region_rectangle (&expose_rect);
1554 event->expose.window = window;
1555 event->expose.count = xevent->xexpose.count;
1561 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1570 case GraphicsExpose:
1572 GdkRectangle expose_rect;
1575 g_message ("graphics expose:\tdrawable: %ld",
1576 xevent->xgraphicsexpose.drawable));
1578 if (window_private == NULL)
1584 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1585 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1586 expose_rect.width = xevent->xgraphicsexpose.width;
1587 expose_rect.height = xevent->xgraphicsexpose.height;
1591 event->expose.type = GDK_EXPOSE;
1592 event->expose.area = expose_rect;
1593 event->expose.region = gdk_region_rectangle (&expose_rect);
1594 event->expose.window = window;
1595 event->expose.count = xevent->xgraphicsexpose.count;
1601 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1611 g_message ("no expose:\t\tdrawable: %ld",
1612 xevent->xnoexpose.drawable));
1614 event->no_expose.type = GDK_NO_EXPOSE;
1615 event->no_expose.window = window;
1619 case VisibilityNotify:
1620 #ifdef G_ENABLE_DEBUG
1621 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1622 switch (xevent->xvisibility.state)
1624 case VisibilityFullyObscured:
1625 g_message ("visibility notify:\twindow: %ld none",
1626 xevent->xvisibility.window);
1628 case VisibilityPartiallyObscured:
1629 g_message ("visibility notify:\twindow: %ld partial",
1630 xevent->xvisibility.window);
1632 case VisibilityUnobscured:
1633 g_message ("visibility notify:\twindow: %ld full",
1634 xevent->xvisibility.window);
1637 #endif /* G_ENABLE_DEBUG */
1639 if (window_private == NULL)
1645 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1646 event->visibility.window = window;
1648 switch (xevent->xvisibility.state)
1650 case VisibilityFullyObscured:
1651 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1654 case VisibilityPartiallyObscured:
1655 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1658 case VisibilityUnobscured:
1659 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1667 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1668 xevent->xcreatewindow.window,
1669 xevent->xcreatewindow.x,
1670 xevent->xcreatewindow.y,
1671 xevent->xcreatewindow.width,
1672 xevent->xcreatewindow.height,
1673 xevent->xcreatewindow.border_width,
1674 xevent->xcreatewindow.parent,
1675 xevent->xcreatewindow.override_redirect));
1676 /* not really handled */
1681 g_message ("destroy notify:\twindow: %ld",
1682 xevent->xdestroywindow.window));
1684 /* Ignore DestroyNotify from SubstructureNotifyMask */
1685 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1687 event->any.type = GDK_DESTROY;
1688 event->any.window = window;
1690 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1692 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1693 gdk_window_destroy_notify (window);
1702 g_message ("unmap notify:\t\twindow: %ld",
1703 xevent->xmap.window));
1705 event->any.type = GDK_UNMAP;
1706 event->any.window = window;
1708 /* If we are shown (not withdrawn) and get an unmap, it means we
1709 * were iconified in the X sense. If we are withdrawn, and get
1710 * an unmap, it means we hid the window ourselves, so we
1711 * will have already flipped the iconified bit off.
1715 if (GDK_WINDOW_IS_MAPPED (window))
1716 gdk_synthesize_window_state (window,
1718 GDK_WINDOW_STATE_ICONIFIED);
1720 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1727 g_message ("map notify:\t\twindow: %ld",
1728 xevent->xmap.window));
1730 event->any.type = GDK_MAP;
1731 event->any.window = window;
1733 /* Unset iconified if it was set */
1734 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1735 gdk_synthesize_window_state (window,
1736 GDK_WINDOW_STATE_ICONIFIED,
1741 case ReparentNotify:
1743 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1744 xevent->xreparent.window,
1745 xevent->xreparent.x,
1746 xevent->xreparent.y,
1747 xevent->xreparent.parent,
1748 xevent->xreparent.override_redirect));
1750 /* Not currently handled */
1754 case ConfigureNotify:
1756 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1757 xevent->xconfigure.window,
1758 xevent->xconfigure.x,
1759 xevent->xconfigure.y,
1760 xevent->xconfigure.width,
1761 xevent->xconfigure.height,
1762 xevent->xconfigure.border_width,
1763 xevent->xconfigure.above,
1764 xevent->xconfigure.override_redirect,
1767 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1768 ? " (discarding child)"
1769 : xevent->xconfigure.event != xevent->xconfigure.window
1770 ? " (discarding substructure)"
1772 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1773 _gdk_x11_screen_size_changed (screen, xevent);
1776 xevent->xconfigure.event == xevent->xconfigure.window &&
1777 !GDK_WINDOW_DESTROYED (window) &&
1778 (window_private->extension_events != 0))
1779 _gdk_input_configure_event (&xevent->xconfigure, window);
1782 if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
1784 toplevel->current_counter_value = toplevel->pending_counter_value;
1785 XSyncIntToValue (&toplevel->pending_counter_value, 0);
1790 xevent->xconfigure.event != xevent->xconfigure.window ||
1791 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1792 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1796 event->configure.type = GDK_CONFIGURE;
1797 event->configure.window = window;
1798 event->configure.width = xevent->xconfigure.width;
1799 event->configure.height = xevent->xconfigure.height;
1801 if (!xevent->xconfigure.send_event &&
1802 !xevent->xconfigure.override_redirect &&
1803 !GDK_WINDOW_DESTROYED (window))
1807 Window child_window = 0;
1809 gdk_error_trap_push ();
1810 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1811 GDK_DRAWABLE_XID (window),
1812 screen_x11->xroot_window,
1817 event->configure.x = tx;
1818 event->configure.y = ty;
1820 gdk_error_trap_pop ();
1824 event->configure.x = xevent->xconfigure.x;
1825 event->configure.y = xevent->xconfigure.y;
1827 window_private->x = event->configure.x;
1828 window_private->y = event->configure.y;
1829 window_impl->width = xevent->xconfigure.width;
1830 window_impl->height = xevent->xconfigure.height;
1831 if (window_private->resize_count >= 1)
1833 window_private->resize_count -= 1;
1835 if (window_private->resize_count == 0)
1836 _gdk_moveresize_configure_done (display, window);
1841 case PropertyNotify:
1843 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1844 xevent->xproperty.window,
1845 xevent->xproperty.atom,
1847 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1850 if (window_private == NULL)
1856 /* We compare with the serial of the last time we mapped the
1857 * window to avoid refetching properties that we set ourselves
1860 xevent->xproperty.serial >= toplevel->map_serial)
1862 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1863 gdk_check_wm_state_changed (window);
1865 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1866 gdk_check_wm_desktop_changed (window);
1869 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1871 event->property.type = GDK_PROPERTY_NOTIFY;
1872 event->property.window = window;
1873 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1874 event->property.time = xevent->xproperty.time;
1875 event->property.state = xevent->xproperty.state;
1882 case SelectionClear:
1884 g_message ("selection clear:\twindow: %ld",
1885 xevent->xproperty.window));
1887 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1889 event->selection.type = GDK_SELECTION_CLEAR;
1890 event->selection.window = window;
1891 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1892 event->selection.time = xevent->xselectionclear.time;
1899 case SelectionRequest:
1901 g_message ("selection request:\twindow: %ld",
1902 xevent->xproperty.window));
1904 event->selection.type = GDK_SELECTION_REQUEST;
1905 event->selection.window = window;
1906 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1907 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1908 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1909 event->selection.requestor = xevent->xselectionrequest.requestor;
1910 event->selection.time = xevent->xselectionrequest.time;
1914 case SelectionNotify:
1916 g_message ("selection notify:\twindow: %ld",
1917 xevent->xproperty.window));
1920 event->selection.type = GDK_SELECTION_NOTIFY;
1921 event->selection.window = window;
1922 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1923 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1924 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1925 event->selection.time = xevent->xselection.time;
1929 case ColormapNotify:
1931 g_message ("colormap notify:\twindow: %ld",
1932 xevent->xcolormap.window));
1934 /* Not currently handled */
1941 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1942 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1945 g_message ("client message:\twindow: %ld",
1946 xevent->xclient.window));
1948 tmp_list = display_x11->client_filters;
1951 GdkClientFilter *filter = tmp_list->data;
1952 tmp_list = tmp_list->next;
1954 if (filter->type == message_type)
1956 result = (*filter->function) (xevent, event, filter->data);
1957 if (result != GDK_FILTER_CONTINUE)
1964 case GDK_FILTER_REMOVE:
1967 case GDK_FILTER_TRANSLATE:
1970 case GDK_FILTER_CONTINUE:
1971 /* Send unknown ClientMessage's on to Gtk for it to use */
1972 if (window_private == NULL)
1978 event->client.type = GDK_CLIENT_EVENT;
1979 event->client.window = window;
1980 event->client.message_type = message_type;
1981 event->client.data_format = xevent->xclient.format;
1982 memcpy(&event->client.data, &xevent->xclient.data,
1983 sizeof(event->client.data));
1993 g_message ("mapping notify"));
1995 /* Let XLib know that there is a new keyboard mapping.
1997 XRefreshKeyboardMapping (&xevent->xmapping);
1998 _gdk_keymap_keys_changed (display);
2004 if (xevent->type == display_x11->xkb_event_type)
2006 XkbEvent *xkb_event = (XkbEvent *)xevent;
2008 switch (xkb_event->any.xkb_type)
2010 case XkbNewKeyboardNotify:
2012 _gdk_keymap_keys_changed (display);
2017 case XkbStateNotify:
2018 _gdk_keymap_state_changed (display);
2025 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
2027 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
2028 event->owner_change.type = GDK_OWNER_CHANGE;
2029 event->owner_change.window = window;
2030 event->owner_change.owner = selection_notify->owner;
2031 event->owner_change.reason = selection_notify->subtype;
2032 event->owner_change.selection =
2033 gdk_x11_xatom_to_atom_for_display (display,
2034 selection_notify->selection);
2035 event->owner_change.time = selection_notify->timestamp;
2036 event->owner_change.selection_time = selection_notify->selection_timestamp;
2043 /* something else - (e.g., a Xinput event) */
2045 if (window_private &&
2046 !GDK_WINDOW_DESTROYED (window_private) &&
2047 (window_private->extension_events != 0))
2048 return_val = _gdk_input_other_event(event, xevent, window);
2059 if (event->any.window)
2060 g_object_ref (event->any.window);
2061 if (((event->any.type == GDK_ENTER_NOTIFY) ||
2062 (event->any.type == GDK_LEAVE_NOTIFY)) &&
2063 (event->crossing.subwindow != NULL))
2064 g_object_ref (event->crossing.subwindow);
2068 /* Mark this event as having no resources to be freed */
2069 event->any.window = NULL;
2070 event->any.type = GDK_NOTHING;
2074 g_object_unref (window);
2079 static GdkFilterReturn
2080 gdk_wm_protocols_filter (GdkXEvent *xev,
2084 XEvent *xevent = (XEvent *)xev;
2085 GdkWindow *win = event->any.window;
2086 GdkDisplay *display;
2090 return GDK_FILTER_REMOVE;
2092 display = GDK_WINDOW_DISPLAY (win);
2093 atom = (Atom)xevent->xclient.data.l[0];
2095 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
2097 /* The delete window request specifies a window
2098 * to delete. We don't actually destroy the
2099 * window because "it is only a request". (The
2100 * window might contain vital data that the
2101 * program does not want destroyed). Instead
2102 * the event is passed along to the program,
2103 * which should then destroy the window.
2106 g_message ("delete window:\t\twindow: %ld",
2107 xevent->xclient.window));
2109 event->any.type = GDK_DELETE;
2111 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
2113 return GDK_FILTER_TRANSLATE;
2115 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
2117 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2118 GdkWindowObject *private = (GdkWindowObject *)win;
2120 /* There is no way of knowing reliably whether we are viewable;
2121 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2123 if (toplevel && private->accept_focus)
2124 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
2126 xevent->xclient.data.l[1]);
2128 return GDK_FILTER_REMOVE;
2130 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
2131 !_gdk_x11_display_is_root_window (display,
2132 xevent->xclient.window))
2134 XEvent xev = *xevent;
2136 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
2137 XSendEvent (GDK_WINDOW_XDISPLAY (win),
2140 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
2142 return GDK_FILTER_REMOVE;
2144 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
2145 GDK_DISPLAY_X11 (display)->use_sync)
2147 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2151 XSyncIntsToValue (&toplevel->pending_counter_value,
2152 xevent->xclient.data.l[2],
2153 xevent->xclient.data.l[3]);
2156 return GDK_FILTER_REMOVE;
2159 return GDK_FILTER_CONTINUE;
2163 _gdk_events_queue (GdkDisplay *display)
2168 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2170 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
2172 XNextEvent (xdisplay, &xevent);
2174 switch (xevent.type)
2180 if (XFilterEvent (&xevent, None))
2184 event = gdk_event_new (GDK_NOTHING);
2186 event->any.window = NULL;
2187 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
2189 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2191 node = _gdk_event_queue_append (display, event);
2193 if (gdk_event_translate (display, event, &xevent, FALSE))
2195 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2199 _gdk_event_queue_remove_link (display, node);
2200 g_list_free_1 (node);
2201 gdk_event_free (event);
2207 gdk_event_prepare (GSource *source,
2210 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2213 GDK_THREADS_ENTER ();
2216 retval = (_gdk_event_queue_find_first (display) != NULL ||
2217 gdk_check_xpending (display));
2219 GDK_THREADS_LEAVE ();
2225 gdk_event_check (GSource *source)
2227 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2230 GDK_THREADS_ENTER ();
2232 if (display_source->event_poll_fd.revents & G_IO_IN)
2233 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2234 gdk_check_xpending (display_source->display));
2238 GDK_THREADS_LEAVE ();
2244 gdk_event_dispatch (GSource *source,
2245 GSourceFunc callback,
2248 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2251 GDK_THREADS_ENTER ();
2253 _gdk_events_queue (display);
2254 event = _gdk_event_unqueue (display);
2258 if (_gdk_event_func)
2259 (*_gdk_event_func) (event, _gdk_event_data);
2261 gdk_event_free (event);
2264 GDK_THREADS_LEAVE ();
2270 * gdk_event_send_client_message_for_display:
2271 * @display: the #GdkDisplay for the window where the message is to be sent.
2272 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2273 * @winid: the window to send the client message to.
2275 * On X11, sends an X ClientMessage event to a given window. On
2276 * Windows, sends a message registered with the name
2277 * GDK_WIN32_CLIENT_MESSAGE.
2279 * This could be used for communicating between different
2280 * applications, though the amount of data is limited to 20 bytes on
2281 * X11, and to just four bytes on Windows.
2283 * Returns: non-zero on success.
2288 gdk_event_send_client_message_for_display (GdkDisplay *display,
2290 GdkNativeWindow winid)
2294 g_return_val_if_fail(event != NULL, FALSE);
2296 /* Set up our event to send, with the exception of its target window */
2297 sev.xclient.type = ClientMessage;
2298 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2299 sev.xclient.format = event->client.data_format;
2300 sev.xclient.window = winid;
2301 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2302 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2304 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2309 /* Sends a ClientMessage to all toplevel client windows */
2311 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2318 unsigned long nitems, after;
2319 unsigned char *data;
2320 Window *ret_children, ret_root, ret_parent;
2321 unsigned int ret_nchildren;
2322 gboolean send = FALSE;
2323 gboolean found = FALSE;
2324 gboolean result = FALSE;
2327 gdk_error_trap_push ();
2329 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2330 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
2331 0, 0, False, AnyPropertyType,
2332 &type, &format, &nitems, &after, &data) != Success)
2342 /* OK, we're all set, now let's find some windows to send this to */
2343 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2344 &ret_root, &ret_parent,
2345 &ret_children, &ret_nchildren))
2348 for(i = 0; i < ret_nchildren; i++)
2349 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2352 XFree (ret_children);
2355 if (send || (!found && (level == 1)))
2357 xev->xclient.window = xid;
2358 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2361 result = send || found;
2364 gdk_error_trap_pop ();
2370 * gdk_screen_broadcast_client_message:
2371 * @screen: the #GdkScreen where the event will be broadcasted.
2372 * @event: the #GdkEvent.
2374 * On X11, sends an X ClientMessage event to all toplevel windows on
2377 * Toplevel windows are determined by checking for the WM_STATE property,
2378 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2379 * If no windows are found with the WM_STATE property set, the message is
2380 * sent to all children of the root window.
2382 * On Windows, broadcasts a message registered with the name
2383 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
2384 * data is limited to one long, i.e. four bytes.
2390 gdk_screen_broadcast_client_message (GdkScreen *screen,
2394 GdkWindow *root_window;
2396 g_return_if_fail (event != NULL);
2398 root_window = gdk_screen_get_root_window (screen);
2400 /* Set up our event to send, with the exception of its target window */
2401 sev.xclient.type = ClientMessage;
2402 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2403 sev.xclient.format = event->client.data_format;
2404 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2405 sev.xclient.message_type =
2406 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2407 event->client.message_type);
2409 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2411 GDK_WINDOW_XID (root_window),
2416 *--------------------------------------------------------------
2419 * Flushes the Xlib output buffer and then waits
2420 * until all requests have been received and processed
2421 * by the X server. The only real use for this function
2422 * is in dealing with XShm.
2430 *--------------------------------------------------------------
2436 GSList *tmp_list = _gdk_displays;
2440 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2441 tmp_list = tmp_list->next;
2446 timestamp_predicate (Display *display,
2450 Window xwindow = GPOINTER_TO_UINT (arg);
2451 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2453 if (xevent->type == PropertyNotify &&
2454 xevent->xproperty.window == xwindow &&
2455 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2456 "GDK_TIMESTAMP_PROP"))
2463 * gdk_x11_get_server_time:
2464 * @window: a #GdkWindow, used for communication with the server.
2465 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2466 * events mask or a hang will result.
2468 * Routine to get the current X server time stamp.
2470 * Return value: the time stamp.
2473 gdk_x11_get_server_time (GdkWindow *window)
2479 Atom timestamp_prop_atom;
2481 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2482 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2484 xdisplay = GDK_WINDOW_XDISPLAY (window);
2485 xwindow = GDK_WINDOW_XWINDOW (window);
2486 timestamp_prop_atom =
2487 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2488 "GDK_TIMESTAMP_PROP");
2490 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2491 timestamp_prop_atom,
2492 8, PropModeReplace, &c, 1);
2494 XIfEvent (xdisplay, &xevent,
2495 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2497 return xevent.xproperty.time;
2501 fetch_net_wm_check_window (GdkScreen *screen)
2503 GdkScreenX11 *screen_x11;
2504 GdkDisplay *display;
2512 /* This function is very slow on every call if you are not running a
2513 * spec-supporting WM. For now not optimized, because it isn't in
2514 * any critical code paths, but if you used it somewhere that had to
2515 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2516 * Probably at that point the function should be changed to query
2517 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2520 screen_x11 = GDK_SCREEN_X11 (screen);
2521 display = screen_x11->display;
2523 if (screen_x11->wmspec_check_window != None)
2524 return; /* already have it */
2526 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2527 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2528 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2529 &n_items, &bytes_after, &data);
2531 if (type != XA_WINDOW)
2534 xwindow = (Window *)data;
2536 gdk_error_trap_push ();
2538 /* Find out if this WM goes away, so we can reset everything. */
2539 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2540 gdk_display_sync (display);
2542 if (gdk_error_trap_pop () == Success)
2544 screen_x11->wmspec_check_window = *xwindow;
2547 screen_x11->need_refetch_net_supported = TRUE;
2548 screen_x11->need_refetch_wm_name = TRUE;
2550 /* Careful, reentrancy */
2551 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2556 * gdk_x11_screen_get_window_manager_name:
2557 * @screen: a #GdkScreen
2559 * Returns the name of the window manager for @screen.
2561 * Return value: the name of the window manager screen @screen, or
2562 * "unknown" if the window manager is unknown. The string is owned by GDK
2563 * and should not be freed.
2568 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2570 GdkScreenX11 *screen_x11;
2572 screen_x11 = GDK_SCREEN_X11 (screen);
2574 fetch_net_wm_check_window (screen);
2576 if (screen_x11->need_refetch_wm_name)
2578 /* Get the name of the window manager */
2579 screen_x11->need_refetch_wm_name = FALSE;
2581 g_free (screen_x11->window_manager_name);
2582 screen_x11->window_manager_name = g_strdup ("unknown");
2584 if (screen_x11->wmspec_check_window != None)
2594 gdk_error_trap_push ();
2596 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2597 screen_x11->wmspec_check_window,
2598 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2600 0, G_MAXLONG, False,
2601 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2604 &n_items, &bytes_after,
2607 gdk_display_sync (screen_x11->display);
2609 gdk_error_trap_pop ();
2613 g_free (screen_x11->window_manager_name);
2614 screen_x11->window_manager_name = g_strdup (name);
2620 return GDK_SCREEN_X11 (screen)->window_manager_name;
2623 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2625 struct _NetWmSupportedAtoms
2632 * gdk_x11_screen_supports_net_wm_hint:
2633 * @screen: the relevant #GdkScreen.
2634 * @property: a property atom.
2636 * This function is specific to the X11 backend of GDK, and indicates
2637 * whether the window manager supports a certain hint from the
2638 * Extended Window Manager Hints Specification. You can find this
2640 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2642 * When using this function, keep in mind that the window manager
2643 * can change over time; so you shouldn't use this function in
2644 * a way that impacts persistent application state. A common bug
2645 * is that your application can start up before the window manager
2646 * does when the user logs in, and before the window manager starts
2647 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2648 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2649 * a window manager change.
2651 * Return value: %TRUE if the window manager supports @property
2656 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2660 GdkScreenX11 *screen_x11;
2661 NetWmSupportedAtoms *supported_atoms;
2662 GdkDisplay *display;
2664 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2666 screen_x11 = GDK_SCREEN_X11 (screen);
2667 display = screen_x11->display;
2669 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2670 if (!supported_atoms)
2672 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2673 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2676 fetch_net_wm_check_window (screen);
2678 if (screen_x11->wmspec_check_window == None)
2681 if (screen_x11->need_refetch_net_supported)
2683 /* WM has changed since we last got the supported list,
2690 screen_x11->need_refetch_net_supported = FALSE;
2692 if (supported_atoms->atoms)
2693 XFree (supported_atoms->atoms);
2695 supported_atoms->atoms = NULL;
2696 supported_atoms->n_atoms = 0;
2698 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2699 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2700 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2701 &supported_atoms->n_atoms, &bytes_after,
2702 (guchar **)&supported_atoms->atoms);
2704 if (type != XA_ATOM)
2708 if (supported_atoms->atoms == NULL)
2712 while (i < supported_atoms->n_atoms)
2714 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2724 * gdk_net_wm_supports:
2725 * @property: a property atom.
2727 * This function is specific to the X11 backend of GDK, and indicates
2728 * whether the window manager for the default screen supports a certain
2729 * hint from the Extended Window Manager Hints Specification. See
2730 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2732 * Return value: %TRUE if the window manager supports @property
2735 gdk_net_wm_supports (GdkAtom property)
2737 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2742 const char *xsettings_name;
2743 const char *gdk_name;
2744 } settings_map[] = {
2745 { "Net/DoubleClickTime", "gtk-double-click-time" },
2746 { "Net/DoubleClickDistance", "gtk-double-click-distance" },
2747 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2748 { "Net/CursorBlink", "gtk-cursor-blink" },
2749 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2750 { "Net/ThemeName", "gtk-theme-name" },
2751 { "Net/IconThemeName", "gtk-icon-theme-name" },
2752 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2753 { "Gtk/ColorPalette", "gtk-color-palette" },
2754 { "Gtk/FontName", "gtk-font-name" },
2755 { "Gtk/IconSizes", "gtk-icon-sizes" },
2756 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2757 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2758 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2759 { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
2760 { "Gtk/IMStatusStyle", "gtk-im-status-style" },
2761 { "Gtk/Modules", "gtk-modules" },
2762 { "Gtk/FileChooserBackend", "gtk-file-chooser-backend" },
2763 { "Gtk/ButtonImages", "gtk-button-images" },
2764 { "Gtk/MenuImages", "gtk-menu-images" },
2765 { "Gtk/MenuBarAccel", "gtk-menu-bar-accel" },
2766 { "Xft/Antialias", "gtk-xft-antialias" },
2767 { "Xft/Hinting", "gtk-xft-hinting" },
2768 { "Xft/HintStyle", "gtk-xft-hintstyle" },
2769 { "Xft/RGBA", "gtk-xft-rgba" },
2770 { "Xft/DPI", "gtk-xft-dpi" },
2774 gdk_xsettings_notify_cb (const char *name,
2775 XSettingsAction action,
2776 XSettingsSetting *setting,
2780 GdkScreen *screen = data;
2781 GdkScreenX11 *screen_x11 = data;
2784 if (screen_x11->xsettings_in_init)
2787 new_event.type = GDK_SETTING;
2788 new_event.setting.window = gdk_screen_get_root_window (screen);
2789 new_event.setting.send_event = FALSE;
2790 new_event.setting.name = NULL;
2792 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2793 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2795 new_event.setting.name = (char *)settings_map[i].gdk_name;
2799 if (!new_event.setting.name)
2804 case XSETTINGS_ACTION_NEW:
2805 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2807 case XSETTINGS_ACTION_CHANGED:
2808 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2810 case XSETTINGS_ACTION_DELETED:
2811 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2815 gdk_event_put (&new_event);
2819 check_transform (const gchar *xsettings_name,
2823 if (!g_value_type_transformable (src_type, dest_type))
2825 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2827 g_type_name (src_type),
2828 g_type_name (dest_type));
2836 * gdk_screen_get_setting:
2837 * @screen: the #GdkScreen where the setting is located
2838 * @name: the name of the setting
2839 * @value: location to store the value of the setting
2841 * Retrieves a desktop-wide setting such as double-click time
2842 * for the #GdkScreen @screen.
2844 * FIXME needs a list of valid settings here, or a link to
2847 * Returns: %TRUE if the setting existed and a value was stored
2848 * in @value, %FALSE otherwise.
2853 gdk_screen_get_setting (GdkScreen *screen,
2858 const char *xsettings_name = NULL;
2859 XSettingsResult result;
2860 XSettingsSetting *setting;
2861 GdkScreenX11 *screen_x11;
2862 gboolean success = FALSE;
2864 GValue tmp_val = { 0, };
2866 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2868 screen_x11 = GDK_SCREEN_X11 (screen);
2870 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2871 if (strcmp (settings_map[i].gdk_name, name) == 0)
2873 xsettings_name = settings_map[i].xsettings_name;
2877 if (!xsettings_name)
2880 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2881 xsettings_name, &setting);
2882 if (result != XSETTINGS_SUCCESS)
2885 switch (setting->type)
2887 case XSETTINGS_TYPE_INT:
2888 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2890 g_value_init (&tmp_val, G_TYPE_INT);
2891 g_value_set_int (&tmp_val, setting->data.v_int);
2892 g_value_transform (&tmp_val, value);
2897 case XSETTINGS_TYPE_STRING:
2898 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2900 g_value_init (&tmp_val, G_TYPE_STRING);
2901 g_value_set_string (&tmp_val, setting->data.v_string);
2902 g_value_transform (&tmp_val, value);
2907 case XSETTINGS_TYPE_COLOR:
2908 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2912 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2915 color.red = setting->data.v_color.red;
2916 color.green = setting->data.v_color.green;
2917 color.blue = setting->data.v_color.blue;
2919 g_value_set_boxed (&tmp_val, &color);
2921 g_value_transform (&tmp_val, value);
2928 g_value_unset (&tmp_val);
2930 xsettings_setting_free (setting);
2935 static GdkFilterReturn
2936 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2940 GdkScreenX11 *screen = data;
2942 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2943 return GDK_FILTER_REMOVE;
2945 return GDK_FILTER_CONTINUE;
2949 gdk_xsettings_watch_cb (Window window,
2955 GdkScreen *screen = cb_data;
2957 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2962 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2964 g_object_ref (gdkwin);
2966 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2971 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2972 g_object_unref (gdkwin);
2976 #define __GDK_EVENTS_X11_C__
2977 #include "gdkaliasdef.c"