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
...@@ -77,7 +77,8 @@ public: ...@@ -77,7 +77,8 @@ 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";
return true; return true;
} }
bool mouseMoved( const MouseEvent &arg ) { bool mouseMoved( const MouseEvent &arg ) {
......
...@@ -100,9 +100,6 @@ namespace OIS ...@@ -100,9 +100,6 @@ namespace OIS
bool grabMouse, grabKeyboard; bool grabMouse, grabKeyboard;
bool mGrabs; bool mGrabs;
bool hideMouse; bool hideMouse;
//! By default, keyboard disables XRepeatRate
bool useXRepeat;
}; };
} }
#endif #endif
...@@ -33,7 +33,7 @@ namespace OIS ...@@ -33,7 +33,7 @@ namespace OIS
class LinuxKeyboard : public Keyboard class LinuxKeyboard : public Keyboard
{ {
public: public:
LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bool useXRepeat ); LinuxKeyboard(InputManager* creator, bool buffered, bool grab);
virtual ~LinuxKeyboard(); virtual ~LinuxKeyboard();
/** @copydoc Keyboard::isKeyDown */ /** @copydoc Keyboard::isKeyDown */
...@@ -57,7 +57,24 @@ namespace OIS ...@@ -57,7 +57,24 @@ namespace OIS
/** @copydoc Object::_initialize */ /** @copydoc Object::_initialize */
virtual void _initialize(); virtual void _initialize();
protected: 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 _injectKeyDown( KeySym key, int text );
bool _injectKeyUp( KeySym key ); bool _injectKeyUp( KeySym key );
...@@ -74,9 +91,6 @@ namespace OIS ...@@ -74,9 +91,6 @@ namespace OIS
bool grabKeyboard; bool grabKeyboard;
bool keyFocusLost; bool keyFocusLost;
bool xAutoRepeat;
bool oldXAutoRepeat;
std::string mGetString; std::string mGetString;
}; };
} }
......
...@@ -39,7 +39,6 @@ LinuxInputManager::LinuxInputManager() : InputManager("X11InputManager") ...@@ -39,7 +39,6 @@ LinuxInputManager::LinuxInputManager() : InputManager("X11InputManager")
grabKeyboard = true; grabKeyboard = true;
hideMouse = true; hideMouse = true;
mGrabs = true; mGrabs = true;
useXRepeat = false;
keyboardUsed = mouseUsed = false; keyboardUsed = mouseUsed = false;
//Setup our internal factories //Setup our internal factories
...@@ -73,11 +72,6 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList ) ...@@ -73,11 +72,6 @@ void LinuxInputManager::_parseConfigSettings( ParamList &paramList )
window = strtoul(i->second.c_str(), 0, 10); window = strtoul(i->second.c_str(), 0, 10);
//--------- Keyboard Settings ------------// //--------- Keyboard Settings ------------//
i = paramList.find("XAutoRepeatOn");
if( i != paramList.end() )
if( i->second == "true" )
useXRepeat = true;
i = paramList.find("x11_keyboard_grab"); i = paramList.find("x11_keyboard_grab");
if( i != paramList.end() ) if( i != paramList.end() )
if( i->second == "false" ) if( i->second == "false" )
...@@ -171,7 +165,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool ...@@ -171,7 +165,7 @@ Object* LinuxInputManager::createObject(InputManager *creator, Type iType, bool
case OISKeyboard: case OISKeyboard:
{ {
if( keyboardUsed == false ) if( keyboardUsed == false )
obj = new LinuxKeyboard(this, bufferMode, grabKeyboard, useXRepeat); obj = new LinuxKeyboard(this, bufferMode, grabKeyboard);
break; break;
} }
case OISMouse: case OISMouse:
......
...@@ -32,7 +32,7 @@ restrictions: ...@@ -32,7 +32,7 @@ restrictions:
using namespace OIS; using namespace OIS;
#include <iostream> #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) : Keyboard(creator->inputSystemName(), buffered, 0, creator)
{ {
setlocale(LC_CTYPE, ""); //Set the locale to (hopefully) the users LANG UTF-8 Env var 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 ...@@ -43,9 +43,6 @@ LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab, bo
grabKeyboard = grab; grabKeyboard = grab;
keyFocusLost = false; keyFocusLost = false;
xAutoRepeat = useXRepeat;
oldXAutoRepeat = false;
//X Key Map to KeyCode //X Key Map to KeyCode
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_1, KC_1));
keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2)); keyConversion.insert(XtoOIS_KeyMap::value_type(XK_2, KC_2));
...@@ -212,20 +209,6 @@ void LinuxKeyboard::_initialize() ...@@ -212,20 +209,6 @@ void LinuxKeyboard::_initialize()
XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime); XGrabKeyboard(display,window,True,GrabModeAsync,GrabModeAsync,CurrentTime);
keyFocusLost = false; 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() ...@@ -233,9 +216,6 @@ LinuxKeyboard::~LinuxKeyboard()
{ {
if( display ) if( display )
{ {
if( oldXAutoRepeat )
XAutoRepeatOn(display);
if( grabKeyboard ) if( grabKeyboard )
XUngrabKeyboard(display, CurrentTime); XUngrabKeyboard(display, CurrentTime);
...@@ -302,14 +282,13 @@ void LinuxKeyboard::capture() ...@@ -302,14 +282,13 @@ void LinuxKeyboard::capture()
LinuxInputManager* linMan = static_cast<LinuxInputManager*>(mCreator); LinuxInputManager* linMan = static_cast<LinuxInputManager*>(mCreator);
while( XPending(display) > 0 ) while( XPending(display) > 0 )
{ {
XNextEvent(display, &event); XNextEvent(display, &event);
if(KeyPress == event.type)
if( KeyPress == event.type )
{ {
unsigned int character = 0; unsigned int character = 0;
if( mTextMode != Off ) if(mTextMode != Off)
{ {
unsigned char buffer[6] = {0,0,0,0,0,0}; unsigned char buffer[6] = {0,0,0,0,0,0};
XLookupString(&event.xkey, (char*)buffer, 6, &key, 0); XLookupString(&event.xkey, (char*)buffer, 6, &key, 0);
...@@ -334,16 +313,17 @@ void LinuxKeyboard::capture() ...@@ -334,16 +313,17 @@ void LinuxKeyboard::capture()
//Check for Alt-Tab //Check for Alt-Tab
if( event.xkey.state & Mod1Mask && key == XK_Tab ) if( event.xkey.state & Mod1Mask && key == XK_Tab )
linMan->_setGrabState(false); linMan->_setGrabState(false);
} }
else if( KeyRelease == event.type ) else if(KeyRelease == event.type)
{ {
//Mask out the modifier states X sets.. or we will get improper values if(!_isKeyRepeat(event))
event.xkey.state &= ~ShiftMask; {
event.xkey.state &= ~LockMask; //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);
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