fix compile errors, work with unmodified SDL

actorid
Jordan Milne 12 years ago
parent 6449f68d61
commit 3b1d285cf3

@ -1,5 +1,15 @@
#include "sdlinputwrapper.hpp" #include "sdlinputwrapper.hpp"
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#include <SDL2/SDL_syswm.h>
#include <OgrePlatform.h>
#if OGRE_PLATFORM == OGRE_PLATFORM_LINUX
# include <X11/Xlib.h>
# include <X11/Xutil.h>
# include <X11/Xos.h>
#endif
namespace MWInput namespace MWInput
{ {
@ -62,9 +72,45 @@ namespace MWInput
size_t windowHnd; size_t windowHnd;
mWindow->getCustomAttribute("WINDOW", &windowHnd); mWindow->getCustomAttribute("WINDOW", &windowHnd);
//just use that one for input //kindly ask SDL not to trash our OGL context
SDL_Init(flags); 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); 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
} }
} }
} }

@ -20,17 +20,12 @@ struct MWSDLMouseMotionEvent : SDL_MouseMotionEvent {
MWSDLMouseMotionEvent() MWSDLMouseMotionEvent()
{ {
x = 0; _init();
y = 0;
xrel = 0;
yrel = 0;
state = 0;
zrel = 0;
} }
MWSDLMouseMotionEvent( const SDL_MouseMotionEvent& evt) : MWSDLMouseMotionEvent( const SDL_MouseMotionEvent& evt)
MWSDLMouseMotionEvent()
{ {
_init();
x = evt.x; x = evt.x;
y = evt.y; y = evt.y;
xrel = evt.xrel; xrel = evt.xrel;
@ -41,8 +36,19 @@ struct MWSDLMouseMotionEvent : SDL_MouseMotionEvent {
MWSDLMouseMotionEvent (const SDL_MouseWheelEvent& evt) : MWSDLMouseMotionEvent (const SDL_MouseWheelEvent& evt) :
MWSDLMouseMotionEvent() MWSDLMouseMotionEvent()
{ {
_init();
zrel = evt.y; zrel = evt.y;
} }
void _init()
{
x = 0;
y = 0;
xrel = 0;
yrel = 0;
state = 0;
zrel = 0;
}
}; };

Loading…
Cancel
Save