shithub: npe

Download patch

ref: be42952f4bdd48141161a0025f28b900ba36b2f5
parent: caf026b08552e401a28cf71c2824c44cb20eccb3
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Wed Mar 17 12:43:21 EDT 2021

sdl2: SDL_WaitThread (and proper "detach"), SDL_ShowWindow nop stub; add more scancodes

--- a/include/npe/SDL2/SDL.h
+++ b/include/npe/SDL2/SDL.h
@@ -130,6 +130,8 @@
 char *SDL_GetPrefPath(char *org, char *app);
 int SDL_SetRenderDrawColor(SDL_Renderer *r, Uint8 r, Uint8 g, Uint8 b, Uint8 a);
 int SDL_GetCurrentDisplayMode(int displayIndex, SDL_DisplayMode *mode);
+void SDL_WaitThread(SDL_Thread *thread, int *status);
+void SDL_ShowWindow(SDL_Window *w);
 
 enum {
 	AUDIO_S16,
@@ -151,6 +153,7 @@
 	SDL_WINDOW_ALLOW_HIGHDPI = 1<<3,
 	SDL_WINDOW_SHOWN = 1<<4,
 	SDL_WINDOW_RESIZABLE = 1<<5,
+	SDL_WINDOW_HIDDEN = 1<<6,
 
 	SDL_WINDOWPOS_CENTERED = -1,
 	SDL_WINDOWPOS_UNDEFINED = -2,
@@ -190,6 +193,7 @@
 
 enum {
 	/* these HAVE to be in this order for notes to work in ft2-clone */
+	SDL_SCANCODE_UNKNOWN,
 	SDL_SCANCODE_A = 0x04,
 	SDL_SCANCODE_B,
 	SDL_SCANCODE_C,
@@ -226,7 +230,7 @@
 	SDL_SCANCODE_8,
 	SDL_SCANCODE_9,
 	SDL_SCANCODE_0,
-	SDL_SCANCODE_ENTER,
+	SDL_SCANCODE_RETURN,
 	SDL_SCANCODE_ESCAPE,
 	SDL_SCANCODE_BACKSPACE,
 	SDL_SCANCODE_TAB,
@@ -242,8 +246,28 @@
 	SDL_SCANCODE_GRAVE,
 	SDL_SCANCODE_SLASH,
 	SDL_SCANCODE_CAPSLOCK,
-
-	SDL_SCANCODE_RIGHT = 0x4f,
+	SDL_SCANCODE_F1,
+	SDL_SCANCODE_F2,
+	SDL_SCANCODE_F3,
+	SDL_SCANCODE_F4,
+	SDL_SCANCODE_F5,
+	SDL_SCANCODE_F6,
+	SDL_SCANCODE_F7,
+	SDL_SCANCODE_F8,
+	SDL_SCANCODE_F9,
+	SDL_SCANCODE_F10,
+	SDL_SCANCODE_F11,
+	SDL_SCANCODE_F12,
+	SDL_SCANCODE_PRINTSCREEN,
+	SDL_SCANCODE_SCROLLLOCK,
+	SDL_SCANCODE_PAUSE,
+	SDL_SCANCODE_INSERT,
+	SDL_SCANCODE_HOME,
+	SDL_SCANCODE_PAGEUP,
+	SDL_SCANCODE_DELETE,
+	SDL_SCANCODE_END,
+	SDL_SCANCODE_PAGEDOWN,
+	SDL_SCANCODE_RIGHT,
 	SDL_SCANCODE_LEFT,
 	SDL_SCANCODE_DOWN,
 	SDL_SCANCODE_UP,
@@ -266,10 +290,22 @@
 	SDL_SCANCODE_KP_PERIOD,
 	SDL_SCANCODE_NONUSBACKSLASH,
 
+	SDL_SCANCODE_MENU = 0x76,
+
 	SDL_SCANCODE_MUTE = 0x7f,
 	SDL_SCANCODE_VOLUMEUP,
 	SDL_SCANCODE_VOLUMEDOWN,
 
+	SDL_SCANCODE_LCTRL = 0xe0,
+	SDL_SCANCODE_LSHIFT,
+	SDL_SCANCODE_LALT,
+	SDL_SCANCODE_LGUI,
+	SDL_SCANCODE_RCTRL,
+	SDL_SCANCODE_RSHIFT,
+	SDL_SCANCODE_RALT,
+	SDL_SCANCODE_RGUI,
+
+	SDL_SCANCODE_MODE = 0x101,
 	SDL_SCANCODE_AUDIOMUTE = 0x106,
 
 	SDLK_a = 'a',
@@ -363,6 +399,7 @@
 	KMOD_RALT = KMOD_LALT,
 	KMOD_LGUI = 1<<3,
 	KMOD_RGUI = KMOD_LGUI,
+	KMOD_CAPS = 1<<4,
 
 	SDL_KEYDOWN = 0,
 	SDL_KEYUP,
--- a/libnpe_sdl2/sdl2.c
+++ b/libnpe_sdl2/sdl2.c
@@ -56,6 +56,7 @@
 	SDL_ThreadFunction f;
 	char *name;
 	void *userdata;
+	Channel *wait;
 };
 
 static SDL_PixelFormat argb8888 = {
@@ -420,14 +421,19 @@
 static void
 sdlthread(void *p)
 {
-	SDL_Thread t;
+	SDL_Thread *t;
+	int res;
 
-	t = *(SDL_Thread*)p;
-	if(t.name != nil)
-		threadsetname(t.name);
-	free(p);
+	t = p;
+	if(t->name != nil)
+		threadsetname(t->name);
 
-	threadexits(t.f(t.userdata) == 0 ? nil : "error");
+	res = t->f(t->userdata);
+	send(t->wait, &res);
+	chanfree(t->wait);
+	free(t);
+
+	threadexits(res == 0 ? nil : "error");
 }
 
 SDL_Thread *
@@ -441,8 +447,10 @@
 	t->f = f;
 	t->name = name;
 	t->userdata = userdata;
+	t->wait = chancreate(sizeof(int), 0);
 
 	if(proccreate(sdlthread, t, mainstacksize) < 0){
+		chanfree(t->wait);
 		free(t);
 		t = nil;
 	}
@@ -451,10 +459,22 @@
 }
 
 void
-SDL_DetachThread(SDL_Thread *)
+SDL_DetachThread(SDL_Thread *t)
 {
+	chanclose(t->wait);
 }
 
+
+void
+SDL_WaitThread(SDL_Thread *t, int *status)
+{
+	int r;
+
+	recv(t->wait, &r);
+	if(status != nil)
+		*status = r;
+}
+
 static void *
 readfile(char *path, int *got)
 {
@@ -776,7 +796,7 @@
 	if(r >= '1' && r <= '9')
 		return r - '1' + SDL_SCANCODE_1;
 	if(r == '0')  return SDL_SCANCODE_0;
-	if(r == '\n') return SDL_SCANCODE_ENTER;
+	if(r == '\n') return SDL_SCANCODE_RETURN;
 	if(r == Kesc) return SDL_SCANCODE_ESCAPE;
 	if(r == Kbs)  return SDL_SCANCODE_BACKSPACE;
 	if(r == '\t') return SDL_SCANCODE_TAB;
@@ -794,8 +814,22 @@
 	if(r == Kleft) return SDL_SCANCODE_LEFT;
 	if(r == Kdown) return SDL_SCANCODE_DOWN;
 	if(r == Kup) return SDL_SCANCODE_UP;
+	if(r == Kins) return SDL_SCANCODE_INSERT;
+	if(r == Khome) return SDL_SCANCODE_HOME;
+	if(r == Kpgup) return SDL_SCANCODE_PAGEUP;
+	if(r == Kdel) return SDL_SCANCODE_DELETE;
+	if(r == Kend) return SDL_SCANCODE_END;
+	if(r == Kpgdown) return SDL_SCANCODE_PAGEDOWN;
+	if(r == Kctl) return SDL_SCANCODE_LCTRL;
+	if(r == Kshift) return SDL_SCANCODE_LSHIFT;
+	if(r == Kalt) return SDL_SCANCODE_LALT;
+	if(r == Kmod4) return SDL_SCANCODE_LGUI;
 
+	if(r >= (KF|1) && r <= (KF|12)) return SDL_SCANCODE_F1 + r - (KF|1);
+
 /* FIXME
+	SDL_SCANCODE_PRINTSCREEN = 0x46,
+	SDL_SCANCODE_SCROLLLOCK,
 	SDL_SCANCODE_NUMLOCKCLEAR,
 	SDL_SCANCODE_KP_DIVIDE,
 	SDL_SCANCODE_KP_MULTIPLY,
@@ -1379,6 +1413,12 @@
 
 void
 SDL_RaiseWindow(SDL_Window *)
+{
+	/* nothing to do here */
+}
+
+void
+SDL_ShowWindow(SDL_Window *)
 {
 	/* nothing to do here */
 }