Changeset 59359 in vbox for trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
- Timestamp:
- Jan 15, 2016 11:39:44 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105047
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r59356 r59359 240 240 #if defined(Q_WS_MAC) 241 241 242 /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */ 242 /* On Mac, keyboard grabbing is ineffective, 243 * a low-level keyboard-hook is used instead. 244 * It is being installed on focus-in event and uninstalled on focus-out. 245 * S.a. UIKeyboardHandler::eventFilter for more information. */ 246 247 /* On Mac, we also 248 * use the Qt method to grab the keyboard, 249 * disable global hot keys and 250 * enable watching modifiers (for right/left separation). */ 251 // TODO: Is that really needed? 243 252 ::DarwinDisableGlobalHotKeys(true); 244 253 m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard(); … … 246 255 #elif defined(Q_WS_WIN) 247 256 248 /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */ 257 /* On Win, keyboard grabbing is ineffective, 258 * a low-level keyboard-hook is used instead. 259 * It is being installed on window-activate event and uninstalled on window-deactivate. 260 * S.a. UIKeyboardHandler::eventFilter for more information. */ 249 261 250 262 #elif defined(Q_WS_X11) … … 300 312 #else 301 313 302 /* On other platforms we are just praying Qt method will work.*/314 /* On other platforms we are just praying Qt method to work: */ 303 315 m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard(); 304 316 … … 324 336 #if defined(Q_WS_MAC) 325 337 338 /* On Mac, keyboard grabbing is ineffective, 339 * a low-level keyboard-hook is used instead. 340 * It is being installed on focus-in event and uninstalled on focus-out. 341 * S.a. UIKeyboardHandler::eventFilter for more information. */ 342 343 /* On Mac, we also 344 * use the Qt method to release the keyboard, 345 * enable global hot keys and 346 * disable watching modifiers (for right/left separation). */ 347 // TODO: Is that really needed? 326 348 ::DarwinDisableGlobalHotKeys(false); 327 349 m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard(); … … 329 351 #elif defined(Q_WS_WIN) 330 352 331 /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */ 353 /* On Win, keyboard grabbing is ineffective, 354 * a low-level keyboard-hook is used instead. 355 * It is being installed on window-activate event and uninstalled on window-deactivate. 356 * S.a. UIKeyboardHandler::eventFilter for more information. */ 332 357 333 358 #elif defined(Q_WS_X11) … … 369 394 #else 370 395 396 /* On other platforms we are just praying Qt method to work: */ 371 397 m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard(); 372 398 373 399 #endif 374 400 375 /* Reset keyboard-capture index: */401 /* Forget which screen had captured keyboard: */ 376 402 m_iKeyboardCaptureViewIndex = -1; 377 403 … … 459 485 460 486 #ifdef Q_WS_WIN 461 /** Tell keyboard event handler to skip host keyboard events. Used for HID LEDs sync462 * when on Windows host a keyboard event is generated in order to change corresponding LED. */463 487 void UIKeyboardHandler::winSkipKeyboardEvents(bool fSkip) 464 488 { … … 974 998 #if defined(Q_WS_MAC) 975 999 976 /* We have to make sure the callback for the keyboard events 977 * is released when closing this view. */ 1000 /* Cleanup keyboard-hook: */ 978 1001 if (m_iKeyboardHookViewIndex != -1) 979 darwinGrabKeyboardEvents(false); 1002 { 1003 /* Ungrab the keyboard and unregister the event callback/hook: */ 1004 ::DarwinReleaseKeyboard(); 1005 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 1006 UIKeyboardHandler::macKeyboardProc, this); 1007 /* Update the id: */ 1008 m_iKeyboardHookViewIndex = -1; 1009 } 980 1010 981 1011 #elif defined(Q_WS_WIN) … … 985 1015 m_pAltGrMonitor = 0; 986 1016 987 /* Clean ingkeyboard-hook: */1017 /* Cleanup keyboard-hook: */ 988 1018 if (m_keyboardHook) 989 1019 { 990 UnhookWindowsHookEx(m_keyboardHook); 1020 /* Uninstall existing keyboard-hook: */ 1021 ::UnhookWindowsHookEx(m_keyboardHook); 991 1022 m_keyboardHook = NULL; 1023 /* Update the id: */ 1024 m_iKeyboardHookViewIndex = -1; 992 1025 } 993 1026 … … 1088 1121 { 1089 1122 #ifdef Q_WS_MAC 1090 /* If keyboard- event handler is NOT currentlyinstalled;1123 /* If keyboard-hook is NOT installed; 1091 1124 * Or installed but NOT for that view: */ 1092 if ( m_iKeyboardHookViewIndex != (int)uScreenId)1125 if ((int)uScreenId != m_iKeyboardHookViewIndex) 1093 1126 { 1094 /* If keyboard- event handleris NOT currently installed: */1127 /* If keyboard-hook is NOT currently installed: */ 1095 1128 if (m_iKeyboardHookViewIndex == -1) 1096 1129 { 1097 /* Install the keyboard-event handler: */ 1098 darwinGrabKeyboardEvents(true); 1130 /* Disable mouse and keyboard event compression/delaying 1131 * to make sure we *really* get all of the events: */ 1132 ::CGSetLocalEventsSuppressionInterval(0.0); 1133 ::darwinSetMouseCoalescingEnabled(false); 1134 1135 /* Bring the caps lock state up to date, 1136 * otherwise e.g. a later Shift key press will accidentally inject a CapsLock key press and release, 1137 * see UIKeyboardHandler::macKeyboardEvent for the code handling modifier key state changes. */ 1138 m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock; 1139 1140 /* Register the event callback/hook and grab the keyboard: */ 1141 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 1142 UIKeyboardHandler::macKeyboardProc, this); 1143 ::DarwinGrabKeyboard(false); 1099 1144 } 1100 1145 /* Update the id: */ … … 1122 1167 { 1123 1168 #ifdef Q_WS_MAC 1124 /* If keyboard- event handler is installed for that view: */1125 if ( m_iKeyboardHookViewIndex == (int)uScreenId)1169 /* If keyboard-hook is installed: */ 1170 if ((int)uScreenId == m_iKeyboardHookViewIndex) 1126 1171 { 1127 /* Remove the keyboard-event handler: */ 1128 darwinGrabKeyboardEvents(false); 1172 /* Ungrab the keyboard and unregister the event callback/hook: */ 1173 ::DarwinReleaseKeyboard(); 1174 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 1175 UIKeyboardHandler::macKeyboardProc, this); 1129 1176 /* Update the id: */ 1130 1177 m_iKeyboardHookViewIndex = -1; … … 1188 1235 1189 1236 #if defined(Q_WS_MAC) 1190 1191 void UIKeyboardHandler::darwinGrabKeyboardEvents(bool fGrab)1192 {1193 if (fGrab)1194 {1195 /* Disable mouse and keyboard event compression/delaying to make sure we *really* get all of the events. */1196 ::CGSetLocalEventsSuppressionInterval(0.0);1197 ::darwinSetMouseCoalescingEnabled(false);1198 1199 /* Bring the caps lock state up to date, otherwise e.g. a later Shift1200 * key press will accidentally inject a CapsLock key press and release,1201 * see UIKeyboardHandler::macKeyboardEvent for the code handling1202 * modifier key state changes */1203 m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;1204 1205 /* Register the event callback/hook and grab the keyboard. */1206 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */,1207 UIKeyboardHandler::macKeyboardProc, this);1208 1209 ::DarwinGrabKeyboard (false);1210 }1211 else1212 {1213 ::DarwinReleaseKeyboard();1214 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */,1215 UIKeyboardHandler::macKeyboardProc, this);1216 }1217 }1218 1237 1219 1238 bool UIKeyboardHandler::macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)
Note:
See TracChangeset
for help on using the changeset viewer.