LUXSET(3) Manual Page

  • Home
  • Back

  • luxset(3) Library Functions Manual luxset(3)

    luxset, luxinc, luxdec, luxsetp, luxincp, luxdecpmodify display brightness levels

    library “liblux”

    #include <lux.h>

    int
    luxset(lux_t *disp, int n);

    int
    luxinc(lux_t *disp, int n);

    int
    luxdec(lux_t *disp, int n);

    double
    luxsetp(lux_t *disp, double p);

    double
    luxincp(lux_t *disp, double p);

    double
    luxdecp(lux_t *disp, double p);

    The () function sets the brightness of the display associated with disp to n. It is the responsibility of the caller to ensure that the given brightness is valid, meaning that it is non-negative and does not exceed the maximum supported brightness. On failure -1 is returned, however it is sometimes possible to guarantee that this function will not fail. For more information, read the luxget(3) manual.

    The () and () functions act identically to luxset() however instead of setting the brightness of the display to n, the current brightness is either incremented or decremented by n respectively.

    The (), (), and () all function similarly to their non-p counterparts, but instead of taking a raw brightness as a parameter they take percentages. As an example, luxincp(&disp, 50.0) increases the display brightness by 50% of the maximum brightness and luxsetp(&disp, 25.0) sets the current display brightness to 25%. On error these three functions return -1, and they can only fail in the same cases as (), so check the luxgetp(3) manual for details on when you should and shouldn't error check.

    The luxset(), luxinc(), and luxdec() functions all return the new raw brightness value of the display.

    The luxsetp(), luxincp(), and luxdecp() functions all return the new brightness percentage of the display. A return value of 100.0 means the display is at 100% brightness.

    On error, all the above functions will return -1 and errno is set to indicate the error.

    The following program allows the user to use the -i and -d flags to increase and decrease the brightness of their display by a certain percentage.

    #define _POSIX_C_SOURCE 2
    #include <err.h>
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    #include <lux.h>
    
    int
    main(int argc, char **argv)
    {
    	int opt;
    	lux_t disp;
    
    	luxinit(&disp);
    	while ((opt = getopt(argc, argv, ":i:d:")) != -1) {
    		switch (opt) {
    		case 'i':
    			if (luxincp(&disp, atoi(optarg)) == -1)
    				err(EXIT_FAILURE, "luxincp");
    			break;
    		case 'd':
    			if (luxdecp(&disp, atoi(optarg)) == -1)
    				err(EXIT_FAILURE, "luxdecp");
    			break;
    		default:
    			fprintf(stderr, "Usage: %s [-id val]\n", argv[0]);
    			exit(EXIT_FAILURE);
    		}
    	}
    
    	luxfree(&disp);
    	return EXIT_SUCCESS;
    }

    luxset(), luxinc(), luxdec(), luxsetp(), luxincp(), and luxdecp() can fail with any of the errors specified for fdopen() or openat().

    lux(3), luxfree(3), luxget(3), luxgetp(3), luxinit(3), luxmax(3)

    Thomas Voss <[email protected]>

    August 7, 2023 Linux