clutter: Add getters/arguments for missed ClutterEvent fields

Add methods, and change the API of some rarely used methods, in order
to make all event info currently held/necessary accessible through
ClutterEvent getters, instead of direct field access.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3153>
This commit is contained in:
Carlos Garnacho 2023-08-04 10:59:42 +02:00
parent fec26f201a
commit 97213041e8
4 changed files with 95 additions and 18 deletions

View File

@ -1449,10 +1449,11 @@ clutter_event_get_mode_group (const ClutterEvent *event)
}
/**
* clutter_event_get_pad_event_details:
* clutter_event_get_pad_details:
* @event: a pad event
* @number: (out) (optional): ring/strip/button number
* @mode: (out) (optional): pad mode as per the event
* @source: (out) (optional): source of the event
* @value: (out) (optional): event axis value
*
* Returns the details of a pad event.
@ -1460,11 +1461,13 @@ clutter_event_get_mode_group (const ClutterEvent *event)
* Returns: #TRUE if event details could be obtained
**/
gboolean
clutter_event_get_pad_event_details (const ClutterEvent *event,
guint *number,
guint *mode,
gdouble *value)
clutter_event_get_pad_details (const ClutterEvent *event,
guint *number,
guint *mode,
ClutterInputDevicePadSource *source,
gdouble *value)
{
ClutterInputDevicePadSource s;
guint n, m;
gdouble v;
@ -1480,16 +1483,19 @@ clutter_event_get_pad_event_details (const ClutterEvent *event,
case CLUTTER_PAD_BUTTON_RELEASE:
n = event->pad_button.button;
m = event->pad_button.mode;
s = CLUTTER_INPUT_DEVICE_PAD_SOURCE_UNKNOWN;
v = 0.0;
break;
case CLUTTER_PAD_RING:
n = event->pad_ring.ring_number;
m = event->pad_ring.mode;
s = event->pad_ring.ring_source;
v = event->pad_ring.angle;
break;
case CLUTTER_PAD_STRIP:
n = event->pad_strip.strip_number;
m = event->pad_strip.mode;
s = event->pad_strip.strip_source;
v = event->pad_strip.value;
break;
default:
@ -1500,6 +1506,8 @@ clutter_event_get_pad_event_details (const ClutterEvent *event,
*number = n;
if (mode)
*mode = m;
if (source)
*source = s;
if (value)
*value = v;
@ -1541,7 +1549,9 @@ clutter_event_get_relative_motion (const ClutterEvent *event,
double *dx,
double *dy,
double *dx_unaccel,
double *dy_unaccel)
double *dy_unaccel,
double *dx_constrained,
double *dy_constrained)
{
if (event->type == CLUTTER_MOTION &&
event->motion.flags & CLUTTER_EVENT_FLAG_RELATIVE_MOTION)
@ -1554,6 +1564,10 @@ clutter_event_get_relative_motion (const ClutterEvent *event,
*dx_unaccel = event->motion.dx_unaccel;
if (dy_unaccel)
*dy_unaccel = event->motion.dy_unaccel;
if (dx_constrained)
*dx_constrained = event->motion.dx_constrained;
if (dy_constrained)
*dy_constrained = event->motion.dy_constrained;
return TRUE;
}
@ -1561,6 +1575,53 @@ clutter_event_get_relative_motion (const ClutterEvent *event,
return FALSE;
}
const char *
clutter_event_get_im_text (const ClutterEvent *event)
{
g_return_val_if_fail (event != NULL, NULL);
g_return_val_if_fail (event->type == CLUTTER_IM_COMMIT ||
event->type == CLUTTER_IM_PREEDIT, NULL);
return event->im.text;
}
gboolean
clutter_event_get_im_location (const ClutterEvent *event,
int32_t *offset,
int32_t *anchor)
{
g_return_val_if_fail (event != NULL, FALSE);
g_return_val_if_fail (event->type == CLUTTER_IM_DELETE ||
event->type == CLUTTER_IM_PREEDIT, FALSE);
if (offset)
*offset = event->im.offset;
if (anchor)
*anchor = event->im.anchor;
return TRUE;
}
uint32_t
clutter_event_get_im_delete_length (const ClutterEvent *event)
{
g_return_val_if_fail (event != NULL, 0);
g_return_val_if_fail (event->type == CLUTTER_IM_DELETE, 0);
return event->im.len;
}
ClutterPreeditResetMode
clutter_event_get_im_preedit_reset_mode (const ClutterEvent *event)
{
g_return_val_if_fail (event != NULL, CLUTTER_PREEDIT_RESET_CLEAR);
g_return_val_if_fail (event->type == CLUTTER_IM_COMMIT ||
event->type == CLUTTER_IM_PREEDIT,
CLUTTER_PREEDIT_RESET_CLEAR);
return event->im.mode;
}
const char *
clutter_event_get_name (const ClutterEvent *event)
{

View File

@ -720,10 +720,11 @@ CLUTTER_EXPORT
guint clutter_event_get_mode_group (const ClutterEvent *event);
CLUTTER_EXPORT
gboolean clutter_event_get_pad_event_details (const ClutterEvent *event,
guint *number,
guint *mode,
gdouble *value);
gboolean clutter_event_get_pad_details (const ClutterEvent *event,
guint *number,
guint *mode,
ClutterInputDevicePadSource *source,
gdouble *value);
CLUTTER_EXPORT
uint32_t clutter_event_get_event_code (const ClutterEvent *event);
@ -733,11 +734,23 @@ int32_t clutter_event_sequence_get_slot (const ClutterEventSequ
CLUTTER_EXPORT
int64_t clutter_event_get_time_us (const ClutterEvent *event);
CLUTTER_EXPORT
gboolean clutter_event_get_relative_motion (const ClutterEvent *event,
double *dx,
double *dy,
double *dx_unaccel,
double *dy_unaccel);
gboolean clutter_event_get_relative_motion (const ClutterEvent *event,
double *dx,
double *dy,
double *dx_unaccel,
double *dy_unaccel,
double *dx_constrained,
double *dy_constrained);
CLUTTER_EXPORT
const char * clutter_event_get_im_text (const ClutterEvent *event);
CLUTTER_EXPORT
gboolean clutter_event_get_im_location (const ClutterEvent *event,
int32_t *offset,
int32_t *anchor);
CLUTTER_EXPORT
uint32_t clutter_event_get_im_delete_length (const ClutterEvent *event);
CLUTTER_EXPORT
ClutterPreeditResetMode clutter_event_get_im_preedit_reset_mode (const ClutterEvent *event);
G_END_DECLS

View File

@ -680,12 +680,14 @@ clutter_stage_compress_motion (ClutterStage *stage,
if (!clutter_event_get_relative_motion (to_discard,
&dx, &dy,
&dx_unaccel, &dy_unaccel))
&dx_unaccel, &dy_unaccel,
NULL, NULL))
return;
clutter_event_get_relative_motion (event,
&dst_dx, &dst_dy,
&dst_dx_unaccel, &dst_dy_unaccel);
&dst_dx_unaccel, &dst_dy_unaccel,
NULL, NULL);
event->motion.flags |= CLUTTER_EVENT_FLAG_RELATIVE_MOTION;
event->motion.dx = dx + dst_dx;

View File

@ -359,7 +359,8 @@ meta_wayland_pointer_send_relative_motion (MetaWaylandPointer *pointer,
if (!clutter_event_get_relative_motion (event,
&dx, &dy,
&dx_unaccel, &dy_unaccel))
&dx_unaccel, &dy_unaccel,
NULL, NULL))
return;
time_us = clutter_event_get_time_us (event);