Commit dc461f60 authored by Phillip Castaneda's avatar Phillip Castaneda
Browse files

Remove x11 auto repeat setting change. Try to detect repeated keys with other method

parent 63f8f424
......@@ -78,6 +78,7 @@ public:
bool keyReleased( const KeyEvent &arg ) {
if( arg.key == KC_ESCAPE || arg.key == KC_Q )
appRunning = false;
std::cout << "KeyReleased {" << ((Keyboard*)(arg.device))->getAsString(arg.key) << "}\n";
return true;
}
bool mouseMoved( const MouseEvent &arg ) {
......
......@@ -100,9 +100,6 @@ namespace OIS
bool grabMouse, grabKeyboard;
bool mGrabs;
bool hideMouse;
//! By default, keyboard disables XRepeatRate
bool useXRepeat;
};
}
#endif
......@@ -33,7 +33,7 @@ namespace OIS
class LinuxKeyboard : public Keyboard
{
public:
LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat );
LinuxKeyboard(InputManager* creator, bool buffered, bool grab);
virtual ~LinuxKeyboard();
/** @copydoc Keyboard::isKeyDown */
......@@ -58,6 +58,23 @@ namespace OIS
virtual void _initialize();
protected:
inline bool _isKeyRepeat(XEvent &event)
{
//When a key is repeated, there will be two events: released, followed by another immediate pressed. So check to see if another pressed is present
if(!XPending(display))
return false;
XEvent e;
XPeekEvent(display, &e);
if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2)
{
XNextEvent(display, &e);
return true;
}
return false;
}
bool _injectKeyDown( KeySym key, int text );
bool _injectKeyUp( KeySym key );
......@@ -74,9 +91,6 @@ namespace OIS
bool grabKeyboard;
bool keyFocusLost;
bool xAutoRepeat;
bool oldXAutoRepeat;
std::string mGetString;
};
}
......
......@@ -39,7 +39,6 @@ LinuxInputManager::LinuxInputManager() : InputManager("X11InputManager")
grabKeyboard = true;
hideMouse = true;
mGrabs = true;
useXRepeat = false;
keyboardUsed = mouseUsed = false;
//Setup our internal factories
......@@ -73,11 +72,6 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList )
window = strtoul(i->second.c_str(), 0, 10);
//--------- Keyboard Settings ------------//
i = paramList.find("XAutoRepeatOn");
if( i != paramList.end() )
if( i->second == "true" )
useXRepeat = true;
i = paramList.find("x11_keyboard_grab");
if( i != paramList.end() )
if( i->second == "false" )
......@@ -171,7 +165,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
case OISKeyboard:
{
if( keyboardUsed == false )
obj = new LinuxKeyboard(this, bufferMode, grabKeyboard, useXRepeat);
obj = new LinuxKeyboard(this, bufferMode, grabKeyboard);
break;
}
case OISMouse:
......
......@@ -32,7 +32,7 @@ restrictions:
using namespace OIS;
#include <iostream>
//-------------------------------------------------------------------//
LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat)
LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab)
: Keyboard(creator->inputSystemName(), buffered, 0, creator)
{
setlocale(LC_CTYPE, ""); //Set the locale to (hopefully) the users LANG UTF-8 Env var
......@@ -43,9 +43,6 @@ LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bo
grabKeyboard = grab;
keyFocusLost = false;
xAutoRepeat = useXRepeat;
oldXAutoRepeat = false;
//X Key Map to KeyCode
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2));
......@@ -212,20 +209,6 @@ void LinuxKeyboard::_initialize()
XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime);
keyFocusLost = false;
if( xAutoRepeat == false )
{
//We do not want to blindly turn on autorepeat later when quiting if
//it was not on to begin with.. So, let us check and see first
XKeyboardState old;
XGetKeyboardControl( display, &old );
oldXAutoRepeat = false;
if( old.global_auto_repeat == AutoRepeatModeOn )
oldXAutoRepeat = true;
XAutoRepeatOff( display );
}
}
//-------------------------------------------------------------------//
......@@ -233,9 +216,6 @@ LinuxKeyboard::~LinuxKeyboard()
{
if( display )
{
if( oldXAutoRepeat )
XAutoRepeatOn(display);
if( grabKeyboard )
XUngrabKeyboard(display, CurrentTime);
......@@ -304,12 +284,11 @@ void LinuxKeyboard::capture()
while( XPending(display) > 0 )
{
XNextEvent(display, &event);
if( KeyPress == event.type )
if(KeyPress == event.type)
{
unsigned int character = 0;
if( mTextMode != Off )
if(mTextMode != Off)
{
unsigned char buffer[6] = {0,0,0,0,0,0};
XLookupString(&event.xkey, (char*)buffer, 6, &key, 0);
......@@ -335,15 +314,16 @@ void LinuxKeyboard::capture()
if( event.xkey.state & Mod1Mask && key == XK_Tab )
linMan->_setGrabState(false);
}
else if( KeyRelease == event.type )
else if(KeyRelease == event.type)
{
if(!_isKeyRepeat(event))
{
//Mask out the modifier states X sets.. or we will get improper values
event.xkey.state &= ~ShiftMask;
event.xkey.state &= ~LockMask;
//Else, it is a valid key release
XLookupString(&event.xkey,NULL,0,&key,NULL);
_injectKeyUp(key);
_injectKeyUp(key); }
}
}
......
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