Re: tiocl.h

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Samuel Thibault, le Tue 27 Nov 2007 22:41:46 +0000, a écrit :
> Samuel Thibault, le Tue 27 Nov 2007 22:39:53 +0000, a écrit :
> > 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.
> > 
> > Setterm should probably provide options for these, which could they be?
> 
> (that could be for instance -blank [0-60|force|poke|], but the parsing
> code is shared with -powerdown...)

(the code could be something like attached)

Samuel

diff --git a/misc-utils/setterm.c b/misc-utils/setterm.c
index eda99a3..2c8dc69 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 ]
@@ -151,6 +151,11 @@ 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
+
 /* Control sequences. */
 #define ESC "\033"
 #define DCS "\033P"
@@ -391,11 +396,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;
 	}
 }
 
@@ -1034,8 +1045,27 @@ 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 = 14;	/* blankscreen */
+			if (ioctl(0,TIOCLINUX,&ioctlarg))
+				fprintf(stderr,_("cannot force blank\n"));
+		} else if (opt_bl_min == UNBLANKSCREEN) {
+			char ioctlarg = 4;	/* unblankscreen */
+			if (ioctl(0,TIOCLINUX,&ioctlarg))
+				fprintf(stderr,_("cannot force blank\n"));
+		} else if (opt_bl_min == BLANKEDSCREEN) {
+			char ioctlarg = 15;	/* 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) {
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux