From ff27ca4072b093a25a22a43decb2e05944de1b46 Mon Sep 17 00:00:00 2001 From: Yuxuan Shui Date: Sun, 30 Sep 2018 14:37:21 +0100 Subject: [PATCH] Move xerror_common to x.c Also rename it to x_print_error Signed-off-by: Yuxuan Shui --- src/compton.c | 108 ++------------------------------------------------ src/x.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++ src/x.h | 9 +++++ 3 files changed, 113 insertions(+), 104 deletions(-) diff --git a/src/compton.c b/src/compton.c index 19d744e..0c2f26e 100644 --- a/src/compton.c +++ b/src/compton.c @@ -2434,114 +2434,13 @@ root_damaged(session_t *ps) { force_repaint(ps); } -/** - * X11 error handler function. - */ -static void -xerror_common(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code) { - session_t * const ps = ps_g; - - int o = 0; - const char *name = "Unknown"; - - if (should_ignore(ps, serial)) { - return; - } - - if (major == ps->composite_opcode - && minor == XCB_COMPOSITE_REDIRECT_SUBWINDOWS) { - fprintf(stderr, "Another composite manager is already running " - "(and does not handle _NET_WM_CM_Sn correctly)\n"); - exit(1); - } - -#define CASESTRRET2(s) case s: name = #s; break - - o = error_code - ps->xfixes_error; - switch (o) { - CASESTRRET2(BadRegion); - } - - o = error_code - ps->damage_error; - switch (o) { - CASESTRRET2(XCB_DAMAGE_BAD_DAMAGE); - } - - o = error_code - ps->render_error; - switch (o) { - CASESTRRET2(XCB_RENDER_PICT_FORMAT); - CASESTRRET2(XCB_RENDER_PICTURE); - CASESTRRET2(XCB_RENDER_PICT_OP); - CASESTRRET2(XCB_RENDER_GLYPH_SET); - CASESTRRET2(XCB_RENDER_GLYPH); - } - -#ifdef CONFIG_OPENGL - if (ps->glx_exists) { - o = error_code - ps->glx_error; - switch (o) { - CASESTRRET2(GLX_BAD_SCREEN); - CASESTRRET2(GLX_BAD_ATTRIBUTE); - CASESTRRET2(GLX_NO_EXTENSION); - CASESTRRET2(GLX_BAD_VISUAL); - CASESTRRET2(GLX_BAD_CONTEXT); - CASESTRRET2(GLX_BAD_VALUE); - CASESTRRET2(GLX_BAD_ENUM); - } - } -#endif - -#ifdef CONFIG_XSYNC - if (ps->xsync_exists) { - o = error_code - ps->xsync_error; - switch (o) { - CASESTRRET2(XSyncBadCounter); - CASESTRRET2(XSyncBadAlarm); - CASESTRRET2(XSyncBadFence); - } - } -#endif - - switch (error_code) { - CASESTRRET2(BadAccess); - CASESTRRET2(BadAlloc); - CASESTRRET2(BadAtom); - CASESTRRET2(BadColor); - CASESTRRET2(BadCursor); - CASESTRRET2(BadDrawable); - CASESTRRET2(BadFont); - CASESTRRET2(BadGC); - CASESTRRET2(BadIDChoice); - CASESTRRET2(BadImplementation); - CASESTRRET2(BadLength); - CASESTRRET2(BadMatch); - CASESTRRET2(BadName); - CASESTRRET2(BadPixmap); - CASESTRRET2(BadRequest); - CASESTRRET2(BadValue); - CASESTRRET2(BadWindow); - } - -#undef CASESTRRET2 - - print_timestamp(ps); - { - char buf[BUF_LEN] = ""; - XGetErrorText(ps->dpy, error_code, buf, BUF_LEN); - printf("error %4d %-12s request %4d minor %4d serial %6lu: \"%s\"\n", - error_code, name, major, - minor, serial, buf); - } - - // print_backtrace(); -} - /** * Xlib error handler function. */ static int xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) { - xerror_common(ev->serial, ev->request_code, ev->minor_code, ev->error_code); + if (!should_ignore(ps_g, ev->serial)) + x_print_error(ev->serial, ev->request_code, ev->minor_code, ev->error_code); return 0; } @@ -2550,7 +2449,8 @@ xerror(Display __attribute__((unused)) *dpy, XErrorEvent *ev) { */ void ev_xcb_error(session_t __attribute__((unused)) *ps, xcb_generic_error_t *err) { - xerror_common(err->sequence, err->major_code, err->minor_code, err->error_code); + if (!should_ignore(ps, err->sequence)) + x_print_error(err->sequence, err->major_code, err->minor_code, err->error_code); } static void diff --git a/src/x.c b/src/x.c index d6abe8e..183f952 100644 --- a/src/x.c +++ b/src/x.c @@ -261,3 +261,103 @@ void x_set_picture_clip_region(session_t *ps, xcb_render_picture_t pict, free(xrects); return; } + +/** + * X11 error handler function. + * + * XXX consider making this error to string + */ +void +x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code) { + session_t * const ps = ps_g; + + int o = 0; + const char *name = "Unknown"; + + if (major == ps->composite_opcode + && minor == XCB_COMPOSITE_REDIRECT_SUBWINDOWS) { + fprintf(stderr, "Another composite manager is already running " + "(and does not handle _NET_WM_CM_Sn correctly)\n"); + exit(1); + } + +#define CASESTRRET2(s) case s: name = #s; break + + o = error_code - ps->xfixes_error; + switch (o) { + CASESTRRET2(BadRegion); + } + + o = error_code - ps->damage_error; + switch (o) { + CASESTRRET2(XCB_DAMAGE_BAD_DAMAGE); + } + + o = error_code - ps->render_error; + switch (o) { + CASESTRRET2(XCB_RENDER_PICT_FORMAT); + CASESTRRET2(XCB_RENDER_PICTURE); + CASESTRRET2(XCB_RENDER_PICT_OP); + CASESTRRET2(XCB_RENDER_GLYPH_SET); + CASESTRRET2(XCB_RENDER_GLYPH); + } + +#ifdef CONFIG_OPENGL + if (ps->glx_exists) { + o = error_code - ps->glx_error; + switch (o) { + CASESTRRET2(GLX_BAD_SCREEN); + CASESTRRET2(GLX_BAD_ATTRIBUTE); + CASESTRRET2(GLX_NO_EXTENSION); + CASESTRRET2(GLX_BAD_VISUAL); + CASESTRRET2(GLX_BAD_CONTEXT); + CASESTRRET2(GLX_BAD_VALUE); + CASESTRRET2(GLX_BAD_ENUM); + } + } +#endif + +#ifdef CONFIG_XSYNC + if (ps->xsync_exists) { + o = error_code - ps->xsync_error; + switch (o) { + CASESTRRET2(XSyncBadCounter); + CASESTRRET2(XSyncBadAlarm); + CASESTRRET2(XSyncBadFence); + } + } +#endif + + switch (error_code) { + CASESTRRET2(BadAccess); + CASESTRRET2(BadAlloc); + CASESTRRET2(BadAtom); + CASESTRRET2(BadColor); + CASESTRRET2(BadCursor); + CASESTRRET2(BadDrawable); + CASESTRRET2(BadFont); + CASESTRRET2(BadGC); + CASESTRRET2(BadIDChoice); + CASESTRRET2(BadImplementation); + CASESTRRET2(BadLength); + CASESTRRET2(BadMatch); + CASESTRRET2(BadName); + CASESTRRET2(BadPixmap); + CASESTRRET2(BadRequest); + CASESTRRET2(BadValue); + CASESTRRET2(BadWindow); + } + +#undef CASESTRRET2 + + print_timestamp(ps); + { + char buf[BUF_LEN] = ""; + XGetErrorText(ps->dpy, error_code, buf, BUF_LEN); + printf("error %4d %-12s request %4d minor %4d serial %6lu: \"%s\"\n", + error_code, name, major, + minor, serial, buf); + } + + // print_backtrace(); +} diff --git a/src/x.h b/src/x.h index e539a93..025e992 100644 --- a/src/x.h +++ b/src/x.h @@ -1,4 +1,5 @@ #pragma once +#include #include #include #include @@ -76,3 +77,11 @@ bool x_fetch_region(session_t *ps, XserverRegion r, region_t *res); void x_set_picture_clip_region(session_t *ps, xcb_render_picture_t, int clip_x_origin, int clip_y_origin, const region_t *); + +/** + * X11 error handler function. + * + * XXX consider making this error to string + */ +void +x_print_error(unsigned long serial, uint8_t major, uint8_t minor, uint8_t error_code);