From 3b1d285cf3898dfaee3336836e81403f379fde75 Mon Sep 17 00:00:00 2001 From: Jordan Milne Date: Tue, 8 Jan 2013 21:01:58 -0400 Subject: [PATCH] fix compile errors, work with unmodified SDL --- apps/openmw/mwinput/sdlinputwrapper.cpp | 50 ++++++++++++++++++++++++- extern/oics/OISCompat.h | 22 +++++++---- 2 files changed, 62 insertions(+), 10 deletions(-) diff --git a/apps/openmw/mwinput/sdlinputwrapper.cpp b/apps/openmw/mwinput/sdlinputwrapper.cpp index 60c7e8f7a..61fc3fc8b 100644 --- a/apps/openmw/mwinput/sdlinputwrapper.cpp +++ b/apps/openmw/mwinput/sdlinputwrapper.cpp @@ -1,5 +1,15 @@ #include "sdlinputwrapper.hpp" #include +#include + +#include + +#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX +# include +# include +# include +#endif + namespace MWInput { @@ -62,9 +72,45 @@ namespace MWInput size_t windowHnd; mWindow->getCustomAttribute("WINDOW", &windowHnd); - //just use that one for input - SDL_Init(flags); + //kindly ask SDL not to trash our OGL context + SDL_SetHint(SDL_HINT_RENDER_DRIVER, "software"); + SDL_Init(SDL_INIT_VIDEO); + + //wrap our own event handler around ogre's mSDLWindow = SDL_CreateWindowFrom((void*)windowHnd); + +#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX + //linux-specific event-handling fixups + SDL_SysWMinfo wm_info; + SDL_VERSION(&wm_info.version); + + if(SDL_GetWindowWMInfo(mSDLWindow,&wm_info)) + { + printf("SDL version %d.%d.%d\n", wm_info.version.major, wm_info.version.minor, wm_info.version.patch); + + Display* display = wm_info.info.x11.display; + Window w = wm_info.info.x11.window; + + // Set the input hints so we get keyboard input + XWMHints *wmhints = XAllocWMHints(); + if (wmhints) { + wmhints->input = True; + wmhints->flags = InputHint; + XSetWMHints(display, w, wmhints); + XFree(wmhints); + } + + //make sure to subscribe to XLib's events + XSelectInput(display, w, + (FocusChangeMask | EnterWindowMask | LeaveWindowMask | + ExposureMask | ButtonPressMask | ButtonReleaseMask | + PointerMotionMask | KeyPressMask | KeyReleaseMask | + PropertyChangeMask | StructureNotifyMask | + KeymapStateMask)); + + XFlush(display); + } +#endif } } } diff --git a/extern/oics/OISCompat.h b/extern/oics/OISCompat.h index 18bdd6bae..74b6acde1 100644 --- a/extern/oics/OISCompat.h +++ b/extern/oics/OISCompat.h @@ -20,17 +20,12 @@ struct MWSDLMouseMotionEvent : SDL_MouseMotionEvent { MWSDLMouseMotionEvent() { - x = 0; - y = 0; - xrel = 0; - yrel = 0; - state = 0; - zrel = 0; + _init(); } - MWSDLMouseMotionEvent( const SDL_MouseMotionEvent& evt) : - MWSDLMouseMotionEvent() + MWSDLMouseMotionEvent( const SDL_MouseMotionEvent& evt) { + _init(); x = evt.x; y = evt.y; xrel = evt.xrel; @@ -41,8 +36,19 @@ struct MWSDLMouseMotionEvent : SDL_MouseMotionEvent { MWSDLMouseMotionEvent (const SDL_MouseWheelEvent& evt) : MWSDLMouseMotionEvent() { + _init(); zrel = evt.y; } + + void _init() + { + x = 0; + y = 0; + xrel = 0; + yrel = 0; + state = 0; + zrel = 0; + } };