kmscon: pass vtnr to pty so XDG_VTNR is set
[platform/upstream/kmscon.git] / tests / test_input.c
index 5e32ba3..7dc06c7 100644 (file)
@@ -37,18 +37,22 @@ static void print_help();
 #include <sys/signalfd.h>
 #include <unistd.h>
 #include <X11/keysym.h>
+#include <xkbcommon/xkbcommon.h>
 #include "eloop.h"
-#include "log.h"
-#include "uterm.h"
+#include "shl_log.h"
+#include "uterm_input.h"
+#include "uterm_monitor.h"
 #include "test_include.h"
 
 static struct ev_eloop *eloop;
 static struct uterm_input *input;
 
 struct {
+       char *xkb_model;
        char *xkb_layout;
        char *xkb_variant;
        char *xkb_options;
+       char *xkb_keymap;
 } input_conf;
 
 /* Pressing Ctrl-\ should toggle the capturing. */
@@ -84,19 +88,19 @@ static void print_modifiers(unsigned int mods)
 }
 
 static void input_arrived(struct uterm_input *input,
-                               struct uterm_input_event *ev,
-                               void *data)
+                         struct uterm_input_event *ev,
+                         void *data)
 {
        char s[32];
 
-       uterm_input_keysym_to_string(input, ev->keysym, s, sizeof(s));
+       xkb_keysym_get_name(ev->keysyms[0], s, sizeof(s));
        printf("sym %s ", s);
-       if (ev->unicode != UTERM_INPUT_INVALID) {
+       if (ev->codepoints[0] != UTERM_INPUT_INVALID) {
                /*
                 * Just a proof-of-concept hack. This works because glibc uses
                 * UTF-32 (= UCS-4) as the internal wchar_t encoding.
                 */
-               printf("unicode %lc ", ev->unicode);
+               printf("unicode %lc ", ev->codepoints[0]);
        }
        print_modifiers(ev->mods);
 }
@@ -106,15 +110,28 @@ static void monitor_event(struct uterm_monitor *mon,
                                void *data)
 {
        int ret;
+       char *keymap;
 
        if (ev->type == UTERM_MONITOR_NEW_SEAT) {
                if (strcmp(ev->seat_name, "seat0"))
                        return;
 
+               keymap = NULL;
+               if (input_conf.xkb_keymap && *input_conf.xkb_keymap) {
+                       ret = shl_read_file(input_conf.xkb_keymap, &keymap,
+                                           NULL);
+                       if (ret)
+                               log_error("cannot read keymap file %s: %d",
+                                         input_conf.xkb_keymap, ret);
+               }
+
                ret = uterm_input_new(&input, eloop,
+                                     input_conf.xkb_model,
                                      input_conf.xkb_layout,
                                      input_conf.xkb_variant,
-                                     input_conf.xkb_options);
+                                     input_conf.xkb_options,
+                                     keymap,
+                                     0, 0);
                if (ret)
                        return;
                ret = uterm_input_register_cb(input, input_arrived, NULL);
@@ -158,9 +175,12 @@ static void print_help()
                TEST_HELP
                "\n"
                "Input Device Options:\n"
-               "\t    --xkb-layout <layout>   [us]    Set XkbLayout for input devices\n"
+               "\t    --xkb-model <model>     [-]     Set XkbModel for input devices\n"
+               "\t    --xkb-layout <layout>   [-]     Set XkbLayout for input devices\n"
                "\t    --xkb-variant <variant> [-]     Set XkbVariant for input devices\n"
-               "\t    --xkb-options <options> [-]     Set XkbOptions for input devices\n",
+               "\t    --xkb-options <options> [-]     Set XkbOptions for input devices\n"
+               "\t    --xkb-keymap <FILE>     [-]     Use a predefined keymap for\n"
+               "\t                                    input devices\n",
                "test_input");
        /*
         * 80 char line:
@@ -174,9 +194,11 @@ static void print_help()
 
 struct conf_option options[] = {
        TEST_OPTIONS,
-       CONF_OPTION_STRING(0, "xkb-layout", NULL, &input_conf.xkb_layout, "us"),
-       CONF_OPTION_STRING(0, "xkb-variant", NULL, &input_conf.xkb_variant, ""),
-       CONF_OPTION_STRING(0, "xkb-options", NULL, &input_conf.xkb_options, ""),
+       CONF_OPTION_STRING(0, "xkb-model", &input_conf.xkb_model, ""),
+       CONF_OPTION_STRING(0, "xkb-layout", &input_conf.xkb_layout, ""),
+       CONF_OPTION_STRING(0, "xkb-variant", &input_conf.xkb_variant, ""),
+       CONF_OPTION_STRING(0, "xkb-options", &input_conf.xkb_options, ""),
+       CONF_OPTION_STRING(0, "xkb-keymap", &input_conf.xkb_keymap, ""),
 };
 
 int main(int argc, char **argv)