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 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_add_client_message_filter (gdk_wm_protocols,
166 gdk_wm_protocols_filter, NULL);
168 xsettings_client = xsettings_client_new (gdk_display, DefaultScreen (gdk_display),
169 gdk_xsettings_notify_cb,
170 gdk_xsettings_watch_cb,
175 *--------------------------------------------------------------
178 * Returns if events are pending on the queue.
183 * Returns TRUE if events are pending
187 *--------------------------------------------------------------
191 gdk_events_pending (void)
193 return (gdk_event_queue_find_first() || XPending (gdk_display));
197 *--------------------------------------------------------------
198 * gdk_event_get_graphics_expose
200 * Waits for a GraphicsExpose or NoExpose event
205 * For GraphicsExpose events, returns a pointer to the event
206 * converted into a GdkEvent Otherwise, returns NULL.
210 *-------------------------------------------------------------- */
213 graphics_expose_predicate (Display *display,
217 if (xevent->xany.window == GDK_DRAWABLE_XID (arg) &&
218 (xevent->xany.type == GraphicsExpose ||
219 xevent->xany.type == NoExpose))
226 gdk_event_get_graphics_expose (GdkWindow *window)
231 g_return_val_if_fail (window != NULL, NULL);
233 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
235 if (xevent.xany.type == GraphicsExpose)
237 event = gdk_event_new ();
239 if (gdk_event_translate (event, &xevent, TRUE))
242 gdk_event_free (event);
249 gdk_event_apply_filters (XEvent *xevent,
254 GdkFilterReturn result;
260 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
262 tmp_list = tmp_list->next;
263 result = filter->function (xevent, event, filter->data);
264 if (result != GDK_FILTER_CONTINUE)
268 return GDK_FILTER_CONTINUE;
272 gdk_add_client_message_filter (GdkAtom message_type,
276 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
278 filter->type = message_type;
279 filter->function = func;
282 client_filters = g_list_prepend (client_filters, filter);
285 static GdkAtom wm_state_atom = 0;
286 static GdkAtom wm_desktop_atom = 0;
289 gdk_check_wm_state_changed (GdkWindow *window)
295 GdkAtom *atoms = NULL;
298 GdkAtom maxvert_atom;
299 GdkAtom maxhorz_atom;
300 gboolean found_sticky, found_maxvert, found_maxhorz;
301 GdkWindowState old_state;
303 if (GDK_WINDOW_DESTROYED (window))
306 if (wm_state_atom == 0)
307 wm_state_atom = gdk_atom_intern ("_NET_WM_STATE", FALSE);
309 if (wm_desktop_atom == 0)
310 wm_desktop_atom = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
312 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
313 wm_state_atom, 0, G_MAXLONG,
314 False, XA_ATOM, &type, &format, &nitems,
315 &bytes_after, (guchar **)&atoms);
320 sticky_atom = gdk_atom_intern ("_NET_WM_STATE_STICKY", FALSE);
321 maxvert_atom = gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_VERT", FALSE);
322 maxhorz_atom = gdk_atom_intern ("_NET_WM_STATE_MAXIMIZED_HORZ", FALSE);
324 found_sticky = FALSE;
325 found_maxvert = FALSE;
326 found_maxhorz = FALSE;
331 if (atoms[i] == sticky_atom)
333 else if (atoms[i] == maxvert_atom)
334 found_maxvert = TRUE;
335 else if (atoms[i] == maxhorz_atom)
336 found_maxhorz = TRUE;
345 found_sticky = FALSE;
346 found_maxvert = FALSE;
347 found_maxhorz = FALSE;
350 /* For found_sticky to remain TRUE, we have to also be on desktop
358 XGetWindowProperty (GDK_WINDOW_XDISPLAY (window), GDK_WINDOW_XID (window),
359 wm_desktop_atom, 0, G_MAXLONG,
360 False, XA_CARDINAL, &type, &format, &nitems,
361 &bytes_after, (guchar **)&desktop);
365 if (*desktop != 0xFFFFFFFF)
366 found_sticky = FALSE;
371 old_state = gdk_window_get_state (window);
373 if (old_state & GDK_WINDOW_STATE_STICKY)
376 gdk_synthesize_window_state (window,
377 GDK_WINDOW_STATE_STICKY,
383 gdk_synthesize_window_state (window,
385 GDK_WINDOW_STATE_STICKY);
388 /* Our "maximized" means both vertical and horizontal; if only one,
389 * we don't expose that via GDK
391 if (old_state & GDK_WINDOW_STATE_MAXIMIZED)
393 if (!(found_maxvert && found_maxhorz))
394 gdk_synthesize_window_state (window,
395 GDK_WINDOW_STATE_MAXIMIZED,
400 if (found_maxvert && found_maxhorz)
401 gdk_synthesize_window_state (window,
403 GDK_WINDOW_STATE_MAXIMIZED);
407 #define HAS_FOCUS(window_impl) \
408 ((window_impl)->has_focus || (window_impl)->has_pointer_focus)
411 generate_focus_event (GdkWindow *window,
416 event.type = GDK_FOCUS_CHANGE;
417 event.focus_change.window = window;
418 event.focus_change.send_event = FALSE;
419 event.focus_change.in = in;
421 gdk_event_put (&event);
425 gdk_event_translate (GdkEvent *event,
427 gboolean return_exposes)
431 GdkWindowObject *window_private;
432 GdkWindowImplX11 *window_impl = NULL;
433 static XComposeStatus compose;
438 gint xoffset, yoffset;
442 /* init these, since the done: block uses them */
444 window_private = NULL;
445 event->any.window = NULL;
447 if (gdk_default_filters)
449 /* Apply global filters */
450 GdkFilterReturn result;
451 result = gdk_event_apply_filters (xevent, event,
452 gdk_default_filters);
454 if (result != GDK_FILTER_CONTINUE)
456 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
461 /* We handle events with window=None
462 * specially - they are generated by XFree86's XInput under
463 * some circumstances. This handling for obvious reasons
464 * goes before we bother to lookup the event window.
467 if (xevent->xany.window == None)
469 return_val = _gdk_input_window_none_event (event, xevent);
471 if (return_val >= 0) /* was handled */
477 /* Find the GdkWindow that this event occurred in. */
479 window = gdk_window_lookup (xevent->xany.window);
480 window_private = (GdkWindowObject *) window;
484 /* Window may be a pixmap, so check its type.
485 * (This check is probably too expensive unless
486 * GLib short-circuits an exact type match,
487 * which has been proposed)
489 if (GDK_IS_WINDOW (window))
491 window_impl = GDK_WINDOW_IMPL_X11 (window_private->impl);
493 if (xevent->xany.window != GDK_WINDOW_XID (window))
495 g_assert (xevent->xany.window == window_impl->focus_window);
497 switch (xevent->type)
501 xevent->xany.window = GDK_WINDOW_XID (window);
509 g_object_ref (G_OBJECT (window));
512 event->any.window = window;
513 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
515 if (window_private && GDK_WINDOW_DESTROYED (window))
517 if (xevent->type != DestroyNotify)
520 else if (window_private)
522 /* Apply per-window filters */
523 GdkFilterReturn result;
524 result = gdk_event_apply_filters (xevent, event,
525 window_private->filters);
527 if (result != GDK_FILTER_CONTINUE)
529 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
534 if (wmspec_check_window != None &&
535 xevent->xany.window == wmspec_check_window)
537 if (xevent->type == DestroyNotify)
538 wmspec_check_window = None;
540 /* Eat events on this window unless someone had wrapped
541 * it as a foreign window
548 _gdk_moveresize_window &&
549 (xevent->xany.type == MotionNotify ||
550 xevent->xany.type == ButtonRelease))
552 _gdk_moveresize_handle_event (xevent);
553 gdk_window_unref (window);
557 /* We do a "manual" conversion of the XEvent to a
558 * GdkEvent. The structures are mostly the same so
559 * the conversion is fairly straightforward. We also
560 * optionally print debugging info regarding events
568 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
576 switch (xevent->type)
579 if (window_private == NULL)
585 /* Lookup the string corresponding to the given keysym.
588 charcount = XLookupString (&xevent->xkey, buf, 16,
590 event->key.keyval = keysym;
591 event->key.hardware_keycode = xevent->xkey.keycode;
593 if (charcount > 0 && buf[charcount-1] == '\0')
596 buf[charcount] = '\0';
598 #ifdef G_ENABLE_DEBUG
599 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
601 g_message ("key press:\twindow: %ld key: %12s %d",
603 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
606 g_message ("\t\tlength: %4d string: \"%s\"",
609 #endif /* G_ENABLE_DEBUG */
611 /* bits 13 and 14 in the "state" field are the keyboard group */
612 #define KEYBOARD_GROUP_SHIFT 13
613 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
615 event->key.type = GDK_KEY_PRESS;
616 event->key.window = window;
617 event->key.time = xevent->xkey.time;
618 event->key.state = (GdkModifierType) xevent->xkey.state;
619 event->key.string = g_strdup (buf);
620 event->key.length = charcount;
622 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
627 if (window_private == NULL)
633 /* Lookup the string corresponding to the given keysym.
636 /* Emulate detectable auto-repeat by checking to see
637 * if the next event is a key press with the same
638 * keycode and timestamp, and if so, ignoring the event.
641 if (!_gdk_have_xkb_autorepeat && XPending (gdk_display))
645 XPeekEvent (gdk_display, &next_event);
647 if (next_event.type == KeyPress &&
648 next_event.xkey.keycode == xevent->xkey.keycode &&
649 next_event.xkey.time == xevent->xkey.time)
653 keysym = GDK_VoidSymbol;
654 charcount = XLookupString (&xevent->xkey, buf, 16,
656 event->key.keyval = keysym;
659 g_message ("key release:\t\twindow: %ld key: %12s %d",
661 XKeysymToString (event->key.keyval),
664 event->key.type = GDK_KEY_RELEASE;
665 event->key.window = window;
666 event->key.time = xevent->xkey.time;
667 event->key.state = (GdkModifierType) xevent->xkey.state;
668 event->key.length = 0;
669 event->key.string = NULL;
675 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
676 xevent->xbutton.window,
677 xevent->xbutton.x, xevent->xbutton.y,
678 xevent->xbutton.button));
680 if (window_private == NULL ||
681 ((window_private->extension_events != 0) &&
682 gdk_input_ignore_core))
688 /* If we get a ButtonPress event where the button is 4 or 5,
689 it's a Scroll event */
690 switch (xevent->xbutton.button)
696 event->scroll.type = GDK_SCROLL;
698 if (xevent->xbutton.button == 4)
699 event->scroll.direction = GDK_SCROLL_UP;
700 else if (xevent->xbutton.button == 5)
701 event->scroll.direction = GDK_SCROLL_DOWN;
702 else if (xevent->xbutton.button == 6)
703 event->scroll.direction = GDK_SCROLL_LEFT;
705 event->scroll.direction = GDK_SCROLL_RIGHT;
707 event->scroll.window = window;
708 event->scroll.time = xevent->xbutton.x;
709 event->scroll.x = xevent->xbutton.x + xoffset;
710 event->scroll.y = xevent->xbutton.y + yoffset;
711 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
712 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
713 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
714 event->scroll.device = gdk_core_pointer;
718 event->button.type = GDK_BUTTON_PRESS;
719 event->button.window = window;
720 event->button.time = xevent->xbutton.time;
721 event->button.x = xevent->xbutton.x + xoffset;
722 event->button.y = xevent->xbutton.y + yoffset;
723 event->button.x_root = (gfloat)xevent->xbutton.x_root;
724 event->button.y_root = (gfloat)xevent->xbutton.y_root;
725 event->button.axes = NULL;
726 event->button.state = (GdkModifierType) xevent->xbutton.state;
727 event->button.button = xevent->xbutton.button;
728 event->button.device = gdk_core_pointer;
730 gdk_event_button_generate (event);
738 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
739 xevent->xbutton.window,
740 xevent->xbutton.x, xevent->xbutton.y,
741 xevent->xbutton.button));
743 if (window_private == NULL ||
744 ((window_private->extension_events != 0) &&
745 gdk_input_ignore_core))
751 /* We treat button presses as scroll wheel events, so ignore the release */
752 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
753 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
759 event->button.type = GDK_BUTTON_RELEASE;
760 event->button.window = window;
761 event->button.time = xevent->xbutton.time;
762 event->button.x = xevent->xbutton.x + xoffset;
763 event->button.y = xevent->xbutton.y + yoffset;
764 event->button.x_root = (gfloat)xevent->xbutton.x_root;
765 event->button.y_root = (gfloat)xevent->xbutton.y_root;
766 event->button.axes = NULL;
767 event->button.state = (GdkModifierType) xevent->xbutton.state;
768 event->button.button = xevent->xbutton.button;
769 event->button.device = gdk_core_pointer;
775 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
776 xevent->xmotion.window,
777 xevent->xmotion.x, xevent->xmotion.y,
778 (xevent->xmotion.is_hint) ? "true" : "false"));
780 if (window_private == NULL ||
781 ((window_private->extension_events != 0) &&
782 gdk_input_ignore_core))
788 event->motion.type = GDK_MOTION_NOTIFY;
789 event->motion.window = window;
790 event->motion.time = xevent->xmotion.time;
791 event->motion.x = xevent->xmotion.x + xoffset;
792 event->motion.y = xevent->xmotion.y + yoffset;
793 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
794 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
795 event->motion.axes = NULL;
796 event->motion.state = (GdkModifierType) xevent->xmotion.state;
797 event->motion.is_hint = xevent->xmotion.is_hint;
798 event->motion.device = gdk_core_pointer;
804 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
805 xevent->xcrossing.window,
806 xevent->xcrossing.detail,
807 xevent->xcrossing.subwindow));
809 if (window_private == NULL)
815 /* Handle focusing (in the case where no window manager is running */
817 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
818 xevent->xcrossing.detail != NotifyInferior &&
819 xevent->xcrossing.focus && !window_impl->has_focus)
821 gboolean had_focus = HAS_FOCUS (window_impl);
823 window_impl->has_pointer_focus = TRUE;
825 if (HAS_FOCUS (window_impl) != had_focus)
826 generate_focus_event (window, TRUE);
829 /* Tell XInput stuff about it if appropriate */
830 if (window_private &&
831 !GDK_WINDOW_DESTROYED (window) &&
832 window_private->extension_events != 0)
833 _gdk_input_enter_event (&xevent->xcrossing, window);
835 event->crossing.type = GDK_ENTER_NOTIFY;
836 event->crossing.window = window;
838 /* If the subwindow field of the XEvent is non-NULL, then
839 * lookup the corresponding GdkWindow.
841 if (xevent->xcrossing.subwindow != None)
842 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
844 event->crossing.subwindow = NULL;
846 event->crossing.time = xevent->xcrossing.time;
847 event->crossing.x = xevent->xcrossing.x + xoffset;
848 event->crossing.y = xevent->xcrossing.y + yoffset;
849 event->crossing.x_root = xevent->xcrossing.x_root;
850 event->crossing.y_root = xevent->xcrossing.y_root;
852 /* Translate the crossing mode into Gdk terms.
854 switch (xevent->xcrossing.mode)
857 event->crossing.mode = GDK_CROSSING_NORMAL;
860 event->crossing.mode = GDK_CROSSING_GRAB;
863 event->crossing.mode = GDK_CROSSING_UNGRAB;
867 /* Translate the crossing detail into Gdk terms.
869 switch (xevent->xcrossing.detail)
872 event->crossing.detail = GDK_NOTIFY_INFERIOR;
875 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
878 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
880 case NotifyNonlinear:
881 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
883 case NotifyNonlinearVirtual:
884 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
887 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
891 event->crossing.focus = xevent->xcrossing.focus;
892 event->crossing.state = xevent->xcrossing.state;
898 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
899 xevent->xcrossing.window,
900 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
902 if (window_private == NULL)
908 /* Handle focusing (in the case where no window manager is running */
910 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
911 xevent->xcrossing.detail != NotifyInferior &&
912 xevent->xcrossing.focus && !window_impl->has_focus)
914 gboolean had_focus = HAS_FOCUS (window_impl);
916 window_impl->has_pointer_focus = FALSE;
918 if (HAS_FOCUS (window_impl) != had_focus)
919 generate_focus_event (window, FALSE);
922 event->crossing.type = GDK_LEAVE_NOTIFY;
923 event->crossing.window = window;
925 /* If the subwindow field of the XEvent is non-NULL, then
926 * lookup the corresponding GdkWindow.
928 if (xevent->xcrossing.subwindow != None)
929 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
931 event->crossing.subwindow = NULL;
933 event->crossing.time = xevent->xcrossing.time;
934 event->crossing.x = xevent->xcrossing.x + xoffset;
935 event->crossing.y = xevent->xcrossing.y + yoffset;
936 event->crossing.x_root = xevent->xcrossing.x_root;
937 event->crossing.y_root = xevent->xcrossing.y_root;
939 /* Translate the crossing mode into Gdk terms.
941 switch (xevent->xcrossing.mode)
944 event->crossing.mode = GDK_CROSSING_NORMAL;
947 event->crossing.mode = GDK_CROSSING_GRAB;
950 event->crossing.mode = GDK_CROSSING_UNGRAB;
954 /* Translate the crossing detail into Gdk terms.
956 switch (xevent->xcrossing.detail)
959 event->crossing.detail = GDK_NOTIFY_INFERIOR;
962 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
965 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
967 case NotifyNonlinear:
968 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
970 case NotifyNonlinearVirtual:
971 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
974 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
978 event->crossing.focus = xevent->xcrossing.focus;
979 event->crossing.state = xevent->xcrossing.state;
983 /* We only care about focus events that indicate that _this_
984 * window (not a ancestor or child) got or lost the focus
988 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
990 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
992 gboolean had_focus = HAS_FOCUS (window_impl);
994 switch (xevent->xfocus.detail)
997 case NotifyNonlinear:
999 case NotifyNonlinearVirtual:
1000 window_impl->has_focus = TRUE;
1003 window_impl->has_pointer_focus = TRUE;
1005 case NotifyInferior:
1006 case NotifyPointerRoot:
1007 case NotifyDetailNone:
1011 if (HAS_FOCUS (window_impl) != had_focus)
1012 generate_focus_event (window, TRUE);
1017 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1019 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1021 gboolean had_focus = HAS_FOCUS (window_impl);
1023 switch (xevent->xfocus.detail)
1025 case NotifyAncestor:
1026 case NotifyNonlinear:
1028 case NotifyNonlinearVirtual:
1029 window_impl->has_focus = FALSE;
1032 window_impl->has_pointer_focus = FALSE;
1034 case NotifyInferior:
1035 case NotifyPointerRoot:
1036 case NotifyDetailNone:
1040 if (HAS_FOCUS (window_impl) != had_focus)
1041 generate_focus_event (window, FALSE);
1046 /* gdk_keyboard_grab() causes following events. These events confuse
1047 * the XIM focus, so ignore them.
1049 if (xevent->xfocus.mode == NotifyGrab ||
1050 xevent->xfocus.mode == NotifyUngrab)
1056 g_message ("keymap notify"));
1058 /* Not currently handled */
1064 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1065 xevent->xexpose.window, xevent->xexpose.count,
1066 xevent->xexpose.x, xevent->xexpose.y,
1067 xevent->xexpose.width, xevent->xexpose.height,
1068 event->any.send_event ? " (send)" : ""));
1070 if (window_private == NULL)
1077 GdkRectangle expose_rect;
1079 expose_rect.x = xevent->xexpose.x + xoffset;
1080 expose_rect.y = xevent->xexpose.y + yoffset;
1081 expose_rect.width = xevent->xexpose.width;
1082 expose_rect.height = xevent->xexpose.height;
1086 event->expose.type = GDK_EXPOSE;
1087 event->expose.area = expose_rect;
1088 event->expose.region = gdk_region_rectangle (&expose_rect);
1089 event->expose.window = window;
1090 event->expose.count = xevent->xexpose.count;
1096 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1106 case GraphicsExpose:
1108 GdkRectangle expose_rect;
1111 g_message ("graphics expose:\tdrawable: %ld",
1112 xevent->xgraphicsexpose.drawable));
1114 if (window_private == NULL)
1120 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1121 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1122 expose_rect.width = xevent->xgraphicsexpose.width;
1123 expose_rect.height = xevent->xgraphicsexpose.height;
1127 event->expose.type = GDK_EXPOSE;
1128 event->expose.area = expose_rect;
1129 event->expose.region = gdk_region_rectangle (&expose_rect);
1130 event->expose.window = window;
1131 event->expose.count = xevent->xgraphicsexpose.count;
1137 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1147 g_message ("no expose:\t\tdrawable: %ld",
1148 xevent->xnoexpose.drawable));
1150 event->no_expose.type = GDK_NO_EXPOSE;
1151 event->no_expose.window = window;
1155 case VisibilityNotify:
1156 #ifdef G_ENABLE_DEBUG
1157 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
1158 switch (xevent->xvisibility.state)
1160 case VisibilityFullyObscured:
1161 g_message ("visibility notify:\twindow: %ld none",
1162 xevent->xvisibility.window);
1164 case VisibilityPartiallyObscured:
1165 g_message ("visibility notify:\twindow: %ld partial",
1166 xevent->xvisibility.window);
1168 case VisibilityUnobscured:
1169 g_message ("visibility notify:\twindow: %ld full",
1170 xevent->xvisibility.window);
1173 #endif /* G_ENABLE_DEBUG */
1175 if (window_private == NULL)
1181 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1182 event->visibility.window = window;
1184 switch (xevent->xvisibility.state)
1186 case VisibilityFullyObscured:
1187 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1190 case VisibilityPartiallyObscured:
1191 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1194 case VisibilityUnobscured:
1195 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1203 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1204 xevent->xcreatewindow.window,
1205 xevent->xcreatewindow.x,
1206 xevent->xcreatewindow.y,
1207 xevent->xcreatewindow.width,
1208 xevent->xcreatewindow.height,
1209 xevent->xcreatewindow.border_width,
1210 xevent->xcreatewindow.parent,
1211 xevent->xcreatewindow.override_redirect));
1212 /* not really handled */
1217 g_message ("destroy notify:\twindow: %ld",
1218 xevent->xdestroywindow.window));
1220 event->any.type = GDK_DESTROY;
1221 event->any.window = window;
1223 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1225 if (window && GDK_WINDOW_XID (window) != GDK_ROOT_WINDOW())
1226 gdk_window_destroy_notify (window);
1231 g_message ("unmap notify:\t\twindow: %ld",
1232 xevent->xmap.window));
1234 event->any.type = GDK_UNMAP;
1235 event->any.window = window;
1237 /* If we are shown (not withdrawn) and get an unmap, it means we
1238 * were iconified in the X sense. If we are withdrawn, and get
1239 * an unmap, it means we hid the window ourselves, so we
1240 * will have already flipped the iconified bit off.
1242 if (window && GDK_WINDOW_IS_MAPPED (window))
1243 gdk_synthesize_window_state (window,
1245 GDK_WINDOW_STATE_ICONIFIED);
1247 if (gdk_xgrab_window == window_private)
1248 gdk_xgrab_window = NULL;
1254 g_message ("map notify:\t\twindow: %ld",
1255 xevent->xmap.window));
1257 event->any.type = GDK_MAP;
1258 event->any.window = window;
1260 /* Unset iconified if it was set */
1261 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1262 gdk_synthesize_window_state (window,
1263 GDK_WINDOW_STATE_ICONIFIED,
1268 case ReparentNotify:
1270 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1271 xevent->xreparent.window,
1272 xevent->xreparent.x,
1273 xevent->xreparent.y,
1274 xevent->xreparent.parent,
1275 xevent->xreparent.override_redirect));
1277 /* Not currently handled */
1281 case ConfigureNotify:
1283 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1284 xevent->xconfigure.window,
1285 xevent->xconfigure.x,
1286 xevent->xconfigure.y,
1287 xevent->xconfigure.width,
1288 xevent->xconfigure.height,
1289 xevent->xconfigure.border_width,
1290 xevent->xconfigure.above,
1291 xevent->xconfigure.override_redirect,
1294 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1295 ? " (discarding child)"
1298 !GDK_WINDOW_DESTROYED (window) &&
1299 (window_private->extension_events != 0))
1300 _gdk_input_configure_event (&xevent->xconfigure, window);
1302 if (!window || GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1306 event->configure.type = GDK_CONFIGURE;
1307 event->configure.window = window;
1308 event->configure.width = xevent->xconfigure.width;
1309 event->configure.height = xevent->xconfigure.height;
1311 if (!xevent->xconfigure.x &&
1312 !xevent->xconfigure.y &&
1313 !GDK_WINDOW_DESTROYED (window))
1317 Window child_window = 0;
1319 gdk_error_trap_push ();
1320 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1321 GDK_DRAWABLE_XID (window),
1327 if (!gdk_error_trap_pop ())
1329 event->configure.x = tx;
1330 event->configure.y = ty;
1334 gdk_error_trap_pop ();
1338 event->configure.x = xevent->xconfigure.x;
1339 event->configure.y = xevent->xconfigure.y;
1341 window_private->x = event->configure.x;
1342 window_private->y = event->configure.y;
1343 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1344 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1345 if (window_private->resize_count >= 1)
1347 window_private->resize_count -= 1;
1349 if (window_private->resize_count == 0 &&
1350 window == _gdk_moveresize_window)
1351 _gdk_moveresize_configure_done ();
1356 case PropertyNotify:
1358 gchar *atom = gdk_atom_name (xevent->xproperty.atom);
1359 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1360 xevent->xproperty.window,
1361 xevent->xproperty.atom,
1363 atom ? atom : "unknown",
1368 if (window_private == NULL)
1374 event->property.type = GDK_PROPERTY_NOTIFY;
1375 event->property.window = window;
1376 event->property.atom = xevent->xproperty.atom;
1377 event->property.time = xevent->xproperty.time;
1378 event->property.state = xevent->xproperty.state;
1380 if (wm_state_atom == 0)
1381 wm_state_atom = gdk_atom_intern ("_NET_WM_STATE", FALSE);
1383 if (wm_desktop_atom == 0)
1384 wm_desktop_atom = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
1386 if (event->property.atom == wm_state_atom ||
1387 event->property.atom == wm_desktop_atom)
1389 /* If window state changed, then synthesize those events. */
1390 gdk_check_wm_state_changed (event->property.window);
1395 case SelectionClear:
1397 g_message ("selection clear:\twindow: %ld",
1398 xevent->xproperty.window));
1400 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1402 event->selection.type = GDK_SELECTION_CLEAR;
1403 event->selection.window = window;
1404 event->selection.selection = xevent->xselectionclear.selection;
1405 event->selection.time = xevent->xselectionclear.time;
1412 case SelectionRequest:
1414 g_message ("selection request:\twindow: %ld",
1415 xevent->xproperty.window));
1417 event->selection.type = GDK_SELECTION_REQUEST;
1418 event->selection.window = window;
1419 event->selection.selection = xevent->xselectionrequest.selection;
1420 event->selection.target = xevent->xselectionrequest.target;
1421 event->selection.property = xevent->xselectionrequest.property;
1422 event->selection.requestor = xevent->xselectionrequest.requestor;
1423 event->selection.time = xevent->xselectionrequest.time;
1427 case SelectionNotify:
1429 g_message ("selection notify:\twindow: %ld",
1430 xevent->xproperty.window));
1433 event->selection.type = GDK_SELECTION_NOTIFY;
1434 event->selection.window = window;
1435 event->selection.selection = xevent->xselection.selection;
1436 event->selection.target = xevent->xselection.target;
1437 event->selection.property = xevent->xselection.property;
1438 event->selection.time = xevent->xselection.time;
1442 case ColormapNotify:
1444 g_message ("colormap notify:\twindow: %ld",
1445 xevent->xcolormap.window));
1447 /* Not currently handled */
1454 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1457 g_message ("client message:\twindow: %ld",
1458 xevent->xclient.window));
1460 tmp_list = client_filters;
1463 GdkClientFilter *filter = tmp_list->data;
1464 if (filter->type == xevent->xclient.message_type)
1466 result = (*filter->function) (xevent, event, filter->data);
1470 tmp_list = tmp_list->next;
1475 case GDK_FILTER_REMOVE:
1478 case GDK_FILTER_TRANSLATE:
1481 case GDK_FILTER_CONTINUE:
1482 /* Send unknown ClientMessage's on to Gtk for it to use */
1483 if (window_private == NULL)
1489 event->client.type = GDK_CLIENT_EVENT;
1490 event->client.window = window;
1491 event->client.message_type = xevent->xclient.message_type;
1492 event->client.data_format = xevent->xclient.format;
1493 memcpy(&event->client.data, &xevent->xclient.data,
1494 sizeof(event->client.data));
1504 g_message ("mapping notify"));
1506 /* Let XLib know that there is a new keyboard mapping.
1508 XRefreshKeyboardMapping (&xevent->xmapping);
1509 ++_gdk_keymap_serial;
1515 if (xevent->type == _gdk_xkb_event_type)
1517 XkbEvent *xkb_event = (XkbEvent *)xevent;
1519 switch (xkb_event->any.xkb_type)
1522 ++_gdk_keymap_serial;
1526 case XkbStateNotify:
1527 _gdk_keymap_state_changed ();
1534 /* something else - (e.g., a Xinput event) */
1536 if (window_private &&
1537 !GDK_WINDOW_DESTROYED (window_private) &&
1538 (window_private->extension_events != 0))
1539 return_val = _gdk_input_other_event(event, xevent, window);
1550 if (event->any.window)
1551 gdk_window_ref (event->any.window);
1552 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1553 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1554 (event->crossing.subwindow != NULL))
1555 gdk_window_ref (event->crossing.subwindow);
1559 /* Mark this event as having no resources to be freed */
1560 event->any.window = NULL;
1561 event->any.type = GDK_NOTHING;
1565 gdk_window_unref (window);
1571 gdk_wm_protocols_filter (GdkXEvent *xev,
1575 XEvent *xevent = (XEvent *)xev;
1577 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1579 /* The delete window request specifies a window
1580 * to delete. We don't actually destroy the
1581 * window because "it is only a request". (The
1582 * window might contain vital data that the
1583 * program does not want destroyed). Instead
1584 * the event is passed along to the program,
1585 * which should then destroy the window.
1588 g_message ("delete window:\t\twindow: %ld",
1589 xevent->xclient.window));
1591 event->any.type = GDK_DELETE;
1593 return GDK_FILTER_TRANSLATE;
1595 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1597 GdkWindow *win = event->any.window;
1598 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1600 /* There is no way of knowing reliably whether we are viewable so we need
1601 * to trap errors so we don't cause a BadMatch.
1603 gdk_error_trap_push ();
1604 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1607 xevent->xclient.data.l[1]);
1608 XSync (GDK_WINDOW_XDISPLAY (win), False);
1609 gdk_error_trap_pop ();
1611 else if ((Atom) xevent->xclient.data.l[0] == gdk_atom_intern ("_NET_WM_PING", FALSE))
1613 XEvent xev = *xevent;
1615 xev.xclient.window = gdk_root_window;
1616 XSendEvent (gdk_display, gdk_root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1619 return GDK_FILTER_REMOVE;
1624 gdk_event_get_type (Display *display,
1631 if (gdk_event_translate (&event, xevent, FALSE))
1633 pred = (GdkPredicate*) arg;
1634 return (* pred->func) (&event, pred->data);
1642 gdk_events_queue (void)
1648 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1650 XNextEvent (gdk_display, &xevent);
1652 switch (xevent.type)
1658 if (XFilterEvent (&xevent, None))
1662 event = gdk_event_new ();
1664 event->any.type = GDK_NOTHING;
1665 event->any.window = NULL;
1666 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1668 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1670 gdk_event_queue_append (event);
1671 node = gdk_queued_tail;
1673 if (gdk_event_translate (event, &xevent, FALSE))
1675 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1679 gdk_event_queue_remove_link (node);
1680 g_list_free_1 (node);
1681 gdk_event_free (event);
1687 gdk_event_prepare (GSource *source,
1692 GDK_THREADS_ENTER ();
1696 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1698 GDK_THREADS_LEAVE ();
1704 gdk_event_check (GSource *source)
1708 GDK_THREADS_ENTER ();
1710 if (event_poll_fd.revents & G_IO_IN)
1711 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1715 GDK_THREADS_LEAVE ();
1721 gdk_event_dispatch (GSource *source,
1722 GSourceFunc callback,
1727 GDK_THREADS_ENTER ();
1730 event = gdk_event_unqueue();
1735 (*gdk_event_func) (event, gdk_event_data);
1737 gdk_event_free (event);
1740 GDK_THREADS_LEAVE ();
1745 /* Sends a ClientMessage to all toplevel client windows */
1747 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1751 g_return_val_if_fail(event != NULL, FALSE);
1753 /* Set up our event to send, with the exception of its target window */
1754 sev.xclient.type = ClientMessage;
1755 sev.xclient.display = gdk_display;
1756 sev.xclient.format = event->client.data_format;
1757 sev.xclient.window = xid;
1758 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1759 sev.xclient.message_type = event->client.message_type;
1761 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1764 /* Sends a ClientMessage to all toplevel client windows */
1766 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1770 static GdkAtom wm_state_atom = GDK_NONE;
1773 unsigned long nitems, after;
1774 unsigned char *data;
1775 Window *ret_children, ret_root, ret_parent;
1776 unsigned int ret_nchildren;
1777 gint old_warnings = gdk_error_warnings;
1778 gboolean send = FALSE;
1779 gboolean found = FALSE;
1783 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
1785 gdk_error_warnings = FALSE;
1787 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1788 &type, &format, &nitems, &after, &data);
1792 gdk_error_warnings = old_warnings;
1804 /* OK, we're all set, now let's find some windows to send this to */
1805 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1806 &ret_children, &ret_nchildren) != True ||
1809 gdk_error_warnings = old_warnings;
1814 for(i = 0; i < ret_nchildren; i++)
1815 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1818 XFree (ret_children);
1821 if (send || (!found && (level == 1)))
1823 xev->xclient.window = xid;
1824 gdk_send_xevent (xid, False, NoEventMask, xev);
1827 gdk_error_warnings = old_warnings;
1829 return (send || found);
1833 gdk_event_send_clientmessage_toall (GdkEvent *event)
1836 gint old_warnings = gdk_error_warnings;
1838 g_return_if_fail(event != NULL);
1840 /* Set up our event to send, with the exception of its target window */
1841 sev.xclient.type = ClientMessage;
1842 sev.xclient.display = gdk_display;
1843 sev.xclient.format = event->client.data_format;
1844 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1845 sev.xclient.message_type = event->client.message_type;
1847 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
1849 gdk_error_warnings = old_warnings;
1853 *--------------------------------------------------------------
1856 * Flushes the Xlib output buffer and then waits
1857 * until all requests have been received and processed
1858 * by the X server. The only real use for this function
1859 * is in dealing with XShm.
1867 *--------------------------------------------------------------
1873 XSync (gdk_display, False);
1876 static GdkAtom timestamp_prop_atom = 0;
1879 timestamp_predicate (Display *display,
1883 Window xwindow = GPOINTER_TO_UINT (arg);
1885 if (xevent->type == PropertyNotify &&
1886 xevent->xproperty.window == xwindow &&
1887 xevent->xproperty.atom == timestamp_prop_atom)
1894 * gdk_x11_get_server_time:
1895 * @window: a #GdkWindow, used for communication with the server.
1896 * The window must have GDK_PROPERTY_CHANGE_MASK in its
1897 * events mask or a hang will result.
1899 * Routine to get the current X server time stamp.
1901 * Return value: the time stamp.
1904 gdk_x11_get_server_time (GdkWindow *window)
1911 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1912 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
1914 if (!timestamp_prop_atom)
1915 timestamp_prop_atom = gdk_atom_intern ("GDK_TIMESTAMP_PROP", FALSE);
1917 xdisplay = GDK_WINDOW_XDISPLAY (window);
1918 xwindow = GDK_WINDOW_XWINDOW (window);
1920 XChangeProperty (xdisplay, xwindow,
1921 timestamp_prop_atom, timestamp_prop_atom,
1922 8, PropModeReplace, &c, 1);
1924 XIfEvent (xdisplay, &xevent,
1925 timestamp_predicate, GUINT_TO_POINTER(xwindow));
1927 return xevent.xproperty.time;
1932 gdk_net_wm_supports (GdkAtom property)
1934 static GdkAtom wmspec_check_atom = 0;
1935 static GdkAtom wmspec_supported_atom = 0;
1936 static GdkAtom *atoms = NULL;
1937 static gulong n_atoms = 0;
1945 if (wmspec_check_window != None)
1953 if (atoms[i] == property)
1968 /* This function is very slow on every call if you are not running a
1969 * spec-supporting WM. For now not optimized, because it isn't in
1970 * any critical code paths, but if you used it somewhere that had to
1971 * be fast you want to avoid "GTK is slow with old WMs" complaints.
1972 * Probably at that point the function should be changed to query
1973 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
1976 if (wmspec_check_atom == 0)
1977 wmspec_check_atom = gdk_atom_intern ("_NET_SUPPORTING_WM_CHECK", FALSE);
1979 if (wmspec_supported_atom == 0)
1980 wmspec_supported_atom = gdk_atom_intern ("_NET_SUPPORTED", FALSE);
1982 XGetWindowProperty (gdk_display, gdk_root_window,
1983 wmspec_check_atom, 0, G_MAXLONG,
1984 False, XA_WINDOW, &type, &format, &nitems,
1985 &bytes_after, (guchar **)&xwindow);
1987 if (type != XA_WINDOW)
1990 gdk_error_trap_push ();
1992 /* Find out if this WM goes away, so we can reset everything. */
1993 XSelectInput (gdk_display, *xwindow,
1994 StructureNotifyMask);
1998 if (gdk_error_trap_pop ())
2004 XGetWindowProperty (gdk_display, gdk_root_window,
2005 wmspec_supported_atom, 0, G_MAXLONG,
2006 False, XA_ATOM, &type, &format, &n_atoms,
2007 &bytes_after, (guchar **)&atoms);
2009 if (type != XA_ATOM)
2012 wmspec_check_window = *xwindow;
2015 /* since wmspec_check_window != None this isn't infinite. ;-) */
2016 return gdk_net_wm_supports (property);
2021 const char *xsettings_name;
2022 const char *gdk_name;
2023 } settings_map[] = {
2024 { "Net/DoubleClickTime", "gtk-double-click-timeout" },
2025 { "Net/DragThreshold", "gtk-drag-threshold" },
2026 { "Gtk/ColorPalette", "gtk-color-palette" },
2027 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2028 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2029 { "Net/CursorBlink", "gtk-cursor-blink" },
2030 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2031 { "Net/ThemeName", "gtk-theme-name" },
2032 { "Gtk/KeyThemeName", "gtk-key-theme-name" }
2036 gdk_xsettings_notify_cb (const char *name,
2037 XSettingsAction action,
2038 XSettingsSetting *setting,
2044 new_event.type = GDK_SETTING;
2045 new_event.setting.window = NULL;
2046 new_event.setting.send_event = FALSE;
2047 new_event.setting.name = NULL;
2049 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2050 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2052 new_event.setting.name = g_strdup (settings_map[i].gdk_name);
2056 if (!new_event.setting.name)
2061 case XSETTINGS_ACTION_NEW:
2062 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2064 case XSETTINGS_ACTION_CHANGED:
2065 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2067 case XSETTINGS_ACTION_DELETED:
2068 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2072 gdk_event_put (&new_event);
2076 check_transform (const gchar *xsettings_name,
2080 if (!g_value_type_transformable (src_type, dest_type))
2082 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2084 g_type_name (src_type),
2085 g_type_name (dest_type));
2093 gdk_setting_get (const gchar *name,
2096 const char *xsettings_name = NULL;
2097 XSettingsResult result;
2098 XSettingsSetting *setting;
2099 gboolean success = FALSE;
2101 GValue tmp_val = { 0, };
2103 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2104 if (strcmp (settings_map[i].gdk_name, name) == 0)
2106 xsettings_name = settings_map[i].xsettings_name;
2110 if (!xsettings_name)
2113 result = xsettings_client_get_setting (xsettings_client, xsettings_name, &setting);
2114 if (result != XSETTINGS_SUCCESS)
2117 switch (setting->type)
2119 case XSETTINGS_TYPE_INT:
2120 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2122 g_value_init (&tmp_val, G_TYPE_INT);
2123 g_value_set_int (&tmp_val, setting->data.v_int);
2124 g_value_transform (&tmp_val, value);
2129 case XSETTINGS_TYPE_STRING:
2130 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2132 g_value_init (&tmp_val, G_TYPE_STRING);
2133 g_value_set_string (&tmp_val, setting->data.v_string);
2134 g_value_transform (&tmp_val, value);
2139 case XSETTINGS_TYPE_COLOR:
2140 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2144 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2147 color.red = setting->data.v_color.red;
2148 color.green = setting->data.v_color.green;
2149 color.blue = setting->data.v_color.blue;
2151 g_value_set_boxed (&tmp_val, &color);
2153 g_value_transform (&tmp_val, value);
2160 g_value_unset (&tmp_val);
2162 xsettings_setting_free (setting);
2168 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2172 if (xsettings_client_process_event (xsettings_client, (XEvent *)xevent))
2173 return GDK_FILTER_REMOVE;
2175 return GDK_FILTER_CONTINUE;
2179 gdk_xsettings_watch_cb (Window window,
2186 gdkwin = gdk_window_lookup (window);
2188 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);
2190 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);