]> 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 21922f386a4a860dc0776ed1620d7e19e09aa20e..1f88dc541495281987aa399adaf9a954c378a004 100644 (file)
@@ -117,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;
@@ -185,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);
@@ -236,28 +238,35 @@ eresized(int new)
 }
 
 int
-click(Mouse m)
+label(Win w, Mouse m)
 {
-       char buf[128];
-       int fd, i;      
+       char buf[512], fname[128];
+       int n, fd;
 
-       if((m.buttons & 7) != 4)
-               return 0;
-       for(i=0; i<nwin; i++)
-               if(ptinrect(m.xy, win[i].r))
-                       break;
-       if(i == nwin)
+       snprint(buf, sizeof(buf), "%s", w.label);
+       n = eenter(nil, buf, sizeof(buf), &m);
+       if(n <= 0)
                return 0;
-       do
-               m = emouse();
-       while((m.buttons & 7) == 4);
-       if((m.buttons & 7) || !ptinrect(m.xy, win[i].r))
+       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;
+}
 
-       sprint(buf, "/dev/wsys/%d/wctl", win[i].n);
+int
+unhide(Win w)
+{
+       char buf[128];
+       int fd;
+
+       sprint(buf, "/dev/wsys/%d/wctl", w.n);
        if((fd = open(buf, OWRITE)) < 0)
                return 0;
-       if(win[i].state == (CURRENT|VISIBLE))
+       if(w.state == (CURRENT|VISIBLE))
                write(fd, "hide\n", 5);
        else {
                write(fd, "unhide\n", 7);
@@ -268,51 +277,33 @@ click(Mouse m)
        return 1;
 }
 
-Cursor crosscursor = {
-       {-7, -7},
-       {0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0,
-        0x03, 0xC0, 0x03, 0xC0, 0xFF, 0xFF, 0xFF, 0xFF,
-        0xFF, 0xFF, 0xFF, 0xFF, 0x03, 0xC0, 0x03, 0xC0,
-        0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, 0x03, 0xC0, },
-       {0x00, 0x00, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
-        0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x7F, 0xFE,
-        0x7F, 0xFE, 0x01, 0x80, 0x01, 0x80, 0x01, 0x80,
-        0x01, 0x80, 0x01, 0x80, 0x01, 0x80, 0x00, 0x00, }
-};
-
-void
-chlabel(void)
+int
+click(Mouse m)
 {
-       Mouse m;
-       char buf[512], fname[128];
-       int i, n, fd;
+       int i, b;
 
-       esetcursor(&crosscursor);
-       do
-               m = emouse();
-       while((m.buttons & 7) == 0);
-       do
-               m = emouse();
-       while((m.buttons & 7) == 1);
-       esetcursor(nil);
-       if((m.buttons & 7) != 0)
-               return;
+       b = m.buttons & 7;
+       if(b != 2 && b != 4)
+               return 0;
        for(i=0; i<nwin; i++)
                if(ptinrect(m.xy, win[i].r))
                        break;
        if(i == nwin)
-               return;
-       buf[0] = 0;
-       n = eenter("label?", buf, sizeof(buf), &m);
-       if(n <= 0)
-               return;
-       sprint(fname, "/dev/wsys/%d/label", win[i].n);
-       if((fd = open(fname, OWRITE)) < 0)
-               return;
-       write(fd, buf, n);
-       close(fd);
-       refreshwin();
-       redraw(screen, 1);
+               return 0;
+       do
+               m = emouse();
+       while((m.buttons & 7) == b);
+       if((m.buttons & 7) || !ptinrect(m.xy, win[i].r))
+               return 0;
+
+       switch(b) {
+       case 2:
+               return label(win[i], m);
+       case 4:
+               return unhide(win[i]);
+       default:
+               return 0;
+       }
 }
 
 void
@@ -369,8 +360,6 @@ main(int argc, char **argv)
                case Ekeyboard:
                        if(e.kbdc==Kdel || e.kbdc=='q')
                                exits(0);
-                       if(e.kbdc == 'l')
-                               chlabel();
                        break;
                case Emouse:
                        if(click(e.mouse) == 0)