e_server: use e_tizen_display_policy 38/317538/1
authorSooChan Lim <sc1.lim@samsung.com>
Fri, 3 Jan 2025 00:14:26 +0000 (09:14 +0900)
committerTizen Window System <tizen.windowsystem@gmail.com>
Fri, 3 Jan 2025 06:54:44 +0000 (15:54 +0900)
Use e_tizen_display_policy instead of the code in e_policy_wl.c

Change-Id: I325e28603e14f7d7fe7f6ff324da4e52858c39fc

src/bin/server/e_policy_wl.c
src/bin/server/e_policy_wl_intern.h
src/bin/windowmgr/e_policy.c
src/bin/windowmgr/e_policy_intern.h

index b301b991544fc9d3883f5aa9af441f4133d92817..dc4a14dfa0b8e31c170d9ef0ef4245c442e04b7b 100644 (file)
@@ -42,7 +42,6 @@
 #include "e_tizen_launch_effect_intern.h"
 #include "e_server_intern.h"
 
-#include <device/display.h>
 #include <wayland-server.h>
 #include <tizen-extension-server-protocol.h>
 #include <tizen-launch-server-protocol.h>
@@ -91,12 +90,6 @@ typedef struct _E_Policy_Wl_Tzpol
    Eina_Bool           bg_state;
 } E_Policy_Wl_Tzpol;
 
-typedef struct _E_Policy_Wl_Tz_Dpy_Pol
-{
-   struct wl_resource *res_tz_dpy_pol;
-   Eina_List          *dpy_surfs;  // list of E_Policy_Wl_Dpy_Surface
-} E_Policy_Wl_Tz_Dpy_Pol;
-
 typedef struct _E_Policy_Wl_Tzsh
 {
    struct wl_resource *res_tzsh; /* tizen_ws_shell_interface */
@@ -166,15 +159,6 @@ typedef struct _E_Policy_Wl_Surface
    Eina_Bool           is_background;
 } E_Policy_Wl_Surface;
 
-typedef struct _E_Policy_Wl_Dpy_Surface
-{
-   E_Policy_Wl_Tz_Dpy_Pol  *tz_dpy_pol;
-   struct wl_resource *surf;
-   E_Client           *ec;
-   Eina_Bool           set;
-   int32_t             brightness;
-} E_Policy_Wl_Dpy_Surface;
-
 typedef struct _E_Policy_Wl_Tz_Indicator
 {
    struct wl_resource *res_tz_indicator;
@@ -192,7 +176,6 @@ typedef struct _E_Policy_Wl
    Eina_List       *globals;                 /* list of wl_global */
    Eina_Hash       *tzpols;                  /* list of E_Policy_Wl_Tzpol */
 
-   Eina_List       *tz_dpy_pols;             /* list of E_Policy_Wl_Tz_Dpy_Pol */
    Eina_List       *pending_vis;             /* list of clients that have pending visibility change*/
 
    /* tizen_ws_shell_interface */
@@ -3042,321 +3025,6 @@ _tzpol_iface_cb_stack_mode_set(struct wl_client *client EINA_UNUSED, struct wl_r
      }
 }
 
-// --------------------------------------------------------
-// E_Policy_Wl_Tz_Dpy_Pol
-// --------------------------------------------------------
-static E_Policy_Wl_Tz_Dpy_Pol *
-_e_policy_wl_tz_dpy_pol_add(struct wl_resource *res_tz_dpy_pol)
-{
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-
-   tz_dpy_pol = E_NEW(E_Policy_Wl_Tz_Dpy_Pol, 1);
-   EINA_SAFETY_ON_NULL_RETURN_VAL(tz_dpy_pol, NULL);
-
-   tz_dpy_pol->res_tz_dpy_pol = res_tz_dpy_pol;
-
-   polwl->tz_dpy_pols = eina_list_append(polwl->tz_dpy_pols, tz_dpy_pol);
-
-   return tz_dpy_pol;
-}
-
-static void
-_e_policy_wl_tz_dpy_pol_del(E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol)
-{
-   E_Policy_Wl_Dpy_Surface *dpy_surf;
-
-   EINA_SAFETY_ON_NULL_RETURN(tz_dpy_pol);
-
-   polwl->tz_dpy_pols = eina_list_remove(polwl->tz_dpy_pols, tz_dpy_pol);
-
-   EINA_LIST_FREE(tz_dpy_pol->dpy_surfs, dpy_surf)
-     {
-        E_FREE(dpy_surf);
-     }
-
-   E_FREE(tz_dpy_pol);
-}
-
-static E_Policy_Wl_Tz_Dpy_Pol *
-_e_policy_wl_tz_dpy_pol_get(struct wl_resource *res_tz_dpy_pol)
-{
-   Eina_List *l;
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-
-   EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
-     {
-        if (tz_dpy_pol->res_tz_dpy_pol == res_tz_dpy_pol)
-          return tz_dpy_pol;
-     }
-
-   return NULL;
-}
-
-// --------------------------------------------------------
-// E_Policy_Wl_Dpy_Surface
-// --------------------------------------------------------
-static E_Policy_Wl_Dpy_Surface *
-_e_policy_wl_dpy_surf_find(E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol, E_Client *ec)
-{
-   Eina_List *l;
-   E_Policy_Wl_Dpy_Surface *dpy_surf;
-
-   EINA_LIST_FOREACH(tz_dpy_pol->dpy_surfs, l, dpy_surf)
-     {
-        if (dpy_surf->ec == ec)
-          return dpy_surf;
-     }
-
-   return NULL;
-}
-
-static E_Policy_Wl_Dpy_Surface *
-_e_policy_wl_dpy_surf_add(E_Client *ec, struct wl_resource *res_tz_dpy_pol)
-{
-   E_Policy_Wl_Tz_Dpy_Pol  *tz_dpy_pol = NULL;
-   E_Policy_Wl_Dpy_Surface *dpy_surf   = NULL;
-   E_Comp_Wl_Client_Data *cdata;
-
-   tz_dpy_pol = _e_policy_wl_tz_dpy_pol_get(res_tz_dpy_pol);
-   EINA_SAFETY_ON_NULL_RETURN_VAL(tz_dpy_pol, NULL);
-
-   dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
-   if (dpy_surf)
-     return dpy_surf;
-
-   dpy_surf = E_NEW(E_Policy_Wl_Dpy_Surface, 1);
-   EINA_SAFETY_ON_NULL_RETURN_VAL(dpy_surf, NULL);
-
-   cdata = e_client_cdata_get(ec);
-   dpy_surf->surf = cdata->surface;
-   dpy_surf->tz_dpy_pol = tz_dpy_pol;
-   dpy_surf->ec = ec;
-   dpy_surf->brightness = -1;
-
-   tz_dpy_pol->dpy_surfs = eina_list_append(tz_dpy_pol->dpy_surfs, dpy_surf);
-   return dpy_surf;
-}
-
-static void
-_e_policy_wl_dpy_surf_del(E_Client *ec)
-{
-   Eina_List *l;
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-   E_Policy_Wl_Dpy_Surface *dpy_surf;
-
-   EINA_SAFETY_ON_NULL_RETURN(ec);
-
-   EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
-     {
-        dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
-        if (dpy_surf)
-          {
-             tz_dpy_pol->dpy_surfs = eina_list_remove(tz_dpy_pol->dpy_surfs, dpy_surf);
-             E_FREE(dpy_surf);
-          }
-     }
-}
-
-// --------------------------------------------------------
-// brightness
-// --------------------------------------------------------
-static Eina_Bool
-_e_policy_system_brightness_get(int *brightness)
-{
-   int error;
-   int sys_brightness = -1;
-
-   if (!brightness) return EINA_FALSE;
-
-   error = device_display_get_brightness(0, &sys_brightness);
-   if (error != DEVICE_ERROR_NONE)
-     {
-        // error
-        return EINA_FALSE;
-     }
-
-   *brightness = sys_brightness;
-
-   return EINA_TRUE;
-}
-
-static Eina_Bool
-_e_policy_system_brightness_set(int brightness)
-{
-   Eina_Bool ret;
-   int error;
-   int num_of_dpy;
-   int id;
-
-   ret = EINA_TRUE;
-
-   error = device_display_get_numbers(&num_of_dpy);
-   if (error != DEVICE_ERROR_NONE)
-     {
-        // error
-        return EINA_FALSE;
-     }
-
-   for (id = 0; id < num_of_dpy; id++)
-     {
-        error = device_display_set_brightness(id, brightness);
-        if (error != DEVICE_ERROR_NONE)
-          {
-             // error
-             ret = EINA_FALSE;
-             break;
-          }
-     }
-
-   return ret;
-}
-
-static Eina_Bool
-_e_policy_change_system_brightness(int new_brightness)
-{
-   Eina_Bool ret;
-   int sys_brightness;
-
-   if (!e_policy_system_info.brightness.use_client)
-     {
-        // save system brightness
-        ret = _e_policy_system_brightness_get(&sys_brightness);
-        if (!ret)
-          {
-             return EINA_FALSE;
-          }
-        e_policy_system_info.brightness.system = sys_brightness;
-     }
-
-   ret = _e_policy_system_brightness_set(new_brightness);
-   if (!ret)
-     {
-        return EINA_FALSE;
-     }
-   e_policy_system_info.brightness.client = new_brightness;
-   e_policy_system_info.brightness.use_client = EINA_TRUE;
-
-   return EINA_TRUE;
-}
-
-static Eina_Bool
-_e_policy_restore_system_brightness(void)
-{
-   Eina_Bool ret;
-
-   if (!e_policy_system_info.brightness.use_client) return EINA_TRUE;
-
-   // restore system brightness
-   ret = _e_policy_system_brightness_set(e_policy_system_info.brightness.system);
-   if (!ret)
-     {
-        return EINA_FALSE;
-     }
-   e_policy_system_info.brightness.use_client = EINA_FALSE;
-
-   // Todo:
-   // if there are another window which set brighteness, then we change brighteness of it
-   // if no, then we rollback system brightness
-
-   return EINA_TRUE;
-}
-
-EINTERN Eina_Bool
-e_policy_wl_win_brightness_apply(E_Client *ec)
-{
-   Eina_Bool ret;
-   Eina_List *l;
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-   E_Policy_Wl_Dpy_Surface *dpy_surf = NULL;
-   int ec_visibility;
-
-   EINA_SAFETY_ON_NULL_RETURN_VAL(ec, EINA_FALSE);
-   if (e_object_is_del(E_OBJECT(ec)))
-     ec_visibility = E_VISIBILITY_FULLY_OBSCURED;
-   else
-     ec_visibility = e_client_visibility_get(ec);
-
-   EINA_LIST_FOREACH(polwl->tz_dpy_pols, l, tz_dpy_pol)
-     {
-        dpy_surf = _e_policy_wl_dpy_surf_find(tz_dpy_pol, ec);
-        if (dpy_surf)
-          break;
-     }
-
-   if (!dpy_surf) return EINA_FALSE;
-   if (!dpy_surf->set) return EINA_FALSE;
-
-   // use system brightness
-   if (dpy_surf->brightness < 0)
-     {
-        ELOGF("TZ_DPY_POL", "Restore system brightness. Win(0x%08zx)'s brightness:%d", ec, e_client_util_win_get(ec), dpy_surf->brightness);
-        ret = _e_policy_restore_system_brightness();
-        return ret;
-     }
-
-   if (ec_visibility == E_VISIBILITY_UNOBSCURED)
-     {
-        ELOGF("TZ_DPY_POL", "Change system brightness(%d). Win(0x%08zx) is un-obscured", ec, dpy_surf->brightness, e_client_util_win_get(ec));
-        ret = _e_policy_change_system_brightness(dpy_surf->brightness);
-        if (!ret) return EINA_FALSE;
-     }
-   else
-     {
-        ELOGF("TZ_DPY_POL", "Restore system brightness. Win(0x%08zx) is obscured", ec, e_client_util_win_get(ec));
-        ret = _e_policy_restore_system_brightness();
-        if (!ret) return EINA_FALSE;
-     }
-
-   return EINA_TRUE;
-}
-
-static void
-_tz_dpy_pol_iface_cb_brightness_set(struct wl_client *client, struct wl_resource *res_tz_dpy_pol, struct wl_resource *surf, int32_t brightness)
-{
-   E_Client *ec;
-   E_Policy_Wl_Dpy_Surface *dpy_surf;
-   pid_t pid = 0;
-   uid_t uid = 0;
-   Eina_Bool res;
-
-   ec = e_client_from_surface_resource(surf);
-   EINA_SAFETY_ON_NULL_RETURN(ec);
-
-   dpy_surf = _e_policy_wl_dpy_surf_add(ec, res_tz_dpy_pol);
-   EINA_SAFETY_ON_NULL_RETURN(dpy_surf);
-
-   wl_client_get_credentials(client, &pid, &uid, NULL);
-   res = e_security_privilege_check(pid, uid,
-                                    E_PRIVILEGE_BRIGHTNESS_SET);
-   if (!res)
-     {
-        ELOGF("TZ_DPY_POL",
-              "Privilege Check Failed! DENY set_brightness",
-              ec);
-
-        tizen_display_policy_send_window_brightness_done
-           (res_tz_dpy_pol,
-            surf,
-            -1,
-            TIZEN_DISPLAY_POLICY_ERROR_STATE_PERMISSION_DENIED);
-        return;
-     }
-   ELOGF("TZ_DPY_POL", "Set Win(0x%08zx)'s brightness:%d", ec, e_client_util_win_get(ec), brightness);
-   dpy_surf->set = EINA_TRUE;
-   dpy_surf->brightness = brightness;
-
-   e_policy_wl_win_brightness_apply(ec);
-
-   tizen_display_policy_send_window_brightness_done
-      (res_tz_dpy_pol, surf, brightness, TIZEN_DISPLAY_POLICY_ERROR_STATE_NONE);
-}
-
-static void
-_tz_dpy_pol_iface_cb_destroy(struct wl_client *client, struct wl_resource *resource)
-{
-   wl_resource_destroy(resource);
-}
-
 static void
 _tzpol_iface_cb_subsurf_watcher_get(struct wl_client *client, struct wl_resource *res_tzpol, uint32_t id, struct wl_resource *surface)
 {
@@ -3724,54 +3392,6 @@ err:
    wl_client_post_no_memory(client);
 }
 
-// --------------------------------------------------------
-// tizen_display_policy_interface
-// --------------------------------------------------------
-static const struct tizen_display_policy_interface _tz_dpy_pol_iface =
-{
-   _tz_dpy_pol_iface_cb_brightness_set,
-   _tz_dpy_pol_iface_cb_destroy,
-};
-
-static void
-_tz_dpy_pol_cb_unbind(struct wl_resource *res_tz_dpy_pol)
-{
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-
-   tz_dpy_pol = _e_policy_wl_tz_dpy_pol_get(res_tz_dpy_pol);
-   EINA_SAFETY_ON_NULL_RETURN(tz_dpy_pol);
-
-   _e_policy_wl_tz_dpy_pol_del(tz_dpy_pol);
-}
-
-static void
-_tz_dpy_pol_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t ver, uint32_t id)
-{
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
-   struct wl_resource *res_tz_dpy_pol;
-
-   EINA_SAFETY_ON_NULL_GOTO(polwl, err);
-
-   res_tz_dpy_pol = wl_resource_create(client,
-                                       &tizen_display_policy_interface,
-                                       ver,
-                                       id);
-   EINA_SAFETY_ON_NULL_GOTO(res_tz_dpy_pol, err);
-
-   tz_dpy_pol = _e_policy_wl_tz_dpy_pol_add(res_tz_dpy_pol);
-   EINA_SAFETY_ON_NULL_GOTO(tz_dpy_pol, err);
-
-   wl_resource_set_implementation(res_tz_dpy_pol,
-                                  &_tz_dpy_pol_iface,
-                                  NULL,
-                                  _tz_dpy_pol_cb_unbind);
-   return;
-
-err:
-   ERR("Could not create tizen_display_policy_interface res: %m");
-   wl_client_post_no_memory(client);
-}
-
 // --------------------------------------------------------
 // tizen_ws_shell_interface::service
 // --------------------------------------------------------
@@ -7324,7 +6944,6 @@ e_policy_wl_client_del(E_Client *ec)
    if (!ec->pixmap) return;
 
    e_policy_wl_pixmap_del(ec->pixmap);
-   _e_policy_wl_dpy_surf_del(ec);
    _e_policy_wl_tz_indicator_unset_client(ec);
    _e_policy_wl_tz_clipboard_unset_client(ec);
 
@@ -7446,14 +7065,6 @@ e_policy_wl_init(void)
    EINA_SAFETY_ON_NULL_GOTO(global, err);
    polwl->globals = eina_list_append(polwl->globals, global);
 
-   global = wl_global_create(comp_wl->wl.disp,
-                             &tizen_display_policy_interface,
-                             1,
-                             NULL,
-                             _tz_dpy_pol_cb_bind);
-   EINA_SAFETY_ON_NULL_GOTO(global, err);
-   polwl->globals = eina_list_append(polwl->globals, global);
-
    global = wl_global_create(comp_wl->wl.disp,
                              &tizen_ws_shell_interface,
                              4,
@@ -7519,7 +7130,6 @@ e_policy_wl_shutdown(void)
    E_Policy_Wl_Tzsh *tzsh;
    E_Policy_Wl_Tzsh_Srv *tzsh_srv;
    E_Policy_Wl_Tzsh_Extension *tzsh_extension;
-   E_Policy_Wl_Tz_Dpy_Pol *tz_dpy_pol;
    E_Policy_Wl_Tz_Indicator *tz_indicator;
    struct wl_global *global;
    int i;
@@ -7548,16 +7158,6 @@ e_policy_wl_shutdown(void)
    EINA_LIST_FREE(polwl->tzshs, tzsh)
      wl_resource_destroy(tzsh->res_tzsh);
 
-   EINA_LIST_FREE(polwl->tz_dpy_pols, tz_dpy_pol)
-     {
-        E_Policy_Wl_Dpy_Surface *dpy_surf;
-        EINA_LIST_FREE(tz_dpy_pol->dpy_surfs, dpy_surf)
-          {
-             E_FREE(dpy_surf);
-          }
-        wl_resource_destroy(tz_dpy_pol->res_tz_dpy_pol);
-     }
-
    EINA_LIST_FREE(polwl->tz_indicators, tz_indicator)
      {
         eina_list_free(tz_indicator->ec_list);
index 440d7b0f0c0e5f5536526717062c1f5c02440e37..2a75b1f40d8a7763a357557a38bb569f15787217 100644 (file)
@@ -30,7 +30,6 @@ EINTERN void      e_policy_wl_win_scrmode_apply(void);
 EINTERN void      e_policy_wl_aux_hint_init(void);
 EINTERN void      e_policy_wl_aux_message_send(E_Client *ec, const char *key, const char *val, Eina_List *options);
 EINTERN void      e_policy_wl_aux_hint_apply(E_Client *ec);
-EINTERN Eina_Bool e_policy_wl_win_brightness_apply(E_Client *ec);
 EINTERN void      e_policy_wl_indicator_flick_send(E_Client *ec);
 EINTERN void      e_policy_wl_clipboard_data_selected_send(E_Client *ec);
 EINTERN void      e_policy_wl_stack_changed_send(E_Client *ec);
index ee1352efd3375a8e8ca09cf886c08eb424c2fc9e..e17fa9141108e893ec52b9cc7e46ab9f1fbac0b9 100644 (file)
@@ -30,8 +30,7 @@ E_Policy *e_policy = NULL;
 Eina_Hash *hash_policy_clients = NULL;
 E_Policy_System_Info e_policy_system_info =
 {
-   {NULL, EINA_FALSE},
-   { -1, -1, EINA_FALSE}
+   {NULL, EINA_FALSE}
 };
 
 static int _e_policy_interceptors_walking = 0;
@@ -538,7 +537,6 @@ _e_policy_cb_hook_client_del(void *d EINA_UNUSED, E_Client *ec)
    if (pc->zone)
      e_tzsh_indicator_srv_ower_win_update(pc->zone);
 
-   e_policy_wl_win_brightness_apply(pc->ec);
    e_policy_wl_client_del(pc->ec);
 
    if (e_policy_client_is_lockscreen(pc->ec))
@@ -765,8 +763,6 @@ _e_policy_cb_hook_client_visibility(void *d EINA_UNUSED, E_Client *ec)
              e_policy_client_iconify_by_visibility(ec);
           }
 
-        e_policy_wl_win_brightness_apply(ec);
-
         _e_pol_changed_vis = EINA_TRUE;
         if (!eina_list_data_find(_e_pol_changed_zone, zone))
           _e_pol_changed_zone = eina_list_append(_e_pol_changed_zone, zone);
index dfea83d0b0edf1d5984889de3f8225498a7ffabb..8994a0e5f8e745eb9c10303942d893da2bb78455 100644 (file)
@@ -68,13 +68,6 @@ struct _E_Policy_System_Info
       E_Client  *ec;
       Eina_Bool  show;
    } lockscreen;
-
-   struct
-   {
-      int system;
-      int client;
-      Eina_Bool use_client;
-   } brightness;
 };
 
 struct _E_Policy_Interceptor