2 #include "e_mod_main.h"
4 /* gadcon requirements */
5 static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
6 static void _gc_shutdown(E_Gadcon_Client *gcc);
7 static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
8 static const char *_gc_label(E_Gadcon_Client_Class *client_class);
9 static Evas_Object *_gc_icon(E_Gadcon_Client_Class *client_class, Evas *evas);
10 static const char *_gc_id_new(E_Gadcon_Client_Class *client_class);
12 /* and actually define the gadcon class that this module provides (just 1) */
13 static const E_Gadcon_Client_Class _gadcon_class =
15 GADCON_CLIENT_CLASS_VERSION,
18 _gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
20 E_GADCON_CLIENT_STYLE_PLAIN
23 /* actual module specifics */
24 typedef struct _Instance Instance;
29 Evas_Object *o_backlight, *o_table, *o_slider;
30 E_Gadcon_Popup *popup;
33 Ecore_X_Window input_win;
34 Ecore_Event_Handler *hand_mouse_down;
35 Ecore_Event_Handler *hand_key_down;
38 static Eina_List *backlight_instances = NULL;
39 static E_Module *backlight_module = NULL;
40 static E_Action *act = NULL;
42 static void _backlight_popup_free(Instance *inst);
45 _backlight_gadget_update(Instance *inst)
47 Edje_Message_Float msg;
50 if (msg.val < 0.0) msg.val = 0.0;
51 else if (msg.val > 1.0) msg.val = 1.0;
52 edje_object_message_send(inst->o_backlight, EDJE_MESSAGE_FLOAT, 0, &msg);
56 _backlight_input_win_del(Instance *inst)
58 e_grabinput_release(0, inst->input_win);
59 ecore_x_window_free(inst->input_win);
61 ecore_event_handler_del(inst->hand_mouse_down);
62 inst->hand_mouse_down = NULL;
63 ecore_event_handler_del(inst->hand_key_down);
64 inst->hand_key_down = NULL;
68 _backlight_input_win_mouse_down_cb(void *data, int type __UNUSED__, void *event)
70 Ecore_Event_Mouse_Button *ev = event;
71 Instance *inst = data;
73 if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
74 _backlight_popup_free(inst);
75 return ECORE_CALLBACK_PASS_ON;
79 _backlight_input_win_key_down_cb(void *data, int type __UNUSED__, void *event)
81 Ecore_Event_Key *ev = event;
82 Instance *inst = data;
85 if (ev->window != inst->input_win) return ECORE_CALLBACK_PASS_ON;
88 if (!strcmp(keysym, "Escape"))
89 _backlight_popup_free(inst);
90 else if ((!strcmp(keysym, "Up")) ||
91 (!strcmp(keysym, "Left")) ||
92 (!strcmp(keysym, "KP_Up")) ||
93 (!strcmp(keysym, "KP_Left")) ||
94 (!strcmp(keysym, "w")) ||
95 (!strcmp(keysym, "d")) ||
96 (!strcmp(keysym, "bracketright")) ||
97 (!strcmp(keysym, "Prior")))
99 double v = inst->val + 0.1;
100 if (v > 1.0) v = 1.0;
101 e_widget_slider_value_double_set(inst->o_slider, v);
103 e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
104 e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
105 _backlight_gadget_update(inst);
107 else if ((!strcmp(keysym, "Down")) ||
108 (!strcmp(keysym, "Right")) ||
109 (!strcmp(keysym, "KP_Down")) ||
110 (!strcmp(keysym, "KP_Right")) ||
111 (!strcmp(keysym, "s")) ||
112 (!strcmp(keysym, "a")) ||
113 (!strcmp(keysym, "bracketleft")) ||
114 (!strcmp(keysym, "Next")))
116 double v = inst->val - 0.1;
117 if (v < 0.0) v = 0.0;
118 e_widget_slider_value_double_set(inst->o_slider, v);
120 e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
121 e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
122 _backlight_gadget_update(inst);
124 else if ((!strcmp(keysym, "0")) ||
125 (!strcmp(keysym, "1")) ||
126 (!strcmp(keysym, "2")) ||
127 (!strcmp(keysym, "3")) ||
128 (!strcmp(keysym, "4")) ||
129 (!strcmp(keysym, "5")) ||
130 (!strcmp(keysym, "6")) ||
131 (!strcmp(keysym, "7")) ||
132 (!strcmp(keysym, "8")) ||
133 (!strcmp(keysym, "9")))
135 double v = (double)atoi(keysym) / 9.0;
136 e_widget_slider_value_double_set(inst->o_slider, v);
138 e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
139 e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
140 _backlight_gadget_update(inst);
145 E_Config_Binding_Key *bind;
146 E_Binding_Modifier mod;
148 for (l = e_config->key_bindings; l; l = l->next)
152 if (bind->action && strcmp(bind->action, "backlight")) continue;
156 if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
157 mod |= E_BINDING_MODIFIER_SHIFT;
158 if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)
159 mod |= E_BINDING_MODIFIER_CTRL;
160 if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT)
161 mod |= E_BINDING_MODIFIER_ALT;
162 if (ev->modifiers & ECORE_EVENT_MODIFIER_WIN)
163 mod |= E_BINDING_MODIFIER_WIN;
165 if (bind->key && (!strcmp(bind->key, ev->keyname)) &&
166 ((bind->modifiers == (int)mod) || (bind->any_mod)))
168 _backlight_popup_free(inst);
173 return ECORE_CALLBACK_PASS_ON;
177 _backlight_input_win_new(Instance *inst)
179 Ecore_X_Window_Configure_Mask mask;
180 Ecore_X_Window w, popup_w;
183 man = inst->gcc->gadcon->zone->container->manager;
185 w = ecore_x_window_input_new(man->root, 0, 0, man->w, man->h);
186 mask = (ECORE_X_WINDOW_CONFIGURE_MASK_STACK_MODE |
187 ECORE_X_WINDOW_CONFIGURE_MASK_SIBLING);
188 popup_w = inst->popup->win->evas_win;
189 ecore_x_window_configure(w, mask, 0, 0, 0, 0, 0, popup_w,
190 ECORE_X_WINDOW_STACK_BELOW);
191 ecore_x_window_show(w);
193 inst->hand_mouse_down =
194 ecore_event_handler_add(ECORE_EVENT_MOUSE_BUTTON_DOWN,
195 _backlight_input_win_mouse_down_cb, inst);
196 inst->hand_key_down =
197 ecore_event_handler_add(ECORE_EVENT_KEY_DOWN,
198 _backlight_input_win_key_down_cb, inst);
200 e_grabinput_get(0, 0, inst->input_win);
204 _backlight_settings_cb(void *d1, void *d2 __UNUSED__)
207 e_configure_registry_call("screen/power_management",
208 inst->gcc->gadcon->zone->container, NULL);
209 _backlight_popup_free(inst);
213 _slider_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
215 Instance *inst = data;
216 e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
217 e_backlight_level_set(inst->gcc->gadcon->zone, inst->val, 0.0);
218 _backlight_gadget_update(inst);
222 _backlight_popup_new(Instance *inst)
227 if (inst->popup) return;
229 e_backlight_update();
230 e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
231 inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
232 _backlight_gadget_update(inst);
234 inst->popup = e_gadcon_popup_new(inst->gcc);
235 evas = inst->popup->win->evas;
237 inst->o_table = e_widget_table_add(evas, 0);
239 o = e_widget_slider_add(evas, 0, 0, NULL, 0.0, 1.0, 0.05, 0, &(inst->val), NULL, 100);
240 evas_object_smart_callback_add(o, "changed", _slider_cb, inst);
242 e_widget_table_object_align_append(inst->o_table, o,
243 0, 0, 1, 1, 0, 0, 0, 0, 0.5, 0.5);
245 o = e_widget_button_add(evas, NULL, "preferences-system",
246 _backlight_settings_cb, inst, NULL);
247 e_widget_table_object_align_append(inst->o_table, o,
248 0, 1, 1, 1, 0, 0, 0, 0, 0.5, 1.0);
250 e_gadcon_popup_content_set(inst->popup, inst->o_table);
251 e_gadcon_popup_show(inst->popup);
252 _backlight_input_win_new(inst);
256 _backlight_popup_free(Instance *inst)
258 if (!inst->popup) return;
261 _backlight_input_win_del(inst);
262 e_object_del(E_OBJECT(inst->popup));
268 _backlight_menu_cb_post(void *data, E_Menu *menu __UNUSED__)
270 Instance *inst = data;
271 if ((!inst) || (!inst->menu))
275 e_object_del(E_OBJECT(inst->menu));
281 _backlight_menu_cb_cfg(void *data, E_Menu *menu __UNUSED__, E_Menu_Item *mi __UNUSED__)
283 Instance *inst = data;
285 _backlight_popup_free(inst);
286 e_configure_registry_call("screen/power_management",
287 inst->gcc->gadcon->zone->container, NULL);
291 _backlight_cb_mouse_down(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
293 Instance *inst = data;
294 Evas_Event_Mouse_Down *ev = event;
298 if (inst->popup) _backlight_popup_free(inst);
299 else _backlight_popup_new(inst);
301 else if ((ev->button == 3) && (!inst->menu))
308 zone = e_util_zone_current_get(e_manager_current_get());
312 mi = e_menu_item_new(m);
313 e_menu_item_label_set(mi, _("Settings"));
314 e_util_menu_item_theme_icon_set(mi, "configure");
315 e_menu_item_callback_set(mi, _backlight_menu_cb_cfg, inst);
317 m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
318 e_menu_post_deactivate_callback_set(m, _backlight_menu_cb_post, inst);
321 e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
322 e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
323 1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
324 evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
325 EVAS_BUTTON_NONE, ev->timestamp, NULL);
330 _backlight_level_decrease(Instance *inst)
332 double v = inst->val - 0.1;
333 if (v < 0.0) v = 0.0;
334 e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
338 _backlight_level_increase(Instance *inst)
340 double v = inst->val + 0.1;
341 if (v > 1.0) v = 1.0;
342 e_backlight_level_set(inst->gcc->gadcon->zone, v, 0.0);
346 _backlight_cb_mouse_wheel(void *data, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, void *event)
349 Evas_Event_Mouse_Wheel *ev = event;
351 Instance *inst = data;
353 inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
355 _backlight_level_decrease(inst);
357 _backlight_level_increase(inst);
360 EINA_LIST_FOREACH(backlight_instances, l, inst)
363 _backlight_gadget_update(inst);
367 static E_Gadcon_Client *
368 _gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
371 E_Gadcon_Client *gcc;
374 inst = E_NEW(Instance, 1);
376 o = edje_object_add(gc->evas);
377 e_theme_edje_object_set(o, "base/theme/modules/backlight",
378 "e/modules/backlight/main");
381 gcc = e_gadcon_client_new(gc, name, id, style, o);
385 inst->o_backlight = o;
387 e_backlight_update();
388 inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
389 _backlight_gadget_update(inst);
391 evas_object_event_callback_add(inst->o_backlight,
392 EVAS_CALLBACK_MOUSE_DOWN,
393 _backlight_cb_mouse_down,
395 evas_object_event_callback_add(inst->o_backlight,
396 EVAS_CALLBACK_MOUSE_WHEEL,
397 _backlight_cb_mouse_wheel,
400 backlight_instances = eina_list_append(backlight_instances, inst);
405 _gc_shutdown(E_Gadcon_Client *gcc)
412 e_menu_post_deactivate_callback_set(inst->menu, NULL, NULL);
413 _backlight_input_win_del(inst);
414 e_object_del(E_OBJECT(inst->menu));
417 _backlight_popup_free(inst);
418 backlight_instances = eina_list_remove(backlight_instances, inst);
419 evas_object_del(inst->o_backlight);
424 _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient __UNUSED__)
431 edje_object_size_min_get(inst->o_backlight, &mw, &mh);
432 if ((mw < 1) || (mh < 1))
433 edje_object_size_min_calc(inst->o_backlight, &mw, &mh);
436 e_gadcon_client_aspect_set(gcc, mw, mh);
437 e_gadcon_client_min_size_set(gcc, mw, mh);
441 _gc_label(E_Gadcon_Client_Class *client_class __UNUSED__)
443 return _("Backlight");
447 _gc_icon(E_Gadcon_Client_Class *client_class __UNUSED__, Evas *evas)
452 o = edje_object_add(evas);
453 snprintf(buf, sizeof(buf), "%s/e-module-backlight.edj",
454 e_module_dir_get(backlight_module));
455 edje_object_file_set(o, buf, "icon");
460 _gc_id_new(E_Gadcon_Client_Class *client_class __UNUSED__)
462 return _gadcon_class.name;
466 _e_mod_action_cb(E_Object *obj __UNUSED__,
467 const char *params __UNUSED__)
472 EINA_LIST_FOREACH(backlight_instances, l, inst)
474 if (inst->popup) _backlight_popup_free(inst);
475 else _backlight_popup_new(inst);
480 EAPI E_Module_Api e_modapi =
482 E_MODULE_API_VERSION,
487 e_modapi_init(E_Module *m)
489 backlight_module = m;
490 e_gadcon_provider_register(&_gadcon_class);
491 act = e_action_add("backlight");
494 act->func.go = _e_mod_action_cb;
495 e_action_predef_name_set(_("Screen"), _("Backlight Controls"), "backlight", NULL, NULL, 0);
501 e_modapi_shutdown(E_Module *m __UNUSED__)
505 e_action_predef_name_del(_("Screen"), _("Backlight Controls"));
506 e_action_del("backlight");
509 backlight_module = NULL;
510 e_gadcon_provider_unregister(&_gadcon_class);
515 e_modapi_save(E_Module *m __UNUSED__)