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"
41 #include "gdkinputprivate.h"
44 #include <X11/XKBlib.h>
47 typedef struct _GdkIOClosure GdkIOClosure;
48 typedef struct _GdkEventPrivate GdkEventPrivate;
50 #define DOUBLE_CLICK_TIME 250
51 #define TRIPLE_CLICK_TIME 500
52 #define DOUBLE_CLICK_DIST 5
53 #define TRIPLE_CLICK_DIST 5
57 /* Following flag is set for events on the event queue during
58 * translation and cleared afterwards.
60 GDK_EVENT_PENDING = 1 << 0
65 GdkInputFunction function;
66 GdkInputCondition condition;
67 GdkDestroyNotify notify;
71 struct _GdkEventPrivate
78 * Private function declarations
81 static gint gdk_event_apply_filters (XEvent *xevent,
84 static gint gdk_event_translate (GdkEvent *event,
86 gboolean return_exposes);
88 static Bool gdk_event_get_type (Display *display,
93 static gboolean gdk_event_prepare (GSource *source,
95 static gboolean gdk_event_check (GSource *source);
96 static gboolean gdk_event_dispatch (GSource *source,
100 GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
104 /* Private variable declarations
107 static int connection_number = 0; /* The file descriptor number of our
108 * connection to the X server. This
109 * is used so that we may determine
110 * when events are pending by using
111 * the "select" system call.
113 static GList *client_filters; /* Filters for client messages */
115 static GSourceFuncs event_funcs = {
122 GPollFD event_poll_fd;
124 /*********************************************
125 * Functions for maintaining the event queue *
126 *********************************************/
129 gdk_events_init (void)
133 connection_number = ConnectionNumber (gdk_display);
135 g_message ("connection number: %d", connection_number));
138 source = g_source_new (&event_funcs, sizeof (GSource));
139 g_source_set_priority (source, GDK_PRIORITY_EVENTS);
141 event_poll_fd.fd = connection_number;
142 event_poll_fd.events = G_IO_IN;
144 g_source_add_poll (source, &event_poll_fd);
145 g_source_set_can_recurse (source, TRUE);
146 g_source_attach (source, NULL);
148 gdk_add_client_message_filter (gdk_wm_protocols,
149 gdk_wm_protocols_filter, NULL);
153 *--------------------------------------------------------------
156 * Returns if events are pending on the queue.
161 * Returns TRUE if events are pending
165 *--------------------------------------------------------------
169 gdk_events_pending (void)
171 return (gdk_event_queue_find_first() || XPending (gdk_display));
175 *--------------------------------------------------------------
176 * gdk_event_get_graphics_expose
178 * Waits for a GraphicsExpose or NoExpose event
183 * For GraphicsExpose events, returns a pointer to the event
184 * converted into a GdkEvent Otherwise, returns NULL.
188 *-------------------------------------------------------------- */
191 graphics_expose_predicate (Display *display,
195 if (xevent->xany.window == GDK_DRAWABLE_XID (arg) &&
196 (xevent->xany.type == GraphicsExpose ||
197 xevent->xany.type == NoExpose))
204 gdk_event_get_graphics_expose (GdkWindow *window)
209 g_return_val_if_fail (window != NULL, NULL);
211 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
213 if (xevent.xany.type == GraphicsExpose)
215 event = gdk_event_new ();
217 if (gdk_event_translate (event, &xevent, TRUE))
220 gdk_event_free (event);
227 gdk_event_apply_filters (XEvent *xevent,
232 GdkFilterReturn result;
238 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
240 tmp_list = tmp_list->next;
241 result = filter->function (xevent, event, filter->data);
242 if (result != GDK_FILTER_CONTINUE)
246 return GDK_FILTER_CONTINUE;
250 gdk_add_client_message_filter (GdkAtom message_type,
254 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
256 filter->type = message_type;
257 filter->function = func;
260 client_filters = g_list_prepend (client_filters, filter);
264 gdk_event_translate (GdkEvent *event,
266 gboolean return_exposes)
270 GdkWindowObject *window_private;
271 static XComposeStatus compose;
275 static gchar* buf = NULL;
276 static gint buf_len= 0;
281 gint xoffset, yoffset;
285 /* Find the GdkWindow that this event occurred in.
287 * We handle events with window=None
288 * specially - they are generated by XFree86's XInput under
289 * some circumstances.
292 if (xevent->xany.window == None)
294 return_val = _gdk_input_window_none_event (event, xevent);
296 if (return_val >= 0) /* was handled */
302 window = gdk_window_lookup (xevent->xany.window);
303 /* FIXME: window might be a GdkPixmap!!! */
305 window_private = (GdkWindowObject *) window;
308 gdk_window_ref (window);
310 event->any.window = window;
311 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
313 if (window_private && GDK_WINDOW_DESTROYED (window))
315 if (xevent->type != DestroyNotify)
320 /* Check for filters for this window
322 GdkFilterReturn result;
323 result = gdk_event_apply_filters (xevent, event,
325 ?window_private->filters
326 :gdk_default_filters);
328 if (result != GDK_FILTER_CONTINUE)
330 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
336 if (window == NULL && gdk_xim_window && xevent->type == KeyPress &&
337 !GDK_WINDOW_DESTROYED (gdk_xim_window))
340 * If user presses a key in Preedit or Status window, keypress event
341 * is sometimes sent to these windows. These windows are not managed
342 * by GDK, so we redirect KeyPress event to xim_window.
344 * If someone want to use the window whitch is not managed by GDK
345 * and want to get KeyPress event, he/she must register the filter
346 * function to gdk_default_filters to intercept the event.
349 GdkFilterReturn result;
351 window = gdk_xim_window;
352 window_private = (GdkWindowObject *) window;
353 gdk_window_ref (window);
354 event->any.window = window;
357 g_message ("KeyPress event is redirected to xim_window: %#lx",
358 xevent->xany.window));
360 result = gdk_event_apply_filters (xevent, event,
361 window_private->filters);
362 if (result != GDK_FILTER_CONTINUE)
364 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
370 /* We do a "manual" conversion of the XEvent to a
371 * GdkEvent. The structures are mostly the same so
372 * the conversion is fairly straightforward. We also
373 * optionally print debugging info regarding events
381 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
389 switch (xevent->type)
392 /* Lookup the string corresponding to the given keysym.
399 buf = g_new (gchar, buf_len);
401 keysym = GDK_VoidSymbol;
403 if (gdk_xim_ic && gdk_xim_ic->xic)
407 /* Clear keyval. Depending on status, may not be set */
408 charcount = XmbLookupString(gdk_xim_ic->xic,
409 &xevent->xkey, buf, buf_len-1,
411 if (status == XBufferOverflow)
413 /* alloc adequate size of buffer */
415 g_message("XIM: overflow (required %i)", charcount));
417 while (buf_len <= charcount)
419 buf = (gchar *) g_realloc (buf, buf_len);
421 charcount = XmbLookupString (gdk_xim_ic->xic,
422 &xevent->xkey, buf, buf_len-1,
425 if (status == XLookupNone)
432 charcount = XLookupString (&xevent->xkey, buf, buf_len,
435 charcount = XLookupString (&xevent->xkey, buf, 16,
438 event->key.keyval = keysym;
439 event->key.hardware_keycode = xevent->xkey.keycode;
441 if (charcount > 0 && buf[charcount-1] == '\0')
444 buf[charcount] = '\0';
446 #ifdef G_ENABLE_DEBUG
447 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
449 g_message ("key press:\twindow: %ld key: %12s %d",
451 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
454 g_message ("\t\tlength: %4d string: \"%s\"",
457 #endif /* G_ENABLE_DEBUG */
459 /* bits 13 and 14 in the "state" field are the keyboard group */
460 #define KEYBOARD_GROUP_MASK ((1 << 13) | (1 << 14))
462 event->key.type = GDK_KEY_PRESS;
463 event->key.window = window;
464 event->key.time = xevent->xkey.time;
465 event->key.state = (GdkModifierType) xevent->xkey.state;
466 event->key.string = g_strdup (buf);
467 event->key.length = charcount;
469 event->key.group = xevent->xkey.state & KEYBOARD_GROUP_MASK;
474 /* Lookup the string corresponding to the given keysym.
480 buf = g_new (gchar, buf_len);
483 keysym = GDK_VoidSymbol;
484 charcount = XLookupString (&xevent->xkey, buf, 16,
486 event->key.keyval = keysym;
489 g_message ("key release:\t\twindow: %ld key: %12s %d",
491 XKeysymToString (event->key.keyval),
494 event->key.type = GDK_KEY_RELEASE;
495 event->key.window = window;
496 event->key.time = xevent->xkey.time;
497 event->key.state = (GdkModifierType) xevent->xkey.state;
498 event->key.length = 0;
499 event->key.string = NULL;
505 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
506 xevent->xbutton.window,
507 xevent->xbutton.x, xevent->xbutton.y,
508 xevent->xbutton.button));
510 if (window_private &&
511 (window_private->extension_events != 0) &&
512 gdk_input_ignore_core)
518 /* If we get a ButtonPress event where the button is 4 or 5,
519 it's a Scroll event */
520 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
522 event->scroll.type = GDK_SCROLL;
523 event->scroll.direction = (xevent->xbutton.button == 4) ?
524 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
525 event->scroll.window = window;
526 event->scroll.time = xevent->xbutton.x;
527 event->scroll.x = xevent->xbutton.x + xoffset;
528 event->scroll.y = xevent->xbutton.y + yoffset;
529 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
530 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
531 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
532 event->scroll.device = gdk_core_pointer;
536 event->button.type = GDK_BUTTON_PRESS;
537 event->button.window = window;
538 event->button.time = xevent->xbutton.time;
539 event->button.x = xevent->xbutton.x + xoffset;
540 event->button.y = xevent->xbutton.y + yoffset;
541 event->button.x_root = (gfloat)xevent->xbutton.x_root;
542 event->button.y_root = (gfloat)xevent->xbutton.y_root;
543 event->button.axes = NULL;
544 event->button.state = (GdkModifierType) xevent->xbutton.state;
545 event->button.button = xevent->xbutton.button;
546 event->button.device = gdk_core_pointer;
548 gdk_event_button_generate (event);
555 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
556 xevent->xbutton.window,
557 xevent->xbutton.x, xevent->xbutton.y,
558 xevent->xbutton.button));
560 if (window_private &&
561 (window_private->extension_events != 0) &&
562 gdk_input_ignore_core)
568 /* We treat button presses as scroll wheel events, so ignore the release */
569 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
575 event->button.type = GDK_BUTTON_RELEASE;
576 event->button.window = window;
577 event->button.time = xevent->xbutton.time;
578 event->button.x = xevent->xbutton.x + xoffset;
579 event->button.y = xevent->xbutton.y + yoffset;
580 event->button.x_root = (gfloat)xevent->xbutton.x_root;
581 event->button.y_root = (gfloat)xevent->xbutton.y_root;
582 event->button.axes = NULL;
583 event->button.state = (GdkModifierType) xevent->xbutton.state;
584 event->button.button = xevent->xbutton.button;
585 event->button.device = gdk_core_pointer;
591 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
592 xevent->xmotion.window,
593 xevent->xmotion.x, xevent->xmotion.y,
594 (xevent->xmotion.is_hint) ? "true" : "false"));
596 if (window_private &&
597 (window_private->extension_events != 0) &&
598 gdk_input_ignore_core)
604 event->motion.type = GDK_MOTION_NOTIFY;
605 event->motion.window = window;
606 event->motion.time = xevent->xmotion.time;
607 event->motion.x = xevent->xmotion.x + xoffset;
608 event->motion.y = xevent->xmotion.y + yoffset;
609 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
610 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
611 event->motion.axes = NULL;
612 event->motion.state = (GdkModifierType) xevent->xmotion.state;
613 event->motion.is_hint = xevent->xmotion.is_hint;
614 event->motion.device = gdk_core_pointer;
620 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
621 xevent->xcrossing.window,
622 xevent->xcrossing.detail,
623 xevent->xcrossing.subwindow));
625 /* Tell XInput stuff about it if appropriate */
626 if (window_private &&
627 !GDK_WINDOW_DESTROYED (window) &&
628 window_private->extension_events != 0)
629 _gdk_input_enter_event (&xevent->xcrossing, window);
631 event->crossing.type = GDK_ENTER_NOTIFY;
632 event->crossing.window = window;
634 /* If the subwindow field of the XEvent is non-NULL, then
635 * lookup the corresponding GdkWindow.
637 if (xevent->xcrossing.subwindow != None)
638 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
640 event->crossing.subwindow = NULL;
642 event->crossing.time = xevent->xcrossing.time;
643 event->crossing.x = xevent->xcrossing.x + xoffset;
644 event->crossing.y = xevent->xcrossing.y + yoffset;
645 event->crossing.x_root = xevent->xcrossing.x_root;
646 event->crossing.y_root = xevent->xcrossing.y_root;
648 /* Translate the crossing mode into Gdk terms.
650 switch (xevent->xcrossing.mode)
653 event->crossing.mode = GDK_CROSSING_NORMAL;
656 event->crossing.mode = GDK_CROSSING_GRAB;
659 event->crossing.mode = GDK_CROSSING_UNGRAB;
663 /* Translate the crossing detail into Gdk terms.
665 switch (xevent->xcrossing.detail)
668 event->crossing.detail = GDK_NOTIFY_INFERIOR;
671 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
674 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
676 case NotifyNonlinear:
677 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
679 case NotifyNonlinearVirtual:
680 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
683 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
687 event->crossing.focus = xevent->xcrossing.focus;
688 event->crossing.state = xevent->xcrossing.state;
694 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
695 xevent->xcrossing.window,
696 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
698 event->crossing.type = GDK_LEAVE_NOTIFY;
699 event->crossing.window = window;
701 /* If the subwindow field of the XEvent is non-NULL, then
702 * lookup the corresponding GdkWindow.
704 if (xevent->xcrossing.subwindow != None)
705 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
707 event->crossing.subwindow = NULL;
709 event->crossing.time = xevent->xcrossing.time;
710 event->crossing.x = xevent->xcrossing.x + xoffset;
711 event->crossing.y = xevent->xcrossing.y + yoffset;
712 event->crossing.x_root = xevent->xcrossing.x_root;
713 event->crossing.y_root = xevent->xcrossing.y_root;
715 /* Translate the crossing mode into Gdk terms.
717 switch (xevent->xcrossing.mode)
720 event->crossing.mode = GDK_CROSSING_NORMAL;
723 event->crossing.mode = GDK_CROSSING_GRAB;
726 event->crossing.mode = GDK_CROSSING_UNGRAB;
730 /* Translate the crossing detail into Gdk terms.
732 switch (xevent->xcrossing.detail)
735 event->crossing.detail = GDK_NOTIFY_INFERIOR;
738 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
741 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
743 case NotifyNonlinear:
744 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
746 case NotifyNonlinearVirtual:
747 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
750 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
754 event->crossing.focus = xevent->xcrossing.focus;
755 event->crossing.state = xevent->xcrossing.state;
761 /* We only care about focus events that indicate that _this_
762 * window (not a ancestor or child) got or lost the focus
764 switch (xevent->xfocus.detail)
768 case NotifyNonlinear:
770 g_message ("focus %s:\t\twindow: %ld",
771 (xevent->xany.type == FocusIn) ? "in" : "out",
772 xevent->xfocus.window));
774 /* gdk_keyboard_grab() causes following events. These events confuse
775 * the XIM focus, so ignore them.
777 if (xevent->xfocus.mode == NotifyGrab ||
778 xevent->xfocus.mode == NotifyUngrab)
781 event->focus_change.type = GDK_FOCUS_CHANGE;
782 event->focus_change.window = window;
783 event->focus_change.in = (xevent->xany.type == FocusIn);
793 g_message ("keymap notify"));
795 /* Not currently handled */
801 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
802 xevent->xexpose.window, xevent->xexpose.count,
803 xevent->xexpose.x, xevent->xexpose.y,
804 xevent->xexpose.width, xevent->xexpose.height,
805 event->any.send_event ? " (send)" : ""));
807 GdkRectangle expose_rect;
809 expose_rect.x = xevent->xexpose.x + xoffset;
810 expose_rect.y = xevent->xexpose.y + yoffset;
811 expose_rect.width = xevent->xexpose.width;
812 expose_rect.height = xevent->xexpose.height;
816 event->expose.type = GDK_EXPOSE;
817 event->expose.area = expose_rect;
818 event->expose.window = window;
819 event->expose.count = xevent->xexpose.count;
825 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
837 GdkRectangle expose_rect;
840 g_message ("graphics expose:\tdrawable: %ld",
841 xevent->xgraphicsexpose.drawable));
843 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
844 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
845 expose_rect.width = xevent->xgraphicsexpose.width;
846 expose_rect.height = xevent->xgraphicsexpose.height;
850 event->expose.type = GDK_EXPOSE;
851 event->expose.area = expose_rect;
852 event->expose.window = window;
853 event->expose.count = xevent->xgraphicsexpose.count;
859 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
869 g_message ("no expose:\t\tdrawable: %ld",
870 xevent->xnoexpose.drawable));
872 event->no_expose.type = GDK_NO_EXPOSE;
873 event->no_expose.window = window;
877 case VisibilityNotify:
878 #ifdef G_ENABLE_DEBUG
879 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
880 switch (xevent->xvisibility.state)
882 case VisibilityFullyObscured:
883 g_message ("visibility notify:\twindow: %ld none",
884 xevent->xvisibility.window);
886 case VisibilityPartiallyObscured:
887 g_message ("visibility notify:\twindow: %ld partial",
888 xevent->xvisibility.window);
890 case VisibilityUnobscured:
891 g_message ("visibility notify:\twindow: %ld full",
892 xevent->xvisibility.window);
895 #endif /* G_ENABLE_DEBUG */
897 event->visibility.type = GDK_VISIBILITY_NOTIFY;
898 event->visibility.window = window;
900 switch (xevent->xvisibility.state)
902 case VisibilityFullyObscured:
903 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
906 case VisibilityPartiallyObscured:
907 event->visibility.state = GDK_VISIBILITY_PARTIAL;
910 case VisibilityUnobscured:
911 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
919 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
920 xevent->xcreatewindow.window,
921 xevent->xcreatewindow.x,
922 xevent->xcreatewindow.y,
923 xevent->xcreatewindow.width,
924 xevent->xcreatewindow.height,
925 xevent->xcreatewindow.border_width,
926 xevent->xcreatewindow.parent,
927 xevent->xcreatewindow.override_redirect));
928 /* not really handled */
933 g_message ("destroy notify:\twindow: %ld",
934 xevent->xdestroywindow.window));
936 event->any.type = GDK_DESTROY;
937 event->any.window = window;
939 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
941 if (window && GDK_WINDOW_XID (window) != GDK_ROOT_WINDOW())
942 gdk_window_destroy_notify (window);
947 g_message ("unmap notify:\t\twindow: %ld",
948 xevent->xmap.window));
950 event->any.type = GDK_UNMAP;
951 event->any.window = window;
953 if (gdk_xgrab_window == window_private)
954 gdk_xgrab_window = NULL;
960 g_message ("map notify:\t\twindow: %ld",
961 xevent->xmap.window));
963 event->any.type = GDK_MAP;
964 event->any.window = window;
970 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
971 xevent->xreparent.window,
974 xevent->xreparent.parent,
975 xevent->xreparent.override_redirect));
977 /* Not currently handled */
981 case ConfigureNotify:
983 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
984 xevent->xconfigure.window,
985 xevent->xconfigure.x,
986 xevent->xconfigure.y,
987 xevent->xconfigure.width,
988 xevent->xconfigure.height,
989 xevent->xconfigure.border_width,
990 xevent->xconfigure.above,
991 xevent->xconfigure.override_redirect,
994 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
995 ? " (discarding child)"
998 !GDK_WINDOW_DESTROYED (window) &&
999 (window_private->extension_events != 0))
1000 _gdk_input_configure_event (&xevent->xconfigure, window);
1002 if (!window || GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
1006 event->configure.type = GDK_CONFIGURE;
1007 event->configure.window = window;
1008 event->configure.width = xevent->xconfigure.width;
1009 event->configure.height = xevent->xconfigure.height;
1011 if (!xevent->xconfigure.x &&
1012 !xevent->xconfigure.y &&
1013 !GDK_WINDOW_DESTROYED (window))
1017 Window child_window = 0;
1019 gdk_error_trap_push ();
1020 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1021 GDK_DRAWABLE_XID (window),
1027 if (!gdk_error_trap_pop ())
1029 event->configure.x = tx;
1030 event->configure.y = ty;
1034 gdk_error_trap_pop ();
1038 event->configure.x = xevent->xconfigure.x;
1039 event->configure.y = xevent->xconfigure.y;
1041 window_private->x = event->configure.x;
1042 window_private->y = event->configure.y;
1043 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1044 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1045 if (window_private->resize_count > 1)
1046 window_private->resize_count -= 1;
1050 case PropertyNotify:
1052 gchar *atom = gdk_atom_name (xevent->xproperty.atom);
1053 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1054 xevent->xproperty.window,
1055 xevent->xproperty.atom,
1057 atom ? atom : "unknown",
1062 event->property.type = GDK_PROPERTY_NOTIFY;
1063 event->property.window = window;
1064 event->property.atom = xevent->xproperty.atom;
1065 event->property.time = xevent->xproperty.time;
1066 event->property.state = xevent->xproperty.state;
1070 case SelectionClear:
1072 g_message ("selection clear:\twindow: %ld",
1073 xevent->xproperty.window));
1075 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1077 event->selection.type = GDK_SELECTION_CLEAR;
1078 event->selection.window = window;
1079 event->selection.selection = xevent->xselectionclear.selection;
1080 event->selection.time = xevent->xselectionclear.time;
1087 case SelectionRequest:
1089 g_message ("selection request:\twindow: %ld",
1090 xevent->xproperty.window));
1092 event->selection.type = GDK_SELECTION_REQUEST;
1093 event->selection.window = window;
1094 event->selection.selection = xevent->xselectionrequest.selection;
1095 event->selection.target = xevent->xselectionrequest.target;
1096 event->selection.property = xevent->xselectionrequest.property;
1097 event->selection.requestor = xevent->xselectionrequest.requestor;
1098 event->selection.time = xevent->xselectionrequest.time;
1102 case SelectionNotify:
1104 g_message ("selection notify:\twindow: %ld",
1105 xevent->xproperty.window));
1108 event->selection.type = GDK_SELECTION_NOTIFY;
1109 event->selection.window = window;
1110 event->selection.selection = xevent->xselection.selection;
1111 event->selection.target = xevent->xselection.target;
1112 event->selection.property = xevent->xselection.property;
1113 event->selection.time = xevent->xselection.time;
1117 case ColormapNotify:
1119 g_message ("colormap notify:\twindow: %ld",
1120 xevent->xcolormap.window));
1122 /* Not currently handled */
1129 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1132 g_message ("client message:\twindow: %ld",
1133 xevent->xclient.window));
1135 tmp_list = client_filters;
1138 GdkClientFilter *filter = tmp_list->data;
1139 if (filter->type == xevent->xclient.message_type)
1141 result = (*filter->function) (xevent, event, filter->data);
1145 tmp_list = tmp_list->next;
1150 case GDK_FILTER_REMOVE:
1153 case GDK_FILTER_TRANSLATE:
1156 case GDK_FILTER_CONTINUE:
1157 /* Send unknown ClientMessage's on to Gtk for it to use */
1158 event->client.type = GDK_CLIENT_EVENT;
1159 event->client.window = window;
1160 event->client.message_type = xevent->xclient.message_type;
1161 event->client.data_format = xevent->xclient.format;
1162 memcpy(&event->client.data, &xevent->xclient.data,
1163 sizeof(event->client.data));
1171 g_message ("mapping notify"));
1173 /* Let XLib know that there is a new keyboard mapping.
1175 XRefreshKeyboardMapping (&xevent->xmapping);
1176 ++_gdk_keymap_serial;
1182 ++_gdk_keymap_serial;
1188 /* something else - (e.g., a Xinput event) */
1190 if (window_private &&
1191 !GDK_WINDOW_DESTROYED (window_private) &&
1192 (window_private->extension_events != 0))
1193 return_val = _gdk_input_other_event(event, xevent, window);
1203 if (event->any.window)
1204 gdk_window_ref (event->any.window);
1205 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1206 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1207 (event->crossing.subwindow != NULL))
1208 gdk_window_ref (event->crossing.subwindow);
1212 /* Mark this event as having no resources to be freed */
1213 event->any.window = NULL;
1214 event->any.type = GDK_NOTHING;
1218 gdk_window_unref (window);
1224 gdk_wm_protocols_filter (GdkXEvent *xev,
1228 XEvent *xevent = (XEvent *)xev;
1230 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1232 /* The delete window request specifies a window
1233 * to delete. We don't actually destroy the
1234 * window because "it is only a request". (The
1235 * window might contain vital data that the
1236 * program does not want destroyed). Instead
1237 * the event is passed along to the program,
1238 * which should then destroy the window.
1241 g_message ("delete window:\t\twindow: %ld",
1242 xevent->xclient.window));
1244 event->any.type = GDK_DELETE;
1246 return GDK_FILTER_TRANSLATE;
1248 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1251 else if ((Atom) xevent->xclient.data.l[0] == gdk_atom_intern ("_NET_WM_PING", FALSE))
1253 XEvent xev = *xevent;
1255 xev.xclient.window = gdk_root_window;
1256 XSendEvent (gdk_display, gdk_root_window, False, SubstructureRedirectMask | SubstructureNotifyMask, &xev);
1259 return GDK_FILTER_REMOVE;
1264 gdk_event_get_type (Display *display,
1271 if (gdk_event_translate (&event, xevent, FALSE))
1273 pred = (GdkPredicate*) arg;
1274 return (* pred->func) (&event, pred->data);
1282 gdk_events_queue (void)
1288 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1293 XNextEvent (gdk_display, &xevent);
1295 switch (xevent.type)
1301 w = GDK_WINDOW_XWINDOW (gdk_xim_window);
1305 if (XFilterEvent (&xevent, w))
1308 XNextEvent (gdk_display, &xevent);
1311 switch (xevent.type)
1317 if (XFilterEvent (&xevent, None))
1321 event = gdk_event_new ();
1323 event->any.type = GDK_NOTHING;
1324 event->any.window = NULL;
1325 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1327 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1329 gdk_event_queue_append (event);
1330 node = gdk_queued_tail;
1332 if (gdk_event_translate (event, &xevent, FALSE))
1334 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1338 gdk_event_queue_remove_link (node);
1339 g_list_free_1 (node);
1340 gdk_event_free (event);
1346 gdk_event_prepare (GSource *source,
1351 GDK_THREADS_ENTER ();
1355 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1357 GDK_THREADS_LEAVE ();
1363 gdk_event_check (GSource *source)
1367 GDK_THREADS_ENTER ();
1369 if (event_poll_fd.revents & G_IO_IN)
1370 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1374 GDK_THREADS_LEAVE ();
1380 gdk_event_dispatch (GSource *source,
1381 GSourceFunc callback,
1386 GDK_THREADS_ENTER ();
1389 event = gdk_event_unqueue();
1394 (*gdk_event_func) (event, gdk_event_data);
1396 gdk_event_free (event);
1399 GDK_THREADS_LEAVE ();
1404 /* Sends a ClientMessage to all toplevel client windows */
1406 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1410 g_return_val_if_fail(event != NULL, FALSE);
1412 /* Set up our event to send, with the exception of its target window */
1413 sev.xclient.type = ClientMessage;
1414 sev.xclient.display = gdk_display;
1415 sev.xclient.format = event->client.data_format;
1416 sev.xclient.window = xid;
1417 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1418 sev.xclient.message_type = event->client.message_type;
1420 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1423 /* Sends a ClientMessage to all toplevel client windows */
1425 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1429 static GdkAtom wm_state_atom = GDK_NONE;
1432 unsigned long nitems, after;
1433 unsigned char *data;
1434 Window *ret_children, ret_root, ret_parent;
1435 unsigned int ret_nchildren;
1436 gint old_warnings = gdk_error_warnings;
1437 gboolean send = FALSE;
1438 gboolean found = FALSE;
1442 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
1444 gdk_error_warnings = FALSE;
1446 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1447 &type, &format, &nitems, &after, &data);
1451 gdk_error_warnings = old_warnings;
1463 /* OK, we're all set, now let's find some windows to send this to */
1464 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1465 &ret_children, &ret_nchildren) != True ||
1468 gdk_error_warnings = old_warnings;
1473 for(i = 0; i < ret_nchildren; i++)
1474 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1477 XFree (ret_children);
1480 if (send || (!found && (level == 1)))
1482 xev->xclient.window = xid;
1483 gdk_send_xevent (xid, False, NoEventMask, xev);
1486 gdk_error_warnings = old_warnings;
1488 return (send || found);
1492 gdk_event_send_clientmessage_toall (GdkEvent *event)
1495 gint old_warnings = gdk_error_warnings;
1497 g_return_if_fail(event != NULL);
1499 /* Set up our event to send, with the exception of its target window */
1500 sev.xclient.type = ClientMessage;
1501 sev.xclient.display = gdk_display;
1502 sev.xclient.format = event->client.data_format;
1503 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1504 sev.xclient.message_type = event->client.message_type;
1506 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
1508 gdk_error_warnings = old_warnings;
1512 *--------------------------------------------------------------
1515 * Flushes the Xlib output buffer and then waits
1516 * until all requests have been received and processed
1517 * by the X server. The only real use for this function
1518 * is in dealing with XShm.
1526 *--------------------------------------------------------------
1532 XSync (gdk_display, False);
1535 static GdkAtom timestamp_prop_atom = 0;
1538 timestamp_predicate (Display *display,
1542 Window xwindow = GPOINTER_TO_UINT (arg);
1544 if (xevent->type == PropertyNotify &&
1545 xevent->xproperty.window == xwindow &&
1546 xevent->xproperty.atom == timestamp_prop_atom)
1553 * gdk_x11_get_server_time:
1554 * @window: a #GdkWindow, used for communication with the server.
1555 * The window must have GDK_PROPERTY_CHANGE_MASK in its
1556 * events mask or a hang will result.
1558 * Routine to get the current X server time stamp.
1560 * Return value: the time stamp.
1563 gdk_x11_get_server_time (GdkWindow *window)
1570 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1571 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
1573 if (!timestamp_prop_atom)
1574 timestamp_prop_atom = gdk_atom_intern ("GDK_TIMESTAMP_PROP", FALSE);
1576 xdisplay = GDK_WINDOW_XDISPLAY (window);
1577 xwindow = GDK_WINDOW_XWINDOW (window);
1579 XChangeProperty (xdisplay, xwindow,
1580 timestamp_prop_atom, timestamp_prop_atom,
1581 8, PropModeReplace, &c, 1);
1583 XIfEvent (xdisplay, &xevent,
1584 timestamp_predicate, GUINT_TO_POINTER(xwindow));
1586 return xevent.xproperty.time;