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/.
29 #include "gdkinternals.h"
37 * @Short_description: Functions for handling events from the window system
39 * @See_also: <link linkend="gdk-Event-Structures">Event Structures</link>
41 * This section describes functions dealing with events from the window
44 * In GTK+ applications the events are handled automatically in
45 * gtk_main_do_event() and passed on to the appropriate widgets, so these
46 * functions are rarely needed. Though some of the fields in the
47 * <link linkend="gdk-Event-Structures">Event Structures</link> are useful.
51 typedef struct _GdkIOClosure GdkIOClosure;
55 GDestroyNotify notify;
59 /* Private variable declarations
62 static GdkEventFunc _gdk_event_func = NULL; /* Callback for events */
63 static gpointer _gdk_event_data = NULL;
64 static GDestroyNotify _gdk_event_notify = NULL;
67 _gdk_event_emit (GdkEvent *event)
70 (*_gdk_event_func) (event, _gdk_event_data);
73 /*********************************************
74 * Functions for maintaining the event queue *
75 *********************************************/
78 * _gdk_event_queue_find_first:
79 * @display: a #GdkDisplay
81 * Find the first event on the queue that is not still
84 * Return value: Pointer to the list node for that event, or NULL.
87 _gdk_event_queue_find_first (GdkDisplay *display)
89 GList *tmp_list = display->queued_events;
93 GdkEventPrivate *event = tmp_list->data;
94 if (!(event->flags & GDK_EVENT_PENDING))
97 tmp_list = g_list_next (tmp_list);
104 * _gdk_event_queue_prepend:
105 * @display: a #GdkDisplay
106 * @event: Event to prepend.
108 * Prepends an event before the head of the event queue.
110 * Returns: the newly prepended list node.
113 _gdk_event_queue_prepend (GdkDisplay *display,
116 display->queued_events = g_list_prepend (display->queued_events, event);
117 if (!display->queued_tail)
118 display->queued_tail = display->queued_events;
119 return display->queued_events;
123 * _gdk_event_queue_append:
124 * @display: a #GdkDisplay
125 * @event: Event to append.
127 * Appends an event onto the tail of the event queue.
129 * Returns: the newly appended list node.
132 _gdk_event_queue_append (GdkDisplay *display,
135 display->queued_tail = g_list_append (display->queued_tail, event);
137 if (!display->queued_events)
138 display->queued_events = display->queued_tail;
140 display->queued_tail = display->queued_tail->next;
142 return display->queued_tail;
146 * _gdk_event_queue_insert_after:
147 * @display: a #GdkDisplay
148 * @sibling: Append after this event.
149 * @event: Event to append.
151 * Appends an event after the specified event, or if it isn't in
152 * the queue, onto the tail of the event queue.
154 * Returns: the newly appended list node.
159 _gdk_event_queue_insert_after (GdkDisplay *display,
163 GList *prev = g_list_find (display->queued_events, sibling);
164 if (prev && prev->next)
166 display->queued_events = g_list_insert_before (display->queued_events, prev->next, event);
170 return _gdk_event_queue_append (display, event);
174 * _gdk_event_queue_insert_after:
175 * @display: a #GdkDisplay
176 * @sibling: Append after this event.
177 * @event: Event to append.
179 * Appends an event before the specified event, or if it isn't in
180 * the queue, onto the tail of the event queue.
182 * Returns: the newly appended list node.
187 _gdk_event_queue_insert_before (GdkDisplay *display,
191 GList *next = g_list_find (display->queued_events, sibling);
194 display->queued_events = g_list_insert_before (display->queued_events, next, event);
198 return _gdk_event_queue_append (display, event);
203 * _gdk_event_queue_remove_link:
204 * @display: a #GdkDisplay
205 * @node: node to remove
207 * Removes a specified list node from the event queue.
210 _gdk_event_queue_remove_link (GdkDisplay *display,
214 node->prev->next = node->next;
216 display->queued_events = node->next;
219 node->next->prev = node->prev;
221 display->queued_tail = node->prev;
225 * _gdk_event_unqueue:
226 * @display: a #GdkDisplay
228 * Removes and returns the first event from the event
229 * queue that is not still being filled in.
231 * Return value: the event, or %NULL. Ownership is transferred
235 _gdk_event_unqueue (GdkDisplay *display)
237 GdkEvent *event = NULL;
240 tmp_list = _gdk_event_queue_find_first (display);
244 event = tmp_list->data;
245 _gdk_event_queue_remove_link (display, tmp_list);
246 g_list_free_1 (tmp_list);
253 * gdk_event_handler_set:
254 * @func: the function to call to handle events from GDK.
255 * @data: user data to pass to the function.
256 * @notify: the function to call when the handler function is removed, i.e. when
257 * gdk_event_handler_set() is called with another event handler.
259 * Sets the function to call to handle all events from GDK.
261 * Note that GTK+ uses this to install its own event handler, so it is
262 * usually not useful for GTK+ applications. (Although an application
263 * can call this function then call gtk_main_do_event() to pass
267 gdk_event_handler_set (GdkEventFunc func,
269 GDestroyNotify notify)
271 if (_gdk_event_notify)
272 (*_gdk_event_notify) (_gdk_event_data);
274 _gdk_event_func = func;
275 _gdk_event_data = data;
276 _gdk_event_notify = notify;
282 * Checks all open displays for a #GdkEvent to process,to be processed
283 * on, fetching events from the windowing system if necessary.
284 * See gdk_display_get_event().
286 * Return value: the next #GdkEvent to be processed, or %NULL if no events
287 * are pending. The returned #GdkEvent should be freed with gdk_event_free().
294 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
296 GdkEvent *event = gdk_display_get_event (tmp_list->data);
307 * If there is an event waiting in the event queue of some open
308 * display, returns a copy of it. See gdk_display_peek_event().
310 * Return value: a copy of the first #GdkEvent on some event queue, or %NULL if no
311 * events are in any queues. The returned #GdkEvent should be freed with
315 gdk_event_peek (void)
319 for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
321 GdkEvent *event = gdk_display_peek_event (tmp_list->data);
331 * @event: a #GdkEvent.
333 * Appends a copy of the given event onto the front of the event
334 * queue for event->any.window's display, or the default event
335 * queue if event->any.window is %NULL. See gdk_display_put_event().
338 gdk_event_put (const GdkEvent *event)
342 g_return_if_fail (event != NULL);
344 if (event->any.window)
345 display = gdk_window_get_display (event->any.window);
349 g_message ("Falling back to default display for gdk_event_put()"));
350 display = gdk_display_get_default ();
353 gdk_display_put_event (display, event);
356 static GHashTable *event_hash = NULL;
360 * @type: a #GdkEventType
362 * Creates a new event of the given type. All fields are set to 0.
364 * Return value: a newly-allocated #GdkEvent. The returned #GdkEvent
365 * should be freed with gdk_event_free().
370 gdk_event_new (GdkEventType type)
372 GdkEventPrivate *new_private;
376 event_hash = g_hash_table_new (g_direct_hash, NULL);
378 new_private = g_slice_new0 (GdkEventPrivate);
380 new_private->flags = 0;
381 new_private->screen = NULL;
383 g_hash_table_insert (event_hash, new_private, GUINT_TO_POINTER (1));
385 new_event = (GdkEvent *) new_private;
387 new_event->any.type = type;
390 * Bytewise 0 initialization is reasonable for most of the
391 * current event types. Explicitely initialize double fields
392 * since I trust bytewise 0 == 0. less than for integers
397 case GDK_MOTION_NOTIFY:
398 new_event->motion.x = 0.;
399 new_event->motion.y = 0.;
400 new_event->motion.x_root = 0.;
401 new_event->motion.y_root = 0.;
403 case GDK_BUTTON_PRESS:
404 case GDK_2BUTTON_PRESS:
405 case GDK_3BUTTON_PRESS:
406 case GDK_BUTTON_RELEASE:
407 new_event->button.x = 0.;
408 new_event->button.y = 0.;
409 new_event->button.x_root = 0.;
410 new_event->button.y_root = 0.;
413 new_event->scroll.x = 0.;
414 new_event->scroll.y = 0.;
415 new_event->scroll.x_root = 0.;
416 new_event->scroll.y_root = 0.;
418 case GDK_ENTER_NOTIFY:
419 case GDK_LEAVE_NOTIFY:
420 new_event->crossing.x = 0.;
421 new_event->crossing.y = 0.;
422 new_event->crossing.x_root = 0.;
423 new_event->crossing.y_root = 0.;
433 gdk_event_is_allocated (const GdkEvent *event)
436 return g_hash_table_lookup (event_hash, event) != NULL;
443 * @event: a #GdkEvent
445 * Copies a #GdkEvent, copying or incrementing the reference count of the
446 * resources associated with it (e.g. #GdkWindow's and strings).
448 * Return value: a copy of @event. The returned #GdkEvent should be freed with
452 gdk_event_copy (const GdkEvent *event)
454 GdkEventPrivate *new_private;
457 g_return_val_if_fail (event != NULL, NULL);
459 new_event = gdk_event_new (GDK_NOTHING);
460 new_private = (GdkEventPrivate *)new_event;
463 if (new_event->any.window)
464 g_object_ref (new_event->any.window);
466 if (gdk_event_is_allocated (event))
468 GdkEventPrivate *private = (GdkEventPrivate *)event;
470 new_private->screen = private->screen;
471 new_private->device = private->device;
474 switch (event->any.type)
477 case GDK_KEY_RELEASE:
478 new_event->key.string = g_strdup (event->key.string);
481 case GDK_ENTER_NOTIFY:
482 case GDK_LEAVE_NOTIFY:
483 if (event->crossing.subwindow != NULL)
484 g_object_ref (event->crossing.subwindow);
489 case GDK_DRAG_MOTION:
490 case GDK_DRAG_STATUS:
492 case GDK_DROP_FINISHED:
493 g_object_ref (event->dnd.context);
498 if (event->expose.region)
499 new_event->expose.region = cairo_region_copy (event->expose.region);
503 new_event->setting.name = g_strdup (new_event->setting.name);
506 case GDK_BUTTON_PRESS:
507 case GDK_BUTTON_RELEASE:
508 if (event->button.axes)
509 new_event->button.axes = g_memdup (event->button.axes,
510 sizeof (gdouble) * gdk_device_get_n_axes (event->button.device));
513 case GDK_MOTION_NOTIFY:
514 if (event->motion.axes)
515 new_event->motion.axes = g_memdup (event->motion.axes,
516 sizeof (gdouble) * gdk_device_get_n_axes (event->motion.device));
523 if (gdk_event_is_allocated (event))
524 _gdk_windowing_event_data_copy (event, new_event);
531 * @event: a #GdkEvent.
533 * Frees a #GdkEvent, freeing or decrementing any resources associated with it.
534 * Note that this function should only be called with events returned from
535 * functions such as gdk_event_peek(), gdk_event_get(), gdk_event_copy()
536 * and gdk_event_new().
539 gdk_event_free (GdkEvent *event)
541 g_return_if_fail (event != NULL);
543 if (event->any.window)
544 g_object_unref (event->any.window);
546 switch (event->any.type)
549 case GDK_KEY_RELEASE:
550 g_free (event->key.string);
553 case GDK_ENTER_NOTIFY:
554 case GDK_LEAVE_NOTIFY:
555 if (event->crossing.subwindow != NULL)
556 g_object_unref (event->crossing.subwindow);
561 case GDK_DRAG_MOTION:
562 case GDK_DRAG_STATUS:
564 case GDK_DROP_FINISHED:
565 if (event->dnd.context != NULL)
566 g_object_unref (event->dnd.context);
569 case GDK_BUTTON_PRESS:
570 case GDK_BUTTON_RELEASE:
571 g_free (event->button.axes);
576 if (event->expose.region)
577 cairo_region_destroy (event->expose.region);
580 case GDK_MOTION_NOTIFY:
581 g_free (event->motion.axes);
585 g_free (event->setting.name);
592 _gdk_windowing_event_data_free (event);
594 g_hash_table_remove (event_hash, event);
595 g_slice_free (GdkEventPrivate, (GdkEventPrivate*) event);
599 * gdk_event_get_time:
600 * @event: a #GdkEvent
602 * Returns the time stamp from @event, if there is one; otherwise
603 * returns #GDK_CURRENT_TIME. If @event is %NULL, returns #GDK_CURRENT_TIME.
605 * Return value: time stamp field from @event
608 gdk_event_get_time (const GdkEvent *event)
613 case GDK_MOTION_NOTIFY:
614 return event->motion.time;
615 case GDK_BUTTON_PRESS:
616 case GDK_2BUTTON_PRESS:
617 case GDK_3BUTTON_PRESS:
618 case GDK_BUTTON_RELEASE:
619 return event->button.time;
621 return event->scroll.time;
623 case GDK_KEY_RELEASE:
624 return event->key.time;
625 case GDK_ENTER_NOTIFY:
626 case GDK_LEAVE_NOTIFY:
627 return event->crossing.time;
628 case GDK_PROPERTY_NOTIFY:
629 return event->property.time;
630 case GDK_SELECTION_CLEAR:
631 case GDK_SELECTION_REQUEST:
632 case GDK_SELECTION_NOTIFY:
633 return event->selection.time;
634 case GDK_PROXIMITY_IN:
635 case GDK_PROXIMITY_OUT:
636 return event->proximity.time;
639 case GDK_DRAG_MOTION:
640 case GDK_DRAG_STATUS:
642 case GDK_DROP_FINISHED:
643 return event->dnd.time;
644 case GDK_CLIENT_EVENT:
645 case GDK_VISIBILITY_NOTIFY:
647 case GDK_FOCUS_CHANGE:
655 case GDK_WINDOW_STATE:
657 case GDK_OWNER_CHANGE:
658 case GDK_GRAB_BROKEN:
660 /* return current time */
664 return GDK_CURRENT_TIME;
668 * gdk_event_get_state:
669 * @event: a #GdkEvent or NULL
670 * @state: (out): return location for state
672 * If the event contains a "state" field, puts that field in @state. Otherwise
673 * stores an empty state (0). Returns %TRUE if there was a state field
674 * in the event. @event may be %NULL, in which case it's treated
675 * as if the event had no state field.
677 * Return value: %TRUE if there was a state field in the event
680 gdk_event_get_state (const GdkEvent *event,
681 GdkModifierType *state)
683 g_return_val_if_fail (state != NULL, FALSE);
688 case GDK_MOTION_NOTIFY:
689 *state = event->motion.state;
691 case GDK_BUTTON_PRESS:
692 case GDK_2BUTTON_PRESS:
693 case GDK_3BUTTON_PRESS:
694 case GDK_BUTTON_RELEASE:
695 *state = event->button.state;
698 *state = event->scroll.state;
701 case GDK_KEY_RELEASE:
702 *state = event->key.state;
704 case GDK_ENTER_NOTIFY:
705 case GDK_LEAVE_NOTIFY:
706 *state = event->crossing.state;
708 case GDK_PROPERTY_NOTIFY:
709 *state = event->property.state;
711 case GDK_VISIBILITY_NOTIFY:
712 case GDK_CLIENT_EVENT:
714 case GDK_FOCUS_CHANGE:
715 case GDK_SELECTION_CLEAR:
716 case GDK_SELECTION_REQUEST:
717 case GDK_SELECTION_NOTIFY:
718 case GDK_PROXIMITY_IN:
719 case GDK_PROXIMITY_OUT:
723 case GDK_DRAG_MOTION:
724 case GDK_DRAG_STATUS:
726 case GDK_DROP_FINISHED:
733 case GDK_WINDOW_STATE:
735 case GDK_OWNER_CHANGE:
736 case GDK_GRAB_BROKEN:
747 * gdk_event_get_coords:
748 * @event: a #GdkEvent
749 * @x_win: (out): location to put event window x coordinate
750 * @y_win: (out): location to put event window y coordinate
752 * Extract the event window relative x/y coordinates from an event.
754 * Return value: %TRUE if the event delivered event window coordinates
757 gdk_event_get_coords (const GdkEvent *event,
761 gdouble x = 0, y = 0;
762 gboolean fetched = TRUE;
764 g_return_val_if_fail (event != NULL, FALSE);
769 x = event->configure.x;
770 y = event->configure.y;
772 case GDK_ENTER_NOTIFY:
773 case GDK_LEAVE_NOTIFY:
774 x = event->crossing.x;
775 y = event->crossing.y;
781 case GDK_BUTTON_PRESS:
782 case GDK_2BUTTON_PRESS:
783 case GDK_3BUTTON_PRESS:
784 case GDK_BUTTON_RELEASE:
788 case GDK_MOTION_NOTIFY:
806 * gdk_event_get_root_coords:
807 * @event: a #GdkEvent
808 * @x_root: (out): location to put root window x coordinate
809 * @y_root: (out): location to put root window y coordinate
811 * Extract the root window relative x/y coordinates from an event.
813 * Return value: %TRUE if the event delivered root window coordinates
816 gdk_event_get_root_coords (const GdkEvent *event,
820 gdouble x = 0, y = 0;
821 gboolean fetched = TRUE;
823 g_return_val_if_fail (event != NULL, FALSE);
827 case GDK_MOTION_NOTIFY:
828 x = event->motion.x_root;
829 y = event->motion.y_root;
832 x = event->scroll.x_root;
833 y = event->scroll.y_root;
835 case GDK_BUTTON_PRESS:
836 case GDK_2BUTTON_PRESS:
837 case GDK_3BUTTON_PRESS:
838 case GDK_BUTTON_RELEASE:
839 x = event->button.x_root;
840 y = event->button.y_root;
842 case GDK_ENTER_NOTIFY:
843 case GDK_LEAVE_NOTIFY:
844 x = event->crossing.x_root;
845 y = event->crossing.y_root;
849 case GDK_DRAG_MOTION:
850 case GDK_DRAG_STATUS:
852 case GDK_DROP_FINISHED:
853 x = event->dnd.x_root;
854 y = event->dnd.y_root;
870 * gdk_event_get_axis:
871 * @event: a #GdkEvent
872 * @axis_use: (out): the axis use to look for
873 * @value: (out): location to store the value found
875 * Extract the axis value for a particular axis use from
876 * an event structure.
878 * Return value: %TRUE if the specified axis was found, otherwise %FALSE
881 gdk_event_get_axis (const GdkEvent *event,
888 g_return_val_if_fail (event != NULL, FALSE);
890 if (axis_use == GDK_AXIS_X || axis_use == GDK_AXIS_Y)
896 case GDK_MOTION_NOTIFY:
904 case GDK_BUTTON_PRESS:
905 case GDK_BUTTON_RELEASE:
909 case GDK_ENTER_NOTIFY:
910 case GDK_LEAVE_NOTIFY:
911 x = event->crossing.x;
912 y = event->crossing.y;
919 if (axis_use == GDK_AXIS_X && value)
921 if (axis_use == GDK_AXIS_Y && value)
926 else if (event->type == GDK_BUTTON_PRESS ||
927 event->type == GDK_BUTTON_RELEASE)
929 device = event->button.device;
930 axes = event->button.axes;
932 else if (event->type == GDK_MOTION_NOTIFY)
934 device = event->motion.device;
935 axes = event->motion.axes;
940 return gdk_device_get_axis (device, axes, axis_use, value);
944 * gdk_event_set_device:
945 * @event: a #GdkEvent
946 * @device: a #GdkDevice
948 * Sets the device for @event to @device. The event must
949 * have been allocated by GTK+, for instance, by
955 gdk_event_set_device (GdkEvent *event,
958 GdkEventPrivate *private;
960 g_return_if_fail (gdk_event_is_allocated (event));
962 private = (GdkEventPrivate *) event;
964 private->device = device;
968 case GDK_MOTION_NOTIFY:
969 event->motion.device = device;
971 case GDK_BUTTON_PRESS:
972 case GDK_2BUTTON_PRESS:
973 case GDK_3BUTTON_PRESS:
974 case GDK_BUTTON_RELEASE:
975 event->button.device = device;
978 event->scroll.device = device;
980 case GDK_PROXIMITY_IN:
981 case GDK_PROXIMITY_OUT:
982 event->proximity.device = device;
990 * gdk_event_get_device:
991 * @event: a #GdkEvent.
993 * If the event contains a "device" field, this function will return
994 * it, else it will return %NULL.
996 * Returns: (transfer none): a #GdkDevice, or %NULL.
1001 gdk_event_get_device (const GdkEvent *event)
1003 g_return_val_if_fail (event != NULL, NULL);
1005 if (gdk_event_is_allocated (event))
1007 GdkEventPrivate *private = (GdkEventPrivate *) event;
1009 if (private->device)
1010 return private->device;
1013 switch (event->type)
1015 case GDK_MOTION_NOTIFY:
1016 return event->motion.device;
1017 case GDK_BUTTON_PRESS:
1018 case GDK_2BUTTON_PRESS:
1019 case GDK_3BUTTON_PRESS:
1020 case GDK_BUTTON_RELEASE:
1021 return event->button.device;
1023 return event->scroll.device;
1024 case GDK_PROXIMITY_IN:
1025 case GDK_PROXIMITY_OUT:
1026 return event->proximity.device;
1031 /* Fallback if event has no device set */
1032 switch (event->type)
1034 case GDK_MOTION_NOTIFY:
1035 case GDK_BUTTON_PRESS:
1036 case GDK_2BUTTON_PRESS:
1037 case GDK_3BUTTON_PRESS:
1038 case GDK_BUTTON_RELEASE:
1039 case GDK_ENTER_NOTIFY:
1040 case GDK_LEAVE_NOTIFY:
1041 case GDK_FOCUS_CHANGE:
1042 case GDK_PROXIMITY_IN:
1043 case GDK_PROXIMITY_OUT:
1044 case GDK_DRAG_ENTER:
1045 case GDK_DRAG_LEAVE:
1046 case GDK_DRAG_MOTION:
1047 case GDK_DRAG_STATUS:
1048 case GDK_DROP_START:
1049 case GDK_DROP_FINISHED:
1051 case GDK_GRAB_BROKEN:
1053 case GDK_KEY_RELEASE:
1055 GdkDisplay *display;
1056 GdkDeviceManager *device_manager;
1057 GdkDevice *client_pointer;
1059 g_warning ("Event with type %d not holding a GdkDevice. "
1060 "It is most likely synthesized outside Gdk/GTK+\n",
1063 display = gdk_window_get_display (event->any.window);
1064 device_manager = gdk_display_get_device_manager (display);
1065 client_pointer = gdk_device_manager_get_client_pointer (device_manager);
1067 if (event->type == GDK_KEY_PRESS ||
1068 event->type == GDK_KEY_RELEASE)
1069 return gdk_device_get_associated_device (client_pointer);
1071 return client_pointer;
1080 * gdk_event_request_motions:
1081 * @event: a valid #GdkEvent
1083 * Request more motion notifies if @event is a motion notify hint event.
1084 * This function should be used instead of gdk_window_get_pointer() to
1085 * request further motion notifies, because it also works for extension
1086 * events where motion notifies are provided for devices other than the
1087 * core pointer. Coordinate extraction, processing and requesting more
1088 * motion events from a %GDK_MOTION_NOTIFY event usually works like this:
1092 * /* motion_event handler */
1093 * x = motion_event->x;
1094 * y = motion_event->y;
1095 * /* handle (x,y) motion */
1096 * gdk_event_request_motions (motion_event); /* handles is_hint events */
1103 gdk_event_request_motions (const GdkEventMotion *event)
1105 GdkDisplay *display;
1107 g_return_if_fail (event != NULL);
1109 if (event->type == GDK_MOTION_NOTIFY && event->is_hint)
1111 gdk_device_get_state (event->device, event->window, NULL, NULL);
1113 display = gdk_window_get_display (event->window);
1114 _gdk_display_enable_motion_hints (display, event->device);
1119 gdk_events_get_axis_distances (GdkEvent *event1,
1121 gdouble *x_distance,
1122 gdouble *y_distance,
1125 gdouble x1, x2, y1, y2;
1128 if (!gdk_event_get_coords (event1, &x1, &y1) ||
1129 !gdk_event_get_coords (event2, &x2, &y2))
1142 *distance = sqrt ((xd * xd) + (yd * yd));
1148 * gdk_events_get_distance:
1149 * @event1: first #GdkEvent
1150 * @event2: second #GdkEvent
1151 * @distance: return location for the distance
1153 * If both events have X/Y information, the distance between both coordinates
1154 * (as in a straight line going from @event1 to @event2) will be returned.
1156 * Returns: %TRUE if the distance could be calculated.
1161 gdk_events_get_distance (GdkEvent *event1,
1165 return gdk_events_get_axis_distances (event1, event2,
1171 * gdk_events_get_angle:
1172 * @event1: first #GdkEvent
1173 * @event2: second #GdkEvent
1174 * @angle: return location for the relative angle between both events
1176 * If both events contain X/Y information, this function will return %TRUE
1177 * and return in @angle the relative angle from @event1 to @event2. The rotation
1178 * direction for positive angles is from the positive X axis towards the positive
1181 * Returns: %TRUE if the angle could be calculated.
1186 gdk_events_get_angle (GdkEvent *event1,
1190 gdouble x_distance, y_distance, distance;
1192 if (!gdk_events_get_axis_distances (event1, event2,
1193 &x_distance, &y_distance,
1199 *angle = atan2 (x_distance, y_distance);
1202 *angle = (2 * G_PI) - *angle;
1207 /* And constraint it to 0°-360° */
1208 *angle = fmod (*angle, 2 * G_PI);
1215 * gdk_events_get_center:
1216 * @event1: first #GdkEvent
1217 * @event2: second #GdkEvent
1218 * @x: (out): return location for the X coordinate of the center
1219 * @y: (out): return location for the Y coordinate of the center
1221 * If both events contain X/Y information, the center of both coordinates
1222 * will be returned in @x and @y.
1224 * Returns: %TRUE if the center could be calculated.
1229 gdk_events_get_center (GdkEvent *event1,
1234 gdouble x1, x2, y1, y2;
1236 if (!gdk_event_get_coords (event1, &x1, &y1) ||
1237 !gdk_event_get_coords (event2, &x2, &y2))
1250 * gdk_event_set_screen:
1251 * @event: a #GdkEvent
1252 * @screen: a #GdkScreen
1254 * Sets the screen for @event to @screen. The event must
1255 * have been allocated by GTK+, for instance, by
1261 gdk_event_set_screen (GdkEvent *event,
1264 GdkEventPrivate *private;
1266 g_return_if_fail (gdk_event_is_allocated (event));
1268 private = (GdkEventPrivate *)event;
1270 private->screen = screen;
1274 * gdk_event_get_screen:
1275 * @event: a #GdkEvent
1277 * Returns the screen for the event. The screen is
1278 * typically the screen for <literal>event->any.window</literal>, but
1279 * for events such as mouse events, it is the screen
1280 * where the pointer was when the event occurs -
1281 * that is, the screen which has the root window
1282 * to which <literal>event->motion.x_root</literal> and
1283 * <literal>event->motion.y_root</literal> are relative.
1285 * Return value: (transfer none): the screen for the event
1290 gdk_event_get_screen (const GdkEvent *event)
1292 if (gdk_event_is_allocated (event))
1294 GdkEventPrivate *private = (GdkEventPrivate *)event;
1296 if (private->screen)
1297 return private->screen;
1300 if (event->any.window)
1301 return gdk_window_get_screen (event->any.window);
1307 * gdk_set_show_events:
1308 * @show_events: %TRUE to output event debugging information.
1310 * Sets whether a trace of received events is output.
1311 * Note that GTK+ must be compiled with debugging (that is,
1312 * configured using the <option>--enable-debug</option> option)
1313 * to use this option.
1316 gdk_set_show_events (gboolean show_events)
1319 _gdk_debug_flags |= GDK_DEBUG_EVENTS;
1321 _gdk_debug_flags &= ~GDK_DEBUG_EVENTS;
1325 * gdk_get_show_events:
1327 * Gets whether event debugging output is enabled.
1329 * Return value: %TRUE if event debugging output is enabled.
1332 gdk_get_show_events (void)
1334 return (_gdk_debug_flags & GDK_DEBUG_EVENTS) != 0;
1337 /* What do we do with G_IO_NVAL?
1339 #define READ_CONDITION (G_IO_IN | G_IO_HUP | G_IO_ERR)
1340 #define WRITE_CONDITION (G_IO_OUT | G_IO_ERR)
1341 #define EXCEPTION_CONDITION (G_IO_PRI)
1344 gdk_synthesize_click (GdkDisplay *display,
1348 GdkEvent temp_event;
1349 GdkEvent *event_copy;
1352 g_return_if_fail (event != NULL);
1354 temp_event = *event;
1355 temp_event.type = (nclicks == 2) ? GDK_2BUTTON_PRESS : GDK_3BUTTON_PRESS;
1357 event_copy = gdk_event_copy (&temp_event);
1358 link = _gdk_event_queue_append (display, event_copy);
1362 _gdk_event_button_generate (GdkDisplay *display,
1365 GdkMultipleClickInfo *info;
1367 info = g_hash_table_lookup (display->multiple_click_info, event->button.device);
1369 if (G_UNLIKELY (!info))
1371 info = g_new0 (GdkMultipleClickInfo, 1);
1372 info->button_number[0] = info->button_number[1] = -1;
1374 g_hash_table_insert (display->multiple_click_info,
1375 event->button.device, info);
1378 if ((event->button.time < (info->button_click_time[1] + 2 * display->double_click_time)) &&
1379 (event->button.window == info->button_window[1]) &&
1380 (event->button.button == info->button_number[1]) &&
1381 (ABS (event->button.x - info->button_x[1]) <= display->double_click_distance) &&
1382 (ABS (event->button.y - info->button_y[1]) <= display->double_click_distance))
1384 gdk_synthesize_click (display, event, 3);
1386 info->button_click_time[1] = 0;
1387 info->button_click_time[0] = 0;
1388 info->button_window[1] = NULL;
1389 info->button_window[0] = NULL;
1390 info->button_number[1] = -1;
1391 info->button_number[0] = -1;
1392 info->button_x[0] = info->button_x[1] = 0;
1393 info->button_y[0] = info->button_y[1] = 0;
1395 else if ((event->button.time < (info->button_click_time[0] + display->double_click_time)) &&
1396 (event->button.window == info->button_window[0]) &&
1397 (event->button.button == info->button_number[0]) &&
1398 (ABS (event->button.x - info->button_x[0]) <= display->double_click_distance) &&
1399 (ABS (event->button.y - info->button_y[0]) <= display->double_click_distance))
1401 gdk_synthesize_click (display, event, 2);
1403 info->button_click_time[1] = info->button_click_time[0];
1404 info->button_click_time[0] = event->button.time;
1405 info->button_window[1] = info->button_window[0];
1406 info->button_window[0] = event->button.window;
1407 info->button_number[1] = info->button_number[0];
1408 info->button_number[0] = event->button.button;
1409 info->button_x[1] = info->button_x[0];
1410 info->button_x[0] = event->button.x;
1411 info->button_y[1] = info->button_y[0];
1412 info->button_y[0] = event->button.y;
1416 info->button_click_time[1] = 0;
1417 info->button_click_time[0] = event->button.time;
1418 info->button_window[1] = NULL;
1419 info->button_window[0] = event->button.window;
1420 info->button_number[1] = -1;
1421 info->button_number[0] = event->button.button;
1422 info->button_x[1] = 0;
1423 info->button_x[0] = event->button.x;
1424 info->button_y[1] = 0;
1425 info->button_y[0] = event->button.y;
1430 gdk_synthesize_window_state (GdkWindow *window,
1431 GdkWindowState unset_flags,
1432 GdkWindowState set_flags)
1434 GdkEvent temp_event;
1437 g_return_if_fail (window != NULL);
1439 temp_event.window_state.window = window;
1440 temp_event.window_state.type = GDK_WINDOW_STATE;
1441 temp_event.window_state.send_event = FALSE;
1443 old = temp_event.window_state.window->state;
1445 temp_event.window_state.new_window_state = old;
1446 temp_event.window_state.new_window_state |= set_flags;
1447 temp_event.window_state.new_window_state &= ~unset_flags;
1448 temp_event.window_state.changed_mask = temp_event.window_state.new_window_state ^ old;
1450 if (temp_event.window_state.new_window_state == old)
1451 return; /* No actual work to do, nothing changed. */
1453 /* Actually update the field in GdkWindow, this is sort of an odd
1454 * place to do it, but seems like the safest since it ensures we expose no
1455 * inconsistent state to the user.
1458 window->state = temp_event.window_state.new_window_state;
1460 if (temp_event.window_state.changed_mask & GDK_WINDOW_STATE_WITHDRAWN)
1461 _gdk_window_update_viewable (window);
1463 /* We only really send the event to toplevels, since
1464 * all the window states don't apply to non-toplevels.
1465 * Non-toplevels do use the GDK_WINDOW_STATE_WITHDRAWN flag
1466 * internally so we needed to update window->state.
1468 switch (window->window_type)
1470 case GDK_WINDOW_TOPLEVEL:
1471 case GDK_WINDOW_TEMP: /* ? */
1472 gdk_display_put_event (gdk_window_get_display (window), &temp_event);
1475 case GDK_WINDOW_FOREIGN:
1476 case GDK_WINDOW_ROOT:
1477 case GDK_WINDOW_CHILD:
1483 * gdk_display_set_double_click_time:
1484 * @display: a #GdkDisplay
1485 * @msec: double click time in milliseconds (thousandths of a second)
1487 * Sets the double click time (two clicks within this time interval
1488 * count as a double click and result in a #GDK_2BUTTON_PRESS event).
1489 * Applications should <emphasis>not</emphasis> set this, it is a global
1490 * user-configured setting.
1495 gdk_display_set_double_click_time (GdkDisplay *display,
1498 display->double_click_time = msec;
1502 * gdk_set_double_click_time:
1503 * @msec: double click time in milliseconds (thousandths of a second)
1505 * Set the double click time for the default display. See
1506 * gdk_display_set_double_click_time().
1507 * See also gdk_display_set_double_click_distance().
1508 * Applications should <emphasis>not</emphasis> set this, it is a
1509 * global user-configured setting.
1512 gdk_set_double_click_time (guint msec)
1514 gdk_display_set_double_click_time (gdk_display_get_default (), msec);
1518 * gdk_display_set_double_click_distance:
1519 * @display: a #GdkDisplay
1520 * @distance: distance in pixels
1522 * Sets the double click distance (two clicks within this distance
1523 * count as a double click and result in a #GDK_2BUTTON_PRESS event).
1524 * See also gdk_display_set_double_click_time().
1525 * Applications should <emphasis>not</emphasis> set this, it is a global
1526 * user-configured setting.
1531 gdk_display_set_double_click_distance (GdkDisplay *display,
1534 display->double_click_distance = distance;
1537 G_DEFINE_BOXED_TYPE (GdkEvent, gdk_event,
1543 * @name: the name of the setting.
1544 * @value: location to store the value of the setting.
1546 * Obtains a desktop-wide setting, such as the double-click time,
1547 * for the default screen. See gdk_screen_get_setting().
1549 * Returns: %TRUE if the setting existed and a value was stored
1550 * in @value, %FALSE otherwise.
1553 gdk_setting_get (const gchar *name,
1556 return gdk_screen_get_setting (gdk_screen_get_default (), name, value);