Commit b1eaa502 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

events: reorganize getters

Restructure the getters for event fields to
be more targeted at particular event types.

Update all callers, and replace all direct
event struct access with getters.

As a side-effect, this drops some unused getters.
parent f1cf0eb3
......@@ -105,7 +105,7 @@ day_selected_cb (GtkCalendar *calendar,
if (gdk_event_get_event_type (event) != GDK_BUTTON_PRESS)
return;
gdk_event_get_coords (event, &x, &y);
gdk_event_get_position (event, &x, &y);
gtk_widget_translate_coordinates (gtk_get_event_widget (event),
GTK_WIDGET (calendar),
x, y,
......
......@@ -141,7 +141,7 @@ clicked (GtkGestureClick *gesture,
window = gtk_widget_get_ancestor (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture)), GTK_TYPE_WINDOW);
event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), NULL);
gdk_event_get_state (event, &state);
state = gdk_event_get_modifier_state (event);
if (state & GDK_CONTROL_MASK)
{
......
......@@ -43,7 +43,7 @@
* context = gdk_display_get_app_launch_context (display);
*
* gdk_app_launch_context_set_display (display);
* gdk_app_launch_context_set_timestamp (event->time);
* gdk_app_launch_context_set_timestamp (gdk_event_get_time (event));
*
* if (!g_app_info_launch_default_for_uri ("http://www.gtk.org", context, &error))
* g_warning ("Launching failed: %s\n", error->message);
......
This diff is collapsed.
......@@ -330,159 +330,137 @@ typedef enum
} GdkCrossingMode;
GDK_AVAILABLE_IN_ALL
GType gdk_event_get_type (void) G_GNUC_CONST;
GType gdk_event_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GType gdk_event_sequence_get_type (void) G_GNUC_CONST;
GType gdk_event_sequence_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GdkEvent * gdk_event_ref (GdkEvent *event);
GdkEvent * gdk_event_ref (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
void gdk_event_unref (GdkEvent *event);
void gdk_event_unref (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkSurface *gdk_event_get_surface (GdkEvent *event);
GdkEventType gdk_event_get_event_type (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
guint32 gdk_event_get_time (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_state (GdkEvent *event,
GdkModifierType *state);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_coords (GdkEvent *event,
gdouble *x_win,
gdouble *y_win);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_button (GdkEvent *event,
guint *button);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_click_count (GdkEvent *event,
guint *click_count);
GdkSurface * gdk_event_get_surface (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_keyval (GdkEvent *event,
guint *keyval);
GdkDevice * gdk_event_get_device (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_keycode (GdkEvent *event,
guint16 *keycode);
GdkDevice * gdk_event_get_source_device (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_key_is_modifier (GdkEvent *event,
gboolean *is_modifier);
GdkDeviceTool * gdk_event_get_device_tool (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_key_group (GdkEvent *event,
guint *group);
guint32 gdk_event_get_time (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_scroll_direction (GdkEvent *event,
GdkScrollDirection *direction);
GdkDisplay * gdk_event_get_display (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_scroll_deltas (GdkEvent *event,
gdouble *delta_x,
gdouble *delta_y);
GdkEventSequence * gdk_event_get_event_sequence (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_is_scroll_stop_event (GdkEvent *event);
GdkModifierType gdk_event_get_modifier_state (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_axis (GdkEvent *event,
GdkAxisUse axis_use,
gdouble *value);
gboolean gdk_event_get_position (GdkEvent *event,
double *x,
double *y);
GDK_AVAILABLE_IN_ALL
GdkDevice* gdk_event_get_device (GdkEvent *event);
gboolean gdk_event_get_axes (GdkEvent *event,
double **axes,
guint *n_axes);
GDK_AVAILABLE_IN_ALL
GdkDevice* gdk_event_get_source_device (GdkEvent *event);
gboolean gdk_event_get_axis (GdkEvent *event,
GdkAxisUse axis_use,
double *value);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_triggers_context_menu (GdkEvent *event);
gboolean gdk_event_get_pointer_emulated (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_events_get_distance (GdkEvent *event1,
GdkEvent *event2,
gdouble *distance);
guint gdk_button_event_get_button (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_events_get_angle (GdkEvent *event1,
GdkEvent *event2,
gdouble *angle);
GdkScrollDirection gdk_scroll_event_get_direction (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_events_get_center (GdkEvent *event1,
GdkEvent *event2,
gdouble *x,
gdouble *y);
void gdk_scroll_event_get_deltas (GdkEvent *event,
double *delta_x,
double *delta_y);
GDK_AVAILABLE_IN_ALL
GdkDisplay *gdk_event_get_display (GdkEvent *event);
gboolean gdk_scroll_event_is_stop (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkEventSequence *gdk_event_get_event_sequence (GdkEvent *event);
guint gdk_key_event_get_keyval (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkEventType gdk_event_get_event_type (GdkEvent *event);
guint gdk_key_event_get_keycode (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkSeat *gdk_event_get_seat (GdkEvent *event);
guint gdk_key_event_get_scancode (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkDeviceTool *gdk_event_get_device_tool (GdkEvent *event);
guint gdk_key_event_get_group (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
int gdk_event_get_scancode (GdkEvent *event);
gboolean gdk_key_event_is_modifier (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_pointer_emulated (GdkEvent *event);
gboolean gdk_focus_event_get_in (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_is_sent (GdkEvent *event);
gboolean gdk_touch_event_get_emulating_pointer (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GdkDrop * gdk_event_get_drop (GdkEvent *event);
GdkCrossingMode gdk_crossing_event_get_mode (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_crossing_mode (GdkEvent *event,
GdkCrossingMode *mode);
GdkNotifyType gdk_crossing_event_get_detail (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_crossing_detail (GdkEvent *event,
GdkNotifyType *detail);
void gdk_configure_event_get_size (GdkEvent *event,
int *width,
int *height);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touchpad_gesture_phase (GdkEvent *event,
GdkTouchpadGesturePhase *phase);
GdkTouchpadGesturePhase
gdk_touchpad_event_get_gesture_phase (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touchpad_gesture_n_fingers (GdkEvent *event,
guint *n_fingers);
guint gdk_touchpad_event_get_n_fingers (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touchpad_deltas (GdkEvent *event,
double *dx,
double *dy);
void gdk_touchpad_event_get_deltas (GdkEvent *event,
double *dx,
double *dy);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touchpad_angle_delta (GdkEvent *event,
double *delta);
double gdk_touchpad_pinch_event_get_angle_delta (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touchpad_scale (GdkEvent *event,
double *scale);
double gdk_touchpad_pinch_event_get_scale (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_touch_emulating_pointer (GdkEvent *event,
gboolean *emulating);
guint gdk_pad_button_event_get_button (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_grab_surface (GdkEvent *event,
GdkSurface **surface);
void gdk_pad_axis_event_get_value (GdkEvent *event,
guint *index,
double *value);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_focus_in (GdkEvent *event,
gboolean *focus_in);
void gdk_pad_event_get_group_mode (GdkEvent *event,
guint *group,
guint *mode);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_pad_group_mode (GdkEvent *event,
guint *group,
guint *mode);
GdkDrop * gdk_drag_event_get_drop (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_pad_button (GdkEvent *event,
guint *button);
GdkSurface * gdk_grab_broken_event_get_grab_surface (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
GList * gdk_event_get_motion_history (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_triggers_context_menu (GdkEvent *event);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_pad_axis_value (GdkEvent *event,
guint *index,
gdouble *value);
gboolean gdk_events_get_distance (GdkEvent *event1,
GdkEvent *event2,
double *distance);
GDK_AVAILABLE_IN_ALL
gboolean gdk_event_get_axes (GdkEvent *event,
gdouble **axes,
guint *n_axes);
gboolean gdk_events_get_angle (GdkEvent *event1,
GdkEvent *event2,
double *angle);
GDK_AVAILABLE_IN_ALL
GList * gdk_event_get_motion_history (GdkEvent *event);
gboolean gdk_events_get_center (GdkEvent *event1,
GdkEvent *event2,
double *x,
double *y);
G_END_DECLS
......
......@@ -521,55 +521,9 @@ struct _GdkEventPadGroupMode {
/*
* GdkEvent:
* @type: the #GdkEventType
* @any: a #GdkEventAny
* @motion: a #GdkEventMotion
* @button: a #GdkEventButton
* @touch: a #GdkEventTouch
* @scroll: a #GdkEventScroll
* @key: a #GdkEventKey
* @crossing: a #GdkEventCrossing
* @focus_change: a #GdkEventFocus
* @configure: a #GdkEventConfigure
* @proximity: a #GdkEventProximity
* @dnd: a #GdkEventDND
* @grab_broken: a #GdkEventGrabBroken
* @touchpad_swipe: a #GdkEventTouchpadSwipe
* @touchpad_pinch: a #GdkEventTouchpadPinch
* @pad_button: a #GdkEventPadButton
* @pad_axis: a #GdkEventPadAxis
* @pad_group_mode: a #GdkEventPadGroupMode
*
* A #GdkEvent contains a union of all of the event types,
* and allows access to the data fields in a number of ways.
*
* The event type is always the first field in all of the event types, and
* can always be accessed with the following code, no matter what type of
* event it is:
* |[<!-- language="C" -->
* GdkEvent *event;
* GdkEventType type;
*
* type = event->type;
* ]|
*
* To access other fields of the event, the pointer to the event
* can be cast to the appropriate event type, or the union member
* name can be used. For example if the event type is %GDK_BUTTON_PRESS
* then the x coordinate of the button press can be accessed with:
* |[<!-- language="C" -->
* GdkEvent *event;
* gdouble x;
*
* x = ((GdkEventButton*)event)->x;
* ]|
* or:
* |[<!-- language="C" -->
* GdkEvent *event;
* gdouble x;
*
* x = event->button.x;
* ]|
* The GdkEvent struct is private and should only be accessed
* using the accessor functions.
*/
union _GdkEvent
{
......
......@@ -559,11 +559,14 @@ gdk_keymap_lookup_key (GdkKeymap *keymap,
* |[<!-- language="C" -->
* // We want to ignore irrelevant modifiers like ScrollLock
* #define ALL_ACCELS_MASK (GDK_CONTROL_MASK | GDK_SHIFT_MASK | GDK_MOD1_MASK)
* gdk_keymap_translate_keyboard_state (keymap, event->hardware_keycode,
* event->state, event->group,
* state = gdk_event_get_modifier_state (event);
* gdk_keymap_translate_keyboard_state (keymap,
* gdk_key_event_get_keycode (event),
* state,
* gdk_key_event_get_group (event),
* &keyval, NULL, NULL, &consumed);
* if (keyval == GDK_PLUS &&
* (event->state & ~consumed & ALL_ACCELS_MASK) == GDK_CONTROL_MASK)
* (state & ~consumed & ALL_ACCELS_MASK) == GDK_CONTROL_MASK)
* // Control was pressed
* ]|
*
......@@ -574,7 +577,7 @@ gdk_keymap_lookup_key (GdkKeymap *keymap,
* |[<!-- language="C" -->
* // XXX Don’t do this XXX
* if (keyval == accel_keyval &&
* (event->state & ~consumed & ALL_ACCELS_MASK) == (accel_mods & ~consumed))
* (state & ~consumed & ALL_ACCELS_MASK) == (accel_mods & ~consumed))
* // Accelerator was pressed
* ]|
*
......
......@@ -2675,6 +2675,7 @@ _gdk_windowing_got_event (GdkDisplay *display,
GdkDeviceGrabInfo *button_release_grab;
GdkPointerSurfaceInfo *pointer_info = NULL;
GdkDevice *device, *source_device;
GdkEventType type;
_gdk_display_update_last_event (display, event);
......@@ -2708,21 +2709,21 @@ _gdk_windowing_got_event (GdkDisplay *display,
}
}
event_surface = event->any.surface;
event_surface = gdk_event_get_surface (event);
if (!event_surface)
goto out;
if (event->any.type == GDK_ENTER_NOTIFY)
type = gdk_event_get_event_type (event);
if (type == GDK_ENTER_NOTIFY)
_gdk_display_set_surface_under_pointer (display, device, event_surface);
else if (event->any.type == GDK_LEAVE_NOTIFY)
else if (type == GDK_LEAVE_NOTIFY)
_gdk_display_set_surface_under_pointer (display, device, NULL);
if ((event->any.type == GDK_BUTTON_RELEASE ||
event->any.type == GDK_TOUCH_CANCEL ||
event->any.type == GDK_TOUCH_END) &&
!event->any.send_event)
if (type == GDK_BUTTON_RELEASE ||
type == GDK_TOUCH_CANCEL ||
type == GDK_TOUCH_END)
{
if (event->any.type == GDK_BUTTON_RELEASE ||
if (type == GDK_BUTTON_RELEASE ||
gdk_event_get_pointer_emulated (event))
{
button_release_grab =
......@@ -2730,7 +2731,7 @@ _gdk_windowing_got_event (GdkDisplay *display,
if (button_release_grab &&
button_release_grab->implicit &&
(event->button.state & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (event->button.button - 1))) == 0)
(gdk_event_get_modifier_state (event) & GDK_ANY_BUTTON_MASK & ~(GDK_BUTTON1_MASK << (gdk_button_event_get_button (event) - 1))) == 0)
{
button_release_grab->serial_end = serial;
button_release_grab->implicit_ungrab = FALSE;
......@@ -3995,16 +3996,29 @@ is_key_event (GdkEvent *event)
return FALSE;
}
static void
static GdkEvent *
rewrite_event_for_toplevel (GdkEvent *event)
{
GdkSurface *surface;
surface = gdk_event_get_surface (event);
if (!surface->parent)
return gdk_event_ref (event);
while (surface->parent)
surface = surface->parent;
g_set_object (&event->any.surface, surface);
return gdk_event_key_new (gdk_event_get_event_type (event),
surface,
gdk_event_get_device (event),
gdk_event_get_source_device (event),
gdk_event_get_time (event),
gdk_event_get_modifier_state (event),
gdk_key_event_get_keyval (event),
gdk_key_event_get_keycode (event),
gdk_key_event_get_scancode (event),
gdk_key_event_get_group (event),
gdk_key_event_is_modifier (event));
}
static void
......@@ -4025,49 +4039,44 @@ add_event_mark (GdkEvent *event,
{
case GDK_MOTION_NOTIFY:
{
GdkEventMotion *motion = (GdkEventMotion *)event;
double x, y;
gdk_event_get_position (event, &x, &y);
message = g_strdup_printf ("{x=%lf, y=%lf, state=0x%x}",
motion->x, motion->y, motion->state);
x, y,
gdk_event_get_modifier_state (event));
break;
}
case GDK_BUTTON_PRESS:
{
GdkEventButton *button = (GdkEventButton *)event;
message = g_strdup_printf ("{button=%u, x=%lf, y=%lf, state=0x%x}",
button->button, button->x, button->y, button->state);
break;
}
case GDK_BUTTON_RELEASE:
{
GdkEventButton *button = (GdkEventButton *)event;
double x, y;
gdk_event_get_position (event, &x, &y);
message = g_strdup_printf ("{button=%u, x=%lf, y=%lf, state=0x%x}",
button->button, button->x, button->y, button->state);
gdk_button_event_get_button (event),
x, y,
gdk_event_get_modifier_state (event));
break;
}
case GDK_KEY_PRESS:
{
GdkEventKey *key = (GdkEventKey *)event;
message = g_strdup_printf ("{keyval=%u, state=0x%x, hardware_keycode=%u key_scancode=%u group=%u is_modifier=%u}",
key->keyval, key->state, key->hardware_keycode, key->key_scancode, key->group, key->is_modifier);
break;
}
case GDK_KEY_RELEASE:
{
GdkEventKey *key = (GdkEventKey *)event;
message = g_strdup_printf ("{keyval=%u, state=0x%x, hardware_keycode=%u key_scancode=%u group=%u is_modifier=%u}",
key->keyval, key->state, key->hardware_keycode, key->key_scancode, key->group, key->is_modifier);
gdk_key_event_get_keyval (event),
gdk_event_get_modifier_state (event),
gdk_key_event_get_keycode (event),
gdk_key_event_get_scancode (event),
gdk_key_event_get_group (event),
gdk_key_event_is_modifier (event));
break;
}
case GDK_CONFIGURE:
{
GdkEventConfigure *config = (GdkEventConfigure *)event;
message = g_strdup_printf ("{x=%d, y=%d, width=%d, height=%d}",
config->x, config->y, config->width, config->height);
int width, height;
gdk_configure_event_get_size (event, &width, &height);
message = g_strdup_printf ("{width=%d, height=%d}", width, height);
break;
}
......@@ -4127,9 +4136,15 @@ gdk_surface_handle_event (GdkEvent *event)
}
else
{
GdkEvent *emitted;
if (is_key_event (event))
rewrite_event_for_toplevel (event);
g_signal_emit (gdk_event_get_surface (event), signals[EVENT], 0, event, &handled);
emitted = rewrite_event_for_toplevel (event);
else
emitted = gdk_event_ref (event);
g_signal_emit (gdk_event_get_surface (emitted), signals[EVENT], 0, emitted, &handled);
gdk_event_unref (emitted);
}
if (GDK_PROFILER_IS_RUNNING)
......
......@@ -1478,7 +1478,7 @@ gdk_wayland_seat_set_frame_event (GdkWaylandSeat *seat,
GdkEvent *event)
{
if (seat->pointer_info.frame.event &&
seat->pointer_info.frame.event->any.type != event->any.type)
gdk_event_get_event_type (seat->pointer_info.frame.event) != gdk_event_get_event_type (event))
gdk_wayland_seat_flush_frame_event (seat);
seat->pointer_info.frame.event = event;
......@@ -1612,10 +1612,13 @@ pointer_handle_motion (void *data,
NULL);
gdk_wayland_seat_set_frame_event (seat, event);
GDK_SEAT_NOTE (seat, EVENTS,
g_message ("motion %f %f, seat %p state %d",
event->motion.x, event->motion.y,
seat, event->motion.state));
if (GDK_DISPLAY_DEBUG_CHECK (gdk_seat_get_display (GDK_SEAT (seat)), EVENTS))
{
double x, y;
gdk_event_get_position (event, &x, &y);
g_message ("motion %f %f, seat %p state %d",
x, y, seat, gdk_event_get_modifier_state (event));
}
if (display->seat_version < WL_POINTER_HAS_FRAME)
gdk_wayland_seat_flush_frame_event (seat);
......@@ -1683,10 +1686,10 @@ pointer_handle_button (void *data,
GDK_SEAT_NOTE (seat, EVENTS,
g_message ("button %d %s, seat %p state %d",
event->button.button,
gdk_button_event_get_button (event),
state ? "press" : "release",
seat,
event->button.state));
gdk_event_get_modifier_state (event)));
if (display->seat_version < WL_POINTER_HAS_FRAME)
gdk_wayland_seat_flush_frame_event (seat);
......@@ -1950,7 +1953,7 @@ keyboard_handle_leave (void *data,
GDK_SEAT_NOTE (seat, EVENTS,
g_message ("focus out, seat %p surface %p",
seat, event->any.surface));
seat, gdk_event_get_surface (event)));
_gdk_wayland_display_deliver_event (seat->display, event);
}
......@@ -2048,9 +2051,10 @@ deliver_key_event (GdkWaylandSeat *seat,
"mods 0x%x",
(state ? "press" : "release"),
(from_key_repeat ? " (repeat)" : ""),
event->any.surface,
event->key.hardware_keycode, event->key.keyval,
event->key.state));
gdk_event_get_surface (event),
gdk_key_event_get_keycode (event),
gdk_key_event_get_keyval (event),
gdk_event_get_modifier_state (event)));
if (!xkb_keymap_key_repeats (xkb_keymap, key))
return;
......@@ -2304,8 +2308,12 @@ touch_handle_down (void *data,
mimic_pointer_emulating_touch_info (seat->touch_master, touch);
}
GDK_SEAT_NOTE (seat, EVENTS,
g_message ("touch begin %f %f", event->touch.x, event->touch.y));
if (GDK_DISPLAY_DEBUG_CHECK (gdk_seat_get_display (GDK_SEAT (seat)), EVENTS))
{
double xx, yy;
gdk_event_get_position (event, &xx, &yy);
g_message ("touch begin %f %f", xx, yy);
}
_gdk_wayland_display_deliver_event (seat->display, event);
}
......@@ -2336,8 +2344,12 @@ touch_handle_up (void *data,
NULL,
touch->initial_touch);
GDK_SEAT_NOTE (seat, EVENTS,
g_message ("touch end %f %f", event->touch.x, event->touch.y));
if (GDK_DISPLAY_DEBUG_CHECK (gdk_seat_get_display (GDK_SEAT (seat)), EVENTS))
{
double x, y;
gdk_event_get_position (event, &x, &y);
g_message ("touch end %f %f", x, y);
}
_gdk_wayland_display_deliver_event (seat->display, event);