VirtualBox

source: vbox/trunk/src/VBox/Main/include/MouseImpl.h

Last change on this file was 106061, checked in by vboxsync, 6 days ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.8 KB
Line 
1/* $Id: MouseImpl.h 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * VirtualBox COM class implementation
4 */
5
6/*
7 * Copyright (C) 2006-2024 Oracle and/or its affiliates.
8 *
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
26 */
27
28#ifndef MAIN_INCLUDED_MouseImpl_h
29#define MAIN_INCLUDED_MouseImpl_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include "MouseWrap.h"
35#include "ConsoleImpl.h"
36#include "EventImpl.h"
37#include <VBox/vmm/pdmdrv.h>
38
39/**
40 * Structure for keeping mouse pointer data.
41 */
42struct 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
128/** Maximum number of devices supported */
129enum { MOUSE_MAX_DEVICES = 4 };
130/** Mouse driver instance data. */
131typedef struct DRVMAINMOUSE DRVMAINMOUSE, *PDRVMAINMOUSE;
132
133class ATL_NO_VTABLE Mouse :
134 public MouseWrap
135{
136public:
137
138 DECLARE_COMMON_CLASS_METHODS (Mouse)
139
140 HRESULT FinalConstruct();
141 void FinalRelease();
142
143 // public initializer/uninitializer for internal purposes only
144 HRESULT init(ConsoleMouseInterface *parent);
145 void uninit();
146
147 static const PDMDRVREG DrvReg;
148
149 ConsoleMouseInterface *i_getParent() const
150 {
151 return mParent;
152 }
153
154 /** notify the front-end of guest capability changes */
155 void i_onVMMDevGuestCapsChange(uint32_t fCaps)
156 {
157 mfVMMDevGuestCaps = fCaps;
158 i_sendMouseCapsNotifications();
159 }
160
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);
166
167 // Wrapped IMouse properties
168 HRESULT getAbsoluteSupported(BOOL *aAbsoluteSupported);
169 HRESULT getRelativeSupported(BOOL *aRelativeSupported);
170 HRESULT getTouchScreenSupported(BOOL *aTouchScreenSupported);
171 HRESULT getTouchPadSupported(BOOL *aTouchPadSupported);
172 HRESULT getNeedsHostCursor(BOOL *aNeedsHostCursor);
173 HRESULT getPointerShape(ComPtr<IMousePointerShape> &aPointerShape);
174 HRESULT getEventSource(ComPtr<IEventSource> &aEventSource);
175
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,
189 BOOL isTouchScreen,
190 ULONG aScanTime);
191 HRESULT putEventMultiTouchString(LONG aCount,
192 const com::Utf8Str &aContacts,
193 BOOL isTouchScreen,
194 ULONG aScanTime);
195private:
196
197 static DECLCALLBACK(void *) i_drvQueryInterface(PPDMIBASE pInterface, const char *pszIID);
198 static DECLCALLBACK(void) i_mouseReportModes(PPDMIMOUSECONNECTOR pInterface, bool fRel, bool fAbs, bool fMTAbs, bool fMTRel);
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,
204 int32_t dw, uint32_t fButtons);
205 HRESULT i_reportAbsEventToMouseDev(int32_t x, int32_t y, int32_t dz,
206 int32_t dw, uint32_t fButtons);
207 HRESULT i_reportMTEventToMouseDev(int32_t x, int32_t z, uint32_t cContact,
208 uint32_t fContact);
209 HRESULT i_reportMultiTouchEventToDevice(uint8_t cContacts, const uint64_t *pau64Contacts, bool fTouchScreen, uint32_t u32ScanTime);
210 HRESULT i_reportAbsEventToVMMDev(int32_t x, int32_t y, int32_t dz, int32_t dw, uint32_t fButtons);
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);
214 HRESULT i_convertDisplayRes(LONG x, LONG y, int32_t *pxAdj, int32_t *pyAdj,
215 bool *pfValid);
216 HRESULT i_putEventMultiTouch(LONG aCount, const LONG64 *paContacts, BOOL isTouchScreen, ULONG aScanTime);
217
218 uint32_t i_getDeviceCaps(void);
219 void i_sendMouseCapsNotifications(void);
220 bool i_guestNeedsHostCursor(void);
221 bool i_vmmdevCanAbs(void);
222 bool i_deviceCanAbs(void);
223 bool i_supportsAbs(uint32_t fCaps) const;
224 bool i_supportsAbs(void);
225 bool i_supportsRel(void);
226 bool i_supportsTS(void);
227 bool i_supportsTP(void);
228
229 ConsoleMouseInterface * const mParent;
230 /** Pointer to the associated mouse driver. */
231 struct DRVMAINMOUSE *mpDrv[MOUSE_MAX_DEVICES];
232
233 uint32_t mfVMMDevGuestCaps; /** We cache this to avoid access races */
234 int32_t mcLastX;
235 int32_t mcLastY;
236 uint32_t mfLastButtons;
237
238 ComPtr<IMousePointerShape> mPointerShape;
239 /** Current mouse pointer data. */
240 MousePointerData mPointerData;
241
242 const ComObjPtr<EventSource> mEventSource;
243 VBoxEventDesc mMouseEvent;
244
245 void i_fireMouseEvent(bool fAbsolute, LONG x, LONG y, LONG dz, LONG dw,
246 LONG fButtons);
247
248 void i_fireMultiTouchEvent(uint8_t cContacts,
249 const LONG64 *paContacts,
250 bool fTouchScreen,
251 uint32_t u32ScanTime);
252};
253
254#endif /* !MAIN_INCLUDED_MouseImpl_h */
255/* vi: set tabstop=4 shiftwidth=4 expandtab: */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette