Hello community,

here is the log from the commit of package brightnessctl for openSUSE:Factory 
checked in at 2020-02-04 19:55:41
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/brightnessctl (Old)
 and      /work/SRC/openSUSE:Factory/.brightnessctl.new.26092 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "brightnessctl"

Tue Feb  4 19:55:41 2020 rev:4 rq:769819 version:0.5.1

Changes:
--------
--- /work/SRC/openSUSE:Factory/brightnessctl/brightnessctl.changes      
2020-01-31 23:59:14.091712048 +0100
+++ /work/SRC/openSUSE:Factory/.brightnessctl.new.26092/brightnessctl.changes   
2020-02-04 19:55:42.653404105 +0100
@@ -1,0 +2,13 @@
+Sun Feb  2 21:10:59 UTC 2020 - R. Tyler Croy <[email protected]>
+
+-  Upgrade to the recently released 0.5.1, which includes previously applied
+   patches
+
+Removed patches (adding this for the bot):
+
+   0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch
+   0002-Support-the-new-SetBrightness-logind-API.patch
+   0003-Make-the-use-of-SetBrightness-dynamic.patch
+   0004-Use-non-suid-permissions-when-logind-is-used.patch
+
+-------------------------------------------------------------------

Old:
----
  0.4.tar.gz
  0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch
  0002-Support-the-new-SetBrightness-logind-API.patch
  0003-Make-the-use-of-SetBrightness-dynamic.patch
  0004-Use-non-suid-permissions-when-logind-is-used.patch

New:
----
  0.5.1.tar.gz

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ brightnessctl.spec ++++++
--- /var/tmp/diff_new_pack.RSVhUz/_old  2020-02-04 19:55:43.413404548 +0100
+++ /var/tmp/diff_new_pack.RSVhUz/_new  2020-02-04 19:55:43.417404551 +0100
@@ -25,20 +25,13 @@
 %global use_logind 0
 %endif
 Name:           brightnessctl
-Version:        0.4
+Version:        0.5.1
 Release:        0
 Summary:        Tool to read and control device brightness
 License:        MIT
 URL:            https://github.com/Hummer12007/%{name}
 Source:         %{URL}/archive/%{version}.tar.gz
-# required to resolve cherry pick conflicts
-# 
https://github.com/Hummer12007/brightnessctl/commit/aa6a71cd8206992a64269239f038dbf5f516e54a
-Patch0:         0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch
-# https://github.com/Hummer12007/brightnessctl/pull/33
-Patch1:         0002-Support-the-new-SetBrightness-logind-API.patch
-Patch2:         0003-Make-the-use-of-SetBrightness-dynamic.patch
-# https://github.com/Hummer12007/brightnessctl/pull/41
-Patch3:         0004-Use-non-suid-permissions-when-logind-is-used.patch
+PreReq:         permissions
 BuildRequires:  gcc
 BuildRequires:  make
 %if %{use_logind}
@@ -53,9 +46,6 @@
 
 %prep
 %autosetup -N
-%if %{use_logind}
-%autopatch -p1
-%endif
 
 %build
 %if %{use_logind}
@@ -74,6 +64,13 @@
 %make_install UDEVDIR=%{_udevrulesdir}
 %endif
 
+%post
+%if 0%{?set_permissions:1}
+    %set_permissions %name
+%else
+    %run_permissions
+%endif
+
 %files
 %doc README.md
 %license LICENSE

++++++ 0.4.tar.gz -> 0.5.1.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/brightnessctl-0.4/Makefile 
new/brightnessctl-0.5.1/Makefile
--- old/brightnessctl-0.4/Makefile      2018-09-04 20:57:33.000000000 +0200
+++ new/brightnessctl-0.5.1/Makefile    2020-02-02 16:10:40.000000000 +0100
@@ -1,4 +1,4 @@
-VERSION = 0.4
+VERSION = 0.5
 CFLAGS += -std=c99 -g -Wall -Wextra -DVERSION=\"${VERSION}\" 
-D_POSIX_C_SOURCE=200809L
 LDLIBS = -lm
 
@@ -15,6 +15,14 @@
 MODE_1 = 0755
 MODE = ${MODE_${INSTALL_UDEV_RULES}}
 
+ifdef ENABLE_SYSTEMD
+       CFLAGS += ${shell pkg-config --cflags libsystemd}
+       LDLIBS += ${shell pkg-config --libs libsystemd}
+       CPPFLAGS += -DENABLE_SYSTEMD
+       INSTALL_UDEV_RULES=0
+       MODE = 0755
+endif
+
 all: brightnessctl brightnessctl.1
 
 install: all ${INSTALL_UDEV_${INSTALL_UDEV_RULES}}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/brightnessctl-0.4/README.md 
new/brightnessctl-0.5.1/README.md
--- old/brightnessctl-0.4/README.md     2018-09-04 20:57:33.000000000 +0200
+++ new/brightnessctl-0.5.1/README.md   2020-02-02 16:10:40.000000000 +0100
@@ -7,23 +7,30 @@
 ## Installation
 
 The program is available in:
-* [Fedora/EPEL](https://apps.fedoraproject.org/packages/brightnessctl)
-* [Arch Linux (AUR)](https://aur.archlinux.org/packages/brightnessctl)
-* [Void 
Linux](https://github.com/voidlinux/void-packages/blob/master/srcpkgs/brightnessctl/template)
+* [Alpine 
Linux](https://pkgs.alpinelinux.org/package/edge/community/x86_64/brightnessctl)
 - starting with 3.11 and Edge
+* [Arch 
Linux](https://www.archlinux.org/packages/community/x86_64/brightnessctl/)
+* [Void 
Linux](https://github.com/void-linux/void-packages/blob/master/srcpkgs/brightnessctl/template)
 * [Debian](https://packages.debian.org/testing/source/brightnessctl) - 
starting with Buster (and derivatives)
 * [Ubuntu](https://packages.ubuntu.com/source/bionic/brightnessctl) - starting 
with 18.04 (and derivatives)
+* [openSUSE](https://build.opensuse.org/package/show/utilities/brightnessctl) 
- available in Tumbleweed, use OBS `utilities/brightnessctl` devel project for 
Leap < 15.1
+* [Fedora/EPEL](https://apps.fedoraproject.org/packages/brightnessctl) 
(orphaned, deleted since F30, maintainer wanted)
+* [NixOS/nix](https://nixos.org/nixos/packages.html?attr=brightnessctl) - 
starting with 17.09, please see the [NixOS Wiki 
page](https://nixos.wiki/wiki/Backlight#brightnessctl) for the "best-practice" 
configuration file based installation
 
 One can build and install the program using `make install`. Consult the 
Makefile for relevant build-time options.
 
 ## Permissions
 
-Modifying brightness requires write permissions for device files. 
`brightnessctl` accomplishes this (without using `sudo`/`su`/etc.) by either of 
the following means:
+Modifying brightness requires write permissions for device files or systemd 
support. `brightnessctl` accomplishes this (without using `sudo`/`su`/etc.) by 
either of the following means:
 
 1) installing relevant udev rules to add permissions to backlight class 
devices for users in `video` and leds for users in `input`. (done by default)
 
 2) installing `brightnessctl` as a suid binary.
 
-The behavior is controlled by the `INSTALL_UDEV_RULES` flag (setting it to `1` 
installs the udev rules, `0` is the default value).
+3) using the `systemd-logind` API.
+
+The behavior is controlled by the `INSTALL_UDEV_RULES` flag (setting it to `1` 
installs the udev rules, it is the default value).
+
+The systemd support (since v243) is controlled by the `ENABLE_SYSTEMD` flag 
(udev rules will not be installed by default).
 
 ## Usage
 ```
@@ -35,6 +42,7 @@
   -p, --pretend                        do not perform write operations.
   -m, --machine-readable       produce machine-readable output.
   -n, --min-value              set minimum brightness, defaults to 1.
+  -e, --exponent[=K]           changes percentage curve to exponential.
   -s, --save                   save previous state in a temporary file.
   -r, --restore                        restore previous saved state.
   -h, --help                   print this help.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/brightnessctl-0.4/brightnessctl.1 
new/brightnessctl-0.5.1/brightnessctl.1
--- old/brightnessctl-0.4/brightnessctl.1       2018-09-04 20:57:33.000000000 
+0200
+++ new/brightnessctl-0.5.1/brightnessctl.1     2020-02-02 16:10:40.000000000 
+0100
@@ -49,6 +49,16 @@
 .RE
 
 .sp
+\fB\-e, \-\-exponent\fP=\fIK\fP
+.RS 4
+Changes percentage scaling curve to exponential (linear by default). Default 
exponent is 4.
+
+Percentage equation: % = \fI[VALUE]\fR^\fI[K]\fR * \fI[MAX]\fR * 
100^-\fI[K]\fR.
+
+The exponential curve may make the adjustments perceptually equal.
+.RE
+
+.sp
 \fB\-s, \-\-save\fP
 .RS 4
 Save state in a temporary file.
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/brightnessctl-0.4/brightnessctl.c 
new/brightnessctl-0.5.1/brightnessctl.c
--- old/brightnessctl-0.4/brightnessctl.c       2018-09-04 20:57:33.000000000 
+0200
+++ new/brightnessctl-0.5.1/brightnessctl.c     2020-02-02 16:10:40.000000000 
+0100
@@ -14,6 +14,10 @@
 #include <string.h>
 #include <math.h>
 
+#ifdef ENABLE_SYSTEMD
+# include <systemd/sd-bus.h>
+#endif
+
 static char *path = "/sys/class";
 static char *classes[] = { "backlight", "leds", NULL };
 
@@ -31,10 +35,10 @@
 static char *dir_child(char *, char*);
 static char *device_path(struct device *);
 static char *class_path(char *);
-static void apply_value(struct device *, struct value *);
+static unsigned int calc_value(struct device *, struct value *);
 static int apply_operation(struct device *, enum operation, struct value *);
 static bool parse_value(struct value *, char *);
-static bool write_device(struct device *);
+static bool do_write_device(struct device *);
 static bool read_device(struct device *, char *, char *);
 static int read_class(struct device **, char *);
 static int read_devices(struct device **);
@@ -44,8 +48,13 @@
 static bool save_device_data(struct device *);
 static bool restore_device_data(struct device *);
 static bool ensure_dir(char *);
+static bool ensure_dev_dir(struct device *);
 #define ensure_run_dir() ensure_dir(run_dir)
 
+#ifdef ENABLE_SYSTEMD
+static bool logind_set_brightness(struct device *);
+#endif
+
 struct device {
        char *class;
        char *id;
@@ -78,6 +87,7 @@
        bool mach;
        bool save;
        bool restore;
+       float exponent;
 };
 
 static struct params p;
@@ -89,6 +99,7 @@
        {"list", no_argument, NULL, 'l'},
        {"machine-readable", no_argument, NULL, 'm'},
        {"min-value", optional_argument, NULL, 'n'},
+       {"exponent", optional_argument, NULL, 'e'},
        {"quiet", no_argument, NULL, 'q'},
        {"pretend", no_argument, NULL, 'p'},
        {"restore", no_argument, NULL, 'r'},
@@ -97,6 +108,8 @@
        {NULL,}
 };
 
+static bool (*write_device)(struct device *) = do_write_device;
+
 int main(int argc, char **argv) {
        struct device *devs[255];
        struct device *dev;
@@ -107,8 +120,9 @@
                fail("Unable to determine current OS. Exiting!\n");
        if (strcmp(name.sysname, "Linux"))
                fail("This program only supports Linux.\n");
+       p.exponent = 1;
        while (1) {
-               if ((c = getopt_long(argc, argv, "lqpmn::srhVc:d:", options, 
NULL)) < 0)
+               if ((c = getopt_long(argc, argv, "lqpmn::e::srhVc:d:", options, 
NULL)) < 0)
                        break;
                switch (c) {
                case 'l':
@@ -135,6 +149,12 @@
                        else
                                p.min = 1;
                        break;
+               case 'e':
+                       if (optarg)
+                               p.exponent = atof(optarg);
+                       else
+                               p.exponent = 4;
+                       break;
                case 'h':
                        usage();
                        exit(EXIT_SUCCESS);
@@ -198,14 +218,18 @@
                errno = 0;
                file_path = cat_with('/', path, dev->class, dev->id, 
"brightness");
                if (access(file_path, W_OK)) {
+#ifdef ENABLE_SYSTEMD
+                       write_device = logind_set_brightness;
+#else
                        perror("Can't modify brightness");
                        fail("\nYou should run this program with root 
privileges.\n"
                                "Alternatively, get write permissions for 
device files.\n");
+#endif
                }
                free(file_path);
        }
        if ((sys_run_dir = getenv("XDG_RUNTIME_DIR")))
-           run_dir = dir_child(sys_run_dir, "brightnessctl");
+               run_dir = dir_child(sys_run_dir, "brightnessctl");
        if (p.save)
                if (!save_device_data(dev))
                        fprintf(stderr, "Could not save data for device 
'%s'.\n", dev->id);
@@ -228,7 +252,7 @@
                fprintf(stdout, "%u\n", dev->max_brightness);
                return 0;
        case SET:
-               apply_value(dev, val);
+               dev->curr_brightness = calc_value(dev, val);
                if (!p.pretend)
                        if (!write_device(dev))
                                goto fail;
@@ -236,8 +260,8 @@
                        if (!p.mach)
                                fprintf(stdout, "Updated device '%s':\n", 
dev->id);
                        print_device(dev);
-                       return 0;
                }
+               return 0;
        /* FALLTHRU */
        fail:
        default:
@@ -296,36 +320,84 @@
                print_device(dev);
 }
 
+float val_to_percent(float val, struct device *d, bool rnd) {
+       if (val < 0)
+               return 0;
+       float ret = powf(val / d->max_brightness, 1.0f / p.exponent) * 100;
+       return rnd ? roundf(ret) : ret;
+}
+
+unsigned long percent_to_val(float percent, struct device *d) {
+       return roundf(powf(percent / 100, p.exponent) * d->max_brightness);
+}
+
 void print_device(struct device *dev) {
-       char *format = p.mach ? "%s,%s,%d,%d%%,%d\n":
+       char *format = p.mach ? "%s,%s,%d,%d%%,%d\n" :
                "Device '%s' of class '%s':\n\tCurrent brightness: %d 
(%d%%)\n\tMax brightness: %d\n\n";
        fprintf(stdout, format,
                dev->id, dev->class,
                dev->curr_brightness,
-               (int) (100.0 * dev->curr_brightness / dev-> max_brightness),
+               (int) val_to_percent(dev->curr_brightness, dev, true),
                dev->max_brightness);
 }
 
-void apply_value(struct device *d, struct value *val) {
-       long new, mod = val->v_type == ABSOLUTE ?
-                       val->val : ceil(val->val / 100.0 * d->max_brightness);
+unsigned int calc_value(struct device *d, struct value *val) {
+       long new = d->curr_brightness;
        if (val->d_type == DIRECT) {
-               new = mod > d->max_brightness ? d->max_brightness : mod;
+               new = val->v_type == ABSOLUTE ? val->val : 
percent_to_val(val->val, d);
                goto apply;
        }
-       mod *= val->sign == PLUS ? 1 : -1;
-       new = d->curr_brightness + mod;
+       long mod = val->val;
+       if (val->sign == MINUS)
+               mod *= -1;
+       if (val->v_type == RELATIVE) {
+               mod = percent_to_val(val_to_percent(d->curr_brightness, d, 
false) + mod, d) - d->curr_brightness;
+               if (val->val != 0 && mod == 0)
+                       mod = val->sign == PLUS ? 1 : -1;
+       }
+       new += mod;
+apply:
        if (new < p.min)
                new = p.min;
        if (new < 0)
                new = 0;
        if (new > d->max_brightness)
                new = d->max_brightness;
-apply:
-       d->curr_brightness = new;
+       return new;
+}
+
+#ifdef ENABLE_SYSTEMD
+
+bool logind_set_brightness(struct device *d) {
+       sd_bus *bus = NULL;
+       int r = sd_bus_default_system(&bus);
+       if (r < 0) {
+               fprintf(stderr, "Can't connect to system bus: %s\n", 
strerror(-r));
+               return false;
+       }
+
+       r = sd_bus_call_method(bus,
+                              "org.freedesktop.login1",
+                              "/org/freedesktop/login1/session/auto",
+                              "org.freedesktop.login1.Session",
+                              "SetBrightness",
+                              NULL,
+                              NULL,
+                              "ssu",
+                              d->class,
+                              d->id,
+                              d->curr_brightness);
+       if (r < 0)
+               fprintf(stderr, "Failed to set brightness: %s\n", strerror(-r));
+
+       sd_bus_unref(bus);
+
+       return r >= 0;
 }
 
-bool write_device(struct device *d) {
+#endif
+
+bool do_write_device(struct device *d) {
        FILE *f;
        char c[16];
        size_t s = sprintf(c, "%u", d->curr_brightness);
@@ -351,9 +423,11 @@
 bool read_device(struct device *d, char *class, char *id) {
        DIR *dirp;
        FILE *f;
-       char *dev_path;
+       char *dev_path = NULL;
+       char *ent_path;
        int error = 0;
        struct dirent *ent;
+       bool cur;
        d->class = strdup(class);
        d->id = strdup(id);
        dev_path = device_path(d);
@@ -362,39 +436,31 @@
        while ((ent = readdir(dirp))) {
                if (!strcmp(ent->d_name, ".") && !strcmp(ent->d_name, ".."))
                        continue;
-               if (!strcmp(ent->d_name, "brightness")) {
-                       if ((f = fopen(dir_child(dev_path, ent->d_name), "r"))) 
{
-                               clearerr(f);
-                               if (fscanf(f, "%u", &d->curr_brightness) == 
EOF) {
-                                       fprintf(stderr, "End-of-file reading 
brightness of device '%s'.", d->id);
-                                       error++;
-                               } else if (ferror(f)) {
-                                       fprintf(stderr, "Error reading 
brightness of device '%s': %s.", d->id, strerror(errno));
-                                       error++;
-                               }
-                               fclose(f);
-                       } else
-                               goto fail;
-               }
-               if (!strcmp(ent->d_name, "max_brightness")) {
-                       if ((f = fopen(dir_child(dev_path, ent->d_name), "r"))) 
{
-                               clearerr(f);
-                               if (fscanf(f, "%u", &d->max_brightness) == EOF) 
{
-                                       fprintf(stderr, "End-of-file reading 
max brightness of device '%s'.", d->id);
-                                       error++;
-                               } else if (ferror(f)) {
-                                       fprintf(stderr, "Error reading max 
brightness of device '%s': %s.", d->id, strerror(errno));
-                                       error++;
-                               }
-                               fclose(f);
-                       } else
+               if ((cur = !strcmp(ent->d_name, "brightness")) ||
+                               !strcmp(ent->d_name, "max_brightness")) {
+                       if (!(f = fopen(ent_path = dir_child(dev_path, 
ent->d_name), "r")))
                                goto fail;
+                       clearerr(f);
+                       if (fscanf(f, "%u", cur ? &d->curr_brightness : 
&d->max_brightness) == EOF) {
+                               fprintf(stderr, "End-of-file reading %s of 
device '%s'.",
+                                               cur ? "brightness" : "max 
brightness", d->id);
+                               error++;
+                       } else if (ferror(f)) {
+                               fprintf(stderr, "Error reading %s of device 
'%s': %s.",
+                                               cur ? "brightness" : "max 
brightness", d->id, strerror(errno));
+                               error++;
+                       }
+                       fclose(f);
+                       free(ent_path);
+                       ent_path = NULL;
                }
        }
        errno = 0;
 fail:
        closedir(dirp);
 dfail:
+       free(dev_path);
+       free(ent_path);
        if (errno) {
                perror("Error reading device");
                error++;
@@ -406,8 +472,9 @@
        DIR *dirp;
        struct dirent *ent;
        struct device *dev;
+       char *c_path;
        int cnt = 0;
-       dirp = opendir(class_path(class));
+       dirp = opendir(c_path = class_path(class));
        if (!dirp)
                return 0;
        while ((ent = readdir(dirp))) {
@@ -421,6 +488,7 @@
                devs[cnt++] = dev;
        }
        closedir(dirp);
+       free(c_path);
        return cnt;
 }
 
@@ -436,8 +504,7 @@
 bool save_device_data(struct device *dev) {
        char c[16];
        size_t s = sprintf(c, "%u", dev->curr_brightness);
-       char *c_path = dir_child(run_dir, dev->class);
-       char *d_path = dir_child(c_path, dev->id);
+       char *d_path = cat_with('/', run_dir, dev->class, dev->id);
        FILE *fp;
        mode_t old = 0;
        int error = 0;
@@ -447,9 +514,7 @@
                error++;
                goto fail;
        }
-       if (!ensure_run_dir())
-               goto fail;
-       if (!ensure_dir(c_path))
+       if (!ensure_dev_dir(dev))
                goto fail;
        old = umask(0);
        fp = fopen(d_path, "w");
@@ -462,7 +527,6 @@
        }
        fclose(fp);
 fail:
-       free(c_path);
        free(d_path);
        if (errno) {
                perror("Error saving device data");
@@ -516,6 +580,17 @@
        return true;
 }
 
+bool ensure_dev_dir(struct device *dev) {
+       char *cpath;
+       bool ret;
+       if (!ensure_run_dir())
+               return false;
+       cpath = dir_child(run_dir, dev->class);
+       ret = ensure_dir(cpath);
+       free(cpath);
+       return ret;
+}
+
 char *_cat_with(char c, ...) {
        size_t size = 32;
        size_t length = 0;
@@ -569,6 +644,7 @@
   -p, --pretend\t\t\tdo not perform write operations.\n\
   -m, --machine-readable\tproduce machine-readable output.\n\
   -n, --min-value\t\tset minimum brightness, defaults to 1.\n\
+  -e, --exponent[=K]\t\tchanges percentage curve to exponential.\n\
   -s, --save\t\t\tsave previous state in a temporary file.\n\
   -r, --restore\t\t\trestore previous saved state.\n\
   -h, --help\t\t\tprint this help.\n\


Reply via email to