winwatch: middle mouse button click also prompts for label

This commit is contained in:
spew 2016-10-25 22:53:38 -05:00
parent 7b8c6ae432
commit d5992857bb
2 changed files with 56 additions and 30 deletions

View file

@ -16,6 +16,8 @@ displays the labels of all current
.IR rio (4) .IR rio (4)
windows, refreshing the display every five seconds. windows, refreshing the display every five seconds.
Right clicking a window's label unhides, raises and gives focus to that window. Right clicking a window's label unhides, raises and gives focus to that window.
Right clicking a window again hides the window.
Middle clicking a window's label prompts for a new label.
Typing Typing
.B q .B q
or or
@ -24,7 +26,7 @@ quits
.IR winwatch . .IR winwatch .
Typing Typing
.B l .B l
and selecting a window by left click prompts for a new label. and selecting a window by a click also prompts for a new label.
.PP .PP
If the If the
.B -e .B -e

View file

@ -236,12 +236,52 @@ eresized(int new)
} }
int int
click(Mouse m) label(Win w, Mouse m)
{
char buf[512], fname[128];
int n, fd;
buf[0] = 0;
n = eenter("label?", 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]; char buf[128];
int fd, i; int fd;
if((m.buttons & 7) != 4) 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;
b = m.buttons & 7;
if(b != 2 && b != 4)
return 0; return 0;
for(i=0; i<nwin; i++) for(i=0; i<nwin; i++)
if(ptinrect(m.xy, win[i].r)) if(ptinrect(m.xy, win[i].r))
@ -250,21 +290,16 @@ click(Mouse m)
return 0; return 0;
do do
m = emouse(); m = emouse();
while((m.buttons & 7) == 4); while((m.buttons & 7) == b);
if((m.buttons & 7) || !ptinrect(m.xy, win[i].r)) if((m.buttons & 7) || !ptinrect(m.xy, win[i].r))
return 0; return 0;
sprint(buf, "/dev/wsys/%d/wctl", win[i].n); switch(b) {
if((fd = open(buf, OWRITE)) < 0) case 2:
return 0; return label(win[i], m);
if(win[i].state == (CURRENT|VISIBLE)) case 4:
write(fd, "hide\n", 5); return unhide(win[i]);
else {
write(fd, "unhide\n", 7);
write(fd, "top\n", 4);
write(fd, "current\n", 8);
} }
close(fd);
return 1; return 1;
} }
@ -281,11 +316,10 @@ Cursor crosscursor = {
}; };
void void
chlabel(void) kbdlabel(void)
{ {
Mouse m; Mouse m;
char buf[512], fname[128]; int i;
int i, n, fd;
esetcursor(&crosscursor); esetcursor(&crosscursor);
do do
@ -302,17 +336,7 @@ chlabel(void)
break; break;
if(i == nwin) if(i == nwin)
return; return;
buf[0] = 0; label(win[i], m);
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);
} }
void void
@ -370,7 +394,7 @@ main(int argc, char **argv)
if(e.kbdc==Kdel || e.kbdc=='q') if(e.kbdc==Kdel || e.kbdc=='q')
exits(0); exits(0);
if(e.kbdc == 'l') if(e.kbdc == 'l')
chlabel(); kbdlabel();
break; break;
case Emouse: case Emouse:
if(click(e.mouse) == 0) if(click(e.mouse) == 0)