Permalink
Browse files

Move GrabInput() and rename to GLimp_GrabInput()

SDL2 supports multiple windows, and the grabbing is set per
window, so move it to sys/glimp.cpp.
  • Loading branch information...
1 parent 6dcf079 commit b8765ccf22eb34f167ecf4c81723c7720ea45671 @dhewg dhewg committed Jul 19, 2012
Showing with 40 additions and 36 deletions.
  1. +6 −0 neo/renderer/tr_local.h
  2. +3 −36 neo/sys/events.cpp
  3. +31 −0 neo/sys/glimp.cpp
View
6 neo/renderer/tr_local.h
@@ -1097,6 +1097,12 @@ void GLimp_DeactivateContext( void );
// being immediate returns, which lets us guage how much time is
// being spent inside OpenGL.
+const int GRAB_ENABLE = (1 << 0);
+const int GRAB_REENABLE = (1 << 1);
+const int GRAB_HIDECURSOR = (1 << 2);
+const int GRAB_SETSTATE = (1 << 3);
+
+void GLimp_GrabInput(int flags);
/*
====================================================================
View
39 neo/sys/events.cpp
@@ -34,14 +34,14 @@ If you have questions concerning this license or the applicable additional terms
#include "framework/Common.h"
#include "framework/KeyInput.h"
#include "renderer/RenderSystem.h"
+#include "renderer/tr_local.h"
#include "sys/sys_public.h"
const char *kbdNames[] = {
"english", "french", "german", "italian", "spanish", "turkish", NULL
};
-idCVar in_nograb("in_nograb", "0", CVAR_SYSTEM | CVAR_NOCHEAT, "prevents input grabbing");
idCVar in_kbd("in_kbd", "english", CVAR_SYSTEM | CVAR_ARCHIVE | CVAR_NOCHEAT, "keyboard layout", kbdNames, idCmdSystem::ArgCompletion_String<kbdNames> );
struct kbd_poll_t {
@@ -72,7 +72,6 @@ struct mouse_poll_t {
static idList<kbd_poll_t> kbd_polls;
static idList<mouse_poll_t> mouse_polls;
-static bool grabbed = false;
static byte mapkey(SDLKey key) {
switch (key) {
@@ -256,38 +255,6 @@ static void PushConsoleEvent(const char *s) {
SDL_PushEvent(&event);
}
-const int GRAB_ENABLE = (1 << 0);
-const int GRAB_REENABLE = (1 << 1);
-const int GRAB_HIDECURSOR = (1 << 2);
-const int GRAB_SETSTATE = (1 << 3);
-
-static void GrabInput(int flags) {
-#if defined(ID_DEDICATED)
- return;
-#else
- bool grab = flags & GRAB_ENABLE;
-
- if (grab && (flags & GRAB_REENABLE))
- grab = false;
-
- if (flags & GRAB_SETSTATE)
- grabbed = grab;
-
- if (flags & GRAB_HIDECURSOR)
- SDL_ShowCursor(SDL_DISABLE);
- else
- SDL_ShowCursor(SDL_ENABLE);
-
- if (in_nograb.GetBool())
- grab = false;
-
- if (grab)
- SDL_WM_GrabInput(SDL_GRAB_ON);
- else
- SDL_WM_GrabInput(SDL_GRAB_OFF);
-#endif
-}
-
/*
=================
Sys_InitInput
@@ -382,7 +349,7 @@ void Sys_GrabMouseCursor(bool grabIt) {
else
flags = GRAB_SETSTATE;
- GrabInput(flags);
+ GLimp_GrabInput(flags);
}
/*
@@ -416,7 +383,7 @@ sysEvent_t Sys_GetEvent() {
if (ev.active.gain)
flags = GRAB_ENABLE | GRAB_REENABLE | GRAB_HIDECURSOR;
- GrabInput(flags);
+ GLimp_GrabInput(flags);
}
return res_none;
View
31 neo/sys/glimp.cpp
@@ -34,6 +34,10 @@ If you have questions concerning this license or the applicable additional terms
#include "renderer/tr_local.h"
+idCVar in_nograb("in_nograb", "0", CVAR_SYSTEM | CVAR_NOCHEAT, "prevents input grabbing");
+
+static bool grabbed = false;
+
/*
===================
GLimp_Init
@@ -227,3 +231,30 @@ GLExtension_t GLimp_ExtensionPointer(const char *name) {
return (GLExtension_t)SDL_GL_GetProcAddress(name);
}
+
+void GLimp_GrabInput(int flags) {
+#if defined(ID_DEDICATED)
+ return;
+#else
+ bool grab = flags & GRAB_ENABLE;
+
+ if (grab && (flags & GRAB_REENABLE))
+ grab = false;
+
+ if (flags & GRAB_SETSTATE)
+ grabbed = grab;
+
+ if (flags & GRAB_HIDECURSOR)
+ SDL_ShowCursor(SDL_DISABLE);
+ else
+ SDL_ShowCursor(SDL_ENABLE);
+
+ if (in_nograb.GetBool())
+ grab = false;
+
+ if (grab)
+ SDL_WM_GrabInput(SDL_GRAB_ON);
+ else
+ SDL_WM_GrabInput(SDL_GRAB_OFF);
+#endif
+}

5 comments on commit b8765cc

@andre-d

I seem to recall it not actually grabbing the mouse (Not resetting it to the centre) (as seen by the hack I did with centring it then checking for events to mouse centre) in SDL2 (Not yet implemented)..did you experience this? (Its possible it has since been fixed, it maybe it was just not fixed in their X11 code)

@dhewg
dhewm member

Well, grabbing always worked for me. I saw your SDL2 patches, but didn't look to closely since you broke SDL1.2 :P
But you might have missed SDL_SetRelativeMouseMode(), which fixed 2 things for me:

  • That mouse center issue
  • Real relative movement, without it axis movement is limited (try turning left/right 720°)
@andre-d

Yeah, the intention wasn’t for it to work alongside 1.2, just to be a port for me to play the game with NetWM fullscreen. I do recall setting that (and likely removed it if it didn't work just in case it suddenly started working), I get back to my normal computer on Monday. I will verify they work then.

@dhewg
dhewm member

NetWM fullscreen?
I just started playing with SDL2, but from the configure output it looked like its using xrandr for that.

@andre-d

NetWM fullscreen is a method of fullscreen whereby you tell the window manager to fullscreen it (using NetWM hints)...this works 100x better for multiple monitors as you dont need to know about the multi desktop environment (or the size of the desktop it is on/etc). It often acts similar to a maximized always on top window. SDL2 backs up to XRANDR if it needs to. This is a problem for me in SDL1 as with my multi-monitor environment I have no available full-screen resolution for just the one monitor. There is some funky thing with creating meta-modes the X11 config, but I prefer a NetWM fullscreen anyway. Basically in SDL1, I get one black monitor and the other one with the window. This also effects minecraft, and other games not considering multiple desktops. It really is a simple fix with the meta resolutions, but eh, kinda a hack to begin with as they are still not aware of what monitor they are on/etc and I need to manually set the resolution to match the current desktop...but then if I switch the window to the other desktop I need to change the resolution again before I fullscreen. But in windowed mode I may want a different res than the fullscreen one..etc

Please sign in to comment.