6 // FIXME: backlight should be tied per zone but this implementation is just
7 // a signleton right now as thats 99% of use cases. but api supports
8 // doing more. for now make it work in the singleton
14 static double bl_val = 1.0;
15 static double bl_animval = 1.0;
16 static E_Backlight_Mode bl_mode = E_BACKLIGHT_MODE_NORMAL;
17 static int sysmode = MODE_NONE;
18 static Ecore_Animator *bl_anim = NULL;
20 static void _e_backlight_update(E_Zone *zone);
21 static void _e_backlight_set(E_Zone *zone, double val);
22 static Eina_Bool _bl_anim(void *data, double pos);
23 static Eina_Bool bl_avail = EINA_FALSE;
25 static const char *bl_sysval = NULL;
26 static Ecore_Event_Handler *bl_sys_exit_handler = NULL;
27 static Ecore_Exe *bl_sys_set_exe = NULL;
28 static Eina_Bool bl_sys_pending_set = EINA_FALSE;
29 static Eina_Bool bl_sys_set_exe_ready = EINA_TRUE;
31 static void _bl_sys_find(void);
32 static void _bl_sys_level_get(void);
33 static Eina_Bool _e_bl_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event);
34 static void _bl_sys_level_set(double val);
38 e_backlight_init(void)
43 bl_avail = ecore_x_randr_output_backlight_available();
45 if (bl_avail == EINA_TRUE)
48 e_backlight_level_set(NULL, 0.0, 0.0);
49 e_backlight_level_set(NULL, e_config->backlight.normal, 1.0);
55 e_backlight_shutdown(void)
57 if (bl_anim) ecore_animator_del(bl_anim);
60 if (bl_sysval) eina_stringshare_del(bl_sysval);
62 if (bl_sys_exit_handler) ecore_event_handler_del(bl_sys_exit_handler);
63 bl_sys_exit_handler = NULL;
64 bl_sys_set_exe = NULL;
65 bl_sys_pending_set = EINA_FALSE;
72 e_backlight_exists(void)
74 if (sysmode == MODE_NONE) return EINA_FALSE;
79 e_backlight_update(void)
86 if (bl_avail == EINA_TRUE)
88 EINA_LIST_FOREACH(e_manager_list(), m, man)
90 EINA_LIST_FOREACH(man->containers, c, con)
92 EINA_LIST_FOREACH(con->zones, z, zone)
94 _e_backlight_update(zone);
102 e_backlight_level_set(E_Zone *zone, double val, double tim)
105 // zone == NULL == everything
106 // set backlight associated with zone to val over period of tim
107 // if tim == 0.0 - then do it instantnly, if time == -1 use some default
109 if (val < 0.0) val = 0.0;
110 else if (val > 1.0) val = 1.0;
111 if (val == bl_val) return;
112 if (!zone) zone = e_util_zone_current_get(e_manager_current_get());
115 if (bl_mode != E_BACKLIGHT_MODE_NORMAL) return;
116 if (tim < 0.0) tim = e_config->backlight.transition;
121 ecore_animator_del(bl_anim);
124 _e_backlight_set(zone, val);
127 if (bl_anim) ecore_animator_del(bl_anim);
128 bl_anim = ecore_animator_timeline_add(tim, _bl_anim, zone);
133 e_backlight_level_get(E_Zone *zone __UNUSED__)
135 // zone == NULL == everything
140 e_backlight_mode_set(E_Zone *zone, E_Backlight_Mode mode)
142 // zone == NULL == everything
143 if (bl_mode == mode) return;
145 if (bl_mode == E_BACKLIGHT_MODE_NORMAL)
146 e_backlight_level_set(zone, bl_val, -1.0);
147 else if (bl_mode == E_BACKLIGHT_MODE_OFF)
148 e_backlight_level_set(zone, 0.0, -1.0);
149 else if (bl_mode == E_BACKLIGHT_MODE_DIM)
150 e_backlight_level_set(zone, e_config->backlight.dim, -1.0);
151 else if (bl_mode == E_BACKLIGHT_MODE_MAX)
152 e_backlight_level_set(zone, 1.0, -1.0);
155 EAPI E_Backlight_Mode
156 e_backlight_mode_get(E_Zone *zone __UNUSED__)
158 // zone == NULL == everything
162 /* local subsystem functions */
165 _e_backlight_update(E_Zone *zone)
169 Ecore_X_Randr_Output *out;
172 root = zone->container->manager->root;
174 out = ecore_x_randr_window_outputs_get(root, &num);
175 if ((out) && (num > 0))
176 x_bl = ecore_x_randr_output_backlight_level_get(root, out[0]);
181 sysmode = MODE_RANDR;
197 _e_backlight_set(E_Zone *zone, double val)
199 if (sysmode == MODE_RANDR)
202 Ecore_X_Randr_Output *out;
205 root = zone->container->manager->root;
206 out = ecore_x_randr_window_outputs_get(root, &num);
207 if ((out) && (num > 0))
209 ecore_x_randr_output_backlight_level_set(root, out[0], val);
214 else if (sysmode == MODE_SYS)
218 _bl_sys_level_set(val);
225 _bl_anim(void *data, double pos)
230 // FIXME: if zone is deleted while anim going... bad things.
231 pos = ecore_animator_pos_map(pos, ECORE_POS_MAP_DECELERATE, 0.0, 0.0);
232 v = (bl_animval * (1.0 - pos)) + (bl_val *pos);
233 _e_backlight_set(zone, v);
249 devs = eeze_udev_find_by_filter("backlight", NULL, NULL);
251 EINA_LIST_FREE(devs, f)
256 _bl_sys_level_get(void)
261 str = eeze_udev_syspath_get_sysattr(bl_sysval, "max_brightness");
265 eina_stringshare_del(str);
266 if (maxval <= 0) maxval = 255;
267 str = eeze_udev_syspath_get_sysattr(bl_sysval, "brightness");
271 eina_stringshare_del(str);
272 if ((val >= 0) && (val <= maxval))
273 bl_val = (double)val / (double)maxval;
274 // printf("GET: %i/%i (%1.3f)\n", val, maxval, bl_val);
278 _e_bl_cb_ext_delay(void *data __UNUSED__)
280 bl_sys_set_exe_ready = EINA_TRUE;
281 if (bl_sys_pending_set)
283 bl_sys_pending_set = EINA_FALSE;
284 _bl_sys_level_set(bl_val);
290 _e_bl_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event)
292 Ecore_Exe_Event_Del *ev;
295 if (ev->exe == bl_sys_set_exe)
297 bl_sys_set_exe_ready = EINA_FALSE;
298 bl_sys_set_exe = NULL;
299 ecore_timer_add(0.1, _e_bl_cb_ext_delay, NULL);
301 return ECORE_CALLBACK_RENEW;
305 _bl_sys_level_set(double val)
309 if (!bl_sys_exit_handler)
310 bl_sys_exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
311 _e_bl_cb_exit, NULL);
312 if ((bl_sys_set_exe) || (!bl_sys_set_exe_ready))
314 bl_sys_pending_set = EINA_TRUE;
317 // printf("SET: %1.3f\n", val);
318 snprintf(buf, sizeof(buf),
319 "%s/enlightenment/utils/enlightenment_backlight %i",
320 e_prefix_lib_get(), (int)(val * 1000.0));
321 bl_sys_set_exe = ecore_exe_run(buf, NULL);