1 // SPDX-FileCopyrightText: Copyright 2013 Intel Corporation
2 // SPDX-License-Identifier: BSD-2-Clause
5 /// @brief Wrappers for Xlib functions
7 /// Each wrapper catches any Xlib error emitted by the wrapped function. The
8 /// wrapper's signature matches the wrapped.
10 /// All Xlib error generated by Waffle must be caught by Waffle. Otherwise, the
11 /// Xlib error handler installed by the user will catch the error and may
12 /// handle it in a way Waffle doesn't like. Or, even worse, the default Xlib
13 /// error handler will catch it, which exits the process.
17 #include <X11/Xlib-xcb.h>
19 #define X11_SAVE_ERROR_HANDLER \
20 int (*old_handler)(Display*, XErrorEvent*) = \
21 XSetErrorHandler(x11_dummy_error_handler);
23 #define X11_RESTORE_ERROR_HANDLER \
24 XSetErrorHandler(old_handler);
27 x11_dummy_error_handler(Display
*dpy
, XErrorEvent
*err
)
32 static inline Display
*
33 wrapped_XOpenDisplay(const char *name
)
35 X11_SAVE_ERROR_HANDLER
36 Display
*dpy
= XOpenDisplay(name
);
37 X11_RESTORE_ERROR_HANDLER
42 wrapped_XCloseDisplay(Display
*dpy
)
44 X11_SAVE_ERROR_HANDLER
45 int error
= XCloseDisplay(dpy
);
46 X11_RESTORE_ERROR_HANDLER
50 static inline xcb_connection_t
*
51 wrapped_XGetXCBConnection(Display
*dpy
)
53 X11_SAVE_ERROR_HANDLER
54 xcb_connection_t
*conn
= XGetXCBConnection(dpy
);
55 X11_RESTORE_ERROR_HANDLER