From dbbfd034363bec1e9c7745e146f5d1e4e0675407 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 4 Aug 2023 12:35:26 +0200 Subject: [PATCH] backends/native: Use ClutterEvent getter methods Part-of: --- .../native/meta-input-device-native.c | 70 +++++++++++-------- src/backends/native/meta-seat-native.c | 2 +- 2 files changed, 43 insertions(+), 29 deletions(-) diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c index 58038bb7c..f7199dc89 100644 --- a/src/backends/native/meta-input-device-native.c +++ b/src/backends/native/meta-input-device-native.c @@ -292,10 +292,10 @@ find_pending_event_by_keycode (gconstpointer a, gconstpointer b) { const SlowKeysEventPending *pa = a; - const ClutterKeyEvent *ka = (ClutterKeyEvent *) pa->event; - const ClutterKeyEvent *kb = b; + const ClutterEvent *ea = pa->event; + const ClutterEvent *eb = b; - return kb->hardware_keycode - ka->hardware_keycode; + return clutter_event_get_key_code (eb) - clutter_event_get_key_code (ea); } static GSource * @@ -321,9 +321,8 @@ start_slow_keys (ClutterEvent *event, MetaInputDeviceNative *device) { SlowKeysEventPending *slow_keys_event; - ClutterKeyEvent *key_event = (ClutterKeyEvent *) event; - if (key_event->flags & CLUTTER_EVENT_FLAG_REPEATED) + if (clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_REPEATED) return TRUE; slow_keys_event = g_new0 (SlowKeysEventPending, 1); @@ -397,7 +396,7 @@ start_bounce_keys (ClutterEvent *event, { stop_bounce_keys (device); - device->debounce_key = ((ClutterKeyEvent *) event)->hardware_keycode; + device->debounce_key = clutter_event_get_key_code (event); device->debounce_timer = timeout_source_new (device->seat_impl, get_debounce_delay (CLUTTER_INPUT_DEVICE (device)), @@ -422,13 +421,13 @@ static gboolean debounce_key (ClutterEvent *event, MetaInputDeviceNative *device) { - return (device->debounce_key == ((ClutterKeyEvent *) event)->hardware_keycode); + return (device->debounce_key == clutter_event_get_key_code (event)); } static gboolean key_event_is_modifier (ClutterEvent *event) { - switch (event->key.keyval) + switch (clutter_event_get_key_symbol (event)) { case XKB_KEY_Shift_L: case XKB_KEY_Shift_R: @@ -694,16 +693,21 @@ static void handle_enablekeys_press (ClutterEvent *event, MetaInputDeviceNative *device) { - if (event->key.keyval == XKB_KEY_Shift_L || event->key.keyval == XKB_KEY_Shift_R) + uint32_t keyval, time_ms; + + keyval = clutter_event_get_key_symbol (event); + time_ms = clutter_event_get_time (event); + + if (keyval == XKB_KEY_Shift_L || keyval == XKB_KEY_Shift_R) { start_toggle_slowkeys (device); - if (event->key.time > device->last_shift_time + 15 * 1000 /* 15 secs */) + if (time_ms > device->last_shift_time + 15 * 1000 /* 15 secs */) device->shift_count = 1; else device->shift_count++; - device->last_shift_time = event->key.time; + device->last_shift_time = time_ms; } else { @@ -716,7 +720,11 @@ static void handle_enablekeys_release (ClutterEvent *event, MetaInputDeviceNative *device) { - if (event->key.keyval == XKB_KEY_Shift_L || event->key.keyval == XKB_KEY_Shift_R) + uint32_t keyval; + + keyval = clutter_event_get_key_symbol (event); + + if (keyval == XKB_KEY_Shift_L || keyval == XKB_KEY_Shift_R) { stop_toggle_slowkeys (device); if (device->shift_count >= 5) @@ -1027,7 +1035,8 @@ static void start_mousekeys_move (ClutterEvent *event, MetaInputDeviceNative *device) { - device->last_mousekeys_key = event->key.keyval; + device->last_mousekeys_key = + clutter_event_get_key_symbol (event); if (device->move_mousekeys_timer != 0) return; @@ -1039,7 +1048,7 @@ static gboolean handle_mousekeys_press (ClutterEvent *event, MetaInputDeviceNative *device) { - if (!(event->key.flags & CLUTTER_EVENT_FLAG_SYNTHETIC)) + if (!(clutter_event_get_flags (event) & CLUTTER_EVENT_FLAG_SYNTHETIC)) stop_mousekeys_move (device); /* Do not handle mousekeys if NumLock is ON */ @@ -1047,7 +1056,7 @@ handle_mousekeys_press (ClutterEvent *event, return FALSE; /* Button selection */ - switch (event->key.keyval) + switch (clutter_event_get_key_symbol (event)) { case XKB_KEY_KP_Divide: device->mousekeys_btn = CLUTTER_BUTTON_PRIMARY; @@ -1063,7 +1072,7 @@ handle_mousekeys_press (ClutterEvent *event, } /* Button events */ - switch (event->key.keyval) + switch (clutter_event_get_key_symbol (event)) { case XKB_KEY_KP_Begin: case XKB_KEY_KP_5: @@ -1086,7 +1095,7 @@ handle_mousekeys_press (ClutterEvent *event, } /* Pointer motion */ - switch (event->key.keyval) + switch (clutter_event_get_key_symbol (event)) { case XKB_KEY_KP_1: case XKB_KEY_KP_2: @@ -1121,7 +1130,7 @@ handle_mousekeys_release (ClutterEvent *event, if (is_numlock_active (device)) return FALSE; - switch (event->key.keyval) + switch (clutter_event_get_key_symbol (event)) { case XKB_KEY_KP_0: case XKB_KEY_KP_1: @@ -1163,10 +1172,13 @@ meta_input_device_native_process_kbd_a11y_event_in_impl (ClutterInputDevice *dev ClutterEvent *event) { MetaInputDeviceNative *device_evdev = META_INPUT_DEVICE_NATIVE (device); + ClutterEventType event_type; + + event_type = clutter_event_type (event); if (device_evdev->a11y_flags & META_A11Y_KEYBOARD_ENABLED) { - if (event->type == CLUTTER_KEY_PRESS) + if (event_type == CLUTTER_KEY_PRESS) handle_enablekeys_press (event, device_evdev); else handle_enablekeys_release (event, device_evdev); @@ -1174,10 +1186,10 @@ meta_input_device_native_process_kbd_a11y_event_in_impl (ClutterInputDevice *dev if (device_evdev->a11y_flags & META_A11Y_MOUSE_KEYS_ENABLED) { - if (event->type == CLUTTER_KEY_PRESS && + if (event_type == CLUTTER_KEY_PRESS && handle_mousekeys_press (event, device_evdev)) return TRUE; /* swallow event */ - if (event->type == CLUTTER_KEY_RELEASE && + if (event_type == CLUTTER_KEY_RELEASE && handle_mousekeys_release (event, device_evdev)) return TRUE; /* swallow event */ } @@ -1185,30 +1197,32 @@ meta_input_device_native_process_kbd_a11y_event_in_impl (ClutterInputDevice *dev if ((device_evdev->a11y_flags & META_A11Y_BOUNCE_KEYS_ENABLED) && (get_debounce_delay (device) != 0)) { - if ((event->type == CLUTTER_KEY_PRESS) && debounce_key (event, device_evdev)) + if ((event_type == CLUTTER_KEY_PRESS) && debounce_key (event, device_evdev)) { notify_bounce_keys_reject (device_evdev); return TRUE; } - else if (event->type == CLUTTER_KEY_RELEASE) - start_bounce_keys (event, device_evdev); + else if (event_type == CLUTTER_KEY_RELEASE) + { + start_bounce_keys (event, device_evdev); + } } if ((device_evdev->a11y_flags & META_A11Y_SLOW_KEYS_ENABLED) && (get_slow_keys_delay (device) != 0)) { - if (event->type == CLUTTER_KEY_PRESS) + if (event_type == CLUTTER_KEY_PRESS) return start_slow_keys (event, device_evdev); - else if (event->type == CLUTTER_KEY_RELEASE) + else if (event_type == CLUTTER_KEY_RELEASE) return stop_slow_keys (event, device_evdev); } if (device_evdev->a11y_flags & META_A11Y_STICKY_KEYS_ENABLED) { - if (event->type == CLUTTER_KEY_PRESS) + if (event_type == CLUTTER_KEY_PRESS) return handle_stickykeys_press (event, device_evdev); - else if (event->type == CLUTTER_KEY_RELEASE) + else if (event_type == CLUTTER_KEY_RELEASE) return handle_stickykeys_release (event, device_evdev); } diff --git a/src/backends/native/meta-seat-native.c b/src/backends/native/meta-seat-native.c index 75ea77fd9..1c1621808 100644 --- a/src/backends/native/meta-seat-native.c +++ b/src/backends/native/meta-seat-native.c @@ -61,7 +61,7 @@ meta_seat_native_handle_event_post (ClutterSeat *seat, { MetaSeatNative *seat_native = META_SEAT_NATIVE (seat); ClutterInputDevice *device = clutter_event_get_source_device (event); - ClutterEventType event_type = event->type; + ClutterEventType event_type = clutter_event_type (event); if (event_type == CLUTTER_PROXIMITY_OUT) {