Browse Source

Merge pull request #43 from troglobit/misc

Misc
Joachim Nilsson 6 years ago
parent
commit
5d5e3c3e83
No account linked to committer's email
5 changed files with 184 additions and 139 deletions
  1. 2
    0
      90-backlight.rules
  2. 134
    85
      README.md
  3. 1
    1
      src/Makefile.am
  4. 36
    39
      src/light.c
  5. 11
    14
      src/light.h

+ 2
- 0
90-backlight.rules View File

@@ -0,0 +1,2 @@
1
+ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
2
+ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"

+ 134
- 85
README.md View File

@@ -1,148 +1,197 @@
1
-# Light
1
+Light - A Program to Control Backlight Controllers
2
+==================================================
2 3
 
3
-Copyright (C) 2012 - 2014, Fredrik Haikarainen
4
-This is free software, see the source for copying conditions.  There is NO
5
-warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
4
+- [Introduction](#introduction)
5
+- [Examples](#examples)
6
+- [Usage](#usage)
7
+  - [Operation modes](#operation-modes)
8
+  - [Value modes](#value-modes)
9
+  - [Target](#target)
10
+  - [Field](#field)
11
+  - [Controller modes](#controller-modes)
12
+- [Installation](#installation)
13
+  - [Arch Linux](#arch-linux)
14
+  - [Manual](#manual)
15
+  - [Permissions](#permissions)
16
+- [Origin & References](#origin--references)
6 17
 
7 18
 
8
-## Description
19
+Introduction
20
+------------
9 21
 
10
-Light is a program to control backlight controllers under GNU/Linux, it is the successor of lightscript, which was a bash script with the same purpose, and tries to maintain the same functionality.
22
+[Light][] is a program to control backlight controllers under GNU/Linux:
11 23
 
24
+* Works, in particular when other software, e.g. xbacklight, does not
25
+* Does not rely on X
26
+* Automatically detects the best controller
27
+* Possibility to set a minimum brightness value
12 28
 
13
-## Features
29
+Let's get started with a few examples, for details, see below for the
30
+full description of the different commands, options and how to access
31
+different controllers.
14 32
 
15
-* Works excellent where other software have been proven unusable or problematic, thanks to how it operates internally and the fact that it does not rely on X.
16
-* Can automatically figure out the best controller to use, making full use of underlying hardware.
17
-* Possibility to set a minimum brightness value, as some controllers set the screen to be pitch black at a vaĺue of 0 (or higher).
18 33
 
34
+Examples
35
+--------
19 36
 
20
-## Installation
37
+Get the current brightness in percent
21 38
 
22
-### Arch Linux
39
+    light -G
23 40
 
24
-If you run Arch Linux, there exists 2 packages;
25
-* [light-git](https://aur.archlinux.org/packages/light-git) - For the absolutely latest version
26
-* [light](https://aur.archlinux.org/packages/light) - For the latest tagged release
41
+or
27 42
 
28
-I recommend you go with light-git as you might miss important features and bugfixes if you do not.
43
+     light
29 44
 
30
-### Manual
45
+Increase brightness by 5 percent
31 46
 
32
-We recommended downloading a versioned tarball from the relases page on
33
-GitHub.  Download and untar the archive:
47
+    light -A 5
34 48
 
35
-    tar xf light-x.yy.tar.gz
36
-    cd light-x.yy/
37
-    ./configure && make
38
-    sudo make install
49
+Set the minimum cap to 2 in raw value on the acpi_video0 controller:
39 50
 
40
-However, should you want to try the latest GitHub source you first need
41
-to clone the repository and run the `autogen.sh` script.  This requires
42
-`automake` and `autoconf` to be installed on your system.
51
+    light -cr -s acpi_video0 -S 2
43 52
 
44
-    ./autogen.sh
45
-    ./configure && make
46
-    sudo make install
53
+Try to set the brightness to 0 after that, it will be changed to the
54
+minimum 2:
47 55
 
48
-The `configure` script and `Makefile.in` files are not part of GIT
49
-because they are generated at release time with `make release`.
56
+    light -r -s acpi_video0 -S 0
50 57
 
58
+Find keyboard controllers:
51 59
 
52
-### Permissions
60
+    light -k -L
61
+
62
+Activate `ScrollLock` LED, here `input15` is used, but this varies
63
+between different systems:
64
+
65
+    light -k -s "input15::scrolllock" -S 100
66
+
67
+Usually, LEDs only take 0 or 1 in raw value (i.e. for off/on), so you
68
+can instead write:
69
+
70
+    light -kr -s "input15::scrolllock" -S 1
53 71
 
54
-**Optional:** If you want to use udev rules instead of suid to manage sysfs permissions, you may skip the `make install` step and instead add something like the following to `/etc/udev/rules.d/90-backlight.rules` after copying your binaries:
55
-```
56
-ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
57
-ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
58
-```
72
+Verify by reading back the max brightness, you should get a value of 1:
59 73
 
74
+    light -kr -m -s "input15::scrolllock
60 75
 
61
-## Usage
62 76
 
63
-This application usually has 5 different criteria on flags to use, which are operation modes, value mode, target, field and controller mode. Flags from these different modes can never be used in conjunction, but all of them do not always have to be specified (although it is recommended to do so for verbosity).
77
+Usage
78
+-----
64 79
 
65
-**Note:** This application will only print errors if you are using it incorrectly. If something goes wrong, and you can't figure out why, try setting the verbosity flag with -v:
80
+### Commands
81
+
82
+* `-G`: Get (read) brightness/data from controllers/files
83
+* `-S VAL`: Set (write)brightness/data to controllers/files
84
+* `-A VAL`: Like `-S`, but adds the given value
85
+* `-U VAL`: Like `-S`, but subtracts the given value
86
+* `-O`: Save the current brightness for later use (usually used on shutdown)
87
+* `-I`: Restore the previously saved brightness (usually used on boot)
88
+* `-L`: List available controllers, see below `-k` option as well
89
+
90
+Without any options (below) the commands operate on the brightness of an
91
+automatically selected controller.  Values are given in percent, unless
92
+the below `r` option is also given.
93
+
94
+**Note:** like most UNIX applications, light only gives output on
95
+  errors.  If something goes wrong try the verbosity option `-v VAL`:
66 96
 
67 97
 * 0: No debug output
68 98
 * 1: Errors
69 99
 * 2: Errors, warnings
70 100
 * 3: Errors, warnings, notices
71 101
 
72
-### Operation modes
73
-
74
-The operation modes describe **what** you want to do.
102
+### Options
75 103
 
76
-* -G: Which **reads/gets** brightness/data from controllers/files
77
-* -S: Which **writes/sets** brightness/data to controllers/files
78
-* -A: Which does like -S but instead **adds** the value
79
-* -U: Which does like -S but instead '**subtracts** the value
80
-* -O: Save the current brightness for later use (usually used on shutdown)
81
-* -I: Restore the previously saved brightness (usually used on boot)
82
-* -L: List the available controllers
104
+Values may be given, or presented, in percent or raw mode.  Raw mode is
105
+the format specific to the controller.  The default is in percent, but
106
+raw mode may be required for precise control, or when the steps are very
107
+few, e.g. for most keyboard backlight controllers.
83 108
 
84
-When used by themselves operate on the brightness of a controller that is selected automatically. S, A and U needs another argument -- except for the main 4 criteria -- which is the value to set/add/subtract.   This can be specified either in percent or in raw values, but remember to specify the value mode (read below) if you want to write raw values.
109
+* `-p`: Percent, default
110
+* `-r`: Raw mode
85 111
 
86
-### Value modes
112
+By default the screen is the active target for all commands, use `-k` to
113
+select the keyboard instead.  In either case you may need to select a
114
+different controller, see below.
87 115
 
88
-The value mode specify in what unit you want to read or write values in. The default one (if not specified) is in percent, the other one is raw mode and should always be used when you need very precise values (or only have a controller with a very small amount of brightness levels).
116
+* `-l`: Act on screen backlight, default
117
+* `-k`: Act on keyboard backlight and LEDs
89 118
 
90
-* -p: Percent
91
-* -r: Raw mode
119
+By default commands act on the brightness property, which is read+write.
120
+The maximum brightness is a read-only property.  The minimum brightness
121
+cap is a feature implemented to protect against setting brightness too
122
+low, since some controllers make the screen go pitch black at 0%.  For
123
+controllers like that it is recommended to set this value.
92 124
 
93
-Remember, this is the unit that will be used when you set, get, add or subtract brightness values.
125
+* `-b`: Current brightness of selected controller, default
126
+* `-m`: Max. brightness of selected controller
127
+* `-c`: Min. brightness (cap) of selected controller (recommend raw mode)
94 128
 
95
-### Target
129
+Controller is automatically done to select the controller with maximum
130
+precision.  It can however also be done manually and we recommend the
131
+`-L` and `-Lk` commands to list available controllers:
96 132
 
97
-You can choose which target to act on:
133
+* `-a`: Automatic controller selection
134
+* `-s ARG`: Manual controller selection
98 135
 
99
-* -l: Act on screen backlight
100
-* -k: Act on keyboard backlight and LEDs
136
+**Note:** Without the `-s` flag on _every_ command light will default
137
+  to automatic controller selection.
101 138
 
102
-### Field
103 139
 
104
-As you can not only handle the **brightness** of controllers, you may also specify a field to read/write from/to:
140
+Installation
141
+------------
105 142
 
106
-* -b: Current brightness of selected controller
107
-* -m: Maximum brightness of selected controller
108
-* -c: Minimum brightness (cap) of selected controller
143
+### Arch Linux
109 144
 
110
-The minimum brightness is a feature implemented as some controllers make the screen go pitch black at 0%, if you have a controller like that, it is recommended to set this value (in either percent or in raw mode). These values will be saved in raw mode though, so if you specify it in percent it might not be too accurate depending on your controller.
145
+If you run Arch Linux, there exists 2 packages;
111 146
 
112
-### Controller modes
147
+* [light-git][] - For the absolutely latest version
148
+* [light-tag][] - For the latest tagged release
113 149
 
114
-Finally, you can either use the built-in controller selection to get the controller with the maximum precision, or you can specify one manually with the -s flag. The -a flag will force automatic mode and is default. Use -L to get a list of controllers to use with the -s flag (to specify which controller to use). 
150
+We recommend you go with light-git as you might miss important features
151
+and bugfixes if you do not.
115 152
 
116
-**Notice: You _need_ to include the `-s` or `-a` flag on _every_ command you run. The controller setting will _not_ be stored anywhere! If you do not use any of the flags, it will always default to automatic selection.**
117 153
 
118
-### Examples
154
+### Manual
119 155
 
120
-Get the current brightness in percent
156
+We recommended downloading a versioned tarball from the relases page on
157
+GitHub.  Download and untar the archive:
121 158
 
122
-`light -G`, or simply `light`
159
+    tar xf light-x.yy.tar.gz
160
+    cd light-x.yy/
161
+    ./configure && make
162
+    sudo make install
123 163
 
124
-Increase brightness by 5 percent
164
+However, should you want to try the latest GitHub source you first need
165
+to clone the repository and run the `autogen.sh` script.  This requires
166
+`automake` and `autoconf` to be installed on your system.
125 167
 
126
-`light -A 5`
168
+    ./autogen.sh
169
+    ./configure && make
170
+    sudo make install
127 171
 
128
-Set the minimum cap to 2 in raw value on the acpi_video0 controller:
172
+The `configure` script and `Makefile.in` files are not part of GIT
173
+because they are generated at release time with `make release`.
129 174
 
130
-`light -Scrs "acpi_video0" 2`
131 175
 
132
-Try to set the brightness to 0 after that, it will be changed to the minimum 2
176
+### Permissions
133 177
 
134
-`light -Srs "acpi_video0" 0`
178
+**Optional:** Instead of SUID root you can set up udev rules to manage
179
+   sysfs permissions, you may skip the `make install` step and instead
180
+   copy the file `90-backlight.rules` to `/etc/udev/rules.d/`:
135 181
 
136
-Find keyboard controllers
137 182
 
138
-`light -Lk`
183
+    ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chgrp video /sys/class/backlight/%k/brightness"
184
+    ACTION=="add", SUBSYSTEM=="backlight", RUN+="/bin/chmod g+w /sys/class/backlight/%k/brightness"
139 185
 
140
-Activate `ScrollLock` LED
141 186
 
142
-`light -Sks "input15::scrolllock" 100`
187
+Origin & References
188
+-------------------
143 189
 
144
-Usually, LEDs only take 0 or 1 in raw value (i.e. for off/on), so you can write
190
+Copyright (C) 2012-2018 Fredrik Haikarainen
145 191
 
146
-`light -Skrs "input15::scrolllock" 1`
192
+This is free software, see the source for copying conditions.  There is NO
193
+warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE
147 194
 
148
-Verify this with `light -v3 -mkrs input15::scrolllock`, you should get a max. brightness of 1
195
+[Light]:     https://github.com/haikarainen/light
196
+[light-git]: https://aur.archlinux.org/packages/light-git
197
+[light-tag]: https://aur.archlinux.org/packages/light

+ 1
- 1
src/Makefile.am View File

@@ -1,7 +1,7 @@
1 1
 bin_PROGRAMS   = light
2 2
 light_SOURCES  = main.c light.c light.h helpers.c helpers.h
3 3
 light_CPPFLAGS = -I../include -D_XOPEN_SOURCE=500
4
-light_CFLAGS   = -W -Wall -Wextra -pedantic -std=c89
4
+light_CFLAGS   = -W -Wall -Wextra -pedantic -std=c99
5 5
 
6 6
 install-exec-hook:
7 7
 	chmod 4755 $(DESTDIR)$(bindir)/light

+ 36
- 39
src/light.c View File

@@ -239,48 +239,45 @@ LIGHT_BOOL light_parseArguments(int argc, char** argv)
239 239
 }
240 240
 
241 241
 void light_printVersion(){
242
-  printf("Light %u.%u (%s)\n", LIGHT_VER_MAJOR, LIGHT_VER_MINOR, LIGHT_VER_TYPE);
243
-  printf("Copyright (C) %u %s\n", LIGHT_YEAR, LIGHT_AUTHOR);
244
-  printf("This is free software, see the source for copying conditions.  There is NO\n");
245
-  printf("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n\n");
242
+  printf("v%s\n", VERSION);
246 243
 }
247 244
 
248 245
 void light_printHelp(){
249
-  printf("Usage: light <options> <value>\n");
250
-  printf("<value> has to be either integral(raw mode) or decimal(percent mode) depending on the specified value mode.\n");
251
-  printf("<options> can be any of the following:\n\n");
252
-
253
-  printf("Operations (can not be used in conjunction):\n");
254
-  printf("  -H -h:\tPrints this help and exits\n");
255
-  printf("  -V:\t\tPrints version info and exits\n");
256
-  printf("  -G:\t\tGet value (default)\n");
257
-  printf("  -S:\t\tSet value\n");
258
-  printf("  -A:\t\tAdd value\n");
259
-  printf("  -U:\t\tSubtract value\n");
260
-  printf("  -L:\t\tList controllers\n");
261
-  printf("  -I:\t\tRestore brightness\n");
262
-  printf("  -O:\t\tSave brightness\n\n");
263
-
264
-  printf("Targets (can not be used in conjunction):\n");
265
-  printf("  -l:\t\tAct on screen backlight (default)\n");
266
-  printf("  -k:\t\tAct on keyboard backlight\n\n");
267
-
268
-  printf("Fields (can not be used in conjunction):\n");
269
-  printf("  -b:\t\tBrightness (default)\n  \t\tUsed with [GSAU]\n\n");
270
-  printf("  -m:\t\tMaximum brightness\n  \t\tUsed with [G]\n\n");
271
-  printf("  -c:\t\tMinimum cap\n  \t\tUsed with [GS]\n");
272
-  printf("  \t\tG returns null if no minimum cap is set.\n\n");
273
-
274
-  printf("Controller selection (can not be used in conjunction):\n");
275
-  printf("  -a:\t\tSelects controller automatically (default).\n");
276
-  printf("  -s:\t\tSpecify controller to use. (needs argument)\n\n");
277
-
278
-  printf("Value modes (can not be used in conjunction):\n");
279
-  printf("  -p:\t\tInterpret <value> as, and output values in, percent. (default)\n");
280
-  printf("  -r:\t\tInterpret <value> as, and output values in, raw mode.\n\n");
281
-
282
-  printf("Other:\n");
283
-  printf("  -v:\t\tSets the verbosity level, (needs argument).\n  \t\t0: Only outputs read values.\n  \t\t1: Read values, Errors.\n  \t\t2: Read values, Errors, Warnings.\n  \t\t3: Read values, Errors, Warnings, Notices.\n\n");
246
+	printf("Usage:\n"
247
+	       "  light [OPTIONS] <COMMAND> [VALUE]\n"
248
+	       "\n"
249
+	       "Commands:\n"
250
+	       "  -A VAL  Add value\n"
251
+	       "  -G      Get (read) value, default command\n"
252
+	       "  -H, -h  Show this help and exit\n"
253
+	       "  -I      Restore brightness\n"
254
+	       "  -L      List available controllers\n"
255
+	       "  -O      Save brightness\n"
256
+	       "  -S VAL  Set (write) value\n"
257
+	       "  -U VAL  Subtract value\n"
258
+	       "  -V      Show program version and exit\n"
259
+	       "\n"
260
+	       "Options:\n"
261
+	       "  -a      Automatic controller selection, default\n"
262
+	       "  -b      Brightness, default\n"
263
+	       "  -c      Act on minimum cap, only possible to read and set\n"
264
+	       "  -k      Act on keyboard backlight\n"
265
+	       "  -l      Act on screen backlight, default\n"
266
+	       "  -m      Maximum brightness, only possible to read\n"
267
+	       "  -p      Interpret input, and output, values in percent, default\n"
268
+	       "  -r      Interpret input, and outpot, values in raw mode\n"
269
+	       "  -s ARG  Specify controller to use, use -L and -Lk to list available\n"
270
+	       "  -v ARG  Verbosity level:\n"
271
+	       "            0: Values only, default\n"
272
+	       "            1: Values, Errors.\n"
273
+	       "            2: Values, Errors, Warnings.\n"
274
+	       "            3: Values, Errors, Warnings, Notices.\n"
275
+	       "\n");
276
+
277
+	printf("Copyright (C) %s  %s\n", LIGHT_YEAR, LIGHT_AUTHOR);
278
+	printf("This is free software, see the source for copying conditions.  There is NO\n"
279
+	       "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE\n"
280
+	       "\n");
284 281
 }
285 282
 
286 283
 LIGHT_BOOL light_initialize(int argc, char** argv)

+ 11
- 14
src/light.h View File

@@ -1,25 +1,22 @@
1
-#ifndef LIGHT_H
2
-#define LIGHT_H
1
+#ifndef LIGHT_H_
2
+#define LIGHT_H_
3 3
 
4
+#include "config.h"
4 5
 #include "helpers.h"
5 6
 
6 7
 #include <sys/types.h>
7 8
 #include <dirent.h>
8 9
 #include <linux/limits.h>
9 10
 
10
-#define LIGHT_VER_MAJOR 0
11
-#define LIGHT_VER_MINOR 10
12
-#define LIGHT_VER_TYPE "beta"
13
-#define LIGHT_YEAR 2014
11
+#define LIGHT_YEAR   "2012-2018"
14 12
 #define LIGHT_AUTHOR "Fredrik Haikarainen"
15 13
 
16
-#define ASSERT_SET(t,v) \
17
-  if(v)\
18
-  {\
19
-    fprintf(stderr, t" arguments can not be used in conjunction.\n");\
20
-    return FALSE;\
21
-  }\
22
-  v = TRUE;
14
+#define ASSERT_SET(t,v)							\
15
+	if (v) {							\
16
+		fprintf(stderr, t" arguments cannot be used in conjunction.\n"); \
17
+		return FALSE;						\
18
+	}								\
19
+	v = TRUE;
23 20
 
24 21
 #define ASSERT_OPSET() ASSERT_SET("Operation", opSet)
25 22
 #define ASSERT_TARGETSET() ASSERT_SET("Target", targetSet)
@@ -138,4 +135,4 @@ LIGHT_BOOL light_saveBrightness(char const *controller, unsigned long v);
138 135
 
139 136
 LIGHT_BOOL light_restoreBrightness(char const *controller);
140 137
 
141
-#endif /* LIGHT_H */
138
+#endif /* LIGHT_H_ */