From debf5e10ce712784775a22043b6ba48221f7f837 Mon Sep 17 00:00:00 2001 From: Doyoun Kang Date: Wed, 29 Mar 2023 17:25:01 +0900 Subject: [PATCH] support the set_auto_placement request of the tizen_launch_appinfo 1. change version of tizen_launch_appinfo to 2 2. implement callback function for set_auto_placement of tizen_launch_appinfo 3. add E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT intercept hook Change-Id: I7a007e403337af41873b1c2205939098d41cf6d4 --- src/bin/e_appinfo.c | 17 +++++++ src/bin/e_appinfo.h | 2 + src/bin/e_client.c | 132 +++++++++++++++++++++++++++++++------------------- src/bin/e_client.h | 1 + src/bin/e_policy_wl.c | 26 +++++++++- 5 files changed, 126 insertions(+), 52 deletions(-) diff --git a/src/bin/e_appinfo.c b/src/bin/e_appinfo.c index 928c125..58aaa0c 100644 --- a/src/bin/e_appinfo.c +++ b/src/bin/e_appinfo.c @@ -21,6 +21,7 @@ struct _E_Appinfo int base_output_width; int base_output_height; E_Appinfo_Owner owner; + Eina_Bool use_auto_placement; }; static void @@ -235,6 +236,22 @@ e_appinfo_owner_set(E_Appinfo *eai, E_Appinfo_Owner owner) eai->owner = owner; } +EINTERN Eina_Bool +e_appinfo_auto_placement_get(E_Appinfo *eai) +{ + if (!eai) return EINA_FALSE; + + return eai->use_auto_placement; +} + +EINTERN void +e_appinfo_auto_placement_set(E_Appinfo *eai, Eina_Bool set) +{ + EINA_SAFETY_ON_NULL_RETURN(eai); + + eai->use_auto_placement = set; +} + E_API E_Appinfo * e_appinfo_find_with_pid(pid_t pid) { diff --git a/src/bin/e_appinfo.h b/src/bin/e_appinfo.h index 2a6d035..afaa94d 100644 --- a/src/bin/e_appinfo.h +++ b/src/bin/e_appinfo.h @@ -39,6 +39,8 @@ EINTERN void e_appinfo_ready_metadata(E_Appinfo *eai, pid_t pid) EINTERN Eina_Bool e_appinfo_base_output_resolution_get(E_Appinfo *eai, int *width, int *height); EINTERN E_Appinfo_Owner e_appinfo_owner_get(E_Appinfo *eai); EINTERN void e_appinfo_owner_set(E_Appinfo *eai, E_Appinfo_Owner owner); +EINTERN Eina_Bool e_appinfo_auto_placement_get(E_Appinfo *eai); +EINTERN void e_appinfo_auto_placement_set(E_Appinfo *eai, Eina_Bool set); E_API E_Appinfo *e_appinfo_find_with_pid(pid_t pid); E_API E_Appinfo *e_appinfo_find_with_appid(const char *appid); diff --git a/src/bin/e_client.c b/src/bin/e_client.c index 7b812de..15ab425 100644 --- a/src/bin/e_client.c +++ b/src/bin/e_client.c @@ -120,6 +120,7 @@ static Eina_Inlist *_e_client_hooks[] = static Eina_Inlist *_e_client_intercept_hooks[] = { [E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT] = NULL, + [E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT] = NULL, }; /////////////////////////////////////////// @@ -2902,6 +2903,76 @@ _e_client_aux_hint_eval(E_Client *ec) } static void +_e_client_apply_auto_placement(E_Client *ec) +{ + Eina_List *skiplist = NULL; + int new_x, new_y, t = 0; + int type; + E_Client *parent_ec; + + // intercept auto placement policy + if (!_e_client_intercept_hook_call(E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, ec)) + { + ELOGF("POL", "Intercepted auto_placement policy.", ec); + return; + } + + int zx = 0, zy = 0, zw = 0, zh = 0; + e_zone_useful_geometry_get(ec->zone, &zx, &zy, &zw, &zh); + + if (zw > ec->w) + new_x = zx + (rand() % (zw - ec->w)); + else + new_x = zx; + if (zh > ec->h) + new_y = zy + (rand() % (zh - ec->h)); + else + new_y = zy; + + e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL); + + parent_ec = ec->parent; + if (parent_ec) + { + type = 1; + new_x = parent_ec->x; + new_y = parent_ec->y; + } + else if ((e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART) || (e_config->window_placement_policy == E_WINDOW_PLACEMENT_ANTIGADGET)) + { + type = 2; + skiplist = eina_list_append(skiplist, ec); + if (ec->desk) + e_place_desk_region_smart(ec->desk, skiplist, + ec->x, ec->y, ec->w, ec->h, + &new_x, &new_y); + else + e_place_zone_region_smart(ec->zone, skiplist, + ec->x, ec->y, ec->w, ec->h, + &new_x, &new_y); + + eina_list_free(skiplist); + } + else if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) + { + type = 3; + e_place_zone_manual(ec->zone, ec->w, t, &new_x, &new_y); + } + else + { + type = 0; + e_place_zone_cursor(ec->zone, ec->x, ec->y, ec->w, ec->h, + t, &new_x, &new_y); + } + + ELOGF("POL", "Apply auto placement (type:%d). (%d,%d) -> (%d,%d).", ec, type, ec->x, ec->y, new_x, new_y); + e_client_pos_set(ec, new_x, new_y); + ec->changes.pos = 1; + ec->placed = 1; + ec->pre_cb.x = ec->x; ec->pre_cb.y = ec->y; +} + +static void _e_client_eval(E_Client *ec) { int send_event = 1; @@ -3033,58 +3104,17 @@ _e_client_eval(E_Client *ec) } } - if (!ec->placed) + E_Appinfo *eai; + eai = e_appinfo_find_with_pid(ec->netwm.pid); + if (!eai) { - Eina_List *skiplist = NULL; - int new_x, new_y, t = 0; - E_Client *trans_ec = NULL; - - if (zw > ec->w) - new_x = zx + (rand() % (zw - ec->w)); - else - new_x = zx; - if (zh > ec->h) - new_y = zy + (rand() % (zh - ec->h)); - else - new_y = zy; - - e_comp_object_frame_geometry_get(ec->frame, NULL, NULL, &t, NULL); - - if (ec->icccm.transient_for) - trans_ec = e_pixmap_find_client(E_PIXMAP_TYPE_X, ec->icccm.transient_for); - if (trans_ec) - { - // if transient for a window and not placed, center on - // transient parent if found - new_x = trans_ec->x + ((trans_ec->w - ec->w) / 2); - new_y = trans_ec->y + ((trans_ec->h - ec->h) / 2); - } - else if ((e_config->window_placement_policy == E_WINDOW_PLACEMENT_SMART) || (e_config->window_placement_policy == E_WINDOW_PLACEMENT_ANTIGADGET)) - { - skiplist = eina_list_append(skiplist, ec); - if (ec->desk) - e_place_desk_region_smart(ec->desk, skiplist, - ec->x, ec->y, ec->w, ec->h, - &new_x, &new_y); - else - e_place_zone_region_smart(ec->zone, skiplist, - ec->x, ec->y, ec->w, ec->h, - &new_x, &new_y); - eina_list_free(skiplist); - } - else if (e_config->window_placement_policy == E_WINDOW_PLACEMENT_MANUAL) - { - e_place_zone_manual(ec->zone, ec->w, t, &new_x, &new_y); - } - else - { - e_place_zone_cursor(ec->zone, ec->x, ec->y, ec->w, ec->h, - t, &new_x, &new_y); - } - e_client_pos_set(ec, new_x, new_y); - ec->changes.pos = 1; - ec->placed = 1; - ec->pre_cb.x = ec->x; ec->pre_cb.y = ec->y; + if (!ec->placed) + _e_client_apply_auto_placement(ec); + } + else + { + if (e_appinfo_auto_placement_get(eai)) + _e_client_apply_auto_placement(ec); } /* Recreate state */ diff --git a/src/bin/e_client.h b/src/bin/e_client.h index 3a851ec..4a35fa6 100644 --- a/src/bin/e_client.h +++ b/src/bin/e_client.h @@ -277,6 +277,7 @@ typedef enum _E_Client_Hook_Point typedef enum _E_Client_Intercept_Hook_Point { E_CLIENT_INTERCEPT_HOOK_FOCUS_REVERT, + E_CLIENT_INTERCEPT_HOOK_AUTO_PLACEMENT, E_CLIENT_INTERCEPT_HOOK_LAST, } E_Client_Intercept_Hook_Point; diff --git a/src/bin/e_policy_wl.c b/src/bin/e_policy_wl.c index 2697a3b..3ba78ce 100644 --- a/src/bin/e_policy_wl.c +++ b/src/bin/e_policy_wl.c @@ -7312,6 +7312,29 @@ _tzlaunch_appinfo_iface_cb_ready_metadata(struct wl_client *client, struct wl_re } } +static void +_tzlaunch_appinfo_iface_cb_set_auto_placement(struct wl_client *client, struct wl_resource *res_tzlaunch_appinfo, + uint32_t pid) +{ + E_Policy_Wl_Tzlaunch_Appinfo *tzlaunch_appinfo = NULL; + E_Appinfo *eai = NULL; + + tzlaunch_appinfo = wl_resource_get_user_data(res_tzlaunch_appinfo); + if (!tzlaunch_appinfo) + { + wl_resource_post_error(res_tzlaunch_appinfo, + WL_DISPLAY_ERROR_INVALID_OBJECT, + "Invalid tzlaunch_appinfo's user data"); + return; + } + + eai = e_appinfo_find_with_pid(pid); + EINA_SAFETY_ON_NULL_RETURN(eai); + + ELOGF("TZ_APPINFO", "Set auto placement. pid(%d)", NULL, pid); + e_appinfo_auto_placement_set(eai, EINA_TRUE); +} + static const struct tizen_launch_appinfo_interface _tzlaunch_appinfo_iface = { _tzlaunch_appinfo_iface_cb_destroy, @@ -7323,6 +7346,7 @@ static const struct tizen_launch_appinfo_interface _tzlaunch_appinfo_iface = _tzlaunch_appinfo_iface_cb_deregister_appid, _tzlaunch_appinfo_iface_cb_set_pid, _tzlaunch_appinfo_iface_cb_ready_metadata, + _tzlaunch_appinfo_iface_cb_set_auto_placement, }; static void @@ -8266,7 +8290,7 @@ e_policy_wl_defer_job(void) global = wl_global_create(e_comp_wl->wl.disp, &tizen_launch_appinfo_interface, - 1, + 2, NULL, _tzlaunch_appinfo_cb_bind); EINA_SAFETY_ON_NULL_GOTO(global, err); -- 2.7.4