Changeset 8284 for code/branches/kicklib2/src/external/ois/linux
- Timestamp:
- Apr 21, 2011, 6:58:23 PM (14 years ago)
- Location:
- code/branches/kicklib2
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/kicklib2
- Property svn:mergeinfo changed
-
code/branches/kicklib2/src/external/ois/linux/LinuxInputManager.cpp
r5781 r8284 40 40 hideMouse = true; 41 41 mGrabs = true; 42 useXRepeat = false;43 42 keyboardUsed = mouseUsed = false; 44 43 … … 74 73 75 74 //--------- Keyboard Settings ------------// 76 i = paramList.find("XAutoRepeatOn");77 if( i != paramList.end() )78 if( i->second == "true" )79 useXRepeat = true;80 81 75 i = paramList.find("x11_keyboard_grab"); 82 76 if( i != paramList.end() ) … … 172 166 { 173 167 if( keyboardUsed == false ) 174 obj = new LinuxKeyboard(this, bufferMode, grabKeyboard , useXRepeat);168 obj = new LinuxKeyboard(this, bufferMode, grabKeyboard); 175 169 break; 176 170 } -
code/branches/kicklib2/src/external/ois/linux/LinuxInputManager.h
r5781 r8284 101 101 bool mGrabs; 102 102 bool hideMouse; 103 104 //! By default, keyboard disables XRepeatRate105 bool useXRepeat;106 103 }; 107 104 } -
code/branches/kicklib2/src/external/ois/linux/LinuxJoyStickEvents.cpp
r5781 r8284 96 96 //We are in non blocking mode - we just read once, and try to fill up buffer 97 97 input_event js[JOY_BUFFERSIZE]; 98 int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); 99 if( ret <= 0 ) 100 return; 101 102 //Determine how many whole events re read up 103 ret /= sizeof(struct input_event); 104 for(int i = 0; i < ret; ++i) 98 while(true) 105 99 { 106 switch(js[i].type) 100 int ret = read(mJoyStick, &js, sizeof(struct input_event) * JOY_BUFFERSIZE); 101 if( ret < 0 ) 102 break; 103 104 //Determine how many whole events re read up 105 ret /= sizeof(struct input_event); 106 for(int i = 0; i < ret; ++i) 107 107 { 108 case EV_KEY: //Button 109 { 110 int button = mButtonMap[js[i].code]; 111 112 #ifdef OIS_LINUX_JOY_DEBUG 113 cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl; 114 #endif 115 116 //Check to see whether push or released event... 117 if(js[i].value) 118 { 119 mState.mButtons[button] = true; 120 if( mBuffered && mListener ) 121 if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return; 122 } 123 else 124 { 125 mState.mButtons[button] = false; 126 if( mBuffered && mListener ) 127 if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return; 128 } 129 break; 130 } 131 132 case EV_ABS: //Absolute Axis 133 { 134 //A Stick (BrakeDefine is the highest possible Axis) 135 if( js[i].code <= ABS_BRAKE ) 136 { 137 int axis = mAxisMap[js[i].code]; 138 assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); 139 140 axisMoved[axis] = true; 141 142 //check for rescaling: 143 if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) 144 { //Scale is perfect 145 mState.mAxes[axis].abs = js[i].value; 108 switch(js[i].type) 109 { 110 case EV_KEY: //Button 111 { 112 int button = mButtonMap[js[i].code]; 113 114 #ifdef OIS_LINUX_JOY_DEBUG 115 cout << "\nButton Code: " << js[i].code << ", OIS Value: " << button << endl; 116 #endif 117 118 //Check to see whether push or released event... 119 if(js[i].value) 120 { 121 mState.mButtons[button] = true; 122 if( mBuffered && mListener ) 123 if(!mListener->buttonPressed(JoyStickEvent(this,mState), button)) return; 146 124 } 147 125 else 148 { //Rescale 149 float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); 150 mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); 126 { 127 mState.mButtons[button] = false; 128 if( mBuffered && mListener ) 129 if(!mListener->buttonReleased(JoyStickEvent(this,mState), button)) return; 151 130 } 152 } 153 else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed 154 { 155 //Normalise the POV to between 0-7 156 //Even is X Axis, Odd is Y Axis 157 unsigned char LinuxPovNumber = js[i].code - 16; 158 short OIS_POVIndex = POV_MASK[LinuxPovNumber]; 159 160 //Handle X Axis first (Even) (left right) 161 if((LinuxPovNumber & 0x0001) == 0) 131 break; 132 } 133 134 case EV_ABS: //Absolute Axis 135 { 136 //A Stick (BrakeDefine is the highest possible Axis) 137 if( js[i].code <= ABS_BRAKE ) 162 138 { 163 //Why do this? Because, we use a bit field, and when this axis is east, 164 //it can't possibly be west too. So clear out the two X axes, then refil 165 //it in with the new direction bit. 166 //Clear the East/West Bit Flags first 167 mState.mPOV[OIS_POVIndex].direction &= 0x11110011; 168 if( js[i].value == -1 ) //Left 169 mState.mPOV[OIS_POVIndex].direction |= Pov::West; 170 else if( js[i].value == 1 ) //Right 171 mState.mPOV[OIS_POVIndex].direction |= Pov::East; 139 int axis = mAxisMap[js[i].code]; 140 assert( axis < 32 && "Too many axes (Max supported is 32). Report this to OIS forums!" ); 141 142 axisMoved[axis] = true; 143 144 //check for rescaling: 145 if( mRanges[axis].min == JoyStick::MIN_AXIS && mRanges[axis].max != JoyStick::MAX_AXIS ) 146 { //Scale is perfect 147 mState.mAxes[axis].abs = js[i].value; 148 } 149 else 150 { //Rescale 151 float proportion = (float)(js[i].value-mRanges[axis].max)/(float)(mRanges[axis].min-mRanges[axis].max); 152 mState.mAxes[axis].abs = (int)(32767.0f - (65535.0f * proportion)); 153 } 172 154 } 173 //Handle Y Axis (Odd) (up down) 174 else 155 else if( js[i].code <= ABS_HAT3Y ) //A POV - Max four POVs allowed 175 156 { 176 //Clear the North/South Bit Flags first 177 mState.mPOV[OIS_POVIndex].direction &= 0x11111100; 178 if( js[i].value == -1 ) //Up 179 mState.mPOV[OIS_POVIndex].direction |= Pov::North; 180 else if( js[i].value == 1 ) //Down 181 mState.mPOV[OIS_POVIndex].direction |= Pov::South; 157 //Normalise the POV to between 0-7 158 //Even is X Axis, Odd is Y Axis 159 unsigned char LinuxPovNumber = js[i].code - 16; 160 short OIS_POVIndex = POV_MASK[LinuxPovNumber]; 161 162 //Handle X Axis first (Even) (left right) 163 if((LinuxPovNumber & 0x0001) == 0) 164 { 165 //Why do this? Because, we use a bit field, and when this axis is east, 166 //it can't possibly be west too. So clear out the two X axes, then refil 167 //it in with the new direction bit. 168 //Clear the East/West Bit Flags first 169 mState.mPOV[OIS_POVIndex].direction &= 0x11110011; 170 if( js[i].value == -1 ) //Left 171 mState.mPOV[OIS_POVIndex].direction |= Pov::West; 172 else if( js[i].value == 1 ) //Right 173 mState.mPOV[OIS_POVIndex].direction |= Pov::East; 174 } 175 //Handle Y Axis (Odd) (up down) 176 else 177 { 178 //Clear the North/South Bit Flags first 179 mState.mPOV[OIS_POVIndex].direction &= 0x11111100; 180 if( js[i].value == -1 ) //Up 181 mState.mPOV[OIS_POVIndex].direction |= Pov::North; 182 else if( js[i].value == 1 ) //Down 183 mState.mPOV[OIS_POVIndex].direction |= Pov::South; 184 } 185 186 if( mBuffered && mListener ) 187 if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) 188 return; 182 189 } 183 184 if( mBuffered && mListener ) 185 if( mListener->povMoved( JoyStickEvent(this,mState), OIS_POVIndex) == false ) 186 return; 187 } 188 break; 189 } 190 191 192 case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) 193 #ifdef OIS_LINUX_JOY_DEBUG 194 cout << "\nWarning: Relatives axes not supported yet" << endl; 195 #endif 196 break; 197 default: break; 190 break; 191 } 192 193 194 case EV_REL: //Relative Axes (Do any joystick actually have a relative axis?) 195 #ifdef OIS_LINUX_JOY_DEBUG 196 cout << "\nWarning: Relatives axes not supported yet" << endl; 197 #endif 198 break; 199 default: break; 200 } 198 201 } 199 202 } -
code/branches/kicklib2/src/external/ois/linux/LinuxKeyboard.cpp
r5781 r8284 33 33 #include <iostream> 34 34 //-------------------------------------------------------------------// 35 LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab , bool useXRepeat)35 LinuxKeyboard::LinuxKeyboard(InputManager* creator, bool buffered, bool grab) 36 36 : Keyboard(creator->inputSystemName(), buffered, 0, creator) 37 37 { … … 43 43 grabKeyboard = grab; 44 44 keyFocusLost = false; 45 46 xAutoRepeat = useXRepeat;47 oldXAutoRepeat = false;48 45 49 46 //X Key Map to KeyCode … … 213 210 214 211 keyFocusLost = false; 215 216 if( xAutoRepeat == false )217 {218 //We do not want to blindly turn on autorepeat later when quiting if219 //it was not on to begin with.. So, let us check and see first220 XKeyboardState old;221 XGetKeyboardControl( display, &old );222 oldXAutoRepeat = false;223 224 if( old.global_auto_repeat == AutoRepeatModeOn )225 oldXAutoRepeat = true;226 227 XAutoRepeatOff( display );228 }229 212 } 230 213 … … 234 217 if( display ) 235 218 { 236 if( oldXAutoRepeat )237 XAutoRepeatOn(display);238 239 219 if( grabKeyboard ) 240 220 XUngrabKeyboard(display, CurrentTime); … … 303 283 304 284 while( XPending(display) > 0 ) 305 { XNextEvent(display, &event); if( KeyPress == event.type ) 285 { 286 XNextEvent(display, &event); 287 288 if(KeyPress == event.type) 306 289 { 307 290 unsigned int character = 0; 308 291 309 if( mTextMode != Off)292 if(mTextMode != Off) 310 293 { 311 294 unsigned char buffer[6] = {0,0,0,0,0,0}; … … 332 315 if( event.xkey.state & Mod1Mask && key == XK_Tab ) 333 316 linMan->_setGrabState(false); 334 } else if( KeyRelease == event.type ) 317 } 318 else if(KeyRelease == event.type) 335 319 { 336 //Mask out the modifier states X sets.. or we will get improper values 337 event.xkey.state &= ~ShiftMask; 338 event.xkey.state &= ~LockMask; 339 340 //Else, it is a valid key release 341 XLookupString(&event.xkey,NULL,0,&key,NULL); 342 _injectKeyUp(key); } 320 if(!_isKeyRepeat(event)) 321 { 322 //Mask out the modifier states X sets.. or we will get improper values 323 event.xkey.state &= ~ShiftMask; 324 event.xkey.state &= ~LockMask; 325 326 XLookupString(&event.xkey,NULL,0,&key,NULL); 327 _injectKeyUp(key); 328 } 329 } 343 330 } 344 331 -
code/branches/kicklib2/src/external/ois/linux/LinuxKeyboard.h
r5781 r8284 34 34 { 35 35 public: 36 LinuxKeyboard(InputManager* creator, bool buffered, bool grab , bool useXRepeat);36 LinuxKeyboard(InputManager* creator, bool buffered, bool grab); 37 37 virtual ~LinuxKeyboard(); 38 38 … … 59 59 60 60 protected: 61 inline bool _isKeyRepeat(XEvent &event) 62 { 63 //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 64 if(!XPending(display)) 65 return false; 66 67 XEvent e; 68 XPeekEvent(display, &e); 69 if(e.type == KeyPress && e.xkey.keycode == event.xkey.keycode && (e.xkey.time - event.xkey.time) < 2) 70 { 71 XNextEvent(display, &e); 72 return true; 73 } 74 75 return false; 76 } 77 61 78 bool _injectKeyDown( KeySym key, int text ); 62 79 bool _injectKeyUp( KeySym key ); … … 75 92 bool keyFocusLost; 76 93 77 bool xAutoRepeat;78 bool oldXAutoRepeat;79 80 94 std::string mGetString; 81 95 }; -
code/branches/kicklib2/src/external/ois/linux/LinuxMouse.cpp
r5781 r8284 173 173 174 174 //Compute this frames Relative X & Y motion 175 mState.X.rel= event.xmotion.x - oldXMouseX;176 mState.Y.rel= event.xmotion.y - oldXMouseY;175 int dx = event.xmotion.x - oldXMouseX; 176 int dy = event.xmotion.y - oldXMouseY; 177 177 178 178 //Store old values for next time to compute relative motion … … 180 180 oldXMouseY = event.xmotion.y; 181 181 182 mState.X.abs += mState.X.rel; 183 mState.Y.abs += mState.Y.rel; 182 mState.X.abs += dx; 183 mState.Y.abs += dy; 184 mState.X.rel += dx; 185 mState.Y.rel += dy; 184 186 185 187 //Check to see if we are grabbing the mouse to the window (requires clipping and warping) -
code/branches/kicklib2/src/external/ois/linux/LinuxPrereqs.h
r5781 r8284 32 32 33 33 //! Max number of elements to collect from buffered input 34 #define JOY_BUFFERSIZE 1034 #define JOY_BUFFERSIZE 64 35 35 36 36 namespace OIS
Note: See TracChangeset
for help on using the changeset viewer.