The problem that e17 couldn't move/resize window when the window fetch the rotation...
[platform/core/uifw/e17.git] / src / bin / e_dpms.c
1 #include "e.h"
2
3 static Ecore_Event_Handler *_e_dpms_handler_config_mode = NULL;
4 static Ecore_Event_Handler *_e_dpms_handler_border_fullscreen = NULL;
5 static Ecore_Event_Handler *_e_dpms_handler_border_unfullscreen = NULL;
6 static Ecore_Event_Handler *_e_dpms_handler_border_remove = NULL;
7 static Ecore_Event_Handler *_e_dpms_handler_border_iconify = NULL;
8 static Ecore_Event_Handler *_e_dpms_handler_border_uniconify = NULL;
9 static Ecore_Event_Handler *_e_dpms_handler_border_desk_set = NULL;
10 static Ecore_Event_Handler *_e_dpms_handler_desk_show = NULL;
11
12 static unsigned int _e_dpms_timeout_standby = 0;
13 static unsigned int _e_dpms_timeout_suspend = 0;
14 static unsigned int _e_dpms_timeout_off = 0;
15 static int _e_dpms_enabled = EINA_FALSE;
16
17
18 EAPI void
19 e_dpms_update(void)
20 {
21    unsigned int standby = 0, suspend = 0, off = 0;
22    int enabled;
23    Eina_Bool changed = EINA_FALSE;
24
25    enabled = ((e_config->dpms_enable) && (!e_config->mode.presentation) &&
26               (!e_util_fullscreen_curreny_any()));
27
28    if (_e_dpms_enabled != enabled)
29      {
30         _e_dpms_enabled = enabled;
31         ecore_x_dpms_enabled_set(enabled);
32      }
33    if (!enabled) return;
34
35    if (e_config->dpms_standby_enable)
36      {
37         standby = e_config->dpms_standby_timeout;
38         if (_e_dpms_timeout_standby != standby)
39           {
40              _e_dpms_timeout_standby = standby;
41              changed = EINA_TRUE;
42           }
43      }
44
45    if (e_config->dpms_suspend_enable)
46      {
47         suspend = e_config->dpms_suspend_timeout;
48         if (_e_dpms_timeout_suspend != suspend)
49           {
50              _e_dpms_timeout_suspend = suspend;
51              changed = EINA_TRUE;
52           }
53      }
54
55    if (e_config->dpms_off_enable)
56      {
57         off = e_config->dpms_off_timeout;
58         if (_e_dpms_timeout_off != off)
59           {
60              _e_dpms_timeout_off = off;
61              changed = EINA_TRUE;
62           }
63      }
64
65    if (changed) ecore_x_dpms_timeouts_set(standby, suspend, off);
66 }
67
68 EAPI void
69 e_dpms_force_update(void)
70 {
71    unsigned int standby = 0, suspend = 0, off = 0;
72    int enabled;
73
74    enabled = ((e_config->dpms_enable) && (!e_config->mode.presentation) &&
75               (!e_util_fullscreen_curreny_any()));
76    ecore_x_dpms_enabled_set(enabled);
77    if (!enabled) return;
78    if (e_config->dpms_standby_enable)
79      standby = e_config->dpms_standby_timeout;
80    if (e_config->dpms_suspend_enable)
81      suspend = e_config->dpms_suspend_timeout;
82    if (e_config->dpms_off_enable)
83      off = e_config->dpms_off_timeout;
84    ecore_x_dpms_timeouts_set(standby + 10, suspend + 10, off + 10);
85    ecore_x_dpms_timeouts_set(standby, suspend, off);
86 }
87
88 static Eina_Bool
89 _e_dpms_handler_config_mode_cb(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
90 {
91    e_dpms_update();
92    return ECORE_CALLBACK_PASS_ON;
93 }
94
95 static Eina_Bool
96 _e_dpms_handler_border_fullscreen_check_cb(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
97 {
98    e_dpms_update();
99    return ECORE_CALLBACK_PASS_ON;
100 }
101
102 static Eina_Bool
103 _e_dpms_handler_border_desk_set_cb(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
104 {
105    e_dpms_update();
106    return ECORE_CALLBACK_PASS_ON;
107 }
108
109 static Eina_Bool
110 _e_dpms_handler_desk_show_cb(void *data __UNUSED__, int type __UNUSED__, void *event __UNUSED__)
111 {
112    e_dpms_update();
113    return ECORE_CALLBACK_PASS_ON;
114 }
115
116 EINTERN int
117 e_dpms_init(void)
118 {
119    _e_dpms_handler_config_mode = ecore_event_handler_add
120      (E_EVENT_CONFIG_MODE_CHANGED, _e_dpms_handler_config_mode_cb, NULL);
121
122    _e_dpms_handler_border_fullscreen = ecore_event_handler_add
123      (E_EVENT_BORDER_FULLSCREEN, _e_dpms_handler_border_fullscreen_check_cb, NULL);
124
125    _e_dpms_handler_border_unfullscreen = ecore_event_handler_add
126      (E_EVENT_BORDER_UNFULLSCREEN, _e_dpms_handler_border_fullscreen_check_cb, NULL);
127
128    _e_dpms_handler_border_remove = ecore_event_handler_add
129      (E_EVENT_BORDER_REMOVE, _e_dpms_handler_border_fullscreen_check_cb, NULL);
130
131    _e_dpms_handler_border_iconify = ecore_event_handler_add
132      (E_EVENT_BORDER_ICONIFY, _e_dpms_handler_border_fullscreen_check_cb, NULL);
133
134    _e_dpms_handler_border_uniconify = ecore_event_handler_add
135      (E_EVENT_BORDER_UNICONIFY, _e_dpms_handler_border_fullscreen_check_cb, NULL);
136
137    _e_dpms_handler_border_desk_set = ecore_event_handler_add
138      (E_EVENT_BORDER_DESK_SET, _e_dpms_handler_border_desk_set_cb, NULL);
139
140    _e_dpms_handler_desk_show = ecore_event_handler_add
141      (E_EVENT_DESK_SHOW, _e_dpms_handler_desk_show_cb, NULL);
142
143    _e_dpms_enabled = ecore_x_dpms_enabled_get();
144    ecore_x_dpms_timeouts_get
145      (&_e_dpms_timeout_standby, &_e_dpms_timeout_suspend, &_e_dpms_timeout_off);
146
147    e_dpms_update();
148
149    return 1;
150 }
151
152 EINTERN int
153 e_dpms_shutdown(void)
154 {
155    if (_e_dpms_handler_config_mode)
156      {
157         ecore_event_handler_del(_e_dpms_handler_config_mode);
158         _e_dpms_handler_config_mode = NULL;
159      }
160
161    if (_e_dpms_handler_border_fullscreen)
162      {
163         ecore_event_handler_del(_e_dpms_handler_border_fullscreen);
164         _e_dpms_handler_border_fullscreen = NULL;
165      }
166
167    if (_e_dpms_handler_border_unfullscreen)
168      {
169         ecore_event_handler_del(_e_dpms_handler_border_unfullscreen);
170         _e_dpms_handler_border_unfullscreen = NULL;
171      }
172
173    if (_e_dpms_handler_border_remove)
174      {
175         ecore_event_handler_del(_e_dpms_handler_border_remove);
176         _e_dpms_handler_border_remove = NULL;
177      }
178
179    if (_e_dpms_handler_border_iconify)
180      {
181         ecore_event_handler_del(_e_dpms_handler_border_iconify);
182         _e_dpms_handler_border_iconify = NULL;
183      }
184
185    if (_e_dpms_handler_border_uniconify)
186      {
187         ecore_event_handler_del(_e_dpms_handler_border_uniconify);
188         _e_dpms_handler_border_uniconify = NULL;
189      }
190
191    if (_e_dpms_handler_border_desk_set)
192      {
193         ecore_event_handler_del(_e_dpms_handler_border_desk_set);
194         _e_dpms_handler_border_desk_set = NULL;
195      }
196
197    if (_e_dpms_handler_desk_show)
198      {
199         ecore_event_handler_del(_e_dpms_handler_desk_show);
200         _e_dpms_handler_desk_show = NULL;
201      }
202
203    return 1;
204 }