1 /* GDK - The GIMP Drawing Kit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
28 #include "gdkprivate-x11.h"
29 #include "gdkinternals.h"
32 #include "gdkkeysyms.h"
34 #include "xsettings-client.h"
43 #include "gdkinputprivate.h"
46 #include <X11/XKBlib.h>
49 #include <X11/Xatom.h>
51 typedef struct _GdkIOClosure GdkIOClosure;
52 typedef struct _GdkEventPrivate GdkEventPrivate;
54 #define DOUBLE_CLICK_TIME 250
55 #define TRIPLE_CLICK_TIME 500
56 #define DOUBLE_CLICK_DIST 5
57 #define TRIPLE_CLICK_DIST 5
61 /* Following flag is set for events on the event queue during
62 * translation and cleared afterwards.
64 GDK_EVENT_PENDING = 1 << 0
69 GdkInputFunction function;
70 GdkInputCondition condition;
71 GdkDestroyNotify notify;
75 struct _GdkEventPrivate
82 * Private function declarations
85 static gint gdk_event_apply_filters (XEvent *xevent,
88 static gint gdk_event_translate (GdkEvent *event,
90 gboolean return_exposes);
92 static Bool gdk_event_get_type (Display *display,
97 static gboolean gdk_event_prepare (GSource *source,
99 static gboolean gdk_event_check (GSource *source);
100 static gboolean gdk_event_dispatch (GSource *source,
101 GSourceFunc callback,
104 static GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
108 static void gdk_xsettings_watch_cb (Window window,
112 static void gdk_xsettings_notify_cb (const char *name,
113 XSettingsAction action,
114 XSettingsSetting *setting,
117 /* Private variable declarations
120 static int connection_number = 0; /* The file descriptor number of our
121 * connection to the X server. This
122 * is used so that we may determine
123 * when events are pending by using
124 * the "select" system call.
126 static GList *client_filters; /* Filters for client messages */
128 static GSourceFuncs event_funcs = {
135 static GPollFD event_poll_fd;
137 static Window wmspec_check_window = None;
139 static XSettingsClient *xsettings_client;
141 /*********************************************
142 * Functions for maintaining the event queue *
143 *********************************************/
146 _gdk_events_init (void)
150 connection_number = ConnectionNumber (gdk_display);
152 g_message ("connection number: %d", connection_number));
155 source = g_source_new (&event_funcs, sizeof (GSource));
156 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
158 event_poll_fd.fd = connection_number;
159 event_poll_fd.events = G_IO_IN;
161 g_source_add_poll (source, &event_poll_fd);
162 g_source_set_can_recurse (source, TRUE);
163 g_source_attach (source, NULL);
165 _gdk_wm_window_protocols[0] = gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW");
166 _gdk_wm_window_protocols[1] = gdk_x11_get_xatom_by_name ("WM_TAKE_FOCUS");
167 _gdk_wm_window_protocols[2] = gdk_x11_get_xatom_by_name ("_NET_WM_PING");
169 gdk_add_client_message_filter (gdk_atom_intern ("WM_PROTOCOLS", FALSE),
170 gdk_wm_protocols_filter, NULL);
172 xsettings_client = xsettings_client_new (gdk_display, DefaultScreen (gdk_display),
173 gdk_xsettings_notify_cb,
174 gdk_xsettings_watch_cb,
179 *--------------------------------------------------------------
182 * Returns if events are pending on the queue.
187 * Returns TRUE if events are pending
191 *--------------------------------------------------------------
195 gdk_events_pending (void)
197 return (_gdk_event_queue_find_first() || XPending (gdk_display));
201 *--------------------------------------------------------------
202 * gdk_event_get_graphics_expose
204 * Waits for a GraphicsExpose or NoExpose event
209 * For GraphicsExpose events, returns a pointer to the event
210 * converted into a GdkEvent Otherwise, returns NULL.
214 *-------------------------------------------------------------- */
217 graphics_expose_predicate (Display *display,
221 if (xevent->xany.window == GDK_DRAWABLE_XID ((GdkDrawable *)arg) &&
222 (xevent->xany.type == GraphicsExpose ||
223 xevent->xany.type == NoExpose))
230 gdk_event_get_graphics_expose (GdkWindow *window)
235 g_return_val_if_fail (window != NULL, NULL);
237 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
239 if (xevent.xany.type == GraphicsExpose)
241 event = _gdk_event_new ();
243 if (gdk_event_translate (event, &xevent, TRUE))
246 gdk_event_free (event);
253 gdk_event_apply_filters (XEvent *xevent,
258 GdkFilterReturn result;
264 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
266 tmp_list = tmp_list->next;
267 result = filter->function (xevent, event, filter->data);
268 if (result != GDK_FILTER_CONTINUE)
272 return GDK_FILTER_CONTINUE;
276 gdk_add_client_message_filter (GdkAtom message_type,
280 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
282 filter->type = message_type;
283 filter->function = func;
286 client_filters = g_list_prepend (client_filters, filter);
289 static Atom wm_state_atom = 0;
290 static Atom wm_desktop_atom = 0;
293 gdk_check_wm_state_changed (GdkWindow *window)
304 gboolean found_sticky, found_maxvert, found_maxhorz;
305 GdkWindowState old_state;
307 if (GDK_WINDOW_DESTROYED (window))
310 if (wm_state_atom == 0)
311 wm_state_atom = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
313 if (wm_desktop_atom == 0)
314 wm_desktop_atom = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
316 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
317 wm_state_atom, 0, G_MAXLONG,
318 False, XA_ATOM, &type, &format, &nitems,
319 &bytes_after, (guchar **)&atoms);
324 sticky_atom = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_STICKY");
325 maxvert_atom = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_VERT");
326 maxhorz_atom = gdk_x11_get_xatom_by_name ("_NET_WM_STATE_MAXIMIZED_HORZ");
328 found_sticky = FALSE;
329 found_maxvert = FALSE;
330 found_maxhorz = FALSE;
335 if (atoms[i] == sticky_atom)
337 else if (atoms[i] == maxvert_atom)
338 found_maxvert = TRUE;
339 else if (atoms[i] == maxhorz_atom)
340 found_maxhorz = TRUE;
349 found_sticky = FALSE;
350 found_maxvert = FALSE;
351 found_maxhorz = FALSE;
354 /* For found_sticky to remain TRUE, we have to also be on desktop
362 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
363 wm_desktop_atom, 0, G_MAXLONG,
364 False, XA_CARDINAL, &type, &format, &nitems,
365 &bytes_after, (guchar **)&desktop);
369 if (*desktop != 0xFFFFFFFF)
370 found_sticky = FALSE;
375 old_state = gdk_window_get_state (window);
377 if (old_state & GDK_WINDOW_STATE_STICKY)
380 gdk_synthesize_window_state (window,
381 GDK_WINDOW_STATE_STICKY,
387 gdk_synthesize_window_state (window,
389 GDK_WINDOW_STATE_STICKY);
392 /* Our "maximized" means both vertical and horizontal; if only one,
393 * we don't expose that via GDK
395 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
397 if (!(found_maxvert && found_maxhorz))
398 gdk_synthesize_window_state (window,
399 GDK_WINDOW_STATE_MAXIMIZED,
404 if (found_maxvert && found_maxhorz)
405 gdk_synthesize_window_state (window,
407 GDK_WINDOW_STATE_MAXIMIZED);
411 #define HAS_FOCUS(window_impl) \
412 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
415 generate_focus_event (GdkWindow *window,
420 event.type = GDK_FOCUS_CHANGE;
421 event.focus_change.window = window;
422 event.focus_change.send_event = FALSE;
423 event.focus_change.in = in;
425 gdk_event_put (&event);
429 gdk_event_translate (GdkEvent *event,
431 gboolean return_exposes)
435 GdkWindowObject *window_private;
436 GdkWindowImplX11 *window_impl = NULL;
437 static XComposeStatus compose;
442 gint xoffset, yoffset;
446 /* init these, since the done: block uses them */
448 window_private = NULL;
449 event->any.window = NULL;
451 if (_gdk_default_filters)
453 /* Apply global filters */
454 GdkFilterReturn result;
455 result = gdk_event_apply_filters (xevent, event,
456 _gdk_default_filters);
458 if (result != GDK_FILTER_CONTINUE)
460 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
465 /* We handle events with window=None
466 * specially - they are generated by XFree86's XInput under
467 * some circumstances. This handling for obvious reasons
468 * goes before we bother to lookup the event window.
471 if (xevent->xany.window == None)
473 return_val = _gdk_input_window_none_event (event, xevent);
475 if (return_val >= 0) /* was handled */
481 /* Find the GdkWindow that this event occurred in. */
483 window = gdk_window_lookup (xevent->xany.window);
484 window_private = (GdkWindowObject *) window;
488 /* Window may be a pixmap, so check its type.
489 * (This check is probably too expensive unless
490 * GLib short-circuits an exact type match,
491 * which has been proposed)
493 if (GDK_IS_WINDOW (window))
495 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
497 if (xevent->xany.window != GDK_WINDOW_XID (window))
499 g_assert (xevent->xany.window == window_impl->focus_window);
501 switch (xevent->type)
505 xevent->xany.window = GDK_WINDOW_XID (window);
513 g_object_ref (G_OBJECT (window));
516 event->any.window = window;
517 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
519 if (window_private && GDK_WINDOW_DESTROYED (window))
521 if (xevent->type != DestroyNotify)
527 else if (window_private)
529 /* Apply per-window filters */
530 GdkFilterReturn result;
531 result = gdk_event_apply_filters (xevent, event,
532 window_private->filters);
534 if (result != GDK_FILTER_CONTINUE)
536 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
541 if (wmspec_check_window != None &&
542 xevent->xany.window == wmspec_check_window)
544 if (xevent->type == DestroyNotify)
545 wmspec_check_window = None;
547 /* Eat events on this window unless someone had wrapped
548 * it as a foreign window
558 _gdk_moveresize_window &&
559 (xevent->xany.type == MotionNotify ||
560 xevent->xany.type == ButtonRelease))
562 _gdk_moveresize_handle_event (xevent);
568 /* We do a "manual" conversion of the XEvent to a
569 * GdkEvent. The structures are mostly the same so
570 * the conversion is fairly straightforward. We also
571 * optionally print debugging info regarding events
579 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
587 switch (xevent->type)
590 if (window_private == NULL)
596 /* Lookup the string corresponding to the given keysym.
599 charcount = XLookupString (&xevent->xkey, buf, 16,
601 event->key.keyval = keysym;
602 event->key.hardware_keycode = xevent->xkey.keycode;
604 if (charcount > 0 && buf[charcount-1] == '\0')
607 buf[charcount] = '\0';
609 #ifdef G_ENABLE_DEBUG
610 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
612 g_message ("key press:\twindow: %ld key: %12s %d",
614 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
617 g_message ("\t\tlength: %4d string: \"%s\"",
620 #endif /* G_ENABLE_DEBUG */
622 /* bits 13 and 14 in the "state" field are the keyboard group */
623 #define KEYBOARD_GROUP_SHIFT 13
624 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
626 event->key.type = GDK_KEY_PRESS;
627 event->key.window = window;
628 event->key.time = xevent->xkey.time;
629 event->key.state = (GdkModifierType) xevent->xkey.state;
630 event->key.string = g_strdup (buf);
631 event->key.length = charcount;
633 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
638 if (window_private == NULL)
644 /* Lookup the string corresponding to the given keysym.
647 /* Emulate detectable auto-repeat by checking to see
648 * if the next event is a key press with the same
649 * keycode and timestamp, and if so, ignoring the event.
652 if (!_gdk_have_xkb_autorepeat && XPending (gdk_display))
656 XPeekEvent (gdk_display, &next_event);
658 if (next_event.type == KeyPress &&
659 next_event.xkey.keycode == xevent->xkey.keycode &&
660 next_event.xkey.time == xevent->xkey.time)
664 keysym = GDK_VoidSymbol;
665 charcount = XLookupString (&xevent->xkey, buf, 16,
667 event->key.keyval = keysym;
670 g_message ("key release:\t\twindow: %ld key: %12s %d",
672 XKeysymToString (event->key.keyval),
675 event->key.type = GDK_KEY_RELEASE;
676 event->key.window = window;
677 event->key.time = xevent->xkey.time;
678 event->key.state = (GdkModifierType) xevent->xkey.state;
679 event->key.length = 0;
680 event->key.string = NULL;
686 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
687 xevent->xbutton.window,
688 xevent->xbutton.x, xevent->xbutton.y,
689 xevent->xbutton.button));
691 if (window_private == NULL ||
692 ((window_private->extension_events != 0) &&
693 _gdk_input_ignore_core))
699 /* If we get a ButtonPress event where the button is 4 or 5,
700 it's a Scroll event */
701 switch (xevent->xbutton.button)
707 event->scroll.type = GDK_SCROLL;
709 if (xevent->xbutton.button == 4)
710 event->scroll.direction = GDK_SCROLL_UP;
711 else if (xevent->xbutton.button == 5)
712 event->scroll.direction = GDK_SCROLL_DOWN;
713 else if (xevent->xbutton.button == 6)
714 event->scroll.direction = GDK_SCROLL_LEFT;
716 event->scroll.direction = GDK_SCROLL_RIGHT;
718 event->scroll.window = window;
719 event->scroll.time = xevent->xbutton.x;
720 event->scroll.x = xevent->xbutton.x + xoffset;
721 event->scroll.y = xevent->xbutton.y + yoffset;
722 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
723 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
724 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
725 event->scroll.device = _gdk_core_pointer;
729 event->button.type = GDK_BUTTON_PRESS;
730 event->button.window = window;
731 event->button.time = xevent->xbutton.time;
732 event->button.x = xevent->xbutton.x + xoffset;
733 event->button.y = xevent->xbutton.y + yoffset;
734 event->button.x_root = (gfloat)xevent->xbutton.x_root;
735 event->button.y_root = (gfloat)xevent->xbutton.y_root;
736 event->button.axes = NULL;
737 event->button.state = (GdkModifierType) xevent->xbutton.state;
738 event->button.button = xevent->xbutton.button;
739 event->button.device = _gdk_core_pointer;
741 _gdk_event_button_generate (event);
749 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
750 xevent->xbutton.window,
751 xevent->xbutton.x, xevent->xbutton.y,
752 xevent->xbutton.button));
754 if (window_private == NULL ||
755 ((window_private->extension_events != 0) &&
756 _gdk_input_ignore_core))
762 /* We treat button presses as scroll wheel events, so ignore the release */
763 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
764 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
770 event->button.type = GDK_BUTTON_RELEASE;
771 event->button.window = window;
772 event->button.time = xevent->xbutton.time;
773 event->button.x = xevent->xbutton.x + xoffset;
774 event->button.y = xevent->xbutton.y + yoffset;
775 event->button.x_root = (gfloat)xevent->xbutton.x_root;
776 event->button.y_root = (gfloat)xevent->xbutton.y_root;
777 event->button.axes = NULL;
778 event->button.state = (GdkModifierType) xevent->xbutton.state;
779 event->button.button = xevent->xbutton.button;
780 event->button.device = _gdk_core_pointer;
786 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
787 xevent->xmotion.window,
788 xevent->xmotion.x, xevent->xmotion.y,
789 (xevent->xmotion.is_hint) ? "true" : "false"));
791 if (window_private == NULL ||
792 ((window_private->extension_events != 0) &&
793 _gdk_input_ignore_core))
799 event->motion.type = GDK_MOTION_NOTIFY;
800 event->motion.window = window;
801 event->motion.time = xevent->xmotion.time;
802 event->motion.x = xevent->xmotion.x + xoffset;
803 event->motion.y = xevent->xmotion.y + yoffset;
804 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
805 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
806 event->motion.axes = NULL;
807 event->motion.state = (GdkModifierType) xevent->xmotion.state;
808 event->motion.is_hint = xevent->xmotion.is_hint;
809 event->motion.device = _gdk_core_pointer;
815 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
816 xevent->xcrossing.window,
817 xevent->xcrossing.detail,
818 xevent->xcrossing.subwindow));
820 if (window_private == NULL)
826 /* Handle focusing (in the case where no window manager is running */
828 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
829 xevent->xcrossing.detail != NotifyInferior &&
830 xevent->xcrossing.focus && !window_impl->has_focus)
832 gboolean had_focus = HAS_FOCUS (window_impl);
834 window_impl->has_pointer_focus = TRUE;
836 if (HAS_FOCUS (window_impl) != had_focus)
837 generate_focus_event (window, TRUE);
840 /* Tell XInput stuff about it if appropriate */
841 if (window_private &&
842 !GDK_WINDOW_DESTROYED (window) &&
843 window_private->extension_events != 0)
844 _gdk_input_enter_event (&xevent->xcrossing, window);
846 event->crossing.type = GDK_ENTER_NOTIFY;
847 event->crossing.window = window;
849 /* If the subwindow field of the XEvent is non-NULL, then
850 * lookup the corresponding GdkWindow.
852 if (xevent->xcrossing.subwindow != None)
853 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
855 event->crossing.subwindow = NULL;
857 event->crossing.time = xevent->xcrossing.time;
858 event->crossing.x = xevent->xcrossing.x + xoffset;
859 event->crossing.y = xevent->xcrossing.y + yoffset;
860 event->crossing.x_root = xevent->xcrossing.x_root;
861 event->crossing.y_root = xevent->xcrossing.y_root;
863 /* Translate the crossing mode into Gdk terms.
865 switch (xevent->xcrossing.mode)
868 event->crossing.mode = GDK_CROSSING_NORMAL;
871 event->crossing.mode = GDK_CROSSING_GRAB;
874 event->crossing.mode = GDK_CROSSING_UNGRAB;
878 /* Translate the crossing detail into Gdk terms.
880 switch (xevent->xcrossing.detail)
883 event->crossing.detail = GDK_NOTIFY_INFERIOR;
886 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
889 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
891 case NotifyNonlinear:
892 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
894 case NotifyNonlinearVirtual:
895 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
898 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
902 event->crossing.focus = xevent->xcrossing.focus;
903 event->crossing.state = xevent->xcrossing.state;
909 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
910 xevent->xcrossing.window,
911 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
913 if (window_private == NULL)
919 /* Handle focusing (in the case where no window manager is running */
921 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
922 xevent->xcrossing.detail != NotifyInferior &&
923 xevent->xcrossing.focus && !window_impl->has_focus)
925 gboolean had_focus = HAS_FOCUS (window_impl);
927 window_impl->has_pointer_focus = FALSE;
929 if (HAS_FOCUS (window_impl) != had_focus)
930 generate_focus_event (window, FALSE);
933 event->crossing.type = GDK_LEAVE_NOTIFY;
934 event->crossing.window = window;
936 /* If the subwindow field of the XEvent is non-NULL, then
937 * lookup the corresponding GdkWindow.
939 if (xevent->xcrossing.subwindow != None)
940 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
942 event->crossing.subwindow = NULL;
944 event->crossing.time = xevent->xcrossing.time;
945 event->crossing.x = xevent->xcrossing.x + xoffset;
946 event->crossing.y = xevent->xcrossing.y + yoffset;
947 event->crossing.x_root = xevent->xcrossing.x_root;
948 event->crossing.y_root = xevent->xcrossing.y_root;
950 /* Translate the crossing mode into Gdk terms.
952 switch (xevent->xcrossing.mode)
955 event->crossing.mode = GDK_CROSSING_NORMAL;
958 event->crossing.mode = GDK_CROSSING_GRAB;
961 event->crossing.mode = GDK_CROSSING_UNGRAB;
965 /* Translate the crossing detail into Gdk terms.
967 switch (xevent->xcrossing.detail)
970 event->crossing.detail = GDK_NOTIFY_INFERIOR;
973 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
976 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
978 case NotifyNonlinear:
979 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
981 case NotifyNonlinearVirtual:
982 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
985 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
989 event->crossing.focus = xevent->xcrossing.focus;
990 event->crossing.state = xevent->xcrossing.state;
994 /* We only care about focus events that indicate that _this_
995 * window (not a ancestor or child) got or lost the focus
999 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
1001 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1003 gboolean had_focus = HAS_FOCUS (window_impl);
1005 switch (xevent->xfocus.detail)
1007 case NotifyAncestor:
1008 case NotifyNonlinear:
1010 case NotifyNonlinearVirtual:
1011 window_impl->has_focus = TRUE;
1014 window_impl->has_pointer_focus = TRUE;
1016 case NotifyInferior:
1017 case NotifyPointerRoot:
1018 case NotifyDetailNone:
1022 if (HAS_FOCUS (window_impl) != had_focus)
1023 generate_focus_event (window, TRUE);
1028 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1030 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1032 gboolean had_focus = HAS_FOCUS (window_impl);
1034 switch (xevent->xfocus.detail)
1036 case NotifyAncestor:
1037 case NotifyNonlinear:
1039 case NotifyNonlinearVirtual:
1040 window_impl->has_focus = FALSE;
1043 window_impl->has_pointer_focus = FALSE;
1045 case NotifyInferior:
1046 case NotifyPointerRoot:
1047 case NotifyDetailNone:
1051 if (HAS_FOCUS (window_impl) != had_focus)
1052 generate_focus_event (window, FALSE);
1057 /* gdk_keyboard_grab() causes following events. These events confuse
1058 * the XIM focus, so ignore them.
1060 if (xevent->xfocus.mode == NotifyGrab ||
1061 xevent->xfocus.mode == NotifyUngrab)
1067 g_message ("keymap notify"));
1069 /* Not currently handled */
1075 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1076 xevent->xexpose.window, xevent->xexpose.count,
1077 xevent->xexpose.x, xevent->xexpose.y,
1078 xevent->xexpose.width, xevent->xexpose.height,
1079 event->any.send_event ? " (send)" : ""));
1081 if (window_private == NULL)
1088 GdkRectangle expose_rect;
1090 expose_rect.x = xevent->xexpose.x + xoffset;
1091 expose_rect.y = xevent->xexpose.y + yoffset;
1092 expose_rect.width = xevent->xexpose.width;
1093 expose_rect.height = xevent->xexpose.height;
1097 event->expose.type = GDK_EXPOSE;
1098 event->expose.area = expose_rect;
1099 event->expose.region = gdk_region_rectangle (&expose_rect);
1100 event->expose.window = window;
1101 event->expose.count = xevent->xexpose.count;
1107 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1117 case GraphicsExpose:
1119 GdkRectangle expose_rect;
1122 g_message ("graphics expose:\tdrawable: %ld",
1123 xevent->xgraphicsexpose.drawable));
1125 if (window_private == NULL)
1131 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1132 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1133 expose_rect.width = xevent->xgraphicsexpose.width;
1134 expose_rect.height = xevent->xgraphicsexpose.height;
1138 event->expose.type = GDK_EXPOSE;
1139 event->expose.area = expose_rect;
1140 event->expose.region = gdk_region_rectangle (&expose_rect);
1141 event->expose.window = window;
1142 event->expose.count = xevent->xgraphicsexpose.count;
1148 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1158 g_message ("no expose:\t\tdrawable: %ld",
1159 xevent->xnoexpose.drawable));
1161 event->no_expose.type = GDK_NO_EXPOSE;
1162 event->no_expose.window = window;
1166 case VisibilityNotify:
1167 #ifdef G_ENABLE_DEBUG
1168 if (_gdk_debug_flags & GDK_DEBUG_EVENTS)
1169 switch (xevent->xvisibility.state)
1171 case VisibilityFullyObscured:
1172 g_message ("visibility notify:\twindow: %ld none",
1173 xevent->xvisibility.window);
1175 case VisibilityPartiallyObscured:
1176 g_message ("visibility notify:\twindow: %ld partial",
1177 xevent->xvisibility.window);
1179 case VisibilityUnobscured:
1180 g_message ("visibility notify:\twindow: %ld full",
1181 xevent->xvisibility.window);
1184 #endif /* G_ENABLE_DEBUG */
1186 if (window_private == NULL)
1192 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1193 event->visibility.window = window;
1195 switch (xevent->xvisibility.state)
1197 case VisibilityFullyObscured:
1198 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1201 case VisibilityPartiallyObscured:
1202 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1205 case VisibilityUnobscured:
1206 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1214 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1215 xevent->xcreatewindow.window,
1216 xevent->xcreatewindow.x,
1217 xevent->xcreatewindow.y,
1218 xevent->xcreatewindow.width,
1219 xevent->xcreatewindow.height,
1220 xevent->xcreatewindow.border_width,
1221 xevent->xcreatewindow.parent,
1222 xevent->xcreatewindow.override_redirect));
1223 /* not really handled */
1228 g_message ("destroy notify:\twindow: %ld",
1229 xevent->xdestroywindow.window));
1231 /* Ignore DestroyNotify from SubstructureNotifyMask */
1232 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1234 event->any.type = GDK_DESTROY;
1235 event->any.window = window;
1237 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1239 if (window && GDK_WINDOW_XID (window) != GDK_ROOT_WINDOW())
1240 gdk_window_destroy_notify (window);
1248 g_message ("unmap notify:\t\twindow: %ld",
1249 xevent->xmap.window));
1251 event->any.type = GDK_UNMAP;
1252 event->any.window = window;
1254 /* If we are shown (not withdrawn) and get an unmap, it means we
1255 * were iconified in the X sense. If we are withdrawn, and get
1256 * an unmap, it means we hid the window ourselves, so we
1257 * will have already flipped the iconified bit off.
1259 if (window && GDK_WINDOW_IS_MAPPED (window))
1260 gdk_synthesize_window_state (window,
1262 GDK_WINDOW_STATE_ICONIFIED);
1264 if (_gdk_xgrab_window == window_private)
1265 _gdk_xgrab_window = NULL;
1271 g_message ("map notify:\t\twindow: %ld",
1272 xevent->xmap.window));
1274 event->any.type = GDK_MAP;
1275 event->any.window = window;
1277 /* Unset iconified if it was set */
1278 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1279 gdk_synthesize_window_state (window,
1280 GDK_WINDOW_STATE_ICONIFIED,
1285 case ReparentNotify:
1287 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1288 xevent->xreparent.window,
1289 xevent->xreparent.x,
1290 xevent->xreparent.y,
1291 xevent->xreparent.parent,
1292 xevent->xreparent.override_redirect));
1294 /* Not currently handled */
1298 case ConfigureNotify:
1300 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1301 xevent->xconfigure.window,
1302 xevent->xconfigure.x,
1303 xevent->xconfigure.y,
1304 xevent->xconfigure.width,
1305 xevent->xconfigure.height,
1306 xevent->xconfigure.border_width,
1307 xevent->xconfigure.above,
1308 xevent->xconfigure.override_redirect,
1311 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1312 ? " (discarding child)"
1315 !GDK_WINDOW_DESTROYED (window) &&
1316 (window_private->extension_events != 0))
1317 _gdk_input_configure_event (&xevent->xconfigure, window);
1320 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1321 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1325 event->configure.type = GDK_CONFIGURE;
1326 event->configure.window = window;
1327 event->configure.width = xevent->xconfigure.width;
1328 event->configure.height = xevent->xconfigure.height;
1330 if (!xevent->xconfigure.send_event &&
1331 !GDK_WINDOW_DESTROYED (window))
1335 Window child_window = 0;
1337 gdk_error_trap_push ();
1338 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1339 GDK_DRAWABLE_XID (window),
1345 if (!gdk_error_trap_pop ())
1347 event->configure.x = tx;
1348 event->configure.y = ty;
1352 gdk_error_trap_pop ();
1356 event->configure.x = xevent->xconfigure.x;
1357 event->configure.y = xevent->xconfigure.y;
1359 window_private->x = event->configure.x;
1360 window_private->y = event->configure.y;
1361 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1362 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1363 if (window_private->resize_count >= 1)
1365 window_private->resize_count -= 1;
1367 if (window_private->resize_count == 0 &&
1368 window == _gdk_moveresize_window)
1369 _gdk_moveresize_configure_done ();
1374 case PropertyNotify:
1376 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1377 xevent->xproperty.window,
1378 xevent->xproperty.atom,
1380 gdk_x11_get_xatom_name (xevent->xproperty.atom),
1383 if (window_private == NULL)
1389 event->property.type = GDK_PROPERTY_NOTIFY;
1390 event->property.window = window;
1391 event->property.atom = gdk_x11_xatom_to_atom (xevent->xproperty.atom);
1392 event->property.time = xevent->xproperty.time;
1393 event->property.state = xevent->xproperty.state;
1395 if (wm_state_atom == 0)
1396 wm_state_atom = gdk_x11_get_xatom_by_name ("_NET_WM_STATE");
1398 if (wm_desktop_atom == 0)
1399 wm_desktop_atom = gdk_x11_get_xatom_by_name ("_NET_WM_DESKTOP");
1401 if (xevent->xproperty.atom == wm_state_atom ||
1402 xevent->xproperty.atom == wm_desktop_atom)
1404 /* If window state changed, then synthesize those events. */
1405 gdk_check_wm_state_changed (event->property.window);
1410 case SelectionClear:
1412 g_message ("selection clear:\twindow: %ld",
1413 xevent->xproperty.window));
1415 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1417 event->selection.type = GDK_SELECTION_CLEAR;
1418 event->selection.window = window;
1419 event->selection.selection = gdk_x11_xatom_to_atom (xevent->xselectionclear.selection);
1420 event->selection.time = xevent->xselectionclear.time;
1427 case SelectionRequest:
1429 g_message ("selection request:\twindow: %ld",
1430 xevent->xproperty.window));
1432 event->selection.type = GDK_SELECTION_REQUEST;
1433 event->selection.window = window;
1434 event->selection.selection = gdk_x11_xatom_to_atom (xevent->xselectionrequest.selection);
1435 event->selection.target = gdk_x11_xatom_to_atom (xevent->xselectionrequest.target);
1436 event->selection.property = gdk_x11_xatom_to_atom (xevent->xselectionrequest.property);
1437 event->selection.requestor = xevent->xselectionrequest.requestor;
1438 event->selection.time = xevent->xselectionrequest.time;
1442 case SelectionNotify:
1444 g_message ("selection notify:\twindow: %ld",
1445 xevent->xproperty.window));
1448 event->selection.type = GDK_SELECTION_NOTIFY;
1449 event->selection.window = window;
1450 event->selection.selection = gdk_x11_xatom_to_atom (xevent->xselection.selection);
1451 event->selection.target = gdk_x11_xatom_to_atom (xevent->xselection.target);
1452 event->selection.property = gdk_x11_xatom_to_atom (xevent->xselection.property);
1453 event->selection.time = xevent->xselection.time;
1457 case ColormapNotify:
1459 g_message ("colormap notify:\twindow: %ld",
1460 xevent->xcolormap.window));
1462 /* Not currently handled */
1469 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1470 GdkAtom message_type = gdk_x11_xatom_to_atom (xevent->xclient.message_type);
1473 g_message ("client message:\twindow: %ld",
1474 xevent->xclient.window));
1476 tmp_list = client_filters;
1479 GdkClientFilter *filter = tmp_list->data;
1480 if (filter->type == message_type)
1482 result = (*filter->function) (xevent, event, filter->data);
1486 tmp_list = tmp_list->next;
1491 case GDK_FILTER_REMOVE:
1494 case GDK_FILTER_TRANSLATE:
1497 case GDK_FILTER_CONTINUE:
1498 /* Send unknown ClientMessage's on to Gtk for it to use */
1499 if (window_private == NULL)
1505 event->client.type = GDK_CLIENT_EVENT;
1506 event->client.window = window;
1507 event->client.message_type = message_type;
1508 event->client.data_format = xevent->xclient.format;
1509 memcpy(&event->client.data, &xevent->xclient.data,
1510 sizeof(event->client.data));
1520 g_message ("mapping notify"));
1522 /* Let XLib know that there is a new keyboard mapping.
1524 XRefreshKeyboardMapping (&xevent->xmapping);
1525 ++_gdk_keymap_serial;
1531 if (xevent->type == _gdk_xkb_event_type)
1533 XkbEvent *xkb_event = (XkbEvent *)xevent;
1535 switch (xkb_event->any.xkb_type)
1538 ++_gdk_keymap_serial;
1542 case XkbStateNotify:
1543 _gdk_keymap_state_changed ();
1550 /* something else - (e.g., a Xinput event) */
1552 if (window_private &&
1553 !GDK_WINDOW_DESTROYED (window_private) &&
1554 (window_private->extension_events != 0))
1555 return_val = _gdk_input_other_event(event, xevent, window);
1566 if (event->any.window)
1567 gdk_window_ref (event->any.window);
1568 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1569 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1570 (event->crossing.subwindow != NULL))
1571 gdk_window_ref (event->crossing.subwindow);
1575 /* Mark this event as having no resources to be freed */
1576 event->any.window = NULL;
1577 event->any.type = GDK_NOTHING;
1581 gdk_window_unref (window);
1586 static GdkFilterReturn
1587 gdk_wm_protocols_filter (GdkXEvent *xev,
1591 XEvent *xevent = (XEvent *)xev;
1593 if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name ("WM_DELETE_WINDOW"))
1595 /* The delete window request specifies a window
1596 * to delete. We don't actually destroy the
1597 * window because "it is only a request". (The
1598 * window might contain vital data that the
1599 * program does not want destroyed). Instead
1600 * the event is passed along to the program,
1601 * which should then destroy the window.
1604 g_message ("delete window:\t\twindow: %ld",
1605 xevent->xclient.window));
1607 event->any.type = GDK_DELETE;
1609 return GDK_FILTER_TRANSLATE;
1611 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name ("WM_TAKE_FOCUS"))
1613 GdkWindow *win = event->any.window;
1614 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1616 /* There is no way of knowing reliably whether we are viewable so we need
1617 * to trap errors so we don't cause a BadMatch.
1619 gdk_error_trap_push ();
1620 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1623 xevent->xclient.data.l[1]);
1624 XSync (GDK_WINDOW_XDISPLAY (win), False);
1625 gdk_error_trap_pop ();
1627 else if ((Atom) xevent->xclient.data.l[0] == gdk_x11_get_xatom_by_name ("_NET_WM_PING"))
1629 XEvent xev = *xevent;
1631 xev.xclient.window = _gdk_root_window;
1632 XSendEvent (gdk_display, _gdk_root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1635 return GDK_FILTER_REMOVE;
1640 gdk_event_get_type (Display *display,
1647 if (gdk_event_translate (&event, xevent, FALSE))
1649 pred = (GdkPredicate*) arg;
1650 return (* pred->func) (&event, pred->data);
1658 _gdk_events_queue (void)
1664 while (!_gdk_event_queue_find_first() && XPending (gdk_display))
1666 XNextEvent (gdk_display, &xevent);
1668 switch (xevent.type)
1674 if (XFilterEvent (&xevent, None))
1678 event = _gdk_event_new ();
1680 event->any.type = GDK_NOTHING;
1681 event->any.window = NULL;
1682 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1684 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1686 _gdk_event_queue_append (event);
1687 node = _gdk_queued_tail;
1689 if (gdk_event_translate (event, &xevent, FALSE))
1691 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1695 _gdk_event_queue_remove_link (node);
1696 g_list_free_1 (node);
1697 gdk_event_free (event);
1703 gdk_event_prepare (GSource *source,
1708 GDK_THREADS_ENTER ();
1712 retval = (_gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1714 GDK_THREADS_LEAVE ();
1720 gdk_event_check (GSource *source)
1724 GDK_THREADS_ENTER ();
1726 if (event_poll_fd.revents & G_IO_IN)
1727 retval = (_gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1731 GDK_THREADS_LEAVE ();
1737 gdk_event_dispatch (GSource *source,
1738 GSourceFunc callback,
1743 GDK_THREADS_ENTER ();
1745 _gdk_events_queue();
1746 event = _gdk_event_unqueue();
1750 if (_gdk_event_func)
1751 (*_gdk_event_func) (event, _gdk_event_data);
1753 gdk_event_free (event);
1756 GDK_THREADS_LEAVE ();
1761 /* Sends a ClientMessage to all toplevel client windows */
1763 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1767 g_return_val_if_fail(event != NULL, FALSE);
1769 /* Set up our event to send, with the exception of its target window */
1770 sev.xclient.type = ClientMessage;
1771 sev.xclient.display = gdk_display;
1772 sev.xclient.format = event->client.data_format;
1773 sev.xclient.window = xid;
1774 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1775 sev.xclient.message_type = gdk_x11_atom_to_xatom (event->client.message_type);
1777 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1780 /* Sends a ClientMessage to all toplevel client windows */
1782 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1786 static Atom wm_state_atom = None;
1789 unsigned long nitems, after;
1790 unsigned char *data;
1791 Window *ret_children, ret_root, ret_parent;
1792 unsigned int ret_nchildren;
1793 gint old_warnings = _gdk_error_warnings;
1794 gboolean send = FALSE;
1795 gboolean found = FALSE;
1799 wm_state_atom = gdk_x11_get_xatom_by_name ("WM_STATE");
1801 _gdk_error_warnings = FALSE;
1802 _gdk_error_code = 0;
1803 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1804 &type, &format, &nitems, &after, &data);
1806 if (_gdk_error_code)
1808 _gdk_error_warnings = old_warnings;
1820 /* OK, we're all set, now let's find some windows to send this to */
1821 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1822 &ret_children, &ret_nchildren) != True ||
1825 _gdk_error_warnings = old_warnings;
1830 for(i = 0; i < ret_nchildren; i++)
1831 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1834 XFree (ret_children);
1837 if (send || (!found && (level == 1)))
1839 xev->xclient.window = xid;
1840 gdk_send_xevent (xid, False, NoEventMask, xev);
1843 _gdk_error_warnings = old_warnings;
1845 return (send || found);
1849 gdk_event_send_clientmessage_toall (GdkEvent *event)
1852 gint old_warnings = _gdk_error_warnings;
1854 g_return_if_fail(event != NULL);
1856 /* Set up our event to send, with the exception of its target window */
1857 sev.xclient.type = ClientMessage;
1858 sev.xclient.display = gdk_display;
1859 sev.xclient.format = event->client.data_format;
1860 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1861 sev.xclient.message_type = gdk_x11_atom_to_xatom (event->client.message_type);
1863 gdk_event_send_client_message_to_all_recurse(&sev, _gdk_root_window, 0);
1865 _gdk_error_warnings = old_warnings;
1869 *--------------------------------------------------------------
1872 * Flushes the Xlib output buffer and then waits
1873 * until all requests have been received and processed
1874 * by the X server. The only real use for this function
1875 * is in dealing with XShm.
1883 *--------------------------------------------------------------
1889 XSync (gdk_display, False);
1892 static Atom timestamp_prop_atom = 0;
1895 timestamp_predicate (Display *display,
1899 Window xwindow = GPOINTER_TO_UINT (arg);
1901 if (xevent->type == PropertyNotify &&
1902 xevent->xproperty.window == xwindow &&
1903 xevent->xproperty.atom == timestamp_prop_atom)
1910 * gdk_x11_get_server_time:
1911 * @window: a #GdkWindow, used for communication with the server.
1912 * The window must have GDK_PROPERTY_CHANGE_MASK in its
1913 * events mask or a hang will result.
1915 * Routine to get the current X server time stamp.
1917 * Return value: the time stamp.
1920 gdk_x11_get_server_time (GdkWindow *window)
1927 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1928 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
1930 if (!timestamp_prop_atom)
1931 timestamp_prop_atom = gdk_x11_get_xatom_by_name ("GDK_TIMESTAMP_PROP");
1933 xdisplay = GDK_WINDOW_XDISPLAY (window);
1934 xwindow = GDK_WINDOW_XWINDOW (window);
1936 XChangeProperty (xdisplay, xwindow,
1937 timestamp_prop_atom, timestamp_prop_atom,
1938 8, PropModeReplace, &c, 1);
1940 XIfEvent (xdisplay, &xevent,
1941 timestamp_predicate, GUINT_TO_POINTER(xwindow));
1943 return xevent.xproperty.time;
1948 * gdk_net_wm_supports:
1949 * @property: a property atom
1951 * This function is specific to the X11 backend of GDK, and indicates
1952 * whether the window manager supports a certain hint from the
1953 * Extended Window Manager Hints Specification. You can find this
1954 * specification on http://www.freedesktop.org.
1956 * When using this function, keep in mind that the window manager
1957 * can change over time; so you shouldn't use this function in
1958 * a way that impacts persistent application state. A common bug
1959 * is that your application can start up before the window manager
1960 * does when the user logs in, and before the window manager starts
1961 * gdk_net_wm_supports() will return %FALSE for every property.
1963 * Return value: %TRUE if the window manager supports @property
1966 gdk_net_wm_supports (GdkAtom property)
1968 static Atom wmspec_check_atom = 0;
1969 static Atom wmspec_supported_atom = 0;
1970 static Atom *atoms = NULL;
1971 static gulong n_atoms = 0;
1972 Atom xproperty = gdk_x11_atom_to_xatom (property);
1980 if (wmspec_check_window != None)
1988 if (atoms[i] == xproperty)
2003 /* This function is very slow on every call if you are not running a
2004 * spec-supporting WM. For now not optimized, because it isn't in
2005 * any critical code paths, but if you used it somewhere that had to
2006 * be fast you want to avoid "GTK is slow with old WMs" complaints.
2007 * Probably at that point the function should be changed to query
2008 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
2011 if (wmspec_check_atom == 0)
2012 wmspec_check_atom = gdk_x11_get_xatom_by_name ("_NET_SUPPORTING_WM_CHECK");
2014 if (wmspec_supported_atom == 0)
2015 wmspec_supported_atom = gdk_x11_get_xatom_by_name ("_NET_SUPPORTED");
2017 XGetWindowProperty (gdk_display, _gdk_root_window,
2018 wmspec_check_atom, 0, G_MAXLONG,
2019 False, XA_WINDOW, &type, &format, &nitems,
2020 &bytes_after, (guchar **)&xwindow);
2022 if (type != XA_WINDOW)
2025 gdk_error_trap_push ();
2027 /* Find out if this WM goes away, so we can reset everything. */
2028 XSelectInput (gdk_display, *xwindow,
2029 StructureNotifyMask);
2033 if (gdk_error_trap_pop ())
2039 XGetWindowProperty (gdk_display, _gdk_root_window,
2040 wmspec_supported_atom, 0, G_MAXLONG,
2041 False, XA_ATOM, &type, &format, &n_atoms,
2042 &bytes_after, (guchar **)&atoms);
2044 if (type != XA_ATOM)
2047 wmspec_check_window = *xwindow;
2050 /* since wmspec_check_window != None this isn't infinite. ;-) */
2051 return gdk_net_wm_supports (property);
2056 const char *xsettings_name;
2057 const char *gdk_name;
2058 } settings_map[] = {
2059 { "Net/DoubleClickTime", "gtk-double-click-timeout" },
2060 { "Net/DragThreshold", "gtk-drag-threshold" },
2061 { "Gtk/ColorPalette", "gtk-color-palette" },
2062 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2063 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2064 { "Net/CursorBlink", "gtk-cursor-blink" },
2065 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2066 { "Net/ThemeName", "gtk-theme-name" },
2067 { "Gtk/KeyThemeName", "gtk-key-theme-name" }
2071 gdk_xsettings_notify_cb (const char *name,
2072 XSettingsAction action,
2073 XSettingsSetting *setting,
2079 new_event.type = GDK_SETTING;
2080 new_event.setting.window = NULL;
2081 new_event.setting.send_event = FALSE;
2082 new_event.setting.name = NULL;
2084 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2085 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2087 new_event.setting.name = g_strdup (settings_map[i].gdk_name);
2091 if (!new_event.setting.name)
2096 case XSETTINGS_ACTION_NEW:
2097 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2099 case XSETTINGS_ACTION_CHANGED:
2100 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2102 case XSETTINGS_ACTION_DELETED:
2103 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2107 gdk_event_put (&new_event);
2111 check_transform (const gchar *xsettings_name,
2115 if (!g_value_type_transformable (src_type, dest_type))
2117 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2119 g_type_name (src_type),
2120 g_type_name (dest_type));
2128 gdk_setting_get (const gchar *name,
2131 const char *xsettings_name = NULL;
2132 XSettingsResult result;
2133 XSettingsSetting *setting;
2134 gboolean success = FALSE;
2136 GValue tmp_val = { 0, };
2138 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2139 if (strcmp (settings_map[i].gdk_name, name) == 0)
2141 xsettings_name = settings_map[i].xsettings_name;
2145 if (!xsettings_name)
2148 result = xsettings_client_get_setting (xsettings_client, xsettings_name, &setting);
2149 if (result != XSETTINGS_SUCCESS)
2152 switch (setting->type)
2154 case XSETTINGS_TYPE_INT:
2155 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2157 g_value_init (&tmp_val, G_TYPE_INT);
2158 g_value_set_int (&tmp_val, setting->data.v_int);
2159 g_value_transform (&tmp_val, value);
2164 case XSETTINGS_TYPE_STRING:
2165 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2167 g_value_init (&tmp_val, G_TYPE_STRING);
2168 g_value_set_string (&tmp_val, setting->data.v_string);
2169 g_value_transform (&tmp_val, value);
2174 case XSETTINGS_TYPE_COLOR:
2175 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2179 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2182 color.red = setting->data.v_color.red;
2183 color.green = setting->data.v_color.green;
2184 color.blue = setting->data.v_color.blue;
2186 g_value_set_boxed (&tmp_val, &color);
2188 g_value_transform (&tmp_val, value);
2195 g_value_unset (&tmp_val);
2197 xsettings_setting_free (setting);
2202 static GdkFilterReturn
2203 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2207 if (xsettings_client_process_event (xsettings_client, (XEvent *)xevent))
2208 return GDK_FILTER_REMOVE;
2210 return GDK_FILTER_CONTINUE;
2214 gdk_xsettings_watch_cb (Window window,
2221 gdkwin = gdk_window_lookup (window);
2223 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);
2225 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);