- Timestamp:
- Jun 30, 2011 4:34:13 PM (13 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r37423 r37716 191 191 case UIVisualStateType_Seamless: 192 192 { 193 /* Keyboard grabbing can fail temporarily because some keyboard shortcut is still grabbed by window manager. */ 194 if (XGrabKeyboard(QX11Info::display(), m_windows[m_iKeyboardCaptureViewIndex]->machineWindow()->winId(), False, GrabModeAsync, GrabModeAsync, CurrentTime)) 195 m_fIsKeyboardCaptured = false; 193 /* Keyboard grabbing can fail because of some keyboard shortcut is still grabbed by window manager. 194 * We can't be sure this shortcut will be released at all, so we will retry to grab keyboard for 50 times, 195 * and after we will just ignore that issue: */ 196 int cTriesLeft = 50; 197 while (cTriesLeft && XGrabKeyboard(QX11Info::display(), m_windows[m_iKeyboardCaptureViewIndex]->machineWindow()->winId(), False, GrabModeAsync, GrabModeAsync, CurrentTime)) { --cTriesLeft; } 196 198 break; 197 199 } … … 210 212 211 213 /* Notify all the listeners: */ 212 if (m_fIsKeyboardCaptured) 213 emit keyboardStateChanged(keyboardState()); 214 emit keyboardStateChanged(keyboardState()); 214 215 } 215 216 } … … 482 483 * and this hack is probably not necessary anymore. So disable it for Qt >= 4.5.0. */ 483 484 case XFocusOut: 485 case XFocusIn: 484 486 { 485 487 if (isSessionRunning()) … … 487 489 if (VBoxGlobal::qtRTVersion() < ((4 << 16) | (5 << 8) | 0)) 488 490 { 489 /* Release keyboard: */ 490 releaseKeyboard(); 491 /* And all pressed keys including host-one: */ 492 releaseAllPressedKeys(true); 491 if (pEvent->type == XFocusIn) 492 { 493 /* Capture keyboard by chosen view number: */ 494 captureKeyboard(uScreenId); 495 /* Reset the single-time disable capture flag: */ 496 if (isAutoCaptureDisabled()) 497 setAutoCaptureDisabled(false); 498 } 499 else 500 { 501 /* Release keyboard: */ 502 releaseKeyboard(); 503 /* And all pressed keys including host-one: */ 504 releaseAllPressedKeys(true); 505 } 493 506 } 494 507 } … … 587 600 /* And all pressed keys except the host-one : */ 588 601 releaseAllPressedKeys(false /* release host-key? */); 602 break; 603 } 604 case KMachineState_Running: 605 { 606 /* Capture the keyboard by the first focused view: */ 607 QList<ulong> theListOfViewIds = m_views.keys(); 608 for (int i = 0; i < theListOfViewIds.size(); ++i) 609 { 610 if (viewHasFocus(theListOfViewIds[i])) 611 { 612 /* Capture keyboard: */ 613 #ifdef Q_WS_WIN 614 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() && 615 GetAncestor(m_views[theListOfViewIds[i]]->winId(), GA_ROOT) == GetForegroundWindow()) 616 #else /* Q_WS_WIN */ 617 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally()) 618 #endif /* !Q_WS_WIN */ 619 captureKeyboard(theListOfViewIds[i]); 620 /* Reset the single-time disable capture flag: */ 621 if (isAutoCaptureDisabled()) 622 setAutoCaptureDisabled(false); 623 break; 624 } 625 } 589 626 break; 590 627 } … … 789 826 switch (pEvent->type()) 790 827 { 828 case QEvent::FocusIn: 829 if (isSessionRunning()) 830 { 831 /* Capture keyboard: */ 832 #ifdef Q_WS_WIN 833 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() && 834 GetAncestor(pWatchedView->winId(), GA_ROOT) == GetForegroundWindow()) 835 #else /* Q_WS_WIN */ 836 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally()) 837 #endif /* !Q_WS_WIN */ 838 captureKeyboard(uScreenId); 839 /* Reset the single-time disable capture flag: */ 840 if (isAutoCaptureDisabled()) 841 setAutoCaptureDisabled(false); 842 } 843 break; 791 844 case QEvent::FocusOut: 792 845 /* Release keyboard: */ … … 1088 1141 /** 1089 1142 * Handle a non-special (C-A-D, pause, print) key press or release 1090 * @returns true if handling should stop here (spurious event), false otherwise1143 * @returns true if handling should stop here, false otherwise 1091 1144 */ 1092 1145 bool UIKeyboardHandler::keyEventHandleNormal(int iKey, uint8_t uScan, int fFlags, LONG *pCodes, uint *puCodesCount) … … 1137 1190 return true; 1138 1191 return false; 1139 }1140 1141 /** Capture the keyboard if a non-modifier key was pressed. */1142 void UIKeyboardHandler::keyEventHandleCapturing(uint8_t uScan, int fFlags,1143 ulong uScreenId)1144 {1145 if ( (fFlags & KeyPressed)1146 && uScan != 0x1d /* ctrl */ && uScan != 0x2a /* left shift */1147 && uScan != 0x36 /* right shift */ && uScan != 0x38 /* alt */1148 && uScan != 0x5b /* left win */ && uScan != 0x5c /* right win */)1149 {1150 /* Capture keyboard by chosen view number: */1151 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally())1152 captureKeyboard(uScreenId);1153 /* Reset the single-time disable capture flag: */1154 if (isAutoCaptureDisabled())1155 setAutoCaptureDisabled(false);1156 }1157 1192 } 1158 1193 … … 1359 1394 } 1360 1395 1361 /* This must come before host key handling */1362 keyEventHandleCapturing(uScan, fFlags, uScreenId);1363 1364 1396 /* Process the host-combo funtionality: */ 1365 1397 if (fFlags & KeyPressed) -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
r37364 r37716 126 126 bool keyEventCADHandled(uint8_t uScan); 127 127 bool keyEventHandleNormal(int iKey, uint8_t uScan, int fFlags, LONG *pCodes, uint *puCodesCount); 128 void keyEventHandleCapturing(uint8_t uScan, int fFlags, ulong uScreenId);129 128 bool keyEventHostComboHandled(int iKey, wchar_t *pUniKey, bool isHostComboStateChanged, bool *pfResult); 130 129 void keyEventHandleHostComboRelease(ulong uScreenId); -
trunk/src/VBox/Frontends/VirtualBox/src/settings/global/UIGlobalSettingsInput.ui
r37368 r37716 82 82 <widget class="QCheckBox" name="m_pEnableAutoGrabCheckbox"> 83 83 <property name="whatsThis"> 84 <string>When checked, the keyboard will be captured automatically when you start typing into the virtual machine, preventing the host system from reacting to key combinations such as Alt-Tab. When the keyboard is not captured the virtual machine may not see certain key combinations.</string>84 <string>When checked, the keyboard is automatically captured every time the VM window is activated. When the keyboard is captured, all keystrokes (including system ones like Alt-Tab) are directed to the VM.</string> 85 85 </property> 86 86 <property name="text">
Note:
See TracChangeset
for help on using the changeset viewer.