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 @@
////////////////////////////////////Needed Windows Headers////////////
#if defined OIS_WIN32_PLATFORM
# define WIN32_LEAN_AND_MEAN
# include "windows.h"
# ifdef min
# undef min
# endif
# include "resource.h"
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
#define WIN32_LEAN_AND_MEAN
#include "windows.h"
#ifdef min
#undef min
#endif
#include "resource.h"
LRESULT DlgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
//////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Linux Headers//////////////
#elif defined OIS_LINUX_PLATFORM
# include <X11/Xlib.h>
void checkX11Events();
#include <X11/Xlib.h>
#include <X11/Xatom.h>
void checkX11Events();
//////////////////////////////////////////////////////////////////////
////////////////////////////////////Needed Mac Headers//////////////
#elif defined OIS_APPLE_PLATFORM
# include <Carbon/Carbon.h>
void checkMacEvents();
#include <Carbon/Carbon.h>
void checkMacEvents();
#endif
//////////////////////////////////////////////////////////////////////
using namespace OIS;
......@@ -77,7 +78,7 @@ public:
}
bool keyReleased( const KeyEvent &arg ) {
if( arg.key == KC_ESCAPE || arg.key == KC_Q )
appRunning = false;
appRunning = false;
std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n";
return true;
}
......@@ -221,6 +222,7 @@ int main()
}
//Destroying the manager will cleanup unfreed devices
std::cout << "Cleaning up...\n";
if( g_InputManager )
InputManager::destroyInputSystem(g_InputManager);
......@@ -230,7 +232,7 @@ int main()
XCloseDisplay(xDisp);
#endif
std::cout << "\n\nGoodbye\n\n";
std::cout << "\nGoodbye!\n";
return 0;
}
......@@ -259,11 +261,15 @@ void doStartup()
if( !(xDisp = XOpenDisplay(0)) )
OIS_EXCEPT(E_General, "Error opening X!");
//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
XMapWindow(xDisp, xWin);
// XInternAtom
//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;
do
{
......@@ -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
void checkX11Events()
{
if(!appRunning)
return;
XEvent event;
//Poll x11 for events (keyboard and mouse events are caught here)
while( XPending(xDisp) > 0 )
while(XPending(xDisp) > 0)
{
XNextEvent(xDisp, &event);
//Handle Resize events
if( event.type == ConfigureNotify )
if(event.type == ConfigureNotify)
{
if( g_m )
if(g_m)
{
const MouseState &ms = g_m->getMouseState();
ms.width = event.xconfigure.width;
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";
appRunning = false;
return;
}
else
{
std::cout << "\nUnknown X Event: " << event.type << std::endl;
}
}
}
#endif
......
......@@ -26,6 +26,7 @@ restrictions:
#include "linux/LinuxMouse.h"
#include "OISException.h"
#include <cstdlib>
#include <stdio.h>
using namespace OIS;
......@@ -66,10 +67,12 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList )
{
ParamList::iterator i = paramList.find("WINDOW");
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 = strtoul(i->second.c_str(), 0, 10);
window = strtoull(i->second.c_str(), 0, 10);
//--------- Keyboard Settings ------------//
i = paramList.find("x11_keyboard_grab");
......@@ -102,11 +105,14 @@ DeviceList LinuxInputManager::freeDeviceList()
{
DeviceList ret;
if( keyboardUsed == false )
ret.insert(std::make_pair(OISKeyboard, mInputSystemName));
if(window)
{
if(keyboardUsed == false)
ret.insert(std::make_pair(OISKeyboard, mInputSystemName));
if( mouseUsed == false )
ret.insert(std::make_pair(OISMouse, mInputSystemName));
if(mouseUsed == false)
ret.insert(std::make_pair(OISMouse, mInputSystemName));
}
for(JoyStickInfoList::iterator i = unusedJoyStickList.begin(); i != unusedJoyStickList.end(); ++i)
ret.insert(std::make_pair(OISJoyStick, i->vendor));
......@@ -119,8 +125,8 @@ int LinuxInputManager::totalDevices(Type iType)
{
switch(iType)
{
case OISKeyboard: return 1;
case OISMouse: return 1;
case OISKeyboard: return window ? 1 : 0;
case OISMouse: return window ? 1 : 0;
case OISJoyStick: return joySticks;
default: return 0;
}
......@@ -131,8 +137,8 @@ int LinuxInputManager::freeDevices(Type iType)
{
switch(iType)
{
case OISKeyboard: return keyboardUsed ? 0 : 1;
case OISMouse: return mouseUsed ? 0 : 1;
case OISKeyboard: return window ? (keyboardUsed ? 0 : 1) : 0;
case OISMouse: return window ? (mouseUsed ? 0 : 1) : 0;
case OISJoyStick: return (int)unusedJoyStickList.size();
default: return 0;
}
......@@ -141,9 +147,9 @@ int LinuxInputManager::freeDevices(Type iType)
//----------------------------------------------------------------------------//
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 )
{
......@@ -164,14 +170,16 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
{
case OISKeyboard:
{
if( keyboardUsed == false )
if(window && keyboardUsed == false)
obj = new LinuxKeyboard(this, bufferMode, grabKeyboard);
break;
}
case OISMouse:
{
if( mouseUsed == false )
if(window && mouseUsed == false)
obj = new LinuxMouse(this, bufferMode, grabMouse, hideMouse);
break;
}
case OISJoyStick:
......@@ -191,7 +199,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
break;
}
if( obj == 0 )
if(obj == 0)
OIS_EXCEPT(E_InputDeviceNonExistant, "No devices match requested type.");
return obj;
......@@ -200,9 +208,9 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
//----------------------------------------------------------------------------//
void LinuxInputManager::destroyObject( Object* obj )
{
if( obj )
if(obj)
{
if( obj->type() == OISJoyStick )
if(obj->type() == OISJoyStick)
{
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