raster pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=f277ab71e71d43bef04473d1ddf2a0b4cc6c7c0f

commit f277ab71e71d43bef04473d1ddf2a0b4cc6c7c0f
Author: Carsten Haitzler (Rasterman) <ras...@rasterman.com>
Date:   Tue Jan 14 11:34:24 2020 +0000

    e backlight - move to the new e system tool for backlight
    
    no improvements like per screen brightness... but a straight
    conversion to the new system tool which simplifies e backlight a lot.
    
    it'd be betetr to use the new system also to read backlight value and
    list lightss etc ... but for now this is a good first stage.
---
 src/bin/e_backlight.c      |  57 +--------------
 src/bin/e_backlight_main.c | 177 ---------------------------------------------
 src/bin/meson.build        |  11 ---
 3 files changed, 2 insertions(+), 243 deletions(-)

diff --git a/src/bin/e_backlight.c b/src/bin/e_backlight.c
index 2bced6766..6ff1eaedc 100644
--- a/src/bin/e_backlight.c
+++ b/src/bin/e_backlight.c
@@ -32,16 +32,10 @@ static Eina_Bool bl_avail = EINA_TRUE;
 static Eina_Bool xbl_avail = EINA_FALSE;
 #endif
 #if defined(HAVE_EEZE) || defined(__FreeBSD_kernel__)
-static double bl_delayval = 1.0;
-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;
+const char *bl_sysval = NULL;
 
 static void      _bl_sys_find(void);
 static void      _bl_sys_level_get(void);
-static Eina_Bool _e_bl_cb_exit(void *data EINA_UNUSED, int type EINA_UNUSED, 
void *event);
 static void      _bl_sys_level_set(double val);
 #endif
 #ifdef __FreeBSD_kernel__
@@ -88,10 +82,6 @@ e_backlight_shutdown(void)
 #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
 
@@ -477,53 +467,10 @@ _bl_sys_level_get(void)
 #endif  // HAVE_EEZE
 
 #if defined(HAVE_EEZE) || defined(__FreeBSD_kernel__)
-static Eina_Bool
-_e_bl_cb_ext_delay(void *data EINA_UNUSED)
-{
-   bl_sys_set_exe_ready = EINA_TRUE;
-   if (bl_sys_pending_set)
-     {
-        bl_sys_pending_set = EINA_FALSE;
-
-        _bl_sys_level_set(bl_delayval);
-     }
-   return EINA_FALSE;
-}
-
-static Eina_Bool
-_e_bl_cb_exit(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
-{
-   Ecore_Exe_Event_Del *ev;
-
-   ev = event;
-   if (ev->exe == bl_sys_set_exe)
-     {
-        bl_sys_set_exe_ready = EINA_FALSE;
-        bl_sys_set_exe = NULL;
-        ecore_timer_loop_add(0.05, _e_bl_cb_ext_delay, NULL);
-     }
-   return ECORE_CALLBACK_RENEW;
-}
-
 static void
 _bl_sys_level_set(double val)
 {
-   char buf[PATH_MAX];
-
-   if (!bl_sys_exit_handler)
-     bl_sys_exit_handler = ecore_event_handler_add(ECORE_EXE_EVENT_DEL,
-                                                   _e_bl_cb_exit, NULL);
-   bl_delayval = val;
-   if ((bl_sys_set_exe) || (!bl_sys_set_exe_ready))
-     {
-        bl_sys_pending_set = EINA_TRUE;
-        return;
-     }
-//   fprintf(stderr, "SET: %1.3f\n", val);
-   snprintf(buf, sizeof(buf),
-            "%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);
+   e_system_send("bklight-set", "%s %i", bl_sysval, (int)(val * 1000.0));
 }
 #endif  // HAVE_EEZE || __FreeBSD_kernel__
 
diff --git a/src/bin/e_backlight_main.c b/src/bin/e_backlight_main.c
deleted file mode 100644
index 6542f770d..000000000
--- a/src/bin/e_backlight_main.c
+++ /dev/null
@@ -1,177 +0,0 @@
-#include "config.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <dirent.h>
-#include <fcntl.h>
-
-#if defined(HAVE_EEZE)
-#include <Eeze.h>
-
-/* local subsystem functions */
-static int
-_bl_write_file(const char *file, int val)
-{
-   char buf[256];
-   int fd = open(file, O_WRONLY);
-   if (fd < 0)
-     {
-        perror("open");
-        return -1;
-     }
-   snprintf(buf, sizeof(buf), "%d", val);
-   if (write(fd, buf, strlen(buf)) != (int)strlen(buf))
-     {
-        perror("write");
-        close(fd);
-        return -1;
-     }
-   close(fd);
-   return 0;
-}
-
-static int
-_bl_set(const char *dev, int level)
-{
-   const char *f, *str;
-   int maxlevel = 0, curlevel = -1;
-   Eina_List *devs, *l;
-   Eina_Bool devok = EINA_FALSE;
-   char buf[4096] = "";
-
-   eeze_init();
-   devs = eeze_udev_find_by_filter("backlight", NULL, NULL);
-   if (!devs)
-     {
-        devs = eeze_udev_find_by_filter("leds", NULL, NULL);
-        if (!devs) return -1;
-     }
-   if (devs)
-     {
-        EINA_LIST_FOREACH(devs, l, f)
-          {
-             if (!strcmp(f, dev))
-               {
-                  dev = f;
-                  devok = EINA_TRUE;
-                  break;
-               }
-          }
-     }
-
-   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) / 1000;
-        if (curlevel > maxlevel) curlevel = maxlevel;
-        else if (curlevel < 0)
-          curlevel = 0;
-        snprintf(buf, sizeof(buf), "%s/brightness", f);
-        return _bl_write_file(buf, curlevel);
-     }
-
-   EINA_LIST_FREE(devs, f)
-     eina_stringshare_del(f);
-   return -1;
-}
-#elif defined(__FreeBSD_kernel__)  // !HAVE_EEZE
-#include <sys/sysctl.h>
-#include <errno.h>
-
-static const char *bl_acpi_sysctl = "hw.acpi.video.lcd0.brightness";
-
-static int
-_bl_set(const char *dev, int level)
-{
-   int rc;
-
-   level = ((100 * level) + 500) / 1000;
-   if (level > 100) level = 100;
-   else if (level < 0) level = 0;
-
-   // Be slightly careful if making this more permissive. We don't want to
-   // allow non-root users to set arbitrary integer sysctls between 0-100.
-   if (strcmp(bl_acpi_sysctl, dev) != 0)
-     {
-        printf("bad device: %s\n", dev);
-        return -1;
-     }
-
-   rc = sysctlbyname(bl_acpi_sysctl, NULL, NULL, &level, sizeof(level));
-   if (rc < 0)
-     {
-        perror("sysctlbyname");
-        return -1;
-     }
-   return 0;
-}
-#endif  // __FreeBSD_kernel__
-
-#if defined(HAVE_EEZE) || defined(__FreeBSD_kernel__)
-int
-main(int argc, char **argv)
-{
-   const char *dev = NULL;
-   int i, level;
-
-   for (i = 1; i < argc; i++)
-     {
-        if ((!strcmp(argv[i], "-h")) ||
-            (!strcmp(argv[i], "-help")) ||
-            (!strcmp(argv[i], "--help")))
-          {
-             printf("This is an internal tool for Enlightenment.\n"
-                    "do not use it.\n");
-             exit(0);
-          }
-     }
-   if (argc == 3)
-     {
-        level = atoi(argv[1]);
-        dev = argv[2];
-     }
-   else
-     exit(1);
-
-   if (!dev) return -1;
-
-   if (setuid(0) != 0)
-     {
-        printf("ERROR: UNABLE TO ASSUME ROOT PRIVILEGES\n");
-        exit(5);
-     }
-   if (setgid(0) != 0)
-     {
-        printf("ERROR: UNABLE TO ASSUME ROOT GROUP PRIVILEGES\n");
-        exit(7);
-     }
-
-   return _bl_set(dev, level);
-}
-#else  // !HAVE_EEZE && !__FreeBSD_kernel__
-int
-main(void)
-{
-   return -1;
-}
-#endif
diff --git a/src/bin/meson.build b/src/bin/meson.build
index fc0dc3480..656a12b83 100644
--- a/src/bin/meson.build
+++ b/src/bin/meson.build
@@ -489,17 +489,6 @@ executable('enlightenment_askpass',
            install     : true
           )
 
-executable('enlightenment_backlight',
-           [ 'e_backlight_main.c' ],
-           include_directories: include_directories('../..'),
-           dependencies       : [ dep_eina, dep_eeze ],
-           c_args             : suid_cflags,
-           link_args          : suid_ldflags,
-           install_dir        : dir_e_utils,
-           install            : true
-          )
-suid_exes += join_paths(dir_e_utils, 'enlightenment_backlight')
-
 executable('enlightenment_fm_op',
            [ 'e_fm_op.c' ],
            include_directories: include_directories('../..'),

-- 


Reply via email to