1
0
Fork 0

backends: Drop X11 ClutterBackend error traps

Replace these with Mtk error traps altogether, and avoid stacking
one API over the other here.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3230>
This commit is contained in:
Carlos Garnacho 2023-08-31 14:54:07 +02:00 committed by Marge Bot
parent 99bcd20f0a
commit 7224bb8a8d
8 changed files with 54 additions and 79 deletions

View file

@ -68,10 +68,6 @@ static const gchar *atom_names[] = {
/* various flags corresponding to pre init setup calls */
static gboolean clutter_enable_stereo = FALSE;
/* X error trap */
static int TrappedErrorCode = 0;
static int (* old_error_handler) (Display *, XErrorEvent *);
static gboolean
meta_clutter_backend_x11_finish_init (ClutterBackend *clutter_backend,
GError **error)
@ -259,29 +255,6 @@ meta_clutter_backend_x11_new (MetaBackend *backend)
return clutter_backend_x11;
}
static int
error_handler (Display *xdisplay,
XErrorEvent *error)
{
TrappedErrorCode = error->error_code;
return 0;
}
void
meta_clutter_x11_trap_x_errors (void)
{
TrappedErrorCode = 0;
old_error_handler = XSetErrorHandler (error_handler);
}
gint
meta_clutter_x11_untrap_x_errors (void)
{
XSetErrorHandler (old_error_handler);
return TrappedErrorCode;
}
void
meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo)
{

View file

@ -58,8 +58,5 @@ G_DECLARE_FINAL_TYPE (MetaClutterBackendX11, meta_clutter_backend_x11,
MetaClutterBackendX11 * meta_clutter_backend_x11_new (MetaBackend *backend);
void meta_clutter_x11_trap_x_errors (void);
gint meta_clutter_x11_untrap_x_errors (void);
void meta_clutter_x11_set_use_stereo_stage (gboolean use_stereo);
gboolean meta_clutter_x11_get_use_stereo_stage (void);

View file

@ -26,6 +26,7 @@
#include "backends/x11/meta-clutter-backend-x11.h"
#include "backends/x11/meta-input-device-x11.h"
#include "backends/x11/meta-seat-x11.h"
#include "mtk/mtk-x11.h"
struct _MetaInputDeviceX11
{
@ -291,12 +292,12 @@ meta_input_device_x11_get_dimensions (ClutterInputDevice *device,
static gboolean atoms_initialized = FALSE;
static Atom abs_axis_atoms[4] = { 0, };
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
info = XIQueryDevice (xdisplay, device_x11->device_id, &n_info);
*width = *height = w = h = 0;
if (meta_clutter_x11_untrap_x_errors ())
if (mtk_x11_error_trap_pop_with_return (xdisplay))
return FALSE;
if (!info)
@ -402,6 +403,7 @@ meta_input_device_x11_query_pointer_location (MetaInputDeviceX11 *device_xi2)
MetaSeatX11 *seat_x11 = META_SEAT_X11 (seat);
MetaBackendX11 *backend_x11 =
META_BACKEND_X11 (meta_seat_x11_get_backend (seat_x11));
Display *xdisplay = meta_backend_x11_get_xdisplay (backend_x11);
Window xroot_window, xchild_window;
double xroot_x, xroot_y, xwin_x, xwin_y;
XIButtonState button_state = { 0 };
@ -409,7 +411,7 @@ meta_input_device_x11_query_pointer_location (MetaInputDeviceX11 *device_xi2)
XIGroupState group_state;
int result;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
result = XIQueryPointer (meta_backend_x11_get_xdisplay (backend_x11),
device_xi2->device_id,
meta_backend_x11_get_root_xwindow (backend_x11),
@ -420,7 +422,7 @@ meta_input_device_x11_query_pointer_location (MetaInputDeviceX11 *device_xi2)
&button_state,
&mod_state,
&group_state);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_free (button_state.mask);

View file

@ -31,7 +31,7 @@
#include "backends/x11/meta-backend-x11.h"
#include "backends/x11/meta-input-device-x11.h"
#include "core/display-private.h"
#include "meta/meta-x11-errors.h"
#include "mtk/mtk-x11.h"
typedef struct
{
@ -64,9 +64,9 @@ device_handle_free (gpointer user_data)
MetaBackend *backend = get_backend (settings);
Display *xdisplay = meta_backend_x11_get_xdisplay (META_BACKEND_X11 (backend));
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XCloseDevice (xdisplay, handle->xdev);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_free (handle);
}
@ -85,9 +85,9 @@ device_ensure_xdevice (MetaInputSettings *settings,
if (handle)
return handle->xdev;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
xdev = XOpenDevice (xdisplay, device_id);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (xdev)
{
@ -123,11 +123,11 @@ get_property (ClutterInputDevice *device,
device_id = meta_input_device_x11_get_device_id (device);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay, device_id, property_atom,
0, 10, False, type, &type_ret, &format_ret,
&nitems_ret, &bytes_after_ret, &data_ret);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (rc == Success && type_ret == type && format_ret == format && nitems_ret >= nitems)
return data_ret;
@ -162,11 +162,12 @@ change_property (MetaInputSettings *settings,
if (!data_ret)
return;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XIChangeProperty (xdisplay, device_id, property_atom, type,
format, XIPropModeReplace, data, nitems);
XSync (xdisplay, False);
err = meta_clutter_x11_untrap_x_errors ();
err = mtk_x11_error_trap_pop_with_return (xdisplay);
if (err)
{
g_warning ("XIChangeProperty failed on device %d property \"%s\" with X error %d",
@ -604,7 +605,7 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings *settings,
XDevice *xdev;
/* Grab the puke bucket! */
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
xdev = device_ensure_xdevice (settings, device);
if (xdev)
{
@ -613,7 +614,7 @@ meta_input_settings_x11_set_tablet_mapping (MetaInputSettings *settings,
Absolute : Relative);
}
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
}
static gboolean
@ -753,7 +754,7 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *setti
XDevice *xdev;
/* Grab the puke bucket! */
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
xdev = device_ensure_xdevice (settings, device);
if (xdev)
{
@ -771,7 +772,7 @@ meta_input_settings_x11_set_stylus_button_map (MetaInputSettings *setti
XSetDeviceButtonMapping (xdisplay, xdev, map, G_N_ELEMENTS (map));
}
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
}
static void

View file

@ -44,6 +44,7 @@
#include "backends/meta-crtc.h"
#include "backends/x11/meta-monitor-manager-xrandr.h"
#include "meta/util.h"
#include "mtk/mtk-x11.h"
struct _MetaOutputXrandr
{
@ -453,11 +454,11 @@ output_get_max_bpc_range_xrandr (Display *xdisplay,
atom = XInternAtom (xdisplay, "max bpc", False);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
property_info = XRRQueryOutputProperty (xdisplay,
(XID) output_id,
atom);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (!property_info)
return FALSE;

View file

@ -39,6 +39,7 @@
#include "clutter/clutter-mutter.h"
#include "core/bell.h"
#include "meta-seat-x11.h"
#include "mtk/mtk-x11.h"
enum
{
@ -301,13 +302,13 @@ is_touchpad_device (MetaSeatX11 *seat_x11,
if (prop == None)
return FALSE;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay,
info->deviceid,
prop,
0, 1, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
(guchar **) &data);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
/* We don't care about the data */
XFree (data);
@ -330,13 +331,13 @@ get_device_ids (MetaSeatX11 *seat_x11,
int rc, format;
Atom type;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay,
info->deviceid,
XInternAtom (xdisplay, "Device Product ID", False),
0, 2, False, XA_INTEGER, &type, &format, &nitems, &bytes_after,
(guchar **) &data);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (rc != Success || type != XA_INTEGER || format != 32 || nitems != 2)
{
@ -369,14 +370,14 @@ get_device_node_path (MetaSeatX11 *seat_x11,
if (prop == None)
return NULL;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay,
info->deviceid, prop, 0, 1024, False,
XA_STRING, &type, &format, &nitems, &bytes_after,
(guchar **) &data);
if (meta_clutter_x11_untrap_x_errors ())
if (mtk_x11_error_trap_pop_with_return (xdisplay))
return NULL;
if (rc != Success || type != XA_STRING || format != 8)
@ -442,13 +443,13 @@ guess_source_from_wacom_type (MetaSeatX11 *seat_x11,
if (prop == None)
return FALSE;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay,
info->deviceid,
prop,
0, 1, False, XA_ATOM, &type, &format, &nitems, &bytes_after,
(guchar **) &data);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (rc != Success || type != XA_ATOM || format != 32 || nitems != 1)
{
@ -697,7 +698,7 @@ pad_passive_button_grab (MetaSeatX11 *seat_x11,
XISetMask (xi_event_mask.mask, XI_ButtonPress);
XISetMask (xi_event_mask.mask, XI_ButtonRelease);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGrabButton (xdisplay,
device_id, XIAnyButton,
root_xwindow, None,
@ -713,7 +714,7 @@ pad_passive_button_grab (MetaSeatX11 *seat_x11,
XIAllowEvents (xdisplay, device_id, XIAsyncDevice, CLUTTER_CURRENT_TIME);
}
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_free (xi_event_mask.mask);
}
@ -864,12 +865,12 @@ device_get_tool_serial (MetaSeatX11 *seat_x11,
if (prop == None)
return 0;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
rc = XIGetProperty (xdisplay,
meta_input_device_x11_get_device_id (device),
prop, 0, 4, FALSE, XA_INTEGER, &type, &format, &nitems, &bytes_after,
(guchar **) &data);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (rc == Success && type == XA_INTEGER && format == 32 && nitems >= 4)
serial_id = data[3];
@ -899,11 +900,11 @@ translate_hierarchy_event (ClutterBackend *clutter_backend,
g_debug ("Hierarchy event: device enabled");
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
info = XIQueryDevice (xdisplay,
ev->info[i].deviceid,
&n_devices);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
if (info != NULL)
{
ClutterInputDevice *device;
@ -1652,14 +1653,14 @@ meta_seat_x11_warp_pointer (ClutterSeat *seat,
Display *xdisplay = xdisplay_from_seat (seat_x11);
Window root_xwindow = root_xwindow_from_seat (seat_x11);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XIWarpPointer (xdisplay,
seat_x11->pointer_id,
None,
root_xwindow,
0, 0, 0, 0,
x, y);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
}
static void
@ -1671,14 +1672,14 @@ meta_seat_x11_init_pointer_position (ClutterSeat *seat,
Display *xdisplay = xdisplay_from_seat (seat_x11);
Window root_xwindow = root_xwindow_from_seat (seat_x11);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XIWarpPointer (xdisplay,
seat_x11->pointer_id,
None,
root_xwindow,
0, 0, 0, 0,
(int) x, (int) y);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
}
static uint32_t
@ -1744,14 +1745,14 @@ meta_seat_x11_query_state (ClutterSeat *seat,
XIModifierState modifier_state;
XIGroupState group_state;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XIQueryPointer (xdisplay,
seat_x11->pointer_id,
meta_backend_x11_get_xwindow (backend_x11),
&root_ret, &child_ret,
&root_x, &root_y, &win_x, &win_y,
&button_state, &modifier_state, &group_state);
if (meta_clutter_x11_untrap_x_errors ())
if (mtk_x11_error_trap_pop_with_return (xdisplay))
{
g_free (button_state.mask);
return FALSE;

View file

@ -29,7 +29,7 @@
#include "backends/x11/meta-clutter-backend-x11.h"
#include "backends/x11/meta-seat-x11.h"
#include "core/display-private.h"
#include "meta/meta-x11-errors.h"
#include "mtk/mtk-x11.h"
#define DEFAULT_XKB_SET_CONTROLS_MASK XkbSlowKeysMask | \
XkbBounceKeysMask | \
@ -56,14 +56,14 @@ get_xkb_desc_rec (Display *xdisplay)
XkbDescRec *desc;
Status status = Success;
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
desc = XkbGetMap (xdisplay, XkbAllMapComponentsMask, XkbUseCoreKbd);
if (desc != NULL)
{
desc->ctrls = NULL;
status = XkbGetControls (xdisplay, XkbAllControlsMask, desc);
}
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_return_val_if_fail (desc != NULL, NULL);
g_return_val_if_fail (desc->ctrls != NULL, NULL);
@ -76,10 +76,10 @@ static void
set_xkb_desc_rec (Display *xdisplay,
XkbDescRec *desc)
{
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
XkbSetControls (xdisplay, DEFAULT_XKB_SET_CONTROLS_MASK, desc);
XSync (xdisplay, FALSE);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
}
void

View file

@ -43,8 +43,8 @@
#include "core/meta-workspace-manager-private.h"
#include "core/workspace-private.h"
#include "meta/compositor.h"
#include "meta/meta-x11-errors.h"
#include "meta/prefs.h"
#include "mtk/mtk-x11.h"
#include "x11/meta-x11-display-private.h"
#include "x11/window-x11.h"
@ -1203,7 +1203,7 @@ meta_change_button_grab (MetaKeyBindingManager *keys,
mods = calc_grab_modifiers (keys, modmask);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
if (window->frame)
xwindow = window->frame->xwindow;
@ -1225,7 +1225,7 @@ meta_change_button_grab (MetaKeyBindingManager *keys,
XSync (xdisplay, False);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_array_free (mods, TRUE);
}
@ -1447,7 +1447,7 @@ meta_change_keygrab (MetaKeyBindingManager *keys,
mods = calc_grab_modifiers (keys, resolved_combo->mask);
meta_clutter_x11_trap_x_errors ();
mtk_x11_error_trap_push (xdisplay);
for (i = 0; i < resolved_combo->len; i++)
{
@ -1473,7 +1473,7 @@ meta_change_keygrab (MetaKeyBindingManager *keys,
XSync (xdisplay, False);
meta_clutter_x11_untrap_x_errors ();
mtk_x11_error_trap_pop (xdisplay);
g_array_free (mods, TRUE);
}