VirtualBox

source: vbox/trunk/src/VBox/Frontends/VBoxBFE/MouseImpl.cpp@ 25517

Last change on this file since 25517 was 22810, checked in by vboxsync, 15 years ago

FE/Qt, Devices/Input, Main, FE/*: upgrade mouse device to an MS IntelliMouse Explorer (five buttons and tilt wheel)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.7 KB
Line 
1/** @file
2 *
3 * VBox frontends: Basic Frontend (BFE):
4 * Implementation of Mouse class
5 */
6
7/*
8 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
9 *
10 * This file is part of VirtualBox Open Source Edition (OSE), as
11 * available from http://www.virtualbox.org. This file is free software;
12 * you can redistribute it and/or modify it under the terms of the GNU
13 * General Public License (GPL) as published by the Free Software
14 * Foundation, in version 2 as it comes in the "COPYING" file of the
15 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17 *
18 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
19 * Clara, CA 95054 USA or visit http://www.sun.com if you need
20 * additional information or have any questions.
21 */
22
23#ifdef VBOXBFE_WITHOUT_COM
24# include "COMDefs.h"
25#else
26# include <VBox/com/defs.h>
27#endif
28#include <VBox/pdm.h>
29#include <VBox/cfgm.h>
30#include <VBox/err.h>
31#include <iprt/assert.h>
32#include <VBox/log.h>
33#include <iprt/asm.h>
34#include <VBox/VMMDev.h>
35#include "MouseImpl.h"
36#include "DisplayImpl.h"
37#include "VMMDevInterface.h"
38
39/**
40 * Mouse driver instance data.
41 */
42typedef struct DRVMAINMOUSE
43{
44 /** Pointer to the associated mouse driver. */
45 Mouse *mpDrv;
46 /** Pointer to the driver instance structure. */
47 PPDMDRVINS pDrvIns;
48 /** Pointer to the mouse port interface of the driver/device above us. */
49 PPDMIMOUSEPORT pUpPort;
50 /** Our mouse connector interface. */
51 PDMIMOUSECONNECTOR Connector;
52} DRVMAINMOUSE, *PDRVMAINMOUSE;
53
54/** Converts PDMIMOUSECONNECTOR pointer to a DRVMAINMOUSE pointer. */
55#define PDMIMOUSECONNECTOR_2_MAINMOUSE(pInterface) ( (PDRVMAINMOUSE) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINMOUSE, Connector)) )
56
57// IMouse methods
58/////////////////////////////////////////////////////////////////////////////
59
60int Mouse::setAbsoluteCoordinates(bool fAbsolute)
61{
62 this->fAbsolute = fAbsolute;
63 return S_OK;
64}
65
66int Mouse::setNeedsHostCursor(bool fNeedsHostCursor)
67{
68 this->fNeedsHostCursor = fNeedsHostCursor;
69 return S_OK;
70}
71
72int Mouse::setHostCursor(bool enable)
73{
74 uHostCaps = enable ? 0 : VMMDEV_MOUSE_HOST_CANNOT_HWPOINTER;
75 gVMMDev->SetMouseCapabilities(uHostCaps);
76 return S_OK;
77}
78
79/**
80 * Send a mouse event.
81 *
82 * @returns COM status code
83 * @param dx X movement
84 * @param dy Y movement
85 * @param dz Z movement
86 * @param buttonState The mouse button state
87 */
88int Mouse::PutMouseEvent(LONG dx, LONG dy, LONG dz, LONG buttonState)
89{
90 uint32_t mouseCaps;
91 gVMMDev->QueryMouseCapabilities(&mouseCaps);
92
93 /*
94 * This method being called implies that the host no
95 * longer wants to use absolute coordinates. If the VMM
96 * device isn't aware of that yet, tell it.
97 */
98 if (mouseCaps & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE)
99 {
100 gVMMDev->SetMouseCapabilities(uHostCaps);
101 }
102
103 uint32_t fButtons = 0;
104 if (buttonState & PDMIMOUSEPORT_BUTTON_LEFT)
105 fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
106 if (buttonState & PDMIMOUSEPORT_BUTTON_RIGHT)
107 fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
108 if (buttonState & PDMIMOUSEPORT_BUTTON_MIDDLE)
109 fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
110
111 int vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, dx, dy, dz, 0 /* Horizontal wheel */, fButtons);
112 if (RT_FAILURE (vrc))
113 return E_FAIL;
114
115 return S_OK;
116}
117
118/**
119 * Send an absolute mouse event to the VM. This only works
120 * when the required guest support has been installed.
121 *
122 * @returns COM status code
123 * @param x X position (pixel)
124 * @param y Y position (pixel)
125 * @param dz Z movement
126 * @param buttonState The mouse button state
127 */
128int Mouse::PutMouseEventAbsolute(LONG x, LONG y, LONG dz, LONG buttonState)
129{
130 uint32_t mouseCaps;
131 gVMMDev->QueryMouseCapabilities(&mouseCaps);
132
133 /*
134 * This method being called implies that the host no
135 * longer wants to use absolute coordinates. If the VMM
136 * device isn't aware of that yet, tell it.
137 */
138 if (!(mouseCaps & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
139 {
140 gVMMDev->SetMouseCapabilities(uHostCaps | VMMDEV_MOUSE_HOST_CAN_ABSOLUTE);
141 }
142
143 ULONG displayWidth;
144 ULONG displayHeight;
145 displayHeight = gDisplay->getHeight();
146 displayWidth = gDisplay->getWidth();
147
148 uint32_t mouseXAbs = (x * 0xFFFF) / displayWidth;
149 uint32_t mouseYAbs = (y * 0xFFFF) / displayHeight;
150
151 /*
152 * Send the absolute mouse position to the VMM device
153 */
154 int vrc = gVMMDev->SetAbsoluteMouse(mouseXAbs, mouseYAbs);
155 AssertRC(vrc);
156
157 // check if the guest actually wants absolute mouse positions
158 if (mouseCaps & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE)
159 {
160 uint32_t fButtons = 0;
161 if (buttonState & PDMIMOUSEPORT_BUTTON_LEFT)
162 fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
163 if (buttonState & PDMIMOUSEPORT_BUTTON_RIGHT)
164 fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
165 if (buttonState & PDMIMOUSEPORT_BUTTON_MIDDLE)
166 fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
167
168 vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, 1, 1, dz, 0 /* Horizontal wheel */, fButtons);
169 if (RT_FAILURE (vrc))
170 return E_FAIL;
171 }
172
173 return S_OK;
174}
175
176/////////////////////////////////////////////////////////////////////////////
177
178/**
179 * Queries an interface to the driver.
180 *
181 * @returns Pointer to interface.
182 * @returns NULL if the interface was not supported by the driver.
183 * @param pInterface Pointer to this interface structure.
184 * @param enmInterface The requested interface identification.
185 */
186DECLCALLBACK(void *) Mouse::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
187{
188 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
189 PDRVMAINMOUSE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
190 switch (enmInterface)
191 {
192 case PDMINTERFACE_BASE:
193 return &pDrvIns->IBase;
194 case PDMINTERFACE_MOUSE_CONNECTOR:
195 return &pDrv->Connector;
196 default:
197 return NULL;
198 }
199}
200
201
202/**
203 * Destruct a mouse driver instance.
204 *
205 * @returns VBox status.
206 * @param pDrvIns The driver instance data.
207 */
208DECLCALLBACK(void) Mouse::drvDestruct(PPDMDRVINS pDrvIns)
209{
210 //PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
211 LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
212}
213
214
215/**
216 * Construct a mouse driver instance.
217 *
218 * @copydoc FNPDMDRVCONSTRUCT
219 */
220DECLCALLBACK(int) Mouse::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
221{
222 PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
223 LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance));
224
225 /*
226 * Validate configuration.
227 */
228 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
229 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
230 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
231 ("Configuration error: Not possible to attach anything to this driver!\n"),
232 VERR_PDM_DRVINS_NO_ATTACH);
233
234 /*
235 * IBase.
236 */
237 pDrvIns->IBase.pfnQueryInterface = Mouse::drvQueryInterface;
238
239 /*
240 * Get the IMousePort interface of the above driver/device.
241 */
242 pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUSE_PORT);
243 if (!pData->pUpPort)
244 {
245 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
246 return VERR_PDM_MISSING_INTERFACE_ABOVE;
247 }
248
249 /*
250 * Get the Mouse object pointer and update the mpDrv member.
251 */
252 void *pv;
253 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
254 if (RT_FAILURE(rc))
255 {
256 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
257 return rc;
258 }
259
260 pData->mpDrv = (Mouse*)pv; /** @todo Check this cast! */
261 pData->mpDrv->mpDrv = pData;
262
263 return VINF_SUCCESS;
264}
265
266
267/**
268 * Main mouse driver registration record.
269 */
270const PDMDRVREG Mouse::DrvReg =
271{
272 /* u32Version */
273 PDM_DRVREG_VERSION,
274 /* szDriverName */
275 "MainMouse",
276 /* pszDescription */
277 "Main mouse driver (Main as in the API).",
278 /* fFlags */
279 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
280 /* fClass. */
281 PDM_DRVREG_CLASS_MOUSE,
282 /* cMaxInstances */
283 ~0,
284 /* cbInstance */
285 sizeof(DRVMAINMOUSE),
286 /* pfnConstruct */
287 Mouse::drvConstruct,
288 /* pfnDestruct */
289 Mouse::drvDestruct,
290 /* pfnIOCtl */
291 NULL,
292 /* pfnPowerOn */
293 NULL,
294 /* pfnReset */
295 NULL,
296 /* pfnSuspend */
297 NULL,
298 /* pfnResume */
299 NULL,
300 /* pfnAttach */
301 NULL,
302 /* pfnDetach */
303 NULL,
304 /* pfnPowerOff */
305 NULL,
306 /* pfnSoftReset */
307 NULL,
308 /* u32EndVersion */
309 PDM_DRVREG_VERSION
310};
311
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