Skip to content
Permalink
Browse files

Fix mouse grab under Windows 10

  • Loading branch information...
barotto committed Mar 18, 2018
1 parent 97ce0d4 commit 6f09e0bf6a28dd6b144ce6a2984279cb3043272f
Showing with 5 additions and 24 deletions.
  1. +2 −1 configure.ac
  2. +2 −19 src/gui/gui.cpp
  3. +1 −4 src/gui/gui.h
@@ -62,10 +62,12 @@ fi
if test x$have_windows = xno ; then
separator="/"
static="no"
SDL_VERSION=2.0.0
else
separator="\\\\"
#-mno-ms-bitfields is required for the __attribute__(packed) to work
CXX_DEFAULTS="$CXX_DEFAULTS -mno-ms-bitfields"
SDL_VERSION=2.0.8
fi

if test x$static = xyes ; then
@@ -82,7 +84,6 @@ AC_DEFINE_UNQUOTED([FS_SEP],["$separator"],[File system separator])
#######################################################################
# Checks for libraries and headers #
#######################################################################
SDL_VERSION=2.0.0
AM_PATH_SDL2($SDL_VERSION, :, AC_MSG_ERROR([*** SDL $SDL_VERSION not found!]))
AX_CHECK_SDLIMAGE
AX_CHECK_OPENGL
@@ -554,11 +554,9 @@ void GUI::input_grab(bool _value)
{
if(m_mouse.grab) {
if(_value) {
SDL_ShowCursor(0);
SDL_SetWindowGrab(m_SDL_window, SDL_TRUE);
SDL_SetRelativeMouseMode(SDL_TRUE);
} else {
SDL_ShowCursor(1);
SDL_SetWindowGrab(m_SDL_window, SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE);
}
}
m_input_grab = _value;
@@ -880,25 +878,10 @@ void GUI::dispatch_hw_event(const SDL_Event &_event)
switch(_event.type)
{
case SDL_MOUSEMOTION:
if(m_mouse.warped
&& _event.motion.x == m_width/2
&& _event.motion.y == m_height/2)
{
// This event was generated as a side effect of the WarpMouse,
// and it must be ignored.
m_mouse.warped = false;
break;
}

buttons = bool(_event.motion.state & SDL_BUTTON(SDL_BUTTON_LEFT));
buttons |= bool(_event.motion.state & SDL_BUTTON(SDL_BUTTON_RIGHT)) << 1;
buttons |= bool(_event.motion.state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) << 2;

m_machine->mouse_motion(_event.motion.xrel, -_event.motion.yrel, 0, buttons);

SDL_WarpMouseInWindow(m_SDL_window, m_width/2, m_height/2);
m_mouse.warped = true;

break;

case SDL_MOUSEBUTTONDOWN:
@@ -140,11 +140,8 @@ class GUI

struct Mouse {
bool grab;
bool warped;

Mouse() :
grab(true),
warped(false)
grab(true)
{}
} m_mouse;

0 comments on commit 6f09e0b

Please sign in to comment.
You can’t perform that action at this time.