- Timestamp:
- Mar 9, 2010 5:34:39 PM (15 years ago)
- Location:
- trunk/src/VBox/Frontends/VirtualBox/src/runtime
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
r27222 r27227 167 167 } 168 168 169 void UIMachineView::setMouseIntegrationEnabled(bool bEnabled) 170 { 171 if (uisession()->isMouseIntegrated() == bEnabled) 169 void UIMachineView::setMouseIntegrationEnabled(bool fEnabled) 170 { 171 /* Do not change anything if its already so: */ 172 if (uisession()->isMouseIntegrated() == fEnabled) 172 173 return; 173 174 174 if (uisession()->isMouseSupportsAbsolute()) 175 captureMouse(!bEnabled, false); 176 177 /* Hiding host cursor in case we are entering mouse integration 178 * mode until it's shape is set to the guest cursor shape. */ 179 if (bEnabled) 180 viewport()->setCursor(QCursor(Qt::BlankCursor)); 181 182 uisession()->setMouseIntegrated(bEnabled); 183 175 /* Storing new mouse 'integrated' value: */ 176 uisession()->setMouseIntegrated(fEnabled); 177 178 /* We should capture/release mouse depending on mouse 'integrated' state: */ 179 captureMouse(!uisession()->isMouseIntegrated(), false /* emit signal? */); 180 181 /* Update mouse cursor shape: */ 182 updateMouseCursorShape(); 183 184 /* Also we switch guest mouse to the absolute mode: */ 185 if (uisession()->isMouseIntegrated() && 186 uisession()->isMouseSupportsAbsolute()) 187 { 188 CMouse mouse = session().GetConsole().GetMouse(); 189 mouse.PutMouseEventAbsolute(-1, -1, 0, 0, 0); 190 } 191 192 /* Notify all listeners: */ 184 193 emitMouseStateChanged(); 185 194 } … … 208 217 , m_bIsHostkeyInCapture(false) 209 218 , m_bIsMachineWindowResizeIgnored(false) 210 , m_bIsFrameBufferResizeIgnored(false)211 219 , m_fPassCAD(false) 212 220 #ifdef VBOX_WITH_VIDEOHWACCEL … … 360 368 } 361 369 362 void UIMachineView::updateMouseClipping() 370 void UIMachineView::updateMouseCursorShape() 371 { 372 /* First of all, we should check if the host pointer should be visible. 373 * We should hide host pointer in case of: 374 * 1. mouse is 'captured' or 375 * 2. mouse is 'not captured', 'integrated', 'absolute', host pointer is hidden by the guest. */ 376 if (uisession()->isMouseCaptured() || 377 (uisession()->isMouseIntegrated() && 378 uisession()->isMouseSupportsAbsolute() && 379 uisession()->isHidingHostPointer())) 380 { 381 viewport()->setCursor(Qt::BlankCursor); 382 } 383 384 else 385 386 /* Otherwise we should show host pointer with guest shape assigned to it if: 387 * mouse is 'integrated', 'absolute', valid pointer shape is present. */ 388 if (uisession()->isMouseIntegrated() && 389 uisession()->isMouseSupportsAbsolute() && 390 uisession()->isValidPointerShapePresent()) 391 { 392 viewport()->setCursor(uisession()->cursor()); 393 } 394 395 else 396 397 /* There could be other states covering such situations as: 398 * 1. mouse is 'not captured', 'integrated', 'not absolute' or 399 * 2. mouse is 'not captured', 'not integrated', 'absolute'. 400 * We have nothing to do with that except just unset the cursor. */ 401 viewport()->unsetCursor(); 402 } 403 404 #ifdef Q_WS_WIN32 405 /* This method is actually required only because 406 * under win-host we do not really grab the mouse 407 * in case of capturing it. I have to check if its 408 * really need, may be just grabMouse() will be enought: */ 409 void UIMachineView::updateMouseCursorClipping() 363 410 { 364 411 if (uisession()->isMouseCaptured()) 365 412 { 366 viewport()->setCursor(QCursor(Qt::BlankCursor));367 #ifdef Q_WS_WIN32368 413 QRect r = viewport()->rect(); 369 r.moveTopLeft(viewport()->mapToGlobal(QPoint 414 r.moveTopLeft(viewport()->mapToGlobal(QPoint(0, 0))); 370 415 RECT rect = { r.left(), r.top(), r.right() + 1, r.bottom() + 1 }; 371 416 ::ClipCursor(&rect); 372 #endif373 417 } 374 418 else 375 419 { 376 #ifdef Q_WS_WIN32377 420 ::ClipCursor(NULL); 378 #endif 379 /* return the cursor to where it was when we captured it and show it */ 380 QCursor::setPos(m_capturedMousePos); 381 viewport()->unsetCursor(); 382 } 383 } 421 } 422 } 423 #endif 384 424 385 425 void UIMachineView::updateSliders() … … 893 933 case QEvent::Resize: 894 934 { 895 if (uisession()->isMouseCaptured()) 896 updateMouseClipping(); 935 #ifdef Q_WS_WIN32 936 updateMouseCursorClipping(); 937 #endif 897 938 #ifdef VBOX_WITH_VIDEOHWACCEL 898 939 if (m_pFrameBuffer) … … 1060 1101 void UIMachineView::sltMousePointerShapeChanged() 1061 1102 { 1062 /* Mouse supports 'absolute' mode? */ 1063 if (uisession()->isMouseSupportsAbsolute()) 1064 { 1065 /* Should we hide pointer first of all? */ 1066 if (uisession()->isHidingHostPointer()) 1067 viewport()->setCursor(Qt::BlankCursor); 1068 /* Or should we use guest pointer shape? */ 1069 else if (uisession()->isValidPointerShapePresent()) 1070 viewport()->setCursor(uisession()->cursor()); 1071 /* Else we have no other way except unset cursor: */ 1072 else 1073 viewport()->unsetCursor(); 1074 } 1103 /* Update mouse cursor: */ 1104 updateMouseCursorShape(); 1075 1105 } 1076 1106 1077 1107 void UIMachineView::sltMouseCapabilityChanged() 1078 1108 { 1079 /* Correct the mouse capture state and reset the cursor to the default shape if necessary: */ 1080 if (uisession()->isMouseSupportsAbsolute()) 1109 /* We should release mouse if guest notified us about it supports 'absolute' mouse 1110 * and mouse is in 'integrated' mode, which could be chosen from main machine menu: */ 1111 if (uisession()->isMouseIntegrated() && uisession()->isMouseSupportsAbsolute()) 1081 1112 { 1082 1113 CMouse mouse = session().GetConsole().GetMouse(); … … 1084 1115 captureMouse(false, false); 1085 1116 } 1086 else 1087 viewport()->unsetCursor(); 1088 1089 /* Notify user about mouse integration state if method was called by signal: */ 1117 1118 /* Update mouse cursor shape: */ 1119 updateMouseCursorShape(); 1120 1121 /* Notify user about mouse 'absolute' state if method was called by signal: */ 1090 1122 if (sender()) vboxProblem().remindAboutMouseIntegration(uisession()->isMouseSupportsAbsolute()); 1091 1123 … … 1096 1128 void UIMachineView::sltMouseCapturedStatusChanged() 1097 1129 { 1130 #ifndef Q_WS_WIN32 1098 1131 if (!uisession()->isMouseCaptured()) 1099 1132 { 1100 /* We will just release mouse if it was released in other than that window: */ 1101 #ifndef Q_WS_WIN32 1133 /* Releasing grabbed mouse from that window: */ 1102 1134 viewport()->releaseMouse(); 1103 #endif 1104 /* Also we will unset cursor if mouse was released in other than that window: */ 1105 viewport()->unsetCursor(); 1106 } 1135 } 1136 #endif 1137 1138 #ifdef Q_WS_WIN32 1139 /* Update mouse clipping: */ 1140 updateMouseCursorClipping(); 1141 #endif 1142 1143 /* Update mouse cursor shape: */ 1144 updateMouseCursorShape(); 1107 1145 } 1108 1146 … … 1199 1237 if (uisession()->isRunning() && m_bIsKeyboardCaptured) 1200 1238 { 1201 captureKbd 1239 captureKbd(false); 1202 1240 if (!(uisession()->isMouseSupportsAbsolute() && uisession()->isMouseIntegrated())) 1203 captureMouse 1241 captureMouse(false); 1204 1242 } 1205 1243 … … 1316 1354 qApp->processEvents(); 1317 1355 #endif 1318 captureMouse 1356 captureMouse(m_bIsKeyboardCaptured); 1319 1357 } 1320 1358 } … … 1474 1512 */ 1475 1513 QRect rect = viewport()->visibleRegion().boundingRect(); 1476 QPoint pw = viewport()->mapToGlobal 1477 rect.translate 1478 1479 QRect dpRect = QApplication::desktop()->screenGeometry 1514 QPoint pw = viewport()->mapToGlobal(viewport()->pos()); 1515 rect.translate(pw.x(), pw.y()); 1516 1517 QRect dpRect = QApplication::desktop()->screenGeometry(viewport()); 1480 1518 if (rect.intersects (dpRect)) 1481 rect = rect.intersect 1519 rect = rect.intersect(dpRect); 1482 1520 1483 1521 int wsafe = rect.width() / 6; 1484 rect.setWidth 1485 rect.setLeft 1522 rect.setWidth(rect.width() - wsafe * 2); 1523 rect.setLeft(rect.left() + wsafe); 1486 1524 1487 1525 int hsafe = rect.height() / 6; 1488 rect.setWidth 1489 rect.setTop 1490 1491 if (rect.contains 1526 rect.setWidth(rect.height() - hsafe * 2); 1527 rect.setTop(rect.top() + hsafe); 1528 1529 if (rect.contains(aGlobalPos, true)) 1492 1530 m_lastMousePos = aGlobalPos; 1493 1531 else 1494 1532 { 1495 1533 m_lastMousePos = rect.center(); 1496 QCursor::setPos 1534 QCursor::setPos(m_lastMousePos); 1497 1535 } 1498 1536 #else /* !Q_WS_MAC */ … … 1506 1544 QPoint p = aPos; 1507 1545 if (aPos.x() == 0) 1508 p.setX 1546 p.setX(we - 1); 1509 1547 else if (aPos.x() == we) 1510 p.setX 1548 p.setX(1); 1511 1549 if (aPos.y() == 0 ) 1512 p.setY 1550 p.setY(he - 1); 1513 1551 else if (aPos.y() == he) 1514 p.setY 1552 p.setY(1); 1515 1553 1516 1554 if (p != aPos) 1517 1555 { 1518 1556 m_lastMousePos = viewport()->mapToGlobal (p); 1519 QCursor::setPos 1557 QCursor::setPos(m_lastMousePos); 1520 1558 } 1521 1559 else … … 1539 1577 { 1540 1578 m_lastMousePos = p; 1541 QCursor::setPos 1579 QCursor::setPos(m_lastMousePos); 1542 1580 } 1543 1581 else … … 2383 2421 void UIMachineView::captureMouse(bool fCapture, bool fEmitSignal /* = true */) 2384 2422 { 2423 /* Do not change anything if its already so: */ 2385 2424 if (uisession()->isMouseCaptured() == fCapture) 2386 2425 return; … … 2391 2430 m_capturedMousePos = QCursor::pos(); 2392 2431 #ifdef Q_WS_WIN32 2393 viewport()->setCursor(QCursor(Qt::BlankCursor));2394 2432 /* Move the mouse to the center of the visible area: */ 2395 QCursor::setPos(mapToGlobal(visibleRegion().boundingRect().center()));2396 m_lastMousePos = QCursor::pos();2433 m_lastMousePos = mapToGlobal(visibleRegion().boundingRect().center()); 2434 QCursor::setPos(m_lastMousePos); 2397 2435 #elif defined (Q_WS_MAC) 2398 2436 /* Move the mouse to the center of the visible area: */ 2399 m_lastMousePos = mapToGlobal 2437 m_lastMousePos = mapToGlobal(visibleRegion().boundingRect().center()); 2400 2438 QCursor::setPos(m_lastMousePos); 2401 2439 /* Grab all mouse events: */ 2402 2440 viewport()->grabMouse(); 2403 2441 #else 2442 /* Grab all mouse events: */ 2404 2443 viewport()->grabMouse(); 2405 2444 m_lastMousePos = QCursor::pos(); … … 2408 2447 else 2409 2448 { 2410 #ifndef Q_WS_WIN32 2411 viewport()->releaseMouse(); 2412 #endif 2413 /* Release mouse buttons: */ 2414 CMouse mouse = session().GetConsole().GetMouse(); 2415 mouse.PutMouseEvent(0, 0, 0, 0, 0); 2416 } 2417 2449 /* Return the cursor to where it was when we captured it: */ 2450 QCursor::setPos(m_capturedMousePos); 2451 } 2452 2453 /* Updating guest mouse: */ 2454 CMouse mouse = session().GetConsole().GetMouse(); 2455 mouse.PutMouseEvent(0, 0, 0, 0, 0); 2456 2457 /* Storing new mouse 'captured' value: */ 2418 2458 uisession()->setMouseCaptured(fCapture); 2419 2459 2420 updateMouseClipping(); 2421 2460 /* Emit signal if required: */ 2422 2461 if (fEmitSignal) 2423 2462 emitMouseStateChanged(); -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
r27215 r27227 110 110 bool isHostKeyPressed() const { return m_bIsHostkeyPressed; } 111 111 bool isMachineWindowResizeIgnored() const { return m_bIsMachineWindowResizeIgnored; } 112 bool isFrameBufferResizeIgnored() const { return m_bIsFrameBufferResizeIgnored; }113 112 const QPixmap& pauseShot() const { return m_pauseShot; } 114 113 QSize storedConsoleSize() const { return m_storedConsoleSize; } … … 119 118 void storeConsoleSize(int iWidth, int iHeight); 120 119 void setMachineWindowResizeIgnored(bool fIgnore = true) { m_bIsMachineWindowResizeIgnored = fIgnore; } 121 void setFrameBufferResizeIgnored(bool fIgnore = true) { m_bIsFrameBufferResizeIgnored = fIgnore; }122 120 123 121 /* Protected helpers: */ 124 122 void calculateDesktopGeometry(); 125 void updateMouseClipping(); 123 void updateMouseCursorShape(); 124 #ifdef Q_WS_WIN32 125 void updateMouseCursorClipping(); 126 #endif 126 127 void updateSliders(); 127 128 … … 237 238 bool m_bIsHostkeyInCapture : 1; 238 239 bool m_bIsMachineWindowResizeIgnored : 1; 239 bool m_bIsFrameBufferResizeIgnored : 1;240 240 bool m_fPassCAD; 241 241 #ifdef VBOX_WITH_VIDEOHWACCEL -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
r27218 r27227 555 555 , m_fIsMouseIntegrated(true) 556 556 , m_fIsValidPointerShapePresent(false) 557 , m_fIsHid eHostPointer(true)557 , m_fIsHidingHostPointer(true) 558 558 { 559 559 /* Register console callback: */ … … 667 667 { 668 668 /* We are ignoring visibility flag: */ 669 m_fIsHid eHostPointer = false;669 m_fIsHidingHostPointer = false; 670 670 671 671 /* And updating current cursor shape: */ … … 678 678 { 679 679 /* Remember if we should hide the cursor: */ 680 m_fIsHid eHostPointer = !pConsoleEvent->isVisible();680 m_fIsHidingHostPointer = !pConsoleEvent->isVisible(); 681 681 } 682 682 -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
r27178 r27227 118 118 bool isMouseIntegrated() const { return m_fIsMouseIntegrated; } 119 119 bool isValidPointerShapePresent() const { return m_fIsValidPointerShapePresent; } 120 bool isHidingHostPointer() const { return m_fIs MouseCaptured || (m_fIsMouseSupportsAbsolute && m_fIsHideHostPointer); }120 bool isHidingHostPointer() const { return m_fIsHidingHostPointer; } 121 121 122 122 /* Common setters: */ … … 224 224 bool m_fIsMouseIntegrated : 1; 225 225 bool m_fIsValidPointerShapePresent : 1; 226 bool m_fIsHid eHostPointer : 1;226 bool m_fIsHidingHostPointer : 1; 227 227 228 228 /* Friend classes: */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineViewFullscreen.cpp
r27154 r27227 189 189 #endif /* Q_WS_MAC */ 190 190 191 /* Unfortunately restoreOverrideCursor() is broken in Qt 4.4.0 if WA_PaintOnScreen widgets are present. 192 * This is the case on linux with SDL. As workaround we save/restore the arrow cursor manually. 193 * See http://trolltech.com/developer/task-tracker/index_html?id=206165&method=entry for details. 194 * Moreover the current cursor, which could be set by the guest, should be restored after resize: */ 195 if (uisession()->isValidPointerShapePresent()) 196 viewport()->setCursor(uisession()->cursor()); 197 else if (uisession()->isHidingHostPointer()) 198 viewport()->setCursor(Qt::BlankCursor); 199 /* This event appears in case of guest video was changed for somehow even without video resolution change. 200 * In this last case the host VM window will not be resized according this event and the host mouse cursor 201 * which was unset to default here will not be hidden in capture state. So it is necessary to perform 202 * updateMouseClipping() for the guest resize event if the mouse cursor was captured: */ 203 if (uisession()->isMouseCaptured()) 204 updateMouseClipping(); 191 /* Update mouse cursor shape: */ 192 updateMouseCursorShape(); 193 #ifdef Q_WS_WIN32 194 updateMouseCursorClipping(); 195 #endif 205 196 206 197 /* May be we have to restrict minimum size? */ -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp
r27124 r27227 144 144 case VBoxDefs::ResizeEventType: 145 145 { 146 /* Some situations require initial VGA Resize Request 147 * to be ignored at all, leaving previous framebuffer, 148 * machine view and machine window sizes preserved: */ 146 /* Some situations require framebuffer resize events to be ignored, 147 * leaving machine window & machine view & framebuffer sizes preserved: */ 149 148 if (uisession()->isGuestResizeIgnored()) 150 149 return true; 151 150 151 /* We are starting to perform machine view resize: */ 152 152 bool oldIgnoreMainwndResize = isMachineWindowResizeIgnored(); 153 153 setMachineWindowResizeIgnored(true); 154 154 155 /* Get guest resize-event: */ 155 156 UIResizeEvent *pResizeEvent = static_cast<UIResizeEvent*>(pEvent); 157 158 /* Perform framebuffer resize: */ 159 frameBuffer()->resizeEvent(pResizeEvent); 160 161 /* Reapply maximum size restriction for machine view: */ 162 setMaximumSize(sizeHint()); 156 163 157 164 /* Store the new size to prevent unwanted resize hints being sent back. */ 158 165 storeConsoleSize(pResizeEvent->width(), pResizeEvent->height()); 159 166 160 /* Unfortunately restoreOverrideCursor() is broken in Qt 4.4.0 if WA_PaintOnScreen widgets are present.161 * This is the case on linux with SDL. As workaround we save/restore the arrow cursor manually.162 * See http://trolltech.com/developer/task-tracker/index_html?id=206165&method=entry for details.163 * Moreover the current cursor, which could be set by the guest, should be restored after resize: */164 QCursor cursor;165 if (uisession()->isHidingHostPointer())166 cursor = QCursor(Qt::BlankCursor);167 else168 cursor = viewport()->cursor();169 frameBuffer()->resizeEvent(pResizeEvent);170 viewport()->setCursor(cursor);171 172 #ifdef Q_WS_MAC173 // TODO_NEW_CORE174 // mDockIconPreview->setOriginalSize(pResizeEvent->width(), pResizeEvent->height());175 #endif /* Q_WS_MAC */176 177 /* This event appears in case of guest video was changed for somehow even without video resolution change.178 * In this last case the host VM window will not be resized according this event and the host mouse cursor179 * which was unset to default here will not be hidden in capture state. So it is necessary to perform180 * updateMouseClipping() for the guest resize event if the mouse cursor was captured: */181 if (uisession()->isMouseCaptured())182 updateMouseClipping();183 184 /* Apply maximum size restriction: */185 setMaximumSize(sizeHint());186 187 /* May be we have to restrict minimum size? */188 maybeRestrictMinimumSize();189 190 167 /* Resize the guest canvas: */ 191 if (!isFrameBufferResizeIgnored()) 192 resize(pResizeEvent->width(), pResizeEvent->height()); 193 updateSliders(); 168 resize(pResizeEvent->width(), pResizeEvent->height()); 194 169 195 170 /* Let our toplevel widget calculate its sizeHint properly. */ … … 203 178 #endif /* Q_WS_X11 */ 204 179 205 if (!isFrameBufferResizeIgnored()) 206 normalizeGeometry(true /* adjustPosition */); 180 #ifdef Q_WS_MAC 181 // TODO_NEW_CORE 182 // mDockIconPreview->setOriginalSize(pResizeEvent->width(), pResizeEvent->height()); 183 #endif /* Q_WS_MAC */ 184 185 /* Update mouse cursor shape: */ 186 updateMouseCursorShape(); 187 #ifdef Q_WS_WIN32 188 updateMouseCursorClipping(); 189 #endif 190 191 /* May be we have to restrict minimum size? */ 192 maybeRestrictMinimumSize(); 193 194 /* Update machine view sliders: */ 195 updateSliders(); 196 197 /* Normalize geometry: */ 198 normalizeGeometry(true /* adjustPosition */); 207 199 208 200 /* Report to the VM thread that we finished resizing */ 209 201 session().GetConsole().GetDisplay().ResizeCompleted(screenId()); 210 202 203 /* We are finishing to perform machine view resize: */ 211 204 setMachineWindowResizeIgnored(oldIgnoreMainwndResize); 212 205 213 206 /* Make sure that all posted signals are processed: */ 214 207 qApp->processEvents(); 215 216 /* Emit a signal about guest was resized: */217 emit resizeHintDone();218 208 219 209 /* We also recalculate the desktop geometry if this is determined … … 222 212 calculateDesktopGeometry(); 223 213 224 /* Enable frame-buffer resize watching: */ 225 if (isFrameBufferResizeIgnored()) 226 setFrameBufferResizeIgnored(false); 214 /* Emit a signal about guest was resized: */ 215 emit resizeHintDone(); 227 216 228 217 return true; -
trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineViewSeamless.cpp
r27150 r27227 188 188 #endif /* Q_WS_MAC */ 189 189 190 /* Unfortunately restoreOverrideCursor() is broken in Qt 4.4.0 if WA_PaintOnScreen widgets are present. 191 * This is the case on linux with SDL. As workaround we save/restore the arrow cursor manually. 192 * See http://trolltech.com/developer/task-tracker/index_html?id=206165&method=entry for details. 193 * Moreover the current cursor, which could be set by the guest, should be restored after resize: */ 194 if (uisession()->isValidPointerShapePresent()) 195 viewport()->setCursor(uisession()->cursor()); 196 else if (uisession()->isHidingHostPointer()) 197 viewport()->setCursor(Qt::BlankCursor); 198 /* This event appears in case of guest video was changed for somehow even without video resolution change. 199 * In this last case the host VM window will not be resized according this event and the host mouse cursor 200 * which was unset to default here will not be hidden in capture state. So it is necessary to perform 201 * updateMouseClipping() for the guest resize event if the mouse cursor was captured: */ 202 if (uisession()->isMouseCaptured()) 203 updateMouseClipping(); 190 /* Update mouse cursor shape: */ 191 updateMouseCursorShape(); 192 #ifdef Q_WS_WIN32 193 updateMouseCursorClipping(); 194 #endif 204 195 205 196 /* Report to the VM thread that we finished resizing: */
Note:
See TracChangeset
for help on using the changeset viewer.