From 6fd7f95ed3a830709166abc5f51642b6a85843b9 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 21 Jul 2023 19:27:05 +0200 Subject: [PATCH] tests: Port faked events to new constructors Part-of: --- src/tests/clutter-test-utils.h | 1 + src/tests/clutter/conform/actor-event-hold.c | 15 ++++---- src/tests/clutter/conform/binding-pool.c | 28 +++++++-------- src/tests/clutter/conform/text.c | 33 +++++++++--------- src/tests/clutter/performance/test-common.h | 36 +++++++++++--------- src/tests/meta-backend-test.c | 14 ++++---- 6 files changed, 64 insertions(+), 63 deletions(-) diff --git a/src/tests/clutter-test-utils.h b/src/tests/clutter-test-utils.h index 77f462d66..fc0ad8d8e 100644 --- a/src/tests/clutter-test-utils.h +++ b/src/tests/clutter-test-utils.h @@ -28,6 +28,7 @@ #include "clutter/clutter-types.h" #include "clutter/clutter-actor.h" #include "clutter/clutter-color.h" +#include "clutter/clutter-event-private.h" #include "clutter/clutter-private.h" #include "meta/common.h" #include "meta-test/meta-context-test.h" diff --git a/src/tests/clutter/conform/actor-event-hold.c b/src/tests/clutter/conform/actor-event-hold.c index 834395c97..2a6826c7f 100644 --- a/src/tests/clutter/conform/actor-event-hold.c +++ b/src/tests/clutter/conform/actor-event-hold.c @@ -106,14 +106,13 @@ actor_event_hold (void) const HoldTestCase *test_case = test_cases + n_test_case; /* Create a synthetic hold event */ - event = clutter_event_new (CLUTTER_TOUCHPAD_HOLD); - event->touchpad_hold.phase = test_case->phase; - event->touchpad_hold.time = EVENT_TIME; - event->touchpad_hold.n_fingers = test_case->n_fingers; - event->touchpad_hold.stage = (ClutterStage *) stage; - clutter_event_set_coords (event, test_case->x, test_case->y); - clutter_event_set_device (event, device); - + event = clutter_event_touchpad_hold_new (CLUTTER_EVENT_NONE, + EVENT_TIME, + device, + test_case->phase, + test_case->n_fingers, + GRAPHENE_POINT_INIT (test_case->x, + test_case->y)); clutter_event_put (event); clutter_event_free (event); diff --git a/src/tests/clutter/conform/binding-pool.c b/src/tests/clutter/conform/binding-pool.c index 8644643f5..b19a58f75 100644 --- a/src/tests/clutter/conform/binding-pool.c +++ b/src/tests/clutter/conform/binding-pool.c @@ -224,27 +224,23 @@ key_group_init (KeyGroup *self) self->selected_index = -1; } -static void -init_event (ClutterKeyEvent *event) -{ - event->type = CLUTTER_KEY_PRESS; - event->time = 0; /* not needed */ - event->flags = CLUTTER_EVENT_FLAG_SYNTHETIC; - event->stage = NULL; /* not needed */ - event->modifier_state = 0; - event->hardware_keycode = 0; /* not needed */ -} - static void send_keyval (KeyGroup *group, int keyval) { - ClutterKeyEvent event; + ClutterSeat *seat; + ClutterEvent *event; - init_event (&event); - event.keyval = keyval; - event.unicode_value = 0; /* should be ignored for cursor keys etc. */ + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + event = clutter_event_key_new (CLUTTER_KEY_PRESS, + CLUTTER_EVENT_FLAG_SYNTHETIC, + CLUTTER_CURRENT_TIME, + clutter_seat_get_keyboard (seat), + 0, + keyval, + 0, 0, 0); - clutter_actor_event (CLUTTER_ACTOR (group), (ClutterEvent *) &event, FALSE); + clutter_actor_event (CLUTTER_ACTOR (group), event, FALSE); + clutter_event_free (event); } static void diff --git a/src/tests/clutter/conform/text.c b/src/tests/clutter/conform/text.c index 304fa1dd4..79492d8f9 100644 --- a/src/tests/clutter/conform/text.c +++ b/src/tests/clutter/conform/text.c @@ -327,25 +327,19 @@ text_password_char (void) clutter_actor_destroy (CLUTTER_ACTOR (text)); } -static ClutterEvent * -init_event (void) -{ - ClutterEvent *retval = clutter_event_new (CLUTTER_KEY_PRESS); - - clutter_event_set_time (retval, CLUTTER_CURRENT_TIME); - clutter_event_set_flags (retval, CLUTTER_EVENT_FLAG_SYNTHETIC); - - return retval; -} - static void send_keyval (ClutterText *text, int keyval) { - ClutterEvent *event = init_event (); + ClutterEvent *event; + ClutterSeat *seat; /* Unicode should be ignored for cursor keys etc. */ - clutter_event_set_key_unicode (event, 0); - clutter_event_set_key_symbol (event, keyval); + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + event = clutter_event_key_new (CLUTTER_KEY_PRESS, + CLUTTER_EVENT_FLAG_SYNTHETIC, + CLUTTER_CURRENT_TIME, + clutter_seat_get_keyboard (seat), + 0, keyval, 0, 0, 0); clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE); @@ -355,11 +349,16 @@ send_keyval (ClutterText *text, int keyval) static void send_unichar (ClutterText *text, gunichar unichar) { - ClutterEvent *event = init_event (); + ClutterEvent *event; + ClutterSeat *seat; /* Key symbol should be ignored for printable characters */ - clutter_event_set_key_symbol (event, 0); - clutter_event_set_key_unicode (event, unichar); + seat = clutter_backend_get_default_seat (clutter_get_default_backend ()); + event = clutter_event_key_new (CLUTTER_KEY_PRESS, + CLUTTER_EVENT_FLAG_SYNTHETIC, + CLUTTER_CURRENT_TIME, + clutter_seat_get_keyboard (seat), + 0, 0, 0, 0, unichar); clutter_actor_event (CLUTTER_ACTOR (text), event, FALSE); diff --git a/src/tests/clutter/performance/test-common.h b/src/tests/clutter/performance/test-common.h index 967422a54..ef3544210 100644 --- a/src/tests/clutter/performance/test-common.h +++ b/src/tests/clutter/performance/test-common.h @@ -78,7 +78,6 @@ static void wrap (gfloat *value, gfloat min, gfloat max) static gboolean perf_fake_mouse_cb (gpointer stage) { - ClutterEvent *event = clutter_event_new (CLUTTER_MOTION); static ClutterInputDevice *device = NULL; int i; static float x = 0.0; @@ -99,35 +98,41 @@ static gboolean perf_fake_mouse_cb (gpointer stage) hack is deprecated */ { - ClutterEvent *event2 = clutter_event_new (CLUTTER_ENTER); + ClutterEvent *event; ClutterBackend *backend = clutter_get_default_backend (); ClutterSeat *seat = clutter_backend_get_default_seat (backend); device = clutter_seat_get_pointer (seat); - event2->crossing.stage = stage; - event2->crossing.x = 10; - event2->crossing.y = 10; - event2->crossing.related = NULL; - - clutter_event_set_device (event2, device); - - clutter_event_put (event2); - clutter_event_free (event2); + event = clutter_event_crossing_new (CLUTTER_ENTER, + CLUTTER_EVENT_NONE, + CLUTTER_CURRENT_TIME, + device, NULL, + GRAPHENE_POINT_INIT (10, 10), + stage, + NULL); + clutter_event_put (event); + clutter_event_free (event); inited = TRUE; } clutter_actor_get_size (stage, &w, &h); - event->motion.stage = stage; - clutter_event_set_device (event, device); /* called about every 60fps, and do 10 picks per stage */ for (i = 0; i < 10; i++) { - event->motion.x = x; - event->motion.y = y; + ClutterEvent *event; + event = clutter_event_motion_new (CLUTTER_EVENT_NONE, + CLUTTER_CURRENT_TIME, + device, NULL, 0, + GRAPHENE_POINT_INIT (x, y), + GRAPHENE_POINT_INIT (0, 0), + GRAPHENE_POINT_INIT (0, 0), + GRAPHENE_POINT_INIT (0, 0), + NULL); clutter_event_put (event); + clutter_event_free (event); x += xd; y += yd; @@ -140,6 +145,5 @@ static gboolean perf_fake_mouse_cb (gpointer stage) xd = CLAMP(xd, -1.3, 1.3); yd = CLAMP(yd, -1.3, 1.3); } - clutter_event_free (event); return G_SOURCE_CONTINUE; } diff --git a/src/tests/meta-backend-test.c b/src/tests/meta-backend-test.c index e2b59e3bf..0280347b6 100644 --- a/src/tests/meta-backend-test.c +++ b/src/tests/meta-backend-test.c @@ -167,9 +167,10 @@ meta_backend_test_add_test_device (MetaBackendTest *backend_test, "n-buttons", n_buttons, NULL); - event = clutter_event_new (CLUTTER_DEVICE_ADDED); - clutter_event_set_device (event, device); - clutter_event_set_stage (event, stage); + event = clutter_event_device_notify_new (CLUTTER_DEVICE_ADDED, + CLUTTER_EVENT_NONE, + CLUTTER_CURRENT_TIME, + device); clutter_event_put (event); clutter_event_free (event); @@ -193,9 +194,10 @@ meta_backend_test_remove_device (MetaBackendTest *backend_test, g_signal_connect (stage, "after-update", G_CALLBACK (on_after_update), &was_updated); - event = clutter_event_new (CLUTTER_DEVICE_REMOVED); - clutter_event_set_device (event, device); - clutter_event_set_stage (event, stage); + event = clutter_event_device_notify_new (CLUTTER_DEVICE_REMOVED, + CLUTTER_EVENT_NONE, + CLUTTER_CURRENT_TIME, + device); clutter_event_put (event); clutter_event_free (event);