e_keyrouter: reduce duplicated code for printing keygrab status 12/325012/1
authorJihoon Kim <jihoon48.kim@samsung.com>
Thu, 29 May 2025 11:36:39 +0000 (20:36 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 30 May 2025 09:17:36 +0000 (18:17 +0900)
Change-Id: I8f1c682f39ca50539fe6700273f87780b861fb02
Signed-off-by: Jihoon Kim <jihoon48.kim@samsung.com>
src/bin/inputmgr/e_keyrouter.c

index d0ef396fc74764fcc6e2468e0932aee2487cec4a..6d00d29428bca6247f5614e031408d9081fdccdd 100644 (file)
@@ -33,6 +33,18 @@ static Eina_Inlist *_e_keyrouter_intercept_hooks[] =
    [E_KEYROUTER_INTERCEPT_HOOK_DELIVER_FOCUS] = NULL,
 };
 
+struct _keygrab_mode {
+   uint32_t keygrab_mode;
+   const char *description;
+};
+
+static struct _keygrab_mode _keygrab_mode_list[] = {
+   { TIZEN_KEYROUTER_MODE_EXCLUSIVE, "== Exclusive Grab ==" },
+   { TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE, "== Overridable Exclusive Grab ==" },
+   { TIZEN_KEYROUTER_MODE_TOPMOST, "== Top Position Grab ==" },
+   { TIZEN_KEYROUTER_MODE_SHARED, "== Shared Grab ==" }
+};
+
 int _keyrouter_log_dom = -1;
 
 E_API E_Keyrouter_Info e_keyrouter;
@@ -171,13 +183,12 @@ static void
 _e_keyrouter_input_thread_keygrab_print(void *data)
 {
    char *log_path = (char *)data;
-   Eina_List *l, *excl_ptr_list, *or_excl_ptr_list, *top_ptr_list, *shared_ptr_list;
-   E_Keyrouter_Key_List_NodePtr kdata;
+   Eina_List *keygrab_list = NULL;
    E_Client *ec_focus;
    struct wl_resource *surface_focus;
    struct wl_client *wc_focus;
-   int pid_focus, pid, i;
-   char *cmd_focus, *cmd, *keyname;
+   int pid_focus, i;
+   char *cmd_focus, *keyname;
    FILE *log_fl;
 
    log_fl = fopen(log_path, "a");
@@ -237,49 +248,15 @@ _e_keyrouter_input_thread_keygrab_print(void *data)
         free(keyname);
         keyname = NULL;
 
-        excl_ptr_list = e_keyrouter_hardkeys_list_get(krt->HardKeys, i, TIZEN_KEYROUTER_MODE_EXCLUSIVE);
-        if (excl_ptr_list)
-          {
-             fprintf(log_fl, "            == Exclusive Grab ==\n");
-             EINA_LIST_FOREACH(excl_ptr_list, l, kdata)
-               {
-                  pid = e_keyrouter_util_get_pid(kdata->wc, kdata->surface);
-                  cmd = e_keyrouter_util_cmd_get_from_pid(pid);
-                  fprintf(log_fl, "                [surface: %p, client: %p, pid: %d(%s)]\n", kdata->surface, kdata->wc, pid, cmd ?: "Unknown");
-                  if(cmd) E_FREE(cmd);
-                  if (kdata->surface)
-                    {
-                       fprintf(log_fl, "                    -- Surface Information --\n");
-                       fprintf(log_fl, "                        = wl_client: %p\n", wl_resource_get_client(kdata->surface));
-                       fprintf(log_fl, "                        = resource: %s(%d)\n", wl_resource_get_class(kdata->surface), wl_resource_get_id(kdata->surface));
-                    }
-                  else
-                    {
-                       fprintf(log_fl, "                    -- Client Information --\n");
-                       fprintf(log_fl, "                        = connected fd: %d\n", wl_client_get_fd(kdata->wc));
-                    }
-               }
-            }
-
-        or_excl_ptr_list = e_keyrouter_hardkeys_list_get(krt->HardKeys, i, TIZEN_KEYROUTER_MODE_OVERRIDABLE_EXCLUSIVE);
-        if (or_excl_ptr_list)
+        for (unsigned int keyrouter_mode_idx = 0;
+             keyrouter_mode_idx < (sizeof(_keygrab_mode_list) / sizeof(_keygrab_mode_list[0]));
+             keyrouter_mode_idx++)
           {
-             fprintf(log_fl, "            == Overidable Exclusive Grab ==\n");
-             _e_keyrouter_keygrab_status_print(log_fl, or_excl_ptr_list);
-          }
+             keygrab_list = e_keyrouter_hardkeys_list_get(krt->HardKeys, i, _keygrab_mode_list[keyrouter_mode_idx].keygrab_mode);
+             if (!keygrab_list) continue;
 
-        top_ptr_list = e_keyrouter_hardkeys_list_get(krt->HardKeys, i, TIZEN_KEYROUTER_MODE_TOPMOST);
-        if (top_ptr_list)
-          {
-             fprintf(log_fl, "            == Top Position Grab ==\n");
-             _e_keyrouter_keygrab_status_print(log_fl, top_ptr_list);
-          }
-
-        shared_ptr_list = e_keyrouter_hardkeys_list_get(krt->HardKeys, i, TIZEN_KEYROUTER_MODE_SHARED);
-        if (shared_ptr_list)
-          {
-             fprintf(log_fl, "            == Shared Grab ==\n");
-             _e_keyrouter_keygrab_status_print(log_fl, shared_ptr_list);
+             fprintf(log_fl, "            %s\n", _keygrab_mode_list[keyrouter_mode_idx].description);
+             _e_keyrouter_keygrab_status_print(log_fl, keygrab_list);
           }
 
         fprintf(log_fl, "\n");