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