* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
*/
-#include <config.h>
-#include <string.h> /* For memset() */
+#include "config.h"
-#include "gdk.h"
#include "gdkinternals.h"
+#include "gdkdisplayprivate.h"
+
+#include <string.h>
+#include <math.h>
+
+
+/**
+ * SECTION:events
+ * @Short_description: Functions for handling events from the window system
+ * @Title: Events
+ * @See_also: <link linkend="gdk-Event-Structures">Event Structures</link>
+ *
+ * This section describes functions dealing with events from the window
+ * system.
+ *
+ * In GTK+ applications the events are handled automatically in
+ * gtk_main_do_event() and passed on to the appropriate widgets, so these
+ * functions are rarely needed. Though some of the fields in the
+ * <link linkend="gdk-Event-Structures">Event Structures</link> are useful.
+ */
+
typedef struct _GdkIOClosure GdkIOClosure;
struct _GdkIOClosure
{
- GdkInputFunction function;
- GdkInputCondition condition;
- GdkDestroyNotify notify;
+ GDestroyNotify notify;
gpointer data;
};
/* Private variable declarations
*/
-GdkEventFunc _gdk_event_func = NULL; /* Callback for events */
-gpointer _gdk_event_data = NULL;
-GDestroyNotify _gdk_event_notify = NULL;
+static GdkEventFunc _gdk_event_func = NULL; /* Callback for events */
+static gpointer _gdk_event_data = NULL;
+static GDestroyNotify _gdk_event_notify = NULL;
+
+void
+_gdk_event_emit (GdkEvent *event)
+{
+ if (_gdk_event_func)
+ (*_gdk_event_func) (event, _gdk_event_data);
+}
/*********************************************
* Functions for maintaining the event queue *
return NULL;
}
+/**
+ * _gdk_event_queue_prepend:
+ * @display: a #GdkDisplay
+ * @event: Event to prepend.
+ *
+ * Prepends an event before the head of the event queue.
+ *
+ * Returns: the newly prepended list node.
+ **/
+GList*
+_gdk_event_queue_prepend (GdkDisplay *display,
+ GdkEvent *event)
+{
+ display->queued_events = g_list_prepend (display->queued_events, event);
+ if (!display->queued_tail)
+ display->queued_tail = display->queued_events;
+ return display->queued_events;
+}
+
/**
* _gdk_event_queue_append:
* @display: a #GdkDisplay
return display->queued_tail;
}
+/**
+ * _gdk_event_queue_insert_after:
+ * @display: a #GdkDisplay
+ * @sibling: Append after this event.
+ * @event: Event to append.
+ *
+ * Appends an event after the specified event, or if it isn't in
+ * the queue, onto the tail of the event queue.
+ *
+ * Returns: the newly appended list node.
+ *
+ * Since: 2.16
+ */
+GList*
+_gdk_event_queue_insert_after (GdkDisplay *display,
+ GdkEvent *sibling,
+ GdkEvent *event)
+{
+ GList *prev = g_list_find (display->queued_events, sibling);
+ if (prev && prev->next)
+ {
+ display->queued_events = g_list_insert_before (display->queued_events, prev->next, event);
+ return prev->next;
+ }
+ else
+ return _gdk_event_queue_append (display, event);
+}
+
+/**
+ * _gdk_event_queue_insert_after:
+ * @display: a #GdkDisplay
+ * @sibling: Append after this event.
+ * @event: Event to append.
+ *
+ * Appends an event before the specified event, or if it isn't in
+ * the queue, onto the tail of the event queue.
+ *
+ * Returns: the newly appended list node.
+ *
+ * Since: 2.16
+ */
+GList*
+_gdk_event_queue_insert_before (GdkDisplay *display,
+ GdkEvent *sibling,
+ GdkEvent *event)
+{
+ GList *next = g_list_find (display->queued_events, sibling);
+ if (next)
+ {
+ display->queued_events = g_list_insert_before (display->queued_events, next, event);
+ return next->prev;
+ }
+ else
+ return _gdk_event_queue_append (display, event);
+}
+
+
/**
* _gdk_event_queue_remove_link:
* @display: a #GdkDisplay
_gdk_event_notify = notify;
}
+/**
+ * gdk_events_pending:
+ *
+ * Checks if any events are ready to be processed for any display.
+ *
+ * Return value: %TRUE if any events are pending.
+ */
+gboolean
+gdk_events_pending (void)
+{
+ GSList *list, *l;
+ gboolean pending;
+
+ pending = FALSE;
+ list = gdk_display_manager_list_displays (gdk_display_manager_get ());
+ for (l = list; l; l = l->next)
+ {
+ if (_gdk_event_queue_find_first (l->data))
+ {
+ pending = TRUE;
+ goto out;
+ }
+ }
+
+ for (l = list; l; l = l->next)
+ {
+ if (gdk_display_has_pending (l->data))
+ {
+ pending = TRUE;
+ goto out;
+ }
+ }
+
+ out:
+ g_slist_free (list);
+
+ return pending;
+}
+
/**
* gdk_event_get:
*
GdkEvent*
gdk_event_get (void)
{
- GSList *tmp_list;
+ GSList *list, *l;
+ GdkEvent *event;
- for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
+ event = NULL;
+ list = gdk_display_manager_list_displays (gdk_display_manager_get ());
+ for (l = list; l; l = l->next)
{
- GdkEvent *event = gdk_display_get_event (tmp_list->data);
+ event = gdk_display_get_event (l->data);
if (event)
- return event;
+ break;
}
- return NULL;
+ g_slist_free (list);
+
+ return event;
}
/**
GdkEvent*
gdk_event_peek (void)
{
- GSList *tmp_list;
+ GSList *list, *l;
+ GdkEvent *event;
- for (tmp_list = _gdk_displays; tmp_list; tmp_list = tmp_list->next)
+ event = NULL;
+ list = gdk_display_manager_list_displays (gdk_display_manager_get ());
+ for (l = list; l; l = l->next)
{
- GdkEvent *event = gdk_display_peek_event (tmp_list->data);
+ event = gdk_display_peek_event (l->data);
if (event)
- return event;
+ break;
}
- return NULL;
+ g_slist_free (list);
+
+ return event;
}
/**
* queue if event->any.window is %NULL. See gdk_display_put_event().
**/
void
-gdk_event_put (GdkEvent *event)
+gdk_event_put (const GdkEvent *event)
{
GdkDisplay *display;
g_return_if_fail (event != NULL);
if (event->any.window)
- display = gdk_drawable_get_display (event->any.window);
+ display = gdk_window_get_display (event->any.window);
else
{
GDK_NOTE (MULTIHEAD,
gdk_display_put_event (display, event);
}
-static GMemChunk *event_chunk = NULL;
static GHashTable *event_hash = NULL;
/**
GdkEventPrivate *new_private;
GdkEvent *new_event;
- if (event_chunk == NULL)
- {
- event_chunk = g_mem_chunk_new ("events",
- sizeof (GdkEventPrivate),
- 4096,
- G_ALLOC_AND_FREE);
- event_hash = g_hash_table_new (g_direct_hash, NULL);
- }
-
- new_private = g_chunk_new (GdkEventPrivate, event_chunk);
- memset (new_private, 0, sizeof (GdkEventPrivate));
+ if (!event_hash)
+ event_hash = g_hash_table_new (g_direct_hash, NULL);
+
+ new_private = g_slice_new0 (GdkEventPrivate);
new_private->flags = 0;
new_private->screen = NULL;
}
static gboolean
-gdk_event_is_allocated (GdkEvent *event)
+gdk_event_is_allocated (const GdkEvent *event)
{
if (event_hash)
return g_hash_table_lookup (event_hash, event) != NULL;
* gdk_event_free().
**/
GdkEvent*
-gdk_event_copy (GdkEvent *event)
+gdk_event_copy (const GdkEvent *event)
{
GdkEventPrivate *new_private;
GdkEvent *new_event;
-
+
g_return_val_if_fail (event != NULL, NULL);
-
+
new_event = gdk_event_new (GDK_NOTHING);
new_private = (GdkEventPrivate *)new_event;
GdkEventPrivate *private = (GdkEventPrivate *)event;
new_private->screen = private->screen;
+ new_private->device = private->device;
+ new_private->source_device = private->source_device;
}
-
+
switch (event->any.type)
{
case GDK_KEY_PRESS:
case GDK_KEY_RELEASE:
new_event->key.string = g_strdup (event->key.string);
break;
-
+
case GDK_ENTER_NOTIFY:
case GDK_LEAVE_NOTIFY:
if (event->crossing.subwindow != NULL)
- g_object_ref (event->crossing.subwindow);
+ g_object_ref (event->crossing.subwindow);
break;
-
+
case GDK_DRAG_ENTER:
case GDK_DRAG_LEAVE:
case GDK_DRAG_MOTION:
case GDK_DROP_FINISHED:
g_object_ref (event->dnd.context);
break;
-
+
case GDK_EXPOSE:
+ case GDK_DAMAGE:
if (event->expose.region)
- new_event->expose.region = gdk_region_copy (event->expose.region);
+ new_event->expose.region = cairo_region_copy (event->expose.region);
break;
-
+
case GDK_SETTING:
new_event->setting.name = g_strdup (new_event->setting.name);
break;
case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
- if (event->button.axes)
- new_event->button.axes = g_memdup (event->button.axes,
- sizeof (gdouble) * event->button.device->num_axes);
+ if (event->button.axes)
+ new_event->button.axes = g_memdup (event->button.axes,
+ sizeof (gdouble) * gdk_device_get_n_axes (event->button.device));
break;
case GDK_MOTION_NOTIFY:
- if (event->motion.axes)
- new_event->motion.axes = g_memdup (event->motion.axes,
- sizeof (gdouble) * event->motion.device->num_axes);
-
+ if (event->motion.axes)
+ new_event->motion.axes = g_memdup (event->motion.axes,
+ sizeof (gdouble) * gdk_device_get_n_axes (event->motion.device));
break;
-
+
+ case GDK_OWNER_CHANGE:
+ new_event->owner_change.owner = event->owner_change.owner;
+ if (new_event->owner_change.owner)
+ g_object_ref (new_event->owner_change.owner);
+ break;
+
+ case GDK_SELECTION_CLEAR:
+ case GDK_SELECTION_NOTIFY:
+ case GDK_SELECTION_REQUEST:
+ new_event->selection.requestor = event->selection.requestor;
+ if (new_event->selection.requestor)
+ g_object_unref (new_event->selection.requestor);
+ break;
+
default:
break;
}
-
+
+ if (gdk_event_is_allocated (event))
+ _gdk_display_event_data_copy (gdk_display_get_default (), event, new_event);
+
return new_event;
}
*
* Frees a #GdkEvent, freeing or decrementing any resources associated with it.
* Note that this function should only be called with events returned from
- * functions such as gdk_event_peek(), gdk_event_get(),
- * gdk_event_get_graphics_expose() and gdk_event_copy().
+ * functions such as gdk_event_peek(), gdk_event_get(), gdk_event_copy()
+ * and gdk_event_new().
**/
void
gdk_event_free (GdkEvent *event)
{
+ GdkDisplay *display;
+
g_return_if_fail (event != NULL);
- g_assert (event_chunk != NULL); /* paranoid */
-
if (event->any.window)
g_object_unref (event->any.window);
case GDK_DRAG_STATUS:
case GDK_DROP_START:
case GDK_DROP_FINISHED:
- g_object_unref (event->dnd.context);
+ if (event->dnd.context != NULL)
+ g_object_unref (event->dnd.context);
break;
case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
case GDK_BUTTON_RELEASE:
- if (event->button.axes)
- g_free (event->button.axes);
+ g_free (event->button.axes);
break;
case GDK_EXPOSE:
+ case GDK_DAMAGE:
if (event->expose.region)
- gdk_region_destroy (event->expose.region);
+ cairo_region_destroy (event->expose.region);
break;
case GDK_MOTION_NOTIFY:
- if (event->motion.axes)
- g_free (event->motion.axes);
+ g_free (event->motion.axes);
break;
case GDK_SETTING:
g_free (event->setting.name);
break;
+ case GDK_OWNER_CHANGE:
+ if (event->owner_change.owner)
+ g_object_unref (event->owner_change.owner);
+ break;
+
+ case GDK_SELECTION_CLEAR:
+ case GDK_SELECTION_NOTIFY:
+ case GDK_SELECTION_REQUEST:
+ if (event->selection.requestor)
+ g_object_unref (event->selection.requestor);
+ break;
+
default:
break;
}
+ display = gdk_display_get_default ();
+ if (display)
+ _gdk_display_event_data_free (display, event);
+
g_hash_table_remove (event_hash, event);
- g_mem_chunk_free (event_chunk, event);
+ g_slice_free (GdkEventPrivate, (GdkEventPrivate*) event);
}
/**
* Return value: time stamp field from @event
**/
guint32
-gdk_event_get_time (GdkEvent *event)
+gdk_event_get_time (const GdkEvent *event)
{
if (event)
switch (event->type)
return event->dnd.time;
case GDK_CLIENT_EVENT:
case GDK_VISIBILITY_NOTIFY:
- case GDK_NO_EXPOSE:
case GDK_CONFIGURE:
case GDK_FOCUS_CHANGE:
case GDK_NOTHING:
+ case GDK_DAMAGE:
case GDK_DELETE:
case GDK_DESTROY:
case GDK_EXPOSE:
case GDK_WINDOW_STATE:
case GDK_SETTING:
case GDK_OWNER_CHANGE:
+ case GDK_GRAB_BROKEN:
+ case GDK_EVENT_LAST:
/* return current time */
break;
}
/**
* gdk_event_get_state:
* @event: a #GdkEvent or NULL
- * @state: return location for state
+ * @state: (out): return location for state
*
* If the event contains a "state" field, puts that field in @state. Otherwise
* stores an empty state (0). Returns %TRUE if there was a state field
* Return value: %TRUE if there was a state field in the event
**/
gboolean
-gdk_event_get_state (GdkEvent *event,
- GdkModifierType *state)
+gdk_event_get_state (const GdkEvent *event,
+ GdkModifierType *state)
{
g_return_val_if_fail (state != NULL, FALSE);
*state = event->crossing.state;
return TRUE;
case GDK_PROPERTY_NOTIFY:
- *state = event->property.state;
- return TRUE;
case GDK_VISIBILITY_NOTIFY:
case GDK_CLIENT_EVENT:
- case GDK_NO_EXPOSE:
case GDK_CONFIGURE:
case GDK_FOCUS_CHANGE:
case GDK_SELECTION_CLEAR:
case GDK_SELECTION_NOTIFY:
case GDK_PROXIMITY_IN:
case GDK_PROXIMITY_OUT:
+ case GDK_DAMAGE:
case GDK_DRAG_ENTER:
case GDK_DRAG_LEAVE:
case GDK_DRAG_MOTION:
case GDK_WINDOW_STATE:
case GDK_SETTING:
case GDK_OWNER_CHANGE:
+ case GDK_GRAB_BROKEN:
+ case GDK_EVENT_LAST:
/* no state field */
break;
}
/**
* gdk_event_get_coords:
* @event: a #GdkEvent
- * @x_win: location to put event window x coordinate
- * @y_win: location to put event window y coordinate
+ * @x_win: (out): location to put event window x coordinate
+ * @y_win: (out): location to put event window y coordinate
*
* Extract the event window relative x/y coordinates from an event.
*
* Return value: %TRUE if the event delivered event window coordinates
**/
gboolean
-gdk_event_get_coords (GdkEvent *event,
- gdouble *x_win,
- gdouble *y_win)
+gdk_event_get_coords (const GdkEvent *event,
+ gdouble *x_win,
+ gdouble *y_win)
{
gdouble x = 0, y = 0;
gboolean fetched = TRUE;
/**
* gdk_event_get_root_coords:
* @event: a #GdkEvent
- * @x_root: location to put root window x coordinate
- * @y_root: location to put root window y coordinate
+ * @x_root: (out): location to put root window x coordinate
+ * @y_root: (out): location to put root window y coordinate
*
* Extract the root window relative x/y coordinates from an event.
*
* Return value: %TRUE if the event delivered root window coordinates
**/
gboolean
-gdk_event_get_root_coords (GdkEvent *event,
- gdouble *x_root,
- gdouble *y_root)
+gdk_event_get_root_coords (const GdkEvent *event,
+ gdouble *x_root,
+ gdouble *y_root)
{
gdouble x = 0, y = 0;
gboolean fetched = TRUE;
x = event->motion.x_root;
y = event->motion.y_root;
break;
+ case GDK_SCROLL:
+ x = event->scroll.x_root;
+ y = event->scroll.y_root;
+ break;
case GDK_BUTTON_PRESS:
case GDK_2BUTTON_PRESS:
case GDK_3BUTTON_PRESS:
* gdk_event_get_axis:
* @event: a #GdkEvent
* @axis_use: the axis use to look for
- * @value: location to store the value found
+ * @value: (out): location to store the value found
*
* Extract the axis value for a particular axis use from
* an event structure.
* Return value: %TRUE if the specified axis was found, otherwise %FALSE
**/
gboolean
-gdk_event_get_axis (GdkEvent *event,
- GdkAxisUse axis_use,
- gdouble *value)
+gdk_event_get_axis (const GdkEvent *event,
+ GdkAxisUse axis_use,
+ gdouble *value)
{
gdouble *axes;
GdkDevice *device;
return gdk_device_get_axis (device, axes, axis_use, value);
}
+/**
+ * gdk_event_set_device:
+ * @event: a #GdkEvent
+ * @device: a #GdkDevice
+ *
+ * Sets the device for @event to @device. The event must
+ * have been allocated by GTK+, for instance, by
+ * gdk_event_copy().
+ *
+ * Since: 3.0
+ **/
+void
+gdk_event_set_device (GdkEvent *event,
+ GdkDevice *device)
+{
+ GdkEventPrivate *private;
+
+ g_return_if_fail (gdk_event_is_allocated (event));
+
+ private = (GdkEventPrivate *) event;
+
+ private->device = device;
+
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ event->motion.device = device;
+ break;
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ event->button.device = device;
+ break;
+ case GDK_SCROLL:
+ event->scroll.device = device;
+ break;
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+ event->proximity.device = device;
+ break;
+ default:
+ break;
+ }
+}
+
+/**
+ * gdk_event_get_device:
+ * @event: a #GdkEvent.
+ *
+ * If the event contains a "device" field, this function will return
+ * it, else it will return %NULL.
+ *
+ * Returns: (transfer none): a #GdkDevice, or %NULL.
+ *
+ * Since: 3.0
+ **/
+GdkDevice *
+gdk_event_get_device (const GdkEvent *event)
+{
+ g_return_val_if_fail (event != NULL, NULL);
+
+ if (gdk_event_is_allocated (event))
+ {
+ GdkEventPrivate *private = (GdkEventPrivate *) event;
+
+ if (private->device)
+ return private->device;
+ }
+
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ return event->motion.device;
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ return event->button.device;
+ case GDK_SCROLL:
+ return event->scroll.device;
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+ return event->proximity.device;
+ default:
+ break;
+ }
+
+ /* Fallback if event has no device set */
+ switch (event->type)
+ {
+ case GDK_MOTION_NOTIFY:
+ case GDK_BUTTON_PRESS:
+ case GDK_2BUTTON_PRESS:
+ case GDK_3BUTTON_PRESS:
+ case GDK_BUTTON_RELEASE:
+ case GDK_ENTER_NOTIFY:
+ case GDK_LEAVE_NOTIFY:
+ case GDK_FOCUS_CHANGE:
+ case GDK_PROXIMITY_IN:
+ case GDK_PROXIMITY_OUT:
+ case GDK_DRAG_ENTER:
+ case GDK_DRAG_LEAVE:
+ case GDK_DRAG_MOTION:
+ case GDK_DRAG_STATUS:
+ case GDK_DROP_START:
+ case GDK_DROP_FINISHED:
+ case GDK_SCROLL:
+ case GDK_GRAB_BROKEN:
+ case GDK_KEY_PRESS:
+ case GDK_KEY_RELEASE:
+ {
+ GdkDisplay *display;
+ GdkDeviceManager *device_manager;
+ GdkDevice *client_pointer;
+
+ g_warning ("Event with type %d not holding a GdkDevice. "
+ "It is most likely synthesized outside Gdk/GTK+\n",
+ event->type);
+
+ display = gdk_window_get_display (event->any.window);
+ device_manager = gdk_display_get_device_manager (display);
+ client_pointer = gdk_device_manager_get_client_pointer (device_manager);
+
+ if (event->type == GDK_KEY_PRESS ||
+ event->type == GDK_KEY_RELEASE)
+ return gdk_device_get_associated_device (client_pointer);
+ else
+ return client_pointer;
+ }
+ break;
+ default:
+ return NULL;
+ }
+}
+
+/**
+ * gdk_event_set_source_device:
+ * @event: a #GdkEvent
+ * @device: a #GdkDevice
+ *
+ * Sets the slave device for @event to @device.
+ *
+ * The event must have been allocated by GTK+,
+ * for instance by gdk_event_copy().
+ *
+ * Since: 3.0
+ **/
+void
+gdk_event_set_source_device (GdkEvent *event,
+ GdkDevice *device)
+{
+ GdkEventPrivate *private;
+
+ g_return_if_fail (gdk_event_is_allocated (event));
+ g_return_if_fail (GDK_IS_DEVICE (device));
+
+ private = (GdkEventPrivate *) event;
+
+ private->source_device = device;
+}
+
+/**
+ * gdk_event_get_source_device:
+ * @event: a #GdkEvent
+ *
+ * This function returns the hardware (slave) #GdkDevice that has
+ * triggered the event, falling back to the virtual (master) device
+ * (as in gdk_event_get_device()) if the event wasn't caused by
+ * interaction with a hardware device. This may happen for example
+ * in synthesized crossing events after a #GdkWindow updates its
+ * geometry or a grab is acquired/released.
+ *
+ * If the event does not contain a device field, this function will
+ * return %NULL.
+ *
+ * Returns: (transfer none): a #GdkDevice, or %NULL.
+ *
+ * Since: 3.0
+ **/
+GdkDevice *
+gdk_event_get_source_device (const GdkEvent *event)
+{
+ GdkEventPrivate *private;
+
+ g_return_val_if_fail (event != NULL, NULL);
+
+ if (!gdk_event_is_allocated (event))
+ return NULL;
+
+ private = (GdkEventPrivate *) event;
+
+ if (private->source_device)
+ return private->source_device;
+
+ /* Fallback to event device */
+ return gdk_event_get_device (event);
+}
+
+/**
+ * gdk_event_request_motions:
+ * @event: a valid #GdkEvent
+ *
+ * Request more motion notifies if @event is a motion notify hint event.
+ *
+ * This function should be used instead of gdk_window_get_pointer() to
+ * request further motion notifies, because it also works for extension
+ * events where motion notifies are provided for devices other than the
+ * core pointer. Coordinate extraction, processing and requesting more
+ * motion events from a %GDK_MOTION_NOTIFY event usually works like this:
+ *
+ * |[
+ * {
+ * /* motion_event handler */
+ * x = motion_event->x;
+ * y = motion_event->y;
+ * /* handle (x,y) motion */
+ * gdk_event_request_motions (motion_event); /* handles is_hint events */
+ * }
+ * ]|
+ *
+ * Since: 2.12
+ **/
+void
+gdk_event_request_motions (const GdkEventMotion *event)
+{
+ GdkDisplay *display;
+
+ g_return_if_fail (event != NULL);
+
+ if (event->type == GDK_MOTION_NOTIFY && event->is_hint)
+ {
+ gdk_device_get_state (event->device, event->window, NULL, NULL);
+
+ display = gdk_window_get_display (event->window);
+ _gdk_display_enable_motion_hints (display, event->device);
+ }
+}
+
+static gboolean
+gdk_events_get_axis_distances (GdkEvent *event1,
+ GdkEvent *event2,
+ gdouble *x_distance,
+ gdouble *y_distance,
+ gdouble *distance)
+{
+ gdouble x1, x2, y1, y2;
+ gdouble xd, yd;
+
+ if (!gdk_event_get_coords (event1, &x1, &y1) ||
+ !gdk_event_get_coords (event2, &x2, &y2))
+ return FALSE;
+
+ xd = x2 - x1;
+ yd = y2 - y1;
+
+ if (x_distance)
+ *x_distance = xd;
+
+ if (y_distance)
+ *y_distance = yd;
+
+ if (distance)
+ *distance = sqrt ((xd * xd) + (yd * yd));
+
+ return TRUE;
+}
+
+/**
+ * gdk_events_get_distance:
+ * @event1: first #GdkEvent
+ * @event2: second #GdkEvent
+ * @distance: (out): return location for the distance
+ *
+ * If both events have X/Y information, the distance between both coordinates
+ * (as in a straight line going from @event1 to @event2) will be returned.
+ *
+ * Returns: %TRUE if the distance could be calculated.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gdk_events_get_distance (GdkEvent *event1,
+ GdkEvent *event2,
+ gdouble *distance)
+{
+ return gdk_events_get_axis_distances (event1, event2,
+ NULL, NULL,
+ distance);
+}
+
+/**
+ * gdk_events_get_angle:
+ * @event1: first #GdkEvent
+ * @event2: second #GdkEvent
+ * @angle: (out): return location for the relative angle between both events
+ *
+ * If both events contain X/Y information, this function will return %TRUE
+ * and return in @angle the relative angle from @event1 to @event2. The rotation
+ * direction for positive angles is from the positive X axis towards the positive
+ * Y axis.
+ *
+ * Returns: %TRUE if the angle could be calculated.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gdk_events_get_angle (GdkEvent *event1,
+ GdkEvent *event2,
+ gdouble *angle)
+{
+ gdouble x_distance, y_distance, distance;
+
+ if (!gdk_events_get_axis_distances (event1, event2,
+ &x_distance, &y_distance,
+ &distance))
+ return FALSE;
+
+ if (angle)
+ {
+ *angle = atan2 (x_distance, y_distance);
+
+ /* Invert angle */
+ *angle = (2 * G_PI) - *angle;
+
+ /* Shift it 90° */
+ *angle += G_PI / 2;
+
+ /* And constraint it to 0°-360° */
+ *angle = fmod (*angle, 2 * G_PI);
+ }
+
+ return TRUE;
+}
+
+/**
+ * gdk_events_get_center:
+ * @event1: first #GdkEvent
+ * @event2: second #GdkEvent
+ * @x: (out): return location for the X coordinate of the center
+ * @y: (out): return location for the Y coordinate of the center
+ *
+ * If both events contain X/Y information, the center of both coordinates
+ * will be returned in @x and @y.
+ *
+ * Returns: %TRUE if the center could be calculated.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gdk_events_get_center (GdkEvent *event1,
+ GdkEvent *event2,
+ gdouble *x,
+ gdouble *y)
+{
+ gdouble x1, x2, y1, y2;
+
+ if (!gdk_event_get_coords (event1, &x1, &y1) ||
+ !gdk_event_get_coords (event2, &x2, &y2))
+ return FALSE;
+
+ if (x)
+ *x = (x2 + x1) / 2;
+
+ if (y)
+ *y = (y2 + y1) / 2;
+
+ return TRUE;
+}
+
/**
* gdk_event_set_screen:
* @event: a #GdkEvent
* Returns the screen for the event. The screen is
* typically the screen for <literal>event->any.window</literal>, but
* for events such as mouse events, it is the screen
- * where the the pointer was when the event occurs -
+ * where the pointer was when the event occurs -
* that is, the screen which has the root window
* to which <literal>event->motion.x_root</literal> and
* <literal>event->motion.y_root</literal> are relative.
*
- * Return value: the screen for the event
+ * Return value: (transfer none): the screen for the event
*
* Since: 2.2
**/
GdkScreen *
-gdk_event_get_screen (GdkEvent *event)
+gdk_event_get_screen (const GdkEvent *event)
{
if (gdk_event_is_allocated (event))
{
}
if (event->any.window)
- return gdk_drawable_get_screen (event->any.window);
+ return gdk_window_get_screen (event->any.window);
return NULL;
}
return (_gdk_debug_flags & GDK_DEBUG_EVENTS) != 0;
}
-static void
-gdk_io_destroy (gpointer data)
-{
- GdkIOClosure *closure = data;
-
- if (closure->notify)
- closure->notify (closure->data);
-
- g_free (closure);
-}
-
/* What do we do with G_IO_NVAL?
*/
#define READ_CONDITION (G_IO_IN | G_IO_HUP | G_IO_ERR)
#define WRITE_CONDITION (G_IO_OUT | G_IO_ERR)
#define EXCEPTION_CONDITION (G_IO_PRI)
-static gboolean
-gdk_io_invoke (GIOChannel *source,
- GIOCondition condition,
- gpointer data)
+static void
+gdk_synthesize_click (GdkDisplay *display,
+ GdkEvent *event,
+ gint nclicks)
{
- GdkIOClosure *closure = data;
- GdkInputCondition gdk_cond = 0;
-
- if (condition & READ_CONDITION)
- gdk_cond |= GDK_INPUT_READ;
- if (condition & WRITE_CONDITION)
- gdk_cond |= GDK_INPUT_WRITE;
- if (condition & EXCEPTION_CONDITION)
- gdk_cond |= GDK_INPUT_EXCEPTION;
+ GdkEvent *event_copy;
- if (closure->condition & gdk_cond)
- closure->function (closure->data, g_io_channel_unix_get_fd (source), gdk_cond);
+ event_copy = gdk_event_copy (event);
+ event_copy->type = (nclicks == 2) ? GDK_2BUTTON_PRESS : GDK_3BUTTON_PRESS;
- return TRUE;
+ _gdk_event_queue_append (display, event_copy);
}
-gint
-gdk_input_add_full (gint source,
- GdkInputCondition condition,
- GdkInputFunction function,
- gpointer data,
- GdkDestroyNotify destroy)
+void
+_gdk_event_button_generate (GdkDisplay *display,
+ GdkEvent *event)
{
- guint result;
- GdkIOClosure *closure = g_new (GdkIOClosure, 1);
- GIOChannel *channel;
- GIOCondition cond = 0;
-
- closure->function = function;
- closure->condition = condition;
- closure->notify = destroy;
- closure->data = data;
-
- if (condition & GDK_INPUT_READ)
- cond |= READ_CONDITION;
- if (condition & GDK_INPUT_WRITE)
- cond |= WRITE_CONDITION;
- if (condition & GDK_INPUT_EXCEPTION)
- cond |= EXCEPTION_CONDITION;
-
- channel = g_io_channel_unix_new (source);
- result = g_io_add_watch_full (channel, G_PRIORITY_DEFAULT, cond,
- gdk_io_invoke,
- closure, gdk_io_destroy);
- g_io_channel_unref (channel);
-
- return result;
-}
+ GdkMultipleClickInfo *info;
-gint
-gdk_input_add (gint source,
- GdkInputCondition condition,
- GdkInputFunction function,
- gpointer data)
-{
- return gdk_input_add_full (source, condition, function, data, NULL);
-}
+ g_return_if_fail (event->type == GDK_BUTTON_PRESS);
-void
-gdk_input_remove (gint tag)
-{
- g_source_remove (tag);
-}
+ info = g_hash_table_lookup (display->multiple_click_info, event->button.device);
-static void
-gdk_synthesize_click (GdkDisplay *display,
- GdkEvent *event,
- gint nclicks)
-{
- GdkEvent temp_event;
-
- g_return_if_fail (event != NULL);
-
- temp_event = *event;
- temp_event.type = (nclicks == 2) ? GDK_2BUTTON_PRESS : GDK_3BUTTON_PRESS;
-
- gdk_display_put_event (display, &temp_event);
-}
+ if (G_UNLIKELY (!info))
+ {
+ info = g_new0 (GdkMultipleClickInfo, 1);
+ info->button_number[0] = info->button_number[1] = -1;
-void
-_gdk_event_button_generate (GdkDisplay *display,
- GdkEvent *event)
-{
- if ((event->button.time < (display->button_click_time[1] + 2*display->double_click_time)) &&
- (event->button.window == display->button_window[1]) &&
- (event->button.button == display->button_number[1]) &&
- (ABS (event->button.x - display->button_x[1]) <= display->double_click_distance) &&
- (ABS (event->button.y - display->button_y[1]) <= display->double_click_distance))
-{
+ g_hash_table_insert (display->multiple_click_info,
+ event->button.device, info);
+ }
+
+ if ((event->button.time < (info->button_click_time[1] + 2 * display->double_click_time)) &&
+ (event->button.window == info->button_window[1]) &&
+ (event->button.button == info->button_number[1]) &&
+ (ABS (event->button.x - info->button_x[1]) <= display->double_click_distance) &&
+ (ABS (event->button.y - info->button_y[1]) <= display->double_click_distance))
+ {
gdk_synthesize_click (display, event, 3);
-
- display->button_click_time[1] = 0;
- display->button_click_time[0] = 0;
- display->button_window[1] = NULL;
- display->button_window[0] = 0;
- display->button_number[1] = -1;
- display->button_number[0] = -1;
- display->button_x[0] = display->button_x[1] = 0;
- display->button_y[0] = display->button_y[1] = 0;
+
+ info->button_click_time[1] = 0;
+ info->button_click_time[0] = 0;
+ info->button_window[1] = NULL;
+ info->button_window[0] = NULL;
+ info->button_number[1] = -1;
+ info->button_number[0] = -1;
+ info->button_x[0] = info->button_x[1] = 0;
+ info->button_y[0] = info->button_y[1] = 0;
}
- else if ((event->button.time < (display->button_click_time[0] + display->double_click_time)) &&
- (event->button.window == display->button_window[0]) &&
- (event->button.button == display->button_number[0]) &&
- (ABS (event->button.x - display->button_x[0]) <= display->double_click_distance) &&
- (ABS (event->button.y - display->button_y[0]) <= display->double_click_distance))
+ else if ((event->button.time < (info->button_click_time[0] + display->double_click_time)) &&
+ (event->button.window == info->button_window[0]) &&
+ (event->button.button == info->button_number[0]) &&
+ (ABS (event->button.x - info->button_x[0]) <= display->double_click_distance) &&
+ (ABS (event->button.y - info->button_y[0]) <= display->double_click_distance))
{
gdk_synthesize_click (display, event, 2);
- display->button_click_time[1] = display->button_click_time[0];
- display->button_click_time[0] = event->button.time;
- display->button_window[1] = display->button_window[0];
- display->button_window[0] = event->button.window;
- display->button_number[1] = display->button_number[0];
- display->button_number[0] = event->button.button;
- display->button_x[1] = display->button_x[0];
- display->button_x[0] = event->button.x;
- display->button_y[1] = display->button_y[0];
- display->button_y[0] = event->button.y;
+ info->button_click_time[1] = info->button_click_time[0];
+ info->button_click_time[0] = event->button.time;
+ info->button_window[1] = info->button_window[0];
+ info->button_window[0] = event->button.window;
+ info->button_number[1] = info->button_number[0];
+ info->button_number[0] = event->button.button;
+ info->button_x[1] = info->button_x[0];
+ info->button_x[0] = event->button.x;
+ info->button_y[1] = info->button_y[0];
+ info->button_y[0] = event->button.y;
}
else
{
- display->button_click_time[1] = 0;
- display->button_click_time[0] = event->button.time;
- display->button_window[1] = NULL;
- display->button_window[0] = event->button.window;
- display->button_number[1] = -1;
- display->button_number[0] = event->button.button;
- display->button_x[1] = 0;
- display->button_x[0] = event->button.x;
- display->button_y[1] = 0;
- display->button_y[0] = event->button.y;
+ info->button_click_time[1] = 0;
+ info->button_click_time[0] = event->button.time;
+ info->button_window[1] = NULL;
+ info->button_window[0] = event->button.window;
+ info->button_number[1] = -1;
+ info->button_number[0] = event->button.button;
+ info->button_x[1] = 0;
+ info->button_x[0] = event->button.x;
+ info->button_y[1] = 0;
+ info->button_y[0] = event->button.y;
}
}
temp_event.window_state.type = GDK_WINDOW_STATE;
temp_event.window_state.send_event = FALSE;
- old = ((GdkWindowObject*) temp_event.window_state.window)->state;
+ old = temp_event.window_state.window->state;
temp_event.window_state.new_window_state = old;
temp_event.window_state.new_window_state |= set_flags;
* inconsistent state to the user.
*/
- ((GdkWindowObject*) window)->state = temp_event.window_state.new_window_state;
+ window->state = temp_event.window_state.new_window_state;
+
+ if (temp_event.window_state.changed_mask & GDK_WINDOW_STATE_WITHDRAWN)
+ _gdk_window_update_viewable (window);
/* We only really send the event to toplevels, since
* all the window states don't apply to non-toplevels.
* Non-toplevels do use the GDK_WINDOW_STATE_WITHDRAWN flag
* internally so we needed to update window->state.
*/
- switch (((GdkWindowObject*) window)->window_type)
+ switch (window->window_type)
{
case GDK_WINDOW_TOPLEVEL:
- case GDK_WINDOW_DIALOG:
case GDK_WINDOW_TEMP: /* ? */
- gdk_display_put_event (gdk_drawable_get_display (window), &temp_event);
+ gdk_display_put_event (gdk_window_get_display (window), &temp_event);
break;
case GDK_WINDOW_FOREIGN:
display->double_click_distance = distance;
}
-GType
-gdk_event_get_type (void)
-{
- static GType our_type = 0;
-
- if (our_type == 0)
- our_type = g_boxed_type_register_static ("GdkEvent",
- (GBoxedCopyFunc)gdk_event_copy,
- (GBoxedFreeFunc)gdk_event_free);
- return our_type;
-}
+G_DEFINE_BOXED_TYPE (GdkEvent, gdk_event,
+ gdk_event_copy,
+ gdk_event_free)
/**
* gdk_setting_get:
* Obtains a desktop-wide setting, such as the double-click time,
* for the default screen. See gdk_screen_get_setting().
*
- * Returns : %TRUE if the setting existed and a value was stored
+ * Returns: %TRUE if the setting existed and a value was stored
* in @value, %FALSE otherwise.
**/
gboolean