Changeset 59347 in vbox for trunk/src/VBox/Frontends/VirtualBox
- Timestamp:
- Jan 14, 2016 1:56:30 PM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105028
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r59345 r59347 138 138 139 139 /* Prepare listened objects: */ 140 void UIKeyboardHandler::prepareListener(ulong u Index, UIMachineWindow *pMachineWindow)140 void UIKeyboardHandler::prepareListener(ulong uScreenId, UIMachineWindow *pMachineWindow) 141 141 { 142 142 /* If that window is NOT registered yet: */ 143 if (!m_windows.contains(u Index))143 if (!m_windows.contains(uScreenId)) 144 144 { 145 145 /* Add window: */ 146 m_windows.insert(u Index, pMachineWindow);146 m_windows.insert(uScreenId, pMachineWindow); 147 147 /* Install event-filter for window: */ 148 m_windows[u Index]->installEventFilter(this);148 m_windows[uScreenId]->installEventFilter(this); 149 149 } 150 150 151 151 /* If that view is NOT registered yet: */ 152 if (!m_views.contains(u Index))152 if (!m_views.contains(uScreenId)) 153 153 { 154 154 /* Add view: */ 155 m_views.insert(u Index, pMachineWindow->machineView());155 m_views.insert(uScreenId, pMachineWindow->machineView()); 156 156 /* Install event-filter for view: */ 157 m_views[u Index]->installEventFilter(this);157 m_views[uScreenId]->installEventFilter(this); 158 158 } 159 159 } 160 160 161 161 /* Cleanup listened objects: */ 162 void UIKeyboardHandler::cleanupListener(ulong u Index)162 void UIKeyboardHandler::cleanupListener(ulong uScreenId) 163 163 { 164 164 /* Check if we should release keyboard first: */ 165 if ((int)u Index== m_iKeyboardCaptureViewIndex)165 if ((int)uScreenId == m_iKeyboardCaptureViewIndex) 166 166 releaseKeyboard(); 167 167 168 168 /* If window still registered: */ 169 if (m_windows.contains(u Index))169 if (m_windows.contains(uScreenId)) 170 170 { 171 171 /* Remove window: */ 172 m_windows.remove(u Index);172 m_windows.remove(uScreenId); 173 173 } 174 174 175 175 /* If view still registered: */ 176 if (m_views.contains(u Index))176 if (m_views.contains(uScreenId)) 177 177 { 178 178 /* Remove view: */ 179 m_views.remove(u Index);179 m_views.remove(uScreenId); 180 180 } 181 181 } … … 406 406 hostComboModifierMask |= ::DarwinKeyCodeToDarwinModifierMask(hostCombo.at(i)); 407 407 /* Clear most of the modifiers: */ 408 m_ darwinKeyModifiers &=408 m_uDarwinKeyModifiers &= 409 409 alphaLock | kEventKeyModifierNumLockMask | 410 410 (aReleaseHostKey ? 0 : hostComboModifierMask); … … 889 889 , m_fDebuggerActive(false) 890 890 #if defined(Q_WS_MAC) 891 , m_darwinKeyModifiers(0) 892 , m_fKeyboardGrabbed(false) 893 , m_iKeyboardGrabViewIndex(-1) 891 , m_iKeyboardHookViewIndex(-1) 892 , m_uDarwinKeyModifiers(0) 894 893 #elif defined(Q_WS_WIN) 895 , m_bIsHostkeyInCapture(false)896 894 , m_iKeyboardHookViewIndex(-1) 895 , m_fIsHostkeyInCapture(false) 897 896 , m_fSkipKeyboardEvents(false) 897 , m_keyboardHook(NULL) 898 898 , m_pAltGrMonitor(0) 899 899 #endif /* Q_WS_WIN */ … … 964 964 /* We have to make sure the callback for the keyboard events 965 965 * is released when closing this view. */ 966 if (m_ fKeyboardGrabbed)966 if (m_iKeyboardHookViewIndex != -1) 967 967 darwinGrabKeyboardEvents(false); 968 968 #endif /* Q_WS_MAC */ … … 1022 1022 } 1023 1023 /* Register new keyboard-hook: */ 1024 m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, lowLevelKeyboardProc, GetModuleHandle(NULL), 0);1024 m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0); 1025 1025 AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError())); 1026 1026 /* Remember which view had captured keyboard: */ … … 1064 1064 /* If keyboard-event handler is NOT currently installed; 1065 1065 * Or installed but NOT for that view: */ 1066 if (m_iKeyboard GrabViewIndex != (int)uScreenId)1066 if (m_iKeyboardHookViewIndex != (int)uScreenId) 1067 1067 { 1068 1068 /* If keyboard-event handler is NOT currently installed: */ 1069 if (m_iKeyboard GrabViewIndex == -1)1069 if (m_iKeyboardHookViewIndex == -1) 1070 1070 { 1071 1071 /* Install the keyboard-event handler: */ … … 1073 1073 } 1074 1074 /* Update the id: */ 1075 m_iKeyboard GrabViewIndex = uScreenId;1075 m_iKeyboardHookViewIndex = uScreenId; 1076 1076 } 1077 1077 #endif /* Q_WS_MAC */ … … 1097 1097 #ifdef Q_WS_MAC 1098 1098 /* If keyboard-event handler is installed for that view: */ 1099 if (m_iKeyboard GrabViewIndex == (int)uScreenId)1099 if (m_iKeyboardHookViewIndex == (int)uScreenId) 1100 1100 { 1101 1101 /* Remove the keyboard-event handler: */ 1102 1102 darwinGrabKeyboardEvents(false); 1103 1103 /* Update the id: */ 1104 m_iKeyboard GrabViewIndex = -1;1104 m_iKeyboardHookViewIndex = -1; 1105 1105 } 1106 1106 #endif /* Q_WS_MAC */ … … 1165 1165 void UIKeyboardHandler::darwinGrabKeyboardEvents(bool fGrab) 1166 1166 { 1167 m_fKeyboardGrabbed = fGrab;1168 1167 if (fGrab) 1169 1168 { … … 1174 1173 /* Bring the caps lock state up to date, otherwise e.g. a later Shift 1175 1174 * key press will accidentally inject a CapsLock key press and release, 1176 * see UIKeyboardHandler:: darwinKeyboardEvent for the code handling1175 * see UIKeyboardHandler::macKeyboardEvent for the code handling 1177 1176 * modifier key state changes */ 1178 m_ darwinKeyModifiers ^= (m_darwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock;1177 m_uDarwinKeyModifiers ^= (m_uDarwinKeyModifiers ^ ::GetCurrentEventKeyModifiers()) & alphaLock; 1179 1178 1180 1179 /* Register the event callback/hook and grab the keyboard. */ 1181 1180 UICocoaApplication::instance()->registerForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 1182 UIKeyboardHandler:: darwinEventHandlerProc, this);1181 UIKeyboardHandler::macKeyboardProc, this); 1183 1182 1184 1183 ::DarwinGrabKeyboard (false); … … 1188 1187 ::DarwinReleaseKeyboard(); 1189 1188 UICocoaApplication::instance()->unregisterForNativeEvents(RT_BIT_32(10) | RT_BIT_32(11) | RT_BIT_32(12) /* NSKeyDown | NSKeyUp | | NSFlagsChanged */, 1190 UIKeyboardHandler:: darwinEventHandlerProc, this);1191 } 1192 } 1193 1194 bool UIKeyboardHandler:: darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser)1189 UIKeyboardHandler::macKeyboardProc, this); 1190 } 1191 } 1192 1193 bool UIKeyboardHandler::macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser) 1195 1194 { 1196 1195 UIKeyboardHandler *pKeyboardHandler = (UIKeyboardHandler*)pvUser; … … 1206 1205 if (eventClass == kEventClassKeyboard) 1207 1206 { 1208 if (pKeyboardHandler-> darwinKeyboardEvent(pvCocoaEvent, inEvent))1207 if (pKeyboardHandler->macKeyboardEvent(pvCocoaEvent, inEvent)) 1209 1208 return true; 1210 1209 } … … 1213 1212 } 1214 1213 1215 bool UIKeyboardHandler:: darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent)1214 bool UIKeyboardHandler::macKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent) 1216 1215 { 1217 1216 bool ret = false; … … 1256 1255 ucs[cbWritten / sizeof(wchar_t)] = 0; /* The api doesn't terminate it. */ 1257 1256 1258 ret = keyEvent(keyCode, scanCode, flags, m_iKeyboard GrabViewIndex, ucs[0] ? ucs : NULL);1257 ret = keyEvent(keyCode, scanCode, flags, m_iKeyboardHookViewIndex, ucs[0] ? ucs : NULL); 1259 1258 } 1260 1259 } … … 1266 1265 sizeof(newMask), NULL, &newMask); 1267 1266 newMask = ::DarwinAdjustModifierMask(newMask, pvCocoaEvent); 1268 UInt32 changed = newMask ^ m_ darwinKeyModifiers;1267 UInt32 changed = newMask ^ m_uDarwinKeyModifiers; 1269 1268 if (changed) 1270 1269 { … … 1285 1284 flags |= KeyExtended; 1286 1285 scanCode &= VBOXKEY_SCANCODE_MASK; 1287 ret |= keyEvent(keyCode, scanCode & 0xff, flags, m_iKeyboard GrabViewIndex);1286 ret |= keyEvent(keyCode, scanCode & 0xff, flags, m_iKeyboardHookViewIndex); 1288 1287 } 1289 1288 else … … 1293 1292 flags |= KeyExtended; 1294 1293 scanCode &= VBOXKEY_SCANCODE_MASK; 1295 keyEvent(keyCode, scanCode, flags | KeyPressed, m_iKeyboard GrabViewIndex);1296 keyEvent(keyCode, scanCode, flags, m_iKeyboard GrabViewIndex);1294 keyEvent(keyCode, scanCode, flags | KeyPressed, m_iKeyboardHookViewIndex); 1295 keyEvent(keyCode, scanCode, flags, m_iKeyboardHookViewIndex); 1297 1296 } 1298 1297 } 1299 1298 } 1300 1299 1301 m_ darwinKeyModifiers = newMask;1300 m_uDarwinKeyModifiers = newMask; 1302 1301 1303 1302 /* Always return true here because we'll otherwise getting a Qt event … … 1311 1310 #elif defined(Q_WS_WIN) 1312 1311 1313 LRESULT CALLBACK UIKeyboardHandler:: lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)1314 { 1315 if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->win LowKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam))1312 LRESULT CALLBACK UIKeyboardHandler::winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam) 1313 { 1314 if (nCode == HC_ACTION && m_spKeyboardHandler && m_spKeyboardHandler->winKeyboardEvent(wParam, *(KBDLLHOOKSTRUCT*)lParam)) 1316 1315 return 1; 1317 1316 … … 1319 1318 } 1320 1319 1321 bool UIKeyboardHandler::win LowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event)1320 bool UIKeyboardHandler::winKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event) 1322 1321 { 1323 1322 /* Check what related machine-view was NOT unregistered yet: */ … … 1333 1332 if ( (event.flags & 0x80) /* released */ 1334 1333 && ( ( UIHostCombo::toKeyCodeList(m_globalSettings.hostCombo()).contains(event.vkCode) 1335 && !m_ bIsHostkeyInCapture)1334 && !m_fIsHostkeyInCapture) 1336 1335 || ( m_pressedKeys[event.scanCode & 0x7F] 1337 1336 & (IsKbdCaptured | what_pressed)) … … 1601 1600 if (m_bIsHostComboPressed || isHostComboStateChanged) 1602 1601 { 1603 /* Currently this is used in win LowKeyboardEvent() only: */1604 m_ bIsHostkeyInCapture = m_fIsKeyboardCaptured;1602 /* Currently this is used in winKeyboardEvent() only: */ 1603 m_fIsHostkeyInCapture = m_fIsKeyboardCaptured; 1605 1604 } 1606 1605 #endif /* Q_WS_WIN */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.h
r59346 r59347 71 71 72 72 /* Prepare/cleanup listeners: */ 73 void prepareListener(ulong u Index, UIMachineWindow *pMachineWindow);74 void cleanupListener(ulong u Index);73 void prepareListener(ulong uScreenId, UIMachineWindow *pMachineWindow); 74 void cleanupListener(ulong uScreenId); 75 75 76 76 /* Commands to capture/release keyboard: */ … … 91 91 #ifdef Q_WS_MAC 92 92 bool isHostKeyAlone() const { return m_bIsHostComboAlone; } 93 bool isKeyboardGrabbed() const { return m_ fKeyboardGrabbed; }93 bool isKeyboardGrabbed() const { return m_iKeyboardHookViewIndex != -1; } 94 94 #endif /* Q_WS_MAC */ 95 95 … … 153 153 void darwinGrabKeyboardEvents(bool fGrab); 154 154 /** Mac: Performs initial pre-processing of all the native keyboard events. */ 155 static bool darwinEventHandlerProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser);155 static bool macKeyboardProc(const void *pvCocoaEvent, const void *pvCarbonEvent, void *pvUser); 156 156 /** Mac: Performs initial pre-processing of all the native keyboard events. */ 157 bool darwinKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent);157 bool macKeyboardEvent(const void *pvCocoaEvent, EventRef inEvent); 158 158 #elif defined(Q_WS_WIN) 159 159 /** Win: Performs initial pre-processing of all the native keyboard events. */ 160 static LRESULT CALLBACK lowLevelKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam);160 static LRESULT CALLBACK winKeyboardProc(int nCode, WPARAM wParam, LPARAM lParam); 161 161 /** Win: Performs initial pre-processing of all the native keyboard events. */ 162 bool win LowKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event);162 bool winKeyboardEvent(UINT msg, const KBDLLHOOKSTRUCT &event); 163 163 #endif /* Q_WS_WIN */ 164 164 … … 212 212 213 213 #if defined(Q_WS_MAC) 214 /** Holds the keyboard hook view index. */ 215 int m_iKeyboardHookViewIndex; 214 216 /** Holds the current modifiers key mask. */ 215 UInt32 m_darwinKeyModifiers; 216 /** Holds whether the keyboard is grabbed. */ 217 bool m_fKeyboardGrabbed; 217 UInt32 m_uDarwinKeyModifiers; 218 #elif defined(Q_WS_WIN) 218 219 /** Holds the keyboard hook view index. */ 219 int m_iKeyboardGrabViewIndex; 220 #elif defined(Q_WS_WIN) 221 /* Currently this is used in winLowKeyboardEvent() only: */ 222 bool m_bIsHostkeyInCapture; 220 int m_iKeyboardHookViewIndex; 221 /* Currently this is used in winKeyboardEvent() only: */ 222 bool m_fIsHostkeyInCapture; 223 /** Holds whether the keyboard event filter should ignore keyboard events. */ 224 bool m_fSkipKeyboardEvents; 225 /** Holds the keyboard hook instance. */ 226 HHOOK m_keyboardHook; 227 /** Holds the object monitoring key event stream for problematic AltGr events. */ 228 WinAltGrMonitor *m_pAltGrMonitor; 223 229 /** Holds the keyboard handler reference to be accessible from the keyboard hook. */ 224 230 static UIKeyboardHandler *m_spKeyboardHandler; 225 /** Holds the keyboard hook instance. */226 HHOOK m_keyboardHook;227 /** Holds the keyboard hook view index. */228 int m_iKeyboardHookViewIndex;229 /** Holds whether the keyboard event filter should ignore keyboard events. */230 bool m_fSkipKeyboardEvents;231 /** Holds the object monitoring key event stream for problematic AltGr events. */232 WinAltGrMonitor *m_pAltGrMonitor;233 231 #endif /* Q_WS_WIN */ 234 232
Note:
See TracChangeset
for help on using the changeset viewer.