[13607] | 1 | /* $Id: MouseImpl.cpp 105006 2024-06-24 17:43:00Z vboxsync $ */
|
---|
[1] | 2 | /** @file
|
---|
| 3 | * VirtualBox COM class implementation
|
---|
| 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2006-2023 Oracle and/or its affiliates.
|
---|
[1] | 8 | *
|
---|
[96407] | 9 | * This file is part of VirtualBox base platform packages, as
|
---|
| 10 | * available from https://www.virtualbox.org.
|
---|
| 11 | *
|
---|
| 12 | * This program is free software; you can redistribute it and/or
|
---|
| 13 | * modify it under the terms of the GNU General Public License
|
---|
| 14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
| 15 | * License.
|
---|
| 16 | *
|
---|
| 17 | * This program is distributed in the hope that it will be useful, but
|
---|
| 18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
| 20 | * General Public License for more details.
|
---|
| 21 | *
|
---|
| 22 | * You should have received a copy of the GNU General Public License
|
---|
| 23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
| 24 | *
|
---|
| 25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
[1] | 26 | */
|
---|
| 27 |
|
---|
[67914] | 28 | #define LOG_GROUP LOG_GROUP_MAIN_MOUSE
|
---|
| 29 | #include "LoggingNew.h"
|
---|
| 30 |
|
---|
[30681] | 31 | #include <iprt/cpp/utils.h>
|
---|
| 32 |
|
---|
[1] | 33 | #include "MouseImpl.h"
|
---|
| 34 | #include "DisplayImpl.h"
|
---|
| 35 | #include "VMMDev.h"
|
---|
[52921] | 36 | #include "MousePointerShapeWrap.h"
|
---|
[85286] | 37 | #include "VBoxEvents.h"
|
---|
[1] | 38 |
|
---|
[35346] | 39 | #include <VBox/vmm/pdmdrv.h>
|
---|
[33758] | 40 | #include <VBox/VMMDev.h>
|
---|
[76760] | 41 | #include <VBox/err.h>
|
---|
[30681] | 42 |
|
---|
| 43 |
|
---|
[52921] | 44 | class ATL_NO_VTABLE MousePointerShape:
|
---|
| 45 | public MousePointerShapeWrap
|
---|
| 46 | {
|
---|
| 47 | public:
|
---|
| 48 |
|
---|
[90828] | 49 | DECLARE_COMMON_CLASS_METHODS(MousePointerShape)
|
---|
[52921] | 50 |
|
---|
| 51 | HRESULT FinalConstruct();
|
---|
| 52 | void FinalRelease();
|
---|
| 53 |
|
---|
| 54 | /* Public initializer/uninitializer for internal purposes only. */
|
---|
| 55 | HRESULT init(ComObjPtr<Mouse> pMouse,
|
---|
| 56 | bool fVisible, bool fAlpha,
|
---|
| 57 | uint32_t hotX, uint32_t hotY,
|
---|
| 58 | uint32_t width, uint32_t height,
|
---|
| 59 | const uint8_t *pu8Shape, uint32_t cbShape);
|
---|
| 60 | void uninit();
|
---|
| 61 |
|
---|
| 62 | private:
|
---|
| 63 | // wrapped IMousePointerShape properties
|
---|
| 64 | virtual HRESULT getVisible(BOOL *aVisible);
|
---|
| 65 | virtual HRESULT getAlpha(BOOL *aAlpha);
|
---|
| 66 | virtual HRESULT getHotX(ULONG *aHotX);
|
---|
| 67 | virtual HRESULT getHotY(ULONG *aHotY);
|
---|
| 68 | virtual HRESULT getWidth(ULONG *aWidth);
|
---|
| 69 | virtual HRESULT getHeight(ULONG *aHeight);
|
---|
| 70 | virtual HRESULT getShape(std::vector<BYTE> &aShape);
|
---|
| 71 |
|
---|
| 72 | struct Data
|
---|
| 73 | {
|
---|
| 74 | ComObjPtr<Mouse> pMouse;
|
---|
| 75 | bool fVisible;
|
---|
| 76 | bool fAlpha;
|
---|
| 77 | uint32_t hotX;
|
---|
| 78 | uint32_t hotY;
|
---|
| 79 | uint32_t width;
|
---|
| 80 | uint32_t height;
|
---|
| 81 | std::vector<BYTE> shape;
|
---|
| 82 | };
|
---|
| 83 |
|
---|
| 84 | Data m;
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | /*
|
---|
| 88 | * MousePointerShape implementation.
|
---|
| 89 | */
|
---|
| 90 | DEFINE_EMPTY_CTOR_DTOR(MousePointerShape)
|
---|
| 91 |
|
---|
| 92 | HRESULT MousePointerShape::FinalConstruct()
|
---|
| 93 | {
|
---|
| 94 | return BaseFinalConstruct();
|
---|
| 95 | }
|
---|
| 96 |
|
---|
| 97 | void MousePointerShape::FinalRelease()
|
---|
| 98 | {
|
---|
| 99 | uninit();
|
---|
| 100 |
|
---|
| 101 | BaseFinalRelease();
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | HRESULT MousePointerShape::init(ComObjPtr<Mouse> pMouse,
|
---|
| 105 | bool fVisible, bool fAlpha,
|
---|
| 106 | uint32_t hotX, uint32_t hotY,
|
---|
| 107 | uint32_t width, uint32_t height,
|
---|
| 108 | const uint8_t *pu8Shape, uint32_t cbShape)
|
---|
| 109 | {
|
---|
| 110 | LogFlowThisFunc(("v %d, a %d, h %d,%d, %dx%d, cb %d\n",
|
---|
| 111 | fVisible, fAlpha, hotX, hotY, width, height, cbShape));
|
---|
| 112 |
|
---|
| 113 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
| 114 | AutoInitSpan autoInitSpan(this);
|
---|
| 115 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
| 116 |
|
---|
| 117 | m.pMouse = pMouse;
|
---|
| 118 | m.fVisible = fVisible;
|
---|
| 119 | m.fAlpha = fAlpha;
|
---|
| 120 | m.hotX = hotX;
|
---|
| 121 | m.hotY = hotY;
|
---|
| 122 | m.width = width;
|
---|
| 123 | m.height = height;
|
---|
| 124 | m.shape.resize(cbShape);
|
---|
| 125 | if (cbShape)
|
---|
| 126 | {
|
---|
| 127 | memcpy(&m.shape.front(), pu8Shape, cbShape);
|
---|
| 128 | }
|
---|
| 129 |
|
---|
| 130 | /* Confirm a successful initialization */
|
---|
| 131 | autoInitSpan.setSucceeded();
|
---|
| 132 |
|
---|
| 133 | return S_OK;
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void MousePointerShape::uninit()
|
---|
| 137 | {
|
---|
| 138 | LogFlowThisFunc(("\n"));
|
---|
| 139 |
|
---|
| 140 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
| 141 | AutoUninitSpan autoUninitSpan(this);
|
---|
| 142 | if (autoUninitSpan.uninitDone())
|
---|
| 143 | return;
|
---|
| 144 |
|
---|
| 145 | m.pMouse.setNull();
|
---|
| 146 | }
|
---|
| 147 |
|
---|
| 148 | HRESULT MousePointerShape::getVisible(BOOL *aVisible)
|
---|
| 149 | {
|
---|
| 150 | *aVisible = m.fVisible;
|
---|
| 151 | return S_OK;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 | HRESULT MousePointerShape::getAlpha(BOOL *aAlpha)
|
---|
| 155 | {
|
---|
| 156 | *aAlpha = m.fAlpha;
|
---|
| 157 | return S_OK;
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | HRESULT MousePointerShape::getHotX(ULONG *aHotX)
|
---|
| 161 | {
|
---|
| 162 | *aHotX = m.hotX;
|
---|
| 163 | return S_OK;
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | HRESULT MousePointerShape::getHotY(ULONG *aHotY)
|
---|
| 167 | {
|
---|
| 168 | *aHotY = m.hotY;
|
---|
| 169 | return S_OK;
|
---|
| 170 | }
|
---|
| 171 |
|
---|
| 172 | HRESULT MousePointerShape::getWidth(ULONG *aWidth)
|
---|
| 173 | {
|
---|
| 174 | *aWidth = m.width;
|
---|
| 175 | return S_OK;
|
---|
| 176 | }
|
---|
| 177 |
|
---|
| 178 | HRESULT MousePointerShape::getHeight(ULONG *aHeight)
|
---|
| 179 | {
|
---|
| 180 | *aHeight = m.height;
|
---|
| 181 | return S_OK;
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | HRESULT MousePointerShape::getShape(std::vector<BYTE> &aShape)
|
---|
| 185 | {
|
---|
| 186 | aShape.resize(m.shape.size());
|
---|
[59858] | 187 | if (m.shape.size())
|
---|
| 188 | memcpy(&aShape.front(), &m.shape.front(), aShape.size());
|
---|
[52921] | 189 | return S_OK;
|
---|
| 190 | }
|
---|
| 191 |
|
---|
| 192 |
|
---|
[27060] | 193 | /** @name Mouse device capabilities bitfield
|
---|
| 194 | * @{ */
|
---|
| 195 | enum
|
---|
| 196 | {
|
---|
| 197 | /** The mouse device can do relative reporting */
|
---|
| 198 | MOUSE_DEVCAP_RELATIVE = 1,
|
---|
| 199 | /** The mouse device can do absolute reporting */
|
---|
[47174] | 200 | MOUSE_DEVCAP_ABSOLUTE = 2,
|
---|
[95271] | 201 | /** The mouse device can do absolute multi-touch reporting */
|
---|
| 202 | MOUSE_DEVCAP_MT_ABSOLUTE = 4,
|
---|
| 203 | /** The mouse device can do relative multi-touch reporting */
|
---|
| 204 | MOUSE_DEVCAP_MT_RELATIVE = 8,
|
---|
[27060] | 205 | };
|
---|
| 206 | /** @} */
|
---|
| 207 |
|
---|
[36161] | 208 |
|
---|
[1] | 209 | /**
|
---|
| 210 | * Mouse driver instance data.
|
---|
| 211 | */
|
---|
[27060] | 212 | struct DRVMAINMOUSE
|
---|
[1] | 213 | {
|
---|
| 214 | /** Pointer to the mouse object. */
|
---|
| 215 | Mouse *pMouse;
|
---|
| 216 | /** Pointer to the driver instance structure. */
|
---|
| 217 | PPDMDRVINS pDrvIns;
|
---|
| 218 | /** Pointer to the mouse port interface of the driver/device above us. */
|
---|
| 219 | PPDMIMOUSEPORT pUpPort;
|
---|
| 220 | /** Our mouse connector interface. */
|
---|
[25985] | 221 | PDMIMOUSECONNECTOR IConnector;
|
---|
[27060] | 222 | /** The capabilities of this device. */
|
---|
| 223 | uint32_t u32DevCaps;
|
---|
| 224 | };
|
---|
[1] | 225 |
|
---|
[30764] | 226 |
|
---|
[1] | 227 | // constructor / destructor
|
---|
| 228 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 229 |
|
---|
[27607] | 230 | Mouse::Mouse()
|
---|
| 231 | : mParent(NULL)
|
---|
| 232 | {
|
---|
| 233 | }
|
---|
[13606] | 234 |
|
---|
[27607] | 235 | Mouse::~Mouse()
|
---|
| 236 | {
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 |
|
---|
[1] | 240 | HRESULT Mouse::FinalConstruct()
|
---|
| 241 | {
|
---|
[27060] | 242 | RT_ZERO(mpDrv);
|
---|
[52921] | 243 | RT_ZERO(mPointerData);
|
---|
[47208] | 244 | mcLastX = 0x8000;
|
---|
| 245 | mcLastY = 0x8000;
|
---|
[33758] | 246 | mfLastButtons = 0;
|
---|
[33779] | 247 | mfVMMDevGuestCaps = 0;
|
---|
[35638] | 248 | return BaseFinalConstruct();
|
---|
[1] | 249 | }
|
---|
| 250 |
|
---|
| 251 | void Mouse::FinalRelease()
|
---|
| 252 | {
|
---|
[13606] | 253 | uninit();
|
---|
[35638] | 254 | BaseFinalRelease();
|
---|
[1] | 255 | }
|
---|
| 256 |
|
---|
| 257 | // public methods only for internal purposes
|
---|
| 258 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 259 |
|
---|
| 260 | /**
|
---|
| 261 | * Initializes the mouse object.
|
---|
| 262 | *
|
---|
| 263 | * @returns COM result indicator
|
---|
| 264 | * @param parent handle of our parent object
|
---|
| 265 | */
|
---|
[47190] | 266 | HRESULT Mouse::init (ConsoleMouseInterface *parent)
|
---|
[1] | 267 | {
|
---|
[21878] | 268 | LogFlowThisFunc(("\n"));
|
---|
[1] | 269 |
|
---|
[26235] | 270 | ComAssertRet(parent, E_INVALIDARG);
|
---|
[1] | 271 |
|
---|
[13606] | 272 | /* Enclose the state transition NotReady->InInit->Ready */
|
---|
[21878] | 273 | AutoInitSpan autoInitSpan(this);
|
---|
| 274 | AssertReturn(autoInitSpan.isOk(), E_FAIL);
|
---|
[1] | 275 |
|
---|
[13606] | 276 | unconst(mParent) = parent;
|
---|
[1] | 277 |
|
---|
[33061] | 278 | unconst(mEventSource).createObject();
|
---|
[94924] | 279 | HRESULT hrc = mEventSource->init();
|
---|
| 280 | AssertComRCReturnRC(hrc);
|
---|
[33061] | 281 |
|
---|
[85286] | 282 | ComPtr<IEvent> ptrEvent;
|
---|
[94924] | 283 | hrc = ::CreateGuestMouseEvent(ptrEvent.asOutParam(), mEventSource,
|
---|
| 284 | (GuestMouseEventMode_T)0, 0 /*x*/, 0 /*y*/, 0 /*z*/, 0 /*w*/, 0 /*buttons*/);
|
---|
| 285 | AssertComRCReturnRC(hrc);
|
---|
[85286] | 286 | mMouseEvent.init(ptrEvent, mEventSource);
|
---|
| 287 |
|
---|
[13606] | 288 | /* Confirm a successful initialization */
|
---|
| 289 | autoInitSpan.setSucceeded();
|
---|
| 290 |
|
---|
[1] | 291 | return S_OK;
|
---|
| 292 | }
|
---|
| 293 |
|
---|
| 294 | /**
|
---|
| 295 | * Uninitializes the instance and sets the ready flag to FALSE.
|
---|
| 296 | * Called either from FinalRelease() or by the parent when it gets destroyed.
|
---|
| 297 | */
|
---|
| 298 | void Mouse::uninit()
|
---|
| 299 | {
|
---|
[21878] | 300 | LogFlowThisFunc(("\n"));
|
---|
[1] | 301 |
|
---|
[13606] | 302 | /* Enclose the state transition Ready->InUninit->NotReady */
|
---|
[21878] | 303 | AutoUninitSpan autoUninitSpan(this);
|
---|
[13606] | 304 | if (autoUninitSpan.uninitDone())
|
---|
| 305 | return;
|
---|
[1] | 306 |
|
---|
[27060] | 307 | for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
|
---|
| 308 | {
|
---|
| 309 | if (mpDrv[i])
|
---|
| 310 | mpDrv[i]->pMouse = NULL;
|
---|
| 311 | mpDrv[i] = NULL;
|
---|
| 312 | }
|
---|
[1] | 313 |
|
---|
[52921] | 314 | mPointerShape.setNull();
|
---|
| 315 |
|
---|
| 316 | RTMemFree(mPointerData.pu8Shape);
|
---|
| 317 | mPointerData.pu8Shape = NULL;
|
---|
| 318 | mPointerData.cbShape = 0;
|
---|
| 319 |
|
---|
[33061] | 320 | mMouseEvent.uninit();
|
---|
| 321 | unconst(mEventSource).setNull();
|
---|
[27607] | 322 | unconst(mParent) = NULL;
|
---|
[1] | 323 | }
|
---|
| 324 |
|
---|
[105006] | 325 | /**
|
---|
| 326 | * Updates the pointer shape data.
|
---|
| 327 | *
|
---|
| 328 | * @returns VBox status code.
|
---|
| 329 | * @param fVisible Whether the mouse cursor actually is visible or not.
|
---|
| 330 | * @param fAlpha Whether the pixel data contains an alpha mask or not.
|
---|
| 331 | * @param uHotX X hot position (in pixel) of the new cursor.
|
---|
| 332 | * @param uHotY Y hot position (in pixel) of the new cursor.
|
---|
| 333 | * @param uWidth Width (in pixel) of the new cursor.
|
---|
| 334 | * @param uHeight Height (in pixel) of the new cursor.
|
---|
| 335 | * @param pu8Shape Pixel data of the new cursor.
|
---|
| 336 | * @param cbShape Size of \a pu8Shape (in bytes).
|
---|
| 337 | *
|
---|
| 338 | * @note Takes the write lock.
|
---|
| 339 | */
|
---|
| 340 | int Mouse::i_updatePointerShape(bool fVisible, bool fAlpha,
|
---|
| 341 | uint32_t uHotX, uint32_t uHotY,
|
---|
| 342 | uint32_t uWidth, uint32_t uHeight,
|
---|
| 343 | const uint8_t *pu8Shape, uint32_t cbShape)
|
---|
[52921] | 344 | {
|
---|
| 345 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[26624] | 346 |
|
---|
[105006] | 347 | mPointerData.Destroy(); /* Destroy old data first. */
|
---|
[52921] | 348 |
|
---|
[105006] | 349 | int vrc = mPointerData.Init(fVisible, fAlpha, uHotX, uHotY, uWidth, uHeight, pu8Shape, cbShape);
|
---|
| 350 | if (RT_SUCCESS(vrc))
|
---|
[52921] | 351 | {
|
---|
[105006] | 352 | mPointerShape.setNull();
|
---|
[52921] | 353 | }
|
---|
| 354 |
|
---|
[105006] | 355 | return vrc;
|
---|
[52921] | 356 | }
|
---|
| 357 |
|
---|
[1] | 358 | // IMouse properties
|
---|
| 359 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 360 |
|
---|
[32828] | 361 | /** Report the front-end's mouse handling capabilities to the VMM device and
|
---|
| 362 | * thus to the guest.
|
---|
| 363 | * @note all calls out of this object are made with no locks held! */
|
---|
[50613] | 364 | HRESULT Mouse::i_updateVMMDevMouseCaps(uint32_t fCapsAdded,
|
---|
| 365 | uint32_t fCapsRemoved)
|
---|
[26624] | 366 | {
|
---|
[51612] | 367 | VMMDevMouseInterface *pVMMDev = mParent->i_getVMMDevMouseInterface();
|
---|
[33758] | 368 | if (!pVMMDev)
|
---|
| 369 | return E_FAIL; /* No assertion, as the front-ends can send events
|
---|
| 370 | * at all sorts of inconvenient times. */
|
---|
[53965] | 371 | DisplayMouseInterface *pDisplay = mParent->i_getDisplayMouseInterface();
|
---|
| 372 | if (pDisplay == NULL)
|
---|
| 373 | return E_FAIL;
|
---|
[26624] | 374 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
[41131] | 375 | if (!pVMMDevPort)
|
---|
| 376 | return E_FAIL; /* same here */
|
---|
[26624] | 377 |
|
---|
[94924] | 378 | int vrc = pVMMDevPort->pfnUpdateMouseCapabilities(pVMMDevPort, fCapsAdded,
|
---|
| 379 | fCapsRemoved);
|
---|
| 380 | if (RT_FAILURE(vrc))
|
---|
[53965] | 381 | return E_FAIL;
|
---|
| 382 | return pDisplay->i_reportHostCursorCapabilities(fCapsAdded, fCapsRemoved);
|
---|
[26624] | 383 | }
|
---|
| 384 |
|
---|
[1] | 385 | /**
|
---|
[47174] | 386 | * Returns whether the currently active device portfolio can accept absolute
|
---|
| 387 | * mouse events.
|
---|
[1] | 388 | *
|
---|
| 389 | * @returns COM status code
|
---|
[65103] | 390 | * @param aAbsoluteSupported address of result variable
|
---|
[1] | 391 | */
|
---|
[50613] | 392 | HRESULT Mouse::getAbsoluteSupported(BOOL *aAbsoluteSupported)
|
---|
[1] | 393 | {
|
---|
[50613] | 394 | *aAbsoluteSupported = i_supportsAbs();
|
---|
[1] | 395 | return S_OK;
|
---|
| 396 | }
|
---|
| 397 |
|
---|
| 398 | /**
|
---|
[47174] | 399 | * Returns whether the currently active device portfolio can accept relative
|
---|
| 400 | * mouse events.
|
---|
[26782] | 401 | *
|
---|
| 402 | * @returns COM status code
|
---|
[65103] | 403 | * @param aRelativeSupported address of result variable
|
---|
[26782] | 404 | */
|
---|
[50613] | 405 | HRESULT Mouse::getRelativeSupported(BOOL *aRelativeSupported)
|
---|
[26782] | 406 | {
|
---|
[50613] | 407 | *aRelativeSupported = i_supportsRel();
|
---|
[26782] | 408 | return S_OK;
|
---|
| 409 | }
|
---|
| 410 |
|
---|
| 411 | /**
|
---|
[47174] | 412 | * Returns whether the currently active device portfolio can accept multi-touch
|
---|
[95368] | 413 | * touchscreen events.
|
---|
[47174] | 414 | *
|
---|
| 415 | * @returns COM status code
|
---|
[95368] | 416 | * @param aTouchScreenSupported address of result variable
|
---|
[47174] | 417 | */
|
---|
[95368] | 418 | HRESULT Mouse::getTouchScreenSupported(BOOL *aTouchScreenSupported)
|
---|
[47174] | 419 | {
|
---|
[95368] | 420 | *aTouchScreenSupported = i_supportsTS();
|
---|
[47174] | 421 | return S_OK;
|
---|
| 422 | }
|
---|
| 423 |
|
---|
| 424 | /**
|
---|
[95368] | 425 | * Returns whether the currently active device portfolio can accept multi-touch
|
---|
| 426 | * touchpad events.
|
---|
| 427 | *
|
---|
| 428 | * @returns COM status code
|
---|
| 429 | * @param aTouchPadSupported address of result variable
|
---|
| 430 | */
|
---|
| 431 | HRESULT Mouse::getTouchPadSupported(BOOL *aTouchPadSupported)
|
---|
| 432 | {
|
---|
| 433 | *aTouchPadSupported = i_supportsTP();
|
---|
| 434 | return S_OK;
|
---|
| 435 | }
|
---|
| 436 |
|
---|
| 437 | /**
|
---|
[32828] | 438 | * Returns whether the guest can currently switch to drawing the mouse cursor
|
---|
| 439 | * itself if it is asked to by the front-end.
|
---|
[1] | 440 | *
|
---|
| 441 | * @returns COM status code
|
---|
[65103] | 442 | * @param aNeedsHostCursor address of result variable
|
---|
[1] | 443 | */
|
---|
[50613] | 444 | HRESULT Mouse::getNeedsHostCursor(BOOL *aNeedsHostCursor)
|
---|
[1] | 445 | {
|
---|
[50613] | 446 | *aNeedsHostCursor = i_guestNeedsHostCursor();
|
---|
[1] | 447 | return S_OK;
|
---|
| 448 | }
|
---|
| 449 |
|
---|
[52921] | 450 | HRESULT Mouse::getPointerShape(ComPtr<IMousePointerShape> &aPointerShape)
|
---|
| 451 | {
|
---|
| 452 | HRESULT hr = S_OK;
|
---|
| 453 |
|
---|
| 454 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 455 |
|
---|
| 456 | if (mPointerShape.isNull())
|
---|
| 457 | {
|
---|
| 458 | ComObjPtr<MousePointerShape> obj;
|
---|
| 459 | hr = obj.createObject();
|
---|
| 460 | if (SUCCEEDED(hr))
|
---|
| 461 | {
|
---|
| 462 | hr = obj->init(this, mPointerData.fVisible, mPointerData.fAlpha,
|
---|
| 463 | mPointerData.hotX, mPointerData.hotY,
|
---|
| 464 | mPointerData.width, mPointerData.height,
|
---|
| 465 | mPointerData.pu8Shape, mPointerData.cbShape);
|
---|
| 466 | }
|
---|
| 467 |
|
---|
| 468 | if (SUCCEEDED(hr))
|
---|
| 469 | {
|
---|
| 470 | mPointerShape = obj;
|
---|
| 471 | }
|
---|
| 472 | }
|
---|
| 473 |
|
---|
| 474 | if (SUCCEEDED(hr))
|
---|
| 475 | {
|
---|
| 476 | aPointerShape = mPointerShape;
|
---|
| 477 | }
|
---|
| 478 |
|
---|
| 479 | return hr;
|
---|
| 480 | }
|
---|
| 481 |
|
---|
[1] | 482 | // IMouse methods
|
---|
| 483 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 484 |
|
---|
[32828] | 485 | /** Converts a bitfield containing information about mouse buttons currently
|
---|
| 486 | * held down from the format used by the front-end to the format used by PDM
|
---|
| 487 | * and the emulated pointing devices. */
|
---|
[50613] | 488 | static uint32_t i_mouseButtonsToPDM(LONG buttonState)
|
---|
[26624] | 489 | {
|
---|
| 490 | uint32_t fButtons = 0;
|
---|
| 491 | if (buttonState & MouseButtonState_LeftButton)
|
---|
| 492 | fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
|
---|
| 493 | if (buttonState & MouseButtonState_RightButton)
|
---|
| 494 | fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
|
---|
| 495 | if (buttonState & MouseButtonState_MiddleButton)
|
---|
| 496 | fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
|
---|
| 497 | if (buttonState & MouseButtonState_XButton1)
|
---|
| 498 | fButtons |= PDMIMOUSEPORT_BUTTON_X1;
|
---|
| 499 | if (buttonState & MouseButtonState_XButton2)
|
---|
| 500 | fButtons |= PDMIMOUSEPORT_BUTTON_X2;
|
---|
| 501 | return fButtons;
|
---|
| 502 | }
|
---|
| 503 |
|
---|
[50613] | 504 | HRESULT Mouse::getEventSource(ComPtr<IEventSource> &aEventSource)
|
---|
[33061] | 505 | {
|
---|
| 506 | // no need to lock - lifetime constant
|
---|
[50613] | 507 | mEventSource.queryInterfaceTo(aEventSource.asOutParam());
|
---|
[33061] | 508 | return S_OK;
|
---|
| 509 | }
|
---|
| 510 |
|
---|
[1] | 511 | /**
|
---|
[32828] | 512 | * Send a relative pointer event to the relative device we deem most
|
---|
| 513 | * appropriate.
|
---|
[26624] | 514 | *
|
---|
| 515 | * @returns COM status code
|
---|
| 516 | */
|
---|
[50613] | 517 | HRESULT Mouse::i_reportRelEventToMouseDev(int32_t dx, int32_t dy, int32_t dz,
|
---|
| 518 | int32_t dw, uint32_t fButtons)
|
---|
[26624] | 519 | {
|
---|
[33758] | 520 | if (dx || dy || dz || dw || fButtons != mfLastButtons)
|
---|
[26624] | 521 | {
|
---|
[27060] | 522 | PPDMIMOUSEPORT pUpPort = NULL;
|
---|
| 523 | {
|
---|
[32817] | 524 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 525 |
|
---|
| 526 | for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
|
---|
| 527 | {
|
---|
| 528 | if (mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_RELATIVE))
|
---|
| 529 | pUpPort = mpDrv[i]->pUpPort;
|
---|
| 530 | }
|
---|
[27060] | 531 | }
|
---|
| 532 | if (!pUpPort)
|
---|
[27129] | 533 | return S_OK;
|
---|
[27060] | 534 |
|
---|
[26624] | 535 | int vrc = pUpPort->pfnPutEvent(pUpPort, dx, dy, dz, dw, fButtons);
|
---|
| 536 |
|
---|
| 537 | if (RT_FAILURE(vrc))
|
---|
[73003] | 538 | return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
|
---|
| 539 | tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
|
---|
| 540 | vrc);
|
---|
[33758] | 541 | mfLastButtons = fButtons;
|
---|
[26624] | 542 | }
|
---|
| 543 | return S_OK;
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 |
|
---|
| 547 | /**
|
---|
[32828] | 548 | * Send an absolute pointer event to the emulated absolute device we deem most
|
---|
| 549 | * appropriate.
|
---|
[26624] | 550 | *
|
---|
| 551 | * @returns COM status code
|
---|
| 552 | */
|
---|
[50613] | 553 | HRESULT Mouse::i_reportAbsEventToMouseDev(int32_t x, int32_t y,
|
---|
| 554 | int32_t dz, int32_t dw, uint32_t fButtons)
|
---|
[26624] | 555 | {
|
---|
[47208] | 556 | if ( x < VMMDEV_MOUSE_RANGE_MIN
|
---|
| 557 | || x > VMMDEV_MOUSE_RANGE_MAX)
|
---|
[36161] | 558 | return S_OK;
|
---|
[47208] | 559 | if ( y < VMMDEV_MOUSE_RANGE_MIN
|
---|
| 560 | || y > VMMDEV_MOUSE_RANGE_MAX)
|
---|
[36161] | 561 | return S_OK;
|
---|
[47208] | 562 | if ( x != mcLastX || y != mcLastY
|
---|
[33758] | 563 | || dz || dw || fButtons != mfLastButtons)
|
---|
[26624] | 564 | {
|
---|
[27060] | 565 | PPDMIMOUSEPORT pUpPort = NULL;
|
---|
| 566 | {
|
---|
[32817] | 567 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 568 |
|
---|
| 569 | for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
|
---|
| 570 | {
|
---|
| 571 | if (mpDrv[i] && (mpDrv[i]->u32DevCaps & MOUSE_DEVCAP_ABSOLUTE))
|
---|
| 572 | pUpPort = mpDrv[i]->pUpPort;
|
---|
| 573 | }
|
---|
[27060] | 574 | }
|
---|
| 575 | if (!pUpPort)
|
---|
[27129] | 576 | return S_OK;
|
---|
[27060] | 577 |
|
---|
[47208] | 578 | int vrc = pUpPort->pfnPutEventAbs(pUpPort, x, y, dz,
|
---|
[27060] | 579 | dw, fButtons);
|
---|
[26624] | 580 | if (RT_FAILURE(vrc))
|
---|
[73003] | 581 | return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
|
---|
| 582 | tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
|
---|
| 583 | vrc);
|
---|
[33758] | 584 | mfLastButtons = fButtons;
|
---|
[33075] | 585 |
|
---|
[26624] | 586 | }
|
---|
| 587 | return S_OK;
|
---|
| 588 | }
|
---|
| 589 |
|
---|
[50613] | 590 | HRESULT Mouse::i_reportMultiTouchEventToDevice(uint8_t cContacts,
|
---|
| 591 | const uint64_t *pau64Contacts,
|
---|
[95368] | 592 | bool fTouchScreen,
|
---|
[50613] | 593 | uint32_t u32ScanTime)
|
---|
[47571] | 594 | {
|
---|
| 595 | HRESULT hrc = S_OK;
|
---|
[26624] | 596 |
|
---|
[95368] | 597 | int match = fTouchScreen ? MOUSE_DEVCAP_MT_ABSOLUTE : MOUSE_DEVCAP_MT_RELATIVE;
|
---|
[47208] | 598 | PPDMIMOUSEPORT pUpPort = NULL;
|
---|
| 599 | {
|
---|
| 600 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 601 |
|
---|
[47571] | 602 | unsigned i;
|
---|
| 603 | for (i = 0; i < MOUSE_MAX_DEVICES; ++i)
|
---|
[47208] | 604 | {
|
---|
| 605 | if ( mpDrv[i]
|
---|
[95368] | 606 | && (mpDrv[i]->u32DevCaps & match))
|
---|
[47571] | 607 | {
|
---|
[47208] | 608 | pUpPort = mpDrv[i]->pUpPort;
|
---|
[47571] | 609 | break;
|
---|
| 610 | }
|
---|
[47208] | 611 | }
|
---|
| 612 | }
|
---|
| 613 |
|
---|
[47571] | 614 | if (pUpPort)
|
---|
| 615 | {
|
---|
[95271] | 616 | int vrc = pUpPort->pfnPutEventTouchScreen(pUpPort, cContacts, pau64Contacts, u32ScanTime);
|
---|
[47571] | 617 | if (RT_FAILURE(vrc))
|
---|
[73003] | 618 | hrc = setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
|
---|
| 619 | tr("Could not send the multi-touch event to the virtual device (%Rrc)"),
|
---|
| 620 | vrc);
|
---|
[47571] | 621 | }
|
---|
| 622 | else
|
---|
| 623 | {
|
---|
| 624 | hrc = E_UNEXPECTED;
|
---|
| 625 | }
|
---|
| 626 |
|
---|
| 627 | return hrc;
|
---|
[47174] | 628 | }
|
---|
| 629 |
|
---|
| 630 |
|
---|
| 631 | /**
|
---|
[26624] | 632 | * Send an absolute position event to the VMM device.
|
---|
[32828] | 633 | * @note all calls out of this object are made with no locks held!
|
---|
[26624] | 634 | *
|
---|
| 635 | * @returns COM status code
|
---|
| 636 | */
|
---|
[97790] | 637 | HRESULT Mouse::i_reportAbsEventToVMMDev(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons)
|
---|
[26624] | 638 | {
|
---|
[51612] | 639 | VMMDevMouseInterface *pVMMDev = mParent->i_getVMMDevMouseInterface();
|
---|
[26624] | 640 | ComAssertRet(pVMMDev, E_FAIL);
|
---|
| 641 | PPDMIVMMDEVPORT pVMMDevPort = pVMMDev->getVMMDevPort();
|
---|
| 642 | ComAssertRet(pVMMDevPort, E_FAIL);
|
---|
| 643 |
|
---|
[97790] | 644 | if (x != mcLastX || y != mcLastY || dz || dw || fButtons != mfLastButtons)
|
---|
[26624] | 645 | {
|
---|
[97790] | 646 | int vrc = pVMMDevPort->pfnSetAbsoluteMouse(pVMMDevPort, x, y, dz, dw, fButtons);
|
---|
[26624] | 647 | if (RT_FAILURE(vrc))
|
---|
[73003] | 648 | return setErrorBoth(VBOX_E_IPRT_ERROR, vrc,
|
---|
| 649 | tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
|
---|
| 650 | vrc);
|
---|
[26624] | 651 | }
|
---|
| 652 | return S_OK;
|
---|
| 653 | }
|
---|
| 654 |
|
---|
[32828] | 655 |
|
---|
| 656 | /**
|
---|
| 657 | * Send an absolute pointer event to a pointing device (the VMM device if
|
---|
| 658 | * possible or whatever emulated absolute device seems best to us if not).
|
---|
| 659 | *
|
---|
| 660 | * @returns COM status code
|
---|
| 661 | */
|
---|
[53965] | 662 | HRESULT Mouse::i_reportAbsEventToInputDevices(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons,
|
---|
| 663 | bool fUsesVMMDevEvent)
|
---|
[32817] | 664 | {
|
---|
[97791] | 665 | HRESULT hrc = S_OK;
|
---|
[97558] | 666 | /** If we are using the VMMDev to report absolute position but without
|
---|
| 667 | * VMMDev IRQ support then we need to send a small "jiggle" to the emulated
|
---|
| 668 | * relative mouse device to alert the guest to changes. */
|
---|
| 669 | LONG cJiggle = 0;
|
---|
| 670 |
|
---|
[50613] | 671 | if (i_vmmdevCanAbs())
|
---|
[32817] | 672 | {
|
---|
[47841] | 673 | /*
|
---|
| 674 | * Send the absolute mouse position to the VMM device.
|
---|
| 675 | */
|
---|
[97790] | 676 | if (x != mcLastX || y != mcLastY || dz || dw || fButtons != mfLastButtons)
|
---|
[32817] | 677 | {
|
---|
[97790] | 678 | hrc = i_reportAbsEventToVMMDev(x, y, dz, dw, fButtons);
|
---|
[33261] | 679 | cJiggle = !fUsesVMMDevEvent;
|
---|
[32817] | 680 | }
|
---|
[97790] | 681 |
|
---|
| 682 | /* If guest cannot yet read full mouse state from DevVMM (i.e.,
|
---|
| 683 | * only 'x' and 'y' coordinates will be read) we need to pass buttons
|
---|
| 684 | * state as well as horizontal and vertical wheel movement over ever-present PS/2
|
---|
| 685 | * emulated mouse device. */
|
---|
| 686 | if (!(mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_USES_FULL_STATE_PROTOCOL))
|
---|
| 687 | hrc = i_reportRelEventToMouseDev(cJiggle, 0, dz, dw, fButtons);
|
---|
[32817] | 688 | }
|
---|
[47841] | 689 | else
|
---|
[94924] | 690 | hrc = i_reportAbsEventToMouseDev(x, y, dz, dw, fButtons);
|
---|
[32817] | 691 |
|
---|
[47208] | 692 | mcLastX = x;
|
---|
| 693 | mcLastY = y;
|
---|
[97790] | 694 | mfLastButtons = fButtons;
|
---|
[94924] | 695 | return hrc;
|
---|
[32817] | 696 | }
|
---|
| 697 |
|
---|
[53965] | 698 |
|
---|
| 699 | /**
|
---|
| 700 | * Send an absolute position event to the display device.
|
---|
| 701 | * @note all calls out of this object are made with no locks held!
|
---|
| 702 | * @param x Cursor X position in pixels relative to the first screen, where
|
---|
| 703 | * (1, 1) is the upper left corner.
|
---|
| 704 | * @param y Cursor Y position in pixels relative to the first screen, where
|
---|
| 705 | * (1, 1) is the upper left corner.
|
---|
| 706 | */
|
---|
| 707 | HRESULT Mouse::i_reportAbsEventToDisplayDevice(int32_t x, int32_t y)
|
---|
| 708 | {
|
---|
| 709 | DisplayMouseInterface *pDisplay = mParent->i_getDisplayMouseInterface();
|
---|
| 710 | ComAssertRet(pDisplay, E_FAIL);
|
---|
| 711 |
|
---|
[77485] | 712 | if (x != mcLastX || y != mcLastY)
|
---|
[53965] | 713 | {
|
---|
[77485] | 714 | pDisplay->i_reportHostCursorPosition(x - 1, y - 1, false);
|
---|
[53965] | 715 | }
|
---|
| 716 | return S_OK;
|
---|
| 717 | }
|
---|
| 718 |
|
---|
| 719 |
|
---|
[50613] | 720 | void Mouse::i_fireMouseEvent(bool fAbsolute, LONG x, LONG y, LONG dz, LONG dw,
|
---|
| 721 | LONG fButtons)
|
---|
[35871] | 722 | {
|
---|
| 723 | /* If mouse button is pressed, we generate new event, to avoid reusable events coalescing and thus
|
---|
| 724 | dropping key press events */
|
---|
[47805] | 725 | GuestMouseEventMode_T mode;
|
---|
| 726 | if (fAbsolute)
|
---|
| 727 | mode = GuestMouseEventMode_Absolute;
|
---|
| 728 | else
|
---|
| 729 | mode = GuestMouseEventMode_Relative;
|
---|
| 730 |
|
---|
[47215] | 731 | if (fButtons != 0)
|
---|
[85300] | 732 | ::FireGuestMouseEvent(mEventSource, mode, x, y, dz, dw, fButtons);
|
---|
[35871] | 733 | else
|
---|
| 734 | {
|
---|
[85286] | 735 | ComPtr<IEvent> ptrEvent;
|
---|
| 736 | mMouseEvent.getEvent(ptrEvent.asOutParam());
|
---|
| 737 | ReinitGuestMouseEvent(ptrEvent, mode, x, y, dz, dw, fButtons);
|
---|
[35871] | 738 | mMouseEvent.fire(0);
|
---|
| 739 | }
|
---|
| 740 | }
|
---|
| 741 |
|
---|
[50613] | 742 | void Mouse::i_fireMultiTouchEvent(uint8_t cContacts,
|
---|
| 743 | const LONG64 *paContacts,
|
---|
[95368] | 744 | bool fTouchScreen,
|
---|
[50613] | 745 | uint32_t u32ScanTime)
|
---|
[47848] | 746 | {
|
---|
| 747 | com::SafeArray<SHORT> xPositions(cContacts);
|
---|
| 748 | com::SafeArray<SHORT> yPositions(cContacts);
|
---|
| 749 | com::SafeArray<USHORT> contactIds(cContacts);
|
---|
| 750 | com::SafeArray<USHORT> contactFlags(cContacts);
|
---|
[35871] | 751 |
|
---|
[47848] | 752 | uint8_t i;
|
---|
| 753 | for (i = 0; i < cContacts; i++)
|
---|
| 754 | {
|
---|
| 755 | uint32_t u32Lo = RT_LO_U32(paContacts[i]);
|
---|
| 756 | uint32_t u32Hi = RT_HI_U32(paContacts[i]);
|
---|
| 757 | xPositions[i] = (int16_t)u32Lo;
|
---|
| 758 | yPositions[i] = (int16_t)(u32Lo >> 16);
|
---|
| 759 | contactIds[i] = RT_BYTE1(u32Hi);
|
---|
| 760 | contactFlags[i] = RT_BYTE2(u32Hi);
|
---|
| 761 | }
|
---|
| 762 |
|
---|
[85300] | 763 | ::FireGuestMultiTouchEvent(mEventSource, cContacts, ComSafeArrayAsInParam(xPositions), ComSafeArrayAsInParam(yPositions),
|
---|
[95368] | 764 | ComSafeArrayAsInParam(contactIds), ComSafeArrayAsInParam(contactFlags), fTouchScreen, u32ScanTime);
|
---|
[47848] | 765 | }
|
---|
| 766 |
|
---|
[26624] | 767 | /**
|
---|
[32828] | 768 | * Send a relative mouse event to the guest.
|
---|
| 769 | * @note the VMMDev capability change is so that the guest knows we are sending
|
---|
| 770 | * real events over the PS/2 device and not dummy events to signal the
|
---|
| 771 | * arrival of new absolute pointer data
|
---|
[1] | 772 | *
|
---|
| 773 | * @returns COM status code
|
---|
[65103] | 774 | * @param dx X movement.
|
---|
| 775 | * @param dy Y movement.
|
---|
| 776 | * @param dz Z movement.
|
---|
| 777 | * @param dw Mouse wheel movement.
|
---|
| 778 | * @param aButtonState The mouse button state.
|
---|
[1] | 779 | */
|
---|
[50613] | 780 | HRESULT Mouse::putMouseEvent(LONG dx, LONG dy, LONG dz, LONG dw,
|
---|
| 781 | LONG aButtonState)
|
---|
[1] | 782 | {
|
---|
[33758] | 783 | LogRel3(("%s: dx=%d, dy=%d, dz=%d, dw=%d\n", __PRETTY_FUNCTION__,
|
---|
[32817] | 784 | dx, dy, dz, dw));
|
---|
| 785 |
|
---|
[94924] | 786 | uint32_t fButtonsAdj = i_mouseButtonsToPDM(aButtonState);
|
---|
[33758] | 787 | /* Make sure that the guest knows that we are sending real movement
|
---|
| 788 | * events to the PS/2 device and not just dummy wake-up ones. */
|
---|
[50613] | 789 | i_updateVMMDevMouseCaps(0, VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE);
|
---|
[94924] | 790 | HRESULT hrc = i_reportRelEventToMouseDev(dx, dy, dz, dw, fButtonsAdj);
|
---|
[1] | 791 |
|
---|
[50613] | 792 | i_fireMouseEvent(false, dx, dy, dz, dw, aButtonState);
|
---|
[33075] | 793 |
|
---|
[94924] | 794 | return hrc;
|
---|
[1] | 795 | }
|
---|
| 796 |
|
---|
| 797 | /**
|
---|
[32817] | 798 | * Convert an (X, Y) value pair in screen co-ordinates (starting from 1) to a
|
---|
[40310] | 799 | * value from VMMDEV_MOUSE_RANGE_MIN to VMMDEV_MOUSE_RANGE_MAX. Sets the
|
---|
| 800 | * optional validity value to false if the pair is not on an active screen and
|
---|
| 801 | * to true otherwise.
|
---|
[38590] | 802 | * @note since guests with recent versions of X.Org use a different method
|
---|
| 803 | * to everyone else to map the valuator value to a screen pixel (they
|
---|
| 804 | * multiply by the screen dimension, do a floating point divide by
|
---|
| 805 | * the valuator maximum and round the result, while everyone else
|
---|
| 806 | * does truncating integer operations) we adjust the value we send
|
---|
| 807 | * so that it maps to the right pixel both when the result is rounded
|
---|
| 808 | * and when it is truncated.
|
---|
[26624] | 809 | *
|
---|
| 810 | * @returns COM status value
|
---|
| 811 | */
|
---|
[50613] | 812 | HRESULT Mouse::i_convertDisplayRes(LONG x, LONG y, int32_t *pxAdj, int32_t *pyAdj,
|
---|
| 813 | bool *pfValid)
|
---|
[26624] | 814 | {
|
---|
[47215] | 815 | AssertPtrReturn(pxAdj, E_POINTER);
|
---|
| 816 | AssertPtrReturn(pyAdj, E_POINTER);
|
---|
[35212] | 817 | AssertPtrNullReturn(pfValid, E_POINTER);
|
---|
[51612] | 818 | DisplayMouseInterface *pDisplay = mParent->i_getDisplayMouseInterface();
|
---|
[26624] | 819 | ComAssertRet(pDisplay, E_FAIL);
|
---|
[38590] | 820 | /** The amount to add to the result (multiplied by the screen width/height)
|
---|
| 821 | * to compensate for differences in guest methods for mapping back to
|
---|
| 822 | * pixels */
|
---|
[40310] | 823 | enum { ADJUST_RANGE = - 3 * VMMDEV_MOUSE_RANGE / 4 };
|
---|
[26624] | 824 |
|
---|
[35212] | 825 | if (pfValid)
|
---|
| 826 | *pfValid = true;
|
---|
[54495] | 827 | if (!(mfVMMDevGuestCaps & VMMDEV_MOUSE_NEW_PROTOCOL) && !pDisplay->i_isInputMappingSet())
|
---|
[34754] | 828 | {
|
---|
| 829 | ULONG displayWidth, displayHeight;
|
---|
[52064] | 830 | ULONG ulDummy;
|
---|
| 831 | LONG lDummy;
|
---|
[34754] | 832 | /* Takes the display lock */
|
---|
[94924] | 833 | HRESULT hrc = pDisplay->i_getScreenResolution(0, &displayWidth,
|
---|
| 834 | &displayHeight, &ulDummy, &lDummy, &lDummy);
|
---|
| 835 | if (FAILED(hrc))
|
---|
| 836 | return hrc;
|
---|
[26624] | 837 |
|
---|
[47215] | 838 | *pxAdj = displayWidth ? (x * VMMDEV_MOUSE_RANGE + ADJUST_RANGE)
|
---|
| 839 | / (LONG) displayWidth: 0;
|
---|
| 840 | *pyAdj = displayHeight ? (y * VMMDEV_MOUSE_RANGE + ADJUST_RANGE)
|
---|
| 841 | / (LONG) displayHeight: 0;
|
---|
[34754] | 842 | }
|
---|
| 843 | else
|
---|
| 844 | {
|
---|
| 845 | int32_t x1, y1, x2, y2;
|
---|
[34835] | 846 | /* Takes the display lock */
|
---|
[52064] | 847 | pDisplay->i_getFramebufferDimensions(&x1, &y1, &x2, &y2);
|
---|
[47215] | 848 | *pxAdj = x1 < x2 ? ((x - x1) * VMMDEV_MOUSE_RANGE + ADJUST_RANGE)
|
---|
| 849 | / (x2 - x1) : 0;
|
---|
| 850 | *pyAdj = y1 < y2 ? ((y - y1) * VMMDEV_MOUSE_RANGE + ADJUST_RANGE)
|
---|
| 851 | / (y2 - y1) : 0;
|
---|
| 852 | if ( *pxAdj < VMMDEV_MOUSE_RANGE_MIN
|
---|
| 853 | || *pxAdj > VMMDEV_MOUSE_RANGE_MAX
|
---|
| 854 | || *pyAdj < VMMDEV_MOUSE_RANGE_MIN
|
---|
| 855 | || *pyAdj > VMMDEV_MOUSE_RANGE_MAX)
|
---|
[35212] | 856 | if (pfValid)
|
---|
| 857 | *pfValid = false;
|
---|
[34754] | 858 | }
|
---|
[26624] | 859 | return S_OK;
|
---|
| 860 | }
|
---|
| 861 |
|
---|
| 862 |
|
---|
| 863 | /**
|
---|
[32817] | 864 | * Send an absolute mouse event to the VM. This requires either VirtualBox-
|
---|
| 865 | * specific drivers installed in the guest or absolute pointing device
|
---|
| 866 | * emulation.
|
---|
[32828] | 867 | * @note the VMMDev capability change is so that the guest knows we are sending
|
---|
| 868 | * dummy events over the PS/2 device to signal the arrival of new
|
---|
| 869 | * absolute pointer data, and not pointer real movement data
|
---|
| 870 | * @note all calls out of this object are made with no locks held!
|
---|
[1] | 871 | *
|
---|
| 872 | * @returns COM status code
|
---|
[65103] | 873 | * @param x X position (pixel), starting from 1
|
---|
| 874 | * @param y Y position (pixel), starting from 1
|
---|
| 875 | * @param dz Z movement
|
---|
| 876 | * @param dw mouse wheel movement
|
---|
| 877 | * @param aButtonState The mouse button state
|
---|
[1] | 878 | */
|
---|
[50613] | 879 | HRESULT Mouse::putMouseEventAbsolute(LONG x, LONG y, LONG dz, LONG dw,
|
---|
| 880 | LONG aButtonState)
|
---|
[1] | 881 | {
|
---|
[47215] | 882 | LogRel3(("%s: x=%d, y=%d, dz=%d, dw=%d, fButtons=0x%x\n",
|
---|
[50613] | 883 | __PRETTY_FUNCTION__, x, y, dz, dw, aButtonState));
|
---|
[1] | 884 |
|
---|
[77485] | 885 | DisplayMouseInterface *pDisplay = mParent->i_getDisplayMouseInterface();
|
---|
| 886 | ComAssertRet(pDisplay, E_FAIL);
|
---|
[47208] | 887 | int32_t xAdj, yAdj;
|
---|
[47215] | 888 | uint32_t fButtonsAdj;
|
---|
[35212] | 889 | bool fValid;
|
---|
[32817] | 890 |
|
---|
[77485] | 891 | /* If we are doing old-style (IRQ-less) absolute reporting to the VMM
|
---|
| 892 | * device then make sure the guest is aware of it, so that it knows to
|
---|
| 893 | * ignore relative movement on the PS/2 device. */
|
---|
| 894 | i_updateVMMDevMouseCaps(VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE, 0);
|
---|
| 895 | /* Detect out-of-range. */
|
---|
| 896 | if (x == 0x7FFFFFFF && y == 0x7FFFFFFF)
|
---|
| 897 | {
|
---|
| 898 | pDisplay->i_reportHostCursorPosition(0, 0, true);
|
---|
| 899 | return S_OK;
|
---|
| 900 | }
|
---|
| 901 | /* Detect "report-only" (-1, -1). This is not ideal, as in theory the
|
---|
| 902 | * front-end could be sending negative values relative to the primary
|
---|
| 903 | * screen. */
|
---|
| 904 | if (x == -1 && y == -1)
|
---|
| 905 | return S_OK;
|
---|
[27208] | 906 | /** @todo the front end should do this conversion to avoid races */
|
---|
[32817] | 907 | /** @note Or maybe not... races are pretty inherent in everything done in
|
---|
| 908 | * this object and not really bad as far as I can see. */
|
---|
[94924] | 909 | HRESULT hrc = i_convertDisplayRes(x, y, &xAdj, &yAdj, &fValid);
|
---|
| 910 | if (FAILED(hrc)) return hrc;
|
---|
[27160] | 911 |
|
---|
[50613] | 912 | fButtonsAdj = i_mouseButtonsToPDM(aButtonState);
|
---|
[35212] | 913 | if (fValid)
|
---|
| 914 | {
|
---|
[94924] | 915 | hrc = i_reportAbsEventToInputDevices(xAdj, yAdj, dz, dw, fButtonsAdj,
|
---|
| 916 | RT_BOOL(mfVMMDevGuestCaps & VMMDEV_MOUSE_NEW_PROTOCOL));
|
---|
| 917 | if (FAILED(hrc)) return hrc;
|
---|
[27060] | 918 |
|
---|
[50613] | 919 | i_fireMouseEvent(true, x, y, dz, dw, aButtonState);
|
---|
[35212] | 920 | }
|
---|
[94924] | 921 | hrc = i_reportAbsEventToDisplayDevice(x, y);
|
---|
[33075] | 922 |
|
---|
[94924] | 923 | return hrc;
|
---|
[1] | 924 | }
|
---|
| 925 |
|
---|
[47208] | 926 | /**
|
---|
[47571] | 927 | * Send a multi-touch event. This requires multi-touch pointing device emulation.
|
---|
| 928 | * @note all calls out of this object are made with no locks held!
|
---|
| 929 | *
|
---|
| 930 | * @returns COM status code.
|
---|
| 931 | * @param aCount Number of contacts.
|
---|
| 932 | * @param aContacts Information about each contact.
|
---|
[95368] | 933 | * @param aIsTouchscreen Distinguishes between touchscreen and touchpad events.
|
---|
[47571] | 934 | * @param aScanTime Timestamp.
|
---|
[47208] | 935 | */
|
---|
[50613] | 936 | HRESULT Mouse::putEventMultiTouch(LONG aCount,
|
---|
| 937 | const std::vector<LONG64> &aContacts,
|
---|
[95368] | 938 | BOOL aIsTouchscreen,
|
---|
[50613] | 939 | ULONG aScanTime)
|
---|
[47208] | 940 | {
|
---|
[47571] | 941 | LogRel3(("%s: aCount %d(actual %d), aScanTime %u\n",
|
---|
[52934] | 942 | __FUNCTION__, aCount, aContacts.size(), aScanTime));
|
---|
[47208] | 943 |
|
---|
[94924] | 944 | HRESULT hrc = S_OK;
|
---|
[47208] | 945 |
|
---|
[52934] | 946 | if ((LONG)aContacts.size() >= aCount)
|
---|
[47208] | 947 | {
|
---|
[52934] | 948 | const LONG64 *paContacts = aCount > 0? &aContacts.front(): NULL;
|
---|
[47208] | 949 |
|
---|
[95368] | 950 | hrc = i_putEventMultiTouch(aCount, paContacts, aIsTouchscreen, aScanTime);
|
---|
[47208] | 951 | }
|
---|
[47571] | 952 | else
|
---|
| 953 | {
|
---|
[94924] | 954 | hrc = E_INVALIDARG;
|
---|
[47571] | 955 | }
|
---|
[47208] | 956 |
|
---|
[94924] | 957 | return hrc;
|
---|
[47208] | 958 | }
|
---|
| 959 |
|
---|
[47571] | 960 | /**
|
---|
| 961 | * Send a multi-touch event. Version for scripting languages.
|
---|
| 962 | *
|
---|
| 963 | * @returns COM status code.
|
---|
| 964 | * @param aCount Number of contacts.
|
---|
| 965 | * @param aContacts Information about each contact.
|
---|
[95368] | 966 | * @param aIsTouchscreen Distinguishes between touchscreen and touchpad events.
|
---|
[47571] | 967 | * @param aScanTime Timestamp.
|
---|
| 968 | */
|
---|
[50613] | 969 | HRESULT Mouse::putEventMultiTouchString(LONG aCount,
|
---|
| 970 | const com::Utf8Str &aContacts,
|
---|
[95368] | 971 | BOOL aIsTouchscreen,
|
---|
[50613] | 972 | ULONG aScanTime)
|
---|
[47571] | 973 | {
|
---|
| 974 | /** @todo implement: convert the string to LONG64 array and call putEventMultiTouch. */
|
---|
| 975 | NOREF(aCount);
|
---|
| 976 | NOREF(aContacts);
|
---|
[95368] | 977 | NOREF(aIsTouchscreen);
|
---|
[47571] | 978 | NOREF(aScanTime);
|
---|
| 979 | return E_NOTIMPL;
|
---|
| 980 | }
|
---|
| 981 |
|
---|
| 982 |
|
---|
[1] | 983 | // private methods
|
---|
| 984 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 985 |
|
---|
[47571] | 986 | /* Used by PutEventMultiTouch and PutEventMultiTouchString. */
|
---|
[50613] | 987 | HRESULT Mouse::i_putEventMultiTouch(LONG aCount,
|
---|
[52934] | 988 | const LONG64 *paContacts,
|
---|
[95368] | 989 | BOOL aIsTouchscreen,
|
---|
[50613] | 990 | ULONG aScanTime)
|
---|
[47571] | 991 | {
|
---|
| 992 | if (aCount >= 256)
|
---|
[96909] | 993 | return E_INVALIDARG;
|
---|
[26650] | 994 |
|
---|
[95368] | 995 | HRESULT hrc = S_OK;
|
---|
[47571] | 996 |
|
---|
[95368] | 997 | /* Touch events in the touchscreen variant are currently mapped to the
|
---|
| 998 | * primary monitor, because the emulated USB touchscreen device is
|
---|
| 999 | * associated with one (normally the primary) screen in the guest.
|
---|
| 1000 | * In the future this could/should be extended to multi-screen support. */
|
---|
[47795] | 1001 | ULONG uScreenId = 0;
|
---|
[47571] | 1002 |
|
---|
[47795] | 1003 | ULONG cWidth = 0;
|
---|
| 1004 | ULONG cHeight = 0;
|
---|
| 1005 | LONG xOrigin = 0;
|
---|
| 1006 | LONG yOrigin = 0;
|
---|
| 1007 |
|
---|
[95368] | 1008 | if (aIsTouchscreen)
|
---|
| 1009 | {
|
---|
| 1010 | DisplayMouseInterface *pDisplay = mParent->i_getDisplayMouseInterface();
|
---|
| 1011 | ComAssertRet(pDisplay, E_FAIL);
|
---|
| 1012 | ULONG cBPP = 0;
|
---|
| 1013 | hrc = pDisplay->i_getScreenResolution(uScreenId, &cWidth, &cHeight, &cBPP, &xOrigin, &yOrigin);
|
---|
| 1014 | NOREF(cBPP);
|
---|
| 1015 | ComAssertComRCRetRC(hrc);
|
---|
| 1016 | }
|
---|
| 1017 |
|
---|
[47571] | 1018 | uint64_t* pau64Contacts = NULL;
|
---|
| 1019 | uint8_t cContacts = 0;
|
---|
| 1020 |
|
---|
| 1021 | /* Deliver 0 contacts too, touch device may use this to reset the state. */
|
---|
| 1022 | if (aCount > 0)
|
---|
| 1023 | {
|
---|
| 1024 | /* Create a copy with converted coords. */
|
---|
| 1025 | pau64Contacts = (uint64_t *)RTMemTmpAlloc(aCount * sizeof(uint64_t));
|
---|
| 1026 | if (pau64Contacts)
|
---|
| 1027 | {
|
---|
[95368] | 1028 | if (aIsTouchscreen)
|
---|
| 1029 | {
|
---|
| 1030 | int32_t x1 = xOrigin;
|
---|
| 1031 | int32_t y1 = yOrigin;
|
---|
| 1032 | int32_t x2 = x1 + cWidth;
|
---|
| 1033 | int32_t y2 = y1 + cHeight;
|
---|
[47571] | 1034 |
|
---|
[95368] | 1035 | LogRel3(("%s: screen [%d] %d,%d %d,%d\n",
|
---|
| 1036 | __FUNCTION__, uScreenId, x1, y1, x2, y2));
|
---|
[47795] | 1037 |
|
---|
[95368] | 1038 | LONG i;
|
---|
| 1039 | for (i = 0; i < aCount; i++)
|
---|
| 1040 | {
|
---|
| 1041 | uint32_t u32Lo = RT_LO_U32(paContacts[i]);
|
---|
| 1042 | uint32_t u32Hi = RT_HI_U32(paContacts[i]);
|
---|
| 1043 | int32_t x = (int16_t)u32Lo;
|
---|
| 1044 | int32_t y = (int16_t)(u32Lo >> 16);
|
---|
| 1045 | uint8_t contactId = RT_BYTE1(u32Hi);
|
---|
| 1046 | bool fInContact = (RT_BYTE2(u32Hi) & 0x1) != 0;
|
---|
| 1047 | bool fInRange = (RT_BYTE2(u32Hi) & 0x2) != 0;
|
---|
[47571] | 1048 |
|
---|
[95368] | 1049 | LogRel3(("%s: touchscreen [%d] %d,%d id %d, inContact %d, inRange %d\n",
|
---|
| 1050 | __FUNCTION__, i, x, y, contactId, fInContact, fInRange));
|
---|
[47571] | 1051 |
|
---|
[95368] | 1052 | /* x1,y1 are inclusive and x2,y2 are exclusive,
|
---|
| 1053 | * while x,y start from 1 and are inclusive.
|
---|
| 1054 | */
|
---|
| 1055 | if (x <= x1 || x > x2 || y <= y1 || y > y2)
|
---|
| 1056 | {
|
---|
| 1057 | /* Out of range. Skip the contact. */
|
---|
| 1058 | continue;
|
---|
| 1059 | }
|
---|
| 1060 |
|
---|
| 1061 | int32_t xAdj = x1 < x2? ((x - 1 - x1) * VMMDEV_MOUSE_RANGE) / (x2 - x1) : 0;
|
---|
| 1062 | int32_t yAdj = y1 < y2? ((y - 1 - y1) * VMMDEV_MOUSE_RANGE) / (y2 - y1) : 0;
|
---|
| 1063 |
|
---|
| 1064 | bool fValid = ( xAdj >= VMMDEV_MOUSE_RANGE_MIN
|
---|
| 1065 | && xAdj <= VMMDEV_MOUSE_RANGE_MAX
|
---|
| 1066 | && yAdj >= VMMDEV_MOUSE_RANGE_MIN
|
---|
| 1067 | && yAdj <= VMMDEV_MOUSE_RANGE_MAX);
|
---|
| 1068 |
|
---|
| 1069 | if (fValid)
|
---|
| 1070 | {
|
---|
| 1071 | uint8_t fu8 = (uint8_t)( (fInContact? 0x01: 0x00)
|
---|
| 1072 | | (fInRange? 0x02: 0x00));
|
---|
| 1073 | pau64Contacts[cContacts] = RT_MAKE_U64_FROM_U16((uint16_t)xAdj,
|
---|
| 1074 | (uint16_t)yAdj,
|
---|
| 1075 | RT_MAKE_U16(contactId, fu8),
|
---|
| 1076 | 0);
|
---|
| 1077 | cContacts++;
|
---|
| 1078 | }
|
---|
| 1079 | }
|
---|
[96909] | 1080 | }
|
---|
| 1081 | else
|
---|
| 1082 | {
|
---|
[95368] | 1083 | LONG i;
|
---|
| 1084 | for (i = 0; i < aCount; i++)
|
---|
[47795] | 1085 | {
|
---|
[95368] | 1086 | uint32_t u32Lo = RT_LO_U32(paContacts[i]);
|
---|
| 1087 | uint32_t u32Hi = RT_HI_U32(paContacts[i]);
|
---|
| 1088 | uint16_t x = (uint16_t)u32Lo;
|
---|
| 1089 | uint16_t y = (uint16_t)(u32Lo >> 16);
|
---|
| 1090 | uint8_t contactId = RT_BYTE1(u32Hi);
|
---|
| 1091 | bool fInContact = (RT_BYTE2(u32Hi) & 0x1) != 0;
|
---|
[47571] | 1092 |
|
---|
[95368] | 1093 | LogRel3(("%s: touchpad [%d] %#04x,%#04x id %d, inContact %d\n",
|
---|
| 1094 | __FUNCTION__, i, x, y, contactId, fInContact));
|
---|
[47795] | 1095 |
|
---|
[95368] | 1096 | uint8_t fu8 = (uint8_t)(fInContact? 0x01: 0x00);
|
---|
[47571] | 1097 |
|
---|
[95368] | 1098 | pau64Contacts[cContacts] = RT_MAKE_U64_FROM_U16(x, y,
|
---|
[47571] | 1099 | RT_MAKE_U16(contactId, fu8),
|
---|
[95368] | 1100 | 0);
|
---|
[47571] | 1101 | cContacts++;
|
---|
| 1102 | }
|
---|
| 1103 | }
|
---|
| 1104 | }
|
---|
| 1105 | else
|
---|
| 1106 | {
|
---|
[94924] | 1107 | hrc = E_OUTOFMEMORY;
|
---|
[47571] | 1108 | }
|
---|
| 1109 | }
|
---|
| 1110 |
|
---|
[94924] | 1111 | if (SUCCEEDED(hrc))
|
---|
[47571] | 1112 | {
|
---|
[95368] | 1113 | hrc = i_reportMultiTouchEventToDevice(cContacts, cContacts? pau64Contacts: NULL, !!aIsTouchscreen, (uint32_t)aScanTime);
|
---|
[47571] | 1114 |
|
---|
[47848] | 1115 | /* Send the original contact information. */
|
---|
[95368] | 1116 | i_fireMultiTouchEvent(cContacts, cContacts? paContacts: NULL, !!aIsTouchscreen, (uint32_t)aScanTime);
|
---|
[47571] | 1117 | }
|
---|
| 1118 |
|
---|
| 1119 | RTMemTmpFree(pau64Contacts);
|
---|
| 1120 |
|
---|
[94924] | 1121 | return hrc;
|
---|
[47571] | 1122 | }
|
---|
| 1123 |
|
---|
| 1124 |
|
---|
[33758] | 1125 | /** Does the guest currently rely on the host to draw the mouse cursor or
|
---|
| 1126 | * can it switch to doing it itself in software? */
|
---|
[50613] | 1127 | bool Mouse::i_guestNeedsHostCursor(void)
|
---|
[26782] | 1128 | {
|
---|
[33758] | 1129 | return RT_BOOL(mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR);
|
---|
| 1130 | }
|
---|
| 1131 |
|
---|
| 1132 |
|
---|
[96909] | 1133 | /**
|
---|
[105006] | 1134 | * Returns the current mouse pointer data.
|
---|
| 1135 | *
|
---|
| 1136 | * @returns VBox status code.
|
---|
| 1137 | * @param aData Where to return the current mouse pointer data.
|
---|
| 1138 | */
|
---|
| 1139 | int Mouse::i_getPointerShape(MousePointerData &aData)
|
---|
| 1140 | {
|
---|
| 1141 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1142 |
|
---|
| 1143 | return aData.Init(mPointerData);
|
---|
| 1144 | }
|
---|
| 1145 |
|
---|
| 1146 |
|
---|
| 1147 | /**
|
---|
[96909] | 1148 | * Gets the combined capabilities of all currently enabled devices.
|
---|
[65103] | 1149 | *
|
---|
[96909] | 1150 | * @returns Combination of MOUSE_DEVCAP_XXX
|
---|
[65103] | 1151 | */
|
---|
[96909] | 1152 | uint32_t Mouse::i_getDeviceCaps(void)
|
---|
[33758] | 1153 | {
|
---|
[96909] | 1154 | uint32_t fCaps = 0;
|
---|
[33758] | 1155 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1156 | for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
|
---|
| 1157 | if (mpDrv[i])
|
---|
[96909] | 1158 | fCaps |= mpDrv[i]->u32DevCaps;
|
---|
| 1159 | return fCaps;
|
---|
[33758] | 1160 | }
|
---|
| 1161 |
|
---|
| 1162 |
|
---|
| 1163 | /** Does the VMM device currently support absolute reporting? */
|
---|
[50613] | 1164 | bool Mouse::i_vmmdevCanAbs(void)
|
---|
[33758] | 1165 | {
|
---|
[96909] | 1166 | /* This requires the VMMDev cap and a relative device, which supposedly
|
---|
| 1167 | consumes these. As seen in @bugref{10285} this isn't quite as clear cut. */
|
---|
| 1168 | return (mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE)
|
---|
| 1169 | && (i_getDeviceCaps() & MOUSE_DEVCAP_RELATIVE);
|
---|
[33758] | 1170 | }
|
---|
| 1171 |
|
---|
| 1172 |
|
---|
[96909] | 1173 | /** Does any device currently support absolute reporting w/o help from VMMDev? */
|
---|
[50613] | 1174 | bool Mouse::i_deviceCanAbs(void)
|
---|
[33758] | 1175 | {
|
---|
[96909] | 1176 | return RT_BOOL(i_getDeviceCaps() & MOUSE_DEVCAP_ABSOLUTE);
|
---|
[33758] | 1177 | }
|
---|
| 1178 |
|
---|
| 1179 |
|
---|
| 1180 | /** Can we currently send relative events to the guest? */
|
---|
[50613] | 1181 | bool Mouse::i_supportsRel(void)
|
---|
[33758] | 1182 | {
|
---|
[96909] | 1183 | return RT_BOOL(i_getDeviceCaps() & MOUSE_DEVCAP_RELATIVE);
|
---|
| 1184 | }
|
---|
[33758] | 1185 |
|
---|
[96909] | 1186 |
|
---|
| 1187 | /** Can we currently send absolute events to the guest (including via VMMDev)? */
|
---|
| 1188 | bool Mouse::i_supportsAbs(uint32_t fCaps) const
|
---|
| 1189 | {
|
---|
| 1190 | return (fCaps & MOUSE_DEVCAP_ABSOLUTE)
|
---|
| 1191 | || /* inlined i_vmmdevCanAbs() to avoid unnecessary i_getDeviceCaps call: */
|
---|
| 1192 | ( (mfVMMDevGuestCaps & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE)
|
---|
| 1193 | && (fCaps & MOUSE_DEVCAP_RELATIVE));
|
---|
[33758] | 1194 | }
|
---|
| 1195 |
|
---|
| 1196 |
|
---|
| 1197 | /** Can we currently send absolute events to the guest? */
|
---|
[50613] | 1198 | bool Mouse::i_supportsAbs(void)
|
---|
[33758] | 1199 | {
|
---|
[96909] | 1200 | return Mouse::i_supportsAbs(i_getDeviceCaps());
|
---|
[33758] | 1201 | }
|
---|
| 1202 |
|
---|
| 1203 |
|
---|
[95369] | 1204 | /** Can we currently send multi-touch events (touchscreen variant) to the guest? */
|
---|
[95368] | 1205 | bool Mouse::i_supportsTS(void)
|
---|
[47174] | 1206 | {
|
---|
[96909] | 1207 | return RT_BOOL(i_getDeviceCaps() & MOUSE_DEVCAP_MT_ABSOLUTE);
|
---|
[47174] | 1208 | }
|
---|
| 1209 |
|
---|
| 1210 |
|
---|
[95369] | 1211 | /** Can we currently send multi-touch events (touchpad variant) to the guest? */
|
---|
| 1212 | bool Mouse::i_supportsTP(void)
|
---|
| 1213 | {
|
---|
[96909] | 1214 | return RT_BOOL(i_getDeviceCaps() & MOUSE_DEVCAP_MT_RELATIVE);
|
---|
[95369] | 1215 | }
|
---|
| 1216 |
|
---|
| 1217 |
|
---|
[33758] | 1218 | /** Check what sort of reporting can be done using the devices currently
|
---|
| 1219 | * enabled (including the VMM device) and notify the guest and the front-end.
|
---|
| 1220 | */
|
---|
[50613] | 1221 | void Mouse::i_sendMouseCapsNotifications(void)
|
---|
[33758] | 1222 | {
|
---|
[95368] | 1223 | bool fRelDev, fTSDev, fTPDev, fCanAbs, fNeedsHostCursor;
|
---|
[32817] | 1224 | {
|
---|
[33758] | 1225 | AutoReadLock aLock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[32817] | 1226 |
|
---|
[96909] | 1227 | uint32_t const fCaps = i_getDeviceCaps();
|
---|
| 1228 | fRelDev = RT_BOOL(fCaps & MOUSE_DEVCAP_RELATIVE);
|
---|
| 1229 | fTSDev = RT_BOOL(fCaps & MOUSE_DEVCAP_MT_ABSOLUTE);
|
---|
| 1230 | fTPDev = RT_BOOL(fCaps & MOUSE_DEVCAP_MT_RELATIVE);
|
---|
| 1231 | fCanAbs = i_supportsAbs(fCaps);
|
---|
[50613] | 1232 | fNeedsHostCursor = i_guestNeedsHostCursor();
|
---|
[32817] | 1233 | }
|
---|
[95368] | 1234 | mParent->i_onMouseCapabilityChange(fCanAbs, fRelDev, fTSDev, fTPDev, fNeedsHostCursor);
|
---|
[26782] | 1235 | }
|
---|
| 1236 |
|
---|
| 1237 |
|
---|
[1] | 1238 | /**
|
---|
[26935] | 1239 | * @interface_method_impl{PDMIMOUSECONNECTOR,pfnReportModes}
|
---|
[26650] | 1240 | */
|
---|
[65103] | 1241 | DECLCALLBACK(void) Mouse::i_mouseReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRelative,
|
---|
[95271] | 1242 | bool fAbsolute, bool fMTAbsolute, bool fMTRelative)
|
---|
[26650] | 1243 | {
|
---|
| 1244 | PDRVMAINMOUSE pDrv = RT_FROM_MEMBER(pInterface, DRVMAINMOUSE, IConnector);
|
---|
[65103] | 1245 | if (fRelative)
|
---|
[27060] | 1246 | pDrv->u32DevCaps |= MOUSE_DEVCAP_RELATIVE;
|
---|
[26935] | 1247 | else
|
---|
[27060] | 1248 | pDrv->u32DevCaps &= ~MOUSE_DEVCAP_RELATIVE;
|
---|
[65103] | 1249 | if (fAbsolute)
|
---|
[27060] | 1250 | pDrv->u32DevCaps |= MOUSE_DEVCAP_ABSOLUTE;
|
---|
[26650] | 1251 | else
|
---|
[27060] | 1252 | pDrv->u32DevCaps &= ~MOUSE_DEVCAP_ABSOLUTE;
|
---|
[95271] | 1253 | if (fMTAbsolute)
|
---|
| 1254 | pDrv->u32DevCaps |= MOUSE_DEVCAP_MT_ABSOLUTE;
|
---|
[47174] | 1255 | else
|
---|
[95271] | 1256 | pDrv->u32DevCaps &= ~MOUSE_DEVCAP_MT_ABSOLUTE;
|
---|
| 1257 | if (fMTRelative)
|
---|
| 1258 | pDrv->u32DevCaps |= MOUSE_DEVCAP_MT_RELATIVE;
|
---|
| 1259 | else
|
---|
| 1260 | pDrv->u32DevCaps &= ~MOUSE_DEVCAP_MT_RELATIVE;
|
---|
[26650] | 1261 |
|
---|
[50613] | 1262 | pDrv->pMouse->i_sendMouseCapsNotifications();
|
---|
[26650] | 1263 | }
|
---|
| 1264 |
|
---|
| 1265 |
|
---|
| 1266 | /**
|
---|
[25966] | 1267 | * @interface_method_impl{PDMIBASE,pfnQueryInterface}
|
---|
[1] | 1268 | */
|
---|
[50613] | 1269 | DECLCALLBACK(void *) Mouse::i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
|
---|
[1] | 1270 | {
|
---|
[25966] | 1271 | PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
|
---|
| 1272 | PDRVMAINMOUSE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
|
---|
[25985] | 1273 |
|
---|
| 1274 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pDrvIns->IBase);
|
---|
| 1275 | PDMIBASE_RETURN_INTERFACE(pszIID, PDMIMOUSECONNECTOR, &pDrv->IConnector);
|
---|
[25966] | 1276 | return NULL;
|
---|
[1] | 1277 | }
|
---|
| 1278 |
|
---|
| 1279 |
|
---|
| 1280 | /**
|
---|
| 1281 | * Destruct a mouse driver instance.
|
---|
| 1282 | *
|
---|
| 1283 | * @param pDrvIns The driver instance data.
|
---|
| 1284 | */
|
---|
[50613] | 1285 | DECLCALLBACK(void) Mouse::i_drvDestruct(PPDMDRVINS pDrvIns)
|
---|
[1] | 1286 | {
|
---|
[45029] | 1287 | PDMDRV_CHECK_VERSIONS_RETURN_VOID(pDrvIns);
|
---|
[45030] | 1288 | PDRVMAINMOUSE pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
|
---|
[1] | 1289 | LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
[26001] | 1290 |
|
---|
[45030] | 1291 | if (pThis->pMouse)
|
---|
[1] | 1292 | {
|
---|
[45030] | 1293 | AutoWriteLock mouseLock(pThis->pMouse COMMA_LOCKVAL_SRC_POS);
|
---|
[27208] | 1294 | for (unsigned cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev)
|
---|
[45030] | 1295 | if (pThis->pMouse->mpDrv[cDev] == pThis)
|
---|
[27208] | 1296 | {
|
---|
[45030] | 1297 | pThis->pMouse->mpDrv[cDev] = NULL;
|
---|
[27208] | 1298 | break;
|
---|
| 1299 | }
|
---|
[1] | 1300 | }
|
---|
| 1301 | }
|
---|
| 1302 |
|
---|
| 1303 |
|
---|
| 1304 | /**
|
---|
| 1305 | * Construct a mouse driver instance.
|
---|
| 1306 | *
|
---|
[22277] | 1307 | * @copydoc FNPDMDRVCONSTRUCT
|
---|
[1] | 1308 | */
|
---|
[50613] | 1309 | DECLCALLBACK(int) Mouse::i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags)
|
---|
[1] | 1310 | {
|
---|
[45029] | 1311 | PDMDRV_CHECK_VERSIONS_RETURN(pDrvIns);
|
---|
[93444] | 1312 | RT_NOREF(fFlags, pCfg);
|
---|
[45030] | 1313 | PDRVMAINMOUSE pThis = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
|
---|
[1] | 1314 | LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance));
|
---|
| 1315 |
|
---|
| 1316 | /*
|
---|
| 1317 | * Validate configuration.
|
---|
| 1318 | */
|
---|
[93444] | 1319 | PDMDRV_VALIDATE_CONFIG_RETURN(pDrvIns, "", "");
|
---|
[25149] | 1320 | AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
|
---|
[22277] | 1321 | ("Configuration error: Not possible to attach anything to this driver!\n"),
|
---|
| 1322 | VERR_PDM_DRVINS_NO_ATTACH);
|
---|
[1] | 1323 |
|
---|
| 1324 | /*
|
---|
| 1325 | * IBase.
|
---|
| 1326 | */
|
---|
[50613] | 1327 | pDrvIns->IBase.pfnQueryInterface = Mouse::i_drvQueryInterface;
|
---|
[1] | 1328 |
|
---|
[50613] | 1329 | pThis->IConnector.pfnReportModes = Mouse::i_mouseReportModes;
|
---|
[26624] | 1330 |
|
---|
[1] | 1331 | /*
|
---|
| 1332 | * Get the IMousePort interface of the above driver/device.
|
---|
| 1333 | */
|
---|
[45030] | 1334 | pThis->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMIMOUSEPORT_IID);
|
---|
| 1335 | if (!pThis->pUpPort)
|
---|
[1] | 1336 | {
|
---|
| 1337 | AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
|
---|
| 1338 | return VERR_PDM_MISSING_INTERFACE_ABOVE;
|
---|
| 1339 | }
|
---|
| 1340 |
|
---|
| 1341 | /*
|
---|
| 1342 | * Get the Mouse object pointer and update the mpDrv member.
|
---|
| 1343 | */
|
---|
[89951] | 1344 | com::Guid uuid(COM_IIDOF(IMouse));
|
---|
| 1345 | IMouse *pIMouse = (IMouse *)PDMDrvHlpQueryGenericUserObject(pDrvIns, uuid.raw());
|
---|
| 1346 | if (!pIMouse)
|
---|
[1] | 1347 | {
|
---|
[89951] | 1348 | AssertMsgFailed(("Configuration error: No/bad Mouse object!\n"));
|
---|
| 1349 | return VERR_NOT_FOUND;
|
---|
[1] | 1350 | }
|
---|
[89951] | 1351 | pThis->pMouse = static_cast<Mouse *>(pIMouse);
|
---|
| 1352 |
|
---|
[27060] | 1353 | unsigned cDev;
|
---|
[32817] | 1354 | {
|
---|
[59995] | 1355 | AutoWriteLock mouseLock(pThis->pMouse COMMA_LOCKVAL_SRC_POS);
|
---|
[32817] | 1356 |
|
---|
| 1357 | for (cDev = 0; cDev < MOUSE_MAX_DEVICES; ++cDev)
|
---|
[47841] | 1358 | if (!pThis->pMouse->mpDrv[cDev])
|
---|
[32817] | 1359 | {
|
---|
[47841] | 1360 | pThis->pMouse->mpDrv[cDev] = pThis;
|
---|
[32817] | 1361 | break;
|
---|
| 1362 | }
|
---|
| 1363 | }
|
---|
[27060] | 1364 | if (cDev == MOUSE_MAX_DEVICES)
|
---|
| 1365 | return VERR_NO_MORE_HANDLES;
|
---|
[1] | 1366 |
|
---|
| 1367 | return VINF_SUCCESS;
|
---|
| 1368 | }
|
---|
| 1369 |
|
---|
| 1370 |
|
---|
| 1371 | /**
|
---|
| 1372 | * Main mouse driver registration record.
|
---|
| 1373 | */
|
---|
| 1374 | const PDMDRVREG Mouse::DrvReg =
|
---|
| 1375 | {
|
---|
| 1376 | /* u32Version */
|
---|
| 1377 | PDM_DRVREG_VERSION,
|
---|
[26166] | 1378 | /* szName */
|
---|
[1] | 1379 | "MainMouse",
|
---|
[25893] | 1380 | /* szRCMod */
|
---|
| 1381 | "",
|
---|
| 1382 | /* szR0Mod */
|
---|
| 1383 | "",
|
---|
[1] | 1384 | /* pszDescription */
|
---|
| 1385 | "Main mouse driver (Main as in the API).",
|
---|
| 1386 | /* fFlags */
|
---|
| 1387 | PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
|
---|
| 1388 | /* fClass. */
|
---|
| 1389 | PDM_DRVREG_CLASS_MOUSE,
|
---|
| 1390 | /* cMaxInstances */
|
---|
[40282] | 1391 | ~0U,
|
---|
[1] | 1392 | /* cbInstance */
|
---|
| 1393 | sizeof(DRVMAINMOUSE),
|
---|
| 1394 | /* pfnConstruct */
|
---|
[50613] | 1395 | Mouse::i_drvConstruct,
|
---|
[1] | 1396 | /* pfnDestruct */
|
---|
[50613] | 1397 | Mouse::i_drvDestruct,
|
---|
[25893] | 1398 | /* pfnRelocate */
|
---|
| 1399 | NULL,
|
---|
[1] | 1400 | /* pfnIOCtl */
|
---|
| 1401 | NULL,
|
---|
| 1402 | /* pfnPowerOn */
|
---|
| 1403 | NULL,
|
---|
| 1404 | /* pfnReset */
|
---|
| 1405 | NULL,
|
---|
| 1406 | /* pfnSuspend */
|
---|
| 1407 | NULL,
|
---|
| 1408 | /* pfnResume */
|
---|
| 1409 | NULL,
|
---|
[22277] | 1410 | /* pfnAttach */
|
---|
| 1411 | NULL,
|
---|
[1] | 1412 | /* pfnDetach */
|
---|
[25149] | 1413 | NULL,
|
---|
[22277] | 1414 | /* pfnPowerOff */
|
---|
[25149] | 1415 | NULL,
|
---|
[22277] | 1416 | /* pfnSoftReset */
|
---|
| 1417 | NULL,
|
---|
| 1418 | /* u32EndVersion */
|
---|
| 1419 | PDM_DRVREG_VERSION
|
---|
[1] | 1420 | };
|
---|
[14772] | 1421 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|