VirtualBox

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

最後變更 在這個檔案從25966是 25966,由 vboxsync 提交於 15 年 前

PDMIBASE refactoring; use UUID as interface IDs.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 8.6 KB
 
1/* $Id: MouseImpl.cpp 25966 2010-01-22 11:15:43Z vboxsync $ */
2/** @file
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.alldomusa.eu.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 <iprt/uuid.h>
35#include <VBox/VMMDev.h>
36#include "MouseImpl.h"
37#include "DisplayImpl.h"
38#include "VMMDevInterface.h"
39
40/**
41 * Mouse driver instance data.
42 */
43typedef struct DRVMAINMOUSE
44{
45 /** Pointer to the associated mouse driver. */
46 Mouse *mpDrv;
47 /** Pointer to the driver instance structure. */
48 PPDMDRVINS pDrvIns;
49 /** Pointer to the mouse port interface of the driver/device above us. */
50 PPDMIMOUSEPORT pUpPort;
51 /** Our mouse connector interface. */
52 PDMIMOUSECONNECTOR Connector;
53} DRVMAINMOUSE, *PDRVMAINMOUSE;
54
55/** Converts PDMIMOUSECONNECTOR pointer to a DRVMAINMOUSE pointer. */
56#define PDMIMOUSECONNECTOR_2_MAINMOUSE(pInterface) ( (PDRVMAINMOUSE) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINMOUSE, Connector)) )
57
58// IMouse methods
59/////////////////////////////////////////////////////////////////////////////
60
61int Mouse::setAbsoluteCoordinates(bool a_fAbsolute)
62{
63 this->fAbsolute = a_fAbsolute;
64 return S_OK;
65}
66
67int Mouse::setNeedsHostCursor(bool a_fNeedsHostCursor)
68{
69 this->fNeedsHostCursor = a_fNeedsHostCursor;
70 return S_OK;
71}
72
73int Mouse::setHostCursor(bool enable)
74{
75 uHostCaps = enable ? 0 : VMMDEV_MOUSE_HOST_CANNOT_HWPOINTER;
76 gVMMDev->SetMouseCapabilities(uHostCaps);
77 return S_OK;
78}
79
80/**
81 * Send a mouse event.
82 *
83 * @returns COM status code
84 * @param dx X movement
85 * @param dy Y movement
86 * @param dz Z movement
87 * @param buttonState The mouse button state
88 */
89int Mouse::PutMouseEvent(LONG dx, LONG dy, LONG dz, LONG buttonState)
90{
91 uint32_t mouseCaps;
92 gVMMDev->QueryMouseCapabilities(&mouseCaps);
93
94 /*
95 * This method being called implies that the host no
96 * longer wants to use absolute coordinates. If the VMM
97 * device isn't aware of that yet, tell it.
98 */
99 if (mouseCaps & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE)
100 {
101 gVMMDev->SetMouseCapabilities(uHostCaps);
102 }
103
104 uint32_t fButtons = 0;
105 if (buttonState & PDMIMOUSEPORT_BUTTON_LEFT)
106 fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
107 if (buttonState & PDMIMOUSEPORT_BUTTON_RIGHT)
108 fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
109 if (buttonState & PDMIMOUSEPORT_BUTTON_MIDDLE)
110 fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
111
112 int vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, dx, dy, dz, 0 /* Horizontal wheel */, fButtons);
113 if (RT_FAILURE (vrc))
114 return E_FAIL;
115
116 return S_OK;
117}
118
119/**
120 * Send an absolute mouse event to the VM. This only works
121 * when the required guest support has been installed.
122 *
123 * @returns COM status code
124 * @param x X position (pixel)
125 * @param y Y position (pixel)
126 * @param dz Z movement
127 * @param buttonState The mouse button state
128 */
129int Mouse::PutMouseEventAbsolute(LONG x, LONG y, LONG dz, LONG buttonState)
130{
131 uint32_t mouseCaps;
132 gVMMDev->QueryMouseCapabilities(&mouseCaps);
133
134 /*
135 * This method being called implies that the host no
136 * longer wants to use absolute coordinates. If the VMM
137 * device isn't aware of that yet, tell it.
138 */
139 if (!(mouseCaps & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
140 {
141 gVMMDev->SetMouseCapabilities(uHostCaps | VMMDEV_MOUSE_HOST_CAN_ABSOLUTE);
142 }
143
144 ULONG displayWidth;
145 ULONG displayHeight;
146 displayHeight = gDisplay->getHeight();
147 displayWidth = gDisplay->getWidth();
148
149 uint32_t mouseXAbs = (x * 0xFFFF) / displayWidth;
150 uint32_t mouseYAbs = (y * 0xFFFF) / displayHeight;
151
152 /*
153 * Send the absolute mouse position to the VMM device
154 */
155 int vrc = gVMMDev->SetAbsoluteMouse(mouseXAbs, mouseYAbs);
156 AssertRC(vrc);
157
158 // check if the guest actually wants absolute mouse positions
159 if (mouseCaps & VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE)
160 {
161 uint32_t fButtons = 0;
162 if (buttonState & PDMIMOUSEPORT_BUTTON_LEFT)
163 fButtons |= PDMIMOUSEPORT_BUTTON_LEFT;
164 if (buttonState & PDMIMOUSEPORT_BUTTON_RIGHT)
165 fButtons |= PDMIMOUSEPORT_BUTTON_RIGHT;
166 if (buttonState & PDMIMOUSEPORT_BUTTON_MIDDLE)
167 fButtons |= PDMIMOUSEPORT_BUTTON_MIDDLE;
168
169 vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, 1, 1, dz, 0 /* Horizontal wheel */, fButtons);
170 if (RT_FAILURE (vrc))
171 return E_FAIL;
172 }
173
174 return S_OK;
175}
176
177/////////////////////////////////////////////////////////////////////////////
178
179/**
180 * @interface_method_impl{PDMIBASE,pfnQueryInterface}
181 */
182DECLCALLBACK(void *) Mouse::drvQueryInterface(PPDMIBASE pInterface, const char *pszIID)
183{
184 PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
185 PDRVMAINMOUSE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
186 if (RTUuidCompare2Strs(pszIID, PDMIBASE_IID) == 0)
187 return &pDrvIns->IBase;
188 if (RTUuidCompare2Strs(pszIID, PDMINTERFACE_MOUSE_CONNECTOR) == 0)
189 return &pDrv->Connector;
190 return NULL;
191}
192
193
194/**
195 * Destruct a mouse driver instance.
196 *
197 * @returns VBox status.
198 * @param pDrvIns The driver instance data.
199 */
200DECLCALLBACK(void) Mouse::drvDestruct(PPDMDRVINS pDrvIns)
201{
202 //PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
203 LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
204}
205
206
207/**
208 * Construct a mouse driver instance.
209 *
210 * @copydoc FNPDMDRVCONSTRUCT
211 */
212DECLCALLBACK(int) Mouse::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle, uint32_t fFlags)
213{
214 PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
215 LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance));
216
217 /*
218 * Validate configuration.
219 */
220 if (!CFGMR3AreValuesValid(pCfgHandle, "Object\0"))
221 return VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES;
222 AssertMsgReturn(PDMDrvHlpNoAttach(pDrvIns) == VERR_PDM_NO_ATTACHED_DRIVER,
223 ("Configuration error: Not possible to attach anything to this driver!\n"),
224 VERR_PDM_DRVINS_NO_ATTACH);
225
226 /*
227 * IBase.
228 */
229 pDrvIns->IBase.pfnQueryInterface = Mouse::drvQueryInterface;
230
231 /*
232 * Get the IMousePort interface of the above driver/device.
233 */
234 pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUSE_PORT);
235 if (!pData->pUpPort)
236 {
237 AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
238 return VERR_PDM_MISSING_INTERFACE_ABOVE;
239 }
240
241 /*
242 * Get the Mouse object pointer and update the mpDrv member.
243 */
244 void *pv;
245 int rc = CFGMR3QueryPtr(pCfgHandle, "Object", &pv);
246 if (RT_FAILURE(rc))
247 {
248 AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
249 return rc;
250 }
251
252 pData->mpDrv = (Mouse*)pv; /** @todo Check this cast! */
253 pData->mpDrv->mpDrv = pData;
254
255 return VINF_SUCCESS;
256}
257
258
259/**
260 * Main mouse driver registration record.
261 */
262const PDMDRVREG Mouse::DrvReg =
263{
264 /* u32Version */
265 PDM_DRVREG_VERSION,
266 /* szDriverName */
267 "MainMouse",
268 /* szRCMod */
269 "",
270 /* szR0Mod */
271 "",
272 /* pszDescription */
273 "Main mouse driver (Main as in the API).",
274 /* fFlags */
275 PDM_DRVREG_FLAGS_HOST_BITS_DEFAULT,
276 /* fClass. */
277 PDM_DRVREG_CLASS_MOUSE,
278 /* cMaxInstances */
279 ~0,
280 /* cbInstance */
281 sizeof(DRVMAINMOUSE),
282 /* pfnConstruct */
283 Mouse::drvConstruct,
284 /* pfnDestruct */
285 Mouse::drvDestruct,
286 /* pfnRelocate */
287 NULL,
288 /* pfnIOCtl */
289 NULL,
290 /* pfnPowerOn */
291 NULL,
292 /* pfnReset */
293 NULL,
294 /* pfnSuspend */
295 NULL,
296 /* pfnResume */
297 NULL,
298 /* pfnAttach */
299 NULL,
300 /* pfnDetach */
301 NULL,
302 /* pfnPowerOff */
303 NULL,
304 /* pfnSoftReset */
305 NULL,
306 /* u32EndVersion */
307 PDM_DRVREG_VERSION
308};
309
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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