enlightenment/src/modules/backlight/e_mod_main.c

512 lines
14 KiB
C
Raw Normal View History

/**
* @addtogroup Optional_Devices
* @{
*
* @defgroup Module_Backlight Backlight
*
* Controls backlights such as laptop LCD.
*
* @}
*/
#include "e.h"
#include "gadget/backlight.h"
/* gadcon requirements */
static E_Gadcon_Client *_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style);
static void _gc_shutdown(E_Gadcon_Client *gcc);
static void _gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient);
static const char *_gc_label(const E_Gadcon_Client_Class *client_class);
static Evas_Object *_gc_icon(const E_Gadcon_Client_Class *client_class, Evas *evas);
static const char *_gc_id_new(const E_Gadcon_Client_Class *client_class);
/* and actually define the gadcon class that this module provides (just 1) */
static const E_Gadcon_Client_Class _gadcon_class =
{
GADCON_CLIENT_CLASS_VERSION,
"backlight",
{
_gc_init, _gc_shutdown, _gc_orient, _gc_label, _gc_icon, _gc_id_new, NULL, NULL
},
E_GADCON_CLIENT_STYLE_PLAIN
};
/* actual module specifics */
typedef struct _Instance Instance;
struct _Instance
{
E_Gadcon_Client *gcc;
Evas_Object *o_backlight, *o_table, *o_slider;
E_Gadcon_Popup *popup;
double val;
Ecore_Timer *popup_timer;
};
static Eina_List *backlight_instances = NULL;
static E_Module *backlight_module = NULL;
static E_Action *act = NULL;
static Eina_List *handlers;
static void _backlight_popup_free(Instance *inst);
static void _backlight_level_set(Instance *inst, double value, Eina_Bool set_slider);
static void
_backlight_gadget_update(Instance *inst)
{
Edje_Message_Float msg;
msg.val = inst->val;
if (msg.val < 0.0) msg.val = 0.0;
else if (msg.val > 1.0) msg.val = 1.0;
edje_object_message_send(inst->o_backlight, EDJE_MESSAGE_FLOAT, 0, &msg);
}
static void
_backlight_level_set(Instance *inst, double val, Eina_Bool set_slider)
{
if (val > 1.0) val = 1.0;
if (val < 0.0) val = 0.0;
if (set_slider)
e_widget_slider_value_double_set(inst->o_slider, val);
inst->val = val;
e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
e_backlight_level_set(inst->gcc->gadcon->zone, val, 0.0);
e_config->backlight.normal = val;
e_config_save_queue();
}
static Eina_Bool
_backlight_win_key_down_cb(void *data, Ecore_Event_Key *ev)
{
Instance *inst = data;
const char *keysym;
keysym = ev->key;
if (!strcmp(keysym, "Escape"))
_backlight_popup_free(inst);
else if ((!strcmp(keysym, "Up")) ||
(!strcmp(keysym, "Left")) ||
(!strcmp(keysym, "KP_Up")) ||
(!strcmp(keysym, "KP_Left")) ||
(!strcmp(keysym, "w")) ||
(!strcmp(keysym, "d")) ||
(!strcmp(keysym, "bracketright")) ||
(!strcmp(keysym, "Prior")))
{
_backlight_level_set(inst, inst->val + 0.1, EINA_TRUE);
_backlight_gadget_update(inst);
}
else if ((!strcmp(keysym, "Down")) ||
(!strcmp(keysym, "Right")) ||
(!strcmp(keysym, "KP_Down")) ||
(!strcmp(keysym, "KP_Right")) ||
(!strcmp(keysym, "s")) ||
(!strcmp(keysym, "a")) ||
(!strcmp(keysym, "bracketleft")) ||
(!strcmp(keysym, "Next")))
{
_backlight_level_set(inst, inst->val - 0.1, EINA_TRUE);
_backlight_gadget_update(inst);
}
else if ((!strcmp(keysym, "0")) ||
(!strcmp(keysym, "1")) ||
(!strcmp(keysym, "2")) ||
(!strcmp(keysym, "3")) ||
(!strcmp(keysym, "4")) ||
(!strcmp(keysym, "5")) ||
(!strcmp(keysym, "6")) ||
(!strcmp(keysym, "7")) ||
(!strcmp(keysym, "8")) ||
(!strcmp(keysym, "9")))
{
_backlight_level_set(inst, (double)atoi(keysym) / 9.0, EINA_TRUE);
_backlight_gadget_update(inst);
}
else
{
Eina_List *l;
E_Config_Binding_Key *binding;
E_Binding_Modifier mod;
EINA_LIST_FOREACH(e_bindings->key_bindings, l, binding)
{
if (binding->action && strcmp(binding->action, "backlight")) continue;
mod = 0;
if (ev->modifiers & ECORE_EVENT_MODIFIER_SHIFT)
mod |= E_BINDING_MODIFIER_SHIFT;
if (ev->modifiers & ECORE_EVENT_MODIFIER_CTRL)
mod |= E_BINDING_MODIFIER_CTRL;
if (ev->modifiers & ECORE_EVENT_MODIFIER_ALT)
mod |= E_BINDING_MODIFIER_ALT;
if (ev->modifiers & ECORE_EVENT_MODIFIER_WIN)
mod |= E_BINDING_MODIFIER_WIN;
if (binding->key && (!strcmp(binding->key, ev->key)) &&
((binding->modifiers == mod) || (binding->any_mod)))
{
_backlight_popup_free(inst);
break;
}
}
}
return ECORE_CALLBACK_PASS_ON;
}
static void
_backlight_settings_cb(void *d1, void *d2 EINA_UNUSED)
{
Instance *inst = d1;
e_configure_registry_call("screen/power_management", NULL, NULL);
_backlight_popup_free(inst);
}
static void
_slider_cb(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
{
Instance *inst = data;
_backlight_level_set(inst, inst->val, EINA_FALSE);
}
static void
_backlight_popup_del_cb(void *obj)
{
_backlight_popup_free(e_object_data_get(obj));
}
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
static void
_backlight_popup_comp_del_cb(void *data, Evas_Object *obj EINA_UNUSED)
{
_backlight_popup_free(data);
}
static void
_backlight_popup_new(Instance *inst)
{
Evas *evas;
Evas_Object *o;
if (inst->popup) return;
e_backlight_mode_set(inst->gcc->gadcon->zone, E_BACKLIGHT_MODE_NORMAL);
inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
_backlight_gadget_update(inst);
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
inst->popup = e_gadcon_popup_new(inst->gcc, 0);
evas = e_comp->evas;
inst->o_table = e_widget_table_add(e_win_evas_win_get(evas), 0);
o = e_widget_slider_add(evas, 0, 0, NULL, 0.05, 1.0, 0.05, 0, &(inst->val), NULL, 100);
evas_object_smart_callback_add(o, "changed", _slider_cb, inst);
inst->o_slider = o;
e_widget_table_object_align_append(inst->o_table, o,
0, 0, 1, 1, 0, 0, 0, 0, 0.5, 0.5);
o = e_widget_button_add(evas, NULL, "preferences-system",
_backlight_settings_cb, inst, NULL);
e_widget_table_object_align_append(inst->o_table, o,
0, 1, 1, 1, 0, 0, 0, 0, 0.5, 1.0);
e_gadcon_popup_content_set(inst->popup, inst->o_table);
e_gadcon_popup_show(inst->popup);
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
e_comp_object_util_autoclose(inst->popup->comp_object, _backlight_popup_comp_del_cb,
_backlight_win_key_down_cb, inst);
e_object_data_set(E_OBJECT(inst->popup), inst);
E_OBJECT_DEL_SET(inst->popup, _backlight_popup_del_cb);
}
static void
_backlight_popup_free(Instance *inst)
{
E_FREE_FUNC(inst->popup, e_object_del);
}
static void
_backlight_menu_cb_cfg(void *data, E_Menu *menu EINA_UNUSED, E_Menu_Item *mi EINA_UNUSED)
{
Instance *inst = data;
_backlight_popup_free(inst);
e_configure_registry_call("screen/power_management", NULL, NULL);
}
static void
_backlight_cb_mouse_down(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
Instance *inst = data;
Evas_Event_Mouse_Down *ev = event;
if (ev->button == 1)
{
if (inst->popup) _backlight_popup_free(inst);
else _backlight_popup_new(inst);
}
else if (ev->button == 3)
{
E_Zone *zone;
E_Menu *m;
E_Menu_Item *mi;
int x, y;
2015-03-13 14:47:36 -07:00
zone = e_zone_current_get();
m = e_menu_new();
mi = e_menu_item_new(m);
e_menu_item_label_set(mi, _("Settings"));
e_util_menu_item_theme_icon_set(mi, "configure");
e_menu_item_callback_set(mi, _backlight_menu_cb_cfg, inst);
m = e_gadcon_client_util_menu_items_append(inst->gcc, m, 0);
e_gadcon_canvas_zone_geometry_get(inst->gcc->gadcon, &x, &y, NULL, NULL);
e_menu_activate_mouse(m, zone, x + ev->output.x, y + ev->output.y,
1, 1, E_MENU_POP_DIRECTION_AUTO, ev->timestamp);
evas_event_feed_mouse_up(inst->gcc->gadcon->evas, ev->button,
EVAS_BUTTON_NONE, ev->timestamp, NULL);
}
}
static void
_backlight_cb_mouse_wheel(void *data, Evas *evas EINA_UNUSED, Evas_Object *obj EINA_UNUSED, void *event)
{
Evas_Event_Mouse_Wheel *ev = event;
Instance *inst = data;
inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
if (ev->z > 0)
_backlight_level_set(inst, inst->val - 0.1, EINA_FALSE);
else if (ev->z < 0)
_backlight_level_set(inst, inst->val + 0.1, EINA_FALSE);
}
static E_Gadcon_Client *
_gc_init(E_Gadcon *gc, const char *name, const char *id, const char *style)
{
Evas_Object *o;
E_Gadcon_Client *gcc;
Instance *inst;
inst = E_NEW(Instance, 1);
o = edje_object_add(gc->evas);
e_theme_edje_object_set(o, "base/theme/modules/backlight",
"e/modules/backlight/main");
evas_object_show(o);
gcc = e_gadcon_client_new(gc, name, id, style, o);
gcc->data = inst;
inst->gcc = gcc;
inst->o_backlight = o;
inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
_backlight_gadget_update(inst);
evas_object_event_callback_add(inst->o_backlight,
EVAS_CALLBACK_MOUSE_DOWN,
_backlight_cb_mouse_down,
inst);
evas_object_event_callback_add(inst->o_backlight,
EVAS_CALLBACK_MOUSE_WHEEL,
_backlight_cb_mouse_wheel,
inst);
backlight_instances = eina_list_append(backlight_instances, inst);
return gcc;
}
static void
_gc_shutdown(E_Gadcon_Client *gcc)
{
Instance *inst;
inst = gcc->data;
_backlight_popup_free(inst);
backlight_instances = eina_list_remove(backlight_instances, inst);
evas_object_del(inst->o_backlight);
free(inst);
}
static void
_gc_orient(E_Gadcon_Client *gcc, E_Gadcon_Orient orient EINA_UNUSED)
{
Instance *inst;
Evas_Coord mw, mh;
inst = gcc->data;
mw = 0, mh = 0;
edje_object_size_min_get(inst->o_backlight, &mw, &mh);
if ((mw < 1) || (mh < 1))
edje_object_size_min_calc(inst->o_backlight, &mw, &mh);
if (mw < 4) mw = 4;
if (mh < 4) mh = 4;
e_gadcon_client_aspect_set(gcc, mw, mh);
e_gadcon_client_min_size_set(gcc, mw, mh);
}
static const char *
_gc_label(const E_Gadcon_Client_Class *client_class EINA_UNUSED)
{
return _("Backlight");
}
static Evas_Object *
_gc_icon(const E_Gadcon_Client_Class *client_class EINA_UNUSED, Evas *evas)
{
Evas_Object *o;
char buf[4096];
o = edje_object_add(evas);
snprintf(buf, sizeof(buf), "%s/e-module-backlight.edj",
e_module_dir_get(backlight_module));
edje_object_file_set(o, buf, "icon");
return o;
}
static const char *
_gc_id_new(const E_Gadcon_Client_Class *client_class)
{
static char buf[4096];
snprintf(buf, sizeof(buf), "%s.%d", client_class->name,
eina_list_count(backlight_instances) + 1);
return buf;
}
static Eina_Bool
_backlight_popup_timer_cb(void *data)
{
Instance *inst;
inst = data;
if (inst->popup)
_backlight_popup_del_cb(inst->popup);
inst->popup_timer = NULL;
return ECORE_CALLBACK_CANCEL;
}
static void
_backlight_popup_timer_new(Instance *inst)
{
if (inst->popup)
{
if (inst->popup_timer)
{
ecore_timer_del(inst->popup_timer);
e_widget_slider_value_double_set(inst->o_slider, inst->val);
inst->popup_timer = ecore_timer_loop_add(1.0, _backlight_popup_timer_cb, inst);
}
}
else
{
_backlight_popup_new(inst);
inst->popup_timer = ecore_timer_loop_add(1.0, _backlight_popup_timer_cb, inst);
}
}
static void
_e_mod_action_cb(E_Object *obj EINA_UNUSED,
const char *params)
{
Eina_List *l;
Instance *inst;
EINA_LIST_FOREACH(backlight_instances, l, inst)
{
if (!params)
{
if (inst->popup) _backlight_popup_free(inst);
else _backlight_popup_new(inst);
}
else
{
_backlight_level_set(inst, inst->val + atof(params), EINA_FALSE);
_backlight_popup_timer_new(inst);
}
}
}
static Eina_Bool
_backlight_cb_mod_init_end(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
{
Eina_List *l;
Instance *inst;
EINA_LIST_FOREACH(backlight_instances, l, inst)
{
inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
_backlight_gadget_update(inst);
}
return ECORE_CALLBACK_RENEW;
}
static Eina_Bool
_backlight_cb_changed(void *d EINA_UNUSED, int type EINA_UNUSED, void *ev EINA_UNUSED)
{
Eina_List *l;
Instance *inst;
EINA_LIST_FOREACH(backlight_instances, l, inst)
{
inst->val = e_backlight_level_get(inst->gcc->gadcon->zone);
_backlight_gadget_update(inst);
}
return ECORE_CALLBACK_RENEW;
}
/* module setup */
E_API E_Module_Api e_modapi =
{
E_MODULE_API_VERSION,
"Backlight"
};
E_API void *
e_modapi_init(E_Module *m)
{
e_modapi_gadget_init(m);
backlight_module = m;
e_gadcon_provider_register(&_gadcon_class);
E_LIST_HANDLER_APPEND(handlers, E_EVENT_BACKLIGHT_CHANGE, _backlight_cb_changed, NULL);
E_LIST_HANDLER_APPEND(handlers, E_EVENT_MODULE_INIT_END, _backlight_cb_mod_init_end, NULL);
act = e_action_add("backlight");
if (act)
{
act->func.go = _e_mod_action_cb;
e_action_predef_name_set(N_("Screen"), N_("Backlight Controls"), "backlight",
NULL, "syntax: brightness change(-1.0 - 1.0), example: -0.1", 1);
}
return m;
}
E_API int
e_modapi_shutdown(E_Module *m)
{
e_modapi_gadget_shutdown(m);
if (act)
{
e_action_predef_name_del("Screen", "Backlight Controls");
e_action_del("backlight");
act = NULL;
}
E_FREE_LIST(handlers, ecore_event_handler_del);
e_gadcon_provider_unregister(&_gadcon_class);
return 1;
}
E_API int
e_modapi_save(E_Module *m)
{
e_modapi_gadget_save(m);
return 1;
}