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 Library 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 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library 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-1999. 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,
83 static Bool gdk_event_get_type (Display *display,
88 static gboolean gdk_event_prepare (gpointer source_data,
89 GTimeVal *current_time,
92 static gboolean gdk_event_check (gpointer source_data,
93 GTimeVal *current_time,
95 static gboolean gdk_event_dispatch (gpointer source_data,
96 GTimeVal *current_time,
99 GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
103 /* Private variable declarations
106 static int connection_number = 0; /* The file descriptor number of our
107 * connection to the X server. This
108 * is used so that we may determine
109 * when events are pending by using
110 * the "select" system call.
112 static GList *client_filters; /* Filters for client messages */
114 static GSourceFuncs event_funcs = {
118 (GDestroyNotify)g_free
121 GPollFD event_poll_fd;
123 /*********************************************
124 * Functions for maintaining the event queue *
125 *********************************************/
128 gdk_events_init (void)
130 connection_number = ConnectionNumber (gdk_display);
132 g_message ("connection number: %d", connection_number));
134 g_source_add (GDK_PRIORITY_EVENTS, TRUE, &event_funcs, NULL, NULL, NULL);
136 event_poll_fd.fd = connection_number;
137 event_poll_fd.events = G_IO_IN;
139 g_main_add_poll (&event_poll_fd, GDK_PRIORITY_EVENTS);
141 gdk_add_client_message_filter (gdk_wm_protocols,
142 gdk_wm_protocols_filter, NULL);
146 *--------------------------------------------------------------
149 * Returns if events are pending on the queue.
154 * Returns TRUE if events are pending
158 *--------------------------------------------------------------
162 gdk_events_pending (void)
164 return (gdk_event_queue_find_first() || XPending (gdk_display));
168 *--------------------------------------------------------------
169 * gdk_event_get_graphics_expose
171 * Waits for a GraphicsExpose or NoExpose event
176 * For GraphicsExpose events, returns a pointer to the event
177 * converted into a GdkEvent Otherwise, returns NULL.
181 *-------------------------------------------------------------- */
184 graphics_expose_predicate (Display *display,
188 if (xevent->xany.window == GDK_DRAWABLE_XID (arg) &&
189 (xevent->xany.type == GraphicsExpose ||
190 xevent->xany.type == NoExpose))
197 gdk_event_get_graphics_expose (GdkWindow *window)
202 g_return_val_if_fail (window != NULL, NULL);
204 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
206 if (xevent.xany.type == GraphicsExpose)
208 event = gdk_event_new ();
210 if (gdk_event_translate (event, &xevent))
213 gdk_event_free (event);
220 gdk_event_apply_filters (XEvent *xevent,
225 GdkFilterReturn result;
231 GdkEventFilter *filter = (GdkEventFilter*) tmp_list->data;
233 tmp_list = tmp_list->next;
234 result = filter->function (xevent, event, filter->data);
235 if (result != GDK_FILTER_CONTINUE)
239 return GDK_FILTER_CONTINUE;
243 gdk_add_client_message_filter (GdkAtom message_type,
247 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
249 filter->type = message_type;
250 filter->function = func;
253 client_filters = g_list_prepend (client_filters, filter);
257 gdk_event_translate (GdkEvent *event,
262 GdkWindowPrivate *window_private;
263 static XComposeStatus compose;
267 static gchar* buf = NULL;
268 static gint buf_len= 0;
273 gint xoffset, yoffset;
277 /* Find the GdkWindow that this event occurred in.
279 * We handle events with window=None
280 * specially - they are generated by XFree86's XInput under
281 * some circumstances.
284 if ((xevent->xany.window == None) &&
285 gdk_input_vtable.window_none_event)
287 return_val = gdk_input_vtable.window_none_event (event,xevent);
289 if (return_val >= 0) /* was handled */
295 window = gdk_window_lookup (xevent->xany.window);
296 /* FIXME: window might be a GdkPixmap!!! */
298 window_private = (GdkWindowPrivate *) window;
301 gdk_window_ref (window);
303 event->any.window = window;
304 event->any.send_event = xevent->xany.send_event ? TRUE : FALSE;
306 if (window_private && GDK_DRAWABLE_DESTROYED (window))
308 if (xevent->type != DestroyNotify)
313 /* Check for filters for this window
315 GdkFilterReturn result;
316 result = gdk_event_apply_filters (xevent, event,
318 ?window_private->filters
319 :gdk_default_filters);
321 if (result != GDK_FILTER_CONTINUE)
323 return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
328 if (window == NULL && gdk_xim_window && xevent->type == KeyPress &&
329 !GDK_DRAWABLE_DESTROYED (gdk_xim_window))
332 * If user presses a key in Preedit or Status window, keypress event
333 * is sometimes sent to these windows. These windows are not managed
334 * by GDK, so we redirect KeyPress event to xim_window.
336 * If someone want to use the window whitch is not managed by GDK
337 * and want to get KeyPress event, he/she must register the filter
338 * function to gdk_default_filters to intercept the event.
341 GdkFilterReturn result;
343 window = gdk_xim_window;
344 window_private = (GdkWindowPrivate *) window;
345 gdk_window_ref (window);
346 event->any.window = window;
349 g_message ("KeyPress event is redirected to xim_window: %#lx",
350 xevent->xany.window));
352 result = gdk_event_apply_filters (xevent, event,
353 window_private->filters);
354 if (result != GDK_FILTER_CONTINUE)
355 return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
359 /* We do a "manual" conversion of the XEvent to a
360 * GdkEvent. The structures are mostly the same so
361 * the conversion is fairly straightforward. We also
362 * optionally print debugging info regarding events
370 _gdk_windowing_window_get_offsets (window, &xoffset, &yoffset);
378 switch (xevent->type)
381 /* Lookup the string corresponding to the given keysym.
388 buf = g_new (gchar, buf_len);
390 keysym = GDK_VoidSymbol;
392 if (gdk_xim_ic && gdk_xim_ic->xic)
396 /* Clear keyval. Depending on status, may not be set */
397 charcount = XmbLookupString(gdk_xim_ic->xic,
398 &xevent->xkey, buf, buf_len-1,
400 if (status == XBufferOverflow)
402 /* alloc adequate size of buffer */
404 g_message("XIM: overflow (required %i)", charcount));
406 while (buf_len <= charcount)
408 buf = (gchar *) g_realloc (buf, buf_len);
410 charcount = XmbLookupString (gdk_xim_ic->xic,
411 &xevent->xkey, buf, buf_len-1,
414 if (status == XLookupNone)
421 charcount = XLookupString (&xevent->xkey, buf, buf_len,
424 charcount = XLookupString (&xevent->xkey, buf, 16,
427 event->key.keyval = keysym;
429 if (charcount > 0 && buf[charcount-1] == '\0')
432 buf[charcount] = '\0';
434 /* Print debugging info. */
436 #ifdef G_ENABLE_DEBUG
437 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
439 g_message ("key press:\twindow: %ld key: %12s %d",
441 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
444 g_message ("\t\tlength: %4d string: \"%s\"",
447 #endif /* G_ENABLE_DEBUG */
449 event->key.type = GDK_KEY_PRESS;
450 event->key.window = window;
451 event->key.time = xevent->xkey.time;
452 event->key.state = (GdkModifierType) xevent->xkey.state;
453 event->key.string = g_strdup (buf);
454 event->key.length = charcount;
459 /* Lookup the string corresponding to the given keysym.
465 buf = g_new (gchar, buf_len);
468 keysym = GDK_VoidSymbol;
469 charcount = XLookupString (&xevent->xkey, buf, 16,
471 event->key.keyval = keysym;
473 /* Print debugging info.
476 g_message ("key release:\t\twindow: %ld key: %12s %d",
478 XKeysymToString (event->key.keyval),
481 event->key.type = GDK_KEY_RELEASE;
482 event->key.window = window;
483 event->key.time = xevent->xkey.time;
484 event->key.state = (GdkModifierType) xevent->xkey.state;
485 event->key.length = 0;
486 event->key.string = NULL;
491 /* Print debugging info.
494 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
495 xevent->xbutton.window,
496 xevent->xbutton.x, xevent->xbutton.y,
497 xevent->xbutton.button));
499 if (window_private &&
500 (window_private->extension_events != 0) &&
501 gdk_input_ignore_core)
507 /* If we get a ButtonPress event where the button is 4 or 5,
508 it's a Scroll event */
509 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
511 event->scroll.type = GDK_SCROLL;
512 event->scroll.direction = (xevent->xbutton.button == 4) ?
513 GDK_SCROLL_UP : GDK_SCROLL_DOWN;
514 event->scroll.window = window;
515 event->scroll.time = xevent->xbutton.x;
516 event->scroll.x = xevent->xbutton.x + xoffset;
517 event->scroll.y = xevent->xbutton.y + yoffset;
518 event->scroll.x_root = (gfloat)xevent->xbutton.x_root;
519 event->scroll.y_root = (gfloat)xevent->xbutton.y_root;
520 event->scroll.pressure = 0.5;
521 event->scroll.xtilt = 0;
522 event->scroll.ytilt = 0;
523 event->scroll.state = (GdkModifierType) xevent->xbutton.state;
524 event->scroll.source = GDK_SOURCE_MOUSE;
525 event->scroll.deviceid = GDK_CORE_POINTER;
529 event->button.type = GDK_BUTTON_PRESS;
530 event->button.window = window;
531 event->button.time = xevent->xbutton.time;
532 event->button.x = xevent->xbutton.x + xoffset;
533 event->button.y = xevent->xbutton.y + yoffset;
534 event->button.x_root = (gfloat)xevent->xbutton.x_root;
535 event->button.y_root = (gfloat)xevent->xbutton.y_root;
536 event->button.pressure = 0.5;
537 event->button.xtilt = 0;
538 event->button.ytilt = 0;
539 event->button.state = (GdkModifierType) xevent->xbutton.state;
540 event->button.button = xevent->xbutton.button;
541 event->button.source = GDK_SOURCE_MOUSE;
542 event->button.deviceid = GDK_CORE_POINTER;
544 gdk_event_button_generate (event);
550 /* Print debugging info.
553 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
554 xevent->xbutton.window,
555 xevent->xbutton.x, xevent->xbutton.y,
556 xevent->xbutton.button));
558 if (window_private &&
559 (window_private->extension_events != 0) &&
560 gdk_input_ignore_core)
566 /* We treat button presses as scroll wheel events, so ignore the release */
567 if (xevent->xbutton.button == 4 || xevent->xbutton.button == 5)
573 event->button.type = GDK_BUTTON_RELEASE;
574 event->button.window = window;
575 event->button.time = xevent->xbutton.time;
576 event->button.x = xevent->xbutton.x + xoffset;
577 event->button.y = xevent->xbutton.y + yoffset;
578 event->button.x_root = (gfloat)xevent->xbutton.x_root;
579 event->button.y_root = (gfloat)xevent->xbutton.y_root;
580 event->button.pressure = 0.5;
581 event->button.xtilt = 0;
582 event->button.ytilt = 0;
583 event->button.state = (GdkModifierType) xevent->xbutton.state;
584 event->button.button = xevent->xbutton.button;
585 event->button.source = GDK_SOURCE_MOUSE;
586 event->button.deviceid = GDK_CORE_POINTER;
591 /* Print debugging info.
594 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
595 xevent->xmotion.window,
596 xevent->xmotion.x, xevent->xmotion.y,
597 (xevent->xmotion.is_hint) ? "true" : "false"));
599 if (window_private &&
600 (window_private->extension_events != 0) &&
601 gdk_input_ignore_core)
607 event->motion.type = GDK_MOTION_NOTIFY;
608 event->motion.window = window;
609 event->motion.time = xevent->xmotion.time;
610 event->motion.x = xevent->xmotion.x + xoffset;
611 event->motion.y = xevent->xmotion.y + yoffset;
612 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
613 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
614 event->motion.pressure = 0.5;
615 event->motion.xtilt = 0;
616 event->motion.ytilt = 0;
617 event->motion.state = (GdkModifierType) xevent->xmotion.state;
618 event->motion.is_hint = xevent->xmotion.is_hint;
619 event->motion.source = GDK_SOURCE_MOUSE;
620 event->motion.deviceid = GDK_CORE_POINTER;
625 /* Print debugging info.
628 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
629 xevent->xcrossing.window,
630 xevent->xcrossing.detail,
631 xevent->xcrossing.subwindow));
633 /* Tell XInput stuff about it if appropriate */
634 if (window_private &&
635 !GDK_DRAWABLE_DESTROYED (window) &&
636 (window_private->extension_events != 0) &&
637 gdk_input_vtable.enter_event)
638 gdk_input_vtable.enter_event (&xevent->xcrossing, window);
640 event->crossing.type = GDK_ENTER_NOTIFY;
641 event->crossing.window = window;
643 /* If the subwindow field of the XEvent is non-NULL, then
644 * lookup the corresponding GdkWindow.
646 if (xevent->xcrossing.subwindow != None)
647 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
649 event->crossing.subwindow = NULL;
651 event->crossing.time = xevent->xcrossing.time;
652 event->crossing.x = xevent->xcrossing.x + xoffset;
653 event->crossing.y = xevent->xcrossing.y + yoffset;
654 event->crossing.x_root = xevent->xcrossing.x_root;
655 event->crossing.y_root = xevent->xcrossing.y_root;
657 /* Translate the crossing mode into Gdk terms.
659 switch (xevent->xcrossing.mode)
662 event->crossing.mode = GDK_CROSSING_NORMAL;
665 event->crossing.mode = GDK_CROSSING_GRAB;
668 event->crossing.mode = GDK_CROSSING_UNGRAB;
672 /* Translate the crossing detail into Gdk terms.
674 switch (xevent->xcrossing.detail)
677 event->crossing.detail = GDK_NOTIFY_INFERIOR;
680 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
683 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
685 case NotifyNonlinear:
686 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
688 case NotifyNonlinearVirtual:
689 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
692 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
696 event->crossing.focus = xevent->xcrossing.focus;
697 event->crossing.state = xevent->xcrossing.state;
702 /* Print debugging info.
705 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
706 xevent->xcrossing.window,
707 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
709 event->crossing.type = GDK_LEAVE_NOTIFY;
710 event->crossing.window = window;
712 /* If the subwindow field of the XEvent is non-NULL, then
713 * lookup the corresponding GdkWindow.
715 if (xevent->xcrossing.subwindow != None)
716 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
718 event->crossing.subwindow = NULL;
720 event->crossing.time = xevent->xcrossing.time;
721 event->crossing.x = xevent->xcrossing.x + xoffset;
722 event->crossing.y = xevent->xcrossing.y + yoffset;
723 event->crossing.x_root = xevent->xcrossing.x_root;
724 event->crossing.y_root = xevent->xcrossing.y_root;
726 /* Translate the crossing mode into Gdk terms.
728 switch (xevent->xcrossing.mode)
731 event->crossing.mode = GDK_CROSSING_NORMAL;
734 event->crossing.mode = GDK_CROSSING_GRAB;
737 event->crossing.mode = GDK_CROSSING_UNGRAB;
741 /* Translate the crossing detail into Gdk terms.
743 switch (xevent->xcrossing.detail)
746 event->crossing.detail = GDK_NOTIFY_INFERIOR;
749 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
752 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
754 case NotifyNonlinear:
755 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
757 case NotifyNonlinearVirtual:
758 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
761 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
765 event->crossing.focus = xevent->xcrossing.focus;
766 event->crossing.state = xevent->xcrossing.state;
772 /* We only care about focus events that indicate that _this_
773 * window (not a ancestor or child) got or lost the focus
775 switch (xevent->xfocus.detail)
779 case NotifyNonlinear:
780 /* Print debugging info.
783 g_message ("focus %s:\t\twindow: %ld",
784 (xevent->xany.type == FocusIn) ? "in" : "out",
785 xevent->xfocus.window));
787 /* gdk_keyboard_grab() causes following events. These events confuse
788 * the XIM focus, so ignore them.
790 if (xevent->xfocus.mode == NotifyGrab ||
791 xevent->xfocus.mode == NotifyUngrab)
794 event->focus_change.type = GDK_FOCUS_CHANGE;
795 event->focus_change.window = window;
796 event->focus_change.in = (xevent->xany.type == FocusIn);
805 /* Print debugging info.
808 g_message ("keymap notify"));
810 /* Not currently handled */
815 /* Print debugging info.
818 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d%s",
819 xevent->xexpose.window, xevent->xexpose.count,
820 xevent->xexpose.x, xevent->xexpose.y,
821 xevent->xexpose.width, xevent->xexpose.height,
822 event->any.send_event ? " (send)" : ""));
824 GdkRectangle expose_rect;
826 expose_rect.x = xevent->xexpose.x + xoffset;
827 expose_rect.y = xevent->xexpose.y + yoffset;
828 expose_rect.width = xevent->xexpose.width;
829 expose_rect.height = xevent->xexpose.height;
831 _gdk_window_process_expose (window, xevent->xexpose.serial, &expose_rect);
839 /* Print debugging info.
842 GdkRectangle expose_rect;
845 g_message ("graphics expose:\tdrawable: %ld",
846 xevent->xgraphicsexpose.drawable));
849 expose_rect.x = xevent->xgraphicsexpose.x + xoffset;
850 expose_rect.y = xevent->xgraphicsexpose.y + yoffset;
851 expose_rect.width = xevent->xgraphicsexpose.width;
852 expose_rect.height = xevent->xgraphicsexpose.height;
854 _gdk_window_process_expose (window, xevent->xgraphicsexpose.serial, &expose_rect);
861 /* Print debugging info.
864 g_message ("no expose:\t\tdrawable: %ld",
865 xevent->xnoexpose.drawable));
867 event->no_expose.type = GDK_NO_EXPOSE;
868 event->no_expose.window = window;
872 case VisibilityNotify:
873 /* Print debugging info.
875 #ifdef G_ENABLE_DEBUG
876 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
877 switch (xevent->xvisibility.state)
879 case VisibilityFullyObscured:
880 g_message ("visibility notify:\twindow: %ld none",
881 xevent->xvisibility.window);
883 case VisibilityPartiallyObscured:
884 g_message ("visibility notify:\twindow: %ld partial",
885 xevent->xvisibility.window);
887 case VisibilityUnobscured:
888 g_message ("visibility notify:\twindow: %ld full",
889 xevent->xvisibility.window);
892 #endif /* G_ENABLE_DEBUG */
894 event->visibility.type = GDK_VISIBILITY_NOTIFY;
895 event->visibility.window = window;
897 switch (xevent->xvisibility.state)
899 case VisibilityFullyObscured:
900 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
903 case VisibilityPartiallyObscured:
904 event->visibility.state = GDK_VISIBILITY_PARTIAL;
907 case VisibilityUnobscured:
908 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
916 g_message ("create notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d parent: %ld ovr: %d",
917 xevent->xcreatewindow.window,
918 xevent->xcreatewindow.x,
919 xevent->xcreatewindow.y,
920 xevent->xcreatewindow.width,
921 xevent->xcreatewindow.height,
922 xevent->xcreatewindow.border_width,
923 xevent->xcreatewindow.parent,
924 xevent->xcreatewindow.override_redirect));
925 /* not really handled */
929 /* Print debugging info.
932 g_message ("destroy notify:\twindow: %ld",
933 xevent->xdestroywindow.window));
935 event->any.type = GDK_DESTROY;
936 event->any.window = window;
938 return_val = window_private && !GDK_DRAWABLE_DESTROYED (window);
940 if (window && GDK_DRAWABLE_XID (window) != GDK_ROOT_WINDOW())
941 gdk_window_destroy_notify (window);
945 /* Print debugging info.
948 g_message ("unmap notify:\t\twindow: %ld",
949 xevent->xmap.window));
951 event->any.type = GDK_UNMAP;
952 event->any.window = window;
954 if (gdk_xgrab_window == window_private)
955 gdk_xgrab_window = NULL;
960 /* Print debugging info.
963 g_message ("map notify:\t\twindow: %ld",
964 xevent->xmap.window));
966 event->any.type = GDK_MAP;
967 event->any.window = window;
972 /* Print debugging info.
975 g_message ("reparent notify:\twindow: %ld x,y: %d %d parent: %ld ovr: %d",
976 xevent->xreparent.window,
979 xevent->xreparent.parent,
980 xevent->xreparent.override_redirect));
982 /* Not currently handled */
986 case ConfigureNotify:
987 /* Print debugging info.
990 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d%s",
991 xevent->xconfigure.window,
992 xevent->xconfigure.x,
993 xevent->xconfigure.y,
994 xevent->xconfigure.width,
995 xevent->xconfigure.height,
996 xevent->xconfigure.border_width,
997 xevent->xconfigure.above,
998 xevent->xconfigure.override_redirect,
1001 : GDK_DRAWABLE_TYPE (window) == GDK_WINDOW_CHILD
1002 ? " (discarding child)"
1005 !GDK_DRAWABLE_DESTROYED (window) &&
1006 (window_private->extension_events != 0) &&
1007 gdk_input_vtable.configure_event)
1008 gdk_input_vtable.configure_event (&xevent->xconfigure, window);
1010 if (!window || GDK_DRAWABLE_TYPE (window) == GDK_WINDOW_CHILD)
1014 event->configure.type = GDK_CONFIGURE;
1015 event->configure.window = window;
1016 event->configure.width = xevent->xconfigure.width;
1017 event->configure.height = xevent->xconfigure.height;
1019 if (!xevent->xconfigure.x &&
1020 !xevent->xconfigure.y &&
1021 !GDK_DRAWABLE_DESTROYED (window))
1025 Window child_window = 0;
1027 gdk_error_trap_push ();
1028 if (XTranslateCoordinates (GDK_DRAWABLE_XDISPLAY (window),
1029 GDK_DRAWABLE_XID (window),
1035 if (!gdk_error_trap_pop ())
1037 event->configure.x = tx;
1038 event->configure.y = ty;
1042 gdk_error_trap_pop ();
1046 event->configure.x = xevent->xconfigure.x;
1047 event->configure.y = xevent->xconfigure.y;
1049 window_private->x = event->configure.x;
1050 window_private->y = event->configure.y;
1051 window_private->drawable.width = xevent->xconfigure.width;
1052 window_private->drawable.height = xevent->xconfigure.height;
1053 if (window_private->resize_count > 1)
1054 window_private->resize_count -= 1;
1058 case PropertyNotify:
1059 /* Print debugging info.
1062 gchar *atom = gdk_atom_name (xevent->xproperty.atom);
1063 g_message ("property notify:\twindow: %ld, atom(%ld): %s%s%s",
1064 xevent->xproperty.window,
1065 xevent->xproperty.atom,
1067 atom ? atom : "unknown",
1072 event->property.type = GDK_PROPERTY_NOTIFY;
1073 event->property.window = window;
1074 event->property.atom = xevent->xproperty.atom;
1075 event->property.time = xevent->xproperty.time;
1076 event->property.state = xevent->xproperty.state;
1080 case SelectionClear:
1082 g_message ("selection clear:\twindow: %ld",
1083 xevent->xproperty.window));
1085 event->selection.type = GDK_SELECTION_CLEAR;
1086 event->selection.window = window;
1087 event->selection.selection = xevent->xselectionclear.selection;
1088 event->selection.time = xevent->xselectionclear.time;
1092 case SelectionRequest:
1094 g_message ("selection request:\twindow: %ld",
1095 xevent->xproperty.window));
1097 event->selection.type = GDK_SELECTION_REQUEST;
1098 event->selection.window = window;
1099 event->selection.selection = xevent->xselectionrequest.selection;
1100 event->selection.target = xevent->xselectionrequest.target;
1101 event->selection.property = xevent->xselectionrequest.property;
1102 event->selection.requestor = xevent->xselectionrequest.requestor;
1103 event->selection.time = xevent->xselectionrequest.time;
1107 case SelectionNotify:
1109 g_message ("selection notify:\twindow: %ld",
1110 xevent->xproperty.window));
1113 event->selection.type = GDK_SELECTION_NOTIFY;
1114 event->selection.window = window;
1115 event->selection.selection = xevent->xselection.selection;
1116 event->selection.target = xevent->xselection.target;
1117 event->selection.property = xevent->xselection.property;
1118 event->selection.time = xevent->xselection.time;
1122 case ColormapNotify:
1123 /* Print debugging info.
1126 g_message ("colormap notify:\twindow: %ld",
1127 xevent->xcolormap.window));
1129 /* Not currently handled */
1136 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1138 /* Print debugging info.
1141 g_message ("client message:\twindow: %ld",
1142 xevent->xclient.window));
1144 tmp_list = client_filters;
1147 GdkClientFilter *filter = tmp_list->data;
1148 if (filter->type == xevent->xclient.message_type)
1150 result = (*filter->function) (xevent, event, filter->data);
1154 tmp_list = tmp_list->next;
1159 case GDK_FILTER_REMOVE:
1162 case GDK_FILTER_TRANSLATE:
1165 case GDK_FILTER_CONTINUE:
1166 /* Send unknown ClientMessage's on to Gtk for it to use */
1167 event->client.type = GDK_CLIENT_EVENT;
1168 event->client.window = window;
1169 event->client.message_type = xevent->xclient.message_type;
1170 event->client.data_format = xevent->xclient.format;
1171 memcpy(&event->client.data, &xevent->xclient.data,
1172 sizeof(event->client.data));
1179 /* Print debugging info.
1182 g_message ("mapping notify"));
1184 /* Let XLib know that there is a new keyboard mapping.
1186 XRefreshKeyboardMapping (&xevent->xmapping);
1191 /* something else - (e.g., a Xinput event) */
1193 if (window_private &&
1194 !window_private->drawable.destroyed &&
1195 (window_private->extension_events != 0) &&
1196 gdk_input_vtable.other_event)
1197 return_val = gdk_input_vtable.other_event(event, xevent, window);
1206 if (event->any.window)
1207 gdk_window_ref (event->any.window);
1208 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1209 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1210 (event->crossing.subwindow != NULL))
1211 gdk_window_ref (event->crossing.subwindow);
1215 /* Mark this event as having no resources to be freed */
1216 event->any.window = NULL;
1217 event->any.type = GDK_NOTHING;
1221 gdk_window_unref (window);
1227 gdk_wm_protocols_filter (GdkXEvent *xev,
1231 XEvent *xevent = (XEvent *)xev;
1233 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1235 /* The delete window request specifies a window
1236 * to delete. We don't actually destroy the
1237 * window because "it is only a request". (The
1238 * window might contain vital data that the
1239 * program does not want destroyed). Instead
1240 * the event is passed along to the program,
1241 * which should then destroy the window.
1244 g_message ("delete window:\t\twindow: %ld",
1245 xevent->xclient.window));
1247 event->any.type = GDK_DELETE;
1249 return GDK_FILTER_TRANSLATE;
1251 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1255 return GDK_FILTER_REMOVE;
1260 gdk_event_get_type (Display *display,
1267 if (gdk_event_translate (&event, xevent))
1269 pred = (GdkPredicate*) arg;
1270 return (* pred->func) (&event, pred->data);
1278 gdk_events_queue (void)
1284 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1289 XNextEvent (gdk_display, &xevent);
1291 switch (xevent.type)
1297 w = GDK_WINDOW_XWINDOW (gdk_xim_window);
1301 if (XFilterEvent (&xevent, w))
1304 XNextEvent (gdk_display, &xevent);
1307 event = gdk_event_new ();
1309 event->any.type = GDK_NOTHING;
1310 event->any.window = NULL;
1311 event->any.send_event = xevent.xany.send_event ? TRUE : FALSE;
1313 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
1315 gdk_event_queue_append (event);
1316 node = gdk_queued_tail;
1318 if (gdk_event_translate (event, &xevent))
1320 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
1324 gdk_event_queue_remove_link (node);
1325 g_list_free_1 (node);
1326 gdk_event_free (event);
1332 gdk_event_prepare (gpointer source_data,
1333 GTimeVal *current_time,
1339 GDK_THREADS_ENTER ();
1343 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1345 GDK_THREADS_LEAVE ();
1351 gdk_event_check (gpointer source_data,
1352 GTimeVal *current_time,
1357 GDK_THREADS_ENTER ();
1359 if (event_poll_fd.revents & G_IO_IN)
1360 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
1364 GDK_THREADS_LEAVE ();
1370 gdk_event_dispatch (gpointer source_data,
1371 GTimeVal *current_time,
1376 GDK_THREADS_ENTER ();
1379 event = gdk_event_unqueue();
1384 (*gdk_event_func) (event, gdk_event_data);
1386 gdk_event_free (event);
1389 GDK_THREADS_LEAVE ();
1394 /* Sends a ClientMessage to all toplevel client windows */
1396 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
1400 g_return_val_if_fail(event != NULL, FALSE);
1402 /* Set up our event to send, with the exception of its target window */
1403 sev.xclient.type = ClientMessage;
1404 sev.xclient.display = gdk_display;
1405 sev.xclient.format = event->client.data_format;
1406 sev.xclient.window = xid;
1407 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1408 sev.xclient.message_type = event->client.message_type;
1410 return gdk_send_xevent (xid, False, NoEventMask, &sev);
1413 /* Sends a ClientMessage to all toplevel client windows */
1415 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
1419 static GdkAtom wm_state_atom = GDK_NONE;
1422 unsigned long nitems, after;
1423 unsigned char *data;
1424 Window *ret_children, ret_root, ret_parent;
1425 unsigned int ret_nchildren;
1426 gint old_warnings = gdk_error_warnings;
1427 gboolean send = FALSE;
1428 gboolean found = FALSE;
1432 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
1434 gdk_error_warnings = FALSE;
1436 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
1437 &type, &format, &nitems, &after, &data);
1441 gdk_error_warnings = old_warnings;
1453 /* OK, we're all set, now let's find some windows to send this to */
1454 if (XQueryTree (gdk_display, xid, &ret_root, &ret_parent,
1455 &ret_children, &ret_nchildren) != True ||
1458 gdk_error_warnings = old_warnings;
1463 for(i = 0; i < ret_nchildren; i++)
1464 if (gdk_event_send_client_message_to_all_recurse (xev, ret_children[i], level + 1))
1467 XFree (ret_children);
1470 if (send || (!found && (level == 1)))
1472 xev->xclient.window = xid;
1473 gdk_send_xevent (xid, False, NoEventMask, xev);
1476 gdk_error_warnings = old_warnings;
1478 return (send || found);
1482 gdk_event_send_clientmessage_toall (GdkEvent *event)
1485 gint old_warnings = gdk_error_warnings;
1487 g_return_if_fail(event != NULL);
1489 /* Set up our event to send, with the exception of its target window */
1490 sev.xclient.type = ClientMessage;
1491 sev.xclient.display = gdk_display;
1492 sev.xclient.format = event->client.data_format;
1493 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
1494 sev.xclient.message_type = event->client.message_type;
1496 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
1498 gdk_error_warnings = old_warnings;
1502 *--------------------------------------------------------------
1505 * Flushes the Xlib output buffer and then waits
1506 * until all requests have been received and processed
1507 * by the X server. The only real use for this function
1508 * is in dealing with XShm.
1516 *--------------------------------------------------------------
1522 XSync (gdk_display, False);