shithub: lola

Download patch

ref: 7b72e7637b8b59b1c30603d310be1b293f620f34
parent: 5d3ac7411f3e3193b721822d94683a647b90aeb3
author: aap <aap@papnet.eu>
date: Mon Mar 4 12:20:33 EST 2024

release keys and mouse buttons on focus loss.

--- a/TODO
+++ b/TODO
@@ -2,7 +2,6 @@
 rethink hiding/unhiding
 check for bad rects (what's left here?)
 top/bottom/current seems to work a bit different in rio
-release keys and buttons when unfocused
 make sure there are no deadlocks
 ...
 
--- a/main.c
+++ b/main.c
@@ -126,12 +126,15 @@
 }
 
 void
-drainmouse(Mousectl *mc, Channel *c)
+drainmouse(Mousectl *mc, Window *w)
 {
-	if(c) send(c, &mc->Mouse);
+	if(w) send(w->mc.c, &mc->Mouse);
 	while(mc->buttons){
 		readmouse(mc);
-		if(c) send(c, &mc->Mouse);
+		/* stop sending once focus changes.
+		 * buttons released in wfocus() */
+		if(w != focused) w = nil;
+		if(w) send(w->mc.c, &mc->Mouse);
 	}
 }
 
@@ -597,7 +600,7 @@
 			if(mctl->buttons && topwin != w)
 				wraise(w);
 			if(mctl->buttons & (1|8|16) || ptinrect(mctl->xy, w->text.scrollr))
-				drainmouse(mctl, w->mc.c);
+				drainmouse(mctl, w);
 			if(mctl->buttons & 2){
 				incref(w);
 				btn2menu(w);
@@ -607,7 +610,7 @@
 				btn3menu();
 		}else{
 			wsetcursor(w);
-			drainmouse(mctl, w->mc.c);
+			drainmouse(mctl, w);
 		}
 	}
 }
--- a/wind.c
+++ b/wind.c
@@ -386,6 +386,17 @@
 		return;
 	prev = focused;
 	focused = w;
+	if(prev){
+		/* release keys (if possible) */
+		char *s = estrdup("K");
+		if(nbsendp(prev->kbd, s) != 1)
+			free(s);
+		/* release mouse buttons */
+		if(prev->mc.buttons){
+			prev->mc.buttons = 0;
+			prev->mq.counter++;
+		}
+	}
 	wfocuschanged(prev);
 	wfocuschanged(focused);
 }