chiark / gitweb /
terminal/idev: forward xkb-messages
authorDavid Herrmann <dh.herrmann@gmail.com>
Tue, 25 Nov 2014 09:24:39 +0000 (10:24 +0100)
committerDavid Herrmann <dh.herrmann@gmail.com>
Tue, 25 Nov 2014 09:24:39 +0000 (10:24 +0100)
Properly forward all XKB messages. You can use XKB_LOG_VERBOSITY= to
control the amount of messages sent by XKB. We explicitly set
XKB_LOG_LEVEL to 7 you can use SYSTEMD_LOG_LEVEL to control the log-level
generically.

src/libsystemd-terminal/idev-keyboard.c

index c690c6647f3fec2fd5838be4eb6d426b1518fb23..ad2d74af1526a1b77344c1a744091e5903271966 100644 (file)
@@ -504,6 +504,27 @@ static int kbdctx_setup_bus(kbdctx *kc) {
         return kbdctx_query_locale(kc);
 }
 
+static void kbdctx_log_fn(struct xkb_context *ctx, enum xkb_log_level lvl, const char *format, va_list args) {
+        char buf[LINE_MAX];
+        int sd_lvl;
+
+        if (lvl >= XKB_LOG_LEVEL_DEBUG)
+                sd_lvl = LOG_DEBUG;
+        else if (lvl >= XKB_LOG_LEVEL_INFO)
+                sd_lvl = LOG_INFO;
+        else if (lvl >= XKB_LOG_LEVEL_WARNING)
+                sd_lvl = LOG_INFO; /* most XKB warnings really are informational */
+        else if (lvl >= XKB_LOG_LEVEL_ERROR)
+                sd_lvl = LOG_ERR;
+        else if (lvl >= XKB_LOG_LEVEL_CRITICAL)
+                sd_lvl = LOG_CRIT;
+        else
+                sd_lvl = LOG_CRIT;
+
+        snprintf(buf, sizeof(buf), "idev-xkb: %s", format);
+        log_metav(sd_lvl, __FILE__, __LINE__, __func__, buf, args);
+}
+
 static kbdctx *kbdctx_ref(kbdctx *kc) {
         assert_return(kc, NULL);
         assert_return(kc->ref > 0, NULL);
@@ -562,6 +583,9 @@ static int kbdctx_new(kbdctx **out, idev_context *c) {
         if (!kc->xkb_context)
                 return errno > 0 ? -errno : -EFAULT;
 
+        xkb_context_set_log_fn(kc->xkb_context, kbdctx_log_fn);
+        xkb_context_set_log_level(kc->xkb_context, XKB_LOG_LEVEL_DEBUG);
+
         r = kbdctx_refresh_keymap(kc);
         if (r < 0)
                 return r;