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"
43 typedef struct _GdkIOClosure GdkIOClosure;
44 typedef struct _GdkEventPrivate GdkEventPrivate;
46 #define DOUBLE_CLICK_TIME 250
47 #define TRIPLE_CLICK_TIME 500
48 #define DOUBLE_CLICK_DIST 5
49 #define TRIPLE_CLICK_DIST 5
53 /* Following flag is set for events on the event queue during
54 * translation and cleared afterwards.
56 GDK_EVENT_PENDING = 1 << 0
61 GdkInputFunction function;
62 GdkInputCondition condition;
63 GdkDestroyNotify notify;
67 struct _GdkEventPrivate
74 * Private function declarations
77 static gint gdk_event_apply_filters (XEvent *xevent,
80 static gint gdk_event_translate (GdkEvent *event,
82 gboolean return_exposes);
84 static Bool gdk_event_get_type (Display *display,
89 static gboolean gdk_event_prepare (gpointer source_data,
90 GTimeVal *current_time,
93 static gboolean gdk_event_check (gpointer source_data,
94 GTimeVal *current_time,
96 static gboolean gdk_event_dispatch (gpointer source_data,
97 GTimeVal *current_time,
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 = {
119 (GDestroyNotify)g_free
122 GPollFD event_poll_fd;
124 /*********************************************
125 * Functions for maintaining the event queue *
126 *********************************************/
129 gdk_events_init (void)
131 connection_number = ConnectionNumber (gdk_display);
133 g_message ("connection number: %d", connection_number));
135 g_source_add (GDK_PRIORITY_EVENTS, TRUE, &event_funcs, NULL, NULL, NULL);
137 event_poll_fd.fd = connection_number;
138 event_poll_fd.events = G_IO_IN;
140 g_main_add_poll (&event_poll_fd, GDK_PRIORITY_EVENTS);
142 gdk_add_client_message_filter (gdk_wm_protocols,
143 gdk_wm_protocols_filter, NULL);
147 *--------------------------------------------------------------
150 * Returns if events are pending on the queue.
155 * Returns TRUE if events are pending
159 *--------------------------------------------------------------
163 gdk_events_pending (void)
165 return (gdk_event_queue_find_first() || XPending (gdk_display));
169 *--------------------------------------------------------------
170 * gdk_event_get_graphics_expose
172 * Waits for a GraphicsExpose or NoExpose event
177 * For GraphicsExpose events, returns a pointer to the event
178 * converted into a GdkEvent Otherwise, returns NULL.
182 *-------------------------------------------------------------- */
185 graphics_expose_predicate (Display *display,
189 if (xevent->xany.window == GDK_DRAWABLE_XID (arg) &&
190 (xevent->xany.type == GraphicsExpose ||
191 xevent->xany.type == NoExpose))
198 gdk_event_get_graphics_expose (GdkWindow *window)
203 g_return_val_if_fail (window != NULL, NULL);
205 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
207 if (xevent.xany.type == GraphicsExpose)
209 event = gdk_event_new ();
211 if (gdk_event_translate (event, &xevent, TRUE))
214 gdk_event_free (event);
221 gdk_event_apply_filters (XEvent *xevent,
226 GdkFilterReturn result;
232 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
234 tmp_list = tmp_list->next;
235 result = filter->function (xevent, event, filter->data);
236 if (result != GDK_FILTER_CONTINUE)
240 return GDK_FILTER_CONTINUE;
244 gdk_add_client_message_filter (GdkAtom message_type,
248 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
250 filter->type = message_type;
251 filter->function = func;
254 client_filters = g_list_prepend (client_filters, filter);
258 gdk_event_translate (GdkEvent *event,
260 gboolean return_exposes)
264 GdkWindowObject *window_private;
265 static XComposeStatus compose;
269 static gchar* buf = NULL;
270 static gint buf_len= 0;
275 gint xoffset, yoffset;
279 /* Find the GdkWindow that this event occurred in.
281 * We handle events with window=None
282 * specially - they are generated by XFree86's XInput under
283 * some circumstances.
286 if (xevent->xany.window == None)
288 return_val = _gdk_input_window_none_event (event, xevent);
290 if (return_val >= 0) /* was handled */
296 window = gdk_window_lookup (xevent->xany.window);
297 /* FIXME: window might be a GdkPixmap!!! */
299 window_private = (GdkWindowObject *) window;
302 gdk_window_ref (window);
304 event->any.window = window;
305 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
307 if (window_private && GDK_WINDOW_DESTROYED (window))
309 if (xevent->type != DestroyNotify)
314 /* Check for filters for this window
316 GdkFilterReturn result;
317 result = gdk_event_apply_filters (xevent, event,
319 ?window_private->filters
320 :gdk_default_filters);
322 if (result != GDK_FILTER_CONTINUE)
324 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
330 if (window == NULL && gdk_xim_window && xevent->type == KeyPress &&
331 !GDK_WINDOW_DESTROYED (gdk_xim_window))
334 * If user presses a key in Preedit or Status window, keypress event
335 * is sometimes sent to these windows. These windows are not managed
336 * by GDK, so we redirect KeyPress event to xim_window.
338 * If someone want to use the window whitch is not managed by GDK
339 * and want to get KeyPress event, he/she must register the filter
340 * function to gdk_default_filters to intercept the event.
343 GdkFilterReturn result;
345 window = gdk_xim_window;
346 window_private = (GdkWindowObject *) window;
347 gdk_window_ref (window);
348 event->any.window = window;
351 g_message ("KeyPress event is redirected to xim_window: %#lx",
352 xevent->xany.window));
354 result = gdk_event_apply_filters (xevent, event,
355 window_private->filters);
356 if (result != GDK_FILTER_CONTINUE)
358 return_val = (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
364 /* We do a "manual" conversion of the XEvent to a
365 * GdkEvent. The structures are mostly the same so
366 * the conversion is fairly straightforward. We also
367 * optionally print debugging info regarding events
375 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
383 switch (xevent->type)
386 /* Lookup the string corresponding to the given keysym.
393 buf = g_new (gchar, buf_len);
395 keysym = GDK_VoidSymbol;
397 if (gdk_xim_ic && gdk_xim_ic->xic)
401 /* Clear keyval. Depending on status, may not be set */
402 charcount = XmbLookupString(gdk_xim_ic->xic,
403 &xevent->xkey, buf, buf_len-1,
405 if (status == XBufferOverflow)
407 /* alloc adequate size of buffer */
409 g_message("XIM: overflow (required %i)", charcount));
411 while (buf_len <= charcount)
413 buf = (gchar *) g_realloc (buf, buf_len);
415 charcount = XmbLookupString (gdk_xim_ic->xic,
416 &xevent->xkey, buf, buf_len-1,
419 if (status == XLookupNone)
426 charcount = XLookupString (&xevent->xkey, buf, buf_len,
429 charcount = XLookupString (&xevent->xkey, buf, 16,
432 event->key.keyval = keysym;
434 if (charcount > 0 && buf[charcount-1] == '\0')
437 buf[charcount] = '\0';
439 #ifdef G_ENABLE_DEBUG
440 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
442 g_message ("key press:\twindow: %ld key: %12s %d",
444 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
447 g_message ("\t\tlength: %4d string: \"%s\"",
450 #endif /* G_ENABLE_DEBUG */
452 event->key.type = GDK_KEY_PRESS;
453 event->key.window = window;
454 event->key.time = xevent->xkey.time;
455 event->key.state = (GdkModifierType) xevent->xkey.state;
456 event->key.string = g_strdup (buf);
457 event->key.length = charcount;
462 /* Lookup the string corresponding to the given keysym.
468 buf = g_new (gchar, buf_len);
471 keysym = GDK_VoidSymbol;
472 charcount = XLookupString (&xevent->xkey, buf, 16,
474 event->key.keyval = keysym;
477 g_message ("key release:\t\twindow: %ld key: %12s %d",
479 XKeysymToString (event->key.keyval),
482 event->key.type = GDK_KEY_RELEASE;
483 event->key.window = window;
484 event->key.time = xevent->xkey.time;
485 event->key.state = (GdkModifierType) xevent->xkey.state;
486 event->key.length = 0;
487 event->key.string = NULL;
493 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
494 xevent->xbutton.window,
495 xevent->xbutton.x, xevent->xbutton.y,
496 xevent->xbutton.button));
498 if (window_private &&
499 (window_private->extension_events != 0) &&
500 gdk_input_ignore_core)
506 /* If we get a ButtonPress event where the button is 4 or 5,
507 it's a Scroll event */
508 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
510 event->scroll.type = GDK_SCROLL;
511 event->scroll.direction = (xevent->xbutton.button == 4) ?
512 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
513 event->scroll.window = window;
514 event->scroll.time = xevent->xbutton.x;
515 event->scroll.x = xevent->xbutton.x + xoffset;
516 event->scroll.y = xevent->xbutton.y + yoffset;
517 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
518 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
519 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
520 event->scroll.device = gdk_core_pointer;
524 event->button.type = GDK_BUTTON_PRESS;
525 event->button.window = window;
526 event->button.time = xevent->xbutton.time;
527 event->button.x = xevent->xbutton.x + xoffset;
528 event->button.y = xevent->xbutton.y + yoffset;
529 event->button.x_root = (gfloat)xevent->xbutton.x_root;
530 event->button.y_root = (gfloat)xevent->xbutton.y_root;
531 event->button.axes = NULL;
532 event->button.state = (GdkModifierType) xevent->xbutton.state;
533 event->button.button = xevent->xbutton.button;
534 event->button.device = gdk_core_pointer;
536 gdk_event_button_generate (event);
543 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
544 xevent->xbutton.window,
545 xevent->xbutton.x, xevent->xbutton.y,
546 xevent->xbutton.button));
548 if (window_private &&
549 (window_private->extension_events != 0) &&
550 gdk_input_ignore_core)
556 /* We treat button presses as scroll wheel events, so ignore the release */
557 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
563 event->button.type = GDK_BUTTON_RELEASE;
564 event->button.window = window;
565 event->button.time = xevent->xbutton.time;
566 event->button.x = xevent->xbutton.x + xoffset;
567 event->button.y = xevent->xbutton.y + yoffset;
568 event->button.x_root = (gfloat)xevent->xbutton.x_root;
569 event->button.y_root = (gfloat)xevent->xbutton.y_root;
570 event->button.axes = NULL;
571 event->button.state = (GdkModifierType) xevent->xbutton.state;
572 event->button.button = xevent->xbutton.button;
573 event->button.device = gdk_core_pointer;
579 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
580 xevent->xmotion.window,
581 xevent->xmotion.x, xevent->xmotion.y,
582 (xevent->xmotion.is_hint) ? "true" : "false"));
584 if (window_private &&
585 (window_private->extension_events != 0) &&
586 gdk_input_ignore_core)
592 event->motion.type = GDK_MOTION_NOTIFY;
593 event->motion.window = window;
594 event->motion.time = xevent->xmotion.time;
595 event->motion.x = xevent->xmotion.x + xoffset;
596 event->motion.y = xevent->xmotion.y + yoffset;
597 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
598 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
599 event->motion.axes = NULL;
600 event->motion.state = (GdkModifierType) xevent->xmotion.state;
601 event->motion.is_hint = xevent->xmotion.is_hint;
602 event->motion.device = gdk_core_pointer;
608 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
609 xevent->xcrossing.window,
610 xevent->xcrossing.detail,
611 xevent->xcrossing.subwindow));
613 /* Tell XInput stuff about it if appropriate */
614 if (window_private &&
615 !GDK_WINDOW_DESTROYED (window) &&
616 window_private->extension_events != 0)
617 _gdk_input_enter_event (&xevent->xcrossing, window);
619 event->crossing.type = GDK_ENTER_NOTIFY;
620 event->crossing.window = window;
622 /* If the subwindow field of the XEvent is non-NULL, then
623 * lookup the corresponding GdkWindow.
625 if (xevent->xcrossing.subwindow != None)
626 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
628 event->crossing.subwindow = NULL;
630 event->crossing.time = xevent->xcrossing.time;
631 event->crossing.x = xevent->xcrossing.x + xoffset;
632 event->crossing.y = xevent->xcrossing.y + yoffset;
633 event->crossing.x_root = xevent->xcrossing.x_root;
634 event->crossing.y_root = xevent->xcrossing.y_root;
636 /* Translate the crossing mode into Gdk terms.
638 switch (xevent->xcrossing.mode)
641 event->crossing.mode = GDK_CROSSING_NORMAL;
644 event->crossing.mode = GDK_CROSSING_GRAB;
647 event->crossing.mode = GDK_CROSSING_UNGRAB;
651 /* Translate the crossing detail into Gdk terms.
653 switch (xevent->xcrossing.detail)
656 event->crossing.detail = GDK_NOTIFY_INFERIOR;
659 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
662 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
664 case NotifyNonlinear:
665 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
667 case NotifyNonlinearVirtual:
668 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
671 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
675 event->crossing.focus = xevent->xcrossing.focus;
676 event->crossing.state = xevent->xcrossing.state;
682 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
683 xevent->xcrossing.window,
684 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
686 event->crossing.type = GDK_LEAVE_NOTIFY;
687 event->crossing.window = window;
689 /* If the subwindow field of the XEvent is non-NULL, then
690 * lookup the corresponding GdkWindow.
692 if (xevent->xcrossing.subwindow != None)
693 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
695 event->crossing.subwindow = NULL;
697 event->crossing.time = xevent->xcrossing.time;
698 event->crossing.x = xevent->xcrossing.x + xoffset;
699 event->crossing.y = xevent->xcrossing.y + yoffset;
700 event->crossing.x_root = xevent->xcrossing.x_root;
701 event->crossing.y_root = xevent->xcrossing.y_root;
703 /* Translate the crossing mode into Gdk terms.
705 switch (xevent->xcrossing.mode)
708 event->crossing.mode = GDK_CROSSING_NORMAL;
711 event->crossing.mode = GDK_CROSSING_GRAB;
714 event->crossing.mode = GDK_CROSSING_UNGRAB;
718 /* Translate the crossing detail into Gdk terms.
720 switch (xevent->xcrossing.detail)
723 event->crossing.detail = GDK_NOTIFY_INFERIOR;
726 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
729 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
731 case NotifyNonlinear:
732 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
734 case NotifyNonlinearVirtual:
735 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
738 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
742 event->crossing.focus = xevent->xcrossing.focus;
743 event->crossing.state = xevent->xcrossing.state;
749 /* We only care about focus events that indicate that _this_
750 * window (not a ancestor or child) got or lost the focus
752 switch (xevent->xfocus.detail)
756 case NotifyNonlinear:
758 g_message ("focus %s:\t\twindow: %ld",
759 (xevent->xany.type == FocusIn) ? "in" : "out",
760 xevent->xfocus.window));
762 /* gdk_keyboard_grab() causes following events. These events confuse
763 * the XIM focus, so ignore them.
765 if (xevent->xfocus.mode == NotifyGrab ||
766 xevent->xfocus.mode == NotifyUngrab)
769 event->focus_change.type = GDK_FOCUS_CHANGE;
770 event->focus_change.window = window;
771 event->focus_change.in = (xevent->xany.type == FocusIn);
781 g_message ("keymap notify"));
783 /* Not currently handled */
789 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
790 xevent->xexpose.window, xevent->xexpose.count,
791 xevent->xexpose.x, xevent->xexpose.y,
792 xevent->xexpose.width, xevent->xexpose.height,
793 event->any.send_event ? " (send)" : ""));
795 GdkRectangle expose_rect;
797 expose_rect.x = xevent->xexpose.x + xoffset;
798 expose_rect.y = xevent->xexpose.y + yoffset;
799 expose_rect.width = xevent->xexpose.width;
800 expose_rect.height = xevent->xexpose.height;
804 event->expose.type = GDK_EXPOSE;
805 event->expose.area = expose_rect;
806 event->expose.window = window;
807 event->expose.count = xevent->xexpose.count;
813 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
825 GdkRectangle expose_rect;
828 g_message ("graphics expose:\tdrawable: %ld",
829 xevent->xgraphicsexpose.drawable));
831 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
832 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
833 expose_rect.width = xevent->xgraphicsexpose.width;
834 expose_rect.height = xevent->xgraphicsexpose.height;
838 event->expose.type = GDK_EXPOSE;
839 event->expose.area = expose_rect;
840 event->expose.window = window;
841 event->expose.count = xevent->xgraphicsexpose.count;
847 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
857 g_message ("no expose:\t\tdrawable: %ld",
858 xevent->xnoexpose.drawable));
860 event->no_expose.type = GDK_NO_EXPOSE;
861 event->no_expose.window = window;
865 case VisibilityNotify:
866 #ifdef G_ENABLE_DEBUG
867 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
868 switch (xevent->xvisibility.state)
870 case VisibilityFullyObscured:
871 g_message ("visibility notify:\twindow: %ld none",
872 xevent->xvisibility.window);
874 case VisibilityPartiallyObscured:
875 g_message ("visibility notify:\twindow: %ld partial",
876 xevent->xvisibility.window);
878 case VisibilityUnobscured:
879 g_message ("visibility notify:\twindow: %ld full",
880 xevent->xvisibility.window);
883 #endif /* G_ENABLE_DEBUG */
885 event->visibility.type = GDK_VISIBILITY_NOTIFY;
886 event->visibility.window = window;
888 switch (xevent->xvisibility.state)
890 case VisibilityFullyObscured:
891 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
894 case VisibilityPartiallyObscured:
895 event->visibility.state = GDK_VISIBILITY_PARTIAL;
898 case VisibilityUnobscured:
899 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
907 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
908 xevent->xcreatewindow.window,
909 xevent->xcreatewindow.x,
910 xevent->xcreatewindow.y,
911 xevent->xcreatewindow.width,
912 xevent->xcreatewindow.height,
913 xevent->xcreatewindow.border_width,
914 xevent->xcreatewindow.parent,
915 xevent->xcreatewindow.override_redirect));
916 /* not really handled */
921 g_message ("destroy notify:\twindow: %ld",
922 xevent->xdestroywindow.window));
924 event->any.type = GDK_DESTROY;
925 event->any.window = window;
927 return_val = window_private && !GDK_WINDOW_DESTROYED (window);
929 if (window && GDK_WINDOW_XID (window) != GDK_ROOT_WINDOW())
930 gdk_window_destroy_notify (window);
935 g_message ("unmap notify:\t\twindow: %ld",
936 xevent->xmap.window));
938 event->any.type = GDK_UNMAP;
939 event->any.window = window;
941 if (gdk_xgrab_window == window_private)
942 gdk_xgrab_window = NULL;
948 g_message ("map notify:\t\twindow: %ld",
949 xevent->xmap.window));
951 event->any.type = GDK_MAP;
952 event->any.window = window;
958 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
959 xevent->xreparent.window,
962 xevent->xreparent.parent,
963 xevent->xreparent.override_redirect));
965 /* Not currently handled */
969 case ConfigureNotify:
971 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
972 xevent->xconfigure.window,
973 xevent->xconfigure.x,
974 xevent->xconfigure.y,
975 xevent->xconfigure.width,
976 xevent->xconfigure.height,
977 xevent->xconfigure.border_width,
978 xevent->xconfigure.above,
979 xevent->xconfigure.override_redirect,
982 : GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD
983 ? " (discarding child)"
986 !GDK_WINDOW_DESTROYED (window) &&
987 (window_private->extension_events != 0))
988 _gdk_input_configure_event (&xevent->xconfigure, window);
990 if (!window || GDK_WINDOW_TYPE (window) == GDK_WINDOW_CHILD)
994 event->configure.type = GDK_CONFIGURE;
995 event->configure.window = window;
996 event->configure.width = xevent->xconfigure.width;
997 event->configure.height = xevent->xconfigure.height;
999 if (!xevent->xconfigure.x &&
1000 !xevent->xconfigure.y &&
1001 !GDK_WINDOW_DESTROYED (window))
1005 Window child_window = 0;
1007 gdk_error_trap_push ();
1008 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1009 GDK_DRAWABLE_XID (window),
1015 if (!gdk_error_trap_pop ())
1017 event->configure.x = tx;
1018 event->configure.y = ty;
1022 gdk_error_trap_pop ();
1026 event->configure.x = xevent->xconfigure.x;
1027 event->configure.y = xevent->xconfigure.y;
1029 window_private->x = event->configure.x;
1030 window_private->y = event->configure.y;
1031 GDK_WINDOW_IMPL_X11 (window_private->impl)->width = xevent->xconfigure.width;
1032 GDK_WINDOW_IMPL_X11 (window_private->impl)->height = xevent->xconfigure.height;
1033 if (window_private->resize_count > 1)
1034 window_private->resize_count -= 1;
1038 case PropertyNotify:
1040 gchar *atom = gdk_atom_name (xevent->xproperty.atom);
1041 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1042 xevent->xproperty.window,
1043 xevent->xproperty.atom,
1045 atom ? atom : "unknown",
1050 event->property.type = GDK_PROPERTY_NOTIFY;
1051 event->property.window = window;
1052 event->property.atom = xevent->xproperty.atom;
1053 event->property.time = xevent->xproperty.time;
1054 event->property.state = xevent->xproperty.state;
1058 case SelectionClear:
1060 g_message ("selection clear:\twindow: %ld",
1061 xevent->xproperty.window));
1063 if (_gdk_selection_filter_clear_event (&xevent->xselectionclear))
1065 event->selection.type = GDK_SELECTION_CLEAR;
1066 event->selection.window = window;
1067 event->selection.selection = xevent->xselectionclear.selection;
1068 event->selection.time = xevent->xselectionclear.time;
1075 case SelectionRequest:
1077 g_message ("selection request:\twindow: %ld",
1078 xevent->xproperty.window));
1080 event->selection.type = GDK_SELECTION_REQUEST;
1081 event->selection.window = window;
1082 event->selection.selection = xevent->xselectionrequest.selection;
1083 event->selection.target = xevent->xselectionrequest.target;
1084 event->selection.property = xevent->xselectionrequest.property;
1085 event->selection.requestor = xevent->xselectionrequest.requestor;
1086 event->selection.time = xevent->xselectionrequest.time;
1090 case SelectionNotify:
1092 g_message ("selection notify:\twindow: %ld",
1093 xevent->xproperty.window));
1096 event->selection.type = GDK_SELECTION_NOTIFY;
1097 event->selection.window = window;
1098 event->selection.selection = xevent->xselection.selection;
1099 event->selection.target = xevent->xselection.target;
1100 event->selection.property = xevent->xselection.property;
1101 event->selection.time = xevent->xselection.time;
1105 case ColormapNotify:
1107 g_message ("colormap notify:\twindow: %ld",
1108 xevent->xcolormap.window));
1110 /* Not currently handled */
1117 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1120 g_message ("client message:\twindow: %ld",
1121 xevent->xclient.window));
1123 tmp_list = client_filters;
1126 GdkClientFilter *filter = tmp_list->data;
1127 if (filter->type == xevent->xclient.message_type)
1129 result = (*filter->function) (xevent, event, filter->data);
1133 tmp_list = tmp_list->next;
1138 case GDK_FILTER_REMOVE:
1141 case GDK_FILTER_TRANSLATE:
1144 case GDK_FILTER_CONTINUE:
1145 /* Send unknown ClientMessage's on to Gtk for it to use */
1146 event->client.type = GDK_CLIENT_EVENT;
1147 event->client.window = window;
1148 event->client.message_type = xevent->xclient.message_type;
1149 event->client.data_format = xevent->xclient.format;
1150 memcpy(&event->client.data, &xevent->xclient.data,
1151 sizeof(event->client.data));
1159 g_message ("mapping notify"));
1161 /* Let XLib know that there is a new keyboard mapping.
1163 XRefreshKeyboardMapping (&xevent->xmapping);
1168 /* something else - (e.g., a Xinput event) */
1170 if (window_private &&
1171 !GDK_WINDOW_DESTROYED (window_private) &&
1172 (window_private->extension_events != 0))
1173 return_val = _gdk_input_other_event(event, xevent, window);
1183 if (event->any.window)
1184 gdk_window_ref (event->any.window);
1185 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1186 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1187 (event->crossing.subwindow != NULL))
1188 gdk_window_ref (event->crossing.subwindow);
1192 /* Mark this event as having no resources to be freed */
1193 event->any.window = NULL;
1194 event->any.type = GDK_NOTHING;
1198 gdk_window_unref (window);
1204 gdk_wm_protocols_filter (GdkXEvent *xev,
1208 XEvent *xevent = (XEvent *)xev;
1210 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1212 /* The delete window request specifies a window
1213 * to delete. We don't actually destroy the
1214 * window because "it is only a request". (The
1215 * window might contain vital data that the
1216 * program does not want destroyed). Instead
1217 * the event is passed along to the program,
1218 * which should then destroy the window.
1221 g_message ("delete window:\t\twindow: %ld",
1222 xevent->xclient.window));
1224 event->any.type = GDK_DELETE;
1226 return GDK_FILTER_TRANSLATE;
1228 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1232 return GDK_FILTER_REMOVE;
1237 gdk_event_get_type (Display *display,
1244 if (gdk_event_translate (&event, xevent, FALSE))
1246 pred = (GdkPredicate*) arg;
1247 return (* pred->func) (&event, pred->data);
1255 gdk_events_queue (void)
1261 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1266 XNextEvent (gdk_display, &xevent);
1268 switch (xevent.type)
1274 w = GDK_WINDOW_XWINDOW (gdk_xim_window);
1278 if (XFilterEvent (&xevent, w))
1281 XNextEvent (gdk_display, &xevent);
1284 event = gdk_event_new ();
1286 event->any.type = GDK_NOTHING;
1287 event->any.window = NULL;
1288 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1290 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1292 gdk_event_queue_append (event);
1293 node = gdk_queued_tail;
1295 if (gdk_event_translate (event, &xevent, FALSE))
1297 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1301 gdk_event_queue_remove_link (node);
1302 g_list_free_1 (node);
1303 gdk_event_free (event);
1309 gdk_event_prepare (gpointer source_data,
1310 GTimeVal *current_time,
1316 GDK_THREADS_ENTER ();
1320 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1322 GDK_THREADS_LEAVE ();
1328 gdk_event_check (gpointer source_data,
1329 GTimeVal *current_time,
1334 GDK_THREADS_ENTER ();
1336 if (event_poll_fd.revents & G_IO_IN)
1337 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1341 GDK_THREADS_LEAVE ();
1347 gdk_event_dispatch (gpointer source_data,
1348 GTimeVal *current_time,
1353 GDK_THREADS_ENTER ();
1356 event = gdk_event_unqueue();
1361 (*gdk_event_func) (event, gdk_event_data);
1363 gdk_event_free (event);
1366 GDK_THREADS_LEAVE ();
1371 /* Sends a ClientMessage to all toplevel client windows */
1373 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1377 g_return_val_if_fail(event != NULL, FALSE);
1379 /* Set up our event to send, with the exception of its target window */
1380 sev.xclient.type = ClientMessage;
1381 sev.xclient.display = gdk_display;
1382 sev.xclient.format = event->client.data_format;
1383 sev.xclient.window = xid;
1384 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1385 sev.xclient.message_type = event->client.message_type;
1387 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1390 /* Sends a ClientMessage to all toplevel client windows */
1392 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1396 static GdkAtom wm_state_atom = GDK_NONE;
1399 unsigned long nitems, after;
1400 unsigned char *data;
1401 Window *ret_children, ret_root, ret_parent;
1402 unsigned int ret_nchildren;
1403 gint old_warnings = gdk_error_warnings;
1404 gboolean send = FALSE;
1405 gboolean found = FALSE;
1409 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
1411 gdk_error_warnings = FALSE;
1413 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1414 &type, &format, &nitems, &after, &data);
1418 gdk_error_warnings = old_warnings;
1430 /* OK, we're all set, now let's find some windows to send this to */
1431 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1432 &ret_children, &ret_nchildren) != True ||
1435 gdk_error_warnings = old_warnings;
1440 for(i = 0; i < ret_nchildren; i++)
1441 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1444 XFree (ret_children);
1447 if (send || (!found && (level == 1)))
1449 xev->xclient.window = xid;
1450 gdk_send_xevent (xid, False, NoEventMask, xev);
1453 gdk_error_warnings = old_warnings;
1455 return (send || found);
1459 gdk_event_send_clientmessage_toall (GdkEvent *event)
1462 gint old_warnings = gdk_error_warnings;
1464 g_return_if_fail(event != NULL);
1466 /* Set up our event to send, with the exception of its target window */
1467 sev.xclient.type = ClientMessage;
1468 sev.xclient.display = gdk_display;
1469 sev.xclient.format = event->client.data_format;
1470 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1471 sev.xclient.message_type = event->client.message_type;
1473 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
1475 gdk_error_warnings = old_warnings;
1479 *--------------------------------------------------------------
1482 * Flushes the Xlib output buffer and then waits
1483 * until all requests have been received and processed
1484 * by the X server. The only real use for this function
1485 * is in dealing with XShm.
1493 *--------------------------------------------------------------
1499 XSync (gdk_display, False);
1502 static GdkAtom timestamp_prop_atom = 0;
1505 timestamp_predicate (Display *display,
1509 Window xwindow = GPOINTER_TO_UINT (arg);
1511 if (xevent->type == PropertyNotify &&
1512 xevent->xproperty.window == xwindow &&
1513 xevent->xproperty.atom == timestamp_prop_atom)
1520 * gdk_x11_get_server_time:
1521 * @window: a #GdkWindow, used for communication with the server.
1522 * The window must have GDK_PROPERTY_CHANGE_MASK in its
1523 * events mask or a hang will result.
1525 * Routine to get the current X server time stamp.
1527 * Return value: the time stamp.
1530 gdk_x11_get_server_time (GdkWindow *window)
1537 g_return_val_if_fail (GDK_IS_WINDOW (window), 0);
1538 g_return_val_if_fail (!GDK_WINDOW_DESTROYED (window), 0);
1540 if (!timestamp_prop_atom)
1541 timestamp_prop_atom = gdk_atom_intern ("GDK_TIMESTAMP_PROP", FALSE);
1543 xdisplay = GDK_WINDOW_XDISPLAY (window);
1544 xwindow = GDK_WINDOW_XWINDOW (window);
1546 XChangeProperty (xdisplay, xwindow,
1547 timestamp_prop_atom, timestamp_prop_atom,
1548 8, PropModeReplace, &c, 1);
1550 XIfEvent (xdisplay, &xevent,
1551 timestamp_predicate, GUINT_TO_POINTER(xwindow));
1553 return xevent.xproperty.time;