]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/src/cmd/winwatch.c
libtags, zuke: add *.mod support (thanks kemal)
[plan9front.git] / sys / src / cmd / winwatch.c
index c86ff7a663ddb2966cf8aeffd2c181af69915bcc..1f88dc541495281987aa399adaf9a954c378a004 100644 (file)
@@ -1,8 +1,10 @@
 #include <u.h>
 #include <libc.h>
 #include <draw.h>
+#include <cursor.h>
 #include <event.h>
 #include <regexp.h>
+#include <keyboard.h>
 
 enum {
        VISIBLE = 1,
@@ -115,7 +117,7 @@ refreshwin(void)
                        n = atoi(pd[i].name);
                        if(n == mywinid)
                                continue;
-                       if(readfile(label, sizeof(label), "/dev/wsys/%d/label", n) <= 0)
+                       if(readfile(label, sizeof(label), "/dev/wsys/%d/label", n) < 0)
                                continue;
                        if(exclude != nil && regexec(exclude,label,nil,0))
                                continue;
@@ -183,19 +185,21 @@ drawwin(int i)
 int
 geometry(void)
 {
-       int i, ncols, z;
+       int i, nrows, ncols, z;
        Rectangle r;
 
        z = 0;
-       rows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD);
-       if(rows <= 0)
-               rows = 1;
-       if(rows*cols < nwin || rows*cols >= nwin*2){
-               ncols = nwin <= 0 ? 1 : (nwin+rows-1)/rows;
-               if(ncols != cols){
-                       cols = ncols;
-                       z = 1;
-               }
+       nrows = (Dy(screen->r)-2*MARGIN+PAD)/(font->height+PAD);
+       if(nrows <= 0)
+               nrows = 1;
+       if(nrows != rows){
+               rows = nrows;
+               z = 1;
+       }
+       ncols = nwin <= 0 ? 1 : (nwin+rows-1)/rows;
+       if(ncols != cols){
+               cols = ncols;
+               z = 1;
        }
 
        r = Rect(0,0,(Dx(screen->r)-2*MARGIN+PAD)/cols-PAD, font->height);
@@ -234,12 +238,52 @@ eresized(int new)
 }
 
 int
-click(Mouse m)
+label(Win w, Mouse m)
+{
+       char buf[512], fname[128];
+       int n, fd;
+
+       snprint(buf, sizeof(buf), "%s", w.label);
+       n = eenter(nil, buf, sizeof(buf), &m);
+       if(n <= 0)
+               return 0;
+       sprint(fname, "/dev/wsys/%d/label", w.n);
+       if((fd = open(fname, OWRITE)) < 0)
+               return 0;
+       write(fd, buf, n);
+       close(fd);
+       refreshwin();
+       redraw(screen, 1);
+       return 1;
+}
+
+int
+unhide(Win w)
 {
        char buf[128];
-       int fd, i;      
+       int fd;
+
+       sprint(buf, "/dev/wsys/%d/wctl", w.n);
+       if((fd = open(buf, OWRITE)) < 0)
+               return 0;
+       if(w.state == (CURRENT|VISIBLE))
+               write(fd, "hide\n", 5);
+       else {
+               write(fd, "unhide\n", 7);
+               write(fd, "top\n", 4);
+               write(fd, "current\n", 8);
+       }
+       close(fd);
+       return 1;
+}
+
+int
+click(Mouse m)
+{
+       int i, b;
 
-       if((m.buttons & 7) != 4)
+       b = m.buttons & 7;
+       if(b != 2 && b != 4)
                return 0;
        for(i=0; i<nwin; i++)
                if(ptinrect(m.xy, win[i].r))
@@ -248,22 +292,18 @@ click(Mouse m)
                return 0;
        do
                m = emouse();
-       while((m.buttons & 7) == 4);
+       while((m.buttons & 7) == b);
        if((m.buttons & 7) || !ptinrect(m.xy, win[i].r))
                return 0;
 
-       sprint(buf, "/dev/wsys/%d/wctl", win[i].n);
-       if((fd = open(buf, OWRITE)) < 0)
+       switch(b) {
+       case 2:
+               return label(win[i], m);
+       case 4:
+               return unhide(win[i]);
+       default:
                return 0;
-       if(win[i].state == (CURRENT|VISIBLE))
-               write(fd, "hide\n", 5);
-       else {
-               write(fd, "unhide\n", 7);
-               write(fd, "top\n", 4);
-               write(fd, "current\n", 8);
        }
-       close(fd);
-       return 1;
 }
 
 void
@@ -318,7 +358,7 @@ main(int argc, char **argv)
        for(;;){
                switch(eread(Emouse|Ekeyboard|Etimer, &e)){
                case Ekeyboard:
-                       if(e.kbdc==0x7F || e.kbdc=='q')
+                       if(e.kbdc==Kdel || e.kbdc=='q')
                                exits(0);
                        break;
                case Emouse: