Commit 34431daf authored by Phillip Castaneda's avatar Phillip Castaneda
Browse files

Added close handler to x11 console demo. Added ability to configure OIS on x11...

Added close handler to x11 console demo. Added ability to configure OIS on x11 without a window... For instance, if one wanted to use another toolkits mouse/keyboard, while using OIS for joysticks
parent b56dc731
...@@ -15,23 +15,24 @@ ...@@ -15,23 +15,24 @@
////////////////////////////////////Needed Windows Headers//////////// ////////////////////////////////////Needed Windows Headers////////////
#if defined OIS_WIN32_PLATFORM #if defined OIS_WIN32_PLATFORM
# define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
# include "windows.h" #include "windows.h"
# ifdef min #ifdef min
# undef min #undef min
# endif #endif
# include "resource.h" #include "resource.h"
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ); LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Linux Headers////////////// ////////////////////////////////////Needed Linux Headers//////////////
#elif defined OIS_LINUX_PLATFORM #elif defined OIS_LINUX_PLATFORM
# include <X11/Xlib.h> #include <X11/Xlib.h>
void checkX11Events(); #include <X11/Xatom.h>
void checkX11Events();
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Mac Headers////////////// ////////////////////////////////////Needed Mac Headers//////////////
#elif defined OIS_APPLE_PLATFORM #elif defined OIS_APPLE_PLATFORM
# include <Carbon/Carbon.h> #include <Carbon/Carbon.h>
void checkMacEvents(); void checkMacEvents();
#endif #endif
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
using namespace OIS; using namespace OIS;
...@@ -77,7 +78,7 @@ public: ...@@ -77,7 +78,7 @@ public:
} }
bool keyReleased( const KeyEvent &arg ) { bool keyReleased( const KeyEvent &arg ) {
if( arg.key == KC_ESCAPE || arg.key == KC_Q ) if( arg.key == KC_ESCAPE || arg.key == KC_Q )
appRunning = false; appRunning = false;
std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n"; std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n";
return true; return true;
} }
...@@ -221,6 +222,7 @@ int main() ...@@ -221,6 +222,7 @@ int main()
} }
//Destroying the manager will cleanup unfreed devices //Destroying the manager will cleanup unfreed devices
std::cout << "Cleaning up...\n";
if( g_InputManager ) if( g_InputManager )
InputManager::destroyInputSystem(g_InputManager); InputManager::destroyInputSystem(g_InputManager);
...@@ -230,7 +232,7 @@ int main() ...@@ -230,7 +232,7 @@ int main()
XCloseDisplay(xDisp); XCloseDisplay(xDisp);
#endif #endif
std::cout << "\n\nGoodbye\n\n"; std::cout << "\nGoodbye!\n";
return 0; return 0;
} }
...@@ -259,11 +261,15 @@ void doStartup() ...@@ -259,11 +261,15 @@ void doStartup()
if( !(xDisp = XOpenDisplay(0)) ) if( !(xDisp = XOpenDisplay(0)) )
OIS_EXCEPT(E_General, "Error opening X!"); OIS_EXCEPT(E_General, "Error opening X!");
//Create a window //Create a window
xWin = XCreateSimpleWindow(xDisp,DefaultRootWindow(xDisp), 0,0, 100,100, 0, 0, 0); xWin = XCreateSimpleWindow(xDisp, DefaultRootWindow(xDisp), 0, 0, 100, 100, 0, 0, 0);
//bind our connection to that window //bind our connection to that window
XMapWindow(xDisp, xWin); XMapWindow(xDisp, xWin);
// XInternAtom
//Select what events we want to listen to locally //Select what events we want to listen to locally
XSelectInput(xDisp, xWin, StructureNotifyMask); XSelectInput(xDisp, xWin, StructureNotifyMask | SubstructureNotifyMask);
Atom wmProto = XInternAtom(xDisp, "WM_PROTOCOLS", False);
Atom wmDelete = XInternAtom(xDisp, "WM_DELETE_WINDOW", False);
XChangeProperty(xDisp, xWin, wmProto, XA_ATOM, 32, 0, (const unsigned char*)&wmDelete, 1);
XEvent evtent; XEvent evtent;
do do
{ {
...@@ -414,29 +420,34 @@ LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam ) ...@@ -414,29 +420,34 @@ LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
//This is just here to show that you still recieve x11 events, as the lib only needs mouse/key events //This is just here to show that you still recieve x11 events, as the lib only needs mouse/key events
void checkX11Events() void checkX11Events()
{ {
if(!appRunning)
return;
XEvent event; XEvent event;
//Poll x11 for events (keyboard and mouse events are caught here) while(XPending(xDisp) > 0)
while( XPending(xDisp) > 0 )
{ {
XNextEvent(xDisp, &event); XNextEvent(xDisp, &event);
//Handle Resize events //Handle Resize events
if( event.type == ConfigureNotify ) if(event.type == ConfigureNotify)
{ {
if( g_m ) if(g_m)
{ {
const MouseState &ms = g_m->getMouseState(); const MouseState &ms = g_m->getMouseState();
ms.width = event.xconfigure.width; ms.width = event.xconfigure.width;
ms.height = event.xconfigure.height; ms.height = event.xconfigure.height;
} }
} }
else if( event.type == DestroyNotify ) else if(event.type == ClientMessage || event.type == DestroyNotify)
{ { // We only get DestroyNotify for child windows. However, we regeistered earlier to receive WM_DELETE_MESSAGEs
std::cout << "Exiting...\n"; std::cout << "Exiting...\n";
appRunning = false; appRunning = false;
return;
} }
else else
{
std::cout << "\nUnknown X Event: " << event.type << std::endl; std::cout << "\nUnknown X Event: " << event.type << std::endl;
}
} }
} }
#endif #endif
......
...@@ -26,6 +26,7 @@ restrictions: ...@@ -26,6 +26,7 @@ restrictions:
#include "linux/LinuxMouse.h" #include "linux/LinuxMouse.h"
#include "OISException.h" #include "OISException.h"
#include <cstdlib> #include <cstdlib>
#include <stdio.h>
using namespace OIS; using namespace OIS;
...@@ -66,10 +67,12 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList ) ...@@ -66,10 +67,12 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList )
{ {
ParamList::iterator i = paramList.find("WINDOW"); ParamList::iterator i = paramList.find("WINDOW");
if( i == paramList.end() ) if( i == paramList.end() )
OIS_EXCEPT( E_InvalidParam, "LinuxInputManager >> No WINDOW!" ); {
printf("OIS: No Window specified... Not using x11 keyboard/mouse\n");
return;
}
//TODO 64 bit proof this little conversion xxx wip window = strtoull(i->second.c_str(), 0, 10);
window = strtoul(i->second.c_str(), 0, 10);
//--------- Keyboard Settings ------------// //--------- Keyboard Settings ------------//
i = paramList.find("x11_keyboard_grab"); i = paramList.find("x11_keyboard_grab");
...@@ -102,11 +105,14 @@ DeviceList LinuxInputManager::freeDeviceList() ...@@ -102,11 +105,14 @@ DeviceList LinuxInputManager::freeDeviceList()
{ {
DeviceList ret; DeviceList ret;
if( keyboardUsed == false ) if(window)
ret.insert(std::make_pair(OISKeyboard, mInputSystemName)); {
if(keyboardUsed == false)
ret.insert(std::make_pair(OISKeyboard, mInputSystemName));
if( mouseUsed == false ) if(mouseUsed == false)
ret.insert(std::make_pair(OISMouse, mInputSystemName)); ret.insert(std::make_pair(OISMouse, mInputSystemName));
}
for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i) for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i)
ret.insert(std::make_pair(OISJoyStick, i->vendor)); ret.insert(std::make_pair(OISJoyStick, i->vendor));
...@@ -119,8 +125,8 @@ int LinuxInputManager::totalDevices(Type iType) ...@@ -119,8 +125,8 @@ int LinuxInputManager::totalDevices(Type iType)
{ {
switch(iType) switch(iType)
{ {
case OISKeyboard: return 1; case OISKeyboard: return window ? 1 : 0;
case OISMouse: return 1; case OISMouse: return window ? 1 : 0;
case OISJoyStick: return joySticks; case OISJoyStick: return joySticks;
default: return 0; default: return 0;
} }
...@@ -131,8 +137,8 @@ int LinuxInputManager::freeDevices(Type iType) ...@@ -131,8 +137,8 @@ int LinuxInputManager::freeDevices(Type iType)
{ {
switch(iType) switch(iType)
{ {
case OISKeyboard: return keyboardUsed ? 0 : 1; case OISKeyboard: return window ? (keyboardUsed ? 0 : 1) : 0;
case OISMouse: return mouseUsed ? 0 : 1; case OISMouse: return window ? (mouseUsed ? 0 : 1) : 0;
case OISJoyStick: return (int)unusedJoyStickList.size(); case OISJoyStick: return (int)unusedJoyStickList.size();
default: return 0; default: return 0;
} }
...@@ -141,9 +147,9 @@ int LinuxInputManager::freeDevices(Type iType) ...@@ -141,9 +147,9 @@ int LinuxInputManager::freeDevices(Type iType)
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
bool LinuxInputManager::vendorExist(Type iType, const std::string & vendor) bool LinuxInputManager::vendorExist(Type iType, const std::string & vendor)
{ {
if( (iType == OISKeyboard || iType == OISMouse) && vendor == mInputSystemName ) if((iType == OISKeyboard || iType == OISMouse) && vendor == mInputSystemName)
{ {
return true; return window ? true : false;
} }
else if( iType == OISJoyStick ) else if( iType == OISJoyStick )
{ {
...@@ -164,14 +170,16 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool ...@@ -164,14 +170,16 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
{ {
case OISKeyboard: case OISKeyboard:
{ {
if( keyboardUsed == false ) if(window && keyboardUsed == false)
obj = new LinuxKeyboard(this, bufferMode, grabKeyboard); obj = new LinuxKeyboard(this, bufferMode, grabKeyboard);
break; break;
} }
case OISMouse: case OISMouse:
{ {
if( mouseUsed == false ) if(window && mouseUsed == false)
obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse); obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse);
break; break;
} }
case OISJoyStick: case OISJoyStick:
...@@ -191,7 +199,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool ...@@ -191,7 +199,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
break; break;
} }
if( obj == 0 ) if(obj == 0)
OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type."); OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type.");
return obj; return obj;
...@@ -200,9 +208,9 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool ...@@ -200,9 +208,9 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
//----------------------------------------------------------------------------// //----------------------------------------------------------------------------//
void LinuxInputManager::destroyObject( Object* obj ) void LinuxInputManager::destroyObject( Object* obj )
{ {
if( obj ) if(obj)
{ {
if( obj->type() == OISJoyStick ) if(obj->type() == OISJoyStick)
{ {
unusedJoyStickList.push_back( ((LinuxJoyStick*)obj)->_getJoyInfo() ); unusedJoyStickList.push_back( ((LinuxJoyStick*)obj)->_getJoyInfo() );
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment