From 6fd913b36188ea1c8666472583f10c0c7c638f0f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 17 Feb 2020 23:08:44 -0500 Subject: [PATCH] Some event struct packing improvements Rearrange a few things, and move some booleans into the Any struct, by using a bitfield there. Some more cleanup could be done - the flags field with its PENDING and FLUSHED members appears entirely unused. Nobody is setting those flags. --- gdk/gdkevents.c | 110 ++++++++++++----------------------------- gdk/gdkeventsprivate.h | 40 ++++++--------- gdk/gdkinternals.h | 6 --- 3 files changed, 46 insertions(+), 110 deletions(-) diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index 67c69a7ada..ac46600a28 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -406,7 +406,7 @@ gdk_event_unref (GdkEvent *event) gboolean gdk_event_get_pointer_emulated (GdkEvent *event) { - return (event->any.flags & GDK_EVENT_POINTER_EMULATED) != 0; + return event->any.pointer_emulated; } static void @@ -832,11 +832,11 @@ gdk_event_button_new (GdkEventType type, event = g_new0 (GdkEventButton, 1); event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->tool = tool ? g_object_ref (tool) : NULL; - event->time = time; event->axes = NULL; event->state = state; event->button = button; @@ -862,11 +862,11 @@ gdk_event_motion_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_MOTION_NOTIFY; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->tool = tool ? g_object_ref (tool) : NULL; - event->time = time; event->state = state; event->x = x; event->y = y; @@ -897,10 +897,10 @@ gdk_event_crossing_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->state = state; event->x = x; event->y = y; @@ -927,11 +927,11 @@ gdk_event_proximity_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->tool = tool ? g_object_ref (tool) : NULL; - event->time = time; return (GdkEvent *)event; } @@ -958,16 +958,16 @@ gdk_event_key_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->state = state; event->keyval = keyval; event->hardware_keycode = keycode; event->key_scancode = scancode; event->group = group; - event->is_modifier = is_modifier; + event->any.key_is_modifier = is_modifier; return (GdkEvent *)event; } @@ -981,6 +981,7 @@ gdk_event_configure_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_CONFIGURE; + event->any.time = GDK_CURRENT_TIME; event->any.surface = g_object_ref (surface); event->width = width; event->height = height; @@ -995,6 +996,7 @@ gdk_event_delete_new (GdkSurface *surface) event->ref_count = 1; event->type = GDK_DELETE; + event->time = GDK_CURRENT_TIME; event->surface = g_object_ref (surface); return (GdkEvent *)event; @@ -1010,10 +1012,11 @@ gdk_event_focus_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_FOCUS_CHANGE; + event->any.time = GDK_CURRENT_TIME; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->in = focus_in; + event->any.focus_in = focus_in; return (GdkEvent *)event; } @@ -1033,18 +1036,18 @@ gdk_event_scroll_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_SCROLL; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->tool = tool ? g_object_ref (tool) : NULL; - event->time = time; event->state = state; event->x = NAN; event->y = NAN; event->direction = GDK_SCROLL_SMOOTH; event->delta_x = delta_x; event->delta_y = delta_y; - event->is_stop = is_stop; + event->any.scroll_is_stop = is_stop; return (GdkEvent *)event; } @@ -1063,17 +1066,16 @@ gdk_event_discrete_scroll_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_SCROLL; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->tool = tool ? g_object_ref (tool) : NULL; - event->time = time; event->state = state; event->x = NAN; event->y = NAN; event->direction = direction; - if (emulated) - event->any.flags = GDK_EVENT_POINTER_EMULATED; + event->any.pointer_emulated = emulated; return (GdkEvent *)event; } @@ -1102,18 +1104,17 @@ gdk_event_touch_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); event->sequence = sequence; - event->time = time; event->state = state; event->x = x; event->y = y; event->axes = axes; - event->emulating_pointer = emulating; - if (emulating) - event->any.flags = GDK_EVENT_POINTER_EMULATED; + event->any.touch_emulating = emulating; + event->any.pointer_emulated = emulating; return (GdkEvent *)event; } @@ -1135,10 +1136,10 @@ gdk_event_touchpad_swipe_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_TOUCHPAD_SWIPE; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->state = state; event->phase = phase; event->x = x; @@ -1169,10 +1170,10 @@ gdk_event_touchpad_pinch_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_TOUCHPAD_PINCH; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->state = state; event->phase = phase; event->x = x; @@ -1200,10 +1201,10 @@ gdk_event_pad_ring_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_PAD_RING; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->group = group; event->index = index; event->mode = mode; @@ -1226,10 +1227,10 @@ gdk_event_pad_strip_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_PAD_STRIP; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->group = group; event->index = index; event->mode = mode; @@ -1257,10 +1258,10 @@ gdk_event_pad_button_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->group = group; event->button = button; event->mode = mode; @@ -1280,10 +1281,10 @@ gdk_event_pad_group_mode_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_PAD_GROUP_MODE; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); - event->time = time; event->group = group; event->mode = mode; @@ -1310,10 +1311,10 @@ gdk_event_drag_new (GdkEventType type, event->any.ref_count = 1; event->any.type = type; + event->any.time = time; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->drop = g_object_ref (drop); - event->time = time; event->x = x; event->y = y; @@ -1331,6 +1332,7 @@ gdk_event_grab_broken_new (GdkSurface *surface, event->any.ref_count = 1; event->any.type = GDK_GRAB_BROKEN; + event->any.time = GDK_CURRENT_TIME; event->any.surface = g_object_ref (surface); event->any.device = g_object_ref (device); event->any.source_device = g_object_ref (source_device); @@ -1452,57 +1454,7 @@ gdk_event_get_device_tool (GdkEvent *event) guint32 gdk_event_get_time (GdkEvent *event) { - switch (event->any.type) - { - case GDK_MOTION_NOTIFY: - return event->motion.time; - case GDK_BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - return event->button.time; - case GDK_TOUCH_BEGIN: - case GDK_TOUCH_UPDATE: - case GDK_TOUCH_END: - case GDK_TOUCH_CANCEL: - return event->touch.time; - case GDK_TOUCHPAD_SWIPE: - return event->touchpad_swipe.time; - case GDK_TOUCHPAD_PINCH: - return event->touchpad_pinch.time; - case GDK_SCROLL: - return event->scroll.time; - case GDK_KEY_PRESS: - case GDK_KEY_RELEASE: - return event->key.time; - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - return event->crossing.time; - case GDK_PROXIMITY_IN: - case GDK_PROXIMITY_OUT: - return event->proximity.time; - case GDK_DRAG_ENTER: - case GDK_DRAG_LEAVE: - case GDK_DRAG_MOTION: - case GDK_DROP_START: - return event->dnd.time; - case GDK_PAD_BUTTON_PRESS: - case GDK_PAD_BUTTON_RELEASE: - return event->pad_button.time; - case GDK_PAD_RING: - case GDK_PAD_STRIP: - return event->pad_axis.time; - case GDK_PAD_GROUP_MODE: - return event->pad_group_mode.time; - case GDK_CONFIGURE: - case GDK_FOCUS_CHANGE: - case GDK_DELETE: - case GDK_GRAB_BROKEN: - case GDK_EVENT_LAST: - default: - /* return current time */ - break; - } - - return GDK_CURRENT_TIME; + return event->any.time; } /** @@ -1781,7 +1733,7 @@ gdk_key_event_is_modifier (GdkEvent *event) g_return_val_if_fail (event->any.type == GDK_KEY_PRESS || event->any.type == GDK_KEY_RELEASE, FALSE); - return event->key.is_modifier; + return event->any.key_is_modifier; } /** @@ -1819,7 +1771,7 @@ gdk_touch_event_get_emulating_pointer (GdkEvent *event) event->any.type == GDK_TOUCH_END || event->any.type == GDK_TOUCH_CANCEL, FALSE); - return event->touch.emulating_pointer; + return event->any.touch_emulating; } /** @@ -1870,7 +1822,7 @@ gdk_focus_event_get_in (GdkEvent *event) { g_return_val_if_fail (event->any.type == GDK_FOCUS_CHANGE, FALSE); - return event->focus_change.in; + return event->any.focus_in; } /** @@ -1930,7 +1882,7 @@ gdk_scroll_event_is_stop (GdkEvent *event) { g_return_val_if_fail (event->any.type == GDK_SCROLL, FALSE); - return event->scroll.is_stop; + return event->any.scroll_is_stop; } /** diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h index b3b389319f..7f7d7ffe73 100644 --- a/gdk/gdkeventsprivate.h +++ b/gdk/gdkeventsprivate.h @@ -45,7 +45,13 @@ struct _GdkEventAny int ref_count; GdkEventType type; GdkSurface *surface; + guint32 time; guint16 flags; + guint pointer_emulated : 1; + guint touch_emulating : 1; + guint scroll_is_stop : 1; + guint key_is_modifier : 1; + guint focus_in : 1; GdkDevice *device; GdkDevice *source_device; }; @@ -72,11 +78,10 @@ struct _GdkEventAny struct _GdkEventMotion { GdkEventAny any; - guint32 time; + GdkModifierType state; double x; double y; double *axes; - GdkModifierType state; GdkDeviceTool *tool; GList *history; }; @@ -108,12 +113,11 @@ struct _GdkEventMotion struct _GdkEventButton { GdkEventAny any; - guint32 time; + GdkModifierType state; + guint button; double x; double y; double *axes; - GdkModifierType state; - guint button; GdkDeviceTool *tool; }; @@ -152,13 +156,11 @@ struct _GdkEventButton struct _GdkEventTouch { GdkEventAny any; - guint32 time; + GdkModifierType state; double x; double y; double *axes; - GdkModifierType state; GdkEventSequence *sequence; - gboolean emulating_pointer; }; /* @@ -192,14 +194,12 @@ struct _GdkEventTouch struct _GdkEventScroll { GdkEventAny any; - guint32 time; double x; double y; GdkModifierType state; GdkScrollDirection direction; double delta_x; double delta_y; - guint is_stop : 1; GdkDeviceTool *tool; }; @@ -225,13 +225,11 @@ struct _GdkEventScroll struct _GdkEventKey { GdkEventAny any; - guint32 time; GdkModifierType state; guint keyval; guint16 hardware_keycode; guint16 key_scancode; guint8 group; - guint is_modifier : 1; }; /* @@ -261,14 +259,13 @@ struct _GdkEventKey struct _GdkEventCrossing { GdkEventAny any; - GdkSurface *child_surface; - guint32 time; + GdkModifierType state; + GdkCrossingMode mode; double x; double y; - GdkCrossingMode mode; GdkNotifyType detail; gboolean focus; - GdkModifierType state; + GdkSurface *child_surface; }; /* @@ -334,7 +331,6 @@ struct _GdkEventConfigure struct _GdkEventProximity { GdkEventAny any; - guint32 time; GdkDeviceTool *tool; }; @@ -378,7 +374,6 @@ struct _GdkEventGrabBroken { struct _GdkEventDND { GdkEventAny any; GdkDrop *drop; - guint32 time; double x; double y; }; @@ -403,14 +398,13 @@ struct _GdkEventDND { */ struct _GdkEventTouchpadSwipe { GdkEventAny any; + GdkModifierType state; gint8 phase; gint8 n_fingers; - guint32 time; double x; double y; double dx; double dy; - GdkModifierType state; }; /* @@ -437,16 +431,15 @@ struct _GdkEventTouchpadSwipe { */ struct _GdkEventTouchpadPinch { GdkEventAny any; + GdkModifierType state; gint8 phase; gint8 n_fingers; - guint32 time; double x; double y; double dx; double dy; double angle_delta; double scale; - GdkModifierType state; }; /* @@ -465,7 +458,6 @@ struct _GdkEventTouchpadPinch { */ struct _GdkEventPadButton { GdkEventAny any; - guint32 time; guint group; guint button; guint mode; @@ -489,7 +481,6 @@ struct _GdkEventPadButton { */ struct _GdkEventPadAxis { GdkEventAny any; - guint32 time; guint group; guint index; guint mode; @@ -512,7 +503,6 @@ struct _GdkEventPadAxis { */ struct _GdkEventPadGroupMode { GdkEventAny any; - guint32 time; guint group; guint mode; }; diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index ebe529c654..f1e06a9b09 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -102,12 +102,6 @@ typedef enum */ GDK_EVENT_PENDING = 1 << 0, - /* The following flag is set for: - * 1) touch events emulating pointer events - * 2) pointer events being emulated by a touch sequence. - */ - GDK_EVENT_POINTER_EMULATED = 1 << 1, - /* When we are ready to draw a frame, we pause event delivery, * mark all events in the queue with this flag, and deliver * only those events until we finish the frame.