e_seat: move keyboard variables (enabled, num_devices) to E_Seat struct
authorduna.oh <duna.oh@samsung.com>
Fri, 4 Apr 2025 09:03:55 +0000 (18:03 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 7 Apr 2025 08:09:16 +0000 (17:09 +0900)
Change-Id: Ibf012d8f0070d34414ec9782731d9e10ecbaeb5a

src/bin/e_comp_screen.c
src/bin/inputmgr/e_comp_input_intern.h
src/bin/inputmgr/e_input.c
src/bin/inputmgr/e_input_backend.c
src/bin/server/e_comp_wl_data.c
src/bin/server/e_comp_wl_input.c
src/bin/server/e_seat.c
src/bin/server/e_seat_intern.h

index efc788e9334c81333ba15552acf0f67feb161262..260615814b2361cfc2e29323114cc8ad212fb80c 100644 (file)
@@ -327,8 +327,8 @@ _e_comp_screen_cb_input_device_add(void *data, int type, void *event)
      {
         if (!e_input_thread_mode_get())
           {
-             e_comp_input_key->kbd.num_devices++;
-             e_comp_wl_input_keyboard_enabled_set(EINA_TRUE);
+             e_seat_keyboard_enabled_set(seat, EINA_TRUE);
+             e_seat_keyboard_device_count_increase(seat);
           }
      }
    else if (e->clas == ECORE_DEVICE_CLASS_TOUCH)
index d8af363584b11c7e935d46d41d3f81e54feaccad..8126603517903e613dee52d0001445831cf00198 100644 (file)
@@ -33,7 +33,6 @@ struct _E_Comp_Input_Key_Data
      {
         Eina_List *resources;
         Eina_List *focused;
-        Eina_Bool enabled : 1;
         xkb_mod_index_t mod_shift, mod_caps;
         xkb_mod_index_t mod_ctrl, mod_alt;
         xkb_mod_index_t mod_super;
@@ -44,7 +43,6 @@ struct _E_Comp_Input_Key_Data
         int mod_changed;
         atomic_int repeat_delay;
         atomic_int repeat_rate;
-        unsigned int num_devices;
         GRecMutex resources_mutex;
         GRecMutex focused_mutex;
      } kbd;
index 6d1c2f5fe326d6235d65a08c53daacdb4f0b6ea8..16bd90a606459b22d045c5bbe0c582b16d4ddb35 100644 (file)
@@ -131,6 +131,13 @@ e_input_thread_enabled_get(void)
    return e_input->use_thread;
 }
 
+static void
+e_input_init_seat_caps_async_cb(void *data)
+{
+   unsigned int seat_caps = *(unsigned int *)data;
+   e_comp_wl_input_seat_caps_set(seat_caps);
+}
+
 EINTERN int
 e_input_init(Ecore_Evas *ee)
 {
@@ -262,8 +269,9 @@ e_input_init(Ecore_Evas *ee)
      {
         /* Enable some of keyboard, touch devices temporarily */
         /* FIXME : get seat caps from e_input configuration or env */
+        EINA_LOG_INFO("This system uses udev backend and select to skip udev enumeration");
         seat_caps = E_INPUT_SEAT_KEYBOARD | E_INPUT_SEAT_TOUCH;
-        e_comp_wl_input_seat_caps_set(seat_caps);
+        ecore_main_loop_thread_safe_call_async(e_input_init_seat_caps_async_cb, (void *)seat_caps);
      }
 
    E_LIST_HANDLER_APPEND(e_input->handlers, E_EVENT_SCREEN_CHANGE, _e_input_cb_screen_change, NULL);
index 586d0c7ec7c8be341cf34466b3897d5438bdc8dc..58e72ec9a9d23d3a80af06edc1d0a1b7221683e1 100644 (file)
@@ -384,6 +384,18 @@ _e_input_device_event_add(const char *name, const char *identifier, const char *
    e_input_event_add(input_event_source, flag ? ECORE_EVENT_DEVICE_ADD : ECORE_EVENT_DEVICE_DEL, ecore_dev_info, _e_input_ecore_device_info_free, NULL);
 }
 
+static void
+_e_input_add_ecore_device_keyboard_async_cb(void *data)
+{
+   E_Seat *seat;
+   const char *seatname = data;
+
+   seat = e_seat_find(seatname);
+   if (!seat) return;
+   e_seat_keyboard_device_count_increase(seat);
+   e_seat_keyboard_enabled_set(seat, EINA_TRUE);
+}
+
 static Eina_Bool
 _e_input_add_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas, Ecore_Device_Subclass subclas)
 {
@@ -393,7 +405,7 @@ _e_input_add_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas, Ecore_D
 
    const GList *device_list = e_device_list_get();
    const gchar *device_identifier;
-   const char *seat_name = NULL;
+   const char *seat_name = e_input_seat_name_get(evdev->seat);
 
    for (GList *list = g_list_first((GList *)device_list); list; list = list->next)
      {
@@ -425,14 +437,13 @@ _e_input_add_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas, Ecore_D
    e_device_identifier_set(e_dev, evdev->path);
    e_device_class_set(e_dev, clas);
    e_device_subclass_set(e_dev, subclas);
-   e_device_seatname_set(e_dev, e_input_evdev_seatname_get(evdev));
+   e_device_seatname_set(e_dev, seat_name);
 
    if (e_input_thread_mode_get())
      {
         if (clas == ECORE_DEVICE_CLASS_KEYBOARD)
           {
-             e_comp_input_key->kbd.num_devices++;
-             e_comp_wl_input_keyboard_enabled_set(EINA_TRUE);
+             ecore_main_loop_thread_safe_call_async(_e_input_add_ecore_device_keyboard_async_cb, (void *)seat_name);
           }
      }
 
@@ -460,7 +471,7 @@ _e_input_add_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas, Ecore_D
 
    INF("[Add Device] device name(%s), identifier(%s), class(%s), subclass(%d), seatname(%s)", e_device_name_get(e_dev), evdev->path, _e_input_ecore_device_class_to_string(clas), subclas, e_device_seatname_get(e_dev));
 
-   _e_input_device_event_add(evdev->name, evdev->path, e_input_seat_name_get(evdev->seat), clas, subclas, EINA_TRUE);
+   _e_input_device_event_add(evdev->name, evdev->path, seat_name, clas, subclas, EINA_TRUE);
 
    dev_info = E_NEW(E_Device_Info, 1);
    EINA_SAFETY_ON_NULL_RETURN_VAL(dev_info, EINA_FALSE);
@@ -468,7 +479,6 @@ _e_input_add_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas, Ecore_D
    dev_info->evdev = evdev;
    dev_info->clas = clas;
    dev_info->subclas = subclas;
-   seat_name = e_device_seatname_get(e_dev);
    dev_info->seatname = seat_name ? strdup(seat_name) : NULL;
 
    ecore_main_loop_thread_safe_call_async(_e_input_add_ecore_device_async_cb, dev_info);
@@ -528,6 +538,20 @@ end:
    E_FREE(dev_info);
 }
 
+
+static void
+_e_input_remove_ecore_device_keyboard_async_cb(void *data)
+{
+   E_Seat *seat;
+   const char *seatname = data;
+
+   seat = e_seat_find(seatname);
+   if (!seat) return;
+   e_seat_keyboard_device_count_decrease(seat);
+   if (e_seat_keyboard_device_count(seat) == 0)
+     e_seat_keyboard_enabled_set(seat, EINA_FALSE);
+}
+
 static Eina_Bool
 _e_input_remove_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas)
 {
@@ -536,6 +560,7 @@ _e_input_remove_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas)
    const gchar *device_identifier;
    const char *device_remove_log = NULL;
    E_Device_Info *dev_info = NULL;
+   const char *seat_name = e_input_seat_name_get(evdev->seat);
 
    e_dev_list = e_device_list_get();
    if (!e_dev_list)
@@ -555,9 +580,7 @@ _e_input_remove_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas)
           {
              if (clas == ECORE_DEVICE_CLASS_KEYBOARD)
                {
-                  e_comp_input_key->kbd.num_devices--;
-                  if (e_comp_input_key->kbd.num_devices == 0)
-                    e_comp_wl_input_keyboard_enabled_set(EINA_FALSE);
+                  ecore_main_loop_thread_safe_call_async(_e_input_remove_ecore_device_keyboard_async_cb, (void *)seat_name);
                }
 
              device_remove_log = eina_stringshare_printf("[Remove Device] device name(%s), identifier(%s), class(%s), subclass(%d), seatname(%s)",
@@ -567,7 +590,7 @@ _e_input_remove_ecore_device(E_Input_Evdev *evdev, Ecore_Device_Class clas)
                                                          e_device_subclass_get(device),
                                                          e_device_seatname_get(device));
 
-             _e_input_device_event_add(e_device_name_get(device), device_identifier, e_input_seat_name_get(evdev->seat), clas, e_device_subclass_get(device), EINA_FALSE);
+             _e_input_device_event_add(e_device_name_get(device), device_identifier, seat_name, clas, e_device_subclass_get(device), EINA_FALSE);
 
              if (evdev->e_dev)
                {
index 612a059bb08769719ee1172883126322c8535fa8..7267a9c50b25a8ddf43f4c2f109257aff90c4321 100644 (file)
@@ -636,7 +636,7 @@ _e_comp_wl_data_device_selection_unset(void)
 
    comp_wl = e_comp_wl_get();
 
-   if (e_comp_input_key->kbd.enabled)
+   if (e_seat_keyboard_enabled_get(NULL))
      focus = e_comp_input_key->kbd.focus;
 
    if (focus)
@@ -842,7 +842,7 @@ _e_comp_wl_data_device_selection_set(E_Comp_Wl_Data *comp_wl, E_Comp_Wl_Data_Sou
    comp_wl->clipboard.xwl_owner = NULL;
    comp_wl->selection.serial = serial;
 
-   if (e_comp_input_key->kbd.enabled)
+   if (e_seat_keyboard_enabled_get(NULL))
      focus = e_comp_input_key->kbd.focus;
 
    //if source is from cbhm_client do not create data offer for cbhm
@@ -1564,7 +1564,7 @@ e_comp_wl_data_device_keyboard_focus_set(void)
    E_Comp_Wl_Data_Source *source;
    E_Comp_Wl_Data *comp_wl;
 
-   if (!e_comp_input_key->kbd.enabled)
+   if (e_seat_keyboard_enabled_get(NULL))
      {
         ERR("Keyboard not enabled");
         return;
index f21a2b93f9bde067653de3ad6d147ad805cd0041..5eec7e084f345990f36968584eec4385a71178b4 100644 (file)
@@ -1336,32 +1336,6 @@ e_comp_wl_input_keyboard_state_update(uint32_t keycode, Eina_Bool pressed)
    e_comp_wl_input_keyboard_modifiers_update();
 }
 
-static void
-_e_comp_wl_input_thread_cb_keyboard_enabled_set(void *data)
-{
-   Eina_Bool enabled;
-   EINA_SAFETY_ON_NULL_RETURN(data);
-
-   enabled = *(Eina_Bool *)data;
-
-   e_comp_input_key->kbd.enabled = !!enabled;
-}
-
-EINTERN void
-e_comp_wl_input_keyboard_enabled_set(Eina_Bool enabled)
-{
-   E_Comp_Wl_Data *comp_wl = e_comp_wl_get();
-   /* check for valid compositor data */
-   if (!comp_wl)
-     {
-        ERR("No compositor data");
-        return;
-     }
-
-   e_input_backend_thread_safe_call(_e_comp_wl_input_thread_cb_keyboard_enabled_set, &enabled, sizeof(Eina_Bool));
-   e_seat_update_seat_caps(NULL, NULL);
-}
-
 E_API Eina_Bool
 e_comp_wl_input_keymap_cache_file_use_get(void)
 {
@@ -1631,7 +1605,10 @@ e_comp_wl_input_seat_caps_set(unsigned int caps)
      }
 
    if (caps & E_INPUT_SEAT_KEYBOARD)
-     e_comp_input_key->kbd.enabled = need_update = EINA_TRUE;
+     {
+        need_update = EINA_TRUE;
+        e_seat_keyboard_enabled_set(seat, need_update);
+     }
 
    if (caps & E_INPUT_SEAT_TOUCH)
      {
index ff84d48a9906c4c9d2965390974d0d7c607639ac..5fe4f4596bf2a30f011697cb6955d1348223ec0d 100644 (file)
@@ -31,6 +31,11 @@ struct _E_Seat
         unsigned int num_devices;
      } touch;
 
+     struct
+     {
+        Eina_Bool enabled : 1;
+        unsigned int num_devices;
+     } kbd;
    E_Zone *zone;
 };
 
@@ -644,7 +649,7 @@ e_seat_update_seat_caps(E_Seat *seat, struct wl_client *wc)
 
    if (seat->ptr.enabled)
      caps |= WL_SEAT_CAPABILITY_POINTER;
-   if (e_comp_input_key->kbd.enabled)
+   if (seat->kbd.enabled)
      caps |= WL_SEAT_CAPABILITY_KEYBOARD;
    if (seat->touch.enabled)
      caps |= WL_SEAT_CAPABILITY_TOUCH;
@@ -1007,6 +1012,46 @@ e_seat_pointer_device_count_decrease(E_Seat *seat)
    seat->ptr.num_devices--;
 }
 
+EINTERN void
+e_seat_keyboard_enabled_set(E_Seat *seat, Eina_Bool enabled)
+{
+   if (!seat) return;
+
+   seat->kbd.enabled = !!enabled;
+   e_seat_update_seat_caps(seat, NULL);
+}
+
+EINTERN Eina_Bool
+e_seat_keyboard_enabled_get(E_Seat *seat)
+{
+   E_Seat *s;
+
+   if (!seat) s = _current_seat;
+   else s = seat;
+
+   if (s->kbd.enabled) return EINA_TRUE;
+
+   return EINA_FALSE;
+}
+
+EINTERN unsigned int
+e_seat_keyboard_device_count(E_Seat *seat)
+{
+   return seat->kbd.num_devices;
+}
+
+EINTERN void
+e_seat_keyboard_device_count_increase(E_Seat *seat)
+{
+   seat->kbd.num_devices++;
+}
+
+EINTERN void
+e_seat_keyboard_device_count_decrease(E_Seat *seat)
+{
+   seat->kbd.num_devices--;
+}
+
 EINTERN Eina_Bool
 e_seat_keyboard_check(struct wl_resource *res)
 {
index d5655a1abf3420c04c3a2933efac0af6be62175e..97b4d46c61c9b9cd8743d85139de0d0d6c65419e 100644 (file)
@@ -58,7 +58,12 @@ EINTERN unsigned int e_seat_pointer_device_count(E_Seat *seat);
 EINTERN void        e_seat_pointer_device_count_increase(E_Seat *seat);
 EINTERN void        e_seat_pointer_device_count_decrease(E_Seat *seat);
 
+EINTERN void        e_seat_keyboard_enabled_set(E_Seat *seat, Eina_Bool enabled);
+EINTERN Eina_Bool   e_seat_keyboard_enabled_get(E_Seat *seat);
 EINTERN Eina_Bool   e_seat_keyboard_check(struct wl_resource *res);
+EINTERN unsigned int e_seat_keyboard_device_count(E_Seat *seat);
+EINTERN void        e_seat_keyboard_device_count_increase(E_Seat *seat);
+EINTERN void        e_seat_keyboard_device_count_decrease(E_Seat *seat);
 
 EINTERN Eina_List  *e_seat_resources_get(E_Seat *seat);
 EINTERN void        e_seat_current_set(E_Seat *seat);