modality_keyboard_srcs = [
'mmi-keyboard-provider.c',
'mmi-keyboard-provider.h',
- 'mmi-wayland-input.h',
- 'mmi-wayland-input.c',
+ 'wayland-input.h',
+ 'wayland-input.c',
]
install_headers(
*/
#include "mmi-keyboard-provider.h"
-#include "mmi-wayland-input.h"
+#include "wayland-input.h"
#include <stdio.h>
#include <stdlib.h>
+++ /dev/null
-/*
-* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice (including the next
-* paragraph) shall be included in all copies or substantial portions of the
-* Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*/
-
-#include "mmi-wayland-input.h"
-#include "../../mmi-manager-dbg.h"
-
-#include <stdlib.h>
-#include <sys/mman.h>
-#include <unistd.h>
-
-#include <wayland-client.h>
-#include <xkbcommon/xkbcommon.h>
-#include <tizen-extension-client-protocol.h>
-
-struct wl_display *display = NULL;
-struct wl_registry *registry = NULL;
-struct wl_seat *seat = NULL;
-struct wl_keyboard *keyboard = NULL;
-struct tizen_keyrouter *tz_keyrouter = NULL;
-
-struct xkb_context *xkb_context;
-struct xkb_keymap *keymap;
-
-typedef struct tizen_keyrouter_notify tizen_keyrouter_notify_t;
-struct tizen_keyrouter_notify
-{
- unsigned int keycode;
- unsigned int mode;
- unsigned int error;
-};
-
-typedef struct keycode_map keycode_map_t;
-struct keycode_map
-{
- xkb_keysym_t keysym;
- xkb_keycode_t *keycodes;
- int nkeycodes;
-};
-
-typedef struct keymap_info keymap_info_t;
-struct keymap_info
-{
- const char *keyname;
- int mode;
-};
-
-unsigned int has_keymap = 0;
-unsigned int set_keymap = 0;
-
-// wl_registry listener
-static void handle_global(void *, struct wl_registry *, unsigned int, const char *, unsigned int);
-static void handle_global_remove(void *, struct wl_registry *, unsigned int);
-
-// wl_seat listener
-static void seat_capabilities(void *, struct wl_seat *, enum wl_seat_capability);
-static void seat_name(void *data, struct wl_seat *seat, const char *name);
-
-// wl_keyboard listener
-static void keyboard_keymap(void *, struct wl_keyboard *, unsigned int, int fd, unsigned int);
-static void keyboard_enter(void *, struct wl_keyboard *, unsigned int, struct wl_surface *, struct wl_array *);
-static void keyboard_leave(void *, struct wl_keyboard *, unsigned int, struct wl_surface *);
-static void keyboard_key(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int);
-static void keyboard_modifiers(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
-static void keyboard_repeat_setup(void *, struct wl_keyboard *, int32_t, int32_t);
-
-// tizen_keyrouter listener
-static void keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error);
-static void keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
-static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
-static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode);
-static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
-static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
-static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key);
-
-static const struct wl_registry_listener registry_listener = {
- handle_global,
- handle_global_remove,
-};
-
-static const struct wl_seat_listener seat_listener = {
- seat_capabilities,
- seat_name,
-};
-
-static const struct wl_keyboard_listener keyboard_listener = {
- keyboard_keymap,
- keyboard_enter,
- keyboard_leave,
- keyboard_key,
- keyboard_modifiers,
- keyboard_repeat_setup,
-};
-
-static const struct tizen_keyrouter_listener keyrouter_listener = {
- keygrab_notify,
- keygrab_notify_list,
- getgrab_notify_list,
- set_register_none_key,
- keyregister_notify,
- set_input_config,
- key_cancel,
-};
-
-static void
-handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version)
-{
- if (!strcmp("wl_seat", interface))
- {
- seat = wl_registry_bind(registry, id, &wl_seat_interface, 4);
- wl_seat_add_listener(seat, &seat_listener, NULL);
- }
- else if (!strcmp("tizen_keyrouter", interface))
- {
- tz_keyrouter = wl_registry_bind(registry, id, &tizen_keyrouter_interface, 1);
- tizen_keyrouter_add_listener(tz_keyrouter, &keyrouter_listener, NULL);
- }
-}
-
-static void
-handle_global_remove(void *data, struct wl_registry *registry, unsigned int id)
-{
- (void) registry;
- (void) id;
-}
-
-static void
-seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
-{
- if ((caps & WL_SEAT_CAPABILITY_KEYBOARD))
- {
- if (keyboard)
- {
- wl_keyboard_release(keyboard);
- keyboard = NULL;
- }
-
- keyboard = wl_seat_get_keyboard(seat);
- if(!keyboard)
- {
- LOGE("Failed to get wl_keyboard from a seat !\n");
- return;
- }
- wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
- LOGD("seat caps update : keyboard added\n");
- }
- else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (keyboard))
- {
- wl_keyboard_release(keyboard);
- keyboard = NULL;
- }
-}
-
-static void
-seat_name(void *data, struct wl_seat *seat, const char *name)
-{
- (void) seat;
- (void) name;
-}
-
-static void
-keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, int fd, unsigned int size)
-{
- char *map = NULL;
-
- LOGD("...WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1=%d, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP=%d\n",
- WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP);
- LOGD("... format=%d, fd=%d, size=%d\n", format, fd, size);
-
- if (!xkb_context)
- {
- LOGE("... This client failed to make xkb context\n");
- close(fd);
- return;
- }
- if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP)
- {
- has_keymap = 0;
- }
- else
- {
- LOGD("wl_keyboard has keymap...\n");
- map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
- if(map == MAP_FAILED)
- {
- LOGE("... Failed to mmap from fd(%d) size(%d)\n", fd, size);
- close(fd);
- return;
- }
-
- keymap = xkb_map_new_from_string(xkb_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
- if(!keymap) {
- LOGE("... Failed to get keymap from fd(%d)\n", fd);
- munmap(map, size);
- close(fd);
- return;
- }
-
- munmap(map, size);
- close(fd);
- has_keymap = 1;
- }
-
- LOGD("has_keymap = %s\n", has_keymap ? "true" : "false");
- set_keymap = 1;
-}
-
-static void
-keyboard_enter(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface, struct wl_array *keys)
-{
- (void) keyboard;
- (void) serial;
- (void) surface;
- (void) keys;
-}
-
-static void
-keyboard_leave(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface)
-{
- (void) keyboard;
- (void) serial;
- (void) surface;
-}
-
-static int
-_covert_kernel_keycode_to_user_keycode(int kernel_keycode)
-{
- LOGD("kernel keycode : %d, user keycode : %d\n", kernel_keycode, kernel_keycode+8);
- return (kernel_keycode+8);
-}
-
-static void
-keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
-{
- int user_keycode = _covert_kernel_keycode_to_user_keycode(keycode);
-
- LOGD("... serial=%d, time=%d, key=%d, state=%d\n", serial, timestamp, user_keycode, state);
- if (!has_keymap)
- {
- //TODO : do anything with the given keycode
- // ex> call application callback(s)
- LOGD("keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
- }
- else
- {
- LOGD("has_keymap | keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
- if(keymap)
- {
- const char * name = NULL;
- if((name = xkb_keymap_key_get_name(keymap, user_keycode)))
- LOGD("key name = %s, keycode = %d\n", name, user_keycode);
- else
- LOGD("No matched keyname from keycode = %d\n", user_keycode);
- }
- }
-}
-
-static void
-keyboard_modifiers(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
-{
- (void) keyboard;
- (void) serial;
- (void) depressed;
- (void) latched;
- (void) locked;
- (void) group;
-}
-
-static void
-keyboard_repeat_setup(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
-{
- (void) keyboard;
- (void) rate;
- (void) delay;
-}
-
-static void
-keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error)
-{
- LOGD("key : %d, mode : %d, error : %d\n", key, mode, error);
-}
-
-static void
-keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
-{
- tizen_keyrouter_notify_t *tz_keyrouter_notify;
- struct wl_array array;
-
- wl_array_init(&array);
- wl_array_copy(&array, notify_result);
-
- wl_array_for_each(tz_keyrouter_notify, &array)
- {
- LOGD("... keygrab result ! (keycode : %d, mode : %d, error : %d)\n",
- tz_keyrouter_notify->keycode, tz_keyrouter_notify->mode, tz_keyrouter_notify->error);
- }
-
- wl_array_release(&array);
-}
-
-static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
-{
- (void) tizen_keyrouter;
- (void) surface;
- (void) notify_result;
-}
-
-static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode)
-{
- (void) tizen_keyrouter;
- (void) surface;
- (void) mode;
-}
-
-static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
-{
- (void) tizen_keyrouter;
- (void) status;
-}
-
-static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
-{
- (void) tizen_keyrouter;
- (void) status;
-}
-
-static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key)
-{
- (void) tizen_keyrouter;
- (void) key;
-}
-
-int _xkb_context_init(void)
-{
- xkb_context = xkb_context_new(0);
- if(!xkb_context)
- {
- LOGE("Failed to get xkb_context!\n");
- return 0;
- }
- return 1;
-}
-
-void _xkb_context_shutdown(void)
-{
- if(!xkb_context)
- return;
-
- xkb_context_unref(xkb_context);
-}
-
-static void
-_find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
-{
- keycode_map_t *found_keycodes = (keycode_map_t *)data;
- xkb_keysym_t keysym = found_keycodes->keysym;
- int nsyms = 0;
- const xkb_keysym_t *syms_out = NULL;
- xkb_keycode_t *tmp_keycodes = NULL;
-
- if(!keymap)
- {
- LOGE("Invalied keymap \n");
- return;
- }
-
- nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
-
- if (nsyms && syms_out)
- {
- if (*syms_out == keysym)
- {
- tmp_keycodes = calloc(1, sizeof(int)*(found_keycodes->nkeycodes+1));
-
- if (tmp_keycodes)
- {
- memcpy(tmp_keycodes, found_keycodes->keycodes, sizeof(int)*found_keycodes->nkeycodes);
- free(found_keycodes->keycodes);
-
- found_keycodes->nkeycodes++;
- found_keycodes->keycodes = tmp_keycodes;
- found_keycodes->keycodes[found_keycodes->nkeycodes-1] = key;
- }
- }
- }
-}
-
-int _get_keycode_from_keysym(struct xkb_keymap *keymap, xkb_keysym_t keysym, xkb_keycode_t **keycodes)
-{
- keycode_map_t found_keycodes = {0,};
- found_keycodes.keysym = keysym;
-
- if(!keymap)
- {
- LOGE("Invalied keymap \n");
- return 0;
- }
-
- xkb_keymap_key_for_each(keymap, _find_keycode, &found_keycodes);
-
- *keycodes = found_keycodes.keycodes;
- return found_keycodes.nkeycodes;
-}
-
-void _do_keygrab(const char *keyname, uint32_t mode)
-{
- xkb_keysym_t keysym = 0x0;
- int nkeycodes = 0;
- xkb_keycode_t *keycodes = NULL;
- int i;
-
- keysym = xkb_keysym_from_name(keyname, XKB_KEYSYM_NO_FLAGS);
- nkeycodes = _get_keycode_from_keysym(keymap, keysym, &keycodes);
- if(!nkeycodes)
- {
- LOGE("Failed do keygrab on %s(%d)\n", keyname, keysym);
- free(keycodes);
- keycodes = NULL;
- return;
- }
-
- for(i=0; i<nkeycodes; i++)
- {
- tizen_keyrouter_set_keygrab(tz_keyrouter, NULL, keycodes[i], mode);
- wl_display_dispatch(display);
- }
-
-}
-
-static keymap_info_t stored_keymap[] = {
- { "XF86Back", TIZEN_KEYROUTER_MODE_EXCLUSIVE },
- { "XF86Info", TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE}
-};
-
-void _keygrab_init(void)
-{
- int i;
- int size = sizeof(stored_keymap)/sizeof(keymap_info_t);
-
- LOGD("stored keymap size = %d\n", size);
- for(i=0; i < size; i++)
- {
- LOGD("stored keymap %d = %s, %d\n", i, stored_keymap[i].keyname, stored_keymap[i].mode);
- _do_keygrab(stored_keymap[i].keyname, stored_keymap[i].mode);
- }
-}
-
-void _wl_init(void)
-{
- int res = 0;
- const char *socket_name = NULL;
-
- socket_name = getenv("WAYLAND_DISPLAY");
- LOGD("socket name = %s\n", socket_name);
- if(!socket_name)
- {
- LOGD("NO has socket name\n");
- socket_name = "wayland-0";
- }
- if (!getenv("XDG_RUNTIME_DIR"))
- {
- LOGD("no xdg runtime dir\n");
- setenv("XDG_RUNTIME_DIR", "/run", 1);
- }
-
- display = wl_display_connect(socket_name);
- if(!display)
- {
- LOGE("Failed to connect wayland display (socket_name = %s) !\n", socket_name);
- return;
- }
-
- res = _xkb_context_init();
- if(!res)
- {
- LOGE("Failed to init xkb\n");
- }
-
- registry = wl_display_get_registry(display);
- if(!registry)
- {
- LOGE("Failed to get registry\n");
- return;
- }
- wl_registry_add_listener(registry, ®istry_listener, NULL);
-
- while(!set_keymap)
- wl_display_roundtrip(display);
-}
-
-void _wl_shutdown(void)
-{
- tizen_keyrouter_destroy(tz_keyrouter);
- wl_keyboard_release(keyboard);
- wl_seat_destroy(seat);
- wl_display_disconnect(display);
-}
-
-void wayland_input_init(void)
-{
- _wl_init();
- _keygrab_init();
-}
-
-void wayland_input_shutdown(void)
-{
- _wl_shutdown();
- _xkb_context_shutdown();
-}
\ No newline at end of file
+++ /dev/null
-/*
-* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
-*
-* Permission is hereby granted, free of charge, to any person obtaining a
-* copy of this software and associated documentation files (the "Software"),
-* to deal in the Software without restriction, including without limitation
-* the rights to use, copy, modify, merge, publish, distribute, sublicense,
-* and/or sell copies of the Software, and to permit persons to whom the
-* Software is furnished to do so, subject to the following conditions:
-*
-* The above copyright notice and this permission notice (including the next
-* paragraph) shall be included in all copies or substantial portions of the
-* Software.
-*
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
-* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
-* DEALINGS IN THE SOFTWARE.
-*/
-
-#ifndef __MMI_WAYLAND_INPUT_H__
-#define __MMI_WAYLAND_INPUT_H__
-
-void wayland_input_init(void);
-void wayland_input_shutdown(void);
-
-#endif // __MMI_WAYLAND_INPUT_H__
\ No newline at end of file
--- /dev/null
+/*
+* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#include "wayland-input.h"
+#include "../../mmi-manager-dbg.h"
+
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#include <wayland-client.h>
+#include <xkbcommon/xkbcommon.h>
+#include <tizen-extension-client-protocol.h>
+
+struct wl_display *display = NULL;
+struct wl_registry *registry = NULL;
+struct wl_seat *seat = NULL;
+struct wl_keyboard *keyboard = NULL;
+struct tizen_keyrouter *tz_keyrouter = NULL;
+
+struct xkb_context *xkb_context;
+struct xkb_keymap *keymap;
+
+typedef struct tizen_keyrouter_notify tizen_keyrouter_notify_t;
+struct tizen_keyrouter_notify
+{
+ unsigned int keycode;
+ unsigned int mode;
+ unsigned int error;
+};
+
+typedef struct keycode_map keycode_map_t;
+struct keycode_map
+{
+ xkb_keysym_t keysym;
+ xkb_keycode_t *keycodes;
+ int nkeycodes;
+};
+
+typedef struct keymap_info keymap_info_t;
+struct keymap_info
+{
+ const char *keyname;
+ int mode;
+};
+
+unsigned int has_keymap = 0;
+unsigned int set_keymap = 0;
+
+// wl_registry listener
+static void handle_global(void *, struct wl_registry *, unsigned int, const char *, unsigned int);
+static void handle_global_remove(void *, struct wl_registry *, unsigned int);
+
+// wl_seat listener
+static void seat_capabilities(void *, struct wl_seat *, enum wl_seat_capability);
+static void seat_name(void *data, struct wl_seat *seat, const char *name);
+
+// wl_keyboard listener
+static void keyboard_keymap(void *, struct wl_keyboard *, unsigned int, int fd, unsigned int);
+static void keyboard_enter(void *, struct wl_keyboard *, unsigned int, struct wl_surface *, struct wl_array *);
+static void keyboard_leave(void *, struct wl_keyboard *, unsigned int, struct wl_surface *);
+static void keyboard_key(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int);
+static void keyboard_modifiers(void *, struct wl_keyboard *, unsigned int, unsigned int, unsigned int, unsigned int, unsigned int);
+static void keyboard_repeat_setup(void *, struct wl_keyboard *, int32_t, int32_t);
+
+// tizen_keyrouter listener
+static void keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error);
+static void keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
+static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result);
+static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode);
+static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
+static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status);
+static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key);
+
+static const struct wl_registry_listener registry_listener = {
+ handle_global,
+ handle_global_remove,
+};
+
+static const struct wl_seat_listener seat_listener = {
+ seat_capabilities,
+ seat_name,
+};
+
+static const struct wl_keyboard_listener keyboard_listener = {
+ keyboard_keymap,
+ keyboard_enter,
+ keyboard_leave,
+ keyboard_key,
+ keyboard_modifiers,
+ keyboard_repeat_setup,
+};
+
+static const struct tizen_keyrouter_listener keyrouter_listener = {
+ keygrab_notify,
+ keygrab_notify_list,
+ getgrab_notify_list,
+ set_register_none_key,
+ keyregister_notify,
+ set_input_config,
+ key_cancel,
+};
+
+static void
+handle_global(void *data, struct wl_registry *registry, unsigned int id, const char *interface, unsigned int version)
+{
+ if (!strcmp("wl_seat", interface))
+ {
+ seat = wl_registry_bind(registry, id, &wl_seat_interface, 4);
+ wl_seat_add_listener(seat, &seat_listener, NULL);
+ }
+ else if (!strcmp("tizen_keyrouter", interface))
+ {
+ tz_keyrouter = wl_registry_bind(registry, id, &tizen_keyrouter_interface, 1);
+ tizen_keyrouter_add_listener(tz_keyrouter, &keyrouter_listener, NULL);
+ }
+}
+
+static void
+handle_global_remove(void *data, struct wl_registry *registry, unsigned int id)
+{
+ (void) registry;
+ (void) id;
+}
+
+static void
+seat_capabilities(void *data, struct wl_seat *seat, enum wl_seat_capability caps)
+{
+ if ((caps & WL_SEAT_CAPABILITY_KEYBOARD))
+ {
+ if (keyboard)
+ {
+ wl_keyboard_release(keyboard);
+ keyboard = NULL;
+ }
+
+ keyboard = wl_seat_get_keyboard(seat);
+ if(!keyboard)
+ {
+ LOGE("Failed to get wl_keyboard from a seat !\n");
+ return;
+ }
+ wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL);
+ LOGD("seat caps update : keyboard added\n");
+ }
+ else if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && (keyboard))
+ {
+ wl_keyboard_release(keyboard);
+ keyboard = NULL;
+ }
+}
+
+static void
+seat_name(void *data, struct wl_seat *seat, const char *name)
+{
+ (void) seat;
+ (void) name;
+}
+
+static void
+keyboard_keymap(void *data, struct wl_keyboard *keyboard, unsigned int format, int fd, unsigned int size)
+{
+ char *map = NULL;
+
+ LOGD("...WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1=%d, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP=%d\n",
+ WL_KEYBOARD_KEYMAP_FORMAT_XKB_V1, WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP);
+ LOGD("... format=%d, fd=%d, size=%d\n", format, fd, size);
+
+ if (!xkb_context)
+ {
+ LOGE("... This client failed to make xkb context\n");
+ close(fd);
+ return;
+ }
+ if (format == WL_KEYBOARD_KEYMAP_FORMAT_NO_KEYMAP)
+ {
+ has_keymap = 0;
+ }
+ else
+ {
+ LOGD("wl_keyboard has keymap...\n");
+ map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+ if(map == MAP_FAILED)
+ {
+ LOGE("... Failed to mmap from fd(%d) size(%d)\n", fd, size);
+ close(fd);
+ return;
+ }
+
+ keymap = xkb_map_new_from_string(xkb_context, map, XKB_KEYMAP_FORMAT_TEXT_V1, 0);
+ if(!keymap) {
+ LOGE("... Failed to get keymap from fd(%d)\n", fd);
+ munmap(map, size);
+ close(fd);
+ return;
+ }
+
+ munmap(map, size);
+ close(fd);
+ has_keymap = 1;
+ }
+
+ LOGD("has_keymap = %s\n", has_keymap ? "true" : "false");
+ set_keymap = 1;
+}
+
+static void
+keyboard_enter(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface, struct wl_array *keys)
+{
+ (void) keyboard;
+ (void) serial;
+ (void) surface;
+ (void) keys;
+}
+
+static void
+keyboard_leave(void *data, struct wl_keyboard *keyboard, unsigned int serial, struct wl_surface *surface)
+{
+ (void) keyboard;
+ (void) serial;
+ (void) surface;
+}
+
+static int
+_covert_kernel_keycode_to_user_keycode(int kernel_keycode)
+{
+ LOGD("kernel keycode : %d, user keycode : %d\n", kernel_keycode, kernel_keycode+8);
+ return (kernel_keycode+8);
+}
+
+static void
+keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
+{
+ int user_keycode = _covert_kernel_keycode_to_user_keycode(keycode);
+
+ LOGD("... serial=%d, time=%d, key=%d, state=%d\n", serial, timestamp, user_keycode, state);
+ if (!has_keymap)
+ {
+ //TODO : do anything with the given keycode
+ // ex> call application callback(s)
+ LOGD("keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
+ }
+ else
+ {
+ LOGD("has_keymap | keycode : %d, state : %d, timestamp : %d\n", user_keycode, state, timestamp);
+ if(keymap)
+ {
+ const char * name = NULL;
+ if((name = xkb_keymap_key_get_name(keymap, user_keycode)))
+ LOGD("key name = %s, keycode = %d\n", name, user_keycode);
+ else
+ LOGD("No matched keyname from keycode = %d\n", user_keycode);
+ }
+ }
+}
+
+static void
+keyboard_modifiers(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int depressed, unsigned int latched, unsigned int locked, unsigned int group)
+{
+ (void) keyboard;
+ (void) serial;
+ (void) depressed;
+ (void) latched;
+ (void) locked;
+ (void) group;
+}
+
+static void
+keyboard_repeat_setup(void *data, struct wl_keyboard *keyboard, int32_t rate, int32_t delay)
+{
+ (void) keyboard;
+ (void) rate;
+ (void) delay;
+}
+
+static void
+keygrab_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t key, uint32_t mode, uint32_t error)
+{
+ LOGD("key : %d, mode : %d, error : %d\n", key, mode, error);
+}
+
+static void
+keygrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
+{
+ tizen_keyrouter_notify_t *tz_keyrouter_notify;
+ struct wl_array array;
+
+ wl_array_init(&array);
+ wl_array_copy(&array, notify_result);
+
+ wl_array_for_each(tz_keyrouter_notify, &array)
+ {
+ LOGD("... keygrab result ! (keycode : %d, mode : %d, error : %d)\n",
+ tz_keyrouter_notify->keycode, tz_keyrouter_notify->mode, tz_keyrouter_notify->error);
+ }
+
+ wl_array_release(&array);
+}
+
+static void getgrab_notify_list(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, struct wl_array *notify_result)
+{
+ (void) tizen_keyrouter;
+ (void) surface;
+ (void) notify_result;
+}
+
+static void set_register_none_key(void *data, struct tizen_keyrouter *tizen_keyrouter, struct wl_surface *surface, uint32_t mode)
+{
+ (void) tizen_keyrouter;
+ (void) surface;
+ (void) mode;
+}
+
+static void keyregister_notify(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
+{
+ (void) tizen_keyrouter;
+ (void) status;
+}
+
+static void set_input_config(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t status)
+{
+ (void) tizen_keyrouter;
+ (void) status;
+}
+
+static void key_cancel(void *data, struct tizen_keyrouter *tizen_keyrouter, uint32_t key)
+{
+ (void) tizen_keyrouter;
+ (void) key;
+}
+
+int _xkb_context_init(void)
+{
+ xkb_context = xkb_context_new(0);
+ if(!xkb_context)
+ {
+ LOGE("Failed to get xkb_context!\n");
+ return 0;
+ }
+ return 1;
+}
+
+void _xkb_context_shutdown(void)
+{
+ if(!xkb_context)
+ return;
+
+ xkb_context_unref(xkb_context);
+}
+
+static void
+_find_keycode(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
+{
+ keycode_map_t *found_keycodes = (keycode_map_t *)data;
+ xkb_keysym_t keysym = found_keycodes->keysym;
+ int nsyms = 0;
+ const xkb_keysym_t *syms_out = NULL;
+ xkb_keycode_t *tmp_keycodes = NULL;
+
+ if(!keymap)
+ {
+ LOGE("Invalied keymap \n");
+ return;
+ }
+
+ nsyms = xkb_keymap_key_get_syms_by_level(keymap, key, 0, 0, &syms_out);
+
+ if (nsyms && syms_out)
+ {
+ if (*syms_out == keysym)
+ {
+ tmp_keycodes = calloc(1, sizeof(int)*(found_keycodes->nkeycodes+1));
+
+ if (tmp_keycodes)
+ {
+ memcpy(tmp_keycodes, found_keycodes->keycodes, sizeof(int)*found_keycodes->nkeycodes);
+ free(found_keycodes->keycodes);
+
+ found_keycodes->nkeycodes++;
+ found_keycodes->keycodes = tmp_keycodes;
+ found_keycodes->keycodes[found_keycodes->nkeycodes-1] = key;
+ }
+ }
+ }
+}
+
+int _get_keycode_from_keysym(struct xkb_keymap *keymap, xkb_keysym_t keysym, xkb_keycode_t **keycodes)
+{
+ keycode_map_t found_keycodes = {0,};
+ found_keycodes.keysym = keysym;
+
+ if(!keymap)
+ {
+ LOGE("Invalied keymap \n");
+ return 0;
+ }
+
+ xkb_keymap_key_for_each(keymap, _find_keycode, &found_keycodes);
+
+ *keycodes = found_keycodes.keycodes;
+ return found_keycodes.nkeycodes;
+}
+
+void _do_keygrab(const char *keyname, uint32_t mode)
+{
+ xkb_keysym_t keysym = 0x0;
+ int nkeycodes = 0;
+ xkb_keycode_t *keycodes = NULL;
+ int i;
+
+ keysym = xkb_keysym_from_name(keyname, XKB_KEYSYM_NO_FLAGS);
+ nkeycodes = _get_keycode_from_keysym(keymap, keysym, &keycodes);
+ if(!nkeycodes)
+ {
+ LOGE("Failed do keygrab on %s(%d)\n", keyname, keysym);
+ free(keycodes);
+ keycodes = NULL;
+ return;
+ }
+
+ for(i=0; i<nkeycodes; i++)
+ {
+ tizen_keyrouter_set_keygrab(tz_keyrouter, NULL, keycodes[i], mode);
+ wl_display_dispatch(display);
+ }
+
+}
+
+static keymap_info_t stored_keymap[] = {
+ { "XF86Back", TIZEN_KEYROUTER_MODE_EXCLUSIVE },
+ { "XF86Info", TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE}
+};
+
+void _keygrab_init(void)
+{
+ int i;
+ int size = sizeof(stored_keymap)/sizeof(keymap_info_t);
+
+ LOGD("stored keymap size = %d\n", size);
+ for(i=0; i < size; i++)
+ {
+ LOGD("stored keymap %d = %s, %d\n", i, stored_keymap[i].keyname, stored_keymap[i].mode);
+ _do_keygrab(stored_keymap[i].keyname, stored_keymap[i].mode);
+ }
+}
+
+void _wl_init(void)
+{
+ int res = 0;
+ const char *socket_name = NULL;
+
+ socket_name = getenv("WAYLAND_DISPLAY");
+ LOGD("socket name = %s\n", socket_name);
+ if(!socket_name)
+ {
+ LOGD("NO has socket name\n");
+ socket_name = "wayland-0";
+ }
+ if (!getenv("XDG_RUNTIME_DIR"))
+ {
+ LOGD("no xdg runtime dir\n");
+ setenv("XDG_RUNTIME_DIR", "/run", 1);
+ }
+
+ display = wl_display_connect(socket_name);
+ if(!display)
+ {
+ LOGE("Failed to connect wayland display (socket_name = %s) !\n", socket_name);
+ return;
+ }
+
+ res = _xkb_context_init();
+ if(!res)
+ {
+ LOGE("Failed to init xkb\n");
+ }
+
+ registry = wl_display_get_registry(display);
+ if(!registry)
+ {
+ LOGE("Failed to get registry\n");
+ return;
+ }
+ wl_registry_add_listener(registry, ®istry_listener, NULL);
+
+ while(!set_keymap)
+ wl_display_roundtrip(display);
+}
+
+void _wl_shutdown(void)
+{
+ tizen_keyrouter_destroy(tz_keyrouter);
+ wl_keyboard_release(keyboard);
+ wl_seat_destroy(seat);
+ wl_display_disconnect(display);
+}
+
+void wayland_input_init(void)
+{
+ _wl_init();
+ _keygrab_init();
+}
+
+void wayland_input_shutdown(void)
+{
+ _wl_shutdown();
+ _xkb_context_shutdown();
+}
\ No newline at end of file
--- /dev/null
+/*
+* Copyright © 2021 Samsung Electronics co., Ltd. All Rights Reserved.
+*
+* Permission is hereby granted, free of charge, to any person obtaining a
+* copy of this software and associated documentation files (the "Software"),
+* to deal in the Software without restriction, including without limitation
+* the rights to use, copy, modify, merge, publish, distribute, sublicense,
+* and/or sell copies of the Software, and to permit persons to whom the
+* Software is furnished to do so, subject to the following conditions:
+*
+* The above copyright notice and this permission notice (including the next
+* paragraph) shall be included in all copies or substantial portions of the
+* Software.
+*
+* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+* DEALINGS IN THE SOFTWARE.
+*/
+
+#ifndef __WAYLAND_INPUT_H__
+#define __WAYLAND_INPUT_H__
+
+void wayland_input_init(void);
+void wayland_input_shutdown(void);
+
+#endif // __WAYLAND_INPUT_H__
\ No newline at end of file