libsdl2: add support for relative mouse mode

This commit is contained in:
Gerasim Troeglazov
2018-09-18 20:49:04 +10:00
parent 2176b3e841
commit b40072d3d2
2 changed files with 154 additions and 19 deletions

View File

@@ -6,7 +6,7 @@ software, emulators, and popular games."
HOMEPAGE="https://www.libsdl.org/"
COPYRIGHT="1997-2018 Sam Lantinga"
LICENSE="Zlib"
REVISION="1"
REVISION="2"
SOURCE_URI="https://www.libsdl.org/release/SDL2-$portVersion.tar.gz"
CHECKSUM_SHA256="edc77c57308661d576e843344d8638e025a7818bff73f8fbfab09c3c5fd092ec"
SOURCE_DIR="SDL2-$portVersion"

View File

@@ -1,11 +1,11 @@
From 5b995581729cb06e58f1d71cb286135951e5d2a5 Mon Sep 17 00:00:00 2001
From 8de05611ed9fddb79890310f63a5e3c6baeeb05c Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Fri, 29 Aug 2014 15:24:11 +0000
Subject: haiku patch
diff --git a/src/video/haiku/SDL_bopengl.cc b/src/video/haiku/SDL_bopengl.cc
index 6bf7a17..0b60466 100644
index 3456932..d32eb94 100644
--- a/src/video/haiku/SDL_bopengl.cc
+++ b/src/video/haiku/SDL_bopengl.cc
@@ -54,7 +54,7 @@ int BE_GL_LoadLibrary(_THIS, const char *path)
@@ -27,20 +27,20 @@ index 6bf7a17..0b60466 100644
&location)) == B_OK) {
return location;
--
2.15.1
2.19.0
From 6cb2a822e56dcd960dd788b84fd7ea48e67caa2a Mon Sep 17 00:00:00 2001
From f81ab56a49a14808f23270f1ac4c7c069f570b48 Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Thu, 25 Feb 2016 20:23:41 +0000
Subject: remove nacl, missing templates on Haiku
diff --git a/configure.in b/configure.in
index 5ac2130..fbfe2cc 100644
index 1c7e793..8e3a74b 100644
--- a/configure.in
+++ b/configure.in
@@ -1530,33 +1530,6 @@ AC_HELP_STRING([--enable-mir-shared], [dynamically load Mir support [[default=ma
@@ -1538,33 +1538,6 @@ AC_HELP_STRING([--enable-mir-shared], [dynamically load Mir support [[default=ma
fi
}
@@ -75,20 +75,20 @@ index 5ac2130..fbfe2cc 100644
{
AC_ARG_ENABLE(video-rpi,
--
2.15.1
2.19.0
From f289ca347419e84ab5bce1e0f9992ea56289ed57 Mon Sep 17 00:00:00 2001
From af792add5f34e3b7ae2429bff09af309a65f59bc Mon Sep 17 00:00:00 2001
From: Jerome Duval <jerome.duval@gmail.com>
Date: Sat, 30 Sep 2017 13:36:12 +0200
Subject: fix AC_DEFINE
diff --git a/configure.in b/configure.in
index fbfe2cc..c77e630 100644
index 8e3a74b..d4d38e4 100644
--- a/configure.in
+++ b/configure.in
@@ -1829,7 +1829,7 @@ int event_type = XI_TouchBegin;
@@ -1841,7 +1841,7 @@ int event_type = XI_TouchBegin;
XITouchClassInfo *t;
],[
have_xinput2_multitouch=yes
@@ -98,10 +98,10 @@ index fbfe2cc..c77e630 100644
])
AC_MSG_RESULT($have_xinput2_multitouch)
--
2.15.1
2.19.0
From 289f0c1f881d64367c560e913f686cf45adaa567 Mon Sep 17 00:00:00 2001
From ffd0621c69136cb61f6513c52b1ae784bd391b66 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Fri, 2 Feb 2018 09:40:46 +0100
Subject: Fix secondary arch build.
@@ -132,10 +132,10 @@ index fe56652..47d9c82 100644
install: all install-bin install-hdrs install-lib install-data
install-bin:
diff --git a/configure.in b/configure.in
index c77e630..ffb09bb 100644
index d4d38e4..7c3a166 100644
--- a/configure.in
+++ b/configure.in
@@ -3595,9 +3595,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
@@ -3642,9 +3642,6 @@ AC_HELP_STRING([--enable-render-d3d], [enable the Direct3D render driver [[defau
# The Haiku platform requires special setup.
SOURCES="$srcdir/src/main/haiku/*.cc $SOURCES"
EXTRA_LDFLAGS="$EXTRA_LDFLAGS -lroot -lbe -lmedia -lgame -ldevice -ltextencoding"
@@ -146,10 +146,10 @@ index c77e630..ffb09bb 100644
arm*-apple-darwin*|*-ios-*)
ARCH=ios
--
2.15.1
2.19.0
From b15465c0835d6e998b6255a7654d14fb7b8b030d Mon Sep 17 00:00:00 2001
From 26d7a60c26b9fa2a8534c5df5b69a0973184d437 Mon Sep 17 00:00:00 2001
From: Adrien Destugues <pulkomandy@pulkomandy.tk>
Date: Fri, 2 Feb 2018 10:40:00 +0100
Subject: Fix crash when opening window
@@ -161,7 +161,7 @@ Subject: Fix crash when opening window
grow.
diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h
index a20147a..105ebb5 100644
index 3e61888..bd4aae7 100644
--- a/src/video/haiku/SDL_BWin.h
+++ b/src/video/haiku/SDL_BWin.h
@@ -86,6 +86,7 @@ class SDL_BWin:public BDirectWindow
@@ -204,5 +204,140 @@ index a20147a..105ebb5 100644
thread_id _draw_thread_id;
--
2.15.1
2.19.0
From e8a281bfa86e9ecaaa297cd60f3bc8499dd8bebe Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Sat, 15 Sep 2018 23:16:25 +1000
Subject: Add simple relative mode for mouse
diff --git a/src/main/haiku/SDL_BApp.h b/src/main/haiku/SDL_BApp.h
index ba3f927..7d4f442 100644
--- a/src/main/haiku/SDL_BApp.h
+++ b/src/main/haiku/SDL_BApp.h
@@ -230,6 +230,21 @@ private:
win = GetSDLWindow(winID);
SDL_SendMouseMotion(win, 0, 0, x, y);
+ // Simple relative mode support for mouse.
+ if ((SDL_GetMouse()->relative_mode ||
+ (win->flags & SDL_WINDOW_INPUT_GRABBED)) &&
+ (win->flags & SDL_WINDOW_INPUT_FOCUS)) {
+ int winWidth, winHeight, winPosX, winPosY;
+ SDL_GetWindowSize(win, &winWidth, &winHeight);
+ SDL_GetWindowPosition(win, &winPosX, &winPosY);
+ set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
+ if (!be_app->IsCursorHidden())
+ be_app->HideCursor();
+ } else {
+ if (be_app->IsCursorHidden())
+ be_app->ShowCursor();
+ }
+
/* Tell the application that the mouse passed over, redraw needed */
BE_UpdateWindowFramebuffer(NULL,win,NULL,-1);
}
--
2.19.0
From 4b7d43c12e26c76cb8befa95b7a3b70799332717 Mon Sep 17 00:00:00 2001
From: Gerasim Troeglazov <3dEyes@gmail.com>
Date: Tue, 18 Sep 2018 20:47:07 +1000
Subject: Add support for relative mouse mode
diff --git a/src/main/haiku/SDL_BApp.h b/src/main/haiku/SDL_BApp.h
index 7d4f442..ec0c458 100644
--- a/src/main/haiku/SDL_BApp.h
+++ b/src/main/haiku/SDL_BApp.h
@@ -228,7 +228,6 @@ private:
return;
}
win = GetSDLWindow(winID);
- SDL_SendMouseMotion(win, 0, 0, x, y);
// Simple relative mode support for mouse.
if ((SDL_GetMouse()->relative_mode ||
@@ -237,10 +236,14 @@ private:
int winWidth, winHeight, winPosX, winPosY;
SDL_GetWindowSize(win, &winWidth, &winHeight);
SDL_GetWindowPosition(win, &winPosX, &winPosY);
+ int dx = x - (winWidth / 2);
+ int dy = y - (winHeight / 2);
+ SDL_SendMouseMotion(win, 0, SDL_GetMouse()->relative_mode, dx, dy);
set_mouse_position((winPosX + winWidth / 2), (winPosY + winHeight / 2));
if (!be_app->IsCursorHidden())
be_app->HideCursor();
} else {
+ SDL_SendMouseMotion(win, 0, 0, x, y);
if (be_app->IsCursorHidden())
be_app->ShowCursor();
}
diff --git a/src/video/haiku/SDL_BWin.h b/src/video/haiku/SDL_BWin.h
index bd4aae7..370bdce 100644
--- a/src/video/haiku/SDL_BWin.h
+++ b/src/video/haiku/SDL_BWin.h
@@ -319,22 +319,17 @@ class SDL_BWin:public BDirectWindow
&& msg->FindInt32("be:transit", &transit) == B_OK) {
_MouseMotionEvent(where, transit);
}
+ break;
- /* FIXME: Apparently a button press/release event might be dropped
- if made before before a different button is released. Does
- B_MOUSE_MOVED have the data needed to check if a mouse button
- state has changed? */
+ case B_MOUSE_DOWN:
if (msg->FindInt32("buttons", &buttons) == B_OK) {
- _MouseButtonEvent(buttons);
+ _MouseButtonEvent(buttons, SDL_PRESSED);
}
break;
- case B_MOUSE_DOWN:
case B_MOUSE_UP:
- /* _MouseButtonEvent() detects any and all buttons that may have
- changed state, as well as that button's new state */
if (msg->FindInt32("buttons", &buttons) == B_OK) {
- _MouseButtonEvent(buttons);
+ _MouseButtonEvent(buttons, SDL_RELEASED);
}
break;
@@ -497,26 +492,17 @@ private:
if true: SDL_SetCursor(NULL); */
}
- void _MouseButtonEvent(int32 buttons) {
+ void _MouseButtonEvent(int32 buttons, Uint8 state) {
int32 buttonStateChange = buttons ^ _last_buttons;
- /* Make sure at least one button has changed state */
- if( !(buttonStateChange) ) {
- return;
- }
-
- /* Add any mouse button events */
if(buttonStateChange & B_PRIMARY_MOUSE_BUTTON) {
- _SendMouseButton(SDL_BUTTON_LEFT, buttons &
- B_PRIMARY_MOUSE_BUTTON);
+ _SendMouseButton(SDL_BUTTON_LEFT, state);
}
if(buttonStateChange & B_SECONDARY_MOUSE_BUTTON) {
- _SendMouseButton(SDL_BUTTON_RIGHT, buttons &
- B_PRIMARY_MOUSE_BUTTON);
+ _SendMouseButton(SDL_BUTTON_RIGHT, state);
}
if(buttonStateChange & B_TERTIARY_MOUSE_BUTTON) {
- _SendMouseButton(SDL_BUTTON_MIDDLE, buttons &
- B_PRIMARY_MOUSE_BUTTON);
+ _SendMouseButton(SDL_BUTTON_MIDDLE, state);
}
_last_buttons = buttons;
--
2.19.0