From 5c55d9bf1ae789fd25d5e4153c699134706c2e9f Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Tue, 27 Nov 2007 22:54:35 +0000 Subject: [PATCH] setterm: add -blan [force|poke] options for TIOCL_{BLANKED,BLANK}SCREEN Linux has some interface to force an immediate blank (TIOCL_BLANK/UNBLANKSCREEN) or get the blank status (TIOCL_BLANKEDSCREEN), which is useful e.g. for blind people. Co-Author: Karel Zak Signed-off-by: Samuel Thibault Signed-off-by: Karel Zak --- configure.ac | 1 + misc-utils/setterm.1 | 10 +++++++- misc-utils/setterm.c | 61 ++++++++++++++++++++++++++++++++++++-------- 3 files changed, 61 insertions(+), 11 deletions(-) diff --git a/configure.ac b/configure.ac index a148e28d..3bedf2ca 100644 --- a/configure.ac +++ b/configure.ac @@ -56,6 +56,7 @@ AC_CHECK_HEADERS( sys/io.h \ pty.h \ err.h \ + linux/tiocl.h \ linux/version.h]) AC_CHECK_HEADERS([linux/raw.h], [AM_CONDITIONAL([HAVE_RAW], [true])], diff --git a/misc-utils/setterm.1 b/misc-utils/setterm.1 index 86c3635d..ec4b6a88 100644 --- a/misc-utils/setterm.1 +++ b/misc-utils/setterm.1 @@ -133,10 +133,18 @@ Clears tab stops from the given horizontal cursor positions, in the range Clears all tab stops, then sets a regular tab stop pattern, with one tab every specified number of positions. Without an argument, defaults to 8. .TP -.BR \-blank " [0-60] (virtual consoles only)" +.BR \-blank " [0-60|force|poke] (virtual consoles only)" Sets the interval of inactivity, in minutes, after which the screen will be automatically blanked (using APM if available). Without an argument, defaults to 0 (disable console blanking). + +The +.B force +option keeps screen blank even if a key is pressed. + +The +.B poke +option returns which vt was blanked. .TP .BR \-dump " [1-NR_CONS]" Writes a snapshot of the given virtual console (with attributes) to the file diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c index eda99a34..2646fc38 100644 --- a/misc-utils/setterm.c +++ b/misc-utils/setterm.c @@ -50,7 +50,7 @@ * [ -tabs [tab1 tab2 tab3 ... ] ] (tabn = 1-160) * [ -clrtabs [ tab1 tab2 tab3 ... ] (tabn = 1-160) * [ -regtabs [1-160] ] - * [ -blank [0-60] ] + * [ -blank [0-60|force|poke|] ] * [ -dump [1-NR_CONS ] ] * [ -append [1-NR_CONS ] ] * [ -file dumpfilename ] @@ -112,6 +112,9 @@ #include /* for MAXPATHLEN */ #include #include +#ifdef HAVE_LINUX_TIOCL_H +#include +#endif #include "nls.h" #if __GNU_LIBRARY__ < 5 @@ -151,6 +154,19 @@ extern int klogctl(int type, char *buf, int len); #define GREY 8 #define DEFAULT 9 +/* Blank commands */ +#define BLANKSCREEN -1 +#define UNBLANKSCREEN -2 +#define BLANKEDSCREEN -3 + +/* fallback */ +#ifndef TIOCL_BLANKSCREEN +# define TIOCL_UNBLANKSCREEN 4 /* unblank screen */ +# define TIOCL_SETVESABLANK 10 /* set vesa blanking mode */ +# define TIOCL_BLANKSCREEN 14 /* keep screen blank even if a key is pressed */ +# define TIOCL_BLANKEDSCREEN 15 /* return which vt was blanked */ +#endif + /* Control sequences. */ #define ESC "\033" #define DCS "\033P" @@ -391,11 +407,17 @@ parse_blank(int argc, char **argv, int *option, int *opt_all, int *bad_arg) { *bad_arg = TRUE; *option = TRUE; if (argc == 1) { - *opt_all = atoi(argv[0]); - if ((*opt_all > 60) || (*opt_all < 0)) - *bad_arg = TRUE; + if (!strcmp(argv[0], "force")) + *opt_all = BLANKSCREEN; + else if (!strcmp(argv[0], "poke")) + *opt_all = UNBLANKSCREEN; + else { + *opt_all = atoi(argv[0]); + if ((*opt_all > 60) || (*opt_all < 0)) + *bad_arg = TRUE; + } } else { - *opt_all = 0; + *opt_all = BLANKEDSCREEN; } } @@ -779,7 +801,7 @@ usage(char *prog_name) { fprintf(stderr, _(" [ -tabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n")); fprintf(stderr, _(" [ -clrtabs [ tab1 tab2 tab3 ... ] ] (tabn = 1-160)\n")); fprintf(stderr, _(" [ -regtabs [1-160] ]\n")); - fprintf(stderr, _(" [ -blank [0-60] ]\n")); + fprintf(stderr, _(" [ -blank [0-60|force|poke] ]\n")); fprintf(stderr, _(" [ -dump [1-NR_CONSOLES] ]\n")); fprintf(stderr, _(" [ -append [1-NR_CONSOLES] ]\n")); fprintf(stderr, _(" [ -file dumpfilename ]\n")); @@ -1034,13 +1056,32 @@ perform_sequence(int vcterm) { } /* -blank [0-60]. */ - if (opt_blank && vcterm) - printf("\033[9;%d]", opt_bl_min); - + if (opt_blank && vcterm) { + if (opt_bl_min >= 0) + printf("\033[9;%d]", opt_bl_min); + else if (opt_bl_min == BLANKSCREEN) { + char ioctlarg = TIOCL_BLANKSCREEN; + if (ioctl(0,TIOCLINUX,&ioctlarg)) + fprintf(stderr,_("cannot force blank\n")); + } else if (opt_bl_min == UNBLANKSCREEN) { + char ioctlarg = TIOCL_UNBLANKSCREEN; + if (ioctl(0,TIOCLINUX,&ioctlarg)) + fprintf(stderr,_("cannot force unblank\n")); + } else if (opt_bl_min == BLANKEDSCREEN) { + char ioctlarg = TIOCL_BLANKEDSCREEN; + int ret; + ret = ioctl(0,TIOCLINUX,&ioctlarg); + if (ret < 0) + fprintf(stderr,_("cannot get blank status\n")); + else + printf("%d\n",ret); + } + } + /* -powersave [on|vsync|hsync|powerdown|off] (console) */ if (opt_powersave) { char ioctlarg[2]; - ioctlarg[0] = 10; /* powersave */ + ioctlarg[0] = TIOCL_SETVESABLANK; ioctlarg[1] = opt_ps_mode; if (ioctl(0,TIOCLINUX,ioctlarg)) fprintf(stderr,_("cannot (un)set powersave mode\n")); -- 2.39.5