aboutsummaryrefslogtreecommitdiff
path: root/man/luxget.3
blob: 1216a2145dbf509ea58f8bf9e4f7e8b0f50ebf5b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
.\" vi: tw=80
.\"
.\" BSD Zero Clause License
.\" 
.\" Copyright (c) 2022 Thomas Voss
.\" 
.\" Permission to use, copy, modify, and/or distribute this software for any
.\" purpose with or without fee is hereby granted.
.\" 
.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
.\" REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
.\" AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
.\" INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
.\" LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
.\" OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
.\" PERFORMANCE OF THIS SOFTWARE.
.\"
.Dd $Mdocdate: September 9 2022 $
.Dt LUXGET 3
.Os
.Sh NAME
.Nm luxget ,
.Nm luxmax ,
.Nm luxgetp
.Nd query the current or maximum brightness of a display
.Sh SYNOPSIS
.In lux.h
.Ft int
.Fn luxget "struct luxdisp *disp"
.Ft int
.Fn luxmax "struct luxdisp *disp"
.Ft double
.Fn luxgetp "struct luxdisp *disp"
.Sh DESCRIPTION
The
.Fn luxget
function takes a pointer to a
.Vt "struct luxdisp"
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
.Va 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.
.Pp
The
.Fn luxmax
function behaves identically to the
.Fn luxget
function except it returns the maximum supported brightness of the display
referred to by
.Va disp .
Additionally, this function can only error if
.Va disp
has not yet been used as a parameter to an invocation of either
.Fn luxmax
or any of the
.Fn lux*p
functions.
.Pp
The
.Fn luxgetp
function takes a pointer to a
.Vt "struct luxdisp"
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
.Fn luxget
and
.Fn 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.
.Sh RETURN VALUES
The
.Fn luxget
function returns the raw brightness value of the associated display.
.Pp
The
.Fn luxmax
function returns the maximum raw brightness value of the associated display.
.Pp
The
.Fn luxgetp
function returns the current brightness percentage of the associated display.
A value of 100.0 is equivalent to 100% brightness.
.Pp
On error, all the above functions will return \-1 and
.Va errno
is set to indicate the error.
.Sh EXAMPLES
The following program queries and prints information regarding displays current
brightness.
.Bd -literal -offset indent
#include <err.h>
#include <stdio.h>
#include <stdlib.h>

#include <lux.h>

int
main(void)
{
	int cur, max;
	double curp;
	struct luxdisp 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\en", cur, max);
	printf("Current Brightness (Percentage): %d%%/100%%\en", (int) curp);

	luxfree(&disp);
	return EXIT_SUCCESS;
}
.Ed
.Sh ERRORS
.Fn luxget ,
.Fn luxmax ,
and
.Fn luxgetp
can fail with any of the errors specified for
.Fn fdopen
or
.Fn openat .
.Sh SEE ALSO
.Xr luxdec 3 ,
.Xr luxdecp 3 ,
.Xr luxfree 3 ,
.Xr luxinc 3 ,
.Xr luxincp 3 ,
.Xr luxinit 3 ,
.Xr luxset 3 ,
.Xr luxsetp 3
.Sh AUTHORS
.An Thomas Voss Aq Mt thomasvoss@live.com