backends/native: Release virtual buttons on dispose instead of finalize

GObject recommends to break references to other objects on dispose
instead of finalize, also we want to release the pressed virtual buttons
as early as possible if we know the object is getting destroyed.

So release the pressed buttons and unref our virtual
MetaInputDeviceNative when the dispose vfunc is called, which also
allows us to release the buttons immediately from javascript instead of
waiting for the garbage collector by calling run_dispose() on the
object.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1157
This commit is contained in:
Jonas Dreßler 2020-03-28 11:34:49 +01:00 committed by verdre
parent e8ea5ecd8a
commit 9f31e7252c

View File

@ -155,6 +155,8 @@ meta_virtual_input_device_native_notify_relative_motion (ClutterVirtualInputDevi
MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -174,6 +176,8 @@ meta_virtual_input_device_native_notify_absolute_motion (ClutterVirtualInputDevi
MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -215,6 +219,8 @@ meta_virtual_input_device_native_notify_button (ClutterVirtualInputDevice *virtu
int button_count;
int evdev_button;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -258,6 +264,8 @@ meta_virtual_input_device_native_notify_key (ClutterVirtualInputDevice *virtual_
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
int key_count;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -395,6 +403,8 @@ meta_virtual_input_device_native_notify_keyval (ClutterVirtualInputDevice *virtu
int key_count;
guint keycode = 0, level = 0, evcode = 0;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -482,6 +492,8 @@ meta_virtual_input_device_native_notify_discrete_scroll (ClutterVirtualInputDevi
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
double discrete_dx = 0.0, discrete_dy = 0.0;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -505,6 +517,8 @@ meta_virtual_input_device_native_notify_scroll_continuous (ClutterVirtualInputDe
MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (virtual_device);
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -529,6 +543,8 @@ meta_virtual_input_device_native_notify_touch_down (ClutterVirtualInputDevice *v
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -562,6 +578,8 @@ meta_virtual_input_device_native_notify_touch_motion (ClutterVirtualInputDevice
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -593,6 +611,8 @@ meta_virtual_input_device_native_notify_touch_up (ClutterVirtualInputDevice *vir
META_INPUT_DEVICE_NATIVE (virtual_evdev->device);
MetaTouchState *touch_state;
g_return_if_fail (virtual_evdev->device != NULL);
if (time_us == CLUTTER_CURRENT_TIME)
time_us = g_get_monotonic_time ();
@ -682,24 +702,26 @@ meta_virtual_input_device_native_constructed (GObject *object)
}
static void
meta_virtual_input_device_native_finalize (GObject *object)
meta_virtual_input_device_native_dispose (GObject *object)
{
ClutterVirtualInputDevice *virtual_device =
CLUTTER_VIRTUAL_INPUT_DEVICE (object);
MetaVirtualInputDeviceNative *virtual_evdev =
META_VIRTUAL_INPUT_DEVICE_NATIVE (object);
GObjectClass *object_class;
GObjectClass *object_class =
G_OBJECT_CLASS (meta_virtual_input_device_native_parent_class);
if (virtual_evdev->device)
{
release_pressed_buttons (virtual_device);
g_signal_emit_by_name (virtual_evdev->seat,
"device-removed",
virtual_evdev->device);
g_clear_object (&virtual_evdev->device);
}
object_class =
G_OBJECT_CLASS (meta_virtual_input_device_native_parent_class);
object_class->finalize (object);
object_class->dispose (object);
}
static void
@ -717,7 +739,7 @@ meta_virtual_input_device_native_class_init (MetaVirtualInputDeviceNativeClass *
object_class->get_property = meta_virtual_input_device_native_get_property;
object_class->set_property = meta_virtual_input_device_native_set_property;
object_class->constructed = meta_virtual_input_device_native_constructed;
object_class->finalize = meta_virtual_input_device_native_finalize;
object_class->dispose = meta_virtual_input_device_native_dispose;
virtual_input_device_class->notify_relative_motion = meta_virtual_input_device_native_notify_relative_motion;
virtual_input_device_class->notify_absolute_motion = meta_virtual_input_device_native_notify_absolute_motion;