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 if (screen_x11->xsettings_client)
198 xsettings_client_destroy (screen_x11->xsettings_client);
199 screen_x11->xsettings_client = NULL;
204 _gdk_events_init (GdkDisplay *display)
207 GdkDisplaySource *display_source;
208 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
210 int connection_number = ConnectionNumber (display_x11->xdisplay);
211 GDK_NOTE (MISC, g_message ("connection number: %d", connection_number));
214 source = display_x11->event_source = gdk_display_source_new (display);
215 display_source = (GdkDisplaySource*) source;
216 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
218 display_source->event_poll_fd.fd = connection_number;
219 display_source->event_poll_fd.events = G_IO_IN;
221 g_source_add_poll (source, &display_source->event_poll_fd);
222 g_source_set_can_recurse (source, TRUE);
223 g_source_attach (source, NULL);
225 display_sources = g_list_prepend (display_sources,display_source);
227 gdk_display_add_client_message_filter (display,
228 gdk_atom_intern_static_string ("WM_PROTOCOLS"),
229 gdk_wm_protocols_filter,
234 _gdk_events_uninit (GdkDisplay *display)
236 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
238 if (display_x11->event_source)
240 display_sources = g_list_remove (display_sources,
241 display_x11->event_source);
242 g_source_destroy (display_x11->event_source);
243 g_source_unref (display_x11->event_source);
244 display_x11->event_source = NULL;
249 * gdk_events_pending:
251 * Checks if any events are ready to be processed for any display.
253 * Return value: %TRUE if any events are pending.
256 gdk_events_pending (void)
260 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
262 GdkDisplaySource *tmp_source = tmp_list->data;
263 GdkDisplay *display = tmp_source->display;
265 if (_gdk_event_queue_find_first (display))
269 for (tmp_list = display_sources; tmp_list; tmp_list = tmp_list->next)
271 GdkDisplaySource *tmp_source = tmp_list->data;
272 GdkDisplay *display = tmp_source->display;
274 if (gdk_check_xpending (display))
282 graphics_expose_predicate (Display *display,
286 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
287 (xevent->xany.type == GraphicsExpose ||
288 xevent->xany.type == NoExpose))
295 * gdk_event_get_graphics_expose:
296 * @window: the #GdkWindow to wait for the events for.
298 * Waits for a GraphicsExpose or NoExpose event from the X server.
299 * This is used in the #GtkText and #GtkCList widgets in GTK+ to make sure any
300 * GraphicsExpose events are handled before the widget is scrolled.
302 * Return value: a #GdkEventExpose if a GraphicsExpose was received, or %NULL if a
303 * NoExpose event was received.
306 gdk_event_get_graphics_expose (GdkWindow *window)
311 g_return_val_if_fail (window != NULL, NULL);
313 XIfEvent (GDK_WINDOW_XDISPLAY (window), &xevent,
314 graphics_expose_predicate, (XPointer) window);
316 if (xevent.xany.type == GraphicsExpose)
318 event = gdk_event_new (GDK_NOTHING);
320 if (gdk_event_translate (GDK_WINDOW_DISPLAY (window), event,
324 gdk_event_free (event);
331 gdk_event_apply_filters (XEvent *xevent,
336 GdkFilterReturn result;
342 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
344 tmp_list = tmp_list->next;
345 result = filter->function (xevent, event, filter->data);
346 if (result != GDK_FILTER_CONTINUE)
350 return GDK_FILTER_CONTINUE;
354 * gdk_display_add_client_message_filter:
355 * @display: a #GdkDisplay for which this message filter applies
356 * @message_type: the type of ClientMessage events to receive.
357 * This will be checked against the @message_type field
358 * of the XClientMessage event struct.
359 * @func: the function to call to process the event.
360 * @data: user data to pass to @func.
362 * Adds a filter to be called when X ClientMessage events are received.
367 gdk_display_add_client_message_filter (GdkDisplay *display,
368 GdkAtom message_type,
372 GdkClientFilter *filter;
373 g_return_if_fail (GDK_IS_DISPLAY (display));
374 filter = g_new (GdkClientFilter, 1);
376 filter->type = message_type;
377 filter->function = func;
380 GDK_DISPLAY_X11(display)->client_filters =
381 g_list_append (GDK_DISPLAY_X11 (display)->client_filters,
386 * gdk_add_client_message_filter:
387 * @message_type: the type of ClientMessage events to receive. This will be
388 * checked against the <structfield>message_type</structfield> field of the
389 * XClientMessage event struct.
390 * @func: the function to call to process the event.
391 * @data: user data to pass to @func.
393 * Adds a filter to the default display to be called when X ClientMessage events
394 * are received. See gdk_display_add_client_message_filter().
397 gdk_add_client_message_filter (GdkAtom message_type,
401 gdk_display_add_client_message_filter (gdk_display_get_default (),
402 message_type, func, data);
406 do_net_wm_state_changes (GdkWindow *window)
408 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
409 GdkWindowState old_state;
411 if (GDK_WINDOW_DESTROYED (window) ||
412 gdk_window_get_window_type (window) != GDK_WINDOW_TOPLEVEL)
415 old_state = gdk_window_get_state (window);
417 /* For found_sticky to remain TRUE, we have to also be on desktop
420 if (old_state & GDK_WINDOW_STATE_STICKY)
422 if (!(toplevel->have_sticky && toplevel->on_all_desktops))
423 gdk_synthesize_window_state (window,
424 GDK_WINDOW_STATE_STICKY,
429 if (toplevel->have_sticky || toplevel->on_all_desktops)
430 gdk_synthesize_window_state (window,
432 GDK_WINDOW_STATE_STICKY);
435 if (old_state & GDK_WINDOW_STATE_FULLSCREEN)
437 if (!toplevel->have_fullscreen)
438 gdk_synthesize_window_state (window,
439 GDK_WINDOW_STATE_FULLSCREEN,
444 if (toplevel->have_fullscreen)
445 gdk_synthesize_window_state (window,
447 GDK_WINDOW_STATE_FULLSCREEN);
450 /* Our "maximized" means both vertical and horizontal; if only one,
451 * we don't expose that via GDK
453 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
455 if (!(toplevel->have_maxvert && toplevel->have_maxhorz))
456 gdk_synthesize_window_state (window,
457 GDK_WINDOW_STATE_MAXIMIZED,
462 if (toplevel->have_maxvert && toplevel->have_maxhorz)
463 gdk_synthesize_window_state (window,
465 GDK_WINDOW_STATE_MAXIMIZED);
470 gdk_check_wm_desktop_changed (GdkWindow *window)
472 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
473 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
483 gdk_error_trap_push ();
484 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display),
485 GDK_WINDOW_XID (window),
486 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"),
487 0, G_MAXLONG, False, XA_CARDINAL, &type,
489 &bytes_after, &data);
490 gdk_error_trap_pop ();
494 desktop = (gulong *)data;
495 toplevel->on_all_desktops = (*desktop == 0xFFFFFFFF);
499 toplevel->on_all_desktops = FALSE;
501 do_net_wm_state_changes (window);
505 gdk_check_wm_state_changed (GdkWindow *window)
507 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (window);
508 GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
518 gboolean had_sticky = toplevel->have_sticky;
520 toplevel->have_sticky = FALSE;
521 toplevel->have_maxvert = FALSE;
522 toplevel->have_maxhorz = FALSE;
523 toplevel->have_fullscreen = FALSE;
526 gdk_error_trap_push ();
527 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XID (window),
528 gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"),
529 0, G_MAXLONG, False, XA_ATOM, &type, &format, &nitems,
530 &bytes_after, &data);
531 gdk_error_trap_pop ();
535 Atom sticky_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_STICKY");
536 Atom maxvert_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_VERT");
537 Atom maxhorz_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_MAXIMIZED_HORZ");
538 Atom fullscreen_atom = gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE_FULLSCREEN");
540 atoms = (Atom *)data;
545 if (atoms[i] == sticky_atom)
546 toplevel->have_sticky = TRUE;
547 else if (atoms[i] == maxvert_atom)
548 toplevel->have_maxvert = TRUE;
549 else if (atoms[i] == maxhorz_atom)
550 toplevel->have_maxhorz = TRUE;
551 else if (atoms[i] == fullscreen_atom)
552 toplevel->have_fullscreen = TRUE;
560 /* When have_sticky is turned on, we have to check the DESKTOP property
563 if (toplevel->have_sticky && !had_sticky)
564 gdk_check_wm_desktop_changed (window);
566 do_net_wm_state_changes (window);
569 #define HAS_FOCUS(toplevel) \
570 ((toplevel)->has_focus || (toplevel)->has_pointer_focus)
573 generate_focus_event (GdkWindow *window,
578 event.type = GDK_FOCUS_CHANGE;
579 event.focus_change.window = window;
580 event.focus_change.send_event = FALSE;
581 event.focus_change.in = in;
583 gdk_event_put (&event);
587 set_screen_from_root (GdkDisplay *display,
593 screen = _gdk_x11_display_screen_for_xrootwin (display, xrootwin);
597 gdk_event_set_screen (event, screen);
606 translate_key_event (GdkDisplay *display,
610 GdkKeymap *keymap = gdk_keymap_get_for_display (display);
614 event->key.type = xevent->xany.type == KeyPress ? GDK_KEY_PRESS : GDK_KEY_RELEASE;
615 event->key.time = xevent->xkey.time;
617 event->key.state = (GdkModifierType) xevent->xkey.state;
618 event->key.group = _gdk_x11_get_group_for_state (display, xevent->xkey.state);
619 event->key.hardware_keycode = xevent->xkey.keycode;
621 event->key.keyval = GDK_VoidSymbol;
623 gdk_keymap_translate_keyboard_state (keymap,
624 event->key.hardware_keycode,
630 _gdk_keymap_add_virtual_modifiers (keymap, &event->key.state);
631 event->key.is_modifier = _gdk_keymap_key_is_modifier (keymap, event->key.hardware_keycode);
633 /* Fill in event->string crudely, since various programs
636 event->key.string = NULL;
638 if (event->key.keyval != GDK_VoidSymbol)
639 c = gdk_keyval_to_unicode (event->key.keyval);
646 /* Apply the control key - Taken from Xlib
648 if (event->key.state & GDK_CONTROL_MASK)
650 if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F;
653 event->key.string = g_memdup ("\0\0", 2);
654 event->key.length = 1;
658 else if (c >= '3' && c <= '7') c -= ('3' - '\033');
659 else if (c == '8') c = '\177';
660 else if (c == '/') c = '_' & 0x1F;
663 len = g_unichar_to_utf8 (c, buf);
666 event->key.string = g_locale_from_utf8 (buf, len,
667 NULL, &bytes_written,
669 if (event->key.string)
670 event->key.length = bytes_written;
672 else if (event->key.keyval == GDK_Escape)
674 event->key.length = 1;
675 event->key.string = g_strdup ("\033");
677 else if (event->key.keyval == GDK_Return ||
678 event->key.keyval == GDK_KP_Enter)
680 event->key.length = 1;
681 event->key.string = g_strdup ("\r");
684 if (!event->key.string)
686 event->key.length = 0;
687 event->key.string = g_strdup ("");
691 #ifdef G_ENABLE_DEBUG
692 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
694 g_message ("%s:\t\twindow: %ld key: %12s %d",
695 event->type == GDK_KEY_PRESS ? "key press " : "key release",
697 event->key.keyval ? gdk_keyval_name (event->key.keyval) : "(none)",
700 if (event->key.length > 0)
701 g_message ("\t\tlength: %4d string: \"%s\"",
702 event->key.length, buf);
704 #endif /* G_ENABLE_DEBUG */
709 * gdk_x11_register_standard_event_type:
710 * @display: a #GdkDisplay
711 * @event_base: first event type code to register
712 * @n_events: number of event type codes to register
714 * Registers interest in receiving extension events with type codes
715 * between @event_base and <literal>event_base + n_events - 1</literal>.
716 * The registered events must have the window field in the same place
717 * as core X events (this is not the case for e.g. XKB extension events).
719 * If an event type is registered, events of this type will go through
720 * global and window-specific filters (see gdk_window_add_filter()).
721 * Unregistered events will only go through global filters.
722 * GDK may register the events of some X extensions on its own.
724 * This function should only be needed in unusual circumstances, e.g.
725 * when filtering XInput extension events on the root window.
730 gdk_x11_register_standard_event_type (GdkDisplay *display,
734 GdkEventTypeX11 *event_type;
735 GdkDisplayX11 *display_x11;
737 display_x11 = GDK_DISPLAY_X11 (display);
738 event_type = g_new (GdkEventTypeX11, 1);
740 event_type->base = event_base;
741 event_type->n_events = n_events;
743 display_x11->event_types = g_slist_prepend (display_x11->event_types, event_type);
746 /* Return the window this has to do with, if any, rather
747 * than the frame or root window that was selecting
751 get_real_window (GdkDisplay *display,
753 Window *event_window,
754 Window *filter_window)
756 /* Core events all have an event->xany.window field, but that's
757 * not true for extension events
759 if (event->type >= KeyPress &&
760 event->type <= MappingNotify)
762 *filter_window = event->xany.window;
766 *event_window = event->xcreatewindow.window;
769 *event_window = event->xdestroywindow.window;
772 *event_window = event->xunmap.window;
775 *event_window = event->xmap.window;
778 *event_window = event->xmaprequest.window;
781 *event_window = event->xreparent.window;
783 case ConfigureNotify:
784 *event_window = event->xconfigure.window;
786 case ConfigureRequest:
787 *event_window = event->xconfigurerequest.window;
790 *event_window = event->xgravity.window;
792 case CirculateNotify:
793 *event_window = event->xcirculate.window;
795 case CirculateRequest:
796 *event_window = event->xcirculaterequest.window;
799 *event_window = event->xany.window;
804 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
807 for (tmp_list = display_x11->event_types;
809 tmp_list = tmp_list->next)
811 GdkEventTypeX11 *event_type = tmp_list->data;
813 if (event->type >= event_type->base &&
814 event->type < event_type->base + event_type->n_events)
816 *event_window = event->xany.window;
817 *filter_window = event->xany.window;
822 *event_window = None;
823 *filter_window = None;
827 #ifdef G_ENABLE_DEBUG
828 static const char notify_modes[][19] = {
835 static const char notify_details[][23] = {
840 "NotifyNonlinearVirtual",
848 set_user_time (GdkWindow *window,
851 g_return_if_fail (event != NULL);
853 window = gdk_window_get_toplevel (event->client.window);
854 g_return_if_fail (GDK_IS_WINDOW (window));
856 /* If an event doesn't have a valid timestamp, we shouldn't use it
857 * to update the latest user interaction time.
859 if (gdk_event_get_time (event) != GDK_CURRENT_TIME)
860 gdk_x11_window_set_user_time (gdk_window_get_toplevel (window),
861 gdk_event_get_time (event));
865 gdk_event_translate (GdkDisplay *display,
868 gboolean return_exposes)
872 GdkWindowObject *window_private;
873 GdkWindow *filter_window;
874 GdkWindowImplX11 *window_impl = NULL;
876 gint xoffset, yoffset;
877 GdkScreen *screen = NULL;
878 GdkScreenX11 *screen_x11 = NULL;
879 GdkToplevelX11 *toplevel = NULL;
880 GdkDisplayX11 *display_x11 = GDK_DISPLAY_X11 (display);
881 Window xwindow, filter_xwindow;
885 /* init these, since the done: block uses them */
887 window_private = NULL;
888 event->any.window = NULL;
890 if (_gdk_default_filters)
892 /* Apply global filters */
893 GdkFilterReturn result;
894 result = gdk_event_apply_filters (xevent, event,
895 _gdk_default_filters);
897 if (result != GDK_FILTER_CONTINUE)
899 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
904 /* Find the GdkWindow that this event relates to.
905 * Basically this means substructure events
906 * are reported same as structure events
908 get_real_window (display, xevent, &xwindow, &filter_xwindow);
910 window = gdk_window_lookup_for_display (display, xwindow);
911 /* We may receive events such as NoExpose/GraphicsExpose
912 * and ShmCompletion for pixmaps
914 if (window && !GDK_IS_WINDOW (window))
916 window_private = (GdkWindowObject *) window;
918 /* We always run the filters for the window where the event
919 * is delivered, not the window that it relates to
921 if (filter_xwindow == xwindow)
922 filter_window = window;
925 filter_window = gdk_window_lookup_for_display (display, filter_xwindow);
926 if (filter_window && !GDK_IS_WINDOW (filter_window))
927 filter_window = NULL;
932 screen = GDK_WINDOW_SCREEN (window);
933 screen_x11 = GDK_SCREEN_X11 (screen);
934 toplevel = _gdk_x11_window_get_toplevel (window);
939 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
941 /* Move key events on focus window to the real toplevel, and
942 * filter out all other events on focus window
944 if (toplevel && xwindow == toplevel->focus_window)
946 switch (xevent->type)
950 xwindow = GDK_WINDOW_XID (window);
951 xevent->xany.window = xwindow;
958 g_object_ref (window);
961 event->any.window = window;
962 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
964 if (window_private && GDK_WINDOW_DESTROYED (window))
966 if (xevent->type != DestroyNotify)
972 else if (filter_window)
974 /* Apply per-window filters */
975 GdkWindowObject *filter_private = (GdkWindowObject *) filter_window;
976 GdkFilterReturn result;
978 if (filter_private->filters)
980 g_object_ref (filter_window);
982 result = gdk_event_apply_filters (xevent, event,
983 filter_private->filters);
985 g_object_unref (filter_window);
987 if (result != GDK_FILTER_CONTINUE)
989 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
995 if (screen_x11 && screen_x11->wmspec_check_window != None &&
996 xwindow == screen_x11->wmspec_check_window)
998 if (xevent->type == DestroyNotify)
1000 screen_x11->wmspec_check_window = None;
1001 g_free (screen_x11->window_manager_name);
1002 screen_x11->window_manager_name = g_strdup ("unknown");
1004 /* careful, reentrancy */
1005 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
1008 /* Eat events on this window unless someone had wrapped
1009 * it as a foreign window
1019 (xevent->xany.type == MotionNotify ||
1020 xevent->xany.type == ButtonRelease))
1022 if (_gdk_moveresize_handle_event (xevent))
1029 /* We do a "manual" conversion of the XEvent to a
1030 * GdkEvent. The structures are mostly the same so
1031 * the conversion is fairly straightforward. We also
1032 * optionally print debugging info regarding events
1040 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
1048 switch (xevent->type)
1051 if (window_private == NULL)
1056 translate_key_event (display, event, xevent);
1057 set_user_time (window, event);
1061 if (window_private == NULL)
1067 /* Emulate detectable auto-repeat by checking to see
1068 * if the next event is a key press with the same
1069 * keycode and timestamp, and if so, ignoring the event.
1072 if (!display_x11->have_xkb_autorepeat && XPending (xevent->xkey.display))
1076 XPeekEvent (xevent->xkey.display, &next_event);
1078 if (next_event.type == KeyPress &&
1079 next_event.xkey.keycode == xevent->xkey.keycode &&
1080 next_event.xkey.time == xevent->xkey.time)
1087 translate_key_event (display, event, xevent);
1092 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1093 xevent->xbutton.window,
1094 xevent->xbutton.x, xevent->xbutton.y,
1095 xevent->xbutton.button));
1097 if (window_private == NULL ||
1098 ((window_private->extension_events != 0) &&
1099 display_x11->input_ignore_core))
1105 /* If we get a ButtonPress event where the button is 4 or 5,
1106 it's a Scroll event */
1107 switch (xevent->xbutton.button)
1113 event->scroll.type = GDK_SCROLL;
1115 if (xevent->xbutton.button == 4)
1116 event->scroll.direction = GDK_SCROLL_UP;
1117 else if (xevent->xbutton.button == 5)
1118 event->scroll.direction = GDK_SCROLL_DOWN;
1119 else if (xevent->xbutton.button == 6)
1120 event->scroll.direction = GDK_SCROLL_LEFT;
1122 event->scroll.direction = GDK_SCROLL_RIGHT;
1124 event->scroll.window = window;
1125 event->scroll.time = xevent->xbutton.time;
1126 event->scroll.x = xevent->xbutton.x + xoffset;
1127 event->scroll.y = xevent->xbutton.y + yoffset;
1128 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
1129 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
1130 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
1131 event->scroll.device = display->core_pointer;
1133 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1142 event->button.type = GDK_BUTTON_PRESS;
1143 event->button.window = window;
1144 event->button.time = xevent->xbutton.time;
1145 event->button.x = xevent->xbutton.x + xoffset;
1146 event->button.y = xevent->xbutton.y + yoffset;
1147 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1148 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1149 event->button.axes = NULL;
1150 event->button.state = (GdkModifierType) xevent->xbutton.state;
1151 event->button.button = xevent->xbutton.button;
1152 event->button.device = display->core_pointer;
1154 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1160 _gdk_event_button_generate (display, event);
1164 set_user_time (window, event);
1166 _gdk_xgrab_check_button_event (window, xevent);
1171 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1172 xevent->xbutton.window,
1173 xevent->xbutton.x, xevent->xbutton.y,
1174 xevent->xbutton.button));
1176 if (window_private == NULL ||
1177 ((window_private->extension_events != 0) &&
1178 display_x11->input_ignore_core))
1184 /* We treat button presses as scroll wheel events, so ignore the release */
1185 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
1186 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
1192 event->button.type = GDK_BUTTON_RELEASE;
1193 event->button.window = window;
1194 event->button.time = xevent->xbutton.time;
1195 event->button.x = xevent->xbutton.x + xoffset;
1196 event->button.y = xevent->xbutton.y + yoffset;
1197 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1198 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1199 event->button.axes = NULL;
1200 event->button.state = (GdkModifierType) xevent->xbutton.state;
1201 event->button.button = xevent->xbutton.button;
1202 event->button.device = display->core_pointer;
1204 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1210 _gdk_xgrab_check_button_event (window, xevent);
1215 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1216 xevent->xmotion.window,
1217 xevent->xmotion.x, xevent->xmotion.y,
1218 (xevent->xmotion.is_hint) ? "true" : "false"));
1220 if (window_private == NULL ||
1221 ((window_private->extension_events != 0) &&
1222 display_x11->input_ignore_core))
1228 event->motion.type = GDK_MOTION_NOTIFY;
1229 event->motion.window = window;
1230 event->motion.time = xevent->xmotion.time;
1231 event->motion.x = xevent->xmotion.x + xoffset;
1232 event->motion.y = xevent->xmotion.y + yoffset;
1233 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1234 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1235 event->motion.axes = NULL;
1236 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1237 event->motion.is_hint = xevent->xmotion.is_hint;
1238 event->motion.device = display->core_pointer;
1240 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1250 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1251 xevent->xcrossing.window,
1252 xevent->xcrossing.detail,
1253 xevent->xcrossing.subwindow));
1255 if (window_private == NULL)
1261 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1267 /* Handle focusing (in the case where no window manager is running */
1268 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1270 toplevel->has_pointer = TRUE;
1272 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1274 gboolean had_focus = HAS_FOCUS (toplevel);
1276 toplevel->has_pointer_focus = TRUE;
1278 if (HAS_FOCUS (toplevel) != had_focus)
1279 generate_focus_event (window, TRUE);
1283 /* Tell XInput stuff about it if appropriate */
1284 if (window_private &&
1285 !GDK_WINDOW_DESTROYED (window) &&
1286 window_private->extension_events != 0)
1287 _gdk_input_enter_event (&xevent->xcrossing, window);
1289 event->crossing.type = GDK_ENTER_NOTIFY;
1290 event->crossing.window = window;
1292 /* If the subwindow field of the XEvent is non-NULL, then
1293 * lookup the corresponding GdkWindow.
1295 if (xevent->xcrossing.subwindow != None)
1296 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1298 event->crossing.subwindow = NULL;
1300 event->crossing.time = xevent->xcrossing.time;
1301 event->crossing.x = xevent->xcrossing.x + xoffset;
1302 event->crossing.y = xevent->xcrossing.y + yoffset;
1303 event->crossing.x_root = xevent->xcrossing.x_root;
1304 event->crossing.y_root = xevent->xcrossing.y_root;
1306 /* Translate the crossing mode into Gdk terms.
1308 switch (xevent->xcrossing.mode)
1311 event->crossing.mode = GDK_CROSSING_NORMAL;
1314 event->crossing.mode = GDK_CROSSING_GRAB;
1317 event->crossing.mode = GDK_CROSSING_UNGRAB;
1321 /* Translate the crossing detail into Gdk terms.
1323 switch (xevent->xcrossing.detail)
1325 case NotifyInferior:
1326 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1328 case NotifyAncestor:
1329 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1332 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1334 case NotifyNonlinear:
1335 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1337 case NotifyNonlinearVirtual:
1338 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1341 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1345 event->crossing.focus = xevent->xcrossing.focus;
1346 event->crossing.state = xevent->xcrossing.state;
1352 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1353 xevent->xcrossing.window,
1354 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1356 if (window_private == NULL)
1362 if (!set_screen_from_root (display, event, xevent->xbutton.root))
1368 /* Handle focusing (in the case where no window manager is running */
1369 if (toplevel && xevent->xcrossing.detail != NotifyInferior)
1371 toplevel->has_pointer = FALSE;
1373 if (xevent->xcrossing.focus && !toplevel->has_focus_window)
1375 gboolean had_focus = HAS_FOCUS (toplevel);
1377 toplevel->has_pointer_focus = FALSE;
1379 if (HAS_FOCUS (toplevel) != had_focus)
1380 generate_focus_event (window, FALSE);
1384 event->crossing.type = GDK_LEAVE_NOTIFY;
1385 event->crossing.window = window;
1387 /* If the subwindow field of the XEvent is non-NULL, then
1388 * lookup the corresponding GdkWindow.
1390 if (xevent->xcrossing.subwindow != None)
1391 event->crossing.subwindow = gdk_window_lookup_for_display (display, xevent->xcrossing.subwindow);
1393 event->crossing.subwindow = NULL;
1395 event->crossing.time = xevent->xcrossing.time;
1396 event->crossing.x = xevent->xcrossing.x + xoffset;
1397 event->crossing.y = xevent->xcrossing.y + yoffset;
1398 event->crossing.x_root = xevent->xcrossing.x_root;
1399 event->crossing.y_root = xevent->xcrossing.y_root;
1401 /* Translate the crossing mode into Gdk terms.
1403 switch (xevent->xcrossing.mode)
1406 event->crossing.mode = GDK_CROSSING_NORMAL;
1409 event->crossing.mode = GDK_CROSSING_GRAB;
1412 event->crossing.mode = GDK_CROSSING_UNGRAB;
1416 /* Translate the crossing detail into Gdk terms.
1418 switch (xevent->xcrossing.detail)
1420 case NotifyInferior:
1421 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1423 case NotifyAncestor:
1424 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1427 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1429 case NotifyNonlinear:
1430 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1432 case NotifyNonlinearVirtual:
1433 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1436 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1440 event->crossing.focus = xevent->xcrossing.focus;
1441 event->crossing.state = xevent->xcrossing.state;
1445 /* We only care about focus events that indicate that _this_
1446 * window (not a ancestor or child) got or lost the focus
1450 g_message ("focus in:\t\twindow: %ld, detail: %s, mode: %s",
1451 xevent->xfocus.window,
1452 notify_details[xevent->xfocus.detail],
1453 notify_modes[xevent->xfocus.mode]));
1457 gboolean had_focus = HAS_FOCUS (toplevel);
1459 switch (xevent->xfocus.detail)
1461 case NotifyAncestor:
1463 /* When the focus moves from an ancestor of the window to
1464 * the window or a descendent of the window, *and* the
1465 * pointer is inside the window, then we were previously
1466 * receiving keystroke events in the has_pointer_focus
1467 * case and are now receiving them in the
1468 * has_focus_window case.
1470 if (toplevel->has_pointer &&
1471 xevent->xfocus.mode != NotifyGrab &&
1472 xevent->xfocus.mode != NotifyUngrab)
1473 toplevel->has_pointer_focus = FALSE;
1476 case NotifyNonlinear:
1477 case NotifyNonlinearVirtual:
1478 if (xevent->xfocus.mode != NotifyGrab &&
1479 xevent->xfocus.mode != NotifyUngrab)
1480 toplevel->has_focus_window = TRUE;
1481 /* We pretend that the focus moves to the grab
1482 * window, so we pay attention to NotifyGrab
1483 * NotifyUngrab, and ignore NotifyWhileGrabbed
1485 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1486 toplevel->has_focus = TRUE;
1489 /* The X server sends NotifyPointer/NotifyGrab,
1490 * but the pointer focus is ignored while a
1493 if (xevent->xfocus.mode != NotifyGrab &&
1494 xevent->xfocus.mode != NotifyUngrab)
1495 toplevel->has_pointer_focus = TRUE;
1497 case NotifyInferior:
1498 case NotifyPointerRoot:
1499 case NotifyDetailNone:
1503 if (HAS_FOCUS (toplevel) != had_focus)
1504 generate_focus_event (window, TRUE);
1509 g_message ("focus out:\t\twindow: %ld, detail: %s, mode: %s",
1510 xevent->xfocus.window,
1511 notify_details[xevent->xfocus.detail],
1512 notify_modes[xevent->xfocus.mode]));
1516 gboolean had_focus = HAS_FOCUS (toplevel);
1518 switch (xevent->xfocus.detail)
1520 case NotifyAncestor:
1522 /* When the focus moves from the window or a descendent
1523 * of the window to an ancestor of the window, *and* the
1524 * pointer is inside the window, then we were previously
1525 * receiving keystroke events in the has_focus_window
1526 * case and are now receiving them in the
1527 * has_pointer_focus case.
1529 if (toplevel->has_pointer &&
1530 xevent->xfocus.mode != NotifyGrab &&
1531 xevent->xfocus.mode != NotifyUngrab)
1532 toplevel->has_pointer_focus = TRUE;
1535 case NotifyNonlinear:
1536 case NotifyNonlinearVirtual:
1537 if (xevent->xfocus.mode != NotifyGrab &&
1538 xevent->xfocus.mode != NotifyUngrab)
1539 toplevel->has_focus_window = FALSE;
1540 if (xevent->xfocus.mode != NotifyWhileGrabbed)
1541 toplevel->has_focus = FALSE;
1544 if (xevent->xfocus.mode != NotifyGrab &&
1545 xevent->xfocus.mode != NotifyUngrab)
1546 toplevel->has_pointer_focus = FALSE;
1548 case NotifyInferior:
1549 case NotifyPointerRoot:
1550 case NotifyDetailNone:
1554 if (HAS_FOCUS (toplevel) != had_focus)
1555 generate_focus_event (window, FALSE);
1560 /* gdk_keyboard_grab() causes following events. These events confuse
1561 * the XIM focus, so ignore them.
1563 if (xevent->xfocus.mode == NotifyGrab ||
1564 xevent->xfocus.mode == NotifyUngrab)
1570 g_message ("keymap notify"));
1572 /* Not currently handled */
1578 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1579 xevent->xexpose.window, xevent->xexpose.count,
1580 xevent->xexpose.x, xevent->xexpose.y,
1581 xevent->xexpose.width, xevent->xexpose.height,
1582 event->any.send_event ? " (send)" : ""));
1584 if (window_private == NULL)
1591 GdkRectangle expose_rect;
1593 expose_rect.x = xevent->xexpose.x + xoffset;
1594 expose_rect.y = xevent->xexpose.y + yoffset;
1595 expose_rect.width = xevent->xexpose.width;
1596 expose_rect.height = xevent->xexpose.height;
1600 event->expose.type = GDK_EXPOSE;
1601 event->expose.area = expose_rect;
1602 event->expose.region = gdk_region_rectangle (&expose_rect);
1603 event->expose.window = window;
1604 event->expose.count = xevent->xexpose.count;
1610 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1619 case GraphicsExpose:
1621 GdkRectangle expose_rect;
1624 g_message ("graphics expose:\tdrawable: %ld",
1625 xevent->xgraphicsexpose.drawable));
1627 if (window_private == NULL)
1633 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1634 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1635 expose_rect.width = xevent->xgraphicsexpose.width;
1636 expose_rect.height = xevent->xgraphicsexpose.height;
1640 event->expose.type = GDK_EXPOSE;
1641 event->expose.area = expose_rect;
1642 event->expose.region = gdk_region_rectangle (&expose_rect);
1643 event->expose.window = window;
1644 event->expose.count = xevent->xgraphicsexpose.count;
1650 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1660 g_message ("no expose:\t\tdrawable: %ld",
1661 xevent->xnoexpose.drawable));
1663 event->no_expose.type = GDK_NO_EXPOSE;
1664 event->no_expose.window = window;
1668 case VisibilityNotify:
1669 #ifdef G_ENABLE_DEBUG
1670 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1671 switch (xevent->xvisibility.state)
1673 case VisibilityFullyObscured:
1674 g_message ("visibility notify:\twindow: %ld none",
1675 xevent->xvisibility.window);
1677 case VisibilityPartiallyObscured:
1678 g_message ("visibility notify:\twindow: %ld partial",
1679 xevent->xvisibility.window);
1681 case VisibilityUnobscured:
1682 g_message ("visibility notify:\twindow: %ld full",
1683 xevent->xvisibility.window);
1686 #endif /* G_ENABLE_DEBUG */
1688 if (window_private == NULL)
1694 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1695 event->visibility.window = window;
1697 switch (xevent->xvisibility.state)
1699 case VisibilityFullyObscured:
1700 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1703 case VisibilityPartiallyObscured:
1704 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1707 case VisibilityUnobscured:
1708 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1716 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1717 xevent->xcreatewindow.window,
1718 xevent->xcreatewindow.x,
1719 xevent->xcreatewindow.y,
1720 xevent->xcreatewindow.width,
1721 xevent->xcreatewindow.height,
1722 xevent->xcreatewindow.border_width,
1723 xevent->xcreatewindow.parent,
1724 xevent->xcreatewindow.override_redirect));
1725 /* not really handled */
1730 g_message ("destroy notify:\twindow: %ld",
1731 xevent->xdestroywindow.window));
1733 /* Ignore DestroyNotify from SubstructureNotifyMask */
1734 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1736 event->any.type = GDK_DESTROY;
1737 event->any.window = window;
1739 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1741 if (window && GDK_WINDOW_XID (window) != screen_x11->xroot_window)
1742 gdk_window_destroy_notify (window);
1751 g_message ("unmap notify:\t\twindow: %ld",
1752 xevent->xmap.window));
1754 event->any.type = GDK_UNMAP;
1755 event->any.window = window;
1757 /* If we are shown (not withdrawn) and get an unmap, it means we
1758 * were iconified in the X sense. If we are withdrawn, and get
1759 * an unmap, it means we hid the window ourselves, so we
1760 * will have already flipped the iconified bit off.
1764 if (GDK_WINDOW_IS_MAPPED (window))
1765 gdk_synthesize_window_state (window,
1767 GDK_WINDOW_STATE_ICONIFIED);
1769 _gdk_xgrab_check_unmap (window, xevent->xany.serial);
1776 g_message ("map notify:\t\twindow: %ld",
1777 xevent->xmap.window));
1779 event->any.type = GDK_MAP;
1780 event->any.window = window;
1782 /* Unset iconified if it was set */
1783 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1784 gdk_synthesize_window_state (window,
1785 GDK_WINDOW_STATE_ICONIFIED,
1790 case ReparentNotify:
1792 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1793 xevent->xreparent.window,
1794 xevent->xreparent.x,
1795 xevent->xreparent.y,
1796 xevent->xreparent.parent,
1797 xevent->xreparent.override_redirect));
1799 /* Not currently handled */
1803 case ConfigureNotify:
1805 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1806 xevent->xconfigure.window,
1807 xevent->xconfigure.x,
1808 xevent->xconfigure.y,
1809 xevent->xconfigure.width,
1810 xevent->xconfigure.height,
1811 xevent->xconfigure.border_width,
1812 xevent->xconfigure.above,
1813 xevent->xconfigure.override_redirect,
1816 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1817 ? " (discarding child)"
1818 : xevent->xconfigure.event != xevent->xconfigure.window
1819 ? " (discarding substructure)"
1821 if (window && GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1822 _gdk_x11_screen_size_changed (screen, xevent);
1825 xevent->xconfigure.event == xevent->xconfigure.window &&
1826 !GDK_WINDOW_DESTROYED (window) &&
1827 (window_private->extension_events != 0))
1828 _gdk_input_configure_event (&xevent->xconfigure, window);
1831 if (toplevel && display_x11->use_sync && !XSyncValueIsZero (toplevel->pending_counter_value))
1833 toplevel->current_counter_value = toplevel->pending_counter_value;
1834 XSyncIntToValue (&toplevel->pending_counter_value, 0);
1839 xevent->xconfigure.event != xevent->xconfigure.window ||
1840 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1841 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1845 event->configure.type = GDK_CONFIGURE;
1846 event->configure.window = window;
1847 event->configure.width = xevent->xconfigure.width;
1848 event->configure.height = xevent->xconfigure.height;
1850 if (!xevent->xconfigure.send_event &&
1851 !xevent->xconfigure.override_redirect &&
1852 !GDK_WINDOW_DESTROYED (window))
1856 Window child_window = 0;
1858 gdk_error_trap_push ();
1859 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1860 GDK_DRAWABLE_XID (window),
1861 screen_x11->xroot_window,
1866 event->configure.x = tx;
1867 event->configure.y = ty;
1869 gdk_error_trap_pop ();
1873 event->configure.x = xevent->xconfigure.x;
1874 event->configure.y = xevent->xconfigure.y;
1876 window_private->x = event->configure.x;
1877 window_private->y = event->configure.y;
1878 window_impl->width = xevent->xconfigure.width;
1879 window_impl->height = xevent->xconfigure.height;
1881 _gdk_x11_drawable_update_size (window_private->impl);
1883 if (window_private->resize_count >= 1)
1885 window_private->resize_count -= 1;
1887 if (window_private->resize_count == 0)
1888 _gdk_moveresize_configure_done (display, window);
1893 case PropertyNotify:
1895 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1896 xevent->xproperty.window,
1897 xevent->xproperty.atom,
1899 gdk_x11_get_xatom_name_for_display (display, xevent->xproperty.atom),
1902 if (window_private == NULL)
1908 /* We compare with the serial of the last time we mapped the
1909 * window to avoid refetching properties that we set ourselves
1912 xevent->xproperty.serial >= toplevel->map_serial)
1914 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_STATE"))
1915 gdk_check_wm_state_changed (window);
1917 if (xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_DESKTOP"))
1918 gdk_check_wm_desktop_changed (window);
1921 if (window_private->event_mask & GDK_PROPERTY_CHANGE_MASK)
1923 event->property.type = GDK_PROPERTY_NOTIFY;
1924 event->property.window = window;
1925 event->property.atom = gdk_x11_xatom_to_atom_for_display (display, xevent->xproperty.atom);
1926 event->property.time = xevent->xproperty.time;
1927 event->property.state = xevent->xproperty.state;
1934 case SelectionClear:
1936 g_message ("selection clear:\twindow: %ld",
1937 xevent->xproperty.window));
1939 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1941 event->selection.type = GDK_SELECTION_CLEAR;
1942 event->selection.window = window;
1943 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionclear.selection);
1944 event->selection.time = xevent->xselectionclear.time;
1951 case SelectionRequest:
1953 g_message ("selection request:\twindow: %ld",
1954 xevent->xproperty.window));
1956 event->selection.type = GDK_SELECTION_REQUEST;
1957 event->selection.window = window;
1958 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.selection);
1959 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.target);
1960 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselectionrequest.property);
1961 event->selection.requestor = xevent->xselectionrequest.requestor;
1962 event->selection.time = xevent->xselectionrequest.time;
1966 case SelectionNotify:
1968 g_message ("selection notify:\twindow: %ld",
1969 xevent->xproperty.window));
1972 event->selection.type = GDK_SELECTION_NOTIFY;
1973 event->selection.window = window;
1974 event->selection.selection = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.selection);
1975 event->selection.target = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.target);
1976 event->selection.property = gdk_x11_xatom_to_atom_for_display (display, xevent->xselection.property);
1977 event->selection.time = xevent->xselection.time;
1981 case ColormapNotify:
1983 g_message ("colormap notify:\twindow: %ld",
1984 xevent->xcolormap.window));
1986 /* Not currently handled */
1993 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1994 GdkAtom message_type = gdk_x11_xatom_to_atom_for_display (display, xevent->xclient.message_type);
1997 g_message ("client message:\twindow: %ld",
1998 xevent->xclient.window));
2000 tmp_list = display_x11->client_filters;
2003 GdkClientFilter *filter = tmp_list->data;
2004 tmp_list = tmp_list->next;
2006 if (filter->type == message_type)
2008 result = (*filter->function) (xevent, event, filter->data);
2009 if (result != GDK_FILTER_CONTINUE)
2016 case GDK_FILTER_REMOVE:
2019 case GDK_FILTER_TRANSLATE:
2022 case GDK_FILTER_CONTINUE:
2023 /* Send unknown ClientMessage's on to Gtk for it to use */
2024 if (window_private == NULL)
2030 event->client.type = GDK_CLIENT_EVENT;
2031 event->client.window = window;
2032 event->client.message_type = message_type;
2033 event->client.data_format = xevent->xclient.format;
2034 memcpy(&event->client.data, &xevent->xclient.data,
2035 sizeof(event->client.data));
2045 g_message ("mapping notify"));
2047 /* Let XLib know that there is a new keyboard mapping.
2049 XRefreshKeyboardMapping (&xevent->xmapping);
2050 _gdk_keymap_keys_changed (display);
2056 if (xevent->type == display_x11->xkb_event_type)
2058 XkbEvent *xkb_event = (XkbEvent *)xevent;
2060 switch (xkb_event->any.xkb_type)
2062 case XkbNewKeyboardNotify:
2064 _gdk_keymap_keys_changed (display);
2069 case XkbStateNotify:
2070 _gdk_keymap_state_changed (display, xevent);
2077 if (xevent->type - display_x11->xfixes_event_base == XFixesSelectionNotify)
2079 XFixesSelectionNotifyEvent *selection_notify = (XFixesSelectionNotifyEvent *)xevent;
2080 event->owner_change.type = GDK_OWNER_CHANGE;
2081 event->owner_change.window = window;
2082 event->owner_change.owner = selection_notify->owner;
2083 event->owner_change.reason = selection_notify->subtype;
2084 event->owner_change.selection =
2085 gdk_x11_xatom_to_atom_for_display (display,
2086 selection_notify->selection);
2087 event->owner_change.time = selection_notify->timestamp;
2088 event->owner_change.selection_time = selection_notify->selection_timestamp;
2095 /* something else - (e.g., a Xinput event) */
2097 if (window_private &&
2098 !GDK_WINDOW_DESTROYED (window_private) &&
2099 (window_private->extension_events != 0))
2100 return_val = _gdk_input_other_event(event, xevent, window);
2111 if (event->any.window)
2112 g_object_ref (event->any.window);
2113 if (((event->any.type == GDK_ENTER_NOTIFY) ||
2114 (event->any.type == GDK_LEAVE_NOTIFY)) &&
2115 (event->crossing.subwindow != NULL))
2116 g_object_ref (event->crossing.subwindow);
2120 /* Mark this event as having no resources to be freed */
2121 event->any.window = NULL;
2122 event->any.type = GDK_NOTHING;
2126 g_object_unref (window);
2131 static GdkFilterReturn
2132 gdk_wm_protocols_filter (GdkXEvent *xev,
2136 XEvent *xevent = (XEvent *)xev;
2137 GdkWindow *win = event->any.window;
2138 GdkDisplay *display;
2142 return GDK_FILTER_REMOVE;
2144 display = GDK_WINDOW_DISPLAY (win);
2145 atom = (Atom)xevent->xclient.data.l[0];
2147 if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_DELETE_WINDOW"))
2149 /* The delete window request specifies a window
2150 * to delete. We don't actually destroy the
2151 * window because "it is only a request". (The
2152 * window might contain vital data that the
2153 * program does not want destroyed). Instead
2154 * the event is passed along to the program,
2155 * which should then destroy the window.
2158 g_message ("delete window:\t\twindow: %ld",
2159 xevent->xclient.window));
2161 event->any.type = GDK_DELETE;
2163 gdk_x11_window_set_user_time (win, xevent->xclient.data.l[1]);
2165 return GDK_FILTER_TRANSLATE;
2167 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "WM_TAKE_FOCUS"))
2169 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2170 GdkWindowObject *private = (GdkWindowObject *)win;
2172 /* There is no way of knowing reliably whether we are viewable;
2173 * _gdk_x11_set_input_focus_safe() traps errors asynchronously.
2175 if (toplevel && private->accept_focus)
2176 _gdk_x11_set_input_focus_safe (display, toplevel->focus_window,
2178 xevent->xclient.data.l[1]);
2180 return GDK_FILTER_REMOVE;
2182 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_PING") &&
2183 !_gdk_x11_display_is_root_window (display,
2184 xevent->xclient.window))
2186 XEvent xev = *xevent;
2188 xev.xclient.window = GDK_WINDOW_XROOTWIN (win);
2189 XSendEvent (GDK_WINDOW_XDISPLAY (win),
2192 SubstructureRedirectMask | SubstructureNotifyMask, &xev);
2194 return GDK_FILTER_REMOVE;
2196 else if (atom == gdk_x11_get_xatom_by_name_for_display (display, "_NET_WM_SYNC_REQUEST") &&
2197 GDK_DISPLAY_X11 (display)->use_sync)
2199 GdkToplevelX11 *toplevel = _gdk_x11_window_get_toplevel (event->any.window);
2203 XSyncIntsToValue (&toplevel->pending_counter_value,
2204 xevent->xclient.data.l[2],
2205 xevent->xclient.data.l[3]);
2208 return GDK_FILTER_REMOVE;
2211 return GDK_FILTER_CONTINUE;
2215 _gdk_events_queue (GdkDisplay *display)
2220 Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
2222 while (!_gdk_event_queue_find_first(display) && XPending (xdisplay))
2224 XNextEvent (xdisplay, &xevent);
2226 switch (xevent.type)
2232 if (XFilterEvent (&xevent, None))
2236 event = gdk_event_new (GDK_NOTHING);
2238 event->any.window = NULL;
2239 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
2241 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2243 node = _gdk_event_queue_append (display, event);
2245 if (gdk_event_translate (display, event, &xevent, FALSE))
2247 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2251 _gdk_event_queue_remove_link (display, node);
2252 g_list_free_1 (node);
2253 gdk_event_free (event);
2259 gdk_event_prepare (GSource *source,
2262 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2265 GDK_THREADS_ENTER ();
2268 retval = (_gdk_event_queue_find_first (display) != NULL ||
2269 gdk_check_xpending (display));
2271 GDK_THREADS_LEAVE ();
2277 gdk_event_check (GSource *source)
2279 GdkDisplaySource *display_source = (GdkDisplaySource*)source;
2282 GDK_THREADS_ENTER ();
2284 if (display_source->event_poll_fd.revents & G_IO_IN)
2285 retval = (_gdk_event_queue_find_first (display_source->display) != NULL ||
2286 gdk_check_xpending (display_source->display));
2290 GDK_THREADS_LEAVE ();
2296 gdk_event_dispatch (GSource *source,
2297 GSourceFunc callback,
2300 GdkDisplay *display = ((GdkDisplaySource*)source)->display;
2303 GDK_THREADS_ENTER ();
2305 _gdk_events_queue (display);
2306 event = _gdk_event_unqueue (display);
2310 if (_gdk_event_func)
2311 (*_gdk_event_func) (event, _gdk_event_data);
2313 gdk_event_free (event);
2316 GDK_THREADS_LEAVE ();
2322 * gdk_event_send_client_message_for_display:
2323 * @display: the #GdkDisplay for the window where the message is to be sent.
2324 * @event: the #GdkEvent to send, which should be a #GdkEventClient.
2325 * @winid: the window to send the client message to.
2327 * On X11, sends an X ClientMessage event to a given window. On
2328 * Windows, sends a message registered with the name
2329 * GDK_WIN32_CLIENT_MESSAGE.
2331 * This could be used for communicating between different
2332 * applications, though the amount of data is limited to 20 bytes on
2333 * X11, and to just four bytes on Windows.
2335 * Returns: non-zero on success.
2340 gdk_event_send_client_message_for_display (GdkDisplay *display,
2342 GdkNativeWindow winid)
2346 g_return_val_if_fail(event != NULL, FALSE);
2348 /* Set up our event to send, with the exception of its target window */
2349 sev.xclient.type = ClientMessage;
2350 sev.xclient.display = GDK_DISPLAY_XDISPLAY (display);
2351 sev.xclient.format = event->client.data_format;
2352 sev.xclient.window = winid;
2353 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2354 sev.xclient.message_type = gdk_x11_atom_to_xatom_for_display (display, event->client.message_type);
2356 return _gdk_send_xevent (display, winid, False, NoEventMask, &sev);
2361 /* Sends a ClientMessage to all toplevel client windows */
2363 gdk_event_send_client_message_to_all_recurse (GdkDisplay *display,
2370 unsigned long nitems, after;
2371 unsigned char *data;
2372 Window *ret_children, ret_root, ret_parent;
2373 unsigned int ret_nchildren;
2374 gboolean send = FALSE;
2375 gboolean found = FALSE;
2376 gboolean result = FALSE;
2379 gdk_error_trap_push ();
2381 if (XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), xid,
2382 gdk_x11_get_xatom_by_name_for_display (display, "WM_STATE"),
2383 0, 0, False, AnyPropertyType,
2384 &type, &format, &nitems, &after, &data) != Success)
2394 /* OK, we're all set, now let's find some windows to send this to */
2395 if (!XQueryTree (GDK_DISPLAY_XDISPLAY (display), xid,
2396 &ret_root, &ret_parent,
2397 &ret_children, &ret_nchildren))
2400 for(i = 0; i < ret_nchildren; i++)
2401 if (gdk_event_send_client_message_to_all_recurse (display, xev, ret_children[i], level + 1))
2404 XFree (ret_children);
2407 if (send || (!found && (level == 1)))
2409 xev->xclient.window = xid;
2410 _gdk_send_xevent (display, xid, False, NoEventMask, xev);
2413 result = send || found;
2416 gdk_error_trap_pop ();
2422 * gdk_screen_broadcast_client_message:
2423 * @screen: the #GdkScreen where the event will be broadcasted.
2424 * @event: the #GdkEvent.
2426 * On X11, sends an X ClientMessage event to all toplevel windows on
2429 * Toplevel windows are determined by checking for the WM_STATE property,
2430 * as described in the Inter-Client Communication Conventions Manual (ICCCM).
2431 * If no windows are found with the WM_STATE property set, the message is
2432 * sent to all children of the root window.
2434 * On Windows, broadcasts a message registered with the name
2435 * GDK_WIN32_CLIENT_MESSAGE to all top-level windows. The amount of
2436 * data is limited to one long, i.e. four bytes.
2442 gdk_screen_broadcast_client_message (GdkScreen *screen,
2446 GdkWindow *root_window;
2448 g_return_if_fail (event != NULL);
2450 root_window = gdk_screen_get_root_window (screen);
2452 /* Set up our event to send, with the exception of its target window */
2453 sev.xclient.type = ClientMessage;
2454 sev.xclient.display = GDK_WINDOW_XDISPLAY (root_window);
2455 sev.xclient.format = event->client.data_format;
2456 memcpy(&sev.xclient.data, &event->client.data, sizeof (sev.xclient.data));
2457 sev.xclient.message_type =
2458 gdk_x11_atom_to_xatom_for_display (GDK_WINDOW_DISPLAY (root_window),
2459 event->client.message_type);
2461 gdk_event_send_client_message_to_all_recurse (gdk_screen_get_display (screen),
2463 GDK_WINDOW_XID (root_window),
2468 *--------------------------------------------------------------
2471 * Flushes the Xlib output buffer and then waits
2472 * until all requests have been received and processed
2473 * by the X server. The only real use for this function
2474 * is in dealing with XShm.
2482 *--------------------------------------------------------------
2488 GSList *tmp_list = _gdk_displays;
2492 XSync (GDK_DISPLAY_XDISPLAY (tmp_list->data), False);
2493 tmp_list = tmp_list->next;
2498 timestamp_predicate (Display *display,
2502 Window xwindow = GPOINTER_TO_UINT (arg);
2503 GdkDisplay *gdk_display = gdk_x11_lookup_xdisplay (display);
2505 if (xevent->type == PropertyNotify &&
2506 xevent->xproperty.window == xwindow &&
2507 xevent->xproperty.atom == gdk_x11_get_xatom_by_name_for_display (gdk_display,
2508 "GDK_TIMESTAMP_PROP"))
2515 * gdk_x11_get_server_time:
2516 * @window: a #GdkWindow, used for communication with the server.
2517 * The window must have GDK_PROPERTY_CHANGE_MASK in its
2518 * events mask or a hang will result.
2520 * Routine to get the current X server time stamp.
2522 * Return value: the time stamp.
2525 gdk_x11_get_server_time (GdkWindow *window)
2531 Atom timestamp_prop_atom;
2533 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
2534 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
2536 xdisplay = GDK_WINDOW_XDISPLAY (window);
2537 xwindow = GDK_WINDOW_XWINDOW (window);
2538 timestamp_prop_atom =
2539 gdk_x11_get_xatom_by_name_for_display (GDK_WINDOW_DISPLAY (window),
2540 "GDK_TIMESTAMP_PROP");
2542 XChangeProperty (xdisplay, xwindow, timestamp_prop_atom,
2543 timestamp_prop_atom,
2544 8, PropModeReplace, &c, 1);
2546 XIfEvent (xdisplay, &xevent,
2547 timestamp_predicate, GUINT_TO_POINTER(xwindow));
2549 return xevent.xproperty.time;
2553 fetch_net_wm_check_window (GdkScreen *screen)
2555 GdkScreenX11 *screen_x11;
2556 GdkDisplay *display;
2564 /* This function is very slow on every call if you are not running a
2565 * spec-supporting WM. For now not optimized, because it isn't in
2566 * any critical code paths, but if you used it somewhere that had to
2567 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2568 * Probably at that point the function should be changed to query
2569 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2572 screen_x11 = GDK_SCREEN_X11 (screen);
2573 display = screen_x11->display;
2575 if (screen_x11->wmspec_check_window != None)
2576 return; /* already have it */
2579 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2580 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTING_WM_CHECK"),
2581 0, G_MAXLONG, False, XA_WINDOW, &type, &format,
2582 &n_items, &bytes_after, &data);
2584 if (type != XA_WINDOW)
2591 xwindow = (Window *)data;
2593 gdk_error_trap_push ();
2595 /* Find out if this WM goes away, so we can reset everything. */
2596 XSelectInput (screen_x11->xdisplay, *xwindow, StructureNotifyMask);
2597 gdk_display_sync (display);
2599 if (gdk_error_trap_pop () == Success)
2601 screen_x11->wmspec_check_window = *xwindow;
2602 screen_x11->need_refetch_net_supported = TRUE;
2603 screen_x11->need_refetch_wm_name = TRUE;
2605 /* Careful, reentrancy */
2606 _gdk_x11_screen_window_manager_changed (GDK_SCREEN (screen_x11));
2613 * gdk_x11_screen_get_window_manager_name:
2614 * @screen: a #GdkScreen
2616 * Returns the name of the window manager for @screen.
2618 * Return value: the name of the window manager screen @screen, or
2619 * "unknown" if the window manager is unknown. The string is owned by GDK
2620 * and should not be freed.
2625 gdk_x11_screen_get_window_manager_name (GdkScreen *screen)
2627 GdkScreenX11 *screen_x11;
2629 screen_x11 = GDK_SCREEN_X11 (screen);
2631 fetch_net_wm_check_window (screen);
2633 if (screen_x11->need_refetch_wm_name)
2635 /* Get the name of the window manager */
2636 screen_x11->need_refetch_wm_name = FALSE;
2638 g_free (screen_x11->window_manager_name);
2639 screen_x11->window_manager_name = g_strdup ("unknown");
2641 if (screen_x11->wmspec_check_window != None)
2651 gdk_error_trap_push ();
2653 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (screen_x11->display),
2654 screen_x11->wmspec_check_window,
2655 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2657 0, G_MAXLONG, False,
2658 gdk_x11_get_xatom_by_name_for_display (screen_x11->display,
2661 &n_items, &bytes_after,
2664 gdk_display_sync (screen_x11->display);
2666 gdk_error_trap_pop ();
2670 g_free (screen_x11->window_manager_name);
2671 screen_x11->window_manager_name = g_strdup (name);
2677 return GDK_SCREEN_X11 (screen)->window_manager_name;
2680 typedef struct _NetWmSupportedAtoms NetWmSupportedAtoms;
2682 struct _NetWmSupportedAtoms
2689 * gdk_x11_screen_supports_net_wm_hint:
2690 * @screen: the relevant #GdkScreen.
2691 * @property: a property atom.
2693 * This function is specific to the X11 backend of GDK, and indicates
2694 * whether the window manager supports a certain hint from the
2695 * Extended Window Manager Hints Specification. You can find this
2697 * <ulink url="http://www.freedesktop.org">http://www.freedesktop.org</ulink>.
2699 * When using this function, keep in mind that the window manager
2700 * can change over time; so you shouldn't use this function in
2701 * a way that impacts persistent application state. A common bug
2702 * is that your application can start up before the window manager
2703 * does when the user logs in, and before the window manager starts
2704 * gdk_x11_screen_supports_net_wm_hint() will return %FALSE for every property.
2705 * You can monitor the window_manager_changed signal on #GdkScreen to detect
2706 * a window manager change.
2708 * Return value: %TRUE if the window manager supports @property
2713 gdk_x11_screen_supports_net_wm_hint (GdkScreen *screen,
2717 GdkScreenX11 *screen_x11;
2718 NetWmSupportedAtoms *supported_atoms;
2719 GdkDisplay *display;
2721 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2723 screen_x11 = GDK_SCREEN_X11 (screen);
2724 display = screen_x11->display;
2726 supported_atoms = g_object_get_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms");
2727 if (!supported_atoms)
2729 supported_atoms = g_new0 (NetWmSupportedAtoms, 1);
2730 g_object_set_data (G_OBJECT (screen), "gdk-net-wm-supported-atoms", supported_atoms);
2733 fetch_net_wm_check_window (screen);
2735 if (screen_x11->wmspec_check_window == None)
2738 if (screen_x11->need_refetch_net_supported)
2740 /* WM has changed since we last got the supported list,
2747 screen_x11->need_refetch_net_supported = FALSE;
2749 if (supported_atoms->atoms)
2750 XFree (supported_atoms->atoms);
2752 supported_atoms->atoms = NULL;
2753 supported_atoms->n_atoms = 0;
2755 XGetWindowProperty (GDK_DISPLAY_XDISPLAY (display), screen_x11->xroot_window,
2756 gdk_x11_get_xatom_by_name_for_display (display, "_NET_SUPPORTED"),
2757 0, G_MAXLONG, False, XA_ATOM, &type, &format,
2758 &supported_atoms->n_atoms, &bytes_after,
2759 (guchar **)&supported_atoms->atoms);
2761 if (type != XA_ATOM)
2765 if (supported_atoms->atoms == NULL)
2769 while (i < supported_atoms->n_atoms)
2771 if (supported_atoms->atoms[i] == gdk_x11_atom_to_xatom_for_display (display, property))
2781 * gdk_net_wm_supports:
2782 * @property: a property atom.
2784 * This function is specific to the X11 backend of GDK, and indicates
2785 * whether the window manager for the default screen supports a certain
2786 * hint from the Extended Window Manager Hints Specification. See
2787 * gdk_x11_screen_supports_net_wm_hint() for complete details.
2789 * Return value: %TRUE if the window manager supports @property
2792 gdk_net_wm_supports (GdkAtom property)
2794 return gdk_x11_screen_supports_net_wm_hint (gdk_screen_get_default (), property);
2797 static const char settings_names[] =
2798 "Net/DoubleClickTime\0" "gtk-double-click-time\0"
2799 "Net/DoubleClickDistance\0" "gtk-double-click-distance\0"
2800 "Net/DndDragThreshold\0" "gtk-dnd-drag-threshold\0"
2801 "Net/CursorBlink\0" "gtk-cursor-blink\0"
2802 "Net/CursorBlinkTime\0" "gtk-cursor-blink-time\0"
2803 "Net/ThemeName\0" "gtk-theme-name\0"
2804 "Net/IconThemeName\0" "gtk-icon-theme-name\0"
2805 "Gtk/CanChangeAccels\0" "gtk-can-change-accels\0"
2806 "Gtk/ColorPalette\0" "gtk-color-palette\0"
2807 "Gtk/FontName\0" "gtk-font-name\0"
2808 "Gtk/IconSizes\0" "gtk-icon-sizes\0"
2809 "Gtk/KeyThemeName\0" "gtk-key-theme-name\0"
2810 "Gtk/ToolbarStyle\0" "gtk-toolbar-style\0"
2811 "Gtk/ToolbarIconSize\0" "gtk-toolbar-icon-size\0"
2812 "Gtk/IMPreeditStyle\0" "gtk-im-preedit-style\0"
2813 "Gtk/IMStatusStyle\0" "gtk-im-status-style\0"
2814 "Gtk/Modules\0" "gtk-modules\0"
2815 "Gtk/FileChooserBackend\0" "gtk-file-chooser-backend\0"
2816 "Gtk/ButtonImages\0" "gtk-button-images\0"
2817 "Gtk/MenuImages\0" "gtk-menu-images\0"
2818 "Gtk/MenuBarAccel\0" "gtk-menu-bar-accel\0"
2819 "Gtk/CursorThemeName\0" "gtk-cursor-theme-name\0"
2820 "Gtk/CursorThemeSize\0" "gtk-cursor-theme-size\0"
2821 "Gtk/ShowInputMethodMenu\0" "gtk-show-input-method-menu\0"
2822 "Gtk/ShowUnicodeMenu\0" "gtk-show-unicode-menu\0"
2823 "Gtk/TimeoutInitial\0" "gtk-timeout-initial\0"
2824 "Gtk/TimeoutRepeat\0" "gtk-timeout-repeat\0"
2825 "Gtk/ColorScheme\0" "gtk-color-scheme\0"
2826 "Gtk/EnableAnimations\0" "gtk-enable-animations\0"
2827 "Xft/Antialias\0" "gtk-xft-antialias\0"
2828 "Xft/Hinting\0" "gtk-xft-hinting\0"
2829 "Xft/HintStyle\0" "gtk-xft-hintstyle\0"
2830 "Xft/RGBA\0" "gtk-xft-rgba\0"
2831 "Xft/DPI\0" "gtk-xft-dpi\0"
2832 "Net/FallbackIconTheme\0" "gtk-fallback-icon-theme\0";
2836 gint xsettings_offset;
2838 } settings_map[] = {
2877 gdk_xsettings_notify_cb (const char *name,
2878 XSettingsAction action,
2879 XSettingsSetting *setting,
2883 GdkScreen *screen = data;
2884 GdkScreenX11 *screen_x11 = data;
2887 if (screen_x11->xsettings_in_init)
2890 new_event.type = GDK_SETTING;
2891 new_event.setting.window = gdk_screen_get_root_window (screen);
2892 new_event.setting.send_event = FALSE;
2893 new_event.setting.name = NULL;
2895 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2896 if (strcmp (settings_names + settings_map[i].xsettings_offset, name) == 0)
2898 new_event.setting.name = (char *)settings_names + settings_map[i].gdk_offset;
2902 if (!new_event.setting.name)
2907 case XSETTINGS_ACTION_NEW:
2908 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2910 case XSETTINGS_ACTION_CHANGED:
2911 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2913 case XSETTINGS_ACTION_DELETED:
2914 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2918 gdk_event_put (&new_event);
2922 check_transform (const gchar *xsettings_name,
2926 if (!g_value_type_transformable (src_type, dest_type))
2928 g_warning ("Cannot transform xsetting %s of type %s to type %s\n",
2930 g_type_name (src_type),
2931 g_type_name (dest_type));
2939 * gdk_screen_get_setting:
2940 * @screen: the #GdkScreen where the setting is located
2941 * @name: the name of the setting
2942 * @value: location to store the value of the setting
2944 * Retrieves a desktop-wide setting such as double-click time
2945 * for the #GdkScreen @screen.
2947 * FIXME needs a list of valid settings here, or a link to
2950 * Returns: %TRUE if the setting existed and a value was stored
2951 * in @value, %FALSE otherwise.
2956 gdk_screen_get_setting (GdkScreen *screen,
2961 const char *xsettings_name = NULL;
2962 XSettingsResult result;
2963 XSettingsSetting *setting = NULL;
2964 GdkScreenX11 *screen_x11;
2965 gboolean success = FALSE;
2967 GValue tmp_val = { 0, };
2969 g_return_val_if_fail (GDK_IS_SCREEN (screen), FALSE);
2971 screen_x11 = GDK_SCREEN_X11 (screen);
2973 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2974 if (strcmp (settings_names + settings_map[i].gdk_offset, name) == 0)
2976 xsettings_name = settings_names + settings_map[i].xsettings_offset;
2980 if (!xsettings_name)
2983 result = xsettings_client_get_setting (screen_x11->xsettings_client,
2984 xsettings_name, &setting);
2985 if (result != XSETTINGS_SUCCESS)
2988 switch (setting->type)
2990 case XSETTINGS_TYPE_INT:
2991 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2993 g_value_init (&tmp_val, G_TYPE_INT);
2994 g_value_set_int (&tmp_val, setting->data.v_int);
2995 g_value_transform (&tmp_val, value);
3000 case XSETTINGS_TYPE_STRING:
3001 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
3003 g_value_init (&tmp_val, G_TYPE_STRING);
3004 g_value_set_string (&tmp_val, setting->data.v_string);
3005 g_value_transform (&tmp_val, value);
3010 case XSETTINGS_TYPE_COLOR:
3011 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
3015 g_value_init (&tmp_val, GDK_TYPE_COLOR);
3018 color.red = setting->data.v_color.red;
3019 color.green = setting->data.v_color.green;
3020 color.blue = setting->data.v_color.blue;
3022 g_value_set_boxed (&tmp_val, &color);
3024 g_value_transform (&tmp_val, value);
3031 g_value_unset (&tmp_val);
3035 xsettings_setting_free (setting);
3040 return _gdk_x11_get_xft_setting (screen, name, value);
3043 static GdkFilterReturn
3044 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
3048 GdkScreenX11 *screen = data;
3050 if (xsettings_client_process_event (screen->xsettings_client, (XEvent *)xevent))
3051 return GDK_FILTER_REMOVE;
3053 return GDK_FILTER_CONTINUE;
3057 gdk_xsettings_watch_cb (Window window,
3063 GdkScreen *screen = cb_data;
3065 gdkwin = gdk_window_lookup_for_display (gdk_screen_get_display (screen), window);
3070 gdkwin = gdk_window_foreign_new_for_display (gdk_screen_get_display (screen), window);
3072 g_object_ref (gdkwin);
3074 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3079 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, screen);
3080 g_object_unref (gdkwin);
3084 #define __GDK_EVENTS_X11_C__
3085 #include "gdkaliasdef.c"