Changeset 59373 in vbox
- Timestamp:
- Jan 18, 2016 9:38:33 AM (9 years ago)
- svn:sync-xref-src-repo-rev:
- 105062
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIKeyboardHandler.cpp
r59372 r59373 251 251 /* On Win, keyboard grabbing is ineffective, 252 252 * a low-level keyboard-hook is used instead. 253 * It is being installed on window-activate event and uninstalled on window-deactivate.253 * It is being installed on focus-in event and uninstalled on focus-out. 254 254 * S.a. UIKeyboardHandler::eventFilter for more information. */ 255 255 … … 350 350 /* On Win, keyboard grabbing is ineffective, 351 351 * a low-level keyboard-hook is used instead. 352 * It is being installed on window-activate event and uninstalled on window-deactivate.352 * It is being installed on focus-in event and uninstalled on focus-out. 353 353 * S.a. UIKeyboardHandler::eventFilter for more information. */ 354 354 … … 1209 1209 bool UIKeyboardHandler::eventFilter(QObject *pWatchedObject, QEvent *pEvent) 1210 1210 { 1211 /* Check if pWatchedObject object is window: */1212 if (UIMachineWindow *pWatchedWindow = isItListenedWindow(pWatchedObject))1213 {1214 /* Get corresponding screen index: */1215 ulong uScreenId = m_windows.key(pWatchedWindow);1216 NOREF(uScreenId);1217 /* Handle window events: */1218 switch (pEvent->type())1219 {1220 #ifdef Q_WS_WIN1221 /* Install/uninstall low-level keyboard-hook on every activation/deactivation to:1222 * a) avoid excess hook calls when we're not active and;1223 * b) be always in front of any other possible hooks. */1224 case QEvent::WindowActivate:1225 {1226 /* If keyboard hook is NOT currently created;1227 * Or created but NOT for that window: */1228 if (!m_keyboardHook || m_iKeyboardHookViewIndex != uScreenId)1229 {1230 /* If keyboard-hook present: */1231 if (m_keyboardHook)1232 {1233 /* We should remove existing keyboard-hook first: */1234 UnhookWindowsHookEx(m_keyboardHook);1235 m_keyboardHook = NULL;1236 }1237 /* Register new keyboard-hook: */1238 m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0);1239 AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError()));1240 /* Remember which view had captured keyboard: */1241 m_iKeyboardHookViewIndex = uScreenId;1242 }1243 break;1244 }1245 case QEvent::WindowDeactivate:1246 {1247 /* If keyboard is currently captured: */1248 if (m_keyboardHook && m_iKeyboardHookViewIndex == uScreenId)1249 {1250 /* We should remove existing keyboard-hook: */1251 UnhookWindowsHookEx(m_keyboardHook);1252 m_keyboardHook = NULL;1253 /* Remember what there is no window captured keyboard: */1254 m_iKeyboardHookViewIndex = -1;1255 }1256 break;1257 }1258 #endif /* Q_WS_WIN */1259 default:1260 break;1261 }1262 }1263 1264 else1265 1266 1211 /* Check if pWatchedObject object is view: */ 1267 1212 if (UIMachineView *pWatchedView = isItListenedView(pWatchedObject)) … … 1275 1220 case QEvent::FocusIn: 1276 1221 { 1277 #ifdef Q_WS_MAC 1222 #if defined(Q_WS_MAC) 1223 1278 1224 /* If keyboard-hook is NOT installed; 1279 1225 * Or installed but NOT for that view: */ 1280 1226 if ((int)uScreenId != m_iKeyboardHookViewIndex) 1281 1227 { 1282 /* If keyboard-hook is NOT currentlyinstalled: */1228 /* If keyboard-hook is NOT installed: */ 1283 1229 if (m_iKeyboardHookViewIndex == -1) 1284 1230 { … … 1301 1247 m_iKeyboardHookViewIndex = uScreenId; 1302 1248 } 1303 #endif /* Q_WS_MAC */ 1249 1250 #elif defined(Q_WS_WIN) 1251 1252 /* If keyboard-hook is NOT installed; 1253 * Or installed but NOT for that view: */ 1254 if (!m_keyboardHook || (int)uScreenId != m_iKeyboardHookViewIndex) 1255 { 1256 /* If keyboard-hook is installed: */ 1257 if (m_keyboardHook) 1258 { 1259 /* Uninstall existing keyboard-hook: */ 1260 UnhookWindowsHookEx(m_keyboardHook); 1261 m_keyboardHook = 0; 1262 } 1263 /* Install new keyboard-hook: */ 1264 m_keyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, UIKeyboardHandler::winKeyboardProc, GetModuleHandle(NULL), 0); 1265 AssertMsg(m_keyboardHook, ("SetWindowsHookEx(): err=%d", GetLastError())); 1266 /* Update the id: */ 1267 m_iKeyboardHookViewIndex = uScreenId; 1268 } 1269 1270 #endif /* Q_WS_WIN */ 1304 1271 1305 1272 if (isSessionRunning()) … … 1321 1288 case QEvent::FocusOut: 1322 1289 { 1323 #ifdef Q_WS_MAC 1290 #if defined(Q_WS_MAC) 1291 1324 1292 /* If keyboard-hook is installed: */ 1325 1293 if ((int)uScreenId == m_iKeyboardHookViewIndex) … … 1332 1300 m_iKeyboardHookViewIndex = -1; 1333 1301 } 1334 #endif /* Q_WS_MAC */ 1302 1303 #elif defined(Q_WS_WIN) 1304 1305 /* If keyboard-hook is installed: */ 1306 if (m_keyboardHook) 1307 { 1308 /* Uninstall existing keyboard-hook: */ 1309 UnhookWindowsHookEx(m_keyboardHook); 1310 m_keyboardHook = 0; 1311 /* Update the id: */ 1312 m_iKeyboardHookViewIndex = -1; 1313 } 1314 1315 #endif /* Q_WS_WIN */ 1335 1316 1336 1317 /* Release keyboard: */
Note:
See TracChangeset
for help on using the changeset viewer.