shithub: cursedfs

Download patch

ref: 0ddab8b30464a21c79fe7fa43621afd3496bc1ee
parent: df658e1cb061e52186c504e84a8430163e9a090b
author: henesy <henesy.dev@gmail.com>
date: Sun Mar 13 13:59:29 EDT 2022

suicide read/stack overflow

--- a/screen.c
+++ b/screen.c
@@ -15,8 +15,10 @@
 usize sheight = 25, swidth = 80;	// screen height, width
 Lock slock;							// screen buffer lock
 
+Channel	*mchan, *kbchan;			// mouse and kb rcvr chans for fs
+
 /* Menus */
-char *buttons[] = {"exit", 0};
+char *buttons[] = {"exit", 0};	// Maybe a refresh button?
 Menu menu = { buttons };
 
 // Clear the screen
@@ -185,6 +187,19 @@
 
 	/* Main event loop */
 
+	kbchan = chancreate(sizeof (int), 1);
+	mchan = chancreate(sizeof (int), 1);
+	int *kbv = calloc(1, sizeof (int));
+	int *mv  = calloc(1, sizeof (int));
+	Alt kbalt[] = {
+		{kbchan, kbv, CHANSND},
+		{nil, nil, CHANEND},
+	};
+	Alt malt[] = {
+		{mchan, mv, CHANSND},
+		{nil, nil, CHANEND},
+	};
+
 	for(;;){
 		e = event(&ev);
 
@@ -193,7 +208,6 @@
 		 * then exit.. */
 
 		char kbdc;
-		Rune *s;
 		if(e == timer){
 			// Render the screen buffer on ticks (top prio)
 			eresized(0);
@@ -202,6 +216,12 @@
 		}else if(e == Ekeyboard){
 			kbdc = ev.kbdc;
 			// Alt to optionally send if getch channel is listening
+			switch(alt(kbalt)){
+			case 0:
+				*kbv = kbdc;
+				send(kbchan, kbv);
+				break;
+			}
 			
 		}else if(e == Emouse){
 			if((ev.mouse.buttons & 4) 
@@ -210,7 +230,13 @@
 				threadexitsall(nil);
 
 			// Alt to optionally send if getm channel is listening
-
+			switch(alt(malt)){
+			case 0:
+				// Send mouse buttons
+				*mv = ev.mouse.buttons;
+				send(mchan, mv);
+				break;
+			}
 		}
 	}
 }