From a49dc78396bda45da43ac111ffdceeca2892800d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20=C3=85dahl?= Date: Fri, 7 May 2021 15:01:44 +0200 Subject: [PATCH] remote-desktop-session: Don't recreate virtual device over and over In 'remote-desktop-session: Create virtual input devices on demand' the intention was to create input devices on-demand, but during a refactorization of the code, instead the virtual input device was recreated over and over. Lets fix that. Fixes: a0af52caf00ed Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/1799 Part-of: --- src/backends/meta-remote-desktop-session.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/backends/meta-remote-desktop-session.c b/src/backends/meta-remote-desktop-session.c index c24f91f63..e15bd63de 100644 --- a/src/backends/meta-remote-desktop-session.c +++ b/src/backends/meta-remote-desktop-session.c @@ -153,24 +153,29 @@ ensure_virtual_device (MetaRemoteDesktopSession *session, MetaBackend *backend = meta_remote_desktop_get_backend (remote_desktop); ClutterBackend *clutter_backend = meta_backend_get_clutter_backend (backend); ClutterSeat *seat = clutter_backend_get_default_seat (clutter_backend); + ClutterVirtualInputDevice **virtual_device_ptr = NULL; switch (device_type) { case CLUTTER_POINTER_DEVICE: - session->virtual_pointer = - clutter_seat_create_virtual_device (seat, CLUTTER_POINTER_DEVICE); + virtual_device_ptr = &session->virtual_pointer; break; case CLUTTER_KEYBOARD_DEVICE: - session->virtual_keyboard = - clutter_seat_create_virtual_device (seat, CLUTTER_KEYBOARD_DEVICE); + virtual_device_ptr = &session->virtual_keyboard; break; case CLUTTER_TOUCHSCREEN_DEVICE: - session->virtual_touchscreen = - clutter_seat_create_virtual_device (seat, CLUTTER_TOUCHSCREEN_DEVICE); + virtual_device_ptr = &session->virtual_touchscreen; break; default: g_assert_not_reached (); } + + g_assert (virtual_device_ptr); + + if (*virtual_device_ptr) + return; + + *virtual_device_ptr = clutter_seat_create_virtual_device (seat, device_type); } static gboolean