[13607] | 1 | /* $Id: MouseImpl.h 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 |
|
---|
[76562] | 28 | #ifndef MAIN_INCLUDED_MouseImpl_h
|
---|
| 29 | #define MAIN_INCLUDED_MouseImpl_h
|
---|
[76487] | 30 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
| 31 | # pragma once
|
---|
| 32 | #endif
|
---|
[1] | 33 |
|
---|
[50613] | 34 | #include "MouseWrap.h"
|
---|
[30764] | 35 | #include "ConsoleImpl.h"
|
---|
[33061] | 36 | #include "EventImpl.h"
|
---|
[35346] | 37 | #include <VBox/vmm/pdmdrv.h>
|
---|
[1] | 38 |
|
---|
[105006] | 39 | /**
|
---|
| 40 | * Structure for keeping mouse pointer data.
|
---|
| 41 | */
|
---|
| 42 | struct MousePointerData
|
---|
| 43 | {
|
---|
| 44 | MousePointerData()
|
---|
| 45 | : fVisible(false)
|
---|
| 46 | , hotX(0)
|
---|
| 47 | , hotY(0)
|
---|
| 48 | , width(0)
|
---|
| 49 | , height(0)
|
---|
| 50 | , pu8Shape(NULL)
|
---|
| 51 | , cbShape(0) { }
|
---|
| 52 |
|
---|
| 53 | virtual ~MousePointerData()
|
---|
| 54 | {
|
---|
| 55 | Destroy();
|
---|
| 56 | }
|
---|
| 57 |
|
---|
| 58 | /**
|
---|
| 59 | * Initialize pointer shape data.
|
---|
| 60 | *
|
---|
| 61 | * @returns VBox status code.
|
---|
| 62 | * @param afVisible Whether the mouse cursor actually is visible or not.
|
---|
| 63 | * @param afAlpha Whether the pixel data contains an alpha mask or not.
|
---|
| 64 | * @param auHotX X hot position (in pixel) of the new cursor.
|
---|
| 65 | * @param auHotY Y hot position (in pixel) of the new cursor.
|
---|
| 66 | * @param auWidth Width (in pixel) of the new cursor.
|
---|
| 67 | * @param auHeight Height (in pixel) of the new cursor.
|
---|
| 68 | * @param apu8Shape Pixel data of the new cursor.
|
---|
| 69 | * @param acbShape Size of \a apu8Shape (in bytes).
|
---|
| 70 | */
|
---|
| 71 | int Init(bool afVisible, bool afAlpha, uint32_t auHotX, uint32_t auHotY, uint32_t auWidth, uint32_t auHeight,
|
---|
| 72 | const uint8_t *apu8Shape, uint32_t acbShape)
|
---|
| 73 | {
|
---|
| 74 | AssertMsgReturn(pu8Shape == NULL, ("Already initialized!\n"), VERR_WRONG_ORDER);
|
---|
| 75 |
|
---|
| 76 | fVisible = afVisible;
|
---|
| 77 | fAlpha = afAlpha;
|
---|
| 78 | hotX = auHotX;
|
---|
| 79 | hotY = auHotY;
|
---|
| 80 | width = auWidth;
|
---|
| 81 | height = auHeight;
|
---|
| 82 | if (acbShape)
|
---|
| 83 | {
|
---|
| 84 | pu8Shape = (uint8_t *)RTMemDup(apu8Shape, acbShape);
|
---|
| 85 | AssertPtrReturn(pu8Shape, VERR_NO_MEMORY);
|
---|
| 86 | cbShape = acbShape;
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | return VINF_SUCCESS;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | /**
|
---|
| 93 | * Initialize pointer shape data with another pointer shape data instance.
|
---|
| 94 | *
|
---|
| 95 | * @returns VBox status code.
|
---|
| 96 | * @param aThat Pointer shape data instance to use for initialization.
|
---|
| 97 | */
|
---|
| 98 | int Init(const MousePointerData &aThat)
|
---|
| 99 | {
|
---|
| 100 | return Init(aThat.fVisible, aThat.fAlpha, aThat.hotX, aThat.hotY, aThat.width, aThat.height,
|
---|
| 101 | aThat.pu8Shape, aThat.cbShape);
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | /**
|
---|
| 105 | * Destroys a pointer shape.
|
---|
| 106 | */
|
---|
| 107 | void Destroy(void)
|
---|
| 108 | {
|
---|
| 109 | if (pu8Shape)
|
---|
| 110 | {
|
---|
| 111 | Assert(cbShape);
|
---|
| 112 | RTMemFree(pu8Shape);
|
---|
| 113 | pu8Shape = NULL;
|
---|
| 114 | }
|
---|
| 115 | cbShape = 0;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | bool fVisible;
|
---|
| 119 | bool fAlpha;
|
---|
| 120 | uint32_t hotX;
|
---|
| 121 | uint32_t hotY;
|
---|
| 122 | uint32_t width;
|
---|
| 123 | uint32_t height;
|
---|
| 124 | uint8_t *pu8Shape;
|
---|
| 125 | uint32_t cbShape;
|
---|
| 126 | };
|
---|
| 127 |
|
---|
[27060] | 128 | /** Maximum number of devices supported */
|
---|
[95395] | 129 | enum { MOUSE_MAX_DEVICES = 4 };
|
---|
[27060] | 130 | /** Mouse driver instance data. */
|
---|
| 131 | typedef struct DRVMAINMOUSE DRVMAINMOUSE, *PDRVMAINMOUSE;
|
---|
| 132 |
|
---|
[1] | 133 | class ATL_NO_VTABLE Mouse :
|
---|
[50613] | 134 | public MouseWrap
|
---|
[1] | 135 | {
|
---|
| 136 | public:
|
---|
| 137 |
|
---|
[90828] | 138 | DECLARE_COMMON_CLASS_METHODS (Mouse)
|
---|
[13606] | 139 |
|
---|
[1] | 140 | HRESULT FinalConstruct();
|
---|
| 141 | void FinalRelease();
|
---|
| 142 |
|
---|
[13606] | 143 | // public initializer/uninitializer for internal purposes only
|
---|
[47190] | 144 | HRESULT init(ConsoleMouseInterface *parent);
|
---|
[1] | 145 | void uninit();
|
---|
| 146 |
|
---|
| 147 | static const PDMDRVREG DrvReg;
|
---|
| 148 |
|
---|
[50613] | 149 | ConsoleMouseInterface *i_getParent() const
|
---|
[26624] | 150 | {
|
---|
| 151 | return mParent;
|
---|
| 152 | }
|
---|
| 153 |
|
---|
[33758] | 154 | /** notify the front-end of guest capability changes */
|
---|
[50613] | 155 | void i_onVMMDevGuestCapsChange(uint32_t fCaps)
|
---|
[26782] | 156 | {
|
---|
[33758] | 157 | mfVMMDevGuestCaps = fCaps;
|
---|
[50613] | 158 | i_sendMouseCapsNotifications();
|
---|
[26782] | 159 | }
|
---|
| 160 |
|
---|
[105006] | 161 | int i_getPointerShape(MousePointerData &aData);
|
---|
| 162 | int i_updatePointerShape(bool fVisible, bool fAlpha,
|
---|
| 163 | uint32_t xHot, uint32_t yHot,
|
---|
| 164 | uint32_t uWidth, uint32_t uHeight,
|
---|
| 165 | const uint8_t *pu8Shape, uint32_t cbShape);
|
---|
[1] | 166 |
|
---|
[50613] | 167 | // Wrapped IMouse properties
|
---|
| 168 | HRESULT getAbsoluteSupported(BOOL *aAbsoluteSupported);
|
---|
| 169 | HRESULT getRelativeSupported(BOOL *aRelativeSupported);
|
---|
[95368] | 170 | HRESULT getTouchScreenSupported(BOOL *aTouchScreenSupported);
|
---|
| 171 | HRESULT getTouchPadSupported(BOOL *aTouchPadSupported);
|
---|
[50613] | 172 | HRESULT getNeedsHostCursor(BOOL *aNeedsHostCursor);
|
---|
[52921] | 173 | HRESULT getPointerShape(ComPtr<IMousePointerShape> &aPointerShape);
|
---|
[50613] | 174 | HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
|
---|
[27129] | 175 |
|
---|
[50613] | 176 | // Wrapped IMouse methods
|
---|
| 177 | HRESULT putMouseEvent(LONG aDx,
|
---|
| 178 | LONG aDy,
|
---|
| 179 | LONG aDz,
|
---|
| 180 | LONG aDw,
|
---|
| 181 | LONG aButtonState);
|
---|
| 182 | HRESULT putMouseEventAbsolute(LONG aX,
|
---|
| 183 | LONG aY,
|
---|
| 184 | LONG aDz,
|
---|
| 185 | LONG aDw,
|
---|
| 186 | LONG aButtonState);
|
---|
| 187 | HRESULT putEventMultiTouch(LONG aCount,
|
---|
| 188 | const std::vector<LONG64> &aContacts,
|
---|
[95368] | 189 | BOOL isTouchScreen,
|
---|
[50613] | 190 | ULONG aScanTime);
|
---|
| 191 | HRESULT putEventMultiTouchString(LONG aCount,
|
---|
| 192 | const com::Utf8Str &aContacts,
|
---|
[95368] | 193 | BOOL isTouchScreen,
|
---|
[50613] | 194 | ULONG aScanTime);
|
---|
[105006] | 195 | private:
|
---|
[50613] | 196 |
|
---|
| 197 | static DECLCALLBACK(void *) i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
|
---|
[95271] | 198 | static DECLCALLBACK(void) i_mouseReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs, bool fMTAbs, bool fMTRel);
|
---|
[50613] | 199 | static DECLCALLBACK(int) i_drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfg, uint32_t fFlags);
|
---|
| 200 | static DECLCALLBACK(void) i_drvDestruct(PPDMDRVINS pDrvIns);
|
---|
| 201 |
|
---|
| 202 | HRESULT i_updateVMMDevMouseCaps(uint32_t fCapsAdded, uint32_t fCapsRemoved);
|
---|
| 203 | HRESULT i_reportRelEventToMouseDev(int32_t dx, int32_t dy, int32_t dz,
|
---|
[26624] | 204 | int32_t dw, uint32_t fButtons);
|
---|
[50613] | 205 | HRESULT i_reportAbsEventToMouseDev(int32_t x, int32_t y, int32_t dz,
|
---|
[47215] | 206 | int32_t dw, uint32_t fButtons);
|
---|
[50613] | 207 | HRESULT i_reportMTEventToMouseDev(int32_t x, int32_t z, uint32_t cContact,
|
---|
[47245] | 208 | uint32_t fContact);
|
---|
[95368] | 209 | HRESULT i_reportMultiTouchEventToDevice(uint8_t cContacts, const uint64_t *pau64Contacts, bool fTouchScreen, uint32_t u32ScanTime);
|
---|
[97790] | 210 | HRESULT i_reportAbsEventToVMMDev(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons);
|
---|
[53965] | 211 | HRESULT i_reportAbsEventToInputDevices(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons,
|
---|
| 212 | bool fUsesVMMDevEvent);
|
---|
| 213 | HRESULT i_reportAbsEventToDisplayDevice(int32_t x, int32_t y);
|
---|
[50613] | 214 | HRESULT i_convertDisplayRes(LONG x, LONG y, int32_t *pxAdj, int32_t *pyAdj,
|
---|
| 215 | bool *pfValid);
|
---|
[95368] | 216 | HRESULT i_putEventMultiTouch(LONG aCount, const LONG64 *paContacts, BOOL isTouchScreen, ULONG aScanTime);
|
---|
[27129] | 217 |
|
---|
[96909] | 218 | uint32_t i_getDeviceCaps(void);
|
---|
[50613] | 219 | void i_sendMouseCapsNotifications(void);
|
---|
| 220 | bool i_guestNeedsHostCursor(void);
|
---|
| 221 | bool i_vmmdevCanAbs(void);
|
---|
| 222 | bool i_deviceCanAbs(void);
|
---|
[96909] | 223 | bool i_supportsAbs(uint32_t fCaps) const;
|
---|
[50613] | 224 | bool i_supportsAbs(void);
|
---|
| 225 | bool i_supportsRel(void);
|
---|
[95368] | 226 | bool i_supportsTS(void);
|
---|
| 227 | bool i_supportsTP(void);
|
---|
[1] | 228 |
|
---|
[47190] | 229 | ConsoleMouseInterface * const mParent;
|
---|
[1] | 230 | /** Pointer to the associated mouse driver. */
|
---|
[27060] | 231 | struct DRVMAINMOUSE *mpDrv[MOUSE_MAX_DEVICES];
|
---|
[1] | 232 |
|
---|
[33758] | 233 | uint32_t mfVMMDevGuestCaps; /** We cache this to avoid access races */
|
---|
[47208] | 234 | int32_t mcLastX;
|
---|
| 235 | int32_t mcLastY;
|
---|
[33758] | 236 | uint32_t mfLastButtons;
|
---|
[33061] | 237 |
|
---|
[52921] | 238 | ComPtr<IMousePointerShape> mPointerShape;
|
---|
[105006] | 239 | /** Current mouse pointer data. */
|
---|
| 240 | MousePointerData mPointerData;
|
---|
[52921] | 241 |
|
---|
[33061] | 242 | const ComObjPtr<EventSource> mEventSource;
|
---|
| 243 | VBoxEventDesc mMouseEvent;
|
---|
[35871] | 244 |
|
---|
[50613] | 245 | void i_fireMouseEvent(bool fAbsolute, LONG x, LONG y, LONG dz, LONG dw,
|
---|
| 246 | LONG fButtons);
|
---|
[47848] | 247 |
|
---|
[50613] | 248 | void i_fireMultiTouchEvent(uint8_t cContacts,
|
---|
| 249 | const LONG64 *paContacts,
|
---|
[95368] | 250 | bool fTouchScreen,
|
---|
[50613] | 251 | uint32_t u32ScanTime);
|
---|
[1] | 252 | };
|
---|
| 253 |
|
---|
[76562] | 254 | #endif /* !MAIN_INCLUDED_MouseImpl_h */
|
---|
[14949] | 255 | /* vi: set tabstop=4 shiftwidth=4 expandtab: */
|
---|