Select the types of activity you want to include in your feed.
Add a -K option to only watch for keyboard input to reset idle
Use XInput to list devices and find the master keyboard device id, then find the corresponding "DEVICEIDLETIME #" idle timer to listen to instead of the global IDLETIME timer.
···11-.Dd $Mdocdate: August 27 2019$
11+.Dd $Mdocdate: January 18 2024$
22.Dt XDIMMER 1
33.Os
44.Sh NAME
···1010.Op Fl a
1111.Op Fl b Ar brighten steps
1212.Op Fl d
1313+.Op Fl K
1314.Op Fl k
1415.Op Fl n
1516.Op Fl p Ar percent
···5859steps.
5960.It Fl d
6061Print debugging messages to stdout.
6262+.It Fl K
6363+Only listen for keyboard input when resetting the idle timer.
6164.It Fl k
6265Affect the keyboard backlight as well as the screen backlight.
6366Currently only supported on OpenBSD.
+43-7
xdimmer.c
···6161#include <X11/Xlib.h>
6262#include <X11/extensions/sync.h>
6363#include <X11/extensions/Xrandr.h>
6464+#include <X11/extensions/XInput.h>
6565+#include <X11/extensions/XInput2.h>
64666567#define DEFAULT_DIM_TIMEOUT 120
6668#define DEFAULT_DIM_PERCENTAGE 10
···120122static int dimmed = 0;
121123static int dim_screen = 1;
122124static int use_als = 0;
125125+static int kbd_idle_only = 0;
123126124127/* ALS reading */
125128static float als = -1;
···154157{
155158 int ch;
156159157157- while ((ch = getopt(argc, argv, "ab:dknp:s:t:")) != -1) {
160160+ while ((ch = getopt(argc, argv, "ab:dkKnp:s:t:")) != -1) {
158161 const char *errstr;
159162160163 switch (ch) {
···180183#endif
181184 dim_kbd = 1;
182185 break;
186186+ case 'K':
187187+ kbd_idle_only = 1;
188188+ break;
183189 case 'n':
184190 dim_screen = 0;
185191 break;
···189195 errx(2, "dim percentage: %s", errstr);
190196 break;
191197 case 's':
192192- dim_steps = strtonum(optarg, 1, 100, &errstr);
198198+ dim_steps = strtonum(optarg, 1, 500, &errstr);
193199 if (errstr)
194200 errx(2, "dim steps: %s", errstr);
195201 break;
···241247 dim_timeout));
242248 if (use_als)
243249 DPRINTF(("automatically updating brightness from ALS\n"));
250250+ if (kbd_idle_only)
251251+ DPRINTF(("only watching idle state of keyboard\n"));
244252245253 signal(SIGINT, bail);
246254 signal(SIGTERM, bail);
···261269 XSyncSystemCounter *counters;
262270 XSyncAlarm idle_alarm = None;
263271 XSyncAlarm reset_alarm = None;
272272+ XIDeviceInfo *xinfo;
273273+ char masdname[25];
264274 int sync_event, error;
265265- int major, minor, ncounters;
266266- int i;
275275+ int major, minor, ncounters, ndevices;
276276+ int i, j;
267277268278 if (XSyncQueryExtension(dpy, &sync_event, &error) != True)
269279 errx(1, "no sync extension available");
270280271281 XSyncInitialize(dpy, &major, &minor);
272282283283+ if (kbd_idle_only) {
284284+ xinfo = XIQueryDevice(dpy, XIAllDevices, &ndevices);
285285+ masdname[0] = '\0';
286286+ for (j = 0; j < ndevices; j++) {
287287+ if (xinfo[j].use != XIMasterKeyboard)
288288+ continue;
289289+290290+ snprintf(masdname, sizeof(masdname),
291291+ "DEVICEIDLETIME %d", xinfo[j].deviceid);
292292+ break;
293293+ }
294294+ if (masdname[0] == '\0')
295295+ errx(1, "no xinput master keyboard device found");
296296+ }
297297+273298 counters = XSyncListSystemCounters(dpy, &ncounters);
274299 for (i = 0; i < ncounters; i++) {
275275- if (!strcmp(counters[i].name, "IDLETIME")) {
276276- idler_counter = counters[i].counter;
277277- break;
300300+ if (kbd_idle_only) {
301301+ if (strcmp(counters[i].name, masdname) == 0) {
302302+ DPRINTF(("using idle time of %s\n",
303303+ counters[i].name));
304304+ idler_counter = counters[i].counter;
305305+ break;
306306+ }
307307+ } else {
308308+ if (strcmp(counters[i].name, "IDLETIME") == 0) {
309309+ idler_counter = counters[i].counter;
310310+ break;
311311+ }
278312 }
279313 }
280314 XSyncFreeSystemCounterList(counters);
315315+ if (kbd_idle_only)
316316+ XIFreeDeviceInfo(xinfo);
281317282318 if (!idler_counter)
283319 errx(1, "no idle counter");