backlight internals now use eeze

this probably breaks some stuff, mail me some good debug info


SVN revision: 64512
This commit is contained in:
Mike Blumenkrantz 2011-10-29 18:45:43 +00:00
parent 8b15afb842
commit db88f8f57d
4 changed files with 82 additions and 240 deletions

View File

@ -314,7 +314,7 @@ AC_ARG_ENABLE([device-udev],
AC_CACHE_VAL([e_cv_want_device_udev], [e_cv_want_device_udev=yes]))
if test "x$e_cv_want_device_udev" != "xno";then
PKG_CHECK_EXISTS([eeze >= 1.0.0],
PKG_CHECK_MODULES([EEZE], [eeze >= 1.0.0],
[
device_backend=eeze
AC_DEFINE_UNQUOTED([HAVE_EEZE],[1],[enable udev support])

View File

@ -29,9 +29,12 @@ enlightenment_fm_op \
enlightenment_init \
enlightenment_sys \
enlightenment_thumb \
enlightenment_backlight \
enlightenment_alert
if HAVE_EEZE
internal_bin_PROGRAMS += enlightenment_backlight
endif
ENLIGHTENMENTHEADERS = \
e_about.h \
e_acpi.h \
@ -367,10 +370,13 @@ e_sys_main.c
enlightenment_sys_LDADD = @E_SYS_LIBS@
if HAVE_EEZE
enlightenment_backlight_SOURCES = \
e_backlight_main.c
enlightenment_backlight_LDADD =
enlightenment_backlight_CFLAGS = @EEZE_CFLAGS@
enlightenment_backlight_LDADD = @EEZE_LIBS@
endif
enlightenment_init_SOURCES = \
e_init_main.c \
@ -388,9 +394,13 @@ enlightenment_alert_CFLAGS = @E_ALERT_CFLAGS@
# and before internal_bin_PROGRAMS are installed. install-data-hook is
# run after both
setuid_root_mode = a=rx,u+xs
if HAVE_EEZE
install-data-hook:
@chmod $(setuid_root_mode) $(DESTDIR)$(libdir)/enlightenment/utils/enlightenment_sys$(EXEEXT) || true
@chmod $(setuid_root_mode) $(DESTDIR)$(libdir)/enlightenment/utils/enlightenment_backlight$(EXEEXT) || true
else
install-data-hook:
@chmod $(setuid_root_mode) $(DESTDIR)$(libdir)/enlightenment/utils/enlightenment_sys$(EXEEXT) || true
endif
installed_headersdir = $(prefix)/include/enlightenment
installed_headers_DATA = $(ENLIGHTENMENTHEADERS)

View File

@ -1,4 +1,7 @@
#include "e.h"
#ifdef HAVE_EEZE
# include <Eeze.h>
#endif
// FIXME: backlight should be tied per zone but this implementation is just
// a signleton right now as thats 99% of use cases. but api supports
@ -13,26 +16,29 @@ static double bl_animval = 1.0;
static E_Backlight_Mode bl_mode = E_BACKLIGHT_MODE_NORMAL;
static int sysmode = MODE_NONE;
static Ecore_Animator *bl_anim = NULL;
static const char *bl_sysvalmax = NULL;
static void _e_backlight_update(E_Zone *zone);
static void _e_backlight_set(E_Zone *zone, double val);
static Eina_Bool _bl_anim(void *data, double pos);
#ifdef HAVE_EEZE
static const char *bl_sysval = NULL;
static Ecore_Event_Handler *bl_sys_exit_handler = NULL;
static Ecore_Exe *bl_sys_set_exe = NULL;
static Eina_Bool bl_sys_pending_set = EINA_FALSE;
static Eina_Bool bl_sys_set_exe_ready = EINA_TRUE;
static void _e_backlight_update(E_Zone *zone);
static void _e_backlight_set(E_Zone *zone, double val);
static Eina_Bool _bl_anim(void *data, double pos);
static char *_bl_read_file(const char *file);
static int _bl_sys_num_get(const char *file);
static void _bl_sys_find(void);
static void _bl_sys_level_get(void);
static Eina_Bool _e_bl_cb_exit(void *data __UNUSED__, int type __UNUSED__, void *event);
static void _bl_sys_level_set(double val);
#endif
EINTERN int
e_backlight_init(void)
{
#ifdef HAVE_EEZE
eeze_init();
#endif
e_backlight_update();
e_backlight_level_set(NULL, 0.0, 0.0);
e_backlight_level_set(NULL, e_config->backlight.normal, 1.0);
@ -44,14 +50,15 @@ e_backlight_shutdown(void)
{
if (bl_anim) ecore_animator_del(bl_anim);
bl_anim = NULL;
if (bl_sysval) eina_stringshare_del(bl_sysvalmax);
bl_sysvalmax = NULL;
#ifdef HAVE_EEZE
if (bl_sysval) eina_stringshare_del(bl_sysval);
bl_sysval = NULL;
if (bl_sys_exit_handler) ecore_event_handler_del(bl_sys_exit_handler);
bl_sys_exit_handler = NULL;
bl_sys_set_exe = NULL;
bl_sys_pending_set = EINA_FALSE;
eeze_shutdown();
#endif
return 1;
}
@ -164,6 +171,7 @@ _e_backlight_update(E_Zone *zone)
bl_val = x_bl;
sysmode = MODE_RANDR;
}
#ifdef HAVE_EEZE
else
{
_bl_sys_find();
@ -173,6 +181,7 @@ _e_backlight_update(E_Zone *zone)
_bl_sys_level_get();
}
}
#endif
}
static void
@ -192,6 +201,7 @@ _e_backlight_set(E_Zone *zone, double val)
}
if (out) free(out);
}
#ifdef HAVE_EEZE
else if (sysmode == MODE_SYS)
{
if (bl_sysval)
@ -199,6 +209,7 @@ _e_backlight_set(E_Zone *zone, double val)
_bl_sys_level_set(val);
}
}
#endif
}
static Eina_Bool
@ -219,149 +230,39 @@ _bl_anim(void *data, double pos)
return EINA_TRUE;
}
static char *
_bl_read_file(const char *file)
{
FILE *f = fopen(file, "r");
size_t len;
char buf[4096], *p;
if (!f) return NULL;
len = fread(buf, 1, sizeof(buf) - 1, f);
if (len == 0)
{
fclose(f);
return NULL;
}
buf[len] = 0;
for (p = buf; *p; p++)
{
if (p[0] == '\n') p[0] = 0;
}
fclose(f);
return strdup(buf);
}
static int
_bl_sys_num_get(const char *file)
{
char *max;
int maxval = -1;
max = _bl_read_file(file);
if (max)
{
maxval = atoi(max);
free(max);
}
return maxval;
}
typedef struct _Bl_Entry
{
char type;
const char *base;
const char *max;
const char *set;
} Bl_Entry;
static const Bl_Entry search[] =
{
{ 'F', "/sys/devices/virtual/backlight/acpi_video0", "max_brightness", "brightness" },
{ 'D', "/sys/devices/virtual/backlight", "max_brightness", "brightness" },
{ 'F', "/sys/class/leds/lcd-backlight", "max_brightness", "brightness" },
{ 'F', "/sys/class/backlight/acpi_video0", "max_brightness", "brightness" },
{ 'D', "/sys/class/backlight", "max_brightness", "brightness" }
};
#ifdef HAVE_EEZE
static void
_bl_sys_find(void)
{
int i, curlevel = 0;
char *valstr;
char file[4096] = "";
Eina_List *devs;
const char *f;
for (i = 0; i < (int)(sizeof(search) / sizeof(Bl_Entry)); i++)
{
char buf[4096];
const Bl_Entry *b = &(search[i]);
if (b->type == 'F')
{
snprintf(buf, sizeof(buf), "%s/%s", b->base, b->set);
valstr = _bl_read_file(buf);
if (valstr)
{
curlevel = atoi(valstr);
if (curlevel < 0)
{
free(valstr);
valstr = NULL;
}
else
{
bl_sysval = eina_stringshare_add(buf);
snprintf(file, sizeof(file), "%s/%s", b->base, b->max);
bl_sysvalmax = eina_stringshare_add(file);
free(valstr);
valstr = NULL;
}
}
}
else if (b->type == 'D')
{
DIR *dirp = opendir(b->base);
struct dirent *dp;
if (dirp)
{
while ((dp = readdir(dirp)))
{
if ((strcmp(dp->d_name, ".")) &&
(strcmp(dp->d_name, "..")))
{
snprintf(buf, sizeof(buf), "%s/%s/%s",
b->base, dp->d_name, b->set);
valstr = _bl_read_file(buf);
if (valstr)
{
curlevel = atoi(valstr);
if (curlevel < 0)
{
free(valstr);
valstr = NULL;
}
else
{
bl_sysval = eina_stringshare_add(buf);
snprintf(file, sizeof(file), "%s/%s/%s",
b->base, dp->d_name, b->max);
bl_sysvalmax = eina_stringshare_add(file);
free(valstr);
valstr = NULL;
break;
}
}
}
}
closedir(dirp);
}
}
if (file[0]) break;
}
devs = eeze_udev_find_by_filter("backlight", NULL, NULL);
if (!devs) return;
EINA_LIST_FREE(devs, f)
bl_sysval = f;
}
static void
_bl_sys_level_get(void)
{
int maxval, val;
if (!bl_sysval) return;
maxval = _bl_sys_num_get(bl_sysvalmax);
const char *str;
str = eeze_udev_syspath_get_sysattr(bl_sysval, "max_brightness");
if (!str) return;
maxval = atoi(str);
eina_stringshare_del(str);
if (maxval <= 0) maxval = 255;
val = _bl_sys_num_get(bl_sysval);
str = eeze_udev_syspath_get_sysattr(bl_sysval, "brightness");
if (!str) return;
val = atoi(str);
eina_stringshare_del(str);
if ((val >= 0) && (val <= maxval))
bl_val = (double)val / (double)maxval;
// printf("GET: %i/%i (%1.3f)\n", val, maxval, bl_val);
bl_val = (double)val / (double)maxval;
// printf("GET: %i/%i (%1.3f)\n", val, maxval, bl_val);
}
static Eina_Bool
@ -410,3 +311,4 @@ _bl_sys_level_set(double val)
e_prefix_lib_get(), (int)(val * 1000.0));
bl_sys_set_exe = ecore_exe_run(buf, NULL);
}
#endif

View File

@ -9,29 +9,9 @@
#include <dirent.h>
#include <fcntl.h>
/* local subsystem functions */
static char *
_bl_read_file(const char *file)
{
FILE *f = fopen(file, "r");
size_t len;
char buf[4096], *p;
if (!f) return NULL;
len = fread(buf, 1, sizeof(buf) - 1, f);
if (len == 0)
{
fclose(f);
return NULL;
}
buf[len] = 0;
for (p = buf; *p; p++)
{
if (p[0] == '\n') p[0] = 0;
}
fclose(f);
return strdup(buf);
}
#include <Eeze.h>
/* local subsystem functions */
static int
_bl_write_file(const char *file, int val)
{
@ -78,8 +58,9 @@ main(int argc, char **argv)
int i;
int level;
char *valstr;
const char *f;
int maxlevel = 0, curlevel = -1;
char file[4096] = "";
Eina_List *devs;
char buf[4096] = "";
for (i = 1; i < argc; i++)
@ -109,87 +90,36 @@ main(int argc, char **argv)
exit(7);
}
for (i = 0; i < (int)(sizeof(search) / sizeof(Bl_Entry)); i++)
eeze_init();
devs = eeze_udev_find_by_filter("backlight", NULL, NULL);
if (!devs) return -1;
EINA_LIST_FREE(devs, f)
{
const Bl_Entry *b = &(search[i]);
if (b->type == 'F')
const char *str;
str = eeze_udev_syspath_get_sysattr(f, "max_brightness");
if (str)
{
snprintf(buf, sizeof(buf), "%s/%s", b->base, b->set);
valstr = _bl_read_file(buf);
if (valstr)
maxlevel = atoi(str);
eina_stringshare_del(str);
str = eeze_udev_syspath_get_sysattr(f, "brightness");
if (str)
{
curlevel = atoi(valstr);
if (curlevel < 0)
{
free(valstr);
valstr = NULL;
}
else
{
snprintf(file, sizeof(file), "%s/%s", b->base, b->max);
free(valstr);
valstr = _bl_read_file(file);
if (valstr)
{
maxlevel = atoi(valstr);
free(valstr);
valstr = NULL;
}
}
curlevel = atoi(str);
eina_stringshare_del(str);
}
}
else if (b->type == 'D')
if (maxlevel <= 0) maxlevel = 255;
if (curlevel >= 0)
{
DIR *dirp = opendir(b->base);
struct dirent *dp;
if (dirp)
{
while ((dp = readdir(dirp)))
{
if ((strcmp(dp->d_name, ".")) &&
(strcmp(dp->d_name, "..")))
{
snprintf(buf, sizeof(buf), "%s/%s/%s",
b->base, dp->d_name, b->set);
valstr = _bl_read_file(buf);
if (valstr)
{
curlevel = atoi(valstr);
if (curlevel < 0)
{
free(valstr);
valstr = NULL;
}
else
{
snprintf(file, sizeof(file), "%s/%s/%s",
b->base, dp->d_name, b->max);
free(valstr);
valstr = _bl_read_file(file);
if (valstr)
{
maxlevel = atoi(valstr);
free(valstr);
valstr = NULL;
}
break;
}
}
}
}
closedir(dirp);
}
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);
}
if (file[0]) break;
}
if (maxlevel <= 0) maxlevel = 255;
if (curlevel >= 0)
{
curlevel = ((maxlevel * level) + (500 / maxlevel)) / 1000;
// printf("SET: %i, %i/%i\n", level, curlevel, maxlevel);
return _bl_write_file(buf, curlevel);
eina_stringshare_del(f);
}
return -1;
}