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"
46 #include <X11/XKBlib.h>
50 #include <X11/extensions/Xfixes.h>
53 #include <X11/Xatom.h>
55 typedef struct _GdkIOClosure GdkIOClosure;
56 typedef struct _GdkDisplaySource GdkDisplaySource;
57 typedef struct _GdkEventTypeX11 GdkEventTypeX11;
61 GdkInputFunction function;
62 GdkInputCondition condition;
63 GdkDestroyNotify notify;
67 struct _GdkDisplaySource
72 GPollFD event_poll_fd;
75 struct _GdkEventTypeX11
82 * Private function declarations
85 static gint gdk_event_apply_filters (XEvent *xevent,
88 static gboolean gdk_event_translate (GdkDisplay *display,
91 gboolean return_exposes);
93 static gboolean gdk_event_prepare (GSource *source,
95 static gboolean gdk_event_check (GSource *source);
96 static gboolean gdk_event_dispatch (GSource *source,
100 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
104 static GSource *gdk_display_source_new (GdkDisplay *display);
105 static gboolean gdk_check_xpending (GdkDisplay *display);
107 static void gdk_xsettings_watch_cb (Window window,
111 static void gdk_xsettings_notify_cb (const char *name,
112 XSettingsAction action,
113 XSettingsSetting *setting,
116 /* Private variable declarations
119 static GList *display_sources;
121 static GSourceFuncs event_funcs = {
129 gdk_display_source_new (GdkDisplay *display)
131 GSource *source = g_source_new (&event_funcs, sizeof (GdkDisplaySource));
132 GdkDisplaySource *display_source = (GdkDisplaySource *)source;
134 display_source->display = display;
140 gdk_check_xpending (GdkDisplay *display)
142 return XPending (GDK_DISPLAY_XDISPLAY (display));
145 /*********************************************
146 * Functions for maintaining the event queue *
147 *********************************************/
150 refcounted_grab_server (Display *xdisplay)
152 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
154 gdk_x11_display_grab (display);
158 refcounted_ungrab_server (Display *xdisplay)
160 GdkDisplay *display = gdk_x11_lookup_xdisplay (xdisplay);
162 gdk_x11_display_ungrab (display);
166 _gdk_x11_events_init_screen (GdkScreen *screen)
168 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
170 /* Keep a flag to avoid extra notifies that we don't need
172 screen_x11->xsettings_in_init = TRUE;
173 screen_x11->xsettings_client = xsettings_client_new (screen_x11->xdisplay,
174 screen_x11->screen_num,
175 gdk_xsettings_notify_cb,
176 gdk_xsettings_watch_cb,
178 xsettings_client_set_grab_func (screen_x11->xsettings_client,
179 refcounted_grab_server);
180 xsettings_client_set_ungrab_func (screen_x11->xsettings_client,
181 refcounted_ungrab_server);
182 screen_x11->xsettings_in_init = FALSE;
186 _gdk_x11_events_uninit_screen (GdkScreen *screen)
188 GdkScreenX11 *screen_x11 = GDK_SCREEN_X11 (screen);
190 xsettings_client_destroy (screen_x11->xsettings_client);
191 screen_x11->xsettings_client = NULL;
195 _gdk_events_init (GdkDisplay *display)
198 GdkDisplaySource *display_source;
199 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
201 int connection_number = ConnectionNumber (display_x11->xdisplay);
202 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
205 source = display_x11->event_source = gdk_display_source_new (display);
206 display_source = (GdkDisplaySource*) source;
207 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
209 display_source->event_poll_fd.fd = connection_number;
210 display_source->event_poll_fd.events = G_IO_IN;
212 g_source_add_poll (source, &display_source->event_poll_fd);
213 g_source_set_can_recurse (source, TRUE);
214 g_source_attach (source, NULL);
216 display_sources = g_list_prepend (display_sources,display_source);
218 gdk_display_add_client_message_filter (
220 gdk_atom_intern ("WM_PROTOCOLS", FALSE),
221 gdk_wm_protocols_filter,
227 * gdk_events_pending:
229 * Checks if any events are ready to be processed for any display.
231 * Return value: %TRUE if any events are pending.
234 gdk_events_pending (void)
238 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
240 GdkDisplaySource *tmp_source = tmp_list->data;
241 GdkDisplay *display = tmp_source->display;
243 if (_gdk_event_queue_find_first (display))
247 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
249 GdkDisplaySource *tmp_source = tmp_list->data;
250 GdkDisplay *display = tmp_source->display;
252 if (gdk_check_xpending (display))
260 graphics_expose_predicate (Display *display,
264 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
265 (xevent->xany.type == GraphicsExpose ||
266 xevent->xany.type == NoExpose))
273 * gdk_event_get_graphics_expose:
274 * @window: the #GdkWindow to wait for the events for.
276 * Waits for a GraphicsExpose or NoExpose event from the X server.
277 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
278 * GraphicsExpose events are handled before the widget is scrolled.
280 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
281 * NoExpose event was received.
284 gdk_event_get_graphics_expose (GdkWindow *window)
289 g_return_val_if_fail (window != NULL, NULL);
291 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
292 graphics_expose_predicate, (XPointer) window);
294 if (xevent.xany.type == GraphicsExpose)
296 event = gdk_event_new (GDK_NOTHING);
298 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
302 gdk_event_free (event);
309 gdk_event_apply_filters (XEvent *xevent,
314 GdkFilterReturn result;
320 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
322 tmp_list = tmp_list->next;
323 result = filter->function (xevent, event, filter->data);
324 if (result != GDK_FILTER_CONTINUE)
328 return GDK_FILTER_CONTINUE;
332 * gdk_display_add_client_message_filter:
333 * @display: a #GdkDisplay for which this message filter applies
334 * @message_type: the type of ClientMessage events to receive.
335 * This will be checked against the @message_type field
336 * of the XClientMessage event struct.
337 * @func: the function to call to process the event.
338 * @data: user data to pass to @func.
340 * Adds a filter to be called when X ClientMessage events are received.
345 gdk_display_add_client_message_filter (GdkDisplay *display,
346 GdkAtom message_type,
350 GdkClientFilter *filter;
351 g_return_if_fail (GDK_IS_DISPLAY (display));
352 filter = g_new (GdkClientFilter, 1);
354 filter->type = message_type;
355 filter->function = func;
358 GDK_DISPLAY_X11(display)->client_filters =
359 g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
364 * gdk_add_client_message_filter:
365 * @message_type: the type of ClientMessage events to receive. This will be
366 * checked against the <structfield>message_type</structfield> field of the
367 * XClientMessage event struct.
368 * @func: the function to call to process the event.
369 * @data: user data to pass to @func.
371 * Adds a filter to the default display to be called when X ClientMessage events
372 * are received. See gdk_display_add_client_message_filter().
375 gdk_add_client_message_filter (GdkAtom message_type,
379 gdk_display_add_client_message_filter (gdk_display_get_default (),
380 message_type, func, data);
384 do_net_wm_state_changes (GdkWindow *window)
386 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
387 GdkWindowState old_state;
389 if (GDK_WINDOW_DESTROYED (window) ||
390 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
393 old_state = gdk_window_get_state (window);
395 /* For found_sticky to remain TRUE, we have to also be on desktop
398 if (old_state & GDK_WINDOW_STATE_STICKY)
400 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
401 gdk_synthesize_window_state (window,
402 GDK_WINDOW_STATE_STICKY,
407 if (toplevel->have_sticky && toplevel->on_all_desktops)
408 gdk_synthesize_window_state (window,
410 GDK_WINDOW_STATE_STICKY);
413 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
415 if (!toplevel->have_fullscreen)
416 gdk_synthesize_window_state (window,
417 GDK_WINDOW_STATE_FULLSCREEN,
422 if (toplevel->have_fullscreen)
423 gdk_synthesize_window_state (window,
425 GDK_WINDOW_STATE_FULLSCREEN);
428 /* Our "maximized" means both vertical and horizontal; if only one,
429 * we don't expose that via GDK
431 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
433 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
434 gdk_synthesize_window_state (window,
435 GDK_WINDOW_STATE_MAXIMIZED,
440 if (toplevel->have_maxvert && toplevel->have_maxhorz)
441 gdk_synthesize_window_state (window,
443 GDK_WINDOW_STATE_MAXIMIZED);
448 gdk_check_wm_desktop_changed (GdkWindow *window)
450 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
451 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
458 if (toplevel->have_sticky)
462 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
463 GDK_WINDOW_XID (window),
464 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
465 0, G_MAXLONG, False, XA_CARDINAL, &type,
467 &bytes_after, (guchar **)&desktop);
471 toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
475 toplevel->on_all_desktops = FALSE;
477 do_net_wm_state_changes (window);
482 gdk_check_wm_state_changed (GdkWindow *window)
484 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
485 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
494 gboolean had_sticky = toplevel->have_sticky;
496 toplevel->have_sticky = FALSE;
497 toplevel->have_maxvert = FALSE;
498 toplevel->have_maxhorz = FALSE;
499 toplevel->have_fullscreen = FALSE;
501 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
502 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
503 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
504 &bytes_after, (guchar **)&atoms);
508 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
509 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
510 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
511 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
516 if (atoms[i] == sticky_atom)
517 toplevel->have_sticky = TRUE;
518 else if (atoms[i] == maxvert_atom)
519 toplevel->have_maxvert = TRUE;
520 else if (atoms[i] == maxhorz_atom)
521 toplevel->have_maxhorz = TRUE;
522 else if (atoms[i] == fullscreen_atom)
523 toplevel->have_fullscreen = TRUE;
531 /* When have_sticky is turned on, we have to check the DESKTOP property
534 if (toplevel->have_sticky && !had_sticky)
535 gdk_check_wm_desktop_changed (window);
537 do_net_wm_state_changes (window);
540 #define HAS_FOCUS(toplevel) \
541 ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
544 generate_focus_event (GdkWindow *window,
549 event.type = GDK_FOCUS_CHANGE;
550 event.focus_change.window = window;
551 event.focus_change.send_event = FALSE;
552 event.focus_change.in = in;
554 gdk_event_put (&event);
558 set_screen_from_root (GdkDisplay *display,
564 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
567 gdk_event_set_screen (event, screen);
571 translate_key_event (GdkDisplay *display,
575 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
579 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
580 event->key.time = xevent->xkey.time;
582 event->key.state = (GdkModifierType) xevent->xkey.state;
583 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
584 event->key.hardware_keycode = xevent->xkey.keycode;
586 event->key.keyval = GDK_VoidSymbol;
588 gdk_keymap_translate_keyboard_state (keymap,
589 event->key.hardware_keycode,
595 /* Fill in event->string crudely, since various programs
598 event->key.string = NULL;
600 if (event->key.keyval != GDK_VoidSymbol)
601 c = gdk_keyval_to_unicode (event->key.keyval);
608 /* Apply the control key - Taken from Xlib
610 if (event->key.state & GDK_CONTROL_MASK)
612 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
615 event->key.string = g_memdup ("\0\0", 2);
616 event->key.length = 1;
620 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
621 else if (c == '8') c = '\177';
622 else if (c == '/') c = '_' & 0x1F;
625 len = g_unichar_to_utf8 (c, buf);
628 event->key.string = g_locale_from_utf8 (buf, len,
629 NULL, &bytes_written,
631 if (event->key.string)
632 event->key.length = bytes_written;
634 else if (event->key.keyval == GDK_Escape)
636 event->key.length = 1;
637 event->key.string = g_strdup ("\033");
639 else if (event->key.keyval == GDK_Return ||
640 event->key.keyval == GDK_KP_Enter)
642 event->key.length = 1;
643 event->key.string = g_strdup ("\r");
646 if (!event->key.string)
648 event->key.length = 0;
649 event->key.string = g_strdup ("");
653 #ifdef G_ENABLE_DEBUG
654 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
656 g_message ("%s:\t\twindow: %ld key: %12s %d",
657 event->type == GDK_KEY_PRESS ? "key press " : "key release",
659 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
662 if (event->key.length > 0)
663 g_message ("\t\tlength: %4d string: \"%s\"",
664 event->key.length, buf);
666 #endif /* G_ENABLE_DEBUG */
671 * gdk_x11_register_standard_event_type:
672 * @display: a #GdkDisplay
673 * @event_base: first event type code to register
674 * @n_events: number of event type codes to register
676 * Registers interest in receiving extension events with type codes
677 * between @event_base and <literal>event_base + n_events - 1</literal>.
678 * The registered events must have the window field in the same place
679 * as core X events (this is not the case for e.g. XKB extension events).
681 * If an event type is registered, events of this type will go through
682 * global and window-specific filters (see gdk_window_add_filter()).
683 * Unregistered events will only go through global filters.
684 * GDK may register the events of some X extensions on its own.
686 * This function should only be needed in unusual circumstances, e.g.
687 * when filtering XInput extension events on the root window.
692 gdk_x11_register_standard_event_type (GdkDisplay *display,
696 GdkEventTypeX11 *event_type;
697 GdkDisplayX11 *display_x11;
699 display_x11 = GDK_DISPLAY_X11 (display);
700 event_type = g_new (GdkEventTypeX11, 1);
702 event_type->base = event_base;
703 event_type->n_events = n_events;
705 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
708 /* Return the window this has to do with, if any, rather
709 * than the frame or root window that was selecting
713 get_real_window (GdkDisplay *display,
715 Window *event_window,
716 Window *filter_window)
718 /* Core events all have an event->xany.window field, but that's
719 * not true for extension events
721 if (event->type >= KeyPress &&
722 event->type <= MappingNotify)
724 *filter_window = event->xany.window;
728 *event_window = event->xcreatewindow.window;
731 *event_window = event->xdestroywindow.window;
734 *event_window = event->xunmap.window;
737 *event_window = event->xmap.window;
740 *event_window = event->xmaprequest.window;
743 *event_window = event->xreparent.window;
745 case ConfigureNotify:
746 *event_window = event->xconfigure.window;
748 case ConfigureRequest:
749 *event_window = event->xconfigurerequest.window;
752 *event_window = event->xgravity.window;
754 case CirculateNotify:
755 *event_window = event->xcirculate.window;
757 case CirculateRequest:
758 *event_window = event->xcirculaterequest.window;
761 *event_window = event->xany.window;
766 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
769 for (tmp_list = display_x11->event_types;
771 tmp_list = tmp_list->next)
773 GdkEventTypeX11 *event_type = tmp_list->data;
775 if (event->type >= event_type->base &&
776 event->type < event_type->base + event_type->n_events)
778 *event_window = event->xany.window;
779 *filter_window = event->xany.window;
784 *event_window = None;
785 *filter_window = None;
789 #ifdef G_ENABLE_DEBUG
790 static const char notify_modes[][19] = {
797 static const char notify_details[][23] = {
802 "NotifyNonlinearVirtual",
810 set_user_time (GdkWindow *window,
813 g_return_if_fail (event != NULL);
815 window = gdk_window_get_toplevel (event->client.window);
816 g_return_if_fail (GDK_IS_WINDOW (window));
818 /* If an event doesn't have a valid timestamp, we shouldn't use it
819 * to update the latest user interaction time.
821 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
822 gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
823 gdk_event_get_time (event));
827 gdk_event_translate (GdkDisplay *display,
830 gboolean return_exposes)
834 GdkWindowObject *window_private;
835 GdkWindow *filter_window;
836 GdkWindowImplX11 *window_impl = NULL;
838 gint xoffset, yoffset;
839 GdkScreen *screen = NULL;
840 GdkScreenX11 *screen_x11 = NULL;
841 GdkToplevelX11 *toplevel = NULL;
842 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
843 Window xwindow, filter_xwindow;
847 /* init these, since the done: block uses them */
849 window_private = NULL;
850 event->any.window = NULL;
852 if (_gdk_default_filters)
854 /* Apply global filters */
855 GdkFilterReturn result;
856 result = gdk_event_apply_filters (xevent, event,
857 _gdk_default_filters);
859 if (result != GDK_FILTER_CONTINUE)
861 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
866 /* Find the GdkWindow that this event relates to.
867 * Basically this means substructure events
868 * are reported same as structure events
870 get_real_window (display, xevent, &xwindow, &filter_xwindow);
872 window = gdk_window_lookup_for_display (display, xwindow);
873 /* We may receive events such as NoExpose/GraphicsExpose
874 * and ShmCompletion for pixmaps
876 if (window && !GDK_IS_WINDOW (window))
878 window_private = (GdkWindowObject *) window;
880 /* We always run the filters for the window where the event
881 * is delivered, not the window that it relates to
883 if (filter_xwindow == xwindow)
884 filter_window = window;
887 filter_window = gdk_window_lookup_for_display (display, filter_xwindow);
888 if (filter_window && !GDK_IS_WINDOW (filter_window))
889 filter_window = NULL;
894 screen = GDK_WINDOW_SCREEN (window);
895 screen_x11 = GDK_SCREEN_X11 (screen);
896 toplevel = _gdk_x11_window_get_toplevel (window);
901 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
903 /* Move key events on focus window to the real toplevel, and
904 * filter out all other events on focus window
906 if (toplevel && xwindow == toplevel->focus_window)
908 switch (xevent->type)
912 xwindow = GDK_WINDOW_XID (window);
913 xevent->xany.window = xwindow;
920 g_object_ref (window);
923 event->any.window = window;
924 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
926 if (window_private && GDK_WINDOW_DESTROYED (window))
928 if (xevent->type != DestroyNotify)
934 else if (filter_window)
936 /* Apply per-window filters */
937 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
938 GdkFilterReturn result;
940 if (filter_private->filters)
942 g_object_ref (filter_window);
944 result = gdk_event_apply_filters (xevent, event,
945 filter_private->filters);
947 g_object_unref (filter_window);
949 if (result != GDK_FILTER_CONTINUE)
951 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
957 if (screen_x11 && screen_x11->wmspec_check_window != None &&
958 xwindow == screen_x11->wmspec_check_window)
960 if (xevent->type == DestroyNotify)
962 screen_x11->wmspec_check_window = None;
963 g_free (screen_x11->window_manager_name);
964 screen_x11->window_manager_name = g_strdup ("unknown");
966 /* careful, reentrancy */
967 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
970 /* Eat events on this window unless someone had wrapped
971 * it as a foreign window
981 (xevent->xany.type == MotionNotify ||
982 xevent->xany.type == ButtonRelease))
984 if (_gdk_moveresize_handle_event (xevent))
991 /* We do a "manual" conversion of the XEvent to a
992 * GdkEvent. The structures are mostly the same so
993 * the conversion is fairly straightforward. We also
994 * optionally print debugging info regarding events
1002 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
1010 switch (xevent->type)
1013 if (window_private == NULL)
1018 translate_key_event (display, event, xevent);
1019 set_user_time (window, event);
1023 if (window_private == NULL)
1029 /* Emulate detectable auto-repeat by checking to see
1030 * if the next event is a key press with the same
1031 * keycode and timestamp, and if so, ignoring the event.
1034 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
1038 XPeekEvent (xevent->xkey.display, &next_event);
1040 if (next_event.type == KeyPress &&
1041 next_event.xkey.keycode == xevent->xkey.keycode &&
1042 next_event.xkey.time == xevent->xkey.time)
1049 translate_key_event (display, event, xevent);
1054 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1055 xevent->xbutton.window,
1056 xevent->xbutton.x, xevent->xbutton.y,
1057 xevent->xbutton.button));
1059 if (window_private == NULL ||
1060 ((window_private->extension_events != 0) &&
1061 display_x11->input_ignore_core))
1067 /* If we get a ButtonPress event where the button is 4 or 5,
1068 it's a Scroll event */
1069 switch (xevent->xbutton.button)
1075 event->scroll.type = GDK_SCROLL;
1077 if (xevent->xbutton.button == 4)
1078 event->scroll.direction = GDK_SCROLL_UP;
1079 else if (xevent->xbutton.button == 5)
1080 event->scroll.direction = GDK_SCROLL_DOWN;
1081 else if (xevent->xbutton.button == 6)
1082 event->scroll.direction = GDK_SCROLL_LEFT;
1084 event->scroll.direction = GDK_SCROLL_RIGHT;
1086 event->scroll.window = window;
1087 event->scroll.time = xevent->xbutton.time;
1088 event->scroll.x = xevent->xbutton.x + xoffset;
1089 event->scroll.y = xevent->xbutton.y + yoffset;
1090 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
1091 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
1092 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
1093 event->scroll.device = display->core_pointer;
1095 set_screen_from_root (display, event, xevent->xbutton.root);
1100 event->button.type = GDK_BUTTON_PRESS;
1101 event->button.window = window;
1102 event->button.time = xevent->xbutton.time;
1103 event->button.x = xevent->xbutton.x + xoffset;
1104 event->button.y = xevent->xbutton.y + yoffset;
1105 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1106 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1107 event->button.axes = NULL;
1108 event->button.state = (GdkModifierType) xevent->xbutton.state;
1109 event->button.button = xevent->xbutton.button;
1110 event->button.device = display->core_pointer;
1112 set_screen_from_root (display, event, xevent->xbutton.root);
1114 _gdk_event_button_generate (display, event);
1118 set_user_time (window, event);
1123 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1124 xevent->xbutton.window,
1125 xevent->xbutton.x, xevent->xbutton.y,
1126 xevent->xbutton.button));
1128 if (window_private == NULL ||
1129 ((window_private->extension_events != 0) &&
1130 display_x11->input_ignore_core))
1136 /* We treat button presses as scroll wheel events, so ignore the release */
1137 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1138 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1144 event->button.type = GDK_BUTTON_RELEASE;
1145 event->button.window = window;
1146 event->button.time = xevent->xbutton.time;
1147 event->button.x = xevent->xbutton.x + xoffset;
1148 event->button.y = xevent->xbutton.y + yoffset;
1149 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1150 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1151 event->button.axes = NULL;
1152 event->button.state = (GdkModifierType) xevent->xbutton.state;
1153 event->button.button = xevent->xbutton.button;
1154 event->button.device = display->core_pointer;
1156 set_screen_from_root (display, event, xevent->xbutton.root);
1162 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1163 xevent->xmotion.window,
1164 xevent->xmotion.x, xevent->xmotion.y,
1165 (xevent->xmotion.is_hint) ? "true" : "false"));
1167 if (window_private == NULL ||
1168 ((window_private->extension_events != 0) &&
1169 display_x11->input_ignore_core))
1175 event->motion.type = GDK_MOTION_NOTIFY;
1176 event->motion.window = window;
1177 event->motion.time = xevent->xmotion.time;
1178 event->motion.x = xevent->xmotion.x + xoffset;
1179 event->motion.y = xevent->xmotion.y + yoffset;
1180 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1181 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1182 event->motion.axes = NULL;
1183 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1184 event->motion.is_hint = xevent->xmotion.is_hint;
1185 event->motion.device = display->core_pointer;
1187 set_screen_from_root (display, event, xevent->xmotion.root);
1193 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1194 xevent->xcrossing.window,
1195 xevent->xcrossing.detail,
1196 xevent->xcrossing.subwindow));
1198 if (window_private == NULL)
1204 /* Handle focusing (in the case where no window manager is running */
1206 xevent->xcrossing.detail != NotifyInferior &&
1207 xevent->xcrossing.focus && !toplevel->has_focus_window)
1209 gboolean had_focus = HAS_FOCUS (toplevel);
1211 toplevel->has_pointer_focus = TRUE;
1213 if (HAS_FOCUS (toplevel) != had_focus)
1214 generate_focus_event (window, TRUE);
1217 /* Tell XInput stuff about it if appropriate */
1218 if (window_private &&
1219 !GDK_WINDOW_DESTROYED (window) &&
1220 window_private->extension_events != 0)
1221 _gdk_input_enter_event (&xevent->xcrossing, window);
1223 event->crossing.type = GDK_ENTER_NOTIFY;
1224 event->crossing.window = window;
1226 /* If the subwindow field of the XEvent is non-NULL, then
1227 * lookup the corresponding GdkWindow.
1229 if (xevent->xcrossing.subwindow != None)
1230 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1232 event->crossing.subwindow = NULL;
1234 event->crossing.time = xevent->xcrossing.time;
1235 event->crossing.x = xevent->xcrossing.x + xoffset;
1236 event->crossing.y = xevent->xcrossing.y + yoffset;
1237 event->crossing.x_root = xevent->xcrossing.x_root;
1238 event->crossing.y_root = xevent->xcrossing.y_root;
1240 set_screen_from_root (display, event, xevent->xcrossing.root);
1242 /* Translate the crossing mode into Gdk terms.
1244 switch (xevent->xcrossing.mode)
1247 event->crossing.mode = GDK_CROSSING_NORMAL;
1250 event->crossing.mode = GDK_CROSSING_GRAB;
1253 event->crossing.mode = GDK_CROSSING_UNGRAB;
1257 /* Translate the crossing detail into Gdk terms.
1259 switch (xevent->xcrossing.detail)
1261 case NotifyInferior:
1262 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1264 case NotifyAncestor:
1265 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1268 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1270 case NotifyNonlinear:
1271 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1273 case NotifyNonlinearVirtual:
1274 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1277 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1281 event->crossing.focus = xevent->xcrossing.focus;
1282 event->crossing.state = xevent->xcrossing.state;
1288 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1289 xevent->xcrossing.window,
1290 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1292 if (window_private == NULL)
1298 /* Handle focusing (in the case where no window manager is running */
1300 xevent->xcrossing.detail != NotifyInferior &&
1301 xevent->xcrossing.focus && !toplevel->has_focus_window)
1303 gboolean had_focus = HAS_FOCUS (toplevel);
1305 toplevel->has_pointer_focus = FALSE;
1307 if (HAS_FOCUS (toplevel) != had_focus)
1308 generate_focus_event (window, FALSE);
1311 event->crossing.type = GDK_LEAVE_NOTIFY;
1312 event->crossing.window = window;
1314 /* If the subwindow field of the XEvent is non-NULL, then
1315 * lookup the corresponding GdkWindow.
1317 if (xevent->xcrossing.subwindow != None)
1318 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1320 event->crossing.subwindow = NULL;
1322 event->crossing.time = xevent->xcrossing.time;
1323 event->crossing.x = xevent->xcrossing.x + xoffset;
1324 event->crossing.y = xevent->xcrossing.y + yoffset;
1325 event->crossing.x_root = xevent->xcrossing.x_root;
1326 event->crossing.y_root = xevent->xcrossing.y_root;
1328 set_screen_from_root (display, event, xevent->xcrossing.root);
1330 /* Translate the crossing mode into Gdk terms.
1332 switch (xevent->xcrossing.mode)
1335 event->crossing.mode = GDK_CROSSING_NORMAL;
1338 event->crossing.mode = GDK_CROSSING_GRAB;
1341 event->crossing.mode = GDK_CROSSING_UNGRAB;
1345 /* Translate the crossing detail into Gdk terms.
1347 switch (xevent->xcrossing.detail)
1349 case NotifyInferior:
1350 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1352 case NotifyAncestor:
1353 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1356 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1358 case NotifyNonlinear:
1359 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1361 case NotifyNonlinearVirtual:
1362 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1365 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1369 event->crossing.focus = xevent->xcrossing.focus;
1370 event->crossing.state = xevent->xcrossing.state;
1374 /* We only care about focus events that indicate that _this_
1375 * window (not a ancestor or child) got or lost the focus
1379 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1380 xevent->xfocus.window,
1381 notify_details[xevent->xfocus.detail],
1382 notify_modes[xevent->xfocus.mode]));
1386 gboolean had_focus = HAS_FOCUS (toplevel);
1388 switch (xevent->xfocus.detail)
1390 case NotifyAncestor:
1391 case NotifyNonlinear:
1393 case NotifyNonlinearVirtual:
1394 toplevel->has_focus_window = TRUE;
1395 /* We pretend that the focus moves to the grab
1396 * window, so we pay attention to NotifyGrab
1397 * NotifyUngrab, and ignore NotifyWhileGrabbed
1399 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1400 toplevel->has_focus = TRUE;
1403 /* The X server sends NotifyPointer/NotifyGrab,
1404 * but the pointer focus is ignored while a
1407 if (xevent->xfocus.mode != NotifyGrab)
1408 toplevel->has_pointer_focus = TRUE;
1410 case NotifyInferior:
1411 case NotifyPointerRoot:
1412 case NotifyDetailNone:
1416 if (HAS_FOCUS (toplevel) != had_focus)
1417 generate_focus_event (window, TRUE);
1422 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1423 xevent->xfocus.window,
1424 notify_details[xevent->xfocus.detail],
1425 notify_modes[xevent->xfocus.mode]));
1429 gboolean had_focus = HAS_FOCUS (toplevel);
1431 switch (xevent->xfocus.detail)
1433 case NotifyAncestor:
1434 case NotifyNonlinear:
1436 case NotifyNonlinearVirtual:
1437 toplevel->has_focus_window = FALSE;
1438 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1439 toplevel->has_focus = FALSE;
1442 if (xevent->xfocus.mode != NotifyUngrab)
1443 toplevel->has_pointer_focus = FALSE;
1445 case NotifyInferior:
1446 case NotifyPointerRoot:
1447 case NotifyDetailNone:
1451 if (HAS_FOCUS (toplevel) != had_focus)
1452 generate_focus_event (window, FALSE);
1457 /* gdk_keyboard_grab() causes following events. These events confuse
1458 * the XIM focus, so ignore them.
1460 if (xevent->xfocus.mode == NotifyGrab ||
1461 xevent->xfocus.mode == NotifyUngrab)
1467 g_message ("keymap notify"));
1469 /* Not currently handled */
1475 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1476 xevent->xexpose.window, xevent->xexpose.count,
1477 xevent->xexpose.x, xevent->xexpose.y,
1478 xevent->xexpose.width, xevent->xexpose.height,
1479 event->any.send_event ? " (send)" : ""));
1481 if (window_private == NULL)
1488 GdkRectangle expose_rect;
1490 expose_rect.x = xevent->xexpose.x + xoffset;
1491 expose_rect.y = xevent->xexpose.y + yoffset;
1492 expose_rect.width = xevent->xexpose.width;
1493 expose_rect.height = xevent->xexpose.height;
1497 event->expose.type = GDK_EXPOSE;
1498 event->expose.area = expose_rect;
1499 event->expose.region = gdk_region_rectangle (&expose_rect);
1500 event->expose.window = window;
1501 event->expose.count = xevent->xexpose.count;
1507 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1516 case GraphicsExpose:
1518 GdkRectangle expose_rect;
1521 g_message ("graphics expose:\tdrawable: %ld",
1522 xevent->xgraphicsexpose.drawable));
1524 if (window_private == NULL)
1530 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1531 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1532 expose_rect.width = xevent->xgraphicsexpose.width;
1533 expose_rect.height = xevent->xgraphicsexpose.height;
1537 event->expose.type = GDK_EXPOSE;
1538 event->expose.area = expose_rect;
1539 event->expose.region = gdk_region_rectangle (&expose_rect);
1540 event->expose.window = window;
1541 event->expose.count = xevent->xgraphicsexpose.count;
1547 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1557 g_message ("no expose:\t\tdrawable: %ld",
1558 xevent->xnoexpose.drawable));
1560 event->no_expose.type = GDK_NO_EXPOSE;
1561 event->no_expose.window = window;
1565 case VisibilityNotify:
1566 #ifdef G_ENABLE_DEBUG
1567 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1568 switch (xevent->xvisibility.state)
1570 case VisibilityFullyObscured:
1571 g_message ("visibility notify:\twindow: %ld none",
1572 xevent->xvisibility.window);
1574 case VisibilityPartiallyObscured:
1575 g_message ("visibility notify:\twindow: %ld partial",
1576 xevent->xvisibility.window);
1578 case VisibilityUnobscured:
1579 g_message ("visibility notify:\twindow: %ld full",
1580 xevent->xvisibility.window);
1583 #endif /* G_ENABLE_DEBUG */
1585 if (window_private == NULL)
1591 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1592 event->visibility.window = window;
1594 switch (xevent->xvisibility.state)
1596 case VisibilityFullyObscured:
1597 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1600 case VisibilityPartiallyObscured:
1601 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1604 case VisibilityUnobscured:
1605 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1613 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1614 xevent->xcreatewindow.window,
1615 xevent->xcreatewindow.x,
1616 xevent->xcreatewindow.y,
1617 xevent->xcreatewindow.width,
1618 xevent->xcreatewindow.height,
1619 xevent->xcreatewindow.border_width,
1620 xevent->xcreatewindow.parent,
1621 xevent->xcreatewindow.override_redirect));
1622 /* not really handled */
1627 g_message ("destroy notify:\twindow: %ld",
1628 xevent->xdestroywindow.window));
1630 /* Ignore DestroyNotify from SubstructureNotifyMask */
1631 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1633 event->any.type = GDK_DESTROY;
1634 event->any.window = window;
1636 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1638 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1639 gdk_window_destroy_notify (window);
1648 g_message ("unmap notify:\t\twindow: %ld",
1649 xevent->xmap.window));
1651 event->any.type = GDK_UNMAP;
1652 event->any.window = window;
1654 /* If we are shown (not withdrawn) and get an unmap, it means we
1655 * were iconified in the X sense. If we are withdrawn, and get
1656 * an unmap, it means we hid the window ourselves, so we
1657 * will have already flipped the iconified bit off.
1661 if (GDK_WINDOW_IS_MAPPED (window))
1662 gdk_synthesize_window_state (window,
1664 GDK_WINDOW_STATE_ICONIFIED);
1666 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1673 g_message ("map notify:\t\twindow: %ld",
1674 xevent->xmap.window));
1676 event->any.type = GDK_MAP;
1677 event->any.window = window;
1679 /* Unset iconified if it was set */
1680 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1681 gdk_synthesize_window_state (window,
1682 GDK_WINDOW_STATE_ICONIFIED,
1687 case ReparentNotify:
1689 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1690 xevent->xreparent.window,
1691 xevent->xreparent.x,
1692 xevent->xreparent.y,
1693 xevent->xreparent.parent,
1694 xevent->xreparent.override_redirect));
1696 /* Not currently handled */
1700 case ConfigureNotify:
1702 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1703 xevent->xconfigure.window,
1704 xevent->xconfigure.x,
1705 xevent->xconfigure.y,
1706 xevent->xconfigure.width,
1707 xevent->xconfigure.height,
1708 xevent->xconfigure.border_width,
1709 xevent->xconfigure.above,
1710 xevent->xconfigure.override_redirect,
1713 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1714 ? " (discarding child)"
1715 : xevent->xconfigure.event != xevent->xconfigure.window
1716 ? " (discarding substructure)"
1718 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1719 _gdk_x11_screen_size_changed (screen, xevent);
1722 xevent->xconfigure.event == xevent->xconfigure.window &&
1723 !GDK_WINDOW_DESTROYED (window) &&
1724 (window_private->extension_events != 0))
1725 _gdk_input_configure_event (&xevent->xconfigure, window);
1728 xevent->xconfigure.event != xevent->xconfigure.window ||
1729 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1730 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1734 event->configure.type = GDK_CONFIGURE;
1735 event->configure.window = window;
1736 event->configure.width = xevent->xconfigure.width;
1737 event->configure.height = xevent->xconfigure.height;
1739 if (!xevent->xconfigure.send_event &&
1740 !xevent->xconfigure.override_redirect &&
1741 !GDK_WINDOW_DESTROYED (window))
1745 Window child_window = 0;
1747 gdk_error_trap_push ();
1748 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1749 GDK_DRAWABLE_XID (window),
1750 screen_x11->xroot_window,
1755 event->configure.x = tx;
1756 event->configure.y = ty;
1758 gdk_error_trap_pop ();
1762 event->configure.x = xevent->xconfigure.x;
1763 event->configure.y = xevent->xconfigure.y;
1765 window_private->x = event->configure.x;
1766 window_private->y = event->configure.y;
1767 window_impl->width = xevent->xconfigure.width;
1768 window_impl->height = xevent->xconfigure.height;
1769 if (window_private->resize_count >= 1)
1771 window_private->resize_count -= 1;
1773 if (window_private->resize_count == 0)
1774 _gdk_moveresize_configure_done (display, window);
1779 case PropertyNotify:
1781 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1782 xevent->xproperty.window,
1783 xevent->xproperty.atom,
1785 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1788 if (window_private == NULL)
1794 /* We compare with the serial of the last time we mapped the
1795 * window to avoid refetching properties that we set ourselves
1798 xevent->xproperty.serial >= toplevel->map_serial)
1800 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1801 gdk_check_wm_state_changed (window);
1803 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1804 gdk_check_wm_desktop_changed (window);
1807 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1809 event->property.type = GDK_PROPERTY_NOTIFY;
1810 event->property.window = window;
1811 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1812 event->property.time = xevent->xproperty.time;
1813 event->property.state = xevent->xproperty.state;
1820 case SelectionClear:
1822 g_message ("selection clear:\twindow: %ld",
1823 xevent->xproperty.window));
1825 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1827 event->selection.type = GDK_SELECTION_CLEAR;
1828 event->selection.window = window;
1829 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1830 event->selection.time = xevent->xselectionclear.time;
1837 case SelectionRequest:
1839 g_message ("selection request:\twindow: %ld",
1840 xevent->xproperty.window));
1842 event->selection.type = GDK_SELECTION_REQUEST;
1843 event->selection.window = window;
1844 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1845 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1846 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1847 event->selection.requestor = xevent->xselectionrequest.requestor;
1848 event->selection.time = xevent->xselectionrequest.time;
1852 case SelectionNotify:
1854 g_message ("selection notify:\twindow: %ld",
1855 xevent->xproperty.window));
1858 event->selection.type = GDK_SELECTION_NOTIFY;
1859 event->selection.window = window;
1860 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1861 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1862 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1863 event->selection.time = xevent->xselection.time;
1867 case ColormapNotify:
1869 g_message ("colormap notify:\twindow: %ld",
1870 xevent->xcolormap.window));
1872 /* Not currently handled */
1879 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1880 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1883 g_message ("client message:\twindow: %ld",
1884 xevent->xclient.window));
1886 tmp_list = display_x11->client_filters;
1889 GdkClientFilter *filter = tmp_list->data;
1890 tmp_list = tmp_list->next;
1892 if (filter->type == message_type)
1894 result = (*filter->function) (xevent, event, filter->data);
1895 if (result != GDK_FILTER_CONTINUE)
1902 case GDK_FILTER_REMOVE:
1905 case GDK_FILTER_TRANSLATE:
1908 case GDK_FILTER_CONTINUE:
1909 /* Send unknown ClientMessage's on to Gtk for it to use */
1910 if (window_private == NULL)
1916 event->client.type = GDK_CLIENT_EVENT;
1917 event->client.window = window;
1918 event->client.message_type = message_type;
1919 event->client.data_format = xevent->xclient.format;
1920 memcpy(&event->client.data, &xevent->xclient.data,
1921 sizeof(event->client.data));
1931 g_message ("mapping notify"));
1933 /* Let XLib know that there is a new keyboard mapping.
1935 XRefreshKeyboardMapping (&xevent->xmapping);
1936 _gdk_keymap_keys_changed (display);
1942 if (xevent->type == display_x11->xkb_event_type)
1944 XkbEvent *xkb_event = (XkbEvent *)xevent;
1946 switch (xkb_event->any.xkb_type)
1948 case XkbNewKeyboardNotify:
1950 _gdk_keymap_keys_changed (display);
1955 case XkbStateNotify:
1956 _gdk_keymap_state_changed (display);
1963 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
1965 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
1966 event->owner_change.type = GDK_OWNER_CHANGE;
1967 event->owner_change.window = window;
1968 event->owner_change.owner = selection_notify->owner;
1969 event->owner_change.reason = selection_notify->subtype;
1970 event->owner_change.selection =
1971 gdk_x11_xatom_to_atom_for_display (display,
1972 selection_notify->selection);
1973 event->owner_change.time = selection_notify->timestamp;
1974 event->owner_change.selection_time = selection_notify->selection_timestamp;
1981 /* something else - (e.g., a Xinput event) */
1983 if (window_private &&
1984 !GDK_WINDOW_DESTROYED (window_private) &&
1985 (window_private->extension_events != 0))
1986 return_val = _gdk_input_other_event(event, xevent, window);
1997 if (event->any.window)
1998 g_object_ref (event->any.window);
1999 if (((event->any.type == GDK_ENTER_NOTIFY) ||
2000 (event->any.type == GDK_LEAVE_NOTIFY)) &&
2001 (event->crossing.subwindow != NULL))
2002 g_object_ref (event->crossing.subwindow);
2006 /* Mark this event as having no resources to be freed */
2007 event->any.window = NULL;
2008 event->any.type = GDK_NOTHING;
2012 g_object_unref (window);
2017 static GdkFilterReturn
2018 gdk_wm_protocols_filter (GdkXEvent *xev,
2022 XEvent *xevent = (XEvent *)xev;
2023 GdkWindow *win = event->any.window;
2024 GdkDisplay *display = GDK_WINDOW_DISPLAY (win);
2026 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
2028 /* The delete window request specifies a window
2029 * to delete. We don't actually destroy the
2030 * window because "it is only a request". (The
2031 * window might contain vital data that the
2032 * program does not want destroyed). Instead
2033 * the event is passed along to the program,
2034 * which should then destroy the window.
2037 g_message ("delete window:\t\twindow: %ld",
2038 xevent->xclient.window));
2040 event->any.type = GDK_DELETE;
2042 return GDK_FILTER_TRANSLATE;
2044 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
2046 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2047 GdkWindowObject *private = (GdkWindowObject *)win;
2049 /* There is no way of knowing reliably whether we are viewable;
2050 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2052 if (toplevel && private->accept_focus)
2053 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
2055 xevent->xclient.data.l[1]);
2057 return GDK_FILTER_REMOVE;
2059 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
2060 !_gdk_x11_display_is_root_window (display,
2061 xevent->xclient.window))
2063 XEvent xev = *xevent;
2065 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
2066 XSendEvent (GDK_WINDOW_XDISPLAY (win),
2069 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
2071 return GDK_FILTER_REMOVE;
2074 return GDK_FILTER_CONTINUE;
2078 _gdk_events_queue (GdkDisplay *display)
2083 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2085 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
2087 XNextEvent (xdisplay, &xevent);
2089 switch (xevent.type)
2095 if (XFilterEvent (&xevent, None))
2099 event = gdk_event_new (GDK_NOTHING);
2101 event->any.window = NULL;
2102 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
2104 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2106 node = _gdk_event_queue_append (display, event);
2108 if (gdk_event_translate (display, event, &xevent, FALSE))
2110 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2114 _gdk_event_queue_remove_link (display, node);
2115 g_list_free_1 (node);
2116 gdk_event_free (event);
2122 gdk_event_prepare (GSource *source,
2125 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2128 GDK_THREADS_ENTER ();
2131 retval = (_gdk_event_queue_find_first (display) != NULL ||
2132 gdk_check_xpending (display));
2134 GDK_THREADS_LEAVE ();
2140 gdk_event_check (GSource *source)
2142 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2145 GDK_THREADS_ENTER ();
2147 if (display_source->event_poll_fd.revents & G_IO_IN)
2148 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2149 gdk_check_xpending (display_source->display));
2153 GDK_THREADS_LEAVE ();
2159 gdk_event_dispatch (GSource *source,
2160 GSourceFunc callback,
2163 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2166 GDK_THREADS_ENTER ();
2168 _gdk_events_queue (display);
2169 event = _gdk_event_unqueue (display);
2173 if (_gdk_event_func)
2174 (*_gdk_event_func) (event, _gdk_event_data);
2176 gdk_event_free (event);
2179 GDK_THREADS_LEAVE ();
2185 * gdk_event_send_client_message_for_display:
2186 * @display: the #GdkDisplay for the window where the message is to be sent.
2187 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2188 * @winid: the window to send the client message to.
2190 * On X11, sends an X ClientMessage event to a given window. On
2191 * Windows, sends a message registered with the name
2192 * GDK_WIN32_CLIENT_MESSAGE.
2194 * This could be used for communicating between different
2195 * applications, though the amount of data is limited to 20 bytes on
2196 * X11, and to just four bytes on Windows.
2198 * Returns: non-zero on success.
2203 gdk_event_send_client_message_for_display (GdkDisplay *display,
2205 GdkNativeWindow winid)
2209 g_return_val_if_fail(event != NULL, FALSE);
2211 /* Set up our event to send, with the exception of its target window */
2212 sev.xclient.type = ClientMessage;
2213 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2214 sev.xclient.format = event->client.data_format;
2215 sev.xclient.window = winid;
2216 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2217 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2219 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2224 /* Sends a ClientMessage to all toplevel client windows */
2226 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2233 unsigned long nitems, after;
2234 unsigned char *data;
2235 Window *ret_children, ret_root, ret_parent;
2236 unsigned int ret_nchildren;
2237 gboolean send = FALSE;
2238 gboolean found = FALSE;
2239 gboolean result = FALSE;
2242 gdk_error_trap_push ();
2244 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2245 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
2246 0, 0, False, AnyPropertyType,
2247 &type, &format, &nitems, &after, &data) != Success)
2257 /* OK, we're all set, now let's find some windows to send this to */
2258 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2259 &ret_root, &ret_parent,
2260 &ret_children, &ret_nchildren))
2263 for(i = 0; i < ret_nchildren; i++)
2264 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2267 XFree (ret_children);
2270 if (send || (!found && (level == 1)))
2272 xev->xclient.window = xid;
2273 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2276 result = send || found;
2279 gdk_error_trap_pop ();
2285 * gdk_screen_broadcast_client_message:
2286 * @screen: the #GdkScreen where the event will be broadcasted.
2287 * @event: the #GdkEvent.
2289 * On X11, sends an X ClientMessage event to all toplevel windows on
2292 * Toplevel windows are determined by checking for the WM_STATE property,
2293 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2294 * If no windows are found with the WM_STATE property set, the message is
2295 * sent to all children of the root window.
2297 * On Windows, broadcasts a message registered with the name
2298 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
2299 * data is limited to one long, i.e. four bytes.
2305 gdk_screen_broadcast_client_message (GdkScreen *screen,
2309 GdkWindow *root_window;
2311 g_return_if_fail (event != NULL);
2313 root_window = gdk_screen_get_root_window (screen);
2315 /* Set up our event to send, with the exception of its target window */
2316 sev.xclient.type = ClientMessage;
2317 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2318 sev.xclient.format = event->client.data_format;
2319 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2320 sev.xclient.message_type =
2321 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2322 event->client.message_type);
2324 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2326 GDK_WINDOW_XID (root_window),
2331 *--------------------------------------------------------------
2334 * Flushes the Xlib output buffer and then waits
2335 * until all requests have been received and processed
2336 * by the X server. The only real use for this function
2337 * is in dealing with XShm.
2345 *--------------------------------------------------------------
2351 GSList *tmp_list = _gdk_displays;
2355 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2356 tmp_list = tmp_list->next;
2361 timestamp_predicate (Display *display,
2365 Window xwindow = GPOINTER_TO_UINT (arg);
2366 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2368 if (xevent->type == PropertyNotify &&
2369 xevent->xproperty.window == xwindow &&
2370 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2371 "GDK_TIMESTAMP_PROP"))
2378 * gdk_x11_get_server_time:
2379 * @window: a #GdkWindow, used for communication with the server.
2380 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2381 * events mask or a hang will result.
2383 * Routine to get the current X server time stamp.
2385 * Return value: the time stamp.
2388 gdk_x11_get_server_time (GdkWindow *window)
2394 Atom timestamp_prop_atom;
2396 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2397 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2399 xdisplay = GDK_WINDOW_XDISPLAY (window);
2400 xwindow = GDK_WINDOW_XWINDOW (window);
2401 timestamp_prop_atom =
2402 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2403 "GDK_TIMESTAMP_PROP");
2405 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2406 timestamp_prop_atom,
2407 8, PropModeReplace, &c, 1);
2409 XIfEvent (xdisplay, &xevent,
2410 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2412 return xevent.xproperty.time;
2416 fetch_net_wm_check_window (GdkScreen *screen)
2418 GdkScreenX11 *screen_x11;
2419 GdkDisplay *display;
2426 /* This function is very slow on every call if you are not running a
2427 * spec-supporting WM. For now not optimized, because it isn't in
2428 * any critical code paths, but if you used it somewhere that had to
2429 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2430 * Probably at that point the function should be changed to query
2431 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2434 screen_x11 = GDK_SCREEN_X11 (screen);
2435 display = screen_x11->display;
2437 if (screen_x11->wmspec_check_window != None)
2438 return; /* already have it */
2440 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2441 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2442 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2443 &n_items, &bytes_after, (guchar **) & xwindow);
2445 if (type != XA_WINDOW)
2448 gdk_error_trap_push ();
2450 /* Find out if this WM goes away, so we can reset everything. */
2451 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2452 gdk_display_sync (display);
2454 if (gdk_error_trap_pop () == Success)
2456 screen_x11->wmspec_check_window = *xwindow;
2459 screen_x11->need_refetch_net_supported = TRUE;
2460 screen_x11->need_refetch_wm_name = TRUE;
2462 /* Careful, reentrancy */
2463 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2468 * gdk_x11_screen_get_window_manager_name:
2469 * @screen: a #GdkScreen
2471 * Returns the name of the window manager for @screen.
2473 * Return value: the name of the window manager screen @screen, or
2474 * "unknown" if the window manager is unknown. The string is owned by GDK
2475 * and should not be freed.
2480 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2482 GdkScreenX11 *screen_x11;
2484 screen_x11 = GDK_SCREEN_X11 (screen);
2486 fetch_net_wm_check_window (screen);
2488 if (screen_x11->need_refetch_wm_name)
2490 /* Get the name of the window manager */
2491 screen_x11->need_refetch_wm_name = FALSE;
2493 g_free (screen_x11->window_manager_name);
2494 screen_x11->window_manager_name = g_strdup ("unknown");
2496 if (screen_x11->wmspec_check_window != None)
2506 gdk_error_trap_push ();
2508 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2509 screen_x11->wmspec_check_window,
2510 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2512 0, G_MAXLONG, False,
2513 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2516 &n_items, &bytes_after,
2519 gdk_display_sync (screen_x11->display);
2521 gdk_error_trap_pop ();
2525 g_free (screen_x11->window_manager_name);
2526 screen_x11->window_manager_name = g_strdup (name);
2532 return GDK_SCREEN_X11 (screen)->window_manager_name;
2535 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2537 struct _NetWmSupportedAtoms
2544 * gdk_x11_screen_supports_net_wm_hint:
2545 * @screen: the relevant #GdkScreen.
2546 * @property: a property atom.
2548 * This function is specific to the X11 backend of GDK, and indicates
2549 * whether the window manager supports a certain hint from the
2550 * Extended Window Manager Hints Specification. You can find this
2552 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2554 * When using this function, keep in mind that the window manager
2555 * can change over time; so you shouldn't use this function in
2556 * a way that impacts persistent application state. A common bug
2557 * is that your application can start up before the window manager
2558 * does when the user logs in, and before the window manager starts
2559 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2560 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2561 * a window manager change.
2563 * Return value: %TRUE if the window manager supports @property
2568 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2572 GdkScreenX11 *screen_x11;
2573 NetWmSupportedAtoms *supported_atoms;
2574 GdkDisplay *display;
2576 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2578 screen_x11 = GDK_SCREEN_X11 (screen);
2579 display = screen_x11->display;
2581 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2582 if (!supported_atoms)
2584 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2585 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2588 fetch_net_wm_check_window (screen);
2590 if (screen_x11->wmspec_check_window == None)
2593 if (screen_x11->need_refetch_net_supported)
2595 /* WM has changed since we last got the supported list,
2602 screen_x11->need_refetch_net_supported = FALSE;
2604 if (supported_atoms->atoms)
2605 XFree (supported_atoms->atoms);
2607 supported_atoms->atoms = NULL;
2608 supported_atoms->n_atoms = 0;
2610 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2611 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2612 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2613 &supported_atoms->n_atoms, &bytes_after,
2614 (guchar **)&supported_atoms->atoms);
2616 if (type != XA_ATOM)
2620 if (supported_atoms->atoms == NULL)
2624 while (i < supported_atoms->n_atoms)
2626 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2636 * gdk_net_wm_supports:
2637 * @property: a property atom.
2639 * This function is specific to the X11 backend of GDK, and indicates
2640 * whether the window manager for the default screen supports a certain
2641 * hint from the Extended Window Manager Hints Specification. See
2642 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2644 * Return value: %TRUE if the window manager supports @property
2647 gdk_net_wm_supports (GdkAtom property)
2649 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2654 const char *xsettings_name;
2655 const char *gdk_name;
2656 } settings_map[] = {
2657 { "Net/DoubleClickTime", "gtk-double-click-time" },
2658 { "Net/DoubleClickDistance", "gtk-double-click-distance" },
2659 { "Net/DndDragThreshold", "gtk-dnd-drag-threshold" },
2660 { "Gtk/CanChangeAccels", "gtk-can-change-accels" },
2661 { "Gtk/ColorPalette", "gtk-color-palette" },
2662 { "Gtk/FontName", "gtk-font-name" },
2663 { "Gtk/IconSizes", "gtk-icon-sizes" },
2664 { "Gtk/KeyThemeName", "gtk-key-theme-name" },
2665 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2666 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2667 { "Gtk/IMPreeditStyle", "gtk-im-preedit-style" },
2668 { "Gtk/IMStatusStyle", "gtk-im-status-style" },
2669 { "Net/CursorBlink", "gtk-cursor-blink" },
2670 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2671 { "Net/ThemeName", "gtk-theme-name" },
2672 { "Net/IconThemeName", "gtk-icon-theme-name" },
2673 { "Gtk/FileChooserBackend", "gtk-file-chooser-backend" },
2674 { "Gtk/ButtonImages", "gtk-button-images" },
2675 { "Gtk/MenuImages", "gtk-menu-images" },
2676 { "Xft/Antialias", "gtk-xft-antialias" },
2677 { "Xft/Hinting", "gtk-xft-hinting" },
2678 { "Xft/HintStyle", "gtk-xft-hintstyle" },
2679 { "Xft/RGBA", "gtk-xft-rgba" },
2680 { "Xft/DPI", "gtk-xft-dpi" },
2684 gdk_xsettings_notify_cb (const char *name,
2685 XSettingsAction action,
2686 XSettingsSetting *setting,
2690 GdkScreen *screen = data;
2691 GdkScreenX11 *screen_x11 = data;
2694 if (screen_x11->xsettings_in_init)
2697 new_event.type = GDK_SETTING;
2698 new_event.setting.window = gdk_screen_get_root_window (screen);
2699 new_event.setting.send_event = FALSE;
2700 new_event.setting.name = NULL;
2702 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2703 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2705 new_event.setting.name = (char *)settings_map[i].gdk_name;
2709 if (!new_event.setting.name)
2714 case XSETTINGS_ACTION_NEW:
2715 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2717 case XSETTINGS_ACTION_CHANGED:
2718 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2720 case XSETTINGS_ACTION_DELETED:
2721 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2725 gdk_event_put (&new_event);
2729 check_transform (const gchar *xsettings_name,
2733 if (!g_value_type_transformable (src_type, dest_type))
2735 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2737 g_type_name (src_type),
2738 g_type_name (dest_type));
2746 * gdk_screen_get_setting:
2747 * @screen: the #GdkScreen where the setting is located
2748 * @name: the name of the setting
2749 * @value: location to store the value of the setting
2751 * Retrieves a desktop-wide setting such as double-click time
2752 * for the #GdkScreen @screen.
2754 * FIXME needs a list of valid settings here, or a link to
2757 * Returns: %TRUE if the setting existed and a value was stored
2758 * in @value, %FALSE otherwise.
2763 gdk_screen_get_setting (GdkScreen *screen,
2768 const char *xsettings_name = NULL;
2769 XSettingsResult result;
2770 XSettingsSetting *setting;
2771 GdkScreenX11 *screen_x11;
2772 gboolean success = FALSE;
2774 GValue tmp_val = { 0, };
2776 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2778 screen_x11 = GDK_SCREEN_X11 (screen);
2780 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2781 if (strcmp (settings_map[i].gdk_name, name) == 0)
2783 xsettings_name = settings_map[i].xsettings_name;
2787 if (!xsettings_name)
2790 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2791 xsettings_name, &setting);
2792 if (result != XSETTINGS_SUCCESS)
2795 switch (setting->type)
2797 case XSETTINGS_TYPE_INT:
2798 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2800 g_value_init (&tmp_val, G_TYPE_INT);
2801 g_value_set_int (&tmp_val, setting->data.v_int);
2802 g_value_transform (&tmp_val, value);
2807 case XSETTINGS_TYPE_STRING:
2808 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2810 g_value_init (&tmp_val, G_TYPE_STRING);
2811 g_value_set_string (&tmp_val, setting->data.v_string);
2812 g_value_transform (&tmp_val, value);
2817 case XSETTINGS_TYPE_COLOR:
2818 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2822 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2825 color.red = setting->data.v_color.red;
2826 color.green = setting->data.v_color.green;
2827 color.blue = setting->data.v_color.blue;
2829 g_value_set_boxed (&tmp_val, &color);
2831 g_value_transform (&tmp_val, value);
2838 g_value_unset (&tmp_val);
2840 xsettings_setting_free (setting);
2845 static GdkFilterReturn
2846 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2850 GdkScreenX11 *screen = data;
2852 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
2853 return GDK_FILTER_REMOVE;
2855 return GDK_FILTER_CONTINUE;
2859 gdk_xsettings_watch_cb (Window window,
2865 GdkScreen *screen = cb_data;
2867 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
2872 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
2874 g_object_ref (gdkwin);
2876 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2881 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
2882 g_object_unref (gdkwin);