mmi-legacy-input : implemente wl_seat interface and add skeleton code of wl_keyboard 47/264047/1
authordyamy-lee <dyamy.lee@samsung.com>
Wed, 25 Aug 2021 10:34:14 +0000 (19:34 +0900)
committerSung-Jin Park <sj76.park@samsung.com>
Mon, 13 Sep 2021 11:24:49 +0000 (20:24 +0900)
Change-Id: Ib267e066d117a9e06fafc4492ceeae765253a432

src/modules/modality_keyboard/mmi-legacy-input.c

index 87210b3..1eef1f6 100644 (file)
 
 struct wl_display *display = NULL;
 struct wl_registry *registry = NULL;
+struct wl_seat *seat = NULL;
+struct wl_keyboard *keyboard = NULL;
 
 // 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);
+
 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 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);
+    }
 }
 
 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)
+{
+    (void) keyboard;
+    (void) format;
+    (void) fd;
+    (void) size;
+}
+
+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 void
+keyboard_key(void *data, struct wl_keyboard *keyboard, unsigned int serial, unsigned int timestamp, unsigned int keycode, unsigned int state)
+{
+    (void) keyboard;
+    (void) serial;
+    (void) timestamp;
+    (void) keycode;
+    (void) state;
+}
+
+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;
 }
 
 void _wl_init(void)
@@ -89,6 +213,8 @@ void _wl_init(void)
 
 void _wl_shutdown(void)
 {
+    wl_keyboard_release(keyboard);
+    wl_seat_destroy(seat);
     wl_display_disconnect(display);
 }