1 #include "e_policy_wl_display_intern.h"
2 #include "e_dbus_conn_intern.h"
3 #include "e_client_intern.h"
5 typedef struct _E_Display_Dbus_Info
7 Eldbus_Connection *edbus_conn;
8 Eldbus_Connection_Type edbus_conn_type;
9 Ecore_Event_Handler *dbus_init_done_handler;
10 } E_Display_Dbus_Info;
12 #define BUS_NAME "org.enlightenment.wm"
14 #define DEVICED_DEST "org.tizen.system.deviced"
15 #define DEVICED_PATH "/Org/Tizen/System/DeviceD/Display"
16 #define DEVICED_IFACE "org.tizen.system.deviced.display"
17 #define DEVICED_LOCK_STATE "lockstate"
18 #define DEVICED_UNLOCK_STATE "unlockstate"
20 #define DEVICED_LCDON "lcdon"
21 #define DEVICED_STAY_CUR_STATE "staycurstate"
22 #define DEVICED_SLEEP_MARGIN "sleepmargin"
24 /* static global variables */
25 static E_Display_Dbus_Info _e_display_dbus_info;
26 static Eina_List *_display_control_hooks = NULL;
27 static Eina_List *_display_control_handlers = NULL;
30 static Eina_List *_screen_mode_client_list = NULL;
31 static E_Display_Screen_Mode _e_display_screen_mode;
33 /* static functions */
34 static Eina_Bool _e_policy_display_dbus_init(void);
35 static void _e_policy_display_dbus_shutdown(void);
36 static void _e_policy_display_dbus_request_name_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED);
38 static Eina_Bool _e_policy_wl_display_client_add_to_list(Eina_List** list, E_Client *ec);
39 static Eina_Bool _e_policy_wl_display_client_remove_from_list(Eina_List** list, E_Client *ec);
41 static void _e_policy_wl_display_hook_client_del(void *d EINA_UNUSED, E_Client *ec);
42 static void _e_policy_wl_display_hook_client_visibility(void *d EINA_UNUSED, E_Client *ec);
44 static Eina_Bool _e_policy_wl_display_cb_client_remove(void *d EINA_UNUSED, int type EINA_UNUSED, void *event);
48 static E_Client *_e_policy_wl_display_screen_mode_find_visible_window(void);
49 static void _e_policy_wl_display_screen_mode_send(E_Display_Screen_Mode mode);
52 _e_policy_display_cb_dbus_init_done(void *data, int type, void *event)
54 E_DBus_Conn_Init_Done_Event *e = event;
56 if (e->status == E_DBUS_CONN_INIT_SUCCESS && e->conn_type == _e_display_dbus_info.edbus_conn_type)
58 _e_display_dbus_info.edbus_conn = e_dbus_conn_connection_ref(_e_display_dbus_info.edbus_conn_type);
60 if (_e_display_dbus_info.edbus_conn)
61 eldbus_name_request(_e_display_dbus_info.edbus_conn,
62 BUS_NAME, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
63 _e_policy_display_dbus_request_name_cb, NULL);
66 ecore_event_handler_del(_e_display_dbus_info.dbus_init_done_handler);
67 _e_display_dbus_info.dbus_init_done_handler = NULL;
69 return ECORE_CALLBACK_PASS_ON;
73 _e_policy_display_dbus_init(void)
75 _e_display_dbus_info.edbus_conn = NULL;
76 _e_display_dbus_info.edbus_conn_type = ELDBUS_CONNECTION_TYPE_SYSTEM;
77 _e_display_dbus_info.dbus_init_done_handler = NULL;
79 if (e_dbus_conn_init() <= 0) return EINA_FALSE;
81 _e_display_dbus_info.dbus_init_done_handler = ecore_event_handler_add(E_EVENT_DBUS_CONN_INIT_DONE, _e_policy_display_cb_dbus_init_done, NULL);
82 e_dbus_conn_dbus_init(_e_display_dbus_info.edbus_conn_type);
88 _e_policy_display_dbus_shutdown(void)
90 if (_e_display_dbus_info.dbus_init_done_handler)
92 ecore_event_handler_del(_e_display_dbus_info.dbus_init_done_handler);
93 _e_display_dbus_info.dbus_init_done_handler = NULL;
97 if (_e_display_dbus_info.edbus_conn)
99 eldbus_name_release(_e_display_dbus_info.edbus_conn, BUS_NAME, NULL, NULL);
100 e_dbus_conn_connection_unref(_e_display_dbus_info.edbus_conn);
101 _e_display_dbus_info.edbus_conn = NULL;
104 e_dbus_conn_shutdown();
108 _e_policy_display_dbus_request_name_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
112 if (eldbus_message_error_get(msg, NULL, NULL))
114 ERR("Could not request bus name");
118 if (!eldbus_message_arguments_get(msg, "u", &flag))
120 ERR("Could not get arguments on on_name_request");
124 if (!(flag & ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER))
126 WRN("Name already in use\n");
131 _e_policy_wl_display_client_add_to_list(Eina_List** list, E_Client *ec)
133 if (!ec) return EINA_FALSE;
135 if (eina_list_data_find(*list, ec) == ec)
138 *list = eina_list_append(*list, ec);
144 _e_policy_wl_display_client_remove_from_list(Eina_List** list, E_Client *ec)
146 if (!ec) return EINA_FALSE;
148 if (!eina_list_data_find(*list, ec))
151 *list = eina_list_remove(*list, ec);
157 _e_policy_wl_display_hook_client_del(void *d EINA_UNUSED, E_Client *ec)
159 _e_policy_wl_display_client_remove_from_list(&_screen_mode_client_list, ec);
163 _e_policy_wl_display_hook_client_visibility(void *d EINA_UNUSED, E_Client *ec)
165 if (ec->visibility.changed)
167 e_policy_display_screen_mode_apply();
172 _e_policy_wl_display_cb_client_remove(void *d EINA_UNUSED, int type EINA_UNUSED, void *event)
174 e_policy_display_screen_mode_apply();
175 return ECORE_CALLBACK_PASS_ON;
179 _e_policy_wl_display_screen_mode_find_visible_window(void)
185 if (_screen_mode_client_list == NULL) return NULL;
187 EINA_LIST_FOREACH(_screen_mode_client_list, l, ec)
189 if (e_object_is_del(E_OBJECT(ec)))
190 ec_visibility = E_VISIBILITY_FULLY_OBSCURED;
192 ec_visibility = e_client_visibility_get(ec);
194 if ((ec_visibility == E_VISIBILITY_UNOBSCURED) ||
195 (ec_visibility == E_VISIBILITY_PARTIALLY_OBSCURED))
205 _e_policy_wl_display_screen_mode_send(E_Display_Screen_Mode mode)
209 unsigned int timeout = 0;
211 if (!_e_display_dbus_info.edbus_conn) return;
213 if (mode == E_DISPLAY_SCREEN_MODE_ALWAYS_ON)
215 msg = eldbus_message_method_call_new(DEVICED_DEST,
221 ret = eldbus_message_arguments_append(msg, "sssi",
223 DEVICED_STAY_CUR_STATE,
229 msg = eldbus_message_method_call_new(DEVICED_DEST,
232 DEVICED_UNLOCK_STATE);
235 ret = eldbus_message_arguments_append(msg, "ss",
237 DEVICED_SLEEP_MARGIN);
243 eldbus_message_unref(msg);
248 _e_display_screen_mode = mode;
249 ELOGF("TZPOL", "SCR_MODE | Send screen mode:%d to system", NULL, mode);
251 eldbus_connection_send(_e_display_dbus_info.edbus_conn, msg, NULL, NULL, -1);
255 e_policy_display_init(void)
257 if (!_e_policy_display_dbus_init()) return EINA_FALSE;
259 _e_display_screen_mode = E_DISPLAY_SCREEN_MODE_DEFAULT;
262 E_CLIENT_HOOK_APPEND(_display_control_hooks, E_CLIENT_HOOK_DEL, _e_policy_wl_display_hook_client_del, NULL);
263 E_CLIENT_HOOK_APPEND(_display_control_hooks, E_CLIENT_HOOK_EVAL_VISIBILITY, _e_policy_wl_display_hook_client_visibility, NULL);
265 /* handler functions */
266 E_LIST_HANDLER_APPEND(_display_control_handlers, E_EVENT_CLIENT_REMOVE, _e_policy_wl_display_cb_client_remove, NULL);
272 e_policy_display_shutdown(void)
274 E_FREE_LIST(_display_control_hooks, e_client_hook_del);
275 E_FREE_LIST(_display_control_handlers, ecore_event_handler_del);
277 if (_screen_mode_client_list) eina_list_free(_screen_mode_client_list);
279 _e_policy_display_dbus_shutdown();
283 e_policy_display_screen_mode_set(E_Client *ec, int mode)
286 if (e_object_is_del(E_OBJECT(ec))) return;
290 _e_policy_wl_display_client_remove_from_list(&_screen_mode_client_list, ec);
291 e_policy_display_screen_mode_apply();
295 _e_policy_wl_display_client_add_to_list(&_screen_mode_client_list, ec);
296 e_policy_display_screen_mode_apply();
301 e_policy_display_screen_mode_apply(void)
305 ec = _e_policy_wl_display_screen_mode_find_visible_window();
308 if (_e_display_screen_mode == E_DISPLAY_SCREEN_MODE_DEFAULT)
310 ELOGF("TZPOL", "SCR_MODE | Request to change screen mode:%d", ec, E_DISPLAY_SCREEN_MODE_ALWAYS_ON);
311 _e_policy_wl_display_screen_mode_send(E_DISPLAY_SCREEN_MODE_ALWAYS_ON);
316 if (_e_display_screen_mode == E_DISPLAY_SCREEN_MODE_ALWAYS_ON)
318 ELOGF("TZPOL", "SCR_MODE | Request to change screen mode:%d", NULL, E_DISPLAY_SCREEN_MODE_DEFAULT);
319 _e_policy_wl_display_screen_mode_send(E_DISPLAY_SCREEN_MODE_DEFAULT);