Changeset 59356 in vbox for trunk/src/VBox/Frontends
- Timestamp:
- Jan 15, 2016 10:58:45 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105043
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r59347 r59356 100 100 /* Prepare keyboard-handler: */ 101 101 UIKeyboardHandler *pKeyboardHandler = 0; 102 102 103 /* Depending on visual-state type: */ 103 104 switch (visualStateType) … … 118 119 break; 119 120 } 121 120 122 #ifdef Q_WS_WIN 121 /* It s requiredto have static pointer to created handler123 /* It is necessary to have static pointer to created handler 122 124 * because windows keyboard-hook works only with static members: */ 123 125 m_spKeyboardHandler = pKeyboardHandler; 124 126 #endif /* Q_WS_WIN */ 127 125 128 /* Return prepared keyboard-handler: */ 126 129 return pKeyboardHandler; … … 130 133 void UIKeyboardHandler::destroy(UIKeyboardHandler *pKeyboardHandler) 131 134 { 132 /* Delete keyboard-handler: */133 135 #ifdef Q_WS_WIN 136 /* It was necessary to have static pointer to created handler 137 * because windows keyboard-hook works only with static members: */ 134 138 m_spKeyboardHandler = 0; 135 139 #endif /* Q_WS_WIN */ 140 141 /* Delete keyboard-handler: */ 136 142 delete pKeyboardHandler; 137 143 } … … 232 238 m_iKeyboardCaptureViewIndex = uScreenId; 233 239 234 #if defined(Q_WS_WIN) 240 #if defined(Q_WS_MAC) 241 242 /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */ 243 ::DarwinDisableGlobalHotKeys(true); 244 m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard(); 245 246 #elif defined(Q_WS_WIN) 247 235 248 /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */ 249 236 250 #elif defined(Q_WS_X11) 251 237 252 /* On X11, we are using passive XGrabKey for normal (windowed) mode 238 253 * instead of XGrabKeyboard (called by QWidget::grabKeyboard()) … … 282 297 break; 283 298 } 284 #elif defined(Q_WS_MAC) 285 /* On Mac, we use the Qt methods + disabling global hot keys + watching modifiers (for right/left separation). */ 286 ::DarwinDisableGlobalHotKeys(true); 287 m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard(); 299 288 300 #else 301 289 302 /* On other platforms we are just praying Qt method will work. */ 290 303 m_views[m_iKeyboardCaptureViewIndex]->grabKeyboard(); 304 291 305 #endif 292 306 … … 308 322 m_fIsKeyboardCaptured = false; 309 323 310 #if defined(Q_WS_WIN) 324 #if defined(Q_WS_MAC) 325 326 ::DarwinDisableGlobalHotKeys(false); 327 m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard(); 328 329 #elif defined(Q_WS_WIN) 330 311 331 /* On Win, keyboard grabbing is ineffective, a low-level keyboard hook is used instead. */ 332 312 333 #elif defined(Q_WS_X11) 334 313 335 /* On X11, we are using passive XGrabKey for normal (windowed) mode 314 336 * instead of XGrabKeyboard (called by QWidget::grabKeyboard()) … … 344 366 break; 345 367 } 346 #elif defined(Q_WS_MAC) 347 ::DarwinDisableGlobalHotKeys(false); 368 369 #else 370 348 371 m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard(); 349 #else 350 m_views[m_iKeyboardCaptureViewIndex]->releaseKeyboard(); 372 351 373 #endif 352 374 … … 409 431 alphaLock | kEventKeyModifierNumLockMask | 410 432 (aReleaseHostKey ? 0 : hostComboModifierMask); 411 #endif 433 #endif /* Q_WS_MAC */ 412 434 413 435 /* Notify all the listeners: */ … … 852 874 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() && 853 875 GetAncestor((HWND)m_views[theListOfViewIds[i]]->winId(), GA_ROOT) == GetForegroundWindow()) 854 #else /* Q_WS_WIN */876 #else /* !Q_WS_WIN */ 855 877 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally()) 856 878 #endif /* !Q_WS_WIN */ … … 939 961 /* Initialize the X keyboard subsystem: */ 940 962 initMappedX11Keyboard(QX11Info::display(), vboxGlobal().settings().publicProperty("GUI/RemapScancodes")); 941 #endif 963 #endif /* Q_WS_X11 */ 942 964 943 965 /* Extra data settings: */ … … 950 972 void UIKeyboardHandler::cleanupCommon() 951 973 { 952 #if defined(Q_WS_WIN) 953 /* Cleanup AltGR monitor: */ 954 delete m_pAltGrMonitor; 955 m_pAltGrMonitor = 0; 956 957 /* Cleaning keyboard-hook: */ 958 if (m_keyboardHook) 959 { 960 UnhookWindowsHookEx(m_keyboardHook); 961 m_keyboardHook = NULL; 962 } 963 #elif defined(Q_WS_MAC) 974 #if defined(Q_WS_MAC) 975 964 976 /* We have to make sure the callback for the keyboard events 965 977 * is released when closing this view. */ 966 978 if (m_iKeyboardHookViewIndex != -1) 967 979 darwinGrabKeyboardEvents(false); 968 #endif /* Q_WS_MAC */ 980 981 #elif defined(Q_WS_WIN) 982 983 /* Cleanup AltGR monitor: */ 984 delete m_pAltGrMonitor; 985 m_pAltGrMonitor = 0; 986 987 /* Cleaning keyboard-hook: */ 988 if (m_keyboardHook) 989 { 990 UnhookWindowsHookEx(m_keyboardHook); 991 m_keyboardHook = NULL; 992 } 993 994 #endif /* Q_WS_WIN */ 969 995 } 970 996 … … 1004 1030 switch (pEvent->type()) 1005 1031 { 1006 #if defined(Q_WS_WIN)1032 #ifdef Q_WS_WIN 1007 1033 /* Install/uninstall low-level keyboard-hook on every activation/deactivation to: 1008 1034 * a) avoid excess hook calls when we're not active and; … … 1042 1068 break; 1043 1069 } 1044 #endif 1070 #endif /* Q_WS_WIN */ 1045 1071 default: 1046 1072 break; … … 1083 1109 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally() && 1084 1110 GetAncestor((HWND)pWatchedView->winId(), GA_ROOT) == GetForegroundWindow()) 1085 #else /* Q_WS_WIN */1111 #else /* !Q_WS_WIN */ 1086 1112 if (!isAutoCaptureDisabled() && autoCaptureSetGlobally()) 1087 1113 #endif /* !Q_WS_WIN */ … … 1707 1733 bool fWasProcessed = false; 1708 1734 1709 #ifdef Q_WS_WIN 1735 #if defined(Q_WS_MAC) 1736 1737 Q_UNUSED(iHotKey); 1738 if (pHotKey && pHotKey[0] && !pHotKey[1]) 1739 fWasProcessed = actionPool()->processHotKey(QKeySequence(Qt::UNICODE_ACCEL + QChar(pHotKey[0]).toUpper().unicode())); 1740 1741 #elif defined(Q_WS_WIN) 1742 1710 1743 Q_UNUSED(pHotKey); 1711 1744 int iKeyboardLayout = GetKeyboardLayoutList(0, NULL); … … 1723 1756 } 1724 1757 delete[] pList; 1725 #endif /* Q_WS_WIN */ 1726 1727 #ifdef Q_WS_X11 1758 1759 #elif defined(Q_WS_X11) 1760 1728 1761 Q_UNUSED(pHotKey); 1729 1762 Display *pDisplay = QX11Info::display(); … … 1741 1774 } 1742 1775 } 1743 #endif /* Q_WS_X11 */ 1744 1745 #ifdef Q_WS_MAC 1746 Q_UNUSED(iHotKey); 1747 if (pHotKey && pHotKey[0] && !pHotKey[1]) 1748 fWasProcessed = actionPool()->processHotKey(QKeySequence(Qt::UNICODE_ACCEL + QChar(pHotKey[0]).toUpper().unicode())); 1749 #endif /* Q_WS_MAC */ 1776 1777 #else 1778 1779 # warning "port me!" 1780 1781 #endif 1750 1782 1751 1783 /* Grab the key from the Qt if it was processed, or pass it to the Qt otherwise … … 1758 1790 /* Synchronize the views of the host and the guest to the modifier keys. 1759 1791 * This function will add up to 6 additional keycodes to codes. */ 1760 #if defined(Q_WS_X11) 1761 Window wDummy1, wDummy2; 1762 int iDummy3, iDummy4, iDummy5, iDummy6; 1763 unsigned uMask; 1764 unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0; 1765 1766 uKeyMaskCaps = LockMask; 1767 XModifierKeymap* map = XGetModifierMapping(QX11Info::display()); 1768 KeyCode keyCodeNum = XKeysymToKeycode(QX11Info::display(), XK_Num_Lock); 1769 1770 for (int i = 0; i < 8; ++ i) 1771 if (keyCodeNum != NoSymbol && map->modifiermap[map->max_keypermod * i] == keyCodeNum) 1772 uKeyMaskNum = 1 << i; 1773 XQueryPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), &wDummy1, &wDummy2, 1774 &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask); 1775 XFreeModifiermap(map); 1776 1777 if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(uMask & uKeyMaskNum))) 1778 { 1779 uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1); 1780 piCodes[(*puCount)++] = 0x45; 1781 piCodes[(*puCount)++] = 0x45 | 0x80; 1782 } 1783 if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(uMask & uKeyMaskCaps))) 1792 1793 #if defined(Q_WS_MAC) 1794 1795 /* if (uisession()->numLockAdaptionCnt()) ... - NumLock isn't implemented by Mac OS X so ignore it. */ 1796 if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(::GetCurrentEventKeyModifiers() & alphaLock))) 1784 1797 { 1785 1798 uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1); … … 1795 1808 } 1796 1809 } 1810 1797 1811 #elif defined(Q_WS_WIN) 1812 1798 1813 if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(GetKeyState(VK_NUMLOCK)))) 1799 1814 { … … 1816 1831 } 1817 1832 } 1818 #elif defined(Q_WS_MAC) 1819 /* if (uisession()->numLockAdaptionCnt()) ... - NumLock isn't implemented by Mac OS X so ignore it. */ 1820 if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(::GetCurrentEventKeyModifiers() & alphaLock))) 1833 1834 #elif defined(Q_WS_X11) 1835 1836 Window wDummy1, wDummy2; 1837 int iDummy3, iDummy4, iDummy5, iDummy6; 1838 unsigned uMask; 1839 unsigned uKeyMaskNum = 0, uKeyMaskCaps = 0; 1840 1841 uKeyMaskCaps = LockMask; 1842 XModifierKeymap* map = XGetModifierMapping(QX11Info::display()); 1843 KeyCode keyCodeNum = XKeysymToKeycode(QX11Info::display(), XK_Num_Lock); 1844 1845 for (int i = 0; i < 8; ++ i) 1846 if (keyCodeNum != NoSymbol && map->modifiermap[map->max_keypermod * i] == keyCodeNum) 1847 uKeyMaskNum = 1 << i; 1848 XQueryPointer(QX11Info::display(), DefaultRootWindow(QX11Info::display()), &wDummy1, &wDummy2, 1849 &iDummy3, &iDummy4, &iDummy5, &iDummy6, &uMask); 1850 XFreeModifiermap(map); 1851 1852 if (uisession()->numLockAdaptionCnt() && (uisession()->isNumLock() ^ !!(uMask & uKeyMaskNum))) 1853 { 1854 uisession()->setNumLockAdaptionCnt(uisession()->numLockAdaptionCnt() - 1); 1855 piCodes[(*puCount)++] = 0x45; 1856 piCodes[(*puCount)++] = 0x45 | 0x80; 1857 } 1858 if (uisession()->capsLockAdaptionCnt() && (uisession()->isCapsLock() ^ !!(uMask & uKeyMaskCaps))) 1821 1859 { 1822 1860 uisession()->setCapsLockAdaptionCnt(uisession()->capsLockAdaptionCnt() - 1); … … 1832 1870 } 1833 1871 } 1872 1834 1873 #else 1835 //#warning Adapt UIKeyboardHandler::fixModifierState 1874 1875 # warning "port me!" 1876 1836 1877 #endif 1837 1878 }
Note:
See TracChangeset
for help on using the changeset viewer.