ref: 41b28a4595a25d2f1eb076d009ef06460b3276db
parent: b55a9366dc1009f5d98fe4c0a937758afd87bc4b
author: spew <spew@palas>
date: Fri Jan 31 20:43:45 EST 2025
get user interaction working on the other window
--- a/guitest.c
+++ b/guitest.c
@@ -8,8 +8,6 @@
#include <frame.h>
#include "mez.h"
-Mousectl *mc;
-Keyboardctl *kc;
char buf[32000];
Rune lorem[32000];
@@ -18,9 +16,9 @@
MOUSE,
KEYBD,
RESIZE,
- MOUSENICK,
- KEYBDNICK,
- RESIZENICK,
+ MOUSENICKS,
+ KEYBDNICKS,
+ RESIZENICKS,
NCHAN,
Scrollwid = 12, /* width of scroll bar */
@@ -159,6 +157,8 @@
void
threadmain(int argc, char **argv)
{
+ Keyboardctl *kc, *kcnicks;
+ Mousectl *mc, *mcnicks;
Rune r, *rs;
Mouse m;
Chan *chan;
@@ -178,7 +178,7 @@
if((mc = initmouse(nil, screen)) == nil)
sysfatal("initmouse failed: %r");
if((kc = initkeyboard(nil)) == nil)
- sysfatal("initmouse failed: %r");
+ sysfatal("initkeyboard failed: %r");
chan = emallocz(sizeof(*chan), 1);
@@ -191,7 +191,6 @@
textinit(&chan->body);
textaddlines(&chan->body, lorem);
-
len = readn(3, buf, sizeof(buf));
buf[len] = '\0';
for(s = buf, rs = lorem; *s != '\0'; s+=len, rs++)
@@ -205,6 +204,10 @@
mntstr = smprint("new -r %d %d %d %d", screen->r.min.x - Dx(screen->r)/3, screen->r.min.y-4, screen->r.min.x-4, screen->r.max.y+4);
if(mount(fd, -1, "/mnt/wsysnicks", MREPL, mntstr) < 0)
sysfatal("cannot create new window: %r");
+ close(fd);
+ fd = open("/mnt/wsysnicks/label", OWRITE);
+ write(fd, "nicks", sizeof("nicks"));
+ close(fd);
if(gengetwindow(display, "/mnt/wsysnicks/winname", &chan->nicks.screen, &chan->nicks._screen, Refnone) < 0)
sysfatal("cannot get window: %r");
chan->nicks.cols[BACK] = allocimagemix(display, DCyan, DWhite);
@@ -214,11 +217,18 @@
chan->nicks.cols[HTEXT] = display->black;
textinit(&chan->nicks);
textaddlines(&chan->nicks, lorem);
+ if((kcnicks = initkeyboard("/mnt/wsysnicks/cons")) == nil)
+ sysfatal("initkeyboard failed: %r");
+ if((mcnicks = initmouse("/mnt/wsysnicks/mouse", chan->nicks.screen)) == nil)
+ sysfatal("initmouse failed: %r");
Alt a[NCHAN+1] = {
[MOUSE] = {mc->c, &m, CHANRCV},
+ [MOUSENICKS] = {mcnicks->c, &m, CHANRCV},
[RESIZE] = {mc->resizec, nil, CHANRCV},
+ [RESIZENICKS] = {mcnicks->resizec, nil, CHANRCV},
[KEYBD] = {kc->c, &r, CHANRCV},
+ [KEYBDNICKS] = {kcnicks->c, &r, CHANRCV},
[NCHAN] = {nil, nil, CHANEND},
};
textdraw(&chan->body);
@@ -227,6 +237,7 @@
for(;;)switch(alt(a)){
default:
break;
+ case KEYBDNICKS:
case KEYBD:
if(r == Kdel)
goto end;
@@ -241,11 +252,27 @@
m = *mc;
}
break;
+ case MOUSENICKS:
+ if(!ptinrect(m.xy, chan->nicks.scrollr))
+ break;
+ while(m.buttons == 2){
+ texttopline(&chan->nicks, m.xy.y);
+ textdraw(&chan->nicks);
+ readmouse(mcnicks);
+ m = *mcnicks;
+ }
+ break;
case RESIZE:
if(getwindow(display, Refnone) < 0)
sysfatal("%s: %r", argv0);
textinit(&chan->body);
textdraw(&chan->body);
+ break;
+ case RESIZENICKS:
+ if(gengetwindow(display, "/mnt/wsysnicks/winname", &chan->nicks.screen, &chan->nicks._screen, Refnone) < 0)
+ sysfatal("%s: %r", argv0);
+ textinit(&chan->nicks);
+ textdraw(&chan->nicks);
break;
}
end: