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.
This commit is contained in:
Matthias Clasen 2020-02-17 23:08:44 -05:00
parent 84edce3732
commit 6fd913b361
3 changed files with 46 additions and 110 deletions

View File

@ -406,7 +406,7 @@ gdk_event_unref (GdkEvent *event)
gboolean gboolean
gdk_event_get_pointer_emulated (GdkEvent *event) gdk_event_get_pointer_emulated (GdkEvent *event)
{ {
return (event->any.flags & GDK_EVENT_POINTER_EMULATED) != 0; return event->any.pointer_emulated;
} }
static void static void
@ -832,11 +832,11 @@ gdk_event_button_new (GdkEventType type,
event = g_new0 (GdkEventButton, 1); event = g_new0 (GdkEventButton, 1);
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->tool = tool ? g_object_ref (tool) : NULL; event->tool = tool ? g_object_ref (tool) : NULL;
event->time = time;
event->axes = NULL; event->axes = NULL;
event->state = state; event->state = state;
event->button = button; event->button = button;
@ -862,11 +862,11 @@ gdk_event_motion_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_MOTION_NOTIFY; event->any.type = GDK_MOTION_NOTIFY;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->tool = tool ? g_object_ref (tool) : NULL; event->tool = tool ? g_object_ref (tool) : NULL;
event->time = time;
event->state = state; event->state = state;
event->x = x; event->x = x;
event->y = y; event->y = y;
@ -897,10 +897,10 @@ gdk_event_crossing_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->state = state; event->state = state;
event->x = x; event->x = x;
event->y = y; event->y = y;
@ -927,11 +927,11 @@ gdk_event_proximity_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->tool = tool ? g_object_ref (tool) : NULL; event->tool = tool ? g_object_ref (tool) : NULL;
event->time = time;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -958,16 +958,16 @@ gdk_event_key_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->state = state; event->state = state;
event->keyval = keyval; event->keyval = keyval;
event->hardware_keycode = keycode; event->hardware_keycode = keycode;
event->key_scancode = scancode; event->key_scancode = scancode;
event->group = group; event->group = group;
event->is_modifier = is_modifier; event->any.key_is_modifier = is_modifier;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -981,6 +981,7 @@ gdk_event_configure_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_CONFIGURE; event->any.type = GDK_CONFIGURE;
event->any.time = GDK_CURRENT_TIME;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->width = width; event->width = width;
event->height = height; event->height = height;
@ -995,6 +996,7 @@ gdk_event_delete_new (GdkSurface *surface)
event->ref_count = 1; event->ref_count = 1;
event->type = GDK_DELETE; event->type = GDK_DELETE;
event->time = GDK_CURRENT_TIME;
event->surface = g_object_ref (surface); event->surface = g_object_ref (surface);
return (GdkEvent *)event; return (GdkEvent *)event;
@ -1010,10 +1012,11 @@ gdk_event_focus_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_FOCUS_CHANGE; event->any.type = GDK_FOCUS_CHANGE;
event->any.time = GDK_CURRENT_TIME;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->in = focus_in; event->any.focus_in = focus_in;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -1033,18 +1036,18 @@ gdk_event_scroll_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_SCROLL; event->any.type = GDK_SCROLL;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->tool = tool ? g_object_ref (tool) : NULL; event->tool = tool ? g_object_ref (tool) : NULL;
event->time = time;
event->state = state; event->state = state;
event->x = NAN; event->x = NAN;
event->y = NAN; event->y = NAN;
event->direction = GDK_SCROLL_SMOOTH; event->direction = GDK_SCROLL_SMOOTH;
event->delta_x = delta_x; event->delta_x = delta_x;
event->delta_y = delta_y; event->delta_y = delta_y;
event->is_stop = is_stop; event->any.scroll_is_stop = is_stop;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -1063,17 +1066,16 @@ gdk_event_discrete_scroll_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_SCROLL; event->any.type = GDK_SCROLL;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->tool = tool ? g_object_ref (tool) : NULL; event->tool = tool ? g_object_ref (tool) : NULL;
event->time = time;
event->state = state; event->state = state;
event->x = NAN; event->x = NAN;
event->y = NAN; event->y = NAN;
event->direction = direction; event->direction = direction;
if (emulated) event->any.pointer_emulated = emulated;
event->any.flags = GDK_EVENT_POINTER_EMULATED;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -1102,18 +1104,17 @@ gdk_event_touch_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->sequence = sequence; event->sequence = sequence;
event->time = time;
event->state = state; event->state = state;
event->x = x; event->x = x;
event->y = y; event->y = y;
event->axes = axes; event->axes = axes;
event->emulating_pointer = emulating; event->any.touch_emulating = emulating;
if (emulating) event->any.pointer_emulated = emulating;
event->any.flags = GDK_EVENT_POINTER_EMULATED;
return (GdkEvent *)event; return (GdkEvent *)event;
} }
@ -1135,10 +1136,10 @@ gdk_event_touchpad_swipe_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_TOUCHPAD_SWIPE; event->any.type = GDK_TOUCHPAD_SWIPE;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->state = state; event->state = state;
event->phase = phase; event->phase = phase;
event->x = x; event->x = x;
@ -1169,10 +1170,10 @@ gdk_event_touchpad_pinch_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_TOUCHPAD_PINCH; event->any.type = GDK_TOUCHPAD_PINCH;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->state = state; event->state = state;
event->phase = phase; event->phase = phase;
event->x = x; event->x = x;
@ -1200,10 +1201,10 @@ gdk_event_pad_ring_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_PAD_RING; event->any.type = GDK_PAD_RING;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->group = group; event->group = group;
event->index = index; event->index = index;
event->mode = mode; event->mode = mode;
@ -1226,10 +1227,10 @@ gdk_event_pad_strip_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_PAD_STRIP; event->any.type = GDK_PAD_STRIP;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->group = group; event->group = group;
event->index = index; event->index = index;
event->mode = mode; event->mode = mode;
@ -1257,10 +1258,10 @@ gdk_event_pad_button_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->group = group; event->group = group;
event->button = button; event->button = button;
event->mode = mode; event->mode = mode;
@ -1280,10 +1281,10 @@ gdk_event_pad_group_mode_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_PAD_GROUP_MODE; event->any.type = GDK_PAD_GROUP_MODE;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
event->time = time;
event->group = group; event->group = group;
event->mode = mode; event->mode = mode;
@ -1310,10 +1311,10 @@ gdk_event_drag_new (GdkEventType type,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = type; event->any.type = type;
event->any.time = time;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->drop = g_object_ref (drop); event->drop = g_object_ref (drop);
event->time = time;
event->x = x; event->x = x;
event->y = y; event->y = y;
@ -1331,6 +1332,7 @@ gdk_event_grab_broken_new (GdkSurface *surface,
event->any.ref_count = 1; event->any.ref_count = 1;
event->any.type = GDK_GRAB_BROKEN; event->any.type = GDK_GRAB_BROKEN;
event->any.time = GDK_CURRENT_TIME;
event->any.surface = g_object_ref (surface); event->any.surface = g_object_ref (surface);
event->any.device = g_object_ref (device); event->any.device = g_object_ref (device);
event->any.source_device = g_object_ref (source_device); event->any.source_device = g_object_ref (source_device);
@ -1452,57 +1454,7 @@ gdk_event_get_device_tool (GdkEvent *event)
guint32 guint32
gdk_event_get_time (GdkEvent *event) gdk_event_get_time (GdkEvent *event)
{ {
switch (event->any.type) return event->any.time;
{
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;
} }
/** /**
@ -1781,7 +1733,7 @@ gdk_key_event_is_modifier (GdkEvent *event)
g_return_val_if_fail (event->any.type == GDK_KEY_PRESS || g_return_val_if_fail (event->any.type == GDK_KEY_PRESS ||
event->any.type == GDK_KEY_RELEASE, FALSE); 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_END ||
event->any.type == GDK_TOUCH_CANCEL, FALSE); 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); 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); g_return_val_if_fail (event->any.type == GDK_SCROLL, FALSE);
return event->scroll.is_stop; return event->any.scroll_is_stop;
} }
/** /**

View File

@ -45,7 +45,13 @@ struct _GdkEventAny
int ref_count; int ref_count;
GdkEventType type; GdkEventType type;
GdkSurface *surface; GdkSurface *surface;
guint32 time;
guint16 flags; 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 *device;
GdkDevice *source_device; GdkDevice *source_device;
}; };
@ -72,11 +78,10 @@ struct _GdkEventAny
struct _GdkEventMotion struct _GdkEventMotion
{ {
GdkEventAny any; GdkEventAny any;
guint32 time; GdkModifierType state;
double x; double x;
double y; double y;
double *axes; double *axes;
GdkModifierType state;
GdkDeviceTool *tool; GdkDeviceTool *tool;
GList *history; GList *history;
}; };
@ -108,12 +113,11 @@ struct _GdkEventMotion
struct _GdkEventButton struct _GdkEventButton
{ {
GdkEventAny any; GdkEventAny any;
guint32 time; GdkModifierType state;
guint button;
double x; double x;
double y; double y;
double *axes; double *axes;
GdkModifierType state;
guint button;
GdkDeviceTool *tool; GdkDeviceTool *tool;
}; };
@ -152,13 +156,11 @@ struct _GdkEventButton
struct _GdkEventTouch struct _GdkEventTouch
{ {
GdkEventAny any; GdkEventAny any;
guint32 time; GdkModifierType state;
double x; double x;
double y; double y;
double *axes; double *axes;
GdkModifierType state;
GdkEventSequence *sequence; GdkEventSequence *sequence;
gboolean emulating_pointer;
}; };
/* /*
@ -192,14 +194,12 @@ struct _GdkEventTouch
struct _GdkEventScroll struct _GdkEventScroll
{ {
GdkEventAny any; GdkEventAny any;
guint32 time;
double x; double x;
double y; double y;
GdkModifierType state; GdkModifierType state;
GdkScrollDirection direction; GdkScrollDirection direction;
double delta_x; double delta_x;
double delta_y; double delta_y;
guint is_stop : 1;
GdkDeviceTool *tool; GdkDeviceTool *tool;
}; };
@ -225,13 +225,11 @@ struct _GdkEventScroll
struct _GdkEventKey struct _GdkEventKey
{ {
GdkEventAny any; GdkEventAny any;
guint32 time;
GdkModifierType state; GdkModifierType state;
guint keyval; guint keyval;
guint16 hardware_keycode; guint16 hardware_keycode;
guint16 key_scancode; guint16 key_scancode;
guint8 group; guint8 group;
guint is_modifier : 1;
}; };
/* /*
@ -261,14 +259,13 @@ struct _GdkEventKey
struct _GdkEventCrossing struct _GdkEventCrossing
{ {
GdkEventAny any; GdkEventAny any;
GdkSurface *child_surface; GdkModifierType state;
guint32 time; GdkCrossingMode mode;
double x; double x;
double y; double y;
GdkCrossingMode mode;
GdkNotifyType detail; GdkNotifyType detail;
gboolean focus; gboolean focus;
GdkModifierType state; GdkSurface *child_surface;
}; };
/* /*
@ -334,7 +331,6 @@ struct _GdkEventConfigure
struct _GdkEventProximity struct _GdkEventProximity
{ {
GdkEventAny any; GdkEventAny any;
guint32 time;
GdkDeviceTool *tool; GdkDeviceTool *tool;
}; };
@ -378,7 +374,6 @@ struct _GdkEventGrabBroken {
struct _GdkEventDND { struct _GdkEventDND {
GdkEventAny any; GdkEventAny any;
GdkDrop *drop; GdkDrop *drop;
guint32 time;
double x; double x;
double y; double y;
}; };
@ -403,14 +398,13 @@ struct _GdkEventDND {
*/ */
struct _GdkEventTouchpadSwipe { struct _GdkEventTouchpadSwipe {
GdkEventAny any; GdkEventAny any;
GdkModifierType state;
gint8 phase; gint8 phase;
gint8 n_fingers; gint8 n_fingers;
guint32 time;
double x; double x;
double y; double y;
double dx; double dx;
double dy; double dy;
GdkModifierType state;
}; };
/* /*
@ -437,16 +431,15 @@ struct _GdkEventTouchpadSwipe {
*/ */
struct _GdkEventTouchpadPinch { struct _GdkEventTouchpadPinch {
GdkEventAny any; GdkEventAny any;
GdkModifierType state;
gint8 phase; gint8 phase;
gint8 n_fingers; gint8 n_fingers;
guint32 time;
double x; double x;
double y; double y;
double dx; double dx;
double dy; double dy;
double angle_delta; double angle_delta;
double scale; double scale;
GdkModifierType state;
}; };
/* /*
@ -465,7 +458,6 @@ struct _GdkEventTouchpadPinch {
*/ */
struct _GdkEventPadButton { struct _GdkEventPadButton {
GdkEventAny any; GdkEventAny any;
guint32 time;
guint group; guint group;
guint button; guint button;
guint mode; guint mode;
@ -489,7 +481,6 @@ struct _GdkEventPadButton {
*/ */
struct _GdkEventPadAxis { struct _GdkEventPadAxis {
GdkEventAny any; GdkEventAny any;
guint32 time;
guint group; guint group;
guint index; guint index;
guint mode; guint mode;
@ -512,7 +503,6 @@ struct _GdkEventPadAxis {
*/ */
struct _GdkEventPadGroupMode { struct _GdkEventPadGroupMode {
GdkEventAny any; GdkEventAny any;
guint32 time;
guint group; guint group;
guint mode; guint mode;
}; };

View File

@ -102,12 +102,6 @@ typedef enum
*/ */
GDK_EVENT_PENDING = 1 << 0, 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, /* When we are ready to draw a frame, we pause event delivery,
* mark all events in the queue with this flag, and deliver * mark all events in the queue with this flag, and deliver
* only those events until we finish the frame. * only those events until we finish the frame.