backends/x11: Use backend-side error traps for input configuration

While it's obviously good to trap possible errors from X calls, we are
mixing the Clutter error trap with the MetaX11Display one for these
calls.

This may result in situations where a X call within a Clutter error
trap fails, but it's actually handled in these sections using the
MetaX11Display error trap. This one will consider the serial out
of the "handled" parts and raise an error.

It is better to stay consistent here, and use the same error traps
than the rest of the X11 backend.

Closes: https://gitlab.gnome.org/GNOME/mutter/-/issues/2796
Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3002>
This commit is contained in:
Carlos Garnacho 2023-05-15 00:56:19 +02:00 committed by Marge Bot
parent 3218626d7e
commit 18e06c2484

View File

@ -58,27 +58,17 @@ get_backend (MetaInputSettings *settings)
return meta_input_settings_get_backend (settings); return meta_input_settings_get_backend (settings);
} }
static MetaDisplay *
get_display (MetaInputSettings *settings)
{
MetaBackend *backend = get_backend (settings);
MetaContext *context = meta_backend_get_context (backend);
return meta_context_get_display (context);
}
static void static void
device_handle_free (gpointer user_data) device_handle_free (gpointer user_data)
{ {
DeviceHandle *handle = user_data; DeviceHandle *handle = user_data;
MetaInputSettings *settings = handle->settings; MetaInputSettings *settings = handle->settings;
MetaDisplay *display = get_display (settings);
MetaBackend *backend = get_backend (settings); MetaBackend *backend = get_backend (settings);
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
meta_x11_error_trap_push (display->x11_display); meta_clutter_x11_trap_x_errors ();
XCloseDevice (xdisplay, handle->xdev); XCloseDevice (xdisplay, handle->xdev);
meta_x11_error_trap_pop (display->x11_display); meta_clutter_x11_untrap_x_errors ();
g_free (handle); g_free (handle);
} }
@ -87,7 +77,6 @@ static XDevice *
device_ensure_xdevice (MetaInputSettings *settings, device_ensure_xdevice (MetaInputSettings *settings,
ClutterInputDevice *device) ClutterInputDevice *device)
{ {
MetaDisplay *display = get_display (settings);
MetaBackend *backend = get_backend (settings); MetaBackend *backend = get_backend (settings);
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
int device_id = meta_input_device_x11_get_device_id (device); int device_id = meta_input_device_x11_get_device_id (device);
@ -98,9 +87,9 @@ device_ensure_xdevice (MetaInputSettings *settings,
if (handle) if (handle)
return handle->xdev; return handle->xdev;
meta_x11_error_trap_push (display->x11_display); meta_clutter_x11_trap_x_errors ();
xdev = XOpenDevice (xdisplay, device_id); xdev = XOpenDevice (xdisplay, device_id);
meta_x11_error_trap_pop (display->x11_display); meta_clutter_x11_untrap_x_errors ();
if (xdev) if (xdev)
{ {
@ -617,16 +606,12 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings *settings,
ClutterInputDevice *device, ClutterInputDevice *device,
GDesktopTabletMapping mapping) GDesktopTabletMapping mapping)
{ {
MetaDisplay *display = get_display (settings);
MetaBackend *backend = get_backend (settings); MetaBackend *backend = get_backend (settings);
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
XDevice *xdev; XDevice *xdev;
if (!display)
return;
/* Grab the puke bucket! */ /* Grab the puke bucket! */
meta_x11_error_trap_push (display->x11_display); meta_clutter_x11_trap_x_errors ();
xdev = device_ensure_xdevice (settings, device); xdev = device_ensure_xdevice (settings, device);
if (xdev) if (xdev)
{ {
@ -635,11 +620,7 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings *settings,
Absolute : Relative); Absolute : Relative);
} }
if (meta_x11_error_trap_pop_with_return (display->x11_display)) meta_clutter_x11_untrap_x_errors ();
{
g_warning ("Could not set tablet mapping for %s",
clutter_input_device_get_device_name (device));
}
} }
static gboolean static gboolean
@ -774,16 +755,12 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *setti
GDesktopStylusButtonAction secondary, GDesktopStylusButtonAction secondary,
GDesktopStylusButtonAction tertiary) GDesktopStylusButtonAction tertiary)
{ {
MetaDisplay *display = get_display (settings);
MetaBackend *backend = get_backend (settings); MetaBackend *backend = get_backend (settings);
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend)); Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
XDevice *xdev; XDevice *xdev;
if (!display)
return;
/* Grab the puke bucket! */ /* Grab the puke bucket! */
meta_x11_error_trap_push (display->x11_display); meta_clutter_x11_trap_x_errors ();
xdev = device_ensure_xdevice (settings, device); xdev = device_ensure_xdevice (settings, device);
if (xdev) if (xdev)
{ {
@ -801,11 +778,7 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *setti
XSetDeviceButtonMapping (xdisplay, xdev, map, G_N_ELEMENTS (map)); XSetDeviceButtonMapping (xdisplay, xdev, map, G_N_ELEMENTS (map));
} }
if (meta_x11_error_trap_pop_with_return (display->x11_display)) meta_clutter_x11_untrap_x_errors ();
{
g_warning ("Could not set stylus button map for %s",
clutter_input_device_get_device_name (device));
}
} }
static void static void