clutter: Drop click count from button events

This does two things to frown upon:
- Modifies ClutterEvent structs, while the effort is to have those
  completely opaque, and readonly after creation from the input
  thread side.
- Stores state in the ClutterInputDevice struct, event though those
  are also considered static after creation, managed by the input
  thread, etc.

Stop doing that. This makes all events just forwarded as-is in
the ClutterStage/clutter-main.c code.

Handling of click count sounds like material for a ClutterGestureAction
(or perhaps ClutterClickAction), all of both callers now do it in place
at the moment, while gestures lack a better state tracking and management.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2024>
This commit is contained in:
Carlos Garnacho 2021-09-27 21:46:07 +02:00
parent 33ca5e3d80
commit 3d37602c54
5 changed files with 1 additions and 154 deletions

View File

@ -823,27 +823,6 @@ clutter_event_set_button (ClutterEvent *event,
event->button.button = button; event->button.button = button;
} }
/**
* clutter_event_get_click_count:
* @event: a #ClutterEvent of type %CLUTTER_BUTTON_PRESS or
* of type %CLUTTER_BUTTON_RELEASE
*
* Retrieves the number of clicks of @event
*
* Return value: the click count
*
* Since: 1.0
*/
guint32
clutter_event_get_click_count (const ClutterEvent *event)
{
g_return_val_if_fail (event != NULL, 0);
g_return_val_if_fail (event->type == CLUTTER_BUTTON_PRESS ||
event->type == CLUTTER_BUTTON_RELEASE, 0);
return event->button.click_count;
}
/* keys */ /* keys */
/** /**

View File

@ -188,8 +188,6 @@ struct _ClutterKeyEvent
* @y: event Y coordinate, relative to the stage * @y: event Y coordinate, relative to the stage
* @modifier_state: button modifiers * @modifier_state: button modifiers
* @button: event button * @button: event button
* @click_count: number of button presses within the default time
* and radius
* @axes: reserved for future use * @axes: reserved for future use
* @device: the device that originated the event. If you want the physical * @device: the device that originated the event. If you want the physical
* device the event originated from, use clutter_event_get_source_device() * device the event originated from, use clutter_event_get_source_device()
@ -214,7 +212,6 @@ struct _ClutterButtonEvent
gfloat y; gfloat y;
ClutterModifierType modifier_state; ClutterModifierType modifier_state;
guint32 button; guint32 button;
guint click_count;
gdouble *axes; /* Future use */ gdouble *axes; /* Future use */
ClutterInputDevice *device; ClutterInputDevice *device;
uint32_t evdev_code; uint32_t evdev_code;
@ -740,8 +737,6 @@ void clutter_event_set_button (ClutterEvent
CLUTTER_EXPORT CLUTTER_EXPORT
guint32 clutter_event_get_button (const ClutterEvent *event); guint32 clutter_event_get_button (const ClutterEvent *event);
CLUTTER_EXPORT CLUTTER_EXPORT
guint clutter_event_get_click_count (const ClutterEvent *event);
CLUTTER_EXPORT
void clutter_event_set_related (ClutterEvent *event, void clutter_event_set_related (ClutterEvent *event,
ClutterActor *actor); ClutterActor *actor);
CLUTTER_EXPORT CLUTTER_EXPORT

View File

@ -59,16 +59,6 @@ struct _ClutterInputDevice
GHashTable *sequence_grab_actors; GHashTable *sequence_grab_actors;
GHashTable *inv_sequence_grab_actors; GHashTable *inv_sequence_grab_actors;
/* the current click count */
int click_count;
int current_button_number;
/* the previous state, used for click count generation */
int previous_x;
int previous_y;
uint32_t previous_time;
int previous_button_number;
/* Accessiblity */ /* Accessiblity */
ClutterVirtualInputDevice *accessibility_virtual_device; ClutterVirtualInputDevice *accessibility_virtual_device;
ClutterPtrA11yData *ptr_a11y_data; ClutterPtrA11yData *ptr_a11y_data;

View File

@ -427,13 +427,6 @@ clutter_input_device_init (ClutterInputDevice *self)
clutter_input_device_get_instance_private (self); clutter_input_device_get_instance_private (self);
priv->device_type = CLUTTER_POINTER_DEVICE; priv->device_type = CLUTTER_POINTER_DEVICE;
self->click_count = 0;
self->previous_time = CLUTTER_CURRENT_TIME;
self->previous_x = -1;
self->previous_y = -1;
self->current_button_number = self->previous_button_number = -1;
} }
/** /**

View File

@ -674,107 +674,6 @@ _clutter_boolean_continue_accumulator (GSignalInvocationHint *ihint,
return continue_emission; return continue_emission;
} }
static void
event_click_count_generate (ClutterEvent *event)
{
/* multiple button click detection */
static gint click_count = 0;
static gint previous_x = -1;
static gint previous_y = -1;
static guint32 previous_time = 0;
static gint previous_button_number = -1;
ClutterInputDevice *device = NULL;
ClutterSettings *settings;
guint double_click_time;
guint double_click_distance;
settings = clutter_settings_get_default ();
g_object_get (settings,
"double-click-distance", &double_click_distance,
"double-click-time", &double_click_time,
NULL);
device = clutter_event_get_device (event);
if (device != NULL)
{
click_count = device->click_count;
previous_x = device->previous_x;
previous_y = device->previous_y;
previous_time = device->previous_time;
previous_button_number = device->previous_button_number;
CLUTTER_NOTE (EVENT,
"Restoring previous click count:%d (device:%s, time:%u)",
click_count,
clutter_input_device_get_device_name (device),
previous_time);
}
else
{
CLUTTER_NOTE (EVENT,
"Restoring previous click count:%d (time:%u)",
click_count,
previous_time);
}
switch (clutter_event_type (event))
{
case CLUTTER_BUTTON_PRESS:
/* check if we are in time and within distance to increment an
* existing click count
*/
if (event->button.button == previous_button_number &&
event->button.time < (previous_time + double_click_time) &&
(ABS (event->button.x - previous_x) <= double_click_distance) &&
(ABS (event->button.y - previous_y) <= double_click_distance))
{
CLUTTER_NOTE (EVENT, "Increase click count (button: %d, time: %u)",
event->button.button,
event->button.time);
click_count += 1;
}
else /* start a new click count*/
{
CLUTTER_NOTE (EVENT, "Reset click count (button: %d, time: %u)",
event->button.button,
event->button.time);
click_count = 1;
previous_button_number = event->button.button;
}
previous_x = event->button.x;
previous_y = event->button.y;
previous_time = event->button.time;
G_GNUC_FALLTHROUGH;
case CLUTTER_BUTTON_RELEASE:
event->button.click_count = click_count;
break;
default:
g_assert_not_reached ();
break;
}
if (event->type == CLUTTER_BUTTON_PRESS && device != NULL)
{
CLUTTER_NOTE (EVENT, "Storing click count: %d (device:%s, time:%u)",
click_count,
clutter_input_device_get_device_name (device),
previous_time);
device->click_count = click_count;
device->previous_x = previous_x;
device->previous_y = previous_y;
device->previous_time = previous_time;
device->previous_button_number = previous_button_number;
}
}
static inline void static inline void
emit_event_chain (ClutterEvent *event) emit_event_chain (ClutterEvent *event)
{ {
@ -789,7 +688,7 @@ emit_event_chain (ClutterEvent *event)
/* /*
* Emits a pointer event after having prepared the event for delivery (setting * Emits a pointer event after having prepared the event for delivery (setting
* source, computing click_count, generating enter/leave etc.). * source, generating enter/leave etc.).
*/ */
static inline void static inline void
@ -1266,7 +1165,6 @@ _clutter_process_event_details (ClutterActor *stage,
x, y); x, y);
event->button.source = stage; event->button.source = stage;
event->button.click_count = 1;
emit_pointer_event (event, device); emit_pointer_event (event, device);
} }
@ -1311,14 +1209,6 @@ _clutter_process_event_details (ClutterActor *stage,
x, y, x, y,
event->any.source); event->any.source);
/* button presses and releases need a click count */
if (event->type == CLUTTER_BUTTON_PRESS ||
event->type == CLUTTER_BUTTON_RELEASE)
{
/* Generate click count */
event_click_count_generate (event);
}
emit_pointer_event (event, device); emit_pointer_event (event, device);
break; break;
} }