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
551 _gdk_moveresize_window &&
552 (xevent->xany.type == MotionNotify ||
553 xevent->xany.type == ButtonRelease))
555 _gdk_moveresize_handle_event (xevent);
561 /* We do a "manual" conversion of the XEvent to a
562 * GdkEvent. The structures are mostly the same so
563 * the conversion is fairly straightforward. We also
564 * optionally print debugging info regarding events
572 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
580 switch (xevent->type)
583 if (window_private == NULL)
589 /* Lookup the string corresponding to the given keysym.
592 charcount = XLookupString (&xevent->xkey, buf, 16,
594 event->key.keyval = keysym;
595 event->key.hardware_keycode = xevent->xkey.keycode;
597 if (charcount > 0 && buf[charcount-1] == '\0')
600 buf[charcount] = '\0';
602 #ifdef G_ENABLE_DEBUG
603 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
605 g_message ("key press:\twindow: %ld key: %12s %d",
607 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
610 g_message ("\t\tlength: %4d string: \"%s\"",
613 #endif /* G_ENABLE_DEBUG */
615 /* bits 13 and 14 in the "state" field are the keyboard group */
616 #define KEYBOARD_GROUP_SHIFT 13
617 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
619 event->key.type = GDK_KEY_PRESS;
620 event->key.window = window;
621 event->key.time = xevent->xkey.time;
622 event->key.state = (GdkModifierType) xevent->xkey.state;
623 event->key.string = g_strdup (buf);
624 event->key.length = charcount;
626 event->key.group = (xevent->xkey.state & KEYBOARD_GROUP_MASK) >> KEYBOARD_GROUP_SHIFT;
631 if (window_private == NULL)
637 /* Lookup the string corresponding to the given keysym.
640 /* Emulate detectable auto-repeat by checking to see
641 * if the next event is a key press with the same
642 * keycode and timestamp, and if so, ignoring the event.
645 if (!_gdk_have_xkb_autorepeat && XPending (gdk_display))
649 XPeekEvent (gdk_display, &next_event);
651 if (next_event.type == KeyPress &&
652 next_event.xkey.keycode == xevent->xkey.keycode &&
653 next_event.xkey.time == xevent->xkey.time)
657 keysym = GDK_VoidSymbol;
658 charcount = XLookupString (&xevent->xkey, buf, 16,
660 event->key.keyval = keysym;
663 g_message ("key release:\t\twindow: %ld key: %12s %d",
665 XKeysymToString (event->key.keyval),
668 event->key.type = GDK_KEY_RELEASE;
669 event->key.window = window;
670 event->key.time = xevent->xkey.time;
671 event->key.state = (GdkModifierType) xevent->xkey.state;
672 event->key.length = 0;
673 event->key.string = NULL;
679 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
680 xevent->xbutton.window,
681 xevent->xbutton.x, xevent->xbutton.y,
682 xevent->xbutton.button));
684 if (window_private == NULL ||
685 ((window_private->extension_events != 0) &&
686 gdk_input_ignore_core))
692 /* If we get a ButtonPress event where the button is 4 or 5,
693 it's a Scroll event */
694 switch (xevent->xbutton.button)
700 event->scroll.type = GDK_SCROLL;
702 if (xevent->xbutton.button == 4)
703 event->scroll.direction = GDK_SCROLL_UP;
704 else if (xevent->xbutton.button == 5)
705 event->scroll.direction = GDK_SCROLL_DOWN;
706 else if (xevent->xbutton.button == 6)
707 event->scroll.direction = GDK_SCROLL_LEFT;
709 event->scroll.direction = GDK_SCROLL_RIGHT;
711 event->scroll.window = window;
712 event->scroll.time = xevent->xbutton.x;
713 event->scroll.x = xevent->xbutton.x + xoffset;
714 event->scroll.y = xevent->xbutton.y + yoffset;
715 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
716 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
717 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
718 event->scroll.device = gdk_core_pointer;
722 event->button.type = GDK_BUTTON_PRESS;
723 event->button.window = window;
724 event->button.time = xevent->xbutton.time;
725 event->button.x = xevent->xbutton.x + xoffset;
726 event->button.y = xevent->xbutton.y + yoffset;
727 event->button.x_root = (gfloat)xevent->xbutton.x_root;
728 event->button.y_root = (gfloat)xevent->xbutton.y_root;
729 event->button.axes = NULL;
730 event->button.state = (GdkModifierType) xevent->xbutton.state;
731 event->button.button = xevent->xbutton.button;
732 event->button.device = gdk_core_pointer;
734 gdk_event_button_generate (event);
742 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
743 xevent->xbutton.window,
744 xevent->xbutton.x, xevent->xbutton.y,
745 xevent->xbutton.button));
747 if (window_private == NULL ||
748 ((window_private->extension_events != 0) &&
749 gdk_input_ignore_core))
755 /* We treat button presses as scroll wheel events, so ignore the release */
756 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5 ||
757 xevent->xbutton.button == 6 || xevent->xbutton.button ==7)
763 event->button.type = GDK_BUTTON_RELEASE;
764 event->button.window = window;
765 event->button.time = xevent->xbutton.time;
766 event->button.x = xevent->xbutton.x + xoffset;
767 event->button.y = xevent->xbutton.y + yoffset;
768 event->button.x_root = (gfloat)xevent->xbutton.x_root;
769 event->button.y_root = (gfloat)xevent->xbutton.y_root;
770 event->button.axes = NULL;
771 event->button.state = (GdkModifierType) xevent->xbutton.state;
772 event->button.button = xevent->xbutton.button;
773 event->button.device = gdk_core_pointer;
779 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
780 xevent->xmotion.window,
781 xevent->xmotion.x, xevent->xmotion.y,
782 (xevent->xmotion.is_hint) ? "true" : "false"));
784 if (window_private == NULL ||
785 ((window_private->extension_events != 0) &&
786 gdk_input_ignore_core))
792 event->motion.type = GDK_MOTION_NOTIFY;
793 event->motion.window = window;
794 event->motion.time = xevent->xmotion.time;
795 event->motion.x = xevent->xmotion.x + xoffset;
796 event->motion.y = xevent->xmotion.y + yoffset;
797 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
798 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
799 event->motion.axes = NULL;
800 event->motion.state = (GdkModifierType) xevent->xmotion.state;
801 event->motion.is_hint = xevent->xmotion.is_hint;
802 event->motion.device = gdk_core_pointer;
808 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
809 xevent->xcrossing.window,
810 xevent->xcrossing.detail,
811 xevent->xcrossing.subwindow));
813 if (window_private == NULL)
819 /* Handle focusing (in the case where no window manager is running */
821 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
822 xevent->xcrossing.detail != NotifyInferior &&
823 xevent->xcrossing.focus && !window_impl->has_focus)
825 gboolean had_focus = HAS_FOCUS (window_impl);
827 window_impl->has_pointer_focus = TRUE;
829 if (HAS_FOCUS (window_impl) != had_focus)
830 generate_focus_event (window, TRUE);
833 /* Tell XInput stuff about it if appropriate */
834 if (window_private &&
835 !GDK_WINDOW_DESTROYED (window) &&
836 window_private->extension_events != 0)
837 _gdk_input_enter_event (&xevent->xcrossing, window);
839 event->crossing.type = GDK_ENTER_NOTIFY;
840 event->crossing.window = window;
842 /* If the subwindow field of the XEvent is non-NULL, then
843 * lookup the corresponding GdkWindow.
845 if (xevent->xcrossing.subwindow != None)
846 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
848 event->crossing.subwindow = NULL;
850 event->crossing.time = xevent->xcrossing.time;
851 event->crossing.x = xevent->xcrossing.x + xoffset;
852 event->crossing.y = xevent->xcrossing.y + yoffset;
853 event->crossing.x_root = xevent->xcrossing.x_root;
854 event->crossing.y_root = xevent->xcrossing.y_root;
856 /* Translate the crossing mode into Gdk terms.
858 switch (xevent->xcrossing.mode)
861 event->crossing.mode = GDK_CROSSING_NORMAL;
864 event->crossing.mode = GDK_CROSSING_GRAB;
867 event->crossing.mode = GDK_CROSSING_UNGRAB;
871 /* Translate the crossing detail into Gdk terms.
873 switch (xevent->xcrossing.detail)
876 event->crossing.detail = GDK_NOTIFY_INFERIOR;
879 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
882 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
884 case NotifyNonlinear:
885 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
887 case NotifyNonlinearVirtual:
888 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
891 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
895 event->crossing.focus = xevent->xcrossing.focus;
896 event->crossing.state = xevent->xcrossing.state;
902 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
903 xevent->xcrossing.window,
904 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
906 if (window_private == NULL)
912 /* Handle focusing (in the case where no window manager is running */
914 GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD &&
915 xevent->xcrossing.detail != NotifyInferior &&
916 xevent->xcrossing.focus && !window_impl->has_focus)
918 gboolean had_focus = HAS_FOCUS (window_impl);
920 window_impl->has_pointer_focus = FALSE;
922 if (HAS_FOCUS (window_impl) != had_focus)
923 generate_focus_event (window, FALSE);
926 event->crossing.type = GDK_LEAVE_NOTIFY;
927 event->crossing.window = window;
929 /* If the subwindow field of the XEvent is non-NULL, then
930 * lookup the corresponding GdkWindow.
932 if (xevent->xcrossing.subwindow != None)
933 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
935 event->crossing.subwindow = NULL;
937 event->crossing.time = xevent->xcrossing.time;
938 event->crossing.x = xevent->xcrossing.x + xoffset;
939 event->crossing.y = xevent->xcrossing.y + yoffset;
940 event->crossing.x_root = xevent->xcrossing.x_root;
941 event->crossing.y_root = xevent->xcrossing.y_root;
943 /* Translate the crossing mode into Gdk terms.
945 switch (xevent->xcrossing.mode)
948 event->crossing.mode = GDK_CROSSING_NORMAL;
951 event->crossing.mode = GDK_CROSSING_GRAB;
954 event->crossing.mode = GDK_CROSSING_UNGRAB;
958 /* Translate the crossing detail into Gdk terms.
960 switch (xevent->xcrossing.detail)
963 event->crossing.detail = GDK_NOTIFY_INFERIOR;
966 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
969 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
971 case NotifyNonlinear:
972 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
974 case NotifyNonlinearVirtual:
975 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
978 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
982 event->crossing.focus = xevent->xcrossing.focus;
983 event->crossing.state = xevent->xcrossing.state;
987 /* We only care about focus events that indicate that _this_
988 * window (not a ancestor or child) got or lost the focus
992 g_message ("focus in:\t\twindow: %ld", xevent->xfocus.window));
994 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
996 gboolean had_focus = HAS_FOCUS (window_impl);
998 switch (xevent->xfocus.detail)
1000 case NotifyAncestor:
1001 case NotifyNonlinear:
1003 case NotifyNonlinearVirtual:
1004 window_impl->has_focus = TRUE;
1007 window_impl->has_pointer_focus = TRUE;
1009 case NotifyInferior:
1010 case NotifyPointerRoot:
1011 case NotifyDetailNone:
1015 if (HAS_FOCUS (window_impl) != had_focus)
1016 generate_focus_event (window, TRUE);
1021 g_message ("focus out:\t\twindow: %ld", xevent->xfocus.window));
1023 if (window && GDK_WINDOW_TYPE (window) != GDK_WINDOW_CHILD)
1025 gboolean had_focus = HAS_FOCUS (window_impl);
1027 switch (xevent->xfocus.detail)
1029 case NotifyAncestor:
1030 case NotifyNonlinear:
1032 case NotifyNonlinearVirtual:
1033 window_impl->has_focus = FALSE;
1036 window_impl->has_pointer_focus = FALSE;
1038 case NotifyInferior:
1039 case NotifyPointerRoot:
1040 case NotifyDetailNone:
1044 if (HAS_FOCUS (window_impl) != had_focus)
1045 generate_focus_event (window, FALSE);
1050 /* gdk_keyboard_grab() causes following events. These events confuse
1051 * the XIM focus, so ignore them.
1053 if (xevent->xfocus.mode == NotifyGrab ||
1054 xevent->xfocus.mode == NotifyUngrab)
1060 g_message ("keymap notify"));
1062 /* Not currently handled */
1068 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
1069 xevent->xexpose.window, xevent->xexpose.count,
1070 xevent->xexpose.x, xevent->xexpose.y,
1071 xevent->xexpose.width, xevent->xexpose.height,
1072 event->any.send_event ? " (send)" : ""));
1074 if (window_private == NULL)
1081 GdkRectangle expose_rect;
1083 expose_rect.x = xevent->xexpose.x + xoffset;
1084 expose_rect.y = xevent->xexpose.y + yoffset;
1085 expose_rect.width = xevent->xexpose.width;
1086 expose_rect.height = xevent->xexpose.height;
1090 event->expose.type = GDK_EXPOSE;
1091 event->expose.area = expose_rect;
1092 event->expose.region = gdk_region_rectangle (&expose_rect);
1093 event->expose.window = window;
1094 event->expose.count = xevent->xexpose.count;
1100 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
1110 case GraphicsExpose:
1112 GdkRectangle expose_rect;
1115 g_message ("graphics expose:\tdrawable: %ld",
1116 xevent->xgraphicsexpose.drawable));
1118 if (window_private == NULL)
1124 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
1125 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
1126 expose_rect.width = xevent->xgraphicsexpose.width;
1127 expose_rect.height = xevent->xgraphicsexpose.height;
1131 event->expose.type = GDK_EXPOSE;
1132 event->expose.area = expose_rect;
1133 event->expose.region = gdk_region_rectangle (&expose_rect);
1134 event->expose.window = window;
1135 event->expose.count = xevent->xgraphicsexpose.count;
1141 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
1151 g_message ("no expose:\t\tdrawable: %ld",
1152 xevent->xnoexpose.drawable));
1154 event->no_expose.type = GDK_NO_EXPOSE;
1155 event->no_expose.window = window;
1159 case VisibilityNotify:
1160 #ifdef G_ENABLE_DEBUG
1161 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
1162 switch (xevent->xvisibility.state)
1164 case VisibilityFullyObscured:
1165 g_message ("visibility notify:\twindow: %ld none",
1166 xevent->xvisibility.window);
1168 case VisibilityPartiallyObscured:
1169 g_message ("visibility notify:\twindow: %ld partial",
1170 xevent->xvisibility.window);
1172 case VisibilityUnobscured:
1173 g_message ("visibility notify:\twindow: %ld full",
1174 xevent->xvisibility.window);
1177 #endif /* G_ENABLE_DEBUG */
1179 if (window_private == NULL)
1185 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1186 event->visibility.window = window;
1188 switch (xevent->xvisibility.state)
1190 case VisibilityFullyObscured:
1191 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1194 case VisibilityPartiallyObscured:
1195 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1198 case VisibilityUnobscured:
1199 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1207 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
1208 xevent->xcreatewindow.window,
1209 xevent->xcreatewindow.x,
1210 xevent->xcreatewindow.y,
1211 xevent->xcreatewindow.width,
1212 xevent->xcreatewindow.height,
1213 xevent->xcreatewindow.border_width,
1214 xevent->xcreatewindow.parent,
1215 xevent->xcreatewindow.override_redirect));
1216 /* not really handled */
1221 g_message ("destroy notify:\twindow: %ld",
1222 xevent->xdestroywindow.window));
1224 /* Ignore DestroyNotify from SubstructureNotifyMask */
1225 if (xevent->xdestroywindow.window == xevent->xdestroywindow.event)
1227 event->any.type = GDK_DESTROY;
1228 event->any.window = window;
1230 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
1232 if (window && GDK_WINDOW_XID (window) != GDK_ROOT_WINDOW())
1233 gdk_window_destroy_notify (window);
1241 g_message ("unmap notify:\t\twindow: %ld",
1242 xevent->xmap.window));
1244 event->any.type = GDK_UNMAP;
1245 event->any.window = window;
1247 /* If we are shown (not withdrawn) and get an unmap, it means we
1248 * were iconified in the X sense. If we are withdrawn, and get
1249 * an unmap, it means we hid the window ourselves, so we
1250 * will have already flipped the iconified bit off.
1252 if (window && GDK_WINDOW_IS_MAPPED (window))
1253 gdk_synthesize_window_state (window,
1255 GDK_WINDOW_STATE_ICONIFIED);
1257 if (gdk_xgrab_window == window_private)
1258 gdk_xgrab_window = NULL;
1264 g_message ("map notify:\t\twindow: %ld",
1265 xevent->xmap.window));
1267 event->any.type = GDK_MAP;
1268 event->any.window = window;
1270 /* Unset iconified if it was set */
1271 if (window && (((GdkWindowObject*)window)->state & GDK_WINDOW_STATE_ICONIFIED))
1272 gdk_synthesize_window_state (window,
1273 GDK_WINDOW_STATE_ICONIFIED,
1278 case ReparentNotify:
1280 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
1281 xevent->xreparent.window,
1282 xevent->xreparent.x,
1283 xevent->xreparent.y,
1284 xevent->xreparent.parent,
1285 xevent->xreparent.override_redirect));
1287 /* Not currently handled */
1291 case ConfigureNotify:
1293 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
1294 xevent->xconfigure.window,
1295 xevent->xconfigure.x,
1296 xevent->xconfigure.y,
1297 xevent->xconfigure.width,
1298 xevent->xconfigure.height,
1299 xevent->xconfigure.border_width,
1300 xevent->xconfigure.above,
1301 xevent->xconfigure.override_redirect,
1304 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
1305 ? " (discarding child)"
1308 !GDK_WINDOW_DESTROYED (window) &&
1309 (window_private->extension_events != 0))
1310 _gdk_input_configure_event (&xevent->xconfigure, window);
1313 GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD ||
1314 GDK_WINDOW_TYPE (window) == GDK_WINDOW_ROOT)
1318 event->configure.type = GDK_CONFIGURE;
1319 event->configure.window = window;
1320 event->configure.width = xevent->xconfigure.width;
1321 event->configure.height = xevent->xconfigure.height;
1323 if (!xevent->xconfigure.send_event &&
1324 !GDK_WINDOW_DESTROYED (window))
1328 Window child_window = 0;
1330 gdk_error_trap_push ();
1331 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1332 GDK_DRAWABLE_XID (window),
1338 if (!gdk_error_trap_pop ())
1340 event->configure.x = tx;
1341 event->configure.y = ty;
1345 gdk_error_trap_pop ();
1349 event->configure.x = xevent->xconfigure.x;
1350 event->configure.y = xevent->xconfigure.y;
1352 window_private->x = event->configure.x;
1353 window_private->y = event->configure.y;
1354 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1355 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1356 if (window_private->resize_count >= 1)
1358 window_private->resize_count -= 1;
1360 if (window_private->resize_count == 0 &&
1361 window == _gdk_moveresize_window)
1362 _gdk_moveresize_configure_done ();
1367 case PropertyNotify:
1369 gchar *atom = gdk_atom_name (xevent->xproperty.atom);
1370 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1371 xevent->xproperty.window,
1372 xevent->xproperty.atom,
1374 atom ? atom : "unknown",
1379 if (window_private == NULL)
1385 event->property.type = GDK_PROPERTY_NOTIFY;
1386 event->property.window = window;
1387 event->property.atom = xevent->xproperty.atom;
1388 event->property.time = xevent->xproperty.time;
1389 event->property.state = xevent->xproperty.state;
1391 if (wm_state_atom == 0)
1392 wm_state_atom = gdk_atom_intern ("_NET_WM_STATE", FALSE);
1394 if (wm_desktop_atom == 0)
1395 wm_desktop_atom = gdk_atom_intern ("_NET_WM_DESKTOP", FALSE);
1397 if (event->property.atom == wm_state_atom ||
1398 event->property.atom == wm_desktop_atom)
1400 /* If window state changed, then synthesize those events. */
1401 gdk_check_wm_state_changed (event->property.window);
1406 case SelectionClear:
1408 g_message ("selection clear:\twindow: %ld",
1409 xevent->xproperty.window));
1411 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1413 event->selection.type = GDK_SELECTION_CLEAR;
1414 event->selection.window = window;
1415 event->selection.selection = xevent->xselectionclear.selection;
1416 event->selection.time = xevent->xselectionclear.time;
1423 case SelectionRequest:
1425 g_message ("selection request:\twindow: %ld",
1426 xevent->xproperty.window));
1428 event->selection.type = GDK_SELECTION_REQUEST;
1429 event->selection.window = window;
1430 event->selection.selection = xevent->xselectionrequest.selection;
1431 event->selection.target = xevent->xselectionrequest.target;
1432 event->selection.property = xevent->xselectionrequest.property;
1433 event->selection.requestor = xevent->xselectionrequest.requestor;
1434 event->selection.time = xevent->xselectionrequest.time;
1438 case SelectionNotify:
1440 g_message ("selection notify:\twindow: %ld",
1441 xevent->xproperty.window));
1444 event->selection.type = GDK_SELECTION_NOTIFY;
1445 event->selection.window = window;
1446 event->selection.selection = xevent->xselection.selection;
1447 event->selection.target = xevent->xselection.target;
1448 event->selection.property = xevent->xselection.property;
1449 event->selection.time = xevent->xselection.time;
1453 case ColormapNotify:
1455 g_message ("colormap notify:\twindow: %ld",
1456 xevent->xcolormap.window));
1458 /* Not currently handled */
1465 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1468 g_message ("client message:\twindow: %ld",
1469 xevent->xclient.window));
1471 tmp_list = client_filters;
1474 GdkClientFilter *filter = tmp_list->data;
1475 if (filter->type == xevent->xclient.message_type)
1477 result = (*filter->function) (xevent, event, filter->data);
1481 tmp_list = tmp_list->next;
1486 case GDK_FILTER_REMOVE:
1489 case GDK_FILTER_TRANSLATE:
1492 case GDK_FILTER_CONTINUE:
1493 /* Send unknown ClientMessage's on to Gtk for it to use */
1494 if (window_private == NULL)
1500 event->client.type = GDK_CLIENT_EVENT;
1501 event->client.window = window;
1502 event->client.message_type = xevent->xclient.message_type;
1503 event->client.data_format = xevent->xclient.format;
1504 memcpy(&event->client.data, &xevent->xclient.data,
1505 sizeof(event->client.data));
1515 g_message ("mapping notify"));
1517 /* Let XLib know that there is a new keyboard mapping.
1519 XRefreshKeyboardMapping (&xevent->xmapping);
1520 ++_gdk_keymap_serial;
1526 if (xevent->type == _gdk_xkb_event_type)
1528 XkbEvent *xkb_event = (XkbEvent *)xevent;
1530 switch (xkb_event->any.xkb_type)
1533 ++_gdk_keymap_serial;
1537 case XkbStateNotify:
1538 _gdk_keymap_state_changed ();
1545 /* something else - (e.g., a Xinput event) */
1547 if (window_private &&
1548 !GDK_WINDOW_DESTROYED (window_private) &&
1549 (window_private->extension_events != 0))
1550 return_val = _gdk_input_other_event(event, xevent, window);
1561 if (event->any.window)
1562 gdk_window_ref (event->any.window);
1563 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1564 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1565 (event->crossing.subwindow != NULL))
1566 gdk_window_ref (event->crossing.subwindow);
1570 /* Mark this event as having no resources to be freed */
1571 event->any.window = NULL;
1572 event->any.type = GDK_NOTHING;
1576 gdk_window_unref (window);
1582 gdk_wm_protocols_filter (GdkXEvent *xev,
1586 XEvent *xevent = (XEvent *)xev;
1588 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1590 /* The delete window request specifies a window
1591 * to delete. We don't actually destroy the
1592 * window because "it is only a request". (The
1593 * window might contain vital data that the
1594 * program does not want destroyed). Instead
1595 * the event is passed along to the program,
1596 * which should then destroy the window.
1599 g_message ("delete window:\t\twindow: %ld",
1600 xevent->xclient.window));
1602 event->any.type = GDK_DELETE;
1604 return GDK_FILTER_TRANSLATE;
1606 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1608 GdkWindow *win = event->any.window;
1609 Window focus_win = GDK_WINDOW_IMPL_X11(((GdkWindowObject *)win)->impl)->focus_window;
1611 /* There is no way of knowing reliably whether we are viewable so we need
1612 * to trap errors so we don't cause a BadMatch.
1614 gdk_error_trap_push ();
1615 XSetInputFocus (GDK_WINDOW_XDISPLAY (win),
1618 xevent->xclient.data.l[1]);
1619 XSync (GDK_WINDOW_XDISPLAY (win), False);
1620 gdk_error_trap_pop ();
1622 else if ((Atom) xevent->xclient.data.l[0] == gdk_atom_intern ("_NET_WM_PING", FALSE))
1624 XEvent xev = *xevent;
1626 xev.xclient.window = gdk_root_window;
1627 XSendEvent (gdk_display, gdk_root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1630 return GDK_FILTER_REMOVE;
1635 gdk_event_get_type (Display *display,
1642 if (gdk_event_translate (&event, xevent, FALSE))
1644 pred = (GdkPredicate*) arg;
1645 return (* pred->func) (&event, pred->data);
1653 gdk_events_queue (void)
1659 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1661 XNextEvent (gdk_display, &xevent);
1663 switch (xevent.type)
1669 if (XFilterEvent (&xevent, None))
1673 event = gdk_event_new ();
1675 event->any.type = GDK_NOTHING;
1676 event->any.window = NULL;
1677 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1679 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1681 gdk_event_queue_append (event);
1682 node = gdk_queued_tail;
1684 if (gdk_event_translate (event, &xevent, FALSE))
1686 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1690 gdk_event_queue_remove_link (node);
1691 g_list_free_1 (node);
1692 gdk_event_free (event);
1698 gdk_event_prepare (GSource *source,
1703 GDK_THREADS_ENTER ();
1707 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1709 GDK_THREADS_LEAVE ();
1715 gdk_event_check (GSource *source)
1719 GDK_THREADS_ENTER ();
1721 if (event_poll_fd.revents & G_IO_IN)
1722 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1726 GDK_THREADS_LEAVE ();
1732 gdk_event_dispatch (GSource *source,
1733 GSourceFunc callback,
1738 GDK_THREADS_ENTER ();
1741 event = gdk_event_unqueue();
1746 (*gdk_event_func) (event, gdk_event_data);
1748 gdk_event_free (event);
1751 GDK_THREADS_LEAVE ();
1756 /* Sends a ClientMessage to all toplevel client windows */
1758 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1762 g_return_val_if_fail(event != NULL, FALSE);
1764 /* Set up our event to send, with the exception of its target window */
1765 sev.xclient.type = ClientMessage;
1766 sev.xclient.display = gdk_display;
1767 sev.xclient.format = event->client.data_format;
1768 sev.xclient.window = xid;
1769 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1770 sev.xclient.message_type = event->client.message_type;
1772 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1775 /* Sends a ClientMessage to all toplevel client windows */
1777 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1781 static GdkAtom wm_state_atom = GDK_NONE;
1784 unsigned long nitems, after;
1785 unsigned char *data;
1786 Window *ret_children, ret_root, ret_parent;
1787 unsigned int ret_nchildren;
1788 gint old_warnings = gdk_error_warnings;
1789 gboolean send = FALSE;
1790 gboolean found = FALSE;
1794 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
1796 gdk_error_warnings = FALSE;
1798 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1799 &type, &format, &nitems, &after, &data);
1803 gdk_error_warnings = old_warnings;
1815 /* OK, we're all set, now let's find some windows to send this to */
1816 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1817 &ret_children, &ret_nchildren) != True ||
1820 gdk_error_warnings = old_warnings;
1825 for(i = 0; i < ret_nchildren; i++)
1826 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1829 XFree (ret_children);
1832 if (send || (!found && (level == 1)))
1834 xev->xclient.window = xid;
1835 gdk_send_xevent (xid, False, NoEventMask, xev);
1838 gdk_error_warnings = old_warnings;
1840 return (send || found);
1844 gdk_event_send_clientmessage_toall (GdkEvent *event)
1847 gint old_warnings = gdk_error_warnings;
1849 g_return_if_fail(event != NULL);
1851 /* Set up our event to send, with the exception of its target window */
1852 sev.xclient.type = ClientMessage;
1853 sev.xclient.display = gdk_display;
1854 sev.xclient.format = event->client.data_format;
1855 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1856 sev.xclient.message_type = event->client.message_type;
1858 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
1860 gdk_error_warnings = old_warnings;
1864 *--------------------------------------------------------------
1867 * Flushes the Xlib output buffer and then waits
1868 * until all requests have been received and processed
1869 * by the X server. The only real use for this function
1870 * is in dealing with XShm.
1878 *--------------------------------------------------------------
1884 XSync (gdk_display, False);
1887 static GdkAtom timestamp_prop_atom = 0;
1890 timestamp_predicate (Display *display,
1894 Window xwindow = GPOINTER_TO_UINT (arg);
1896 if (xevent->type == PropertyNotify &&
1897 xevent->xproperty.window == xwindow &&
1898 xevent->xproperty.atom == timestamp_prop_atom)
1905 * gdk_x11_get_server_time:
1906 * @window: a #GdkWindow, used for communication with the server.
1907 * The window must have GDK_PROPERTY_CHANGE_MASK in its
1908 * events mask or a hang will result.
1910 * Routine to get the current X server time stamp.
1912 * Return value: the time stamp.
1915 gdk_x11_get_server_time (GdkWindow *window)
1922 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1923 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
1925 if (!timestamp_prop_atom)
1926 timestamp_prop_atom = gdk_atom_intern ("GDK_TIMESTAMP_PROP", FALSE);
1928 xdisplay = GDK_WINDOW_XDISPLAY (window);
1929 xwindow = GDK_WINDOW_XWINDOW (window);
1931 XChangeProperty (xdisplay, xwindow,
1932 timestamp_prop_atom, timestamp_prop_atom,
1933 8, PropModeReplace, &c, 1);
1935 XIfEvent (xdisplay, &xevent,
1936 timestamp_predicate, GUINT_TO_POINTER(xwindow));
1938 return xevent.xproperty.time;
1943 gdk_net_wm_supports (GdkAtom property)
1945 static GdkAtom wmspec_check_atom = 0;
1946 static GdkAtom wmspec_supported_atom = 0;
1947 static GdkAtom *atoms = NULL;
1948 static gulong n_atoms = 0;
1956 if (wmspec_check_window != None)
1964 if (atoms[i] == property)
1979 /* This function is very slow on every call if you are not running a
1980 * spec-supporting WM. For now not optimized, because it isn't in
1981 * any critical code paths, but if you used it somewhere that had to
1982 * be fast you want to avoid "GTK is slow with old WMs" complaints.
1983 * Probably at that point the function should be changed to query
1984 * _NET_SUPPORTING_WM_CHECK only once every 10 seconds or something.
1987 if (wmspec_check_atom == 0)
1988 wmspec_check_atom = gdk_atom_intern ("_NET_SUPPORTING_WM_CHECK", FALSE);
1990 if (wmspec_supported_atom == 0)
1991 wmspec_supported_atom = gdk_atom_intern ("_NET_SUPPORTED", FALSE);
1993 XGetWindowProperty (gdk_display, gdk_root_window,
1994 wmspec_check_atom, 0, G_MAXLONG,
1995 False, XA_WINDOW, &type, &format, &nitems,
1996 &bytes_after, (guchar **)&xwindow);
1998 if (type != XA_WINDOW)
2001 gdk_error_trap_push ();
2003 /* Find out if this WM goes away, so we can reset everything. */
2004 XSelectInput (gdk_display, *xwindow,
2005 StructureNotifyMask);
2009 if (gdk_error_trap_pop ())
2015 XGetWindowProperty (gdk_display, gdk_root_window,
2016 wmspec_supported_atom, 0, G_MAXLONG,
2017 False, XA_ATOM, &type, &format, &n_atoms,
2018 &bytes_after, (guchar **)&atoms);
2020 if (type != XA_ATOM)
2023 wmspec_check_window = *xwindow;
2026 /* since wmspec_check_window != None this isn't infinite. ;-) */
2027 return gdk_net_wm_supports (property);
2032 const char *xsettings_name;
2033 const char *gdk_name;
2034 } settings_map[] = {
2035 { "Net/DoubleClickTime", "gtk-double-click-timeout" },
2036 { "Net/DragThreshold", "gtk-drag-threshold" },
2037 { "Gtk/ColorPalette", "gtk-color-palette" },
2038 { "Gtk/ToolbarStyle", "gtk-toolbar-style" },
2039 { "Gtk/ToolbarIconSize", "gtk-toolbar-icon-size" },
2040 { "Net/CursorBlink", "gtk-cursor-blink" },
2041 { "Net/CursorBlinkTime", "gtk-cursor-blink-time" },
2042 { "Net/ThemeName", "gtk-theme-name" },
2043 { "Gtk/KeyThemeName", "gtk-key-theme-name" }
2047 gdk_xsettings_notify_cb (const char *name,
2048 XSettingsAction action,
2049 XSettingsSetting *setting,
2055 new_event.type = GDK_SETTING;
2056 new_event.setting.window = NULL;
2057 new_event.setting.send_event = FALSE;
2058 new_event.setting.name = NULL;
2060 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2061 if (strcmp (settings_map[i].xsettings_name, name) == 0)
2063 new_event.setting.name = g_strdup (settings_map[i].gdk_name);
2067 if (!new_event.setting.name)
2072 case XSETTINGS_ACTION_NEW:
2073 new_event.setting.action = GDK_SETTING_ACTION_NEW;
2075 case XSETTINGS_ACTION_CHANGED:
2076 new_event.setting.action = GDK_SETTING_ACTION_CHANGED;
2078 case XSETTINGS_ACTION_DELETED:
2079 new_event.setting.action = GDK_SETTING_ACTION_DELETED;
2083 gdk_event_put (&new_event);
2087 check_transform (const gchar *xsettings_name,
2091 if (!g_value_type_transformable (src_type, dest_type))
2093 g_warning ("Cannot tranform xsetting %s of type %s to type %s\n",
2095 g_type_name (src_type),
2096 g_type_name (dest_type));
2104 gdk_setting_get (const gchar *name,
2107 const char *xsettings_name = NULL;
2108 XSettingsResult result;
2109 XSettingsSetting *setting;
2110 gboolean success = FALSE;
2112 GValue tmp_val = { 0, };
2114 for (i = 0; i < G_N_ELEMENTS (settings_map) ; i++)
2115 if (strcmp (settings_map[i].gdk_name, name) == 0)
2117 xsettings_name = settings_map[i].xsettings_name;
2121 if (!xsettings_name)
2124 result = xsettings_client_get_setting (xsettings_client, xsettings_name, &setting);
2125 if (result != XSETTINGS_SUCCESS)
2128 switch (setting->type)
2130 case XSETTINGS_TYPE_INT:
2131 if (check_transform (xsettings_name, G_TYPE_INT, G_VALUE_TYPE (value)))
2133 g_value_init (&tmp_val, G_TYPE_INT);
2134 g_value_set_int (&tmp_val, setting->data.v_int);
2135 g_value_transform (&tmp_val, value);
2140 case XSETTINGS_TYPE_STRING:
2141 if (check_transform (xsettings_name, G_TYPE_STRING, G_VALUE_TYPE (value)))
2143 g_value_init (&tmp_val, G_TYPE_STRING);
2144 g_value_set_string (&tmp_val, setting->data.v_string);
2145 g_value_transform (&tmp_val, value);
2150 case XSETTINGS_TYPE_COLOR:
2151 if (!check_transform (xsettings_name, GDK_TYPE_COLOR, G_VALUE_TYPE (value)))
2155 g_value_init (&tmp_val, GDK_TYPE_COLOR);
2158 color.red = setting->data.v_color.red;
2159 color.green = setting->data.v_color.green;
2160 color.blue = setting->data.v_color.blue;
2162 g_value_set_boxed (&tmp_val, &color);
2164 g_value_transform (&tmp_val, value);
2171 g_value_unset (&tmp_val);
2173 xsettings_setting_free (setting);
2179 gdk_xsettings_client_event_filter (GdkXEvent *xevent,
2183 if (xsettings_client_process_event (xsettings_client, (XEvent *)xevent))
2184 return GDK_FILTER_REMOVE;
2186 return GDK_FILTER_CONTINUE;
2190 gdk_xsettings_watch_cb (Window window,
2197 gdkwin = gdk_window_lookup (window);
2199 gdk_window_add_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);
2201 gdk_window_remove_filter (gdkwin, gdk_xsettings_client_event_filter, NULL);