input: Use ds_tizen_input_devicemgr 91/279091/1
authorduna.oh <duna.oh@samsung.com>
Fri, 8 Jul 2022 01:12:33 +0000 (10:12 +0900)
committerSeunghun Lee <shiin.lee@samsung.com>
Tue, 2 Aug 2022 01:18:11 +0000 (10:18 +0900)
Change-Id: I7a75887e4cdd6a9021e635d03f5c29f7de3556af

configure.ac
packaging/headless-server.spec
src/input/input.c

index b8f19bf..7e98ae9 100644 (file)
@@ -29,7 +29,7 @@ fi
 AC_SUBST(GCC_CFLAGS)
 
 # headless server
-HEADLESS_SERVER_REQUIRES="xkbcommon capi-system-peripheral-io xdg-shell-unstable-v6-server tizen-extension-server wayland-tbm-server dlog wayland-server libds libds-tizen-tbm-server libds-tizen-keyrouter"
+HEADLESS_SERVER_REQUIRES="xkbcommon capi-system-peripheral-io xdg-shell-unstable-v6-server tizen-extension-server wayland-tbm-server dlog wayland-server libds libds-tizen-tbm-server libds-tizen-keyrouter libds-tizen-input-devicemgr"
 PKG_CHECK_MODULES(HEADLESS_SERVER, $[HEADLESS_SERVER_REQUIRES])
 
 AC_SUBST(HEADLESS_SERVER_CFLAGS)
index fcae547..9f6716e 100644 (file)
@@ -23,6 +23,7 @@ BuildRequires:  pkgconfig(wayland-server)
 BuildRequires:  pkgconfig(libds)
 BuildRequires:  pkgconfig(libds-tizen-tbm-server)
 BuildRequires:  pkgconfig(libds-tizen-keyrouter)
+BuildRequires:  pkgconfig(libds-tizen-input-devicemgr)
 
 Requires: libtbm
 Requires: capi-system-peripheral-io
index dbe1bb3..894f239 100644 (file)
 #include <libds/keyboard.h>
 #include <libds/seat.h>
 #include <libds-tizen/keyrouter.h>
+#include <libds-tizen/input_devicemgr.h>
 #include <xkbcommon/xkbcommon.h>
 
 #include "headless_server.h"
 
+#define KEYNAME_XF86_VOLUME_RAISE "XF86VolumeRaise"
+#define KEYNAME_XF86_VOLUME_LOWER "XF86VolumeLower"
+#define KEYNAME_XF86_LIGHT_ON "XF86LightOn"
+#define KEYNAME_XF86_LIGHT_OFF "XF86LightOff"
+
+#define KEYCODE_XF86_VOLUME_RAISE 455
+#define KEYCODE_XF86_VOLUME_LOWER 456
+#define KEYCODE_XF86_LIGHT_ON 457
+#define KEYCODE_XF86_LIGHT_OFF 458
+
 typedef struct headless_input headless_input_t;
 typedef struct headless_keyboard headless_keyboard_t;
 
@@ -49,6 +60,7 @@ struct headless_input
        struct ds_backend *backend;
        struct ds_seat *seat;
        struct ds_tizen_keyrouter *keyrouter;
+       struct ds_tizen_input_devicemgr *devicemgr;
 
        struct wl_listener new_input;
        struct wl_listener focus_change;
@@ -75,6 +87,7 @@ static headless_keyboard_t *create_keyboard(headless_input_t *input,
 static void keyboard_destroy(headless_keyboard_t *keyboard);
 static void keyboard_handle_destroy(struct wl_listener *listener, void *data);
 static void keyboard_handle_key(struct wl_listener *listener, void *data);
+static void devicemgr_set_keymap(struct ds_tizen_input_devicemgr *devicemgr);
 
 headless_input_t *
 headless_input_create(headless_server_t *server)
@@ -105,6 +118,15 @@ headless_input_create(headless_server_t *server)
                goto err_seat;
        }
 
+       input->devicemgr = ds_tizen_input_devicemgr_create(
+               input->backend, input->seat);
+       if (!input->devicemgr) {
+               ds_err("Could not create ds_tizen_input_devicemgr");
+               goto err_input_devicemgr;
+       }
+
+       devicemgr_set_keymap(input->devicemgr);
+
        input->new_input.notify = handle_new_input;
        ds_backend_add_new_input_listener(input->backend, &input->new_input);
 
@@ -120,6 +142,7 @@ headless_input_create(headless_server_t *server)
 
        return input;
 
+err_input_devicemgr:
 err_seat:
 err_keyrouter:
        ds_backend_destroy(input->backend);
@@ -308,6 +331,61 @@ keyboard_handle_key(struct wl_listener *listener, void *data)
                        input->top_view ? input->top_view->surface : NULL,
                        ev->time_msec, ev->keycode, ev->state);
 }
+
+static void
+devicemgr_add_keymap_data(struct wl_list *list, const char *name, int keycode)
+{
+       struct ds_tizen_input_devicemgr_keymap_data *data;
+
+       data = calloc(1, sizeof *data);
+       if (!data) {
+               ds_err("Failed to alloc memory");
+               return;
+       }
+
+       data->name = strdup(name);
+       data->keycode = keycode;
+
+       wl_list_insert(list, &data->link);
+}
+
+static void
+devicemgr_remove_keymap_data(struct wl_list *list, int keycode)
+{
+       struct ds_tizen_input_devicemgr_keymap_data *data, *tmp;
+
+       wl_list_for_each_safe(data, tmp, list, link) {
+               if (data->keycode == keycode) {
+                       wl_list_remove(&data->link);
+                       free(data->name);
+                       free(data);
+               }
+       }
+}
+
+static void
+devicemgr_set_keymap(struct ds_tizen_input_devicemgr *devicemgr)
+{
+       struct wl_list keymap_list;
+       bool res;
+
+       wl_list_init(&keymap_list);
+
+       devicemgr_add_keymap_data(&keymap_list, KEYNAME_XF86_VOLUME_RAISE, KEYCODE_XF86_VOLUME_RAISE);
+       devicemgr_add_keymap_data(&keymap_list, KEYNAME_XF86_VOLUME_LOWER, KEYCODE_XF86_VOLUME_LOWER);
+       devicemgr_add_keymap_data(&keymap_list, KEYNAME_XF86_LIGHT_ON, KEYCODE_XF86_LIGHT_ON);
+       devicemgr_add_keymap_data(&keymap_list, KEYNAME_XF86_LIGHT_OFF, KEYCODE_XF86_LIGHT_OFF);
+
+       res = ds_tizen_input_devicemgr_set_keymap_list(devicemgr, &keymap_list);
+       if (!res)
+               ds_inf("Failed to set keymap");
+
+       devicemgr_remove_keymap_data(&keymap_list, KEYCODE_XF86_VOLUME_RAISE);
+       devicemgr_remove_keymap_data(&keymap_list, KEYCODE_XF86_VOLUME_LOWER);
+       devicemgr_remove_keymap_data(&keymap_list, KEYCODE_XF86_LIGHT_ON);
+       devicemgr_remove_keymap_data(&keymap_list, KEYCODE_XF86_LIGHT_OFF);
+}
+
 #else
 #include <pepper-evdev.h>
 #include <pepper-input-backend.h>