[ui-core] Support adjusting the position of the window 88/262588/2
authorHwankyu Jhun <h.jhun@samsung.com>
Fri, 13 Aug 2021 11:56:26 +0000 (20:56 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 26 Aug 2021 01:59:58 +0000 (01:59 +0000)
Change-Id: I85d76260dddd0c9d3abfbd03234810ef02378e97
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
src/modules/ui-core/src/app_group.c

index 224327b168198f3c93b5cfa4b5ff89601597b1bc..3a5b2abb8b795dc6a5b344c7651aa8e257ada3bb 100644 (file)
@@ -71,6 +71,7 @@ struct app_group_context_s {
        bool reroute;
        bool can_shift;
        bool recycle;
+       bool attach_below;
 };
 
 struct launch_context_s {
@@ -349,6 +350,17 @@ const char *_app_group_node_get_id(app_group_node_h node)
        return NULL;
 }
 
+static void __attach_window(int parent_wid, struct app_group_context_s *ctx)
+{
+       if (ctx->wid == 0)
+               return;
+
+       if (ctx->attach_below)
+               _app_group_wayland_attach_window_below(parent_wid, ctx->wid);
+       else
+               _app_group_wayland_attach_window(parent_wid, ctx->wid);
+}
+
 int _app_group_node_set_window(app_group_node_h node, int wid)
 {
        struct app_group_context_s *ctx;
@@ -357,6 +369,8 @@ int _app_group_node_set_window(app_group_node_h node, int wid)
        int caller_wid;
        app_group_node_h caller_node;
        amd_comp_status_h comp = NULL;
+       app_group_node_h next_node;
+       struct app_group_context_s *next_ctx;
 
        if (!node) {
                _E("Invalid parameter");
@@ -374,18 +388,21 @@ int _app_group_node_set_window(app_group_node_h node, int wid)
 
        prev_wid = _app_group_node_get_window(g_list_previous(node));
        if (prev_wid != 0)
-               _app_group_wayland_attach_window(prev_wid, wid);
+               __attach_window(prev_wid, ctx);
 
        if (ctx->can_shift && ctx->caller_id) {
                caller_node = _app_group_node_find(ctx->caller_id);
                caller_wid = _app_group_node_get_window(caller_node);
                if (caller_wid != 0)
-                       _app_group_wayland_attach_window(caller_wid, wid);
+                       __attach_window(caller_wid, ctx);
        }
 
-       next_wid = _app_group_node_get_window(g_list_next(node));
-       if (next_wid != 0)
-               _app_group_wayland_attach_window(wid, next_wid);
+       next_node = g_list_next(node);
+       next_wid = _app_group_node_get_window(next_node);
+       if (next_wid != 0) {
+               next_ctx = (struct app_group_context_s *)next_node->data;
+               __attach_window(wid, next_ctx);
+       }
 
        return 0;
 }
@@ -704,17 +721,21 @@ static void __app_group_node_reroute(app_group_node_h node)
 {
        int prev_wid;
        int next_wid;
+       app_group_node_h next_node;
+       struct app_group_context_s *next_ctx;
 
        prev_wid = _app_group_node_get_window(g_list_previous(node));
        if (!prev_wid)
                return;
 
-       next_wid = _app_group_node_get_window(g_list_next(node));
+       next_node = g_list_next(node);
+       next_wid = _app_group_node_get_window(next_node);
        if (!next_wid)
                return;
 
        _D("Reroute");
-       _app_group_wayland_attach_window(prev_wid, next_wid);
+       next_ctx = (struct app_group_context_s *)next_node->data;
+       __attach_window(prev_wid, next_ctx);
 }
 
 static bool __app_group_node_is_sub(app_group_node_h node)
@@ -811,7 +832,7 @@ static struct app_group_context_s *__app_group_add(
                pid_t caller_pid, const char *caller_id,
                app_group_launch_mode_e launch_mode,
                bool can_shift, bool recycle,
-               int before_wid)
+               int before_wid, bool attach_below)
 {
        struct app_group_context_s *ctx;
        app_group_h group;
@@ -839,6 +860,7 @@ static struct app_group_context_s *__app_group_add(
                else
                        ctx->group_sig = false;
        }
+       ctx->attach_below = attach_below;
 
        found = g_list_find_custom(__app_group_list, leader_id,
                        __compare_group_id);
@@ -910,6 +932,9 @@ static void __app_group_start(pid_t leader_pid, const char *leader_id,
        pid_t caller_pid;
        struct app_group_context_s *ctx;
        int before_wid = 0;
+       bool attach_below = false;
+       app_group_node_h caller_node;
+       app_group_node_h next_node;
 
        _D("app_group_start");
 
@@ -930,14 +955,25 @@ static void __app_group_start(pid_t leader_pid, const char *leader_id,
        if (str && isdigit(str[0]))
                before_wid = atoi(str);
 
+       str = bundle_get_val(b, "__K_ATTACH_BELOW");
+       if (str && !strcmp(str, "true"))
+               attach_below = true;
+
+       str = bundle_get_val(b, "__K_INSERT_AFTER_CALLER");
+       if (str && !strcmp(str, "true")) {
+               caller_node = _app_group_node_find(caller_id);
+               next_node = g_list_next(caller_node);
+               before_wid = _app_group_node_get_window(next_node);
+       }
+
        if (can_attach) {
                ctx = __app_group_add(leader_pid, leader_id, pid, id,
                                caller_pid, caller_id, launch_mode,
-                               false, recycle, before_wid);
+                               false, recycle, before_wid, attach_below);
        } else {
                ctx = __app_group_add(pid, id, pid, id,
                                caller_pid, caller_id, launch_mode,
-                               can_shift, false, before_wid);
+                               can_shift, false, before_wid, attach_below);
        }
        __set_hint(ctx, b);
 }
@@ -1004,6 +1040,41 @@ void _app_group_node_lower(app_group_node_h node, bool *exit)
        }
 }
 
+static void __app_group_node_insert_after_caller(app_group_node_h node,
+               struct app_group_context_s *ctx)
+{
+       app_group_node_h caller_node;
+       int caller_wid;
+       app_group_h group;
+       gint pos;
+
+       _W("node(%p), ctx(%p), ctx->caller_id(%s), ctx->wid(%d)",
+                       node, ctx, ctx->caller_id, ctx->wid);
+
+       group = _app_group_find(ctx->caller_id);
+       if (!group) {
+               _E("Failed to find app group. caller_id(%s)", ctx->caller_id);
+               return;
+       }
+
+       caller_node = _app_group_node_find(ctx->caller_id);
+       caller_wid = _app_group_node_get_window(caller_node);
+       if (caller_wid == 0)
+               return;
+
+       group->list = g_list_delete_link(group->list, node);
+       pos = __app_group_get_nth(group, caller_wid);
+       if (pos == -1)
+               group->list = g_list_append(group->list, ctx);
+       else
+               group->list = g_list_insert(group->list, ctx, pos + 1);
+
+       if (ctx->wid != 0) {
+               node = _app_group_node_find_by_wid(ctx->wid);
+               _app_group_node_set_window(node, ctx->wid);
+       }
+}
+
 static void __app_group_restart(const char *id, bundle *b)
 {
        struct app_group_context_s *ctx;
@@ -1012,6 +1083,8 @@ static void __app_group_restart(const char *id, bundle *b)
        int caller_wid;
        const char *caller_id;
        app_group_node_h caller_node;
+       const char *str;
+       bool insert_after_caller = false;
 
        if (!id || !b) {
                _E("Invalid parameter");
@@ -1019,12 +1092,16 @@ static void __app_group_restart(const char *id, bundle *b)
        }
 
        node = _app_group_node_find(id);
-       if (!node)
+       if (!node) {
+               _E("Failed to find app group node. id(%s)", id);
                return;
+       }
 
        ctx = (struct app_group_context_s *)node->data;
-       if (!ctx)
+       if (!ctx) {
+               _E("context is nullptr");
                return;
+       }
 
        ctx->caller_pid = __get_caller_pid(b);
 
@@ -1039,6 +1116,28 @@ static void __app_group_restart(const char *id, bundle *b)
 
        ctx->caller_id = strdup(caller_id ? caller_id : "NULL");
 
+       str = bundle_get_val(b, "__K_ATTACH_BELOW");
+       if (str && !strcmp(str, "true"))
+               ctx->attach_below = true;
+       else
+               ctx->attach_below = false;
+
+       str = bundle_get_val(b, "__K_INSERT_AFTER_CALLER");
+       if (str && !strcmp(str, "true"))
+               insert_after_caller = true;
+       else
+               _E("Key not found");
+
+       if (insert_after_caller) {
+               if (ctx->wid != 0) {
+                       _E("Detach window(%d)", ctx->wid);
+                       _app_group_wayland_detach_window(ctx->wid);
+               }
+
+               __app_group_node_insert_after_caller(node, ctx);
+               return;
+       }
+
        if (ctx->can_shift) {
                if (ctx->wid != 0)
                        _app_group_wayland_detach_window(ctx->wid);
@@ -1051,12 +1150,10 @@ static void __app_group_restart(const char *id, bundle *b)
                if (ctx->wid != 0) {
                        caller_node = _app_group_node_find(ctx->caller_id);
                        caller_wid = _app_group_node_get_window(caller_node);
-                       if (caller_wid != 0) {
-                               _app_group_wayland_attach_window(caller_wid,
-                                               ctx->wid);
-                       } else {
+                       if (caller_wid != 0)
+                               __attach_window(caller_wid, ctx);
+                       else
                                _E("Invalid caller window id");
-                       }
                }
        }
 }