]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/screenlock.c
merge
[plan9front.git] / sys / src / cmd / screenlock.c
index b010a0c173858f6a67c949c6036055e84a9f024f..9ac9fa06442b68315f1bc7e2e351f614019a7568 100644 (file)
@@ -17,6 +17,7 @@ usage(void)
        exits("usage");
 }
 
+/* ^D, Delete, Enter, Backspace, ^U */
 void
 readline(char *buf, int nbuf)
 {
@@ -91,8 +92,8 @@ blanker(void *)
 void
 grabmouse(void*)
 {
+       int fd, x, y;
        char ibuf[256], obuf[256];
-       int fd;
 
        if((fd = open("/dev/mouse", ORDWR)) < 0)
                sysfatal("can't open /dev/mouse: %r");
@@ -102,34 +103,52 @@ grabmouse(void*)
                screen->r.min.y + Dy(screen->r)/2);
 
        while(read(fd, ibuf, sizeof ibuf) > 0){
-               if(!debug)
-                       fprint(fd, "%s", obuf);
-               blank = time(0);
+               ibuf[12] = 0;
+               ibuf[24] = 0;
+               x = atoi(ibuf+1);
+               y = atoi(ibuf+13);
+               if(x != screen->r.min.x + Dx(screen->r)/2 ||
+                  y != screen->r.min.y + Dy(screen->r)/2){
+                       if(!debug)
+                               fprint(fd, "%s", obuf);
+                       blank = time(0);
+               }
+       }
+}
+
+void
+top(void*)
+{
+       int fd;
+
+       if((fd = open("/dev/wctl", OWRITE)) < 0)
+               return;
+
+       for(;;){
+               write(fd, "current", 7);
+               sleep(500);
        }
 }
 
 void
 lockscreen(void)
 {
-       enum { Nfld = 5, Fldlen = 12, Cursorlen = 2*4 + 2*2*16, };
+       enum { Cursorlen = 2*4 + 2*2*16 };
        char *s;
-       char buf[Nfld*Fldlen], *flds[Nfld], newcmd[128], cbuf[Cursorlen];
+       char newcmd[128], cbuf[Cursorlen];
        int fd, dx, dy;
        Image *i;
        Point p;
        Rectangle r;
        Tm *tm;
 
-       if((fd = open("/dev/screen", OREAD)) < 0)
-               sysfatal("can't open /dev/screen: %r");
-       if(read(fd, buf, Nfld*Fldlen) != Nfld*Fldlen)
-               sysfatal("can't read /dev/screen: %r");
-       close(fd);
-       buf[sizeof buf-1] = 0;
-       if(tokenize(buf, flds, Nfld) != Nfld)
-               sysfatal("can't tokenize /dev/screen header");
-       snprint(newcmd, sizeof newcmd, "-r %s %s %s %s",
-               flds[1], flds[2], flds[3], flds[4]);
+       display = initdisplay(nil, nil, nil);
+       if(display == nil)
+               sysfatal("can't open /dev/draw: %r");
+       r = display->image->r;
+       snprint(newcmd, sizeof newcmd, "-r %d %d %d %d",
+               r.min.x, r.min.y, r.max.x, r.max.y);
+       closedisplay(display);
 
        newwindow(newcmd);
        if((fd = open("/dev/consctl", OWRITE)) >= 0)
@@ -172,6 +191,7 @@ lockscreen(void)
        flushimage(display, 1);
 
        /* screen is now open and covered.  grab mouse and hold on tight */
+       procrfork(top, nil, 8*1024, RFFDG);
        procrfork(grabmouse, nil, 8*1024, RFFDG);
        procrfork(blanker, nil, 8*1024, RFFDG);