From 3000145191a00d4c9b90efb221fadb9ce37380c0 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 29 Mar 2007 23:18:14 -0700 Subject: Add -time and -steps options to adjust fade --- xbacklight.c | 25 +++++++++++++++++++++---- xbacklight.man | 7 ++++++- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/xbacklight.c b/xbacklight.c index df99905..9090cb5 100644 --- a/xbacklight.c +++ b/xbacklight.c @@ -21,6 +21,8 @@ usage (void) fprintf(stderr, " -inc or + \n"); fprintf(stderr, " -dec or - \n"); fprintf(stderr, " -get\n"); + fprintf(stderr, " -time \n"); + fprintf(stderr, " -steps \n"); /*NOTREACHED*/ exit (1); } @@ -65,6 +67,8 @@ main (int argc, char **argv) op_t op = Get; int value = 0; int i; + int total_time = 200; /* ms */ + int steps = 20; program_name = argv[0]; @@ -120,10 +124,23 @@ main (int argc, char **argv) op = Get; continue; } + if (!strcmp (argv[i], "-time")) + { + if (++i >= argc) usage(); + total_time = atoi (argv[i]); + continue; + } + if (!strcmp (argv[i], "-steps")) + { + if (++i >= argc) usage(); + steps = atoi (argv[i]); + continue; + } if (!strcmp (argv[i], "-help") || !strcmp (argv[i], "-?")) { usage (); } + usage (); } dpy = XOpenDisplay (dpy_name); if (!dpy) @@ -190,16 +207,16 @@ main (int argc, char **argv) } if (new > max) new = max; if (new < min) new = min; - step = (new - cur) / 50; - for (i = 0; i < 50; i++) + step = (new - cur) / steps; + for (i = 0; i < steps && step != 0; i++) { - if (i == 49) + if (i == steps - 1) cur = new; else cur += step; backlight_set (dpy, output, (long) cur); XFlush (dpy); - usleep (10 * 1000); + usleep (total_time * 1000 / steps); } } } diff --git a/xbacklight.man b/xbacklight.man index 0a998f6..b5a060c 100644 --- a/xbacklight.man +++ b/xbacklight.man @@ -44,8 +44,13 @@ Sets each backlight brightness to the specified level. Increases brightness by the specified amount. .IP "-dec \fIpercent\fP" Decreases brightness by the specified amount. -.IP --help +.IP -help Print out a summary of the usage and exit. +.IP "-time \fImilliseconds\fP" +Length of time to spend fading the backlight between old and new value. +Default is 200. +.IP "-steps \fInumber\fP" +Number of steps to take while faiding. Default is 20. .SH "SEE ALSO" Xrandr(3) .SH AUTHORS -- cgit v1.2.3