tests: Use ClutterEvent getter methods

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3153>
This commit is contained in:
Carlos Garnacho 2023-08-04 12:36:12 +02:00
parent 60aa098e94
commit ba4795a5f9
10 changed files with 59 additions and 39 deletions

View File

@ -120,8 +120,8 @@ key_group_key_press (ClutterActor *actor,
g_assert (pool != NULL); g_assert (pool != NULL);
res = clutter_binding_pool_activate (pool, res = clutter_binding_pool_activate (pool,
event->keyval, clutter_event_get_key_symbol ((ClutterEvent *) event),
event->modifier_state, clutter_event_get_state ((ClutterEvent *) event),
G_OBJECT (actor)); G_OBJECT (actor));
/* if we activate a key binding, redraw the actor */ /* if we activate a key binding, redraw the actor */

View File

@ -53,13 +53,16 @@ event_cb (ClutterActor *actor,
GArray *events = user_data; GArray *events = user_data;
EventLog entry; EventLog entry;
switch (event->type) switch (clutter_event_type (event))
{ {
case CLUTTER_ENTER: case CLUTTER_ENTER:
case CLUTTER_LEAVE: case CLUTTER_LEAVE:
if ((event->any.flags & CLUTTER_EVENT_FLAG_GRAB_NOTIFY) != 0) if ((clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_GRAB_NOTIFY) != 0)
{ {
entry = (EventLog) { clutter_actor_get_name (actor), event->type }; entry = (EventLog) {
clutter_actor_get_name (actor),
clutter_event_type (event)
};
g_debug ("Event '%s' on actor '%s'", g_debug ("Event '%s' on actor '%s'",
clutter_event_get_name (event), clutter_event_get_name (event),
@ -69,7 +72,10 @@ event_cb (ClutterActor *actor,
break; break;
default: default:
entry = (EventLog) { clutter_actor_get_name (actor), event->type }; entry = (EventLog) {
clutter_actor_get_name (actor),
clutter_event_type (event)
};
g_debug ("Event '%s' on actor '%s'", g_debug ("Event '%s' on actor '%s'",
clutter_event_get_name (event), clutter_event_get_name (event),
entry.name); entry.name);
@ -560,7 +566,7 @@ handle_input_only_event (const ClutterEvent *event,
gpointer user_data) gpointer user_data)
{ {
GArray *events = user_data; GArray *events = user_data;
EventLog entry = { "input-only grab", event->type }; EventLog entry = { "input-only grab", clutter_event_type (event) };
g_debug ("Input only grab event '%s'", clutter_event_get_name (event)); g_debug ("Input only grab event '%s'", clutter_event_get_name (event));
g_array_append_val (events, entry); g_array_append_val (events, entry);

View File

@ -75,7 +75,7 @@ input_cb (ClutterActor *stage,
{ {
SuperOH *oh = data; SuperOH *oh = data;
if (event->type == CLUTTER_KEY_RELEASE) if (clutter_event_type (event) == CLUTTER_KEY_RELEASE)
{ {
g_print ("*** key press event (key:%c) ***\n", g_print ("*** key press event (key:%c) ***\n",
clutter_event_get_key_symbol (event)); clutter_event_get_key_symbol (event));

View File

@ -140,8 +140,8 @@ key_group_key_press (ClutterActor *actor,
g_assert (pool != NULL); g_assert (pool != NULL);
res = clutter_binding_pool_activate (pool, res = clutter_binding_pool_activate (pool,
event->keyval, clutter_event_get_key_symbol ((ClutterEvent *) event),
event->modifier_state, clutter_event_get_state ((ClutterEvent *) event),
G_OBJECT (actor)); G_OBJECT (actor));
/* if we activate a key binding, redraw the actor */ /* if we activate a key binding, redraw the actor */

View File

@ -240,7 +240,7 @@ button_release_cb (ClutterActor *actor,
* which shader to display */ * which shader to display */
g_clear_handle_id (&timeout_id, g_source_remove); g_clear_handle_id (&timeout_id, g_source_remove);
if (event->button.button == 1) if (clutter_event_get_button (event) == 1)
{ {
new_no = shader_no - 1; new_no = shader_no - 1;
if (new_no < 0) if (new_no < 0)

View File

@ -89,7 +89,7 @@ on_button_press (ClutterActor *actor,
ClutterButtonEvent *event, ClutterButtonEvent *event,
ClutterActor *rectangle) ClutterActor *rectangle)
{ {
if (event->button == CLUTTER_BUTTON_SECONDARY) if (clutter_event_get_button ((ClutterEvent *) event) == CLUTTER_BUTTON_SECONDARY)
{ {
gchar *text; gchar *text;
@ -107,16 +107,18 @@ on_button_press (ClutterActor *actor,
clutter_text_set_text (CLUTTER_TEXT (easing_mode_label), text); clutter_text_set_text (CLUTTER_TEXT (easing_mode_label), text);
g_free (text); g_free (text);
} }
else if (event->button == CLUTTER_BUTTON_PRIMARY) else if (clutter_event_get_button ((ClutterEvent *) event) == CLUTTER_BUTTON_PRIMARY)
{ {
ClutterAnimationMode cur_mode; ClutterAnimationMode cur_mode;
float x, y;
cur_mode = easing_modes[current_mode].mode; cur_mode = easing_modes[current_mode].mode;
clutter_actor_save_easing_state (rectangle); clutter_actor_save_easing_state (rectangle);
clutter_actor_set_easing_duration (rectangle, DURATION * 1000); clutter_actor_set_easing_duration (rectangle, DURATION * 1000);
clutter_actor_set_easing_mode (rectangle, cur_mode); clutter_actor_set_easing_mode (rectangle, cur_mode);
clutter_actor_set_position (rectangle, event->x, event->y); clutter_event_get_coords ((ClutterEvent *) event, &x, &y);
clutter_actor_set_position (rectangle, x, y);
/* if we were asked to, recenter the bouncer at the end of the /* if we were asked to, recenter the bouncer at the end of the
* animation. we keep track of the animation to avoid connecting * animation. we keep track of the animation to avoid connecting

View File

@ -15,7 +15,7 @@ test_events_describe (void);
static const gchar * static const gchar *
get_event_type_name (const ClutterEvent *event) get_event_type_name (const ClutterEvent *event)
{ {
switch (event->type) switch (clutter_event_type (event))
{ {
case CLUTTER_BUTTON_PRESS: case CLUTTER_BUTTON_PRESS:
return "BUTTON PRESS"; return "BUTTON PRESS";
@ -140,40 +140,45 @@ key_focus_in_cb (ClutterActor *actor,
static void static void
fill_keybuf (char *keybuf, ClutterKeyEvent *event) fill_keybuf (char *keybuf, ClutterKeyEvent *event)
{ {
ClutterModifierType state;
char utf8[6]; char utf8[6];
uint32_t keyval;
int len; int len;
/* printable character, if any (ß, ∑) */ /* printable character, if any (ß, ∑) */
len = g_unichar_to_utf8 (event->unicode_value, utf8); len = g_unichar_to_utf8 (clutter_event_get_key_unicode ((ClutterEvent *) event), utf8);
utf8[len] = '\0'; utf8[len] = '\0';
sprintf (keybuf, "'%s' ", utf8); sprintf (keybuf, "'%s' ", utf8);
/* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */ /* key combination (<Mod1>s, <Shift><Mod1>S, <Ctrl><Mod1>Delete) */
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->keyval), utf8); keyval = clutter_event_get_key_symbol ((ClutterEvent *) event);
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (keyval), utf8);
utf8[len] = '\0'; utf8[len] = '\0';
if (event->modifier_state & CLUTTER_SHIFT_MASK) state = clutter_event_get_state ((ClutterEvent *) event);
if (state & CLUTTER_SHIFT_MASK)
strcat (keybuf, "<Shift>"); strcat (keybuf, "<Shift>");
if (event->modifier_state & CLUTTER_LOCK_MASK) if (state & CLUTTER_LOCK_MASK)
strcat (keybuf, "<Lock>"); strcat (keybuf, "<Lock>");
if (event->modifier_state & CLUTTER_CONTROL_MASK) if (state & CLUTTER_CONTROL_MASK)
strcat (keybuf, "<Control>"); strcat (keybuf, "<Control>");
if (event->modifier_state & CLUTTER_MOD1_MASK) if (state & CLUTTER_MOD1_MASK)
strcat (keybuf, "<Mod1>"); strcat (keybuf, "<Mod1>");
if (event->modifier_state & CLUTTER_MOD2_MASK) if (state & CLUTTER_MOD2_MASK)
strcat (keybuf, "<Mod2>"); strcat (keybuf, "<Mod2>");
if (event->modifier_state & CLUTTER_MOD3_MASK) if (state & CLUTTER_MOD3_MASK)
strcat (keybuf, "<Mod3>"); strcat (keybuf, "<Mod3>");
if (event->modifier_state & CLUTTER_MOD4_MASK) if (state & CLUTTER_MOD4_MASK)
strcat (keybuf, "<Mod4>"); strcat (keybuf, "<Mod4>");
if (event->modifier_state & CLUTTER_MOD5_MASK) if (state & CLUTTER_MOD5_MASK)
strcat (keybuf, "<Mod5>"); strcat (keybuf, "<Mod5>");
strcat (keybuf, utf8); strcat (keybuf, utf8);
@ -191,12 +196,14 @@ input_cb (ClutterActor *actor,
gchar keybuf[128]; gchar keybuf[128];
ClutterInputDevice *device, *source; ClutterInputDevice *device, *source;
const gchar *device_name, *source_name = NULL; const gchar *device_name, *source_name = NULL;
ClutterEventType event_type;
device = clutter_event_get_device (event); device = clutter_event_get_device (event);
device_name = clutter_input_device_get_device_name (device); device_name = clutter_input_device_get_device_name (device);
event_type = clutter_event_type (event);
if (event->type == CLUTTER_KEY_PRESS || if (event_type == CLUTTER_KEY_PRESS ||
event->type == CLUTTER_KEY_RELEASE) event_type == CLUTTER_KEY_RELEASE)
{ {
source_actor = clutter_stage_get_key_focus (CLUTTER_STAGE (stage)); source_actor = clutter_stage_get_key_focus (CLUTTER_STAGE (stage));
} }
@ -215,16 +222,16 @@ input_cb (ClutterActor *actor,
state = get_event_state_string (event); state = get_event_state_string (event);
switch (event->type) switch (event_type)
{ {
case CLUTTER_KEY_PRESS: case CLUTTER_KEY_PRESS:
fill_keybuf (keybuf, &event->key); fill_keybuf (keybuf, (ClutterKeyEvent *) event);
printf ("[%s] KEY PRESS %s", printf ("[%s] KEY PRESS %s",
clutter_actor_get_name (source_actor), clutter_actor_get_name (source_actor),
keybuf); keybuf);
break; break;
case CLUTTER_KEY_RELEASE: case CLUTTER_KEY_RELEASE:
fill_keybuf (keybuf, &event->key); fill_keybuf (keybuf, (ClutterKeyEvent *) event);
printf ("[%s] KEY RELEASE %s", printf ("[%s] KEY RELEASE %s",
clutter_actor_get_name (source_actor), clutter_actor_get_name (source_actor),
keybuf); keybuf);

View File

@ -16,18 +16,21 @@ debug_event_cb (ClutterActor *actor,
{ {
gchar keybuf[9], *source = (gchar*)data; gchar keybuf[9], *source = (gchar*)data;
ClutterActor *target; ClutterActor *target;
int len = 0; uint32_t keyval;
int len = 0;
switch (event->type) switch (clutter_event_type (event))
{ {
case CLUTTER_KEY_PRESS: case CLUTTER_KEY_PRESS:
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval), keyval = clutter_event_get_key_symbol (event);
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (keyval),
keybuf); keybuf);
keybuf[len] = '\0'; keybuf[len] = '\0';
printf ("[%s] KEY PRESS '%s'", source, keybuf); printf ("[%s] KEY PRESS '%s'", source, keybuf);
break; break;
case CLUTTER_KEY_RELEASE: case CLUTTER_KEY_RELEASE:
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (event->key.keyval), keyval = clutter_event_get_key_symbol (event);
len = g_unichar_to_utf8 (clutter_keysym_to_unicode (keyval),
keybuf); keybuf);
keybuf[len] = '\0'; keybuf[len] = '\0';
printf ("[%s] KEY RELEASE '%s'", source, keybuf); printf ("[%s] KEY RELEASE '%s'", source, keybuf);

View File

@ -35,7 +35,7 @@ on_captured_event (ClutterText *text,
gunichar c; gunichar c;
guint keyval; guint keyval;
if (event->type != CLUTTER_KEY_PRESS) if (clutter_event_type (event) != CLUTTER_KEY_PRESS)
return FALSE; return FALSE;
is_unicode_mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text), is_unicode_mode = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (text),

View File

@ -59,6 +59,7 @@ draw_touch (ClutterEvent *event,
{ {
ClutterEventSequence *sequence = clutter_event_get_event_sequence (event); ClutterEventSequence *sequence = clutter_event_get_event_sequence (event);
const ClutterColor *color; const ClutterColor *color;
float x, y;
color = g_hash_table_lookup (sequence_to_color, sequence); color = g_hash_table_lookup (sequence_to_color, sequence);
if (color == NULL) if (color == NULL)
@ -71,7 +72,8 @@ draw_touch (ClutterEvent *event,
color->green / 255, color->green / 255,
color->blue / 255, color->blue / 255,
color->alpha / 255); color->alpha / 255);
cairo_arc (cr, event->touch.x, event->touch.y, 5, 0, 2 * G_PI); clutter_event_get_coords (event, &x, &y);
cairo_arc (cr, x, y, 5, 0, 2 * G_PI);
cairo_fill (cr); cairo_fill (cr);
} }
@ -94,7 +96,7 @@ event_cb (ClutterActor *actor, ClutterEvent *event, ClutterActor *canvas)
{ {
ClutterEvent *copy; ClutterEvent *copy;
if (event->type != CLUTTER_TOUCH_UPDATE) if (clutter_event_type (event) != CLUTTER_TOUCH_UPDATE)
return FALSE; return FALSE;
copy = clutter_event_copy (event); copy = clutter_event_copy (event);
@ -110,7 +112,7 @@ rect_event_cb (ClutterActor *actor, ClutterEvent *event, gpointer data)
{ {
ClutterColor color; ClutterColor color;
if (event->type != CLUTTER_TOUCH_BEGIN) if (clutter_event_type (event) != CLUTTER_TOUCH_BEGIN)
return FALSE; return FALSE;
color = static_colors[g_random_int_range (0, NUM_COLORS)]; color = static_colors[g_random_int_range (0, NUM_COLORS)];