e_keyrouter_wl: simplify code in e_keyrouter_wl_key_send() 04/324404/1
authorduna.oh <duna.oh@samsung.com>
Thu, 15 May 2025 11:42:41 +0000 (20:42 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 16 May 2025 09:02:35 +0000 (18:02 +0900)
Change-Id: I22c6fb403c9399d227d237ffa4d58acc2c754e70

src/bin/server/e_keyrouter_wl.c

index 96e2e1522e261b382adfa51c2e9ee0c4c3c6f332..c1fe88b8e4a6bceae9f08f87825ce0d83e4715a2 100644 (file)
@@ -82,13 +82,11 @@ e_keyrouter_wl_event_surface_send(struct wl_resource *surface, int key, int mode
 }
 
 static void
-_e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_state state, Eina_List *key_list, Eina_Bool focused, struct wl_client *client, struct wl_resource *surface)
+_e_keyrouter_wl_key_send_to_resource_list(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_state state, struct wl_client *client, struct wl_resource *surface)
 {
    struct wl_resource *res;
    Eina_List *l;
    uint32_t serial, keycode;
-   struct wl_client *wc;
-   E_Comp_Config *comp_conf = NULL;
    E_Comp_Wl_Data *comp_wl;
 
    keycode = (ev->keycode - 8);
@@ -96,9 +94,7 @@ _e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_ke
    comp_wl = e_comp_wl_get();
    serial = wl_display_next_serial(comp_wl->wl.disp);
 
-   comp_conf = e_comp_config_get();
-
-   if (surface && !focused)
+   if (surface)
      {
         e_input_thread_request_boost();
         e_keyrouter_wl_event_surface_send(surface, ev->keycode, TIZEN_KEYROUTER_MODE_NONE);
@@ -120,19 +116,64 @@ _e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_ke
           e_comp_wl_send_event_e_device(client, ev->timestamp, dev, serial);
      }
 
-   EINA_LIST_FOREACH(key_list, l, res)
+   g_rec_mutex_lock(&e_comp_input_key->kbd.resources_mutex);
+   EINA_LIST_FOREACH(e_comp_input_key->kbd.resources, l, res)
+     {
+        if (wl_resource_get_client(res) != client) continue;
+        TRACE_INPUT_BEGIN(_e_keyrouter_wl_key_send);
+        wl_keyboard_send_key(res, serial, ev->timestamp,
+                             keycode, state);
+        TRACE_INPUT_END();
+     }
+   g_rec_mutex_unlock(&e_comp_input_key->kbd.resources_mutex);
+
+   if (e_config->key_input_ttrace_enable)
+     {
+        TRACE_INPUT_END();
+        ELOGF("INPUT", "wl_keyboard_send_key|E|", NULL);
+     }
+}
+
+static void
+_e_keyrouter_wl_key_send_to_focused_list(Ecore_Event_Key *ev, E_Device *dev, enum wl_keyboard_key_state state)
+{
+   struct wl_resource *res;
+   Eina_List *l;
+   uint32_t serial, keycode;
+   struct wl_client *wc;
+   E_Comp_Wl_Data *comp_wl;
+
+   keycode = (ev->keycode - 8);
+
+   comp_wl = e_comp_wl_get();
+   serial = wl_display_next_serial(comp_wl->wl.disp);
+
+   if (e_config->key_input_ttrace_enable)
+     {
+        TRACE_INPUT_BEGIN(wl_keyboard_send_key:%s:%s, (state ? "PRESS" : "RELEASE"), ev->keyname);
+        ELOGF("INPUT", "wl_keyboard_send_key:%s:%s|B|", NULL, (state ? "PRESS" : "RELEASE"), ev->keyname);
+     }
+
+   g_rec_mutex_lock(&e_comp_input_key->kbd.focused_mutex);
+   EINA_LIST_FOREACH(e_comp_input_key->kbd.focused, l, res)
      {
         wc = wl_resource_get_client(res);
-        if (!focused && wc != client) continue;
+        if (!e_input_thread_mode_get())
+          {
+             e_comp_wl_send_event_device(wc, ev->timestamp, ev->dev, serial);
+          }
+        else
+          {
+             if (dev)
+               e_comp_wl_send_event_e_device(wc, ev->timestamp, dev, serial);
+          }
 
         TRACE_INPUT_BEGIN(_e_keyrouter_wl_key_send);
-        if (comp_conf && comp_conf->input_log_enable)
-          INF("[Server] Routed Key %s (time: %d)\n", (state ? "Down" : "Up"), ev->timestamp);
-
         wl_keyboard_send_key(res, serial, ev->timestamp,
                              keycode, state);
         TRACE_INPUT_END();
      }
+   g_rec_mutex_unlock(&e_comp_input_key->kbd.focused_mutex);
 
    if (e_config->key_input_ttrace_enable)
      {
@@ -146,12 +187,12 @@ e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, Eina_Bool pressed, s
 {
    E_Comp *comp;
    E_Client *ec = NULL;
-   struct wl_client *wc = NULL;
    uint32_t keycode;
    enum wl_keyboard_key_state state;
    const char *seat_name = NULL;
    E_Seat *seat;
    E_Zone *zone = NULL;
+   E_Comp_Config *comp_conf = NULL;
 
    if (ev->window != e_comp_ee_win_get())
      {
@@ -174,11 +215,13 @@ e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, Eina_Bool pressed, s
    if (pressed) state = WL_KEYBOARD_KEY_STATE_PRESSED;
    else state = WL_KEYBOARD_KEY_STATE_RELEASED;
 
+   comp_conf = e_comp_config_get();
+   if (comp_conf && comp_conf->input_log_enable)
+     INF("[Server] Routed Key %s (time: %d)\n", (state ? "Down" : "Up"), ev->timestamp);
+
    if (!focused)
      {
-        g_rec_mutex_lock(&e_comp_input_key->kbd.resources_mutex);
-        _e_keyrouter_wl_key_send(ev, dev, state, e_comp_input_key->kbd.resources, EINA_FALSE, client, surface);
-        g_rec_mutex_unlock(&e_comp_input_key->kbd.resources_mutex);
+        _e_keyrouter_wl_key_send_to_resource_list(ev, dev, state, client, surface);
         return EINA_FALSE;
      }
 
@@ -194,23 +237,17 @@ e_keyrouter_wl_key_send(Ecore_Event_Key *ev, E_Device *dev, Eina_Bool pressed, s
         ec = e_zone_focused_client_get(zone);
         ELOGF("KRT", "Key Send. seat:%s zone_id:%d", ec, seat_name, e_zone_id_get(zone));
 
-        if (ec && ec->comp_data)
+        g_rec_mutex_lock(&e_comp_input_key->kbd.focused_mutex);
+        if (!e_comp_input_key->kbd.focused)
           {
-             struct wl_resource *surface = e_comp_wl_client_surface_get(ec);
-             if (surface)
-               {
-                  g_rec_mutex_lock(&e_comp_input_key->kbd.focused_mutex);
-                  if (e_comp_input_key->kbd.focused)
-                    {
-                       wc = wl_resource_get_client(surface);
-                       _e_keyrouter_wl_key_send(ev, dev, state, e_comp_input_key->kbd.focused, EINA_TRUE, wc, surface);
-                    }
-                  g_rec_mutex_unlock(&e_comp_input_key->kbd.focused_mutex);
-               }
-
-             /* update modifier state */
-             e_comp_wl_input_keyboard_state_update(keycode, pressed);
+             g_rec_mutex_unlock(&e_comp_input_key->kbd.focused_mutex);
+             return EINA_FALSE;
           }
+        g_rec_mutex_unlock(&e_comp_input_key->kbd.focused_mutex);
+        _e_keyrouter_wl_key_send_to_focused_list(ev, dev, state);
+
+        /* update modifier state */
+        e_comp_wl_input_keyboard_state_update(keycode, pressed);
      }
    return !!ec;
 }