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/.
29 #include "gdkprivate.h"
31 #include "gdkkeysyms.h"
41 typedef struct _GdkIOClosure GdkIOClosure;
42 typedef struct _GdkEventPrivate GdkEventPrivate;
44 #define DOUBLE_CLICK_TIME 250
45 #define TRIPLE_CLICK_TIME 500
46 #define DOUBLE_CLICK_DIST 5
47 #define TRIPLE_CLICK_DIST 5
51 /* Following flag is set for events on the event queue during
52 * translation and cleared afterwards.
54 GDK_EVENT_PENDING = 1 << 0
59 GdkInputFunction function;
60 GdkInputCondition condition;
61 GdkDestroyNotify notify;
65 struct _GdkEventPrivate
72 * Private function declarations
75 static GdkEvent *gdk_event_new (void);
76 static gint gdk_event_apply_filters (XEvent *xevent,
79 static gint gdk_event_translate (GdkEvent *event,
82 static Bool gdk_event_get_type (Display *display,
86 static void gdk_events_queue (void);
87 static GdkEvent* gdk_event_unqueue (void);
89 static gboolean gdk_event_prepare (gpointer source_data,
90 GTimeVal *current_time,
92 static gboolean gdk_event_check (gpointer source_data,
93 GTimeVal *current_time);
94 static gboolean gdk_event_dispatch (gpointer source_data,
95 GTimeVal *current_time,
98 static void gdk_synthesize_click (GdkEvent *event,
101 GdkFilterReturn gdk_wm_protocols_filter (GdkXEvent *xev,
105 /* Private variable declarations
108 static int connection_number = 0; /* The file descriptor number of our
109 * connection to the X server. This
110 * is used so that we may determine
111 * when events are pending by using
112 * the "select" system call.
114 static guint32 button_click_time[2]; /* The last 2 button click times. Used
115 * to determine if the latest button click
116 * is part of a double or triple click.
118 static GdkWindow *button_window[2]; /* The last 2 windows to receive button presses.
119 * Also used to determine if the latest button
120 * click is part of a double or triple click.
122 static guint button_number[2]; /* The last 2 buttons to be pressed.
124 static GdkEventFunc event_func = NULL; /* Callback for events */
125 static gpointer event_data = NULL;
126 static GDestroyNotify event_notify = NULL;
128 static GList *client_filters; /* Filters for client messages */
130 /* FIFO's for event queue, and for events put back using
133 static GList *queued_events = NULL;
134 static GList *queued_tail = NULL;
136 static GSourceFuncs event_funcs = {
140 (GDestroyNotify)g_free
143 GPollFD event_poll_fd;
145 /*********************************************
146 * Functions for maintaining the event queue *
147 *********************************************/
149 /*************************************************************
150 * gdk_event_queue_find_first:
151 * Find the first event on the queue that is not still
156 * Pointer to the list node for that event, or NULL
157 *************************************************************/
160 gdk_event_queue_find_first (void)
162 GList *tmp_list = queued_events;
166 GdkEventPrivate *event = tmp_list->data;
167 if (!(event->flags & GDK_EVENT_PENDING))
170 tmp_list = g_list_next (tmp_list);
176 /*************************************************************
177 * gdk_event_queue_remove_link:
178 * Remove a specified list node from the event queue.
180 * node: Node to remove.
182 *************************************************************/
185 gdk_event_queue_remove_link (GList *node)
188 node->prev->next = node->next;
190 queued_events = node->next;
193 node->next->prev = node->prev;
195 queued_tail = node->prev;
199 /*************************************************************
200 * gdk_event_queue_append:
201 * Append an event onto the tail of the event queue.
203 * event: Event to append.
205 *************************************************************/
208 gdk_event_queue_append (GdkEvent *event)
210 queued_tail = g_list_append (queued_tail, event);
213 queued_events = queued_tail;
215 queued_tail = queued_tail->next;
219 gdk_events_init (void)
221 connection_number = ConnectionNumber (gdk_display);
223 g_message ("connection number: %d", connection_number));
225 g_source_add (GDK_PRIORITY_EVENTS, TRUE, &event_funcs, NULL, NULL, NULL);
227 event_poll_fd.fd = connection_number;
228 event_poll_fd.events = G_IO_IN;
230 g_main_add_poll (&event_poll_fd, GDK_PRIORITY_EVENTS);
232 button_click_time[0] = 0;
233 button_click_time[1] = 0;
234 button_window[0] = NULL;
235 button_window[1] = NULL;
236 button_number[0] = -1;
237 button_number[1] = -1;
239 gdk_add_client_message_filter (gdk_wm_protocols,
240 gdk_wm_protocols_filter, NULL);
244 *--------------------------------------------------------------
247 * Returns if events are pending on the queue.
252 * Returns TRUE if events are pending
256 *--------------------------------------------------------------
260 gdk_events_pending (void)
262 return (gdk_event_queue_find_first() || XPending (gdk_display));
266 *--------------------------------------------------------------
267 * gdk_event_get_graphics_expose
269 * Waits for a GraphicsExpose or NoExpose event
274 * For GraphicsExpose events, returns a pointer to the event
275 * converted into a GdkEvent Otherwise, returns NULL.
279 *-------------------------------------------------------------- */
282 graphics_expose_predicate (Display *display,
286 GdkWindowPrivate *private = (GdkWindowPrivate*) arg;
288 g_return_val_if_fail (private != NULL, False);
290 if (xevent->xany.window == private->xwindow &&
291 (xevent->xany.type == GraphicsExpose ||
292 xevent->xany.type == NoExpose))
299 gdk_event_get_graphics_expose (GdkWindow *window)
304 g_return_val_if_fail (window != NULL, NULL);
306 XIfEvent (gdk_display, &xevent, graphics_expose_predicate, (XPointer) window);
308 if (xevent.xany.type == GraphicsExpose)
310 event = gdk_event_new ();
312 if (gdk_event_translate (event, &xevent))
315 gdk_event_free (event);
321 /************************
322 * Exposure compression *
323 ************************/
326 * The following implements simple exposure compression. It is
327 * modelled after the way Xt does exposure compression - in
328 * particular compress_expose = XtExposeCompressMultiple.
329 * It compress consecutive sequences of exposure events,
330 * but not sequences that cross other events. (This is because
331 * if it crosses a ConfigureNotify, we could screw up and
332 * mistakenly compress the exposures generated for the new
333 * size - could we just check for ConfigureNotify?)
335 * Xt compresses to a region / bounding rectangle, we compress
336 * to two rectangles, and try find the two rectangles of minimal
337 * area for this - this is supposed to handle the typical
338 * L-shaped regions generated by OpaqueMove.
341 /* Given three rectangles, find the two rectangles that cover
342 * them with the smallest area.
345 gdk_add_rect_to_rects (GdkRectangle *rect1,
347 GdkRectangle *new_rect)
349 GdkRectangle t1, t2, t3;
350 gint size1, size2, size3;
352 gdk_rectangle_union (rect1, rect2, &t1);
353 gdk_rectangle_union (rect1, new_rect, &t2);
354 gdk_rectangle_union (rect2, new_rect, &t3);
356 size1 = t1.width * t1.height + new_rect->width * new_rect->height;
357 size2 = t2.width * t2.height + rect2->width * rect2->height;
358 size3 = t1.width * t1.height + rect1->width * rect1->height;
379 typedef struct _GdkExposeInfo GdkExposeInfo;
381 struct _GdkExposeInfo
384 gboolean seen_nonmatching;
388 expose_predicate (Display *display,
392 GdkExposeInfo *info = (GdkExposeInfo*) arg;
394 /* Compressing across GravityNotify events is safe, because
395 * we completely ignore them, so they can't change what
396 * we are going to draw. Compressing across GravityNotify
397 * events is necessay because during window-unshading animation
398 * we'll get a whole bunch of them interspersed with
401 if (xevent->xany.type != Expose &&
402 xevent->xany.type != GravityNotify)
404 info->seen_nonmatching = TRUE;
407 if (info->seen_nonmatching ||
408 xevent->xany.type != Expose ||
409 xevent->xany.window != info->window)
416 gdk_compress_exposures (XEvent *xevent,
423 GdkRectangle tmp_rect;
425 GdkFilterReturn result;
429 info.window = xevent->xany.window;
430 info.seen_nonmatching = FALSE;
432 rect1.x = xevent->xexpose.x;
433 rect1.y = xevent->xexpose.y;
434 rect1.width = xevent->xexpose.width;
435 rect1.height = xevent->xexpose.height;
441 if (!XCheckIfEvent (gdk_display,
448 XIfEvent (gdk_display,
453 /* We apply filters here, and if it was filtered, completely
456 result = gdk_event_apply_filters (xevent, &event,
458 ((GdkWindowPrivate *)window)->filters
459 : gdk_default_filters);
461 if (result != GDK_FILTER_CONTINUE)
463 if (result == GDK_FILTER_TRANSLATE)
464 gdk_event_put (&event);
470 rect2.x = tmp_event.xexpose.x;
471 rect2.y = tmp_event.xexpose.y;
472 rect2.width = tmp_event.xexpose.width;
473 rect2.height = tmp_event.xexpose.height;
479 tmp_rect.x = tmp_event.xexpose.x;
480 tmp_rect.y = tmp_event.xexpose.y;
481 tmp_rect.width = tmp_event.xexpose.width;
482 tmp_rect.height = tmp_event.xexpose.height;
484 gdk_add_rect_to_rects (&rect1, &rect2, &tmp_rect);
487 count = tmp_event.xexpose.count;
492 gdk_rectangle_union (&rect1, &rect2, &tmp_rect);
494 if ((tmp_rect.width * tmp_rect.height) <
495 2 * (rect1.height * rect1.width +
496 rect2.height * rect2.width))
505 event.expose.type = GDK_EXPOSE;
506 event.expose.window = window;
507 event.expose.area.x = rect2.x;
508 event.expose.area.y = rect2.y;
509 event.expose.area.width = rect2.width;
510 event.expose.area.height = rect2.height;
511 event.expose.count = 0;
513 gdk_event_put (&event);
516 xevent->xexpose.count = nrects - 1;
517 xevent->xexpose.x = rect1.x;
518 xevent->xexpose.y = rect1.y;
519 xevent->xexpose.width = rect1.width;
520 xevent->xexpose.height = rect1.height;
523 /*************************************************************
524 * gdk_event_handler_set:
527 * func: Callback function to be called for each event.
528 * data: Data supplied to the function
529 * notify: function called when function is no longer needed
532 *************************************************************/
535 gdk_event_handler_set (GdkEventFunc func,
537 GDestroyNotify notify)
540 (*event_notify) (event_data);
544 event_notify = notify;
548 *--------------------------------------------------------------
551 * Gets the next event.
556 * If an event is waiting that we care about, returns
557 * a pointer to that event, to be freed with gdk_event_free.
558 * Otherwise, returns NULL.
562 *--------------------------------------------------------------
570 return gdk_event_unqueue ();
574 *--------------------------------------------------------------
577 * Gets the next event.
582 * If an event is waiting that we care about, returns
583 * a copy of that event, but does not remove it from
584 * the queue. The pointer is to be freed with gdk_event_free.
585 * Otherwise, returns NULL.
589 *--------------------------------------------------------------
593 gdk_event_peek (void)
597 tmp_list = gdk_event_queue_find_first ();
600 return gdk_event_copy (tmp_list->data);
606 gdk_event_put (GdkEvent *event)
610 g_return_if_fail (event != NULL);
612 new_event = gdk_event_copy (event);
614 gdk_event_queue_append (new_event);
618 *--------------------------------------------------------------
621 * Copy a event structure into new storage.
624 * "event" is the event struct to copy.
627 * A new event structure. Free it with gdk_event_free.
630 * The reference count of the window in the event is increased.
632 *--------------------------------------------------------------
635 static GMemChunk *event_chunk = NULL;
640 GdkEventPrivate *new_event;
642 if (event_chunk == NULL)
643 event_chunk = g_mem_chunk_new ("events",
644 sizeof (GdkEventPrivate),
648 new_event = g_chunk_new (GdkEventPrivate, event_chunk);
649 new_event->flags = 0;
651 return (GdkEvent*) new_event;
655 gdk_event_copy (GdkEvent *event)
659 g_return_val_if_fail (event != NULL, NULL);
661 new_event = gdk_event_new ();
664 gdk_window_ref (new_event->any.window);
666 switch (event->any.type)
669 case GDK_KEY_RELEASE:
670 new_event->key.string = g_strdup (event->key.string);
673 case GDK_ENTER_NOTIFY:
674 case GDK_LEAVE_NOTIFY:
675 if (event->crossing.subwindow != NULL)
676 gdk_window_ref (event->crossing.subwindow);
681 case GDK_DRAG_MOTION:
682 case GDK_DRAG_STATUS:
684 case GDK_DROP_FINISHED:
685 gdk_drag_context_ref (event->dnd.context);
696 *--------------------------------------------------------------
699 * Free a event structure obtained from gdk_event_copy. Do not use
700 * with other event structures.
703 * "event" is the event struct to free.
708 * The reference count of the window in the event is decreased and
709 * might be freed, too.
711 *-------------------------------------------------------------- */
714 gdk_event_free (GdkEvent *event)
716 g_return_if_fail (event != NULL);
718 g_assert (event_chunk != NULL); /* paranoid */
720 if (event->any.window)
721 gdk_window_unref (event->any.window);
723 switch (event->any.type)
726 case GDK_KEY_RELEASE:
727 g_free (event->key.string);
730 case GDK_ENTER_NOTIFY:
731 case GDK_LEAVE_NOTIFY:
732 if (event->crossing.subwindow != NULL)
733 gdk_window_unref (event->crossing.subwindow);
738 case GDK_DRAG_MOTION:
739 case GDK_DRAG_STATUS:
741 case GDK_DROP_FINISHED:
742 gdk_drag_context_unref (event->dnd.context);
749 g_mem_chunk_free (event_chunk, event);
753 *--------------------------------------------------------------
754 * gdk_event_get_time:
755 * Get the timestamp from an event.
759 * The event's time stamp, if it has one, otherwise
761 *--------------------------------------------------------------
765 gdk_event_get_time (GdkEvent *event)
770 case GDK_MOTION_NOTIFY:
771 return event->motion.time;
772 case GDK_BUTTON_PRESS:
773 case GDK_2BUTTON_PRESS:
774 case GDK_3BUTTON_PRESS:
775 case GDK_BUTTON_RELEASE:
776 return event->button.time;
778 case GDK_KEY_RELEASE:
779 return event->key.time;
780 case GDK_ENTER_NOTIFY:
781 case GDK_LEAVE_NOTIFY:
782 return event->crossing.time;
783 case GDK_PROPERTY_NOTIFY:
784 return event->property.time;
785 case GDK_SELECTION_CLEAR:
786 case GDK_SELECTION_REQUEST:
787 case GDK_SELECTION_NOTIFY:
788 return event->selection.time;
789 case GDK_PROXIMITY_IN:
790 case GDK_PROXIMITY_OUT:
791 return event->proximity.time;
794 case GDK_DRAG_MOTION:
795 case GDK_DRAG_STATUS:
797 case GDK_DROP_FINISHED:
798 return event->dnd.time;
799 default: /* use current time */
803 return GDK_CURRENT_TIME;
807 *--------------------------------------------------------------
808 * gdk_set_show_events
810 * Turns on/off the showing of events.
813 * "show_events" is a boolean describing whether or
814 * not to show the events gdk receives.
819 * When "show_events" is TRUE, calls to "gdk_event_get"
820 * will output debugging informatin regarding the event
821 * received to stdout.
823 *--------------------------------------------------------------
827 gdk_set_show_events (gint show_events)
830 gdk_debug_flags |= GDK_DEBUG_EVENTS;
832 gdk_debug_flags &= ~GDK_DEBUG_EVENTS;
836 gdk_get_show_events (void)
838 return gdk_debug_flags & GDK_DEBUG_EVENTS;
842 gdk_io_destroy (gpointer data)
844 GdkIOClosure *closure = data;
847 closure->notify (closure->data);
853 gdk_io_invoke (GIOChannel *source,
854 GIOCondition condition,
857 GdkIOClosure *closure = data;
858 GdkInputCondition gdk_cond = 0;
860 if (condition & (G_IO_IN | G_IO_PRI))
861 gdk_cond |= GDK_INPUT_READ;
862 if (condition & G_IO_OUT)
863 gdk_cond |= GDK_INPUT_WRITE;
864 if (condition & (G_IO_ERR | G_IO_HUP | G_IO_NVAL))
865 gdk_cond |= GDK_INPUT_EXCEPTION;
867 if (closure->condition & gdk_cond)
868 closure->function (closure->data, g_io_channel_unix_get_fd (source), gdk_cond);
874 gdk_input_add_full (gint source,
875 GdkInputCondition condition,
876 GdkInputFunction function,
878 GdkDestroyNotify destroy)
881 GdkIOClosure *closure = g_new (GdkIOClosure, 1);
883 GIOCondition cond = 0;
885 closure->function = function;
886 closure->condition = condition;
887 closure->notify = destroy;
888 closure->data = data;
890 if (condition & GDK_INPUT_READ)
891 cond |= (G_IO_IN | G_IO_PRI);
892 if (condition & GDK_INPUT_WRITE)
894 if (condition & GDK_INPUT_EXCEPTION)
895 cond |= G_IO_ERR|G_IO_HUP|G_IO_NVAL;
897 channel = g_io_channel_unix_new (source);
898 result = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, cond,
900 closure, gdk_io_destroy);
901 g_io_channel_unref (channel);
907 gdk_input_add (gint source,
908 GdkInputCondition condition,
909 GdkInputFunction function,
912 return gdk_input_add_full (source, condition, function, data, NULL);
916 gdk_input_remove (gint tag)
918 g_source_remove (tag);
922 gdk_event_apply_filters (XEvent *xevent,
926 GdkEventFilter *filter;
928 GdkFilterReturn result;
934 filter = (GdkEventFilter*) tmp_list->data;
936 result = (*filter->function) (xevent, event, filter->data);
937 if (result != GDK_FILTER_CONTINUE)
940 tmp_list = tmp_list->next;
943 return GDK_FILTER_CONTINUE;
947 gdk_add_client_message_filter (GdkAtom message_type,
951 GdkClientFilter *filter = g_new (GdkClientFilter, 1);
953 filter->type = message_type;
954 filter->function = func;
957 client_filters = g_list_prepend (client_filters, filter);
961 gdk_event_translate (GdkEvent *event,
966 GdkWindowPrivate *window_private;
967 static XComposeStatus compose;
971 static gchar* buf = NULL;
972 static gint buf_len= 0;
980 /* Find the GdkWindow that this event occurred in.
982 * We handle events with window=None
983 * specially - they are generated by XFree86's XInput under
984 * some circumstances.
987 if ((xevent->xany.window == None) &&
988 gdk_input_vtable.window_none_event)
990 return_val = gdk_input_vtable.window_none_event (event,xevent);
992 if (return_val >= 0) /* was handled */
998 window = gdk_window_lookup (xevent->xany.window);
999 window_private = (GdkWindowPrivate *) window;
1002 gdk_window_ref (window);
1004 event->any.window = window;
1005 event->any.send_event = xevent->xany.send_event;
1007 if (window_private && window_private->destroyed)
1009 if (xevent->type != DestroyNotify)
1014 /* Check for filters for this window
1016 GdkFilterReturn result;
1017 result = gdk_event_apply_filters (xevent, event,
1019 ?window_private->filters
1020 :gdk_default_filters);
1022 if (result != GDK_FILTER_CONTINUE)
1024 return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
1029 if (window == NULL && gdk_xim_window && xevent->type == KeyPress &&
1030 !((GdkWindowPrivate *) gdk_xim_window)->destroyed)
1033 * If user presses a key in Preedit or Status window, keypress event
1034 * is sometimes sent to these windows. These windows are not managed
1035 * by GDK, so we redirect KeyPress event to xim_window.
1037 * If someone want to use the window whitch is not managed by GDK
1038 * and want to get KeyPress event, he/she must register the filter
1039 * function to gdk_default_filters to intercept the event.
1042 GdkFilterReturn result;
1044 window = gdk_xim_window;
1045 window_private = (GdkWindowPrivate *) window;
1046 gdk_window_ref (window);
1047 event->any.window = window;
1050 g_message ("KeyPress event is redirected to xim_window: %#lx",
1051 xevent->xany.window));
1053 result = gdk_event_apply_filters (xevent, event,
1054 window_private->filters);
1055 if (result != GDK_FILTER_CONTINUE)
1056 return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
1061 g_message ("Got event for unknown window: %#lx\n", xevent->xany.window);
1063 /* We do a "manual" conversion of the XEvent to a
1064 * GdkEvent. The structures are mostly the same so
1065 * the conversion is fairly straightforward. We also
1066 * optionally print debugging info regarding events
1072 switch (xevent->type)
1075 /* Lookup the string corresponding to the given keysym.
1082 buf = g_new (gchar, buf_len);
1084 keysym = GDK_VoidSymbol;
1086 if (gdk_xim_ic && gdk_xim_ic->xic)
1090 /* Clear keyval. Depending on status, may not be set */
1091 charcount = XmbLookupString(gdk_xim_ic->xic,
1092 &xevent->xkey, buf, buf_len-1,
1094 if (status == XBufferOverflow)
1096 /* alloc adequate size of buffer */
1098 g_message("XIM: overflow (required %i)", charcount));
1100 while (buf_len <= charcount)
1102 buf = (gchar *) g_realloc (buf, buf_len);
1104 charcount = XmbLookupString (gdk_xim_ic->xic,
1105 &xevent->xkey, buf, buf_len-1,
1108 if (status == XLookupNone)
1115 charcount = XLookupString (&xevent->xkey, buf, buf_len,
1118 charcount = XLookupString (&xevent->xkey, buf, 16,
1121 event->key.keyval = keysym;
1123 if (charcount > 0 && buf[charcount-1] == '\0')
1126 buf[charcount] = '\0';
1128 /* Print debugging info. */
1130 #ifdef G_ENABLE_DEBUG
1131 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
1133 g_message ("key press:\twindow: %ld key: %12s %d",
1134 xevent->xkey.window,
1135 event->key.keyval ? XKeysymToString (event->key.keyval) : "(none)",
1138 g_message ("\t\tlength: %4d string: \"%s\"",
1141 #endif /* G_ENABLE_DEBUG */
1143 event->key.type = GDK_KEY_PRESS;
1144 event->key.window = window;
1145 event->key.time = xevent->xkey.time;
1146 event->key.state = (GdkModifierType) xevent->xkey.state;
1147 event->key.string = g_strdup (buf);
1148 event->key.length = charcount;
1153 /* Lookup the string corresponding to the given keysym.
1159 buf = g_new (gchar, buf_len);
1162 keysym = GDK_VoidSymbol;
1163 charcount = XLookupString (&xevent->xkey, buf, 16,
1165 event->key.keyval = keysym;
1167 /* Print debugging info.
1170 g_message ("key release:\t\twindow: %ld key: %12s %d",
1171 xevent->xkey.window,
1172 XKeysymToString (event->key.keyval),
1173 event->key.keyval));
1175 event->key.type = GDK_KEY_RELEASE;
1176 event->key.window = window;
1177 event->key.time = xevent->xkey.time;
1178 event->key.state = (GdkModifierType) xevent->xkey.state;
1179 event->key.length = 0;
1180 event->key.string = NULL;
1185 /* Print debugging info.
1188 g_message ("button press:\t\twindow: %ld x,y: %d %d button: %d",
1189 xevent->xbutton.window,
1190 xevent->xbutton.x, xevent->xbutton.y,
1191 xevent->xbutton.button));
1193 if (window_private &&
1194 (window_private->extension_events != 0) &&
1195 gdk_input_ignore_core)
1201 event->button.type = GDK_BUTTON_PRESS;
1202 event->button.window = window;
1203 event->button.time = xevent->xbutton.time;
1204 event->button.x = xevent->xbutton.x;
1205 event->button.y = xevent->xbutton.y;
1206 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1207 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1208 event->button.pressure = 0.5;
1209 event->button.xtilt = 0;
1210 event->button.ytilt = 0;
1211 event->button.state = (GdkModifierType) xevent->xbutton.state;
1212 event->button.button = xevent->xbutton.button;
1213 event->button.source = GDK_SOURCE_MOUSE;
1214 event->button.deviceid = GDK_CORE_POINTER;
1216 if ((event->button.time < (button_click_time[1] + TRIPLE_CLICK_TIME)) &&
1217 (event->button.window == button_window[1]) &&
1218 (event->button.button == button_number[1]))
1220 gdk_synthesize_click (event, 3);
1222 button_click_time[1] = 0;
1223 button_click_time[0] = 0;
1224 button_window[1] = NULL;
1225 button_window[0] = 0;
1226 button_number[1] = -1;
1227 button_number[0] = -1;
1229 else if ((event->button.time < (button_click_time[0] + DOUBLE_CLICK_TIME)) &&
1230 (event->button.window == button_window[0]) &&
1231 (event->button.button == button_number[0]))
1233 gdk_synthesize_click (event, 2);
1235 button_click_time[1] = button_click_time[0];
1236 button_click_time[0] = event->button.time;
1237 button_window[1] = button_window[0];
1238 button_window[0] = event->button.window;
1239 button_number[1] = button_number[0];
1240 button_number[0] = event->button.button;
1244 button_click_time[1] = 0;
1245 button_click_time[0] = event->button.time;
1246 button_window[1] = NULL;
1247 button_window[0] = event->button.window;
1248 button_number[1] = -1;
1249 button_number[0] = event->button.button;
1255 /* Print debugging info.
1258 g_message ("button release:\twindow: %ld x,y: %d %d button: %d",
1259 xevent->xbutton.window,
1260 xevent->xbutton.x, xevent->xbutton.y,
1261 xevent->xbutton.button));
1263 if (window_private &&
1264 (window_private->extension_events != 0) &&
1265 gdk_input_ignore_core)
1271 event->button.type = GDK_BUTTON_RELEASE;
1272 event->button.window = window;
1273 event->button.time = xevent->xbutton.time;
1274 event->button.x = xevent->xbutton.x;
1275 event->button.y = xevent->xbutton.y;
1276 event->button.x_root = (gfloat)xevent->xbutton.x_root;
1277 event->button.y_root = (gfloat)xevent->xbutton.y_root;
1278 event->button.pressure = 0.5;
1279 event->button.xtilt = 0;
1280 event->button.ytilt = 0;
1281 event->button.state = (GdkModifierType) xevent->xbutton.state;
1282 event->button.button = xevent->xbutton.button;
1283 event->button.source = GDK_SOURCE_MOUSE;
1284 event->button.deviceid = GDK_CORE_POINTER;
1289 /* Print debugging info.
1292 g_message ("motion notify:\t\twindow: %ld x,y: %d %d hint: %s",
1293 xevent->xmotion.window,
1294 xevent->xmotion.x, xevent->xmotion.y,
1295 (xevent->xmotion.is_hint) ? "true" : "false"));
1297 if (window_private &&
1298 (window_private->extension_events != 0) &&
1299 gdk_input_ignore_core)
1305 event->motion.type = GDK_MOTION_NOTIFY;
1306 event->motion.window = window;
1307 event->motion.time = xevent->xmotion.time;
1308 event->motion.x = xevent->xmotion.x;
1309 event->motion.y = xevent->xmotion.y;
1310 event->motion.x_root = (gfloat)xevent->xmotion.x_root;
1311 event->motion.y_root = (gfloat)xevent->xmotion.y_root;
1312 event->motion.pressure = 0.5;
1313 event->motion.xtilt = 0;
1314 event->motion.ytilt = 0;
1315 event->motion.state = (GdkModifierType) xevent->xmotion.state;
1316 event->motion.is_hint = xevent->xmotion.is_hint;
1317 event->motion.source = GDK_SOURCE_MOUSE;
1318 event->motion.deviceid = GDK_CORE_POINTER;
1323 /* Print debugging info.
1326 g_message ("enter notify:\t\twindow: %ld detail: %d subwin: %ld",
1327 xevent->xcrossing.window,
1328 xevent->xcrossing.detail,
1329 xevent->xcrossing.subwindow));
1331 /* Tell XInput stuff about it if appropriate */
1332 if (window_private &&
1333 !window_private->destroyed &&
1334 (window_private->extension_events != 0) &&
1335 gdk_input_vtable.enter_event)
1336 gdk_input_vtable.enter_event (&xevent->xcrossing, window);
1338 event->crossing.type = GDK_ENTER_NOTIFY;
1339 event->crossing.window = window;
1341 /* If the subwindow field of the XEvent is non-NULL, then
1342 * lookup the corresponding GdkWindow.
1344 if (xevent->xcrossing.subwindow != None)
1345 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
1347 event->crossing.subwindow = NULL;
1349 event->crossing.time = xevent->xcrossing.time;
1350 event->crossing.x = xevent->xcrossing.x;
1351 event->crossing.y = xevent->xcrossing.y;
1352 event->crossing.x_root = xevent->xcrossing.x_root;
1353 event->crossing.y_root = xevent->xcrossing.y_root;
1355 /* Translate the crossing mode into Gdk terms.
1357 switch (xevent->xcrossing.mode)
1360 event->crossing.mode = GDK_CROSSING_NORMAL;
1363 event->crossing.mode = GDK_CROSSING_GRAB;
1366 event->crossing.mode = GDK_CROSSING_UNGRAB;
1370 /* Translate the crossing detail into Gdk terms.
1372 switch (xevent->xcrossing.detail)
1374 case NotifyInferior:
1375 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1377 case NotifyAncestor:
1378 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1381 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1383 case NotifyNonlinear:
1384 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1386 case NotifyNonlinearVirtual:
1387 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1390 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1394 event->crossing.focus = xevent->xcrossing.focus;
1395 event->crossing.state = xevent->xcrossing.state;
1400 /* Print debugging info.
1403 g_message ("leave notify:\t\twindow: %ld detail: %d subwin: %ld",
1404 xevent->xcrossing.window,
1405 xevent->xcrossing.detail, xevent->xcrossing.subwindow));
1407 event->crossing.type = GDK_LEAVE_NOTIFY;
1408 event->crossing.window = window;
1410 /* If the subwindow field of the XEvent is non-NULL, then
1411 * lookup the corresponding GdkWindow.
1413 if (xevent->xcrossing.subwindow != None)
1414 event->crossing.subwindow = gdk_window_lookup (xevent->xcrossing.subwindow);
1416 event->crossing.subwindow = NULL;
1418 event->crossing.time = xevent->xcrossing.time;
1419 event->crossing.x = xevent->xcrossing.x;
1420 event->crossing.y = xevent->xcrossing.y;
1421 event->crossing.x_root = xevent->xcrossing.x_root;
1422 event->crossing.y_root = xevent->xcrossing.y_root;
1424 /* Translate the crossing mode into Gdk terms.
1426 switch (xevent->xcrossing.mode)
1429 event->crossing.mode = GDK_CROSSING_NORMAL;
1432 event->crossing.mode = GDK_CROSSING_GRAB;
1435 event->crossing.mode = GDK_CROSSING_UNGRAB;
1439 /* Translate the crossing detail into Gdk terms.
1441 switch (xevent->xcrossing.detail)
1443 case NotifyInferior:
1444 event->crossing.detail = GDK_NOTIFY_INFERIOR;
1446 case NotifyAncestor:
1447 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
1450 event->crossing.detail = GDK_NOTIFY_VIRTUAL;
1452 case NotifyNonlinear:
1453 event->crossing.detail = GDK_NOTIFY_NONLINEAR;
1455 case NotifyNonlinearVirtual:
1456 event->crossing.detail = GDK_NOTIFY_NONLINEAR_VIRTUAL;
1459 event->crossing.detail = GDK_NOTIFY_UNKNOWN;
1463 event->crossing.focus = xevent->xcrossing.focus;
1464 event->crossing.state = xevent->xcrossing.state;
1470 /* We only care about focus events that indicate that _this_
1471 * window (not a ancestor or child) got or lost the focus
1473 switch (xevent->xfocus.detail)
1475 case NotifyAncestor:
1476 case NotifyInferior:
1477 case NotifyNonlinear:
1478 /* Print debugging info.
1481 g_message ("focus %s:\t\twindow: %ld",
1482 (xevent->xany.type == FocusIn) ? "in" : "out",
1483 xevent->xfocus.window));
1485 /* gdk_keyboard_grab() causes following events. These events confuse
1486 * the XIM focus, so ignore them.
1488 if (xevent->xfocus.mode == NotifyGrab ||
1489 xevent->xfocus.mode == NotifyUngrab)
1492 event->focus_change.type = GDK_FOCUS_CHANGE;
1493 event->focus_change.window = window;
1494 event->focus_change.in = (xevent->xany.type == FocusIn);
1503 /* Print debugging info.
1506 g_message ("keymap notify"));
1508 /* Not currently handled */
1513 /* Print debugging info.
1516 g_message ("expose:\t\twindow: %ld %d x,y: %d %d w,h: %d %d",
1517 xevent->xexpose.window, xevent->xexpose.count,
1518 xevent->xexpose.x, xevent->xexpose.y,
1519 xevent->xexpose.width, xevent->xexpose.height));
1520 gdk_compress_exposures (xevent, window);
1522 event->expose.type = GDK_EXPOSE;
1523 event->expose.window = window;
1524 event->expose.area.x = xevent->xexpose.x;
1525 event->expose.area.y = xevent->xexpose.y;
1526 event->expose.area.width = xevent->xexpose.width;
1527 event->expose.area.height = xevent->xexpose.height;
1528 event->expose.count = xevent->xexpose.count;
1532 case GraphicsExpose:
1533 /* Print debugging info.
1536 g_message ("graphics expose:\tdrawable: %ld",
1537 xevent->xgraphicsexpose.drawable));
1539 event->expose.type = GDK_EXPOSE;
1540 event->expose.window = window;
1541 event->expose.area.x = xevent->xgraphicsexpose.x;
1542 event->expose.area.y = xevent->xgraphicsexpose.y;
1543 event->expose.area.width = xevent->xgraphicsexpose.width;
1544 event->expose.area.height = xevent->xgraphicsexpose.height;
1545 event->expose.count = xevent->xexpose.count;
1550 /* Print debugging info.
1553 g_message ("no expose:\t\tdrawable: %ld",
1554 xevent->xnoexpose.drawable));
1556 event->no_expose.type = GDK_NO_EXPOSE;
1557 event->no_expose.window = window;
1561 case VisibilityNotify:
1562 /* Print debugging info.
1564 #ifdef G_ENABLE_DEBUG
1565 if (gdk_debug_flags & GDK_DEBUG_EVENTS)
1566 switch (xevent->xvisibility.state)
1568 case VisibilityFullyObscured:
1569 g_message ("visibility notify:\twindow: %ld none",
1570 xevent->xvisibility.window);
1572 case VisibilityPartiallyObscured:
1573 g_message ("visibility notify:\twindow: %ld partial",
1574 xevent->xvisibility.window);
1576 case VisibilityUnobscured:
1577 g_message ("visibility notify:\twindow: %ld full",
1578 xevent->xvisibility.window);
1581 #endif /* G_ENABLE_DEBUG */
1583 event->visibility.type = GDK_VISIBILITY_NOTIFY;
1584 event->visibility.window = window;
1586 switch (xevent->xvisibility.state)
1588 case VisibilityFullyObscured:
1589 event->visibility.state = GDK_VISIBILITY_FULLY_OBSCURED;
1592 case VisibilityPartiallyObscured:
1593 event->visibility.state = GDK_VISIBILITY_PARTIAL;
1596 case VisibilityUnobscured:
1597 event->visibility.state = GDK_VISIBILITY_UNOBSCURED;
1604 /* Not currently handled */
1608 /* Print debugging info.
1611 g_message ("destroy notify:\twindow: %ld",
1612 xevent->xdestroywindow.window));
1614 event->any.type = GDK_DESTROY;
1615 event->any.window = window;
1617 return_val = window_private && !window_private->destroyed;
1619 if(window && window_private->xwindow != GDK_ROOT_WINDOW())
1620 gdk_window_destroy_notify (window);
1624 /* Print debugging info.
1627 g_message ("unmap notify:\t\twindow: %ld",
1628 xevent->xmap.window));
1630 event->any.type = GDK_UNMAP;
1631 event->any.window = window;
1633 if (gdk_xgrab_window == window_private)
1634 gdk_xgrab_window = NULL;
1639 /* Print debugging info.
1642 g_message ("map notify:\t\twindow: %ld",
1643 xevent->xmap.window));
1645 event->any.type = GDK_MAP;
1646 event->any.window = window;
1650 case ReparentNotify:
1651 /* Print debugging info.
1654 g_message ("reparent notify:\twindow: %ld",
1655 xevent->xreparent.window));
1657 /* Not currently handled */
1661 case ConfigureNotify:
1662 /* Print debugging info.
1664 while ((XPending (gdk_display) > 0) &&
1665 XCheckTypedWindowEvent(gdk_display, xevent->xany.window,
1666 ConfigureNotify, xevent))
1668 GdkFilterReturn result;
1671 g_message ("configure notify discarded:\twindow: %ld",
1672 xevent->xconfigure.window));
1674 result = gdk_event_apply_filters (xevent, event,
1676 ?window_private->filters
1677 :gdk_default_filters);
1679 /* If the result is GDK_FILTER_REMOVE, there will be
1680 * trouble, but anybody who filtering the Configure events
1681 * better know what they are doing
1683 if (result != GDK_FILTER_CONTINUE)
1685 return (result == GDK_FILTER_TRANSLATE) ? TRUE : FALSE;
1688 /*XSync (gdk_display, 0);*/
1693 g_message ("configure notify:\twindow: %ld x,y: %d %d w,h: %d %d b-w: %d above: %ld ovr: %d",
1694 xevent->xconfigure.window,
1695 xevent->xconfigure.x,
1696 xevent->xconfigure.y,
1697 xevent->xconfigure.width,
1698 xevent->xconfigure.height,
1699 xevent->xconfigure.border_width,
1700 xevent->xconfigure.above,
1701 xevent->xconfigure.override_redirect));
1703 if (!window_private->destroyed &&
1704 (window_private->extension_events != 0) &&
1705 gdk_input_vtable.configure_event)
1706 gdk_input_vtable.configure_event (&xevent->xconfigure, window);
1708 if (window_private->window_type == GDK_WINDOW_CHILD)
1712 event->configure.type = GDK_CONFIGURE;
1713 event->configure.window = window;
1714 event->configure.width = xevent->xconfigure.width;
1715 event->configure.height = xevent->xconfigure.height;
1717 if (!xevent->xconfigure.x &&
1718 !xevent->xconfigure.y &&
1719 !window_private->destroyed)
1723 Window child_window = 0;
1725 if (!XTranslateCoordinates (window_private->xdisplay,
1726 window_private->xwindow,
1731 g_warning ("GdkWindow %ld doesn't share root windows display?",
1732 window_private->xwindow);
1733 event->configure.x = tx;
1734 event->configure.y = ty;
1738 event->configure.x = xevent->xconfigure.x;
1739 event->configure.y = xevent->xconfigure.y;
1741 window_private->x = event->configure.x;
1742 window_private->y = event->configure.y;
1743 window_private->width = xevent->xconfigure.width;
1744 window_private->height = xevent->xconfigure.height;
1745 if (window_private->resize_count > 1)
1746 window_private->resize_count -= 1;
1750 case PropertyNotify:
1751 /* Print debugging info.
1754 g_message ("property notify:\twindow: %ld",
1755 xevent->xproperty.window));
1757 event->property.type = GDK_PROPERTY_NOTIFY;
1758 event->property.window = window;
1759 event->property.atom = xevent->xproperty.atom;
1760 event->property.time = xevent->xproperty.time;
1761 event->property.state = xevent->xproperty.state;
1765 case SelectionClear:
1767 g_message ("selection clear:\twindow: %ld",
1768 xevent->xproperty.window));
1770 event->selection.type = GDK_SELECTION_CLEAR;
1771 event->selection.window = window;
1772 event->selection.selection = xevent->xselectionclear.selection;
1773 event->selection.time = xevent->xselectionclear.time;
1777 case SelectionRequest:
1779 g_message ("selection request:\twindow: %ld",
1780 xevent->xproperty.window));
1782 event->selection.type = GDK_SELECTION_REQUEST;
1783 event->selection.window = window;
1784 event->selection.selection = xevent->xselectionrequest.selection;
1785 event->selection.target = xevent->xselectionrequest.target;
1786 event->selection.property = xevent->xselectionrequest.property;
1787 event->selection.requestor = xevent->xselectionrequest.requestor;
1788 event->selection.time = xevent->xselectionrequest.time;
1792 case SelectionNotify:
1794 g_message ("selection notify:\twindow: %ld",
1795 xevent->xproperty.window));
1798 event->selection.type = GDK_SELECTION_NOTIFY;
1799 event->selection.window = window;
1800 event->selection.selection = xevent->xselection.selection;
1801 event->selection.target = xevent->xselection.target;
1802 event->selection.property = xevent->xselection.property;
1803 event->selection.time = xevent->xselection.time;
1807 case ColormapNotify:
1808 /* Print debugging info.
1811 g_message ("colormap notify:\twindow: %ld",
1812 xevent->xcolormap.window));
1814 /* Not currently handled */
1821 GdkFilterReturn result = GDK_FILTER_CONTINUE;
1823 /* Print debugging info.
1826 g_message ("client message:\twindow: %ld",
1827 xevent->xclient.window));
1829 tmp_list = client_filters;
1832 GdkClientFilter *filter = tmp_list->data;
1833 if (filter->type == xevent->xclient.message_type)
1835 result = (*filter->function) (xevent, event, filter->data);
1839 tmp_list = tmp_list->next;
1844 case GDK_FILTER_REMOVE:
1847 case GDK_FILTER_TRANSLATE:
1850 case GDK_FILTER_CONTINUE:
1851 /* Send unknown ClientMessage's on to Gtk for it to use */
1852 event->client.type = GDK_CLIENT_EVENT;
1853 event->client.window = window;
1854 event->client.message_type = xevent->xclient.message_type;
1855 event->client.data_format = xevent->xclient.format;
1856 memcpy(&event->client.data, &xevent->xclient.data,
1857 sizeof(event->client.data));
1864 /* Print debugging info.
1867 g_message ("mapping notify"));
1869 /* Let XLib know that there is a new keyboard mapping.
1871 XRefreshKeyboardMapping (&xevent->xmapping);
1876 /* something else - (e.g., a Xinput event) */
1878 if (window_private &&
1879 !window_private->destroyed &&
1880 (window_private->extension_events != 0) &&
1881 gdk_input_vtable.other_event)
1882 return_val = gdk_input_vtable.other_event(event, xevent, window);
1891 if (event->any.window)
1892 gdk_window_ref (event->any.window);
1893 if (((event->any.type == GDK_ENTER_NOTIFY) ||
1894 (event->any.type == GDK_LEAVE_NOTIFY)) &&
1895 (event->crossing.subwindow != NULL))
1896 gdk_window_ref (event->crossing.subwindow);
1900 /* Mark this event as having no resources to be freed */
1901 event->any.window = NULL;
1902 event->any.type = GDK_NOTHING;
1906 gdk_window_unref (window);
1912 gdk_wm_protocols_filter (GdkXEvent *xev,
1916 XEvent *xevent = (XEvent *)xev;
1918 if ((Atom) xevent->xclient.data.l[0] == gdk_wm_delete_window)
1920 /* The delete window request specifies a window
1921 * to delete. We don't actually destroy the
1922 * window because "it is only a request". (The
1923 * window might contain vital data that the
1924 * program does not want destroyed). Instead
1925 * the event is passed along to the program,
1926 * which should then destroy the window.
1929 g_message ("delete window:\t\twindow: %ld",
1930 xevent->xclient.window));
1932 event->any.type = GDK_DELETE;
1934 return GDK_FILTER_TRANSLATE;
1936 else if ((Atom) xevent->xclient.data.l[0] == gdk_wm_take_focus)
1940 return GDK_FILTER_REMOVE;
1945 gdk_event_get_type (Display *display,
1952 if (gdk_event_translate (&event, xevent))
1954 pred = (GdkPredicate*) arg;
1955 return (* pred->func) (&event, pred->data);
1963 gdk_events_queue (void)
1969 while (!gdk_event_queue_find_first() && XPending (gdk_display))
1974 XNextEvent (gdk_display, &xevent);
1976 switch (xevent.type)
1982 w = GDK_WINDOW_XWINDOW (gdk_xim_window);
1986 if (XFilterEvent (&xevent, w))
1989 XNextEvent (gdk_display, &xevent);
1992 event = gdk_event_new ();
1994 event->any.type = GDK_NOTHING;
1995 event->any.window = NULL;
1996 event->any.send_event = FALSE;
1997 event->any.send_event = xevent.xany.send_event;
1999 ((GdkEventPrivate *)event)->flags |= GDK_EVENT_PENDING;
2001 gdk_event_queue_append (event);
2004 if (gdk_event_translate (event, &xevent))
2006 ((GdkEventPrivate *)event)->flags &= ~GDK_EVENT_PENDING;
2010 gdk_event_queue_remove_link (node);
2011 g_list_free_1 (node);
2012 gdk_event_free (event);
2018 gdk_event_prepare (gpointer source_data,
2019 GTimeVal *current_time,
2024 GDK_THREADS_ENTER ();
2028 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
2030 GDK_THREADS_LEAVE ();
2036 gdk_event_check (gpointer source_data,
2037 GTimeVal *current_time)
2041 GDK_THREADS_ENTER ();
2043 if (event_poll_fd.revents & G_IO_IN)
2044 retval = (gdk_event_queue_find_first () != NULL) || XPending (gdk_display);
2048 GDK_THREADS_LEAVE ();
2054 gdk_event_unqueue (void)
2056 GdkEvent *event = NULL;
2059 tmp_list = gdk_event_queue_find_first ();
2063 event = tmp_list->data;
2064 gdk_event_queue_remove_link (tmp_list);
2065 g_list_free_1 (tmp_list);
2072 gdk_event_dispatch (gpointer source_data,
2073 GTimeVal *current_time,
2078 GDK_THREADS_ENTER ();
2081 event = gdk_event_unqueue();
2086 (*event_func) (event, event_data);
2088 gdk_event_free (event);
2091 GDK_THREADS_LEAVE ();
2097 gdk_synthesize_click (GdkEvent *event,
2100 GdkEvent temp_event;
2102 g_return_if_fail (event != NULL);
2104 temp_event = *event;
2105 temp_event.type = (nclicks == 2) ? GDK_2BUTTON_PRESS : GDK_3BUTTON_PRESS;
2107 gdk_event_put (&temp_event);
2110 /* Sends a ClientMessage to all toplevel client windows */
2112 gdk_event_send_client_message (GdkEvent *event, guint32 xid)
2116 g_return_val_if_fail(event != NULL, FALSE);
2118 /* Set up our event to send, with the exception of its target window */
2119 sev.xclient.type = ClientMessage;
2120 sev.xclient.display = gdk_display;
2121 sev.xclient.format = event->client.data_format;
2122 sev.xclient.window = xid;
2123 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
2124 sev.xclient.message_type = event->client.message_type;
2126 return gdk_send_xevent (xid, False, NoEventMask, &sev);
2129 /* Sends a ClientMessage to all toplevel client windows */
2131 gdk_event_send_client_message_to_all_recurse (XEvent *xev,
2135 static GdkAtom wm_state_atom = GDK_NONE;
2139 unsigned long nitems, after;
2140 unsigned char *data;
2142 Window *ret_children, ret_root, ret_parent;
2143 unsigned int ret_nchildren;
2146 gboolean send = FALSE;
2147 gboolean found = FALSE;
2150 wm_state_atom = gdk_atom_intern ("WM_STATE", FALSE);
2153 XGetWindowProperty (gdk_display, xid, wm_state_atom, 0, 0, False, AnyPropertyType,
2154 &type, &format, &nitems, &after, &data);
2169 /* OK, we're all set, now let's find some windows to send this to */
2170 if (XQueryTree(gdk_display, xid, &ret_root, &ret_parent,
2171 &ret_children, &ret_nchildren) != True)
2177 for(i = 0; i < ret_nchildren; i++)
2178 if (gdk_event_send_client_message_to_all_recurse(xev, ret_children[i], level + 1))
2181 XFree(ret_children);
2184 if (send || (!found && (level == 1)))
2186 xev->xclient.window = xid;
2187 gdk_send_xevent (xid, False, NoEventMask, xev);
2190 return (send || found);
2194 gdk_event_send_clientmessage_toall (GdkEvent *event)
2197 gint old_warnings = gdk_error_warnings;
2199 g_return_if_fail(event != NULL);
2201 /* Set up our event to send, with the exception of its target window */
2202 sev.xclient.type = ClientMessage;
2203 sev.xclient.display = gdk_display;
2204 sev.xclient.format = event->client.data_format;
2205 memcpy(&sev.xclient.data, &event->client.data, sizeof(sev.xclient.data));
2206 sev.xclient.message_type = event->client.message_type;
2208 gdk_event_send_client_message_to_all_recurse(&sev, gdk_root_window, 0);
2210 gdk_error_warnings = old_warnings;
2214 *--------------------------------------------------------------
2217 * Flushes the Xlib output buffer and then waits
2218 * until all requests have been received and processed
2219 * by the X server. The only real use for this function
2220 * is in dealing with XShm.
2228 *--------------------------------------------------------------
2234 XSync (gdk_display, False);