shithub: npe

Download patch

ref: 320b7d8531b3fb2a1a002ac214c7c703a9e92082
parent: af064114fd7e744e3af0cc67478aab670b5d13c6
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Mon Mar 15 09:30:28 EDT 2021

sdl2: mouse: support middle button

--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -801,7 +801,7 @@
 		}
 		if(mouse.buttons == oldmouse.buttons)
 			break;
-		/* FIXME there is a lot of hope for both buttons to never change at the same time */
+		/* FIXME there is a lot of hope for multiple buttons to never change its state at the same time */
 		if((down = (mouse.buttons & 1)) != (oldmouse.buttons & 1)){ /* left */
 			e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
 			e->button.button = SDL_BUTTON_LEFT;
@@ -808,6 +808,12 @@
 			oldmouse.buttons = (oldmouse.buttons & ~1) | (mouse.buttons & 1);
 			return 1;
 		}
+		if((down = (mouse.buttons & 2)) != (oldmouse.buttons & 2)){ /* middle */
+			e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
+			e->button.button = SDL_BUTTON_MIDDLE;
+			oldmouse.buttons = (oldmouse.buttons & ~2) | (mouse.buttons & 2);
+			return 1;
+		}
 		if((down = (mouse.buttons & 4)) != (oldmouse.buttons & 4)){ /* right */
 			e->type = down ? SDL_MOUSEBUTTONDOWN : SDL_MOUSEBUTTONUP;
 			e->button.button = SDL_BUTTON_RIGHT;
@@ -864,9 +870,10 @@
 	b = 0;
 	if(mouse.buttons & 1)
 		b |= SDL_BUTTON_LMASK;
+	if(mouse.buttons & 2)
+		b |= SDL_BUTTON_MMASK;
 	if(mouse.buttons & 4)
 		b |= SDL_BUTTON_RMASK;
-	/* FIXME no middle button use AT ALL? */
 
 	return b;
 }