aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/conf_display/e_int_config_screensaver.c
blob: bcd8167936e7cede0caa65f99ac9ea7f534953f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#include "e.h"

#define E_CONFIG_BLANKING_DEFAULT 2
#define E_CONFIG_BLANKING_PREFERRED 1
#define E_CONFIG_BLANKING_NOT_PREFERRED 0

#define E_CONFIG_EXPOSURES_DEFAULT 2
#define E_CONFIG_EXPOSURES_ALLOWED 1
#define E_CONFIG_EXPOSURES_NOT_ALLOWED 0

static void *_create_data(E_Config_Dialog *cfd);
static void _free_data(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_apply(E_Config_Dialog *cfd, E_Config_Dialog_Data *cfdata);
static int _basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata);
static Evas_Object *_basic_create(E_Config_Dialog *cfd, Evas *evas, E_Config_Dialog_Data *cfdata);
static void _cb_ask_presentation_changed(void *data, Evas_Object *obj);

struct _E_Config_Dialog_Data
{
   E_Config_Dialog *cfd;

   int enable_screensaver;
   double timeout;
   double desklock_timeout;
   int ask_presentation;
   double ask_presentation_timeout;
   
   int screensaver_suspend;
   int screensaver_suspend_on_ac;
   double screensaver_suspend_delay_seconds;
   double screensaver_suspend_delay_minutes;
   double screensaver_suspend_delay_hours;

   int wake_on_notify;
   int wake_on_urgent;
   int no_dpms_on_fullscreen;
   int use_dpms;

   struct 
     {
        Evas_Object *ask_presentation_slider;
        Evas_Object *slider_suspend_seconds;
     } gui;
};

E_Config_Dialog *
e_int_config_screensaver(Evas_Object *parent EINA_UNUSED, const char *params EINA_UNUSED)
{
   E_Config_Dialog *cfd;
   E_Config_Dialog_View *v;

   if (e_config_dialog_find("E", "screen/screen_saver")) return NULL;
   v = E_NEW(E_Config_Dialog_View, 1);

   v->create_cfdata = _create_data;
   v->free_cfdata = _free_data;
   v->basic.apply_cfdata = _basic_apply;
   v->basic.create_widgets = _basic_create;
   v->basic.check_changed = _basic_check_changed;

   v->override_auto_apply = 1;

   cfd = e_config_dialog_new(NULL,_("Screen Blank Settings"),
			     "E", "screen/screen_saver",
			     "preferences-desktop-screensaver", 0, v, NULL);
   return cfd;
}

static void
_fill_data(E_Config_Dialog_Data *cfdata)
{
   cfdata->enable_screensaver = e_config->screensaver_enable;
   cfdata->timeout = (double)e_config->screensaver_timeout / 60.0;
   cfdata->desklock_timeout = (double)e_config->screensaver_desklock_timeout;
   cfdata->ask_presentation = e_config->screensaver_ask_presentation;
   cfdata->ask_presentation_timeout = e_config->screensaver_ask_presentation_timeout;
   cfdata->screensaver_suspend = e_config->screensaver_suspend;
   cfdata->screensaver_suspend_on_ac = e_config->screensaver_suspend_on_ac;
   cfdata->screensaver_suspend_delay_seconds = (int)e_config->screensaver_suspend_delay % 60;
   cfdata->screensaver_suspend_delay_minutes = ((int)e_config->screensaver_suspend_delay % 3600) / 60;
   cfdata->screensaver_suspend_delay_hours = (int)e_config->screensaver_suspend_delay / 3600;

   cfdata->wake_on_notify = e_config->screensaver_wake_on_notify;
   cfdata->wake_on_urgent = e_config->screensaver_wake_on_urgent;
   cfdata->no_dpms_on_fullscreen = e_config->no_dpms_on_fullscreen;
   cfdata->use_dpms = !e_config->screensaver_dpms_off;
}

static void *
_create_data(E_Config_Dialog *cfd)
{
   E_Config_Dialog_Data *cfdata;

   cfdata = E_NEW(E_Config_Dialog_Data, 1);
   cfdata->cfd = cfd;
   _fill_data(cfdata);
   return cfdata;
}

static void
_free_data(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
   free(cfdata);
}

static int
_basic_apply(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
   e_config->screensaver_enable = cfdata->enable_screensaver;
   e_config->screensaver_timeout = lround(cfdata->timeout * 60.0);
   e_config->screensaver_desklock_timeout = lround(cfdata->desklock_timeout);
   e_config->screensaver_ask_presentation = cfdata->ask_presentation;
   e_config->screensaver_ask_presentation_timeout = cfdata->ask_presentation_timeout;
   e_config->screensaver_suspend = cfdata->screensaver_suspend;
   e_config->screensaver_suspend_on_ac = cfdata->screensaver_suspend_on_ac;
   e_config->screensaver_suspend_delay =
      (cfdata->screensaver_suspend_delay_seconds
       + (cfdata->screensaver_suspend_delay_minutes * 60.0)
       + (cfdata->screensaver_suspend_delay_hours * 3600.0));

   e_config->screensaver_wake_on_notify = cfdata->wake_on_notify;
   e_config->screensaver_wake_on_urgent = cfdata->wake_on_urgent;

   // enough of dpms vs screensaver being different! useless
//   e_config->dpms_enable = e_config->screensaver_enable;
//   e_config->dpms_standby_enable = e_config->dpms_enable;
//   e_config->dpms_suspend_enable = e_config->dpms_enable;
//   e_config->dpms_off_enable = e_config->dpms_enable;
   // XXX: 5 seconds after screenblank until dpms - enough for most anims;
//   e_config->dpms_standby_timeout = e_config->screensaver_timeout;
//   e_config->dpms_suspend_timeout = e_config->screensaver_timeout;
//   e_config->dpms_off_timeout = e_config->screensaver_timeout;

   e_config->screensaver_interval = 0;

   if ((e_config->backlight.idle_dim) &&
       (e_config->backlight.timer > (e_config->screensaver_timeout)))
     {
        e_config->screensaver_timeout = e_config->backlight.timer;
        e_config->dpms_standby_timeout = e_config->screensaver_timeout;
        e_config->dpms_suspend_timeout = e_config->screensaver_timeout;
        e_config->dpms_off_timeout = e_config->screensaver_timeout;
     }
   
   e_config->no_dpms_on_fullscreen = cfdata->no_dpms_on_fullscreen;
   e_config->screensaver_dpms_off = !cfdata->use_dpms;
   
   /* Apply settings */
   e_screensaver_update();
   e_dpms_update();
   
   e_config_save_queue();
   return 1;
}

static int
_basic_check_changed(E_Config_Dialog *cfd EINA_UNUSED, E_Config_Dialog_Data *cfdata)
{
   double screensaver_suspend_delay = cfdata->screensaver_suspend_delay_seconds
      + (cfdata->screensaver_suspend_delay_minutes * 60.0)
      + (cfdata->screensaver_suspend_delay_hours * 3600.0);
   if (screensaver_suspend_delay < 1.0)
     {
        screensaver_suspend_delay = 1.0;
        cfdata->screensaver_suspend_delay_seconds = 1.0;
        e_widget_slider_value_double_set(cfdata->gui.slider_suspend_seconds,
                                         cfdata->screensaver_suspend_delay_seconds);

     }
   return ((e_config->screensaver_enable != cfdata->enable_screensaver) ||
          (e_config->screensaver_timeout != lround(cfdata->timeout * 60.0)) ||
          (e_config->screensaver_desklock_timeout != lround(cfdata->desklock_timeout)) ||
          (e_config->screensaver_ask_presentation != cfdata->ask_presentation) ||
          (!EINA_DBL_EQ(e_config->screensaver_ask_presentation_timeout, cfdata->ask_presentation_timeout)) ||
          (e_config->screensaver_suspend != cfdata->screensaver_suspend) ||
          (e_config->screensaver_suspend_on_ac != cfdata->screensaver_suspend_on_ac) ||
          (!EINA_DBL_EQ(e_config->screensaver_suspend_delay, screensaver_suspend_delay)) ||
          (e_config->screensaver_wake_on_notify != cfdata->wake_on_notify) ||
          (e_config->screensaver_wake_on_urgent != cfdata->wake_on_urgent) ||
          (e_config->dpms_off_timeout != cfdata->no_dpms_on_fullscreen)
   );
}

static Evas_Object *
_basic_create(E_Config_Dialog *cfd EINA_UNUSED, Evas *evas, E_Config_Dialog_Data *cfdata)
{
   Evas_Object *otb, *ol, *ow, *oc, *oc2;

   e_dialog_resizable_set(cfd->dia, 1);
   otb = e_widget_toolbook_add(evas, (24 * e_scale), (24 * e_scale));

   /* Screensaver */
   ol = e_widget_list_add(evas, 0, 0);
   oc = e_widget_check_add(evas, _("Enable screen blanking"),
                           &(cfdata->enable_screensaver));
   e_widget_list_object_append(ol, oc, 1, 1, 0.5);
   oc2 = e_widget_check_add(evas, _("Use Power Saving (DPMS)"),
                           &(cfdata->use_dpms));
   e_widget_list_object_append(ol, oc2, 1, 1, 0.5);
   
   ow = e_widget_label_add(evas, _("Timeout"));
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.1f minutes"),
			    0.1, 60.0, 0.1, 0, &(cfdata->timeout), NULL, 100);
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   
   ow = e_widget_label_add(evas, _("Special timeout when locked (0 is off)"));
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"),
			    0.0, 60.0, 1.0, 0, &(cfdata->desklock_timeout), NULL, 100);
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   
   ow = e_widget_check_add(evas, _("Suspend on blank"), 
                           &(cfdata->screensaver_suspend));
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_check_add(evas, _("Suspend even if AC"),
                           &(cfdata->screensaver_suspend_on_ac));
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   
   ow = e_widget_label_add(evas, _("Suspend delay"));
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.0f hours"),
			    0.0, 23.0, 1.0, 0, &(cfdata->screensaver_suspend_delay_hours), NULL, 100);
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.0f minutes"),
			    0.0, 59.0, 1.0, 0, &(cfdata->screensaver_suspend_delay_minutes), NULL, 100);
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"),
			    0.0, 59.0, 1.0, 0, &(cfdata->screensaver_suspend_delay_seconds), NULL, 100);
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   cfdata->gui.slider_suspend_seconds = ow;
   
   oc = e_widget_check_add(evas, _("Disable blanking for Fullscreen Windows"),
                           &(cfdata->no_dpms_on_fullscreen));
   e_widget_list_object_append(ol, oc, 1, 1, 0.5);

   e_widget_toolbook_page_append(otb, NULL, _("Blanking"), ol, 
                                 1, 0, 1, 0, 0.5, 0.0);

   /* Wakeups */
   ol = e_widget_list_add(evas, 0, 0);
   oc = e_widget_check_add(evas, _("Wake on notification"),
                           &(cfdata->wake_on_notify));
   e_widget_list_object_append(ol, oc, 1, 1, 0.5);
   oc = e_widget_check_add(evas, _("Wake on urgency"),
                           &(cfdata->wake_on_urgent));
   e_widget_list_object_append(ol, oc, 1, 1, 0.5);
   e_widget_toolbook_page_append(otb, NULL, _("Wakeups"), ol,
                                 1, 0, 1, 0, 0.5, 0.0);
   /* Presentation */
   ol = e_widget_list_add(evas, 0, 0);
   oc2 = e_widget_check_add(evas, _("Suggest if deactivated before"), 
                           &(cfdata->ask_presentation));
   e_widget_check_widget_disable_on_unchecked_add(oc, oc2);
   e_widget_list_object_append(ol, oc2, 1, 1, 0.5);
   ow = e_widget_slider_add(evas, 1, 0, _("%1.0f seconds"),
			    1.0, 300.0, 10.0, 0,
			    &(cfdata->ask_presentation_timeout), NULL, 100);
   cfdata->gui.ask_presentation_slider = ow;
   e_widget_check_widget_disable_on_unchecked_add(oc, ow);
   e_widget_check_widget_disable_on_unchecked_add(oc2, ow);
   e_widget_on_disable_hook_set(ow, _cb_ask_presentation_changed, cfdata);
   e_widget_list_object_append(ol, ow, 1, 1, 0.5);
   e_widget_toolbook_page_append(otb, NULL, _("Presentation"), ol,
                                 1, 0, 1, 0, 0.5, 0.0);
   
   e_widget_toolbook_page_show(otb, 0);

   return otb;
}

static void
_cb_ask_presentation_changed(void *data, Evas_Object *obj EINA_UNUSED)
{
   E_Config_Dialog_Data *cfdata = data;
   Eina_Bool disable;

   disable = ((!cfdata->enable_screensaver) || (!cfdata->ask_presentation));
   e_widget_disabled_set(cfdata->gui.ask_presentation_slider, disable);
}