ref: d4cabc863723fbc7bc94d9223c27665a9f95ed26
parent: 3c761dea5de8d7b2bce06a39c51c7885f08910de
author: henesy <[email protected]>
date: Tue Mar 15 10:14:47 EDT 2022
working cross proc cross channel printing and event handling
--- a/fs.h
+++ b/fs.h
@@ -8,6 +8,9 @@
// All available files on the 9p fs
extern File9 *files[Nfiles];
+/* Channels for mouse and kb events */
+extern Channel *mchan, *kbchan;
+
// Init the draw screen
void initscreen(void*);
// Put a rune on the screen (x,y)
--- a/main.c
+++ b/main.c
@@ -151,6 +151,36 @@
threadexits(nil);
}
+
+// Drain channels
+void
+drainer(void*)
+{
+ int mv, kbv;
+ Alt alts[3];
+ alts[0].c = mchan;
+ alts[0].v = &mv;
+ alts[0].op = CHANRCV;
+ alts[1].c = kbchan;
+ alts[1].v = &kbv;
+ alts[1].op = CHANRCV;
+ alts[2].op = CHANEND;
+
+ for(;;)
+ switch(alt(alts)){
+ case 0:
+ putstring(runesmprint(" %d", mv), 2);
+ break;
+ case 1:
+ putstring(runesmprint(" %d", kbv), 4);
+ break;
+ default:
+ break;
+ }
+
+}
+
+
/* A simple 9p fileserver to show a minimal set of operations */
void
threadmain(int argc, char *argv[])
@@ -176,12 +206,14 @@
if(argc != 0)
usage();
+ kbchan = chancreate(sizeof (int), 20);
+ mchan = chancreate(sizeof (int), 20);
+
+ proccreate(drainer, nil, mainstacksize);
proccreate(initfs, nil, mainstacksize);
proccreate(initscreen, nil, mainstacksize);
threadexits(nil);
}
-
-
// Handle 9p attach -- independent implementation
static void
--- a/screen.c
+++ b/screen.c
@@ -198,8 +198,6 @@
/* Main event loop */
- kbchan = chancreate(sizeof (int), 10);
- mchan = chancreate(sizeof (int), 10);
//kbv = calloc(1, sizeof (int));
//mv = calloc(1, sizeof (int));
//memset(&alts, 0, sizeof alts);
@@ -228,6 +226,7 @@
kbdc = ev.kbdc;
// Alt to optionally send if getch channel is listening
kbv = kbdc;
+ //putstring(runesmprint(" %d", kbv), 2);
}else if(e == Emouse){
if((ev.mouse.buttons & 4)
@@ -238,7 +237,7 @@
// Alt to optionally send if getm channel is listening
mv = ev.mouse.buttons;
}
- /* « deadlocks »
+ /* « deadlocks » */
switch(alt(alts)){
case 0:
break;
@@ -247,6 +246,6 @@
default:
break;
}
- */
+
}
}