[gpm][CORRECT_PATCH] Re: [PATCH] Updated +clock diff

Petr Baudis pasky@pasky.ji.cz
Mon, 5 Aug 2002 19:07:23 +0200


--IrhDeMKUP4DT/M7F
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

Dear diary, on Mon, Aug 05, 2002 at 06:53:28PM CEST, I got a letter,
where Petr Baudis <pasky@pasky.ji.cz> told me, that...
>   here goes updated +clock diff against 1.20.1rc1. Yes, it's still buggy
> somehow and with various evil tricks it's possible to convience it to mess up
> the screen when selecting contents behind it. Yes, it's non-system solution and
> it should rather reside in something like gpm-root. But it's IMHO still very
> tiny and nice feature and living as a patch somewhere is enough for it until
> someone will adapt it to gpm-root.

I'm sorry, this one actually compiles (obviously, it's still available at
http://pasky.ji.cz/~pasky/dev/gpm/ as well).

-- 
 
				Petr "Pasky" Baudis
 
* ELinks maintainer                * IPv6 guy (XS26 co-coordinator)
* IRCnet operator                  * FreeCiv AI occassional hacker
.
You can get much further with a kind word and a gun than you can with a
kind word alone. -- Al Capone
.
Public PGP key && geekcode && homepage: http://pasky.ji.cz/~pasky/

--IrhDeMKUP4DT/M7F
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="clock.diff"

diff -ru gpm-1.20.1rc1/src/gpm.c gpm-1.20.1rc1+clock/src/gpm.c
--- gpm-1.20.1rc1/src/gpm.c	Wed May 29 00:47:24 2002
+++ gpm-1.20.1rc1+clock/src/gpm.c	Mon Aug  5 19:03:10 2002
@@ -32,6 +32,7 @@
 #include <sys/fcntl.h>     /* O_RDONLY */
 #include <sys/wait.h>      /* wait()   */
 #include <sys/stat.h>      /* mkdir()  */
+#include <time.h>          /* time()   */
 #include <sys/time.h>      /* timeval */
 #include <sys/types.h>     /* socket() */
 #include <sys/socket.h>    /* socket() */
@@ -85,6 +86,7 @@
 int opt_aged = 0;
 char *opt_special=NULL; /* special commands, like reboot or such */
 int opt_rawrep=0;
+int opt_clock = 0;
 Gpm_Type *repeated_type=0;
 
 static int opt_resize=0; /* not really an option */
@@ -92,6 +94,7 @@
 struct winsize win;
 int maxx, maxy;
 int fifofd=-1;
+static int clock_printed = -1;
 char *consolename;
 int run_status = GPM_RUN_STARTUP;
 
@@ -243,6 +246,52 @@
    close(fd);
 }
 
+#define CLOCK_FMT "%02d:%02d"
+#define CLOCK_LEN 5
+#define POSITION (4 + 2 * (0 * 80 + (maxx - CLOCK_LEN - 1)))
+
+static void display_clock(int restore)
+{
+    int fd;
+    static char save[CLOCK_LEN * 2];
+
+    if ((fd = open("/dev/vcc/a", O_RDWR)) < 1) {
+	if (errno != ENOENT)
+	    gpm_report(GPM_PR_OOPS,"open(\"/dev/vcc/a\")");
+	if ((fd = open("/dev/vcsa", O_RDWR)) < 1)
+	    gpm_report(GPM_PR_OOPS,"open(\"/dev/vcsa\")");
+    }
+    if (restore == 2) {			/* restore the old characters */
+	lseek(fd, POSITION, 0);
+	write(fd, &save, sizeof(save));
+    } else {				/* print the clock */
+	char buf[CLOCK_LEN * 2], buf0[CLOCK_LEN];
+	time_t t;
+	struct tm *tm;
+	int i, j;
+
+	if (restore == 0) {		/* save the old characters for later */
+	    lseek(fd, POSITION, 0);
+	    read(fd, &save, sizeof(save));
+	}
+	t = time(NULL);
+	tm = localtime(&t);
+	sprintf(buf0, CLOCK_FMT, tm->tm_hour, tm->tm_min);
+	i = j = 0;
+	while (i <= sizeof(buf0)) {	/* add the color attribute */
+	    buf[j++] = buf0[i++];
+	    buf[j++] = '\032';		/* green on blue */
+	}
+	lseek(fd, POSITION, 0);
+	write(fd, &buf, sizeof(buf));
+    }
+    close(fd);
+}
+
+#undef POSITION
+#undef CLOCK_FMT
+#undef CLOCK_LEN
+
 /*-------------------------------------------------------------------*/
 static  inline int do_selection(Gpm_Event *event)  /* returns 0, always */
 {
@@ -253,7 +302,18 @@
    switch(GPM_BARE_EVENTS(event->type)) {
       case GPM_MOVE:
          if (x2<1) x2++; else if (x2>maxx) x2--;
-         if (y2<1) y2++; else if (y2>maxy) y2--;
+	 if (y2<1) y2++; else if (y2>maxy) y2--;
+	 if (opt_clock && x2 == maxx && y2 == 1
+	     && (clock_printed < 0 || clock_printed == event->vc)) {
+	   selection_copy(x2,y2,x2,y2,3);  /* move pointer before saving content
+					      of the screen, so we don't get
+					      pollution after clock hiding */
+	   display_clock(clock_printed);   /* print the clock */
+	   clock_printed = event->vc;
+	 } else if (clock_printed == event->vc) {
+	   display_clock(2);               /* restore the screen */
+	   clock_printed = -1;
+	 }
          selection_copy(x2,y2,x2,y2,3); /* just highlight pointer */
          return 0;
 
diff -ru gpm-1.20.1rc1/src/gpn.c gpm-1.20.1rc1+clock/src/gpn.c
--- gpm-1.20.1rc1/src/gpn.c	Wed May 29 00:39:16 2002
+++ gpm-1.20.1rc1+clock/src/gpn.c	Mon Aug  5 18:46:55 2002
@@ -233,7 +233,7 @@
  *****************************************************************************/
 int cmdline(int argc, char **argv)
 {
-   char options[]="a:A::b:B:d:Dg:hi:kl:m:Mo:pr:R::s:S:t:TvV::23";
+   char options[]="a:A::b:B:cd:Dg:hi:kl:m:Mo:pr:R::s:S:t:TvV::23";
    int i, opt;
    extern int run_status;  /* main */
    extern char *prgname;   /* main */
@@ -263,6 +263,7 @@
             break;
          case 'b': opt_baud = atoi(optarg); break;
          case 'B': opt_sequence = optarg; break;
+	 case 'c': opt_clock = 1; break;
          case 'd': opt_delta = atoi(optarg); break;
          case 'D': run_status = GPM_RUN_DEBUG; break;
          case 'g': opt_glidepoint_tap=atoi(optarg); break;
diff -ru gpm-1.20.1rc1/src/headers/gpmInt.h gpm-1.20.1rc1+clock/src/headers/gpmInt.h
--- gpm-1.20.1rc1/src/headers/gpmInt.h	Sat Feb 23 22:19:07 2002
+++ gpm-1.20.1rc1+clock/src/headers/gpmInt.h	Mon Aug  5 18:43:30 2002
@@ -153,6 +153,7 @@
 extern time_t opt_age_limit;
 extern char *opt_special;
 extern int opt_rawrep;
+extern int opt_clock;
 extern int fifofd;
 extern char *consolename;
 
diff -ru gpm-1.20.1rc1/src/headers/message.h gpm-1.20.1rc1+clock/src/headers/message.h
--- gpm-1.20.1rc1/src/headers/message.h	Wed May 29 00:42:03 2002
+++ gpm-1.20.1rc1+clock/src/headers/message.h	Mon Aug  5 18:48:44 2002
@@ -74,6 +74,7 @@
          "    -A [limit]       start with selection disabled (`aged')\n" \
          "    -b baud-rate     sets the baud rate (default %d)\n" \
          "    -B sequence      allows changing the buttons (default '%s')\n" \
+	 "    -c               print small clock in top-right screen corner\n" \
          "    -d delta         sets the delta value (default %d) (must be 2 or more)\n" \
          "    -D	             debug mode: don't auto-background\n" \
          "    -g tap-button    sets the button (1-3) that is emulated by tapping on\n" \

--IrhDeMKUP4DT/M7F--