Browse Source

Use xcb-errors library if it is available

This library allows to get a human-readable string describing X11
requests, events, and errors. We now use this library to pretty-print
X11 errors if we get any.

To test this code, I added the following two lines to AwesomeWM so that
X11 errors are generated:

    xcb_set_input_focus(globalconf.connection, 42, 42, 42);
    xcb_randr_set_output_primary(globalconf.connection,
        globalconf.screen->root, 42);

Output without xcb-errors:

    X error: request=SetInputFocus (major 42, minor 0), error=BadValue (2)
    X error: request=(null) (major 140, minor 30), error=(null) (147)

Output with xcb-errors:

    X error: request=SetInputFocus (major 42, minor 0), error=Value (2)
    X error: request=RandR-SetOutputPrimary (major 140, minor 30), error=RandR-BadOutput (147)

Signed-off-by: Uli Schlachter <psychon@znc.in>
Uli Schlachter 7 months ago
parent
commit
a57c79687a
7 changed files with 55 additions and 4 deletions
  1. 8
    0
      awesome.c
  2. 11
    0
      awesomeConfig.cmake
  3. 7
    1
      common/version.c
  4. 1
    0
      config.h
  5. 2
    0
      docs/01-readme.md
  6. 17
    3
      event.c
  7. 9
    0
      globalconf.h

+ 8
- 0
awesome.c View File

@@ -145,6 +145,9 @@ awesome_atexit(bool restart)
145 145
 
146 146
     /* Disconnect *after* closing lua */
147 147
     xcb_cursor_context_free(globalconf.cursor_ctx);
148
+#ifdef WITH_XCB_ERRORS
149
+    xcb_errors_context_free(globalconf.errors_ctx);
150
+#endif
148 151
     xcb_disconnect(globalconf.connection);
149 152
 
150 153
     close(sigchld_pipe[0]);
@@ -751,6 +754,11 @@ main(int argc, char **argv)
751 754
                 globalconf.visual->visual_id);
752 755
     }
753 756
 
757
+#ifdef WITH_XCB_ERRORS
758
+    if (xcb_errors_context_new(globalconf.connection, &globalconf.errors_ctx) < 0)
759
+        fatal("Failed to initialize xcb-errors");
760
+#endif
761
+
754 762
     /* Get a recent timestamp */
755 763
     acquire_timestamp();
756 764
 

+ 11
- 0
awesomeConfig.cmake View File

@@ -13,6 +13,7 @@ autoOption(GENERATE_MANPAGES "generate manpages")
13 13
 option(COMPRESS_MANPAGES "compress manpages" ON)
14 14
 option(GENERATE_DOC "generate API documentation" ON)
15 15
 option(DO_COVERAGE "build with coverage" OFF)
16
+autoOption(WITH_XCB_ERRORS "build with xcb-errors")
16 17
 if (GENERATE_DOC AND DO_COVERAGE)
17 18
     message(STATUS "Not generating API documentation with DO_COVERAGE")
18 19
     set(GENERATE_DOC OFF)
@@ -213,6 +214,16 @@ if(WITH_DBUS)
213 214
         autoDisable(WITH_DBUS "DBus not found.")
214 215
     endif()
215 216
 endif()
217
+
218
+if(WITH_XCB_ERRORS)
219
+    pkg_check_modules(XCB_ERRORS xcb-errors)
220
+    if(XCB_ERRORS_FOUND)
221
+        set(AWESOME_OPTIONAL_LDFLAGS ${AWESOME_OPTIONAL_LDFLAGS} ${XCB_ERRORS_LDFLAGS})
222
+        set(AWESOME_OPTIONAL_INCLUDE_DIRS ${AWESOME_OPTIONAL_INCLUDE_DIRS} ${XCB_ERRORS_INCLUDE_DIRS})
223
+    else()
224
+        autoDisable(WITH_XCB_ERRORS "xcb-errors not found.")
225
+    endif()
226
+endif()
216 227
 # }}}
217 228
 
218 229
 # {{{ Install path and configuration variables

+ 7
- 1
common/version.c View File

@@ -54,6 +54,11 @@ eprint_version(void)
54 54
 #else
55 55
     const char *has_dbus = "✘";
56 56
 #endif
57
+#ifdef WITH_XCB_ERRORS
58
+    const char *has_xcb_errors = "✔";
59
+#else
60
+    const char *has_xcb_errors = "✘";
61
+#endif
57 62
 #ifdef HAS_EXECINFO
58 63
     const char *has_execinfo = "✔";
59 64
 #else
@@ -63,12 +68,13 @@ eprint_version(void)
63 68
     printf("awesome %s (%s)\n"
64 69
            " • Compiled against %s (running with %s)\n"
65 70
            " • D-Bus support: %s\n"
71
+           " • xcb-errors support: %s\n"
66 72
            " • execinfo support: %s\n"
67 73
            " • xcb-randr version: %d.%d\n"
68 74
            " • LGI version: %s\n",
69 75
            AWESOME_VERSION, AWESOME_RELEASE,
70 76
            LUA_RELEASE, lua_tostring(L, -2),
71
-           has_dbus, has_execinfo,
77
+           has_dbus, has_xcb_errors, has_execinfo,
72 78
            XCB_RANDR_MAJOR_VERSION, XCB_RANDR_MINOR_VERSION,
73 79
            lua_tostring(L, -1));
74 80
     lua_close(L);

+ 1
- 0
config.h View File

@@ -8,6 +8,7 @@
8 8
 #define AWESOME_DEFAULT_CONF  "@AWESOME_SYSCONFDIR@/rc.lua"
9 9
 
10 10
 #cmakedefine WITH_DBUS
11
+#cmakedefine WITH_XCB_ERRORS
11 12
 #cmakedefine HAS_EXECINFO
12 13
 
13 14
 #endif //_CONFIG_H_

+ 2
- 0
docs/01-readme.md View File

@@ -102,6 +102,8 @@ Additionally, the following optional dependencies exist:
102 102
   generate slightly better backtraces on crashes
103 103
 - `Xephyr` or `Xvfb` for running integration tests
104 104
 - [GTK+ >= 3.10](https://www.gtk.org/) for `./themes/gtk/`
105
+- [xcb-errors](https://gitlab.freedesktop.org/xorg/lib/libxcb-errors) for
106
+  pretty-printing of X11 errors
105 107
 
106 108
 ## Running Awesome
107 109
 

+ 17
- 3
event.c View File

@@ -1036,10 +1036,24 @@ xerror(xcb_generic_error_t *e)
1036 1036
            && e->major_code == XCB_CONFIGURE_WINDOW))
1037 1037
         return;
1038 1038
 
1039
-    warn("X error: request=%s (major %d, minor %d), error=%s (%d)",
1040
-         xcb_event_get_request_label(e->major_code),
1039
+#ifdef WITH_XCB_ERRORS
1040
+    const char *major = xcb_errors_get_name_for_major_code(
1041
+            globalconf.errors_ctx, e->major_code);
1042
+    const char *minor = xcb_errors_get_name_for_minor_code(
1043
+            globalconf.errors_ctx, e->major_code, e->minor_code);
1044
+    const char *extension = NULL;
1045
+    const char *error = xcb_errors_get_name_for_error(
1046
+            globalconf.errors_ctx, e->error_code, &extension);
1047
+#else
1048
+    const char *major = xcb_event_get_request_label(e->major_code);
1049
+    const char *minor = NULL;
1050
+    const char *extension = NULL;
1051
+    const char *error = xcb_event_get_error_label(e->error_code);
1052
+#endif
1053
+    warn("X error: request=%s%s%s (major %d, minor %d), error=%s%s%s (%d)",
1054
+         major, minor == NULL ? "" : "-", NONULL(minor),
1041 1055
          e->major_code, e->minor_code,
1042
-         xcb_event_get_error_label(e->error_code),
1056
+         NONULL(extension), extension == NULL ? "" : "-", error,
1043 1057
          e->error_code);
1044 1058
 
1045 1059
     return;

+ 9
- 0
globalconf.h View File

@@ -33,6 +33,11 @@
33 33
 #include <xcb/xcb_xrm.h>
34 34
 #include <X11/Xresource.h>
35 35
 
36
+#include "config.h"
37
+#ifdef WITH_XCB_ERRORS
38
+#include <xcb/xcb_errors.h>
39
+#endif
40
+
36 41
 #include "objects/key.h"
37 42
 #include "common/xembed.h"
38 43
 #include "common/buffer.h"
@@ -82,6 +87,10 @@ typedef struct
82 87
     int default_screen;
83 88
     /** xcb-cursor context */
84 89
     xcb_cursor_context_t *cursor_ctx;
90
+#ifdef WITH_XCB_ERRORS
91
+    /** xcb-errors context */
92
+    xcb_errors_context_t *errors_ctx;
93
+#endif
85 94
     /** Keys symbol table */
86 95
     xcb_key_symbols_t *keysyms;
87 96
     /** Logical screens */

Loading…
Cancel
Save