proc-monitor: Modify variable type and function to parse window info 03/298703/3
authorUnsung Lee <unsung.lee@samsung.com>
Fri, 8 Sep 2023 01:56:49 +0000 (10:56 +0900)
committerUnsung Lee <unsung.lee@samsung.com>
Wed, 13 Sep 2023 06:09:16 +0000 (15:09 +0900)
Modify variable type and function to parse an array of windows received
from the window system. This is fundamentally to solve the issue while
parsing window info.

In gvariant, i and b are gint32 and gboolean, whereas previously
int and bool types were used respectively.

In addition, g_variant_iter_next() is definitely preferred over
g_variant_iter_loop() when parsing simple type such as integer and string within a loop.

Change-Id: If19b9199f9bdd4a0a32518f9a400dbf9423ff410
Signed-off-by: Unsung Lee <unsung.lee@samsung.com>
src/process/proc-monitor.c

index d45dfc7..cdfb7ed 100644 (file)
@@ -178,6 +178,50 @@ static void free_window_stack(GVariantIter *iter, GVariant *reply,
                g_hash_table_remove_all(window_table);
 }
 
+static gboolean get_window_info_from_window_stack_dbus(GVariantIter *iter,
+               struct proc_app_window_info *window, gchar **name)
+{
+       gint32 pid;
+       gint32 x;
+       gint32 y;
+       gint32 w;
+       gint32 h;
+       gint32 layer;
+       gint32 opaque;
+       gint32 visibility;
+       gboolean is_transformed;
+       gboolean alpha;
+       gboolean is_focused;
+       gboolean is_mapped;
+       gboolean ret;
+
+       assert(window);
+       assert(name);
+
+       ret = g_variant_iter_next(iter, "("VISIBLE_WINDOW_INFO_V2_VALUE_TYPE")",
+                               &pid, &x, &y, &w, &h, &is_transformed, &alpha,
+                               &opaque, &visibility, &is_focused,
+                               &is_mapped, &layer, name);
+
+       if (!ret)
+               return ret;
+
+       window->pid = (int)pid;
+       window->x = (int)x;
+       window->y = (int)y;
+       window->w = (int)w;
+       window->h = (int)h;
+       window->is_transformed = (bool)is_transformed;
+       window->alpha = (bool)alpha;
+       window->opaque = (int)opaque;
+       window->visibility = (int)visibility;
+       window->is_focused = (bool)is_focused;
+       window->is_mapped = (bool)is_mapped;
+       window->layer = (int)layer;
+
+       return ret;
+}
+
 static int dbus_update_window_stack(pid_t pid, bool has_focus)
 {
        static GHashTable *window_table = NULL;
@@ -218,13 +262,9 @@ static int dbus_update_window_stack(pid_t pid, bool has_focus)
        if (pid == 0)
                is_valid_window_stack = true;
 
-       while (g_variant_iter_loop(iter, "("VISIBLE_WINDOW_INFO_V2_VALUE_TYPE")",
-                               &window.pid, &window.x, &window.y, &window.w, &window.h,
-                               &window.is_transformed, &window.alpha, &window.opaque,
-                               &window.visibility, &window.is_focused,
-                               &window.is_mapped, &window.layer, &name)) {
-               ++z;
-               window.z = z;
+       while (1) {
+               if (!get_window_info_from_window_stack_dbus(iter, &window, &name))
+                       break;
 
                if (!name) {
                        is_valid_window_stack = false;
@@ -236,6 +276,9 @@ static int dbus_update_window_stack(pid_t pid, bool has_focus)
                        break;
                }
 
+               ++z;
+               window.z = z;
+
                /**
                 * A process (same pid) can have more than one window,
                 * so Although current window's focus information is different