BOARD-patches/sdl2: force window focus(kbd/mouse) and restrict mouse x/y (#141)

- mv custom sdl2 patches to miyoo
- focus on window a restritc mouse moves (hack)
This commit is contained in:
Apaczer
2024-12-11 21:43:58 +01:00
committed by GitHub
parent 7eb45df5a8
commit 28019c452b
3 changed files with 120 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
From 3b5366a8ff954159a18af6512c90a2e1bd9389b9 Mon Sep 17 00:00:00 2001
From: Apaczer <94932128+Apaczer@users.noreply.github.com>
Date: Thu, 21 Nov 2024 22:24:14 +0100
Subject: [PATCH 1/2] SDL_DirectFB_events: always focus on SDL_Window
with mouse & keyboard respectivly
---
src/video/directfb/SDL_DirectFB_events.c | 29 +++++-------------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/src/video/directfb/SDL_DirectFB_events.c b/src/video/directfb/SDL_DirectFB_events.c
index e6ca47ad3..6b211eb88 100644
--- a/src/video/directfb/SDL_DirectFB_events.c
+++ b/src/video/directfb/SDL_DirectFB_events.c
@@ -178,6 +178,12 @@ ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
SDL_Keysym keysym;
Uint32 unicode;
char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
+ FocusAllMice(_this, sdlwin);
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
+ DirectFB_SetContext(_this, sdlwin);
+ FocusAllKeyboards(_this, sdlwin);
+ SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
+ 0, 0);
if (evt->clazz == DFEC_WINDOW) {
switch (evt->type) {
@@ -274,29 +280,6 @@ ProcessWindowEvent(_THIS, SDL_Window *sdlwin, DFBWindowEvent * evt)
case DWET_CLOSE:
SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_CLOSE, 0, 0);
break;
- case DWET_GOTFOCUS:
- DirectFB_SetContext(_this, sdlwin);
- FocusAllKeyboards(_this, sdlwin);
- SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_GAINED,
- 0, 0);
- break;
- case DWET_LOSTFOCUS:
- SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_FOCUS_LOST, 0, 0);
- FocusAllKeyboards(_this, 0);
- break;
- case DWET_ENTER:
- /* SDL_DirectFB_ReshowCursor(_this, 0); */
- FocusAllMice(_this, sdlwin);
- /* FIXME: when do we really enter ? */
- if (ClientXY(windata, &evt->x, &evt->y))
- MotionAllMice(_this, evt->x, evt->y);
- SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_ENTER, 0, 0);
- break;
- case DWET_LEAVE:
- SDL_SendWindowEvent(sdlwin, SDL_WINDOWEVENT_LEAVE, 0, 0);
- FocusAllMice(_this, 0);
- /* SDL_DirectFB_ReshowCursor(_this, 1); */
- break;
default:
;
}
--
2.45.2.windows.1

View File

@@ -0,0 +1,60 @@
From f8be41d773280e0e316ce69de4bf90b9ad636e57 Mon Sep 17 00:00:00 2001
From: Apaczer <94932128+Apaczer@users.noreply.github.com>
Date: Sun, 24 Nov 2024 21:44:03 +0100
Subject: [PATCH 2/2] SDL_mouse: block relative mouse mv beyond screen res
---
src/events/SDL_mouse.c | 30 ++++++++++++++++++++++++++----
1 file changed, 26 insertions(+), 4 deletions(-)
diff --git a/src/events/SDL_mouse.c b/src/events/SDL_mouse.c
index 259ee9f20..d86f43e95 100644
--- a/src/events/SDL_mouse.c
+++ b/src/events/SDL_mouse.c
@@ -401,8 +401,8 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
mouse->x = x;
mouse->y = y;
} else {
- mouse->x += xrel;
- mouse->y += yrel;
+ mouse->x = mouse->last_x + xrel;
+ mouse->y = mouse->last_y + yrel;
}
/* make sure that the pointers find themselves inside the windows,
@@ -473,8 +473,30 @@ SDL_PrivateSendMouseMotion(SDL_Window * window, SDL_MouseID mouseID, int relativ
posted = (SDL_PushEvent(&event) > 0);
}
if (relative) {
- mouse->last_x = mouse->x;
- mouse->last_y = mouse->y;
+ int screen_width = 0;
+ int screen_height = 0;
+
+ SDL_DisplayMode displayMode;
+ if ((SDL_GetCurrentDisplayMode(0, &displayMode) == 0)) {
+ screen_width = displayMode.w;
+ screen_height = displayMode.h;
+ --screen_width;
+ --screen_height;
+
+ if (mouse->x > screen_width) {
+ mouse->last_x = screen_width;
+ } else if (mouse->x < 0) {
+ mouse->last_x = 0;
+ } else
+ mouse->last_x = mouse->x;
+
+ if (mouse->y > screen_height) {
+ mouse->last_y = screen_height;
+ } else if (mouse->y < 0) {
+ mouse->last_y = 0;
+ } else
+ mouse->last_y = mouse->y;
+ }
} else {
/* Use unclamped values if we're getting events outside the window */
mouse->last_x = x;
--
2.45.2.windows.1