LUXGET(3) Manual Page

  • Home
  • Back

  • luxget(3) Library Functions Manual luxget(3)

    luxget, luxmax, luxgetpquery the current or maximum brightness of a display

    library “liblux”

    #include <lux.h>

    int
    luxget(lux_t *disp);

    int
    luxmax(lux_t *disp);

    double
    luxgetp(lux_t *disp);

    The () function takes a pointer to a lux_t structure and returns the raw brightness value of the associated display. If the function returns -1 it means that an error has occurred, however this is only possible if disp has not yet been passed to any other library function that interacts with the current brightness level, whether that be to get the current brightness or set the current brightness.

    The () function behaves identically to the luxget() function except it returns the maximum supported brightness of the display referred to by disp. Additionally, this function can only error if disp has not yet been used as a parameter to an invocation of either luxmax() or any of the () functions.

    The () function takes a pointer to a lux_t structure and returns the brightness of the associated display as a percentage. A return value of 100.0 means the display is at 100% brightness. If the function returns -1 it means that an error has occurred. Internally this function calls both luxget() and luxmax(), so if both of those functions are in a state where they can no longer fail, then you do not need to error check this function.

    The luxget() function returns the raw brightness value of the associated display.

    The luxmax() function returns the maximum raw brightness value of the associated display.

    The luxgetp() function returns the current brightness percentage of the associated display. A value of 100.0 is equivalent to 100% brightness.

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

    The following program queries and prints information regarding displays current brightness.

    #include <err.h>
    #include <stdio.h>
    #include <stdlib.h>
    
    #include <lux.h>
    
    int
    main(void)
    {
    	int cur, max;
    	double curp;
    	lux_t disp;
    
    	luxinit(&disp);
    
    	if ((cur = luxget(&disp)) == -1)
    		err(EXIT_FAILURE, "luxget");
    	if ((max = luxmax(&disp)) == -1)
    		err(EXIT_FAILURE, "luxmax");
    
    	/* Because we already passed disp to luxget() and luxmax() previously,
    	 * we don't need to do error checking!
    	 */
    	curp = luxgetp(&disp);
    
    	printf("Current Brightness (Raw):        %d/%d\n", cur, max);
    	printf("Current Brightness (Percentage): %d%%/100%%\n", (int) curp);
    
    	luxfree(&disp);
    	return EXIT_SUCCESS;
    }

    luxget(), luxmax(), and luxgetp() can fail with any of the errors specified for fdopen() or openat().

    lux(3), luxdec(3), luxdecp(3), luxfree(3), luxinc(3), luxincp(3), luxinit(3), luxset(3), luxsetp(3)

    Thomas Voss <[email protected]>

    August 7, 2023 Linux