provide a way to select backlight device or output and then use it.
SVN revision: 76709
This commit is contained in:
parent
45ded3832b
commit
6669ca71a3
|
@ -15,6 +15,7 @@ static double bl_val = 1.0;
|
|||
static double bl_animval = 1.0;
|
||||
static int sysmode = MODE_NONE;
|
||||
static Ecore_Animator *bl_anim = NULL;
|
||||
static Eina_List *bl_devs = NULL;
|
||||
|
||||
static Ecore_Event_Handler *_e_backlight_handler_config_mode = NULL;
|
||||
static Ecore_Event_Handler *_e_backlight_handler_border_fullscreen = NULL;
|
||||
|
@ -96,8 +97,11 @@ e_backlight_init(void)
|
|||
EINTERN int
|
||||
e_backlight_shutdown(void)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
if (bl_anim) ecore_animator_del(bl_anim);
|
||||
bl_anim = NULL;
|
||||
EINA_LIST_FREE(bl_devs, s) eina_stringshare_del(s);
|
||||
#ifdef HAVE_EEZE
|
||||
if (bl_sysval) eina_stringshare_del(bl_sysval);
|
||||
bl_sysval = NULL;
|
||||
|
@ -272,6 +276,12 @@ e_backlight_mode_get(E_Zone *zone __UNUSED__)
|
|||
return e_config->backlight.mode;
|
||||
}
|
||||
|
||||
EAPI const Eina_List *
|
||||
e_backlight_devices_get(void)
|
||||
{
|
||||
return bl_devs;
|
||||
}
|
||||
|
||||
/* local subsystem functions */
|
||||
|
||||
static Eina_Bool
|
||||
|
@ -295,13 +305,33 @@ _e_backlight_update(E_Zone *zone)
|
|||
double x_bl = -1.0;
|
||||
Ecore_X_Window root;
|
||||
Ecore_X_Randr_Output *out;
|
||||
int num = 0;
|
||||
int i, num = 0;
|
||||
|
||||
root = zone->container->manager->root;
|
||||
// try randr
|
||||
out = ecore_x_randr_window_outputs_get(root, &num);
|
||||
if ((out) && (num > 0) && (ecore_x_randr_output_backlight_available()))
|
||||
x_bl = ecore_x_randr_output_backlight_level_get(root, out[0]);
|
||||
{
|
||||
char *name;
|
||||
const char *s;
|
||||
Eina_Bool gotten = EINA_FALSE;
|
||||
|
||||
EINA_LIST_FREE(bl_devs, s) eina_stringshare_del(s);
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
name = ecore_x_randr_output_name_get(root, out[i], NULL);
|
||||
bl_devs = eina_list_append(bl_devs, eina_stringshare_add(name));
|
||||
if ((name) && (e_config->backlight.sysdev) &&
|
||||
(!strcmp(name, e_config->backlight.sysdev)))
|
||||
{
|
||||
x_bl = ecore_x_randr_output_backlight_level_get(root, out[i]);
|
||||
gotten = EINA_TRUE;
|
||||
}
|
||||
if (name) free(name);
|
||||
}
|
||||
if (!gotten)
|
||||
x_bl = ecore_x_randr_output_backlight_level_get(root, out[0]);
|
||||
}
|
||||
if (out) free(out);
|
||||
if (x_bl >= 0.0)
|
||||
{
|
||||
|
@ -327,13 +357,33 @@ _e_backlight_set(E_Zone *zone, double val)
|
|||
{
|
||||
Ecore_X_Window root;
|
||||
Ecore_X_Randr_Output *out;
|
||||
int num = 0;
|
||||
int num = 0, i;
|
||||
char *name;
|
||||
|
||||
root = zone->container->manager->root;
|
||||
out = ecore_x_randr_window_outputs_get(root, &num);
|
||||
if ((out) && (num > 0))
|
||||
{
|
||||
ecore_x_randr_output_backlight_level_set(root, out[0], val);
|
||||
Eina_Bool gotten = EINA_FALSE;
|
||||
for (i = 0; i < num; i++)
|
||||
{
|
||||
name = ecore_x_randr_output_name_get(root, out[i], NULL);
|
||||
if (name)
|
||||
{
|
||||
if ((e_config->backlight.sysdev) &&
|
||||
(!strcmp(name, e_config->backlight.sysdev)))
|
||||
{
|
||||
ecore_x_randr_output_backlight_level_set(root, out[i], val);
|
||||
gotten = EINA_TRUE;
|
||||
}
|
||||
free(name);
|
||||
}
|
||||
}
|
||||
if (!gotten)
|
||||
{
|
||||
for (i = 0; i < num; i++)
|
||||
ecore_x_randr_output_backlight_level_set(root, out[i], val);
|
||||
}
|
||||
}
|
||||
if (out) free(out);
|
||||
}
|
||||
|
@ -370,8 +420,10 @@ _bl_anim(void *data, double pos)
|
|||
static void
|
||||
_bl_sys_find(void)
|
||||
{
|
||||
Eina_List *devs;
|
||||
const char *f;
|
||||
Eina_List *l, *devs, *pdevs = NULL;
|
||||
Eina_Bool use;
|
||||
const char *f, *s;
|
||||
int v;
|
||||
|
||||
devs = eeze_udev_find_by_filter("backlight", NULL, NULL);
|
||||
if (!devs)
|
||||
|
@ -382,10 +434,6 @@ _bl_sys_find(void)
|
|||
}
|
||||
if (eina_list_count(devs) > 1)
|
||||
{
|
||||
const char *s = NULL;
|
||||
Eina_List *l;
|
||||
Eina_Bool use = EINA_FALSE;
|
||||
|
||||
/* prefer backlights of type "firmware" where available */
|
||||
EINA_LIST_FOREACH(devs, l, f)
|
||||
{
|
||||
|
@ -393,18 +441,77 @@ _bl_sys_find(void)
|
|||
use = (s && (!strcmp(s, "firmware")));
|
||||
eina_stringshare_del(s);
|
||||
if (!use) continue;
|
||||
s = eeze_udev_syspath_get_sysattr(f, "brightness");
|
||||
if (!s) continue;
|
||||
v = atoi(s);
|
||||
eina_stringshare_del(s);
|
||||
if (v < 0) continue;
|
||||
pdevs = eina_list_append(pdevs, eina_stringshare_add(f));
|
||||
eina_stringshare_del(f);
|
||||
l->data = NULL;
|
||||
eina_stringshare_del(bl_sysval);
|
||||
bl_sysval = f;
|
||||
EINA_LIST_FREE(devs, f)
|
||||
eina_stringshare_del(f);
|
||||
return;
|
||||
}
|
||||
EINA_LIST_FOREACH(devs, l, f)
|
||||
{
|
||||
if (!l->data) continue;
|
||||
s = eeze_udev_syspath_get_sysattr(f, "brightness");
|
||||
if (!s) continue;
|
||||
v = atoi(s);
|
||||
eina_stringshare_del(s);
|
||||
if (v < 0) continue;
|
||||
pdevs = eina_list_append(pdevs, eina_stringshare_add(f));
|
||||
}
|
||||
}
|
||||
if (!pdevs)
|
||||
{
|
||||
/* add the other backlight or led's if none found */
|
||||
EINA_LIST_FOREACH(devs, l, f)
|
||||
{
|
||||
use = EINA_FALSE;
|
||||
s = eeze_udev_syspath_get_sysattr(f, "brightness");
|
||||
if (!s) continue;
|
||||
v = atoi(s);
|
||||
eina_stringshare_del(s);
|
||||
if (v < 0) continue;
|
||||
pdevs = eina_list_append(pdevs, eina_stringshare_add(f));
|
||||
}
|
||||
}
|
||||
/* clear out original devs list now we've filtered */
|
||||
EINA_LIST_FREE(devs, f)
|
||||
{
|
||||
eina_stringshare_replace(&bl_sysval, NULL);
|
||||
bl_sysval = f;
|
||||
if (f) eina_stringshare_del(f);
|
||||
}
|
||||
/* clear out old configured bl sysval */
|
||||
if (bl_sysval)
|
||||
{
|
||||
eina_stringshare_del(bl_sysval);
|
||||
bl_sysval = NULL;
|
||||
}
|
||||
EINA_LIST_FREE(bl_devs, s) eina_stringshare_del(s);
|
||||
/* if configured backlight is there - use it, or if not use first */
|
||||
EINA_LIST_FOREACH(pdevs, l, f)
|
||||
{
|
||||
bl_devs = eina_list_append(bl_devs, eina_stringshare_add(f));
|
||||
if (!bl_sysval)
|
||||
{
|
||||
if ((e_config->backlight.sysdev) &&
|
||||
(!strcmp(e_config->backlight.sysdev, f)))
|
||||
bl_sysval = eina_stringshare_add(f);
|
||||
else
|
||||
bl_sysval = eina_stringshare_add(f);
|
||||
}
|
||||
}
|
||||
if (!bl_sysval)
|
||||
{
|
||||
EINA_LIST_FOREACH(pdevs, l, f)
|
||||
{
|
||||
if (!bl_sysval)
|
||||
bl_sysval = eina_stringshare_add(f);
|
||||
}
|
||||
}
|
||||
/* clear out preferred devs list */
|
||||
EINA_LIST_FREE(pdevs, f)
|
||||
{
|
||||
eina_stringshare_del(f);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -472,8 +579,8 @@ _bl_sys_level_set(double val)
|
|||
}
|
||||
// printf("SET: %1.3f\n", val);
|
||||
snprintf(buf, sizeof(buf),
|
||||
"%s/enlightenment/utils/enlightenment_backlight %i",
|
||||
e_prefix_lib_get(), (int)(val * 1000.0));
|
||||
"%s/enlightenment/utils/enlightenment_backlight %i %s",
|
||||
e_prefix_lib_get(), (int)(val * 1000.0), bl_sysval);
|
||||
bl_sys_set_exe = ecore_exe_run(buf, NULL);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -32,6 +32,7 @@ EAPI void e_backlight_level_set(E_Zone *zone, double val, double
|
|||
EAPI double e_backlight_level_get(E_Zone *zone);
|
||||
EAPI void e_backlight_mode_set(E_Zone *zone, E_Backlight_Mode mode);
|
||||
EAPI E_Backlight_Mode e_backlight_mode_get(E_Zone *zone);
|
||||
EAPI const Eina_List *e_backlight_devices_get(void);
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -37,11 +37,10 @@ _bl_write_file(const char *file, int val)
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
int level;
|
||||
const char *f;
|
||||
int i, level, devok = 0;
|
||||
const char *f, *dev = NULL, *str;
|
||||
int maxlevel = 0, curlevel = -1;
|
||||
Eina_List *devs;
|
||||
Eina_List *devs, *l;
|
||||
char buf[4096] = "";
|
||||
|
||||
for (i = 1; i < argc; i++)
|
||||
|
@ -55,10 +54,15 @@ main(int argc, char **argv)
|
|||
exit(0);
|
||||
}
|
||||
}
|
||||
if (argc == 2)
|
||||
level = atoi(argv[1]);
|
||||
if (argc == 3)
|
||||
{
|
||||
level = atoi(argv[1]);
|
||||
dev = argv[2];
|
||||
}
|
||||
else
|
||||
exit(1);
|
||||
|
||||
if (!dev) return -1;
|
||||
|
||||
if (setuid(0) != 0)
|
||||
{
|
||||
|
@ -78,56 +82,44 @@ main(int argc, char **argv)
|
|||
devs = eeze_udev_find_by_filter("leds", NULL, NULL);
|
||||
if (!devs) return -1;
|
||||
}
|
||||
if (eina_list_count(devs) > 1)
|
||||
if (devs)
|
||||
{
|
||||
const char *s = NULL;
|
||||
Eina_List *l, *new = NULL;
|
||||
Eina_Bool use = EINA_FALSE;
|
||||
|
||||
/* prefer backlights of type "firmware" where available */
|
||||
EINA_LIST_FOREACH(devs, l, f)
|
||||
{
|
||||
s = eeze_udev_syspath_get_sysattr(f, "type");
|
||||
use = (s && (!strcmp(s, "firmware")));
|
||||
eina_stringshare_del(s);
|
||||
if (!use) continue;
|
||||
eina_list_move_list(&new, &devs, l);
|
||||
EINA_LIST_FREE(devs, f)
|
||||
eina_stringshare_del(f);
|
||||
devs = new;
|
||||
break;
|
||||
}
|
||||
}
|
||||
EINA_LIST_FREE(devs, f)
|
||||
{
|
||||
const char *str;
|
||||
|
||||
str = eeze_udev_syspath_get_sysattr(f, "max_brightness");
|
||||
if (str)
|
||||
{
|
||||
maxlevel = atoi(str);
|
||||
eina_stringshare_del(str);
|
||||
str = eeze_udev_syspath_get_sysattr(f, "brightness");
|
||||
if (str)
|
||||
if (!strcmp(f, dev))
|
||||
{
|
||||
curlevel = atoi(str);
|
||||
eina_stringshare_del(str);
|
||||
dev = f;
|
||||
devok = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxlevel <= 0) maxlevel = 255;
|
||||
if (curlevel >= 0)
|
||||
{
|
||||
curlevel = ((maxlevel * level) + (500 / maxlevel)) / 1000;
|
||||
// printf("SET: %i, %i/%i\n", level, curlevel, maxlevel);
|
||||
snprintf(buf, sizeof(buf), "%s/brightness", f);
|
||||
return _bl_write_file(buf, curlevel);
|
||||
}
|
||||
eina_stringshare_del(f);
|
||||
/* Currently this will set brightness levels on ALL detected devices
|
||||
If this is not desired, add a break here
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
if (!devok) return -1;
|
||||
|
||||
str = eeze_udev_syspath_get_sysattr(dev, "max_brightness");
|
||||
if (str)
|
||||
{
|
||||
maxlevel = atoi(str);
|
||||
eina_stringshare_del(str);
|
||||
str = eeze_udev_syspath_get_sysattr(dev, "brightness");
|
||||
if (str)
|
||||
{
|
||||
curlevel = atoi(str);
|
||||
eina_stringshare_del(str);
|
||||
}
|
||||
}
|
||||
|
||||
if (maxlevel <= 0) maxlevel = 255;
|
||||
if (curlevel >= 0)
|
||||
{
|
||||
curlevel = ((maxlevel * level) + (500 / maxlevel)) / 1000;
|
||||
snprintf(buf, sizeof(buf), "%s/brightness", f);
|
||||
return _bl_write_file(buf, curlevel);
|
||||
}
|
||||
|
||||
EINA_LIST_FREE(devs, f)
|
||||
eina_stringshare_del(f);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
|
|
@ -896,8 +896,9 @@ e_config_init(void)
|
|||
E_CONFIG_VAL(D, T, backlight.normal, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, backlight.dim, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, backlight.transition, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, backlight.idle_dim, UCHAR);
|
||||
E_CONFIG_VAL(D, T, backlight.timer, DOUBLE);
|
||||
E_CONFIG_VAL(D, T, backlight.sysdev, STR);
|
||||
E_CONFIG_VAL(D, T, backlight.idle_dim, UCHAR);
|
||||
|
||||
E_CONFIG_VAL(D, T, deskenv.load_xrdb, UCHAR);
|
||||
E_CONFIG_VAL(D, T, deskenv.load_xmodmap, UCHAR);
|
||||
|
@ -2152,6 +2153,8 @@ _e_config_free(E_Config *ecf)
|
|||
eina_stringshare_del(ecf->xsettings.net_theme_name);
|
||||
if (ecf->xsettings.gtk_font_name)
|
||||
eina_stringshare_del(ecf->xsettings.gtk_font_name);
|
||||
if (ecf->backlight.sysdev)
|
||||
eina_stringshare_del(ecf->backlight.sysdev);
|
||||
|
||||
E_FREE(ecf);
|
||||
}
|
||||
|
|
|
@ -332,8 +332,9 @@ struct _E_Config
|
|||
double normal; // GUI
|
||||
double dim; // GUI
|
||||
double transition; // GUI
|
||||
unsigned char idle_dim; // GUI
|
||||
double timer; // GUI
|
||||
const char *sysdev; // GUI
|
||||
unsigned char idle_dim; // GUI
|
||||
E_Backlight_Mode mode; /* not saved, display-only */
|
||||
} backlight;
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@ struct _E_Config_Dialog_Data
|
|||
|
||||
Evas_Object *backlight_slider;
|
||||
|
||||
char *bl_dev;
|
||||
|
||||
int enable_idle_dim;
|
||||
|
||||
double backlight_normal;
|
||||
|
@ -110,6 +112,8 @@ static Evas_Object *
|
|||
_advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_Dialog_Data *cfdata)
|
||||
{
|
||||
Evas_Object *o, *ob;
|
||||
Eina_List *devs, *l;
|
||||
const char *s, *label;
|
||||
|
||||
o = e_widget_list_add(evas, 0, 0);
|
||||
/*
|
||||
|
@ -158,6 +162,28 @@ _advanced_create_widgets(E_Config_Dialog *cfd __UNUSED__, Evas *evas, E_Config_D
|
|||
&(cfdata->backlight_transition), NULL, 100);
|
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5);
|
||||
|
||||
devs = (Eina_List *)e_backlight_devices_get();
|
||||
if ((devs) && (eina_list_count(devs) > 1))
|
||||
{
|
||||
int sel = -1, i = 0;
|
||||
|
||||
ob = e_widget_ilist_add(evas, 16, 16, NULL);
|
||||
e_widget_size_min_set(ob, 100, 100);
|
||||
e_widget_list_object_append(o, ob, 1, 1, 0.5);
|
||||
EINA_LIST_FOREACH(devs, l, s)
|
||||
{
|
||||
label = strchr(s, '/');
|
||||
if (!label) label = s;
|
||||
else label++;
|
||||
e_widget_ilist_append(ob, NULL, label, NULL, NULL, s);
|
||||
if ((e_config->backlight.sysdev) &&
|
||||
(!strcmp(e_config->backlight.sysdev, s)))
|
||||
sel = i;
|
||||
i++;
|
||||
}
|
||||
e_widget_ilist_go(ob);
|
||||
if (sel >= 0) e_widget_ilist_selected_set(ob, sel);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue