diff options
-rw-r--r-- | docs/reference/gdk/gdk4-sections.txt | 2 | ||||
-rw-r--r-- | gdk/gdkevents.c | 81 | ||||
-rw-r--r-- | gdk/gdkevents.h | 16 | ||||
-rw-r--r-- | gtk/gtkgesturestylus.c | 6 |
4 files changed, 33 insertions, 72 deletions
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index cc1bdd0189..c5ae73d1dc 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -498,6 +498,7 @@ gdk_event_get_modifier_state gdk_event_get_position gdk_event_get_axes gdk_event_get_axis +gdk_event_get_history gdk_event_get_pointer_emulated gdk_event_triggers_context_menu gdk_button_event_get_button @@ -529,7 +530,6 @@ gdk_touchpad_event_get_pinch_scale gdk_pad_event_get_axis_value gdk_pad_event_get_button gdk_pad_event_get_group_mode -gdk_motion_event_get_history <SUBSECTION> gdk_events_get_angle diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index 7c621f7e5b..759f8a0128 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -633,6 +633,7 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display) GList *scrolls = NULL; double delta_x, delta_y; GArray *history = NULL; + GdkTimeCoord hist; l = g_queue_peek_tail_link (&display->queued_events); @@ -671,20 +672,22 @@ gdk_event_queue_handle_scroll_compression (GdkDisplay *display) { GdkEvent *event = scrolls->data; GList *next = scrolls->next; - GdkScrollHistory h; double dx, dy; if (!history) - history = g_array_new (FALSE, TRUE, sizeof (GdkScrollHistory)); + history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord)); gdk_scroll_event_get_deltas (event, &dx, &dy); delta_x += dx; delta_y += dy; - h.time = gdk_event_get_time (event); - h.delta_x = dx; - h.delta_y = dy; - g_array_append_val (history, h); + memset (&hist, 0, sizeof (GdkTimeCoord)); + hist.time = gdk_event_get_time (event); + hist.flags = GDK_AXIS_FLAG_DELTA_X | GDK_AXIS_FLAG_DELTA_Y; + hist.axes[GDK_AXIS_DELTA_X] = dx; + hist.axes[GDK_AXIS_DELTA_Y] = dy; + + g_array_append_val (history, hist); gdk_event_unref (event); g_queue_delete_link (&display->queued_events, scrolls); @@ -739,8 +742,15 @@ gdk_motion_event_push_history (GdkEvent *event, device = gdk_event_get_device (history_event); n_axes = gdk_device_get_n_axes (device); - for (i = 0; i <= MIN (n_axes, GDK_MAX_TIMECOORD_AXES); i++) - gdk_event_get_axis (history_event, i, &hist.axes[i]); + memset (&hist, 0, sizeof (GdkTimeCoord)); + hist.time = gdk_event_get_time (history_event); + hist.flags = gdk_device_get_axes (device); + + for (i = 0; i < n_axes; i++) + { + GdkAxisUse use = gdk_device_get_axis_use (device, i); + gdk_event_get_axis (history_event, use, &hist.axes[use]); + } if (G_UNLIKELY (!self->history)) self->history = g_array_new (FALSE, TRUE, sizeof (GdkTimeCoord)); @@ -2411,44 +2421,6 @@ gdk_scroll_event_is_stop (GdkEvent *event) return self->is_stop; } -/** - * gdk_scroll_event_get_history: - * @event: (type GdkScrollEvent): a scroll #GdkEvent - * @out_n: (out): Return location for the length of the returned array - * - * Retrieves the history of the @event, as a list of times and deltas. - * - * Returns: (transfer container) (array length=out_n) (nullable): an - * array of #GdkScrollHistory - */ -GdkScrollHistory * -gdk_scroll_event_get_history (GdkEvent *event, - guint *out_n) -{ - GdkScrollEvent *self = (GdkScrollEvent *) event; - - g_return_val_if_fail (GDK_IS_EVENT (event), NULL); - g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_SCROLL), NULL); - g_return_val_if_fail (out_n != NULL, NULL); - - if (self->history && - self->history->len > 0) - { - GdkScrollHistory *result; - - *out_n = self->history->len; - - result = g_new (GdkScrollHistory, self->history->len); - memcpy (result, self->history->data, sizeof (GdkScrollHistory) * self->history->len); - - return result; - } - - *out_n = 0; - - return NULL; -} - /* }}} */ /* {{{ GdkTouchpadEvent */ @@ -2921,28 +2893,27 @@ gdk_motion_event_new (GdkSurface *surface, } /** - * gdk_motion_event_get_history: - * @event: (type GdkMotionEvent): a motion #GdkEvent + * gdk_event_get_history: + * @event: a motion or scroll #GdkEvent * @out_n_coords: (out): Return location for the length of the returned array * - * Retrieves the history of the @event motion, as a list of time and - * coordinates. + * Retrieves the history of the @event, as a list of time and coordinates. * * Returns: (transfer container) (array length=out_n_coords) (nullable): an * array of time and coordinates */ GdkTimeCoord * -gdk_motion_event_get_history (GdkEvent *event, - guint *out_n_coords) +gdk_event_get_history (GdkEvent *event, + guint *out_n_coords) { GdkMotionEvent *self = (GdkMotionEvent *) event; g_return_val_if_fail (GDK_IS_EVENT (event), NULL); - g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY), NULL); + g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY) || + GDK_IS_EVENT_TYPE (event, GDK_SCROLL), NULL); g_return_val_if_fail (out_n_coords != NULL, NULL); - if (self->history && - self->history->len > 0) + if (self->history && self->history->len > 0) { GdkTimeCoord *result; diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h index 17f76ce0d8..9abb9a96cd 100644 --- a/gdk/gdkevents.h +++ b/gdk/gdkevents.h @@ -378,6 +378,9 @@ gboolean gdk_event_get_axis (GdkEvent *event, GdkAxisUse axis_use, double *value); GDK_AVAILABLE_IN_ALL +GdkTimeCoord * gdk_event_get_history (GdkEvent *event, + guint *out_n_coords); +GDK_AVAILABLE_IN_ALL gboolean gdk_event_get_pointer_emulated (GdkEvent *event); GDK_AVAILABLE_IN_ALL @@ -393,16 +396,6 @@ void gdk_scroll_event_get_deltas (GdkEvent *event, double *delta_x, double *delta_y); -typedef struct { - guint32 time; - double delta_x; - double delta_y; -} GdkScrollHistory; - -GDK_AVAILABLE_IN_ALL -GdkScrollHistory * gdk_scroll_event_get_history (GdkEvent *event, - guint *out_n); - GDK_AVAILABLE_IN_ALL gboolean gdk_scroll_event_is_stop (GdkEvent *event); GDK_AVAILABLE_IN_ALL @@ -481,9 +474,6 @@ gboolean gdk_grab_broken_event_get_implicit (GdkEvent *event) GDK_AVAILABLE_IN_ALL GType gdk_motion_event_get_type (void) G_GNUC_CONST; -GDK_AVAILABLE_IN_ALL -GdkTimeCoord * gdk_motion_event_get_history (GdkEvent *event, - guint *out_n_coords); GDK_AVAILABLE_IN_ALL GType gdk_delete_event_get_type (void) G_GNUC_CONST; diff --git a/gtk/gtkgesturestylus.c b/gtk/gtkgesturestylus.c index da0dbc868f..094a759553 100644 --- a/gtk/gtkgesturestylus.c +++ b/gtk/gtkgesturestylus.c @@ -278,8 +278,8 @@ gtk_gesture_stylus_get_axes (GtkGestureStylus *gesture, **/ gboolean gtk_gesture_stylus_get_backlog (GtkGestureStylus *gesture, - GdkTimeCoord **backlog, - guint *n_elems) + GdkTimeCoord **backlog, + guint *n_elems) { GdkEvent *event; GArray *backlog_array; @@ -292,7 +292,7 @@ gtk_gesture_stylus_get_backlog (GtkGestureStylus *gesture, event = gesture_get_current_event (gesture); if (event && GDK_IS_EVENT_TYPE (event, GDK_MOTION_NOTIFY)) - history = gdk_motion_event_get_history (event, &n_coords); + history = gdk_event_get_history (event, &n_coords); if (!history) return FALSE; |