devicemgr: generate a input device key event instead of keyboard key event 36/203036/2
authorjeon <jhyuni.kang@samsung.com>
Tue, 9 Apr 2019 07:14:11 +0000 (16:14 +0900)
committerjeon <jhyuni.kang@samsung.com>
Tue, 9 Apr 2019 07:16:01 +0000 (16:16 +0900)
Change-Id: I6b84130f6e8a76528923cebb56f3a7a7848474a9

src/lib/devicemgr/devicemgr-internal.h
src/lib/devicemgr/devicemgr.c
src/lib/devicemgr/devicemgr.h
src/lib/devicemgr/pepper-devicemgr.c

index a8dc8d481e57d119390dadadab3985d3d0160743..754356bcf401df3ba0ec47cf5977f5e4149e00df 100644 (file)
@@ -36,7 +36,6 @@
 struct devicemgr_device {
        char name[UINPUT_MAX_NAME_SIZE + 1];
        pepper_input_device_t *input_device;
-       pepper_keyboard_t *kbd;
 };
 
 struct devicemgr {
index 6378f2da34a9a336ba6aa1a2b705030e337fcfee..69063fbe87f716f8ec22f22725c5cb511bf93713 100644 (file)
@@ -25,7 +25,7 @@
 #include <tizen-extension-server-protocol.h>
 
 static void
-_devicemgr_generate_key(pepper_keyboard_t *keyboard, int keycode, int pressed)
+_devicemgr_generate_key(pepper_input_device_t *device, int keycode, int pressed)
 {
        pepper_input_event_t event;
        struct timeval time;
@@ -38,8 +38,8 @@ _devicemgr_generate_key(pepper_keyboard_t *keyboard, int keycode, int pressed)
        event.key = keycode - 8;
        event.state = pressed ? PEPPER_KEY_STATE_PRESSED : PEPPER_KEY_STATE_RELEASED;
 
-       pepper_object_emit_event((pepper_object_t *)keyboard,
-                                                               PEPPER_EVENT_KEYBOARD_KEY, &event);
+       pepper_object_emit_event((pepper_object_t *)device,
+               PEPPER_EVENT_INPUT_DEVICE_KEYBOARD_KEY, &event);
 }
 
 PEPPER_API int
@@ -48,36 +48,36 @@ devicemgr_input_generator_generate_key(devicemgr_t *devicemgr, int keycode, pepp
        PEPPER_CHECK(devicemgr,
                return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES,
                "Invalid devicemgr structure.\n");
-       PEPPER_CHECK(devicemgr->keyboard && devicemgr->keyboard->kbd,
+       PEPPER_CHECK(devicemgr->keyboard && devicemgr->keyboard->input_device,
                return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NO_SYSTEM_RESOURCES,
                "Keyboard device is not initialized\n");
 
-       _devicemgr_generate_key(devicemgr->keyboard->kbd, keycode, pressed);
+       _devicemgr_generate_key(devicemgr->keyboard->input_device, keycode, pressed);
 
        return TIZEN_INPUT_DEVICE_MANAGER_ERROR_NONE;
 }
 
 PEPPER_API void
-devicemgr_input_generator_keyboard_set(devicemgr_t *devicemgr, pepper_keyboard_t *keyboard)
+devicemgr_input_generator_keyboard_set(devicemgr_t *devicemgr, pepper_input_device_t *device)
 {
        PEPPER_CHECK(devicemgr, return, "Invalid devicemgr structure.\n");
        PEPPER_CHECK(devicemgr->keyboard, return, "input generator is not initialized yet.\n");
-       if (devicemgr->keyboard->kbd) return;
-       devicemgr->keyboard->kbd = keyboard;
+       if (devicemgr->keyboard->input_device) return;
+       devicemgr->keyboard->input_device = device;
 }
 
 PEPPER_API void
-devicemgr_input_generator_keyboard_unset(devicemgr_t *devicemgr, pepper_keyboard_t *keyboard)
+devicemgr_input_generator_keyboard_unset(devicemgr_t *devicemgr, pepper_input_device_t *device)
 {
        PEPPER_CHECK(devicemgr, return, "Invalid devicemgr structure.\n");
-       devicemgr->keyboard->kbd = NULL;
+       devicemgr->keyboard->input_device = NULL;
 }
 
 
 static pepper_bool_t
 _devicemgr_input_generator_keyboard_create(devicemgr_t *devicemgr, const char *name)
 {
-       if (devicemgr->keyboard->kbd) return PEPPER_TRUE;
+       if (devicemgr->keyboard->input_device) return PEPPER_TRUE;
 
        devicemgr->keyboard->input_device = pepper_input_device_create(devicemgr->compositor, WL_SEAT_CAPABILITY_KEYBOARD, NULL, NULL);
        PEPPER_CHECK(devicemgr->keyboard->input_device, return PEPPER_FALSE, "Failed to create input device !\n");
index 56f54cb5febc1fdc81b577f9a101b86198443952..cff136b7b2392a1b7816a3317bbb1d21939f39d6 100644 (file)
@@ -39,8 +39,8 @@ PEPPER_API int devicemgr_input_generator_init(devicemgr_t *devicemgr, unsigned i
 PEPPER_API int devicemgr_input_generator_deinit(devicemgr_t *devicemgr);
 PEPPER_API int devicemgr_input_generator_generate_key(devicemgr_t *devicemgr, int keycode, pepper_bool_t pressed);
 
-PEPPER_API void devicemgr_input_generator_keyboard_set(devicemgr_t *devicemgr, pepper_keyboard_t *keyboard);
-PEPPER_API void devicemgr_input_generator_keyboard_unset(devicemgr_t *devicemgr, pepper_keyboard_t *keyboard);
+PEPPER_API void devicemgr_input_generator_keyboard_set(devicemgr_t *devicemgr, pepper_input_device_t *device);
+PEPPER_API void devicemgr_input_generator_keyboard_unset(devicemgr_t *devicemgr, pepper_input_device_t *device);
 
 #ifdef __cplusplus
 }
index 799fbaa7f1a16b9708fc26ee39c17841074509bd..68351aabdfe64433e6ca35e1ab9bbf7e1f313825 100644 (file)
@@ -43,8 +43,11 @@ struct pepper_devicemgr {
        pepper_list_t *keymap_list;
 #endif
 
+       pepper_event_listener_t *listener_input_device_add;
+#ifdef _F_DEVICEMGR_XKB
        pepper_event_listener_t *listener_seat_keyboard_add;
        pepper_event_listener_t *listener_keyboard_keymap_update;
+#endif
 
        pepper_list_t resources;
 
@@ -67,7 +70,6 @@ _pepper_devicemgr_handle_keyboard_keymap_update(pepper_event_listener_t *listene
 
        pepper_devicemgr->xkb_info = keyboard->xkb_info;
 }
-#endif
 
 static void
 _pepper_devicemgr_handle_seat_keyboard_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
@@ -75,15 +77,23 @@ _pepper_devicemgr_handle_seat_keyboard_add(pepper_event_listener_t *listener, pe
        pepper_keyboard_t *keyboard = (pepper_keyboard_t *)info;
        pepper_devicemgr_t *pepper_devicemgr = (pepper_devicemgr_t *)data;
 
-       devicemgr_input_generator_keyboard_set(pepper_devicemgr->devicemgr, keyboard);
-#ifdef _F_DEVICEMGR_XKB
        pepper_devicemgr->xkb_info = keyboard->xkb_info;
 
        pepper_devicemgr->listener_keyboard_keymap_update =
                pepper_object_add_event_listener((pepper_object_t *)keyboard,
                        PEPPER_EVENT_KEYBOARD_KEYMAP_UPDATE, 0,
                        _pepper_devicemgr_handle_keyboard_keymap_update, pepper_devicemgr);
+}
 #endif
+
+static void
+_pepper_devicemgr_handle_input_device_add(pepper_event_listener_t *listener, pepper_object_t *object, uint32_t id, void *info, void *data)
+{
+       pepper_input_device_t *device = (pepper_input_device_t *)info;
+       pepper_devicemgr_t *pepper_devicemgr = (pepper_devicemgr_t *)data;
+
+       if (pepper_input_device_get_caps(device) & WL_SEAT_CAPABILITY_KEYBOARD)
+               devicemgr_input_generator_keyboard_set(pepper_devicemgr->devicemgr, device);
 }
 
 static void
@@ -375,9 +385,15 @@ pepper_devicemgr_create(pepper_compositor_t *compositor, pepper_seat_t *seat)
        pepper_devicemgr->compositor = compositor;
        pepper_devicemgr->seat = seat;
 
+       pepper_devicemgr->listener_input_device_add = pepper_object_add_event_listener((pepper_object_t *)pepper_devicemgr->compositor,
+               PEPPER_EVENT_COMPOSITOR_INPUT_DEVICE_ADD,
+               0, _pepper_devicemgr_handle_input_device_add, pepper_devicemgr);
+
+#ifdef _F_DEVICEMGR_XKB
        pepper_devicemgr->listener_seat_keyboard_add = pepper_object_add_event_listener((pepper_object_t *)pepper_devicemgr->seat,
                PEPPER_EVENT_SEAT_KEYBOARD_ADD,
                0, _pepper_devicemgr_handle_seat_keyboard_add, pepper_devicemgr);
+#endif
 
        pepper_list_init(&pepper_devicemgr->resources);