1 #include "e_policy_wl_display_intern.h"
2 #include "e_dbus_conn_intern.h"
4 typedef struct _E_Display_Dbus_Info
6 Eldbus_Connection *edbus_conn;
7 Eldbus_Connection_Type edbus_conn_type;
8 Ecore_Event_Handler *dbus_init_done_handler;
11 #define BUS_NAME "org.enlightenment.wm"
13 #define DEVICED_DEST "org.tizen.system.deviced"
14 #define DEVICED_PATH "/Org/Tizen/System/DeviceD/Display"
15 #define DEVICED_IFACE "org.tizen.system.deviced.display"
16 #define DEVICED_LOCK_STATE "lockstate"
17 #define DEVICED_UNLOCK_STATE "unlockstate"
19 #define DEVICED_LCDON "lcdon"
20 #define DEVICED_STAY_CUR_STATE "staycurstate"
21 #define DEVICED_SLEEP_MARGIN "sleepmargin"
23 /* static global variables */
24 static E_Display_Dbus_Info _e_display_dbus_info;
25 static Eina_List *_display_control_hooks = NULL;
26 static Eina_List *_display_control_handlers = NULL;
29 static Eina_List *_screen_mode_client_list = NULL;
30 static E_Display_Screen_Mode _e_display_screen_mode;
32 /* static functions */
33 static Eina_Bool _e_policy_display_dbus_init(void);
34 static void _e_policy_display_dbus_shutdown(void);
35 static void _e_policy_display_dbus_request_name_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED);
37 static Eina_Bool _e_policy_wl_display_client_add_to_list(Eina_List** list, E_Client *ec);
38 static Eina_Bool _e_policy_wl_display_client_remove_from_list(Eina_List** list, E_Client *ec);
40 static void _e_policy_wl_display_hook_client_del(void *d EINA_UNUSED, E_Client *ec);
41 static void _e_policy_wl_display_hook_client_visibility(void *d EINA_UNUSED, E_Client *ec);
43 static Eina_Bool _e_policy_wl_display_cb_client_remove(void *d EINA_UNUSED, int type EINA_UNUSED, void *event);
47 static E_Client *_e_policy_wl_display_screen_mode_find_visible_window(void);
48 static void _e_policy_wl_display_screen_mode_send(E_Display_Screen_Mode mode);
51 _e_policy_display_cb_dbus_init_done(void *data, int type, void *event)
53 E_DBus_Conn_Init_Done_Event *e = event;
55 if (e->status == E_DBUS_CONN_INIT_SUCCESS && e->conn_type == _e_display_dbus_info.edbus_conn_type)
57 _e_display_dbus_info.edbus_conn = e_dbus_conn_connection_ref(_e_display_dbus_info.edbus_conn_type);
59 if (_e_display_dbus_info.edbus_conn)
60 eldbus_name_request(_e_display_dbus_info.edbus_conn,
61 BUS_NAME, ELDBUS_NAME_REQUEST_FLAG_DO_NOT_QUEUE,
62 _e_policy_display_dbus_request_name_cb, NULL);
65 ecore_event_handler_del(_e_display_dbus_info.dbus_init_done_handler);
66 _e_display_dbus_info.dbus_init_done_handler = NULL;
68 return ECORE_CALLBACK_PASS_ON;
72 _e_policy_display_dbus_init(void)
74 _e_display_dbus_info.edbus_conn = NULL;
75 _e_display_dbus_info.edbus_conn_type = ELDBUS_CONNECTION_TYPE_SYSTEM;
76 _e_display_dbus_info.dbus_init_done_handler = NULL;
78 if (e_dbus_conn_init() <= 0) return EINA_FALSE;
80 _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);
81 e_dbus_conn_dbus_init(_e_display_dbus_info.edbus_conn_type);
87 _e_policy_display_dbus_shutdown(void)
89 if (_e_display_dbus_info.dbus_init_done_handler)
91 ecore_event_handler_del(_e_display_dbus_info.dbus_init_done_handler);
92 _e_display_dbus_info.dbus_init_done_handler = NULL;
96 if (_e_display_dbus_info.edbus_conn)
98 eldbus_name_release(_e_display_dbus_info.edbus_conn, BUS_NAME, NULL, NULL);
99 e_dbus_conn_connection_unref(_e_display_dbus_info.edbus_conn);
100 _e_display_dbus_info.edbus_conn = NULL;
103 e_dbus_conn_shutdown();
107 _e_policy_display_dbus_request_name_cb(void *data EINA_UNUSED, const Eldbus_Message *msg, Eldbus_Pending *pending EINA_UNUSED)
111 if (eldbus_message_error_get(msg, NULL, NULL))
113 ERR("Could not request bus name");
117 if (!eldbus_message_arguments_get(msg, "u", &flag))
119 ERR("Could not get arguments on on_name_request");
123 if (!(flag & ELDBUS_NAME_REQUEST_REPLY_PRIMARY_OWNER))
125 WRN("Name already in use\n");
130 _e_policy_wl_display_client_add_to_list(Eina_List** list, E_Client *ec)
132 if (!ec) return EINA_FALSE;
134 if (eina_list_data_find(*list, ec) == ec)
137 *list = eina_list_append(*list, ec);
143 _e_policy_wl_display_client_remove_from_list(Eina_List** list, E_Client *ec)
145 if (!ec) return EINA_FALSE;
147 if (!eina_list_data_find(*list, ec))
150 *list = eina_list_remove(*list, ec);
156 _e_policy_wl_display_hook_client_del(void *d EINA_UNUSED, E_Client *ec)
158 _e_policy_wl_display_client_remove_from_list(&_screen_mode_client_list, ec);
162 _e_policy_wl_display_hook_client_visibility(void *d EINA_UNUSED, E_Client *ec)
164 if (ec->visibility.changed)
166 e_policy_display_screen_mode_apply();
171 _e_policy_wl_display_cb_client_remove(void *d EINA_UNUSED, int type EINA_UNUSED, void *event)
173 e_policy_display_screen_mode_apply();
174 return ECORE_CALLBACK_PASS_ON;
178 _e_policy_wl_display_screen_mode_find_visible_window(void)
184 if (_screen_mode_client_list == NULL) return NULL;
186 EINA_LIST_FOREACH(_screen_mode_client_list, l, ec)
188 if (e_object_is_del(E_OBJECT(ec)))
189 ec_visibility = E_VISIBILITY_FULLY_OBSCURED;
191 ec_visibility = ec->visibility.obscured;
193 if ((ec_visibility == E_VISIBILITY_UNOBSCURED) ||
194 (ec_visibility == E_VISIBILITY_PARTIALLY_OBSCURED))
204 _e_policy_wl_display_screen_mode_send(E_Display_Screen_Mode mode)
208 unsigned int timeout = 0;
210 if (!_e_display_dbus_info.edbus_conn) return;
212 if (mode == E_DISPLAY_SCREEN_MODE_ALWAYS_ON)
214 msg = eldbus_message_method_call_new(DEVICED_DEST,
220 ret = eldbus_message_arguments_append(msg, "sssi",
222 DEVICED_STAY_CUR_STATE,
228 msg = eldbus_message_method_call_new(DEVICED_DEST,
231 DEVICED_UNLOCK_STATE);
234 ret = eldbus_message_arguments_append(msg, "ss",
236 DEVICED_SLEEP_MARGIN);
242 eldbus_message_unref(msg);
247 _e_display_screen_mode = mode;
248 ELOGF("TZPOL", "SCR_MODE | Send screen mode:%d to system", NULL, mode);
250 eldbus_connection_send(_e_display_dbus_info.edbus_conn, msg, NULL, NULL, -1);
254 e_policy_display_init(void)
256 if (!_e_policy_display_dbus_init()) return EINA_FALSE;
258 _e_display_screen_mode = E_DISPLAY_SCREEN_MODE_DEFAULT;
261 E_CLIENT_HOOK_APPEND(_display_control_hooks, E_CLIENT_HOOK_DEL, _e_policy_wl_display_hook_client_del, NULL);
262 E_CLIENT_HOOK_APPEND(_display_control_hooks, E_CLIENT_HOOK_EVAL_VISIBILITY, _e_policy_wl_display_hook_client_visibility, NULL);
264 /* handler functions */
265 E_LIST_HANDLER_APPEND(_display_control_handlers, E_EVENT_CLIENT_REMOVE, _e_policy_wl_display_cb_client_remove, NULL);
271 e_policy_display_shutdown(void)
273 E_FREE_LIST(_display_control_hooks, e_client_hook_del);
274 E_FREE_LIST(_display_control_handlers, ecore_event_handler_del);
276 if (_screen_mode_client_list) eina_list_free(_screen_mode_client_list);
278 _e_policy_display_dbus_shutdown();
282 e_policy_display_screen_mode_set(E_Client *ec, int mode)
285 if (e_object_is_del(E_OBJECT(ec))) return;
289 _e_policy_wl_display_client_remove_from_list(&_screen_mode_client_list, ec);
290 e_policy_display_screen_mode_apply();
294 _e_policy_wl_display_client_add_to_list(&_screen_mode_client_list, ec);
295 e_policy_display_screen_mode_apply();
300 e_policy_display_screen_mode_apply(void)
304 ec = _e_policy_wl_display_screen_mode_find_visible_window();
307 if (_e_display_screen_mode == E_DISPLAY_SCREEN_MODE_DEFAULT)
309 ELOGF("TZPOL", "SCR_MODE | Request to change screen mode:%d", ec, E_DISPLAY_SCREEN_MODE_ALWAYS_ON);
310 _e_policy_wl_display_screen_mode_send(E_DISPLAY_SCREEN_MODE_ALWAYS_ON);
315 if (_e_display_screen_mode == E_DISPLAY_SCREEN_MODE_ALWAYS_ON)
317 ELOGF("TZPOL", "SCR_MODE | Request to change screen mode:%d", NULL, E_DISPLAY_SCREEN_MODE_DEFAULT);
318 _e_policy_wl_display_screen_mode_send(E_DISPLAY_SCREEN_MODE_DEFAULT);