MouseImpl.cpp revision 9fb5c93ff4449e19077128c07c080acbed35ceea
77b1a2d8b5dbe2c0b5200794914239fee3c8ee5dvboxsync * VBox frontends: Basic Frontend (BFE):
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Implementation of Mouse class
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Copyright (C) 2006-2007 Sun Microsystems, Inc.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * available from http://www.virtualbox.org. This file is free software;
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * you can redistribute it and/or modify it under the terms of the GNU
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * General Public License (GPL) as published by the Free Software
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a16eb14ad7a4b5ef91ddc22d3e8e92d930f736fcvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * additional information or have any questions.
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync * Mouse driver instance data.
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsynctypedef struct DRVMAINMOUSE
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync /** Pointer to the associated mouse driver. */
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync /** Pointer to the driver instance structure. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync /** Pointer to the mouse port interface of the driver/device above us. */
30c39307775310ba50de9d9b74f1ea9e12524102vboxsync /** Our mouse connector interface. */
f5e53763b0a581b0299e98028c6c52192eb06785vboxsync/** Converts PDMIMOUSECONNECTOR pointer to a DRVMAINMOUSE pointer. */
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync#define PDMIMOUSECONNECTOR_2_MAINMOUSE(pInterface) ( (PDRVMAINMOUSE) ((uintptr_t)pInterface - RT_OFFSETOF(DRVMAINMOUSE, Connector)) )
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync// IMouse methods
51fe8789a74f6c118894aaa12eb69ec155386dbdvboxsync/////////////////////////////////////////////////////////////////////////////
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsyncint Mouse::setNeedsHostCursor(bool fNeedsHostCursor)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync uHostCaps = enable ? 0 : VMMDEV_MOUSEHOSTCANNOTHWPOINTER;
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Send a mouse event.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * @returns COM status code
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * @param dx X movement
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param dy Y movement
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param dz Z movement
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param buttonState The mouse button state
e4f367251aede667a6de69baa54ef9eb5f150871vboxsyncint Mouse::PutMouseEvent(LONG dx, LONG dy, LONG dz, LONG buttonState)
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * This method being called implies that the host no
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * longer wants to use absolute coordinates. If the VMM
5341459ca931b65de60b5af2a4cba6836b6b45cavboxsync * device isn't aware of that yet, tell it.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync int vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, dx, dy, dz, fButtons);
ee4d840f54fd2dcea8a73b1b86d5ec0db370b05dvboxsync * Send an absolute mouse event to the VM. This only works
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * when the required guest support has been installed.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @returns COM status code
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @param x X position (pixel)
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param y Y position (pixel)
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @param dz Z movement
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param buttonState The mouse button state
e4f367251aede667a6de69baa54ef9eb5f150871vboxsyncint Mouse::PutMouseEventAbsolute(LONG x, LONG y, LONG dz, LONG buttonState)
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * This method being called implies that the host no
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * longer wants to use absolute coordinates. If the VMM
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * device isn't aware of that yet, tell it.
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync gVMMDev->SetMouseCapabilities(uHostCaps | VMMDEV_MOUSEHOSTWANTSABS);
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Send the absolute mouse position to the VMM device
16a9adc14900ca18e6909679a579f6833425e030vboxsync int vrc = gVMMDev->SetAbsoluteMouse(mouseXAbs, mouseYAbs);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync // check if the guest actually wants absolute mouse positions
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync vrc = mpDrv->pUpPort->pfnPutEvent(mpDrv->pUpPort, 1, 1, dz, fButtons);
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync/////////////////////////////////////////////////////////////////////////////
61b5982fad4660d0fe3dd6ceba9eda85eb32f7e8vboxsync * Queries an interface to the driver.
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync * @returns Pointer to interface.
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync * @returns NULL if the interface was not supported by the driver.
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync * @param pInterface Pointer to this interface structure.
681fd85cc7cd49e9cf66a917d6ae9ff36eb7d9e9vboxsync * @param enmInterface The requested interface identification.
009d45aa55691312278d41edb20154dc208d9cd8vboxsyncDECLCALLBACK(void *) Mouse::drvQueryInterface(PPDMIBASE pInterface, PDMINTERFACE enmInterface)
e4f367251aede667a6de69baa54ef9eb5f150871vboxsync PPDMDRVINS pDrvIns = PDMIBASE_2_PDMDRV(pInterface);
1741b757f7a570a7e6d48db46c3f4cd50f2ee296vboxsync PDRVMAINMOUSE pDrv = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * Destruct a mouse driver instance.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsync * @returns VBox status.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * @param pDrvIns The driver instance data.
a0240ff4f7663045c848fdbc192ea3d4d9f70a11vboxsyncDECLCALLBACK(void) Mouse::drvDestruct(PPDMDRVINS pDrvIns)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync //PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync LogFlow(("Mouse::drvDestruct: iInstance=%d\n", pDrvIns->iInstance));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Construct a mouse driver instance.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * @returns VBox status.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * @param pDrvIns The driver instance data.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * If the registration structure is needed, pDrvIns->pDrvReg points to it.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * @param pCfgHandle Configuration node handle for the driver. Use this to obtain the configuration
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * of the driver instance. It's also found in pDrvIns->pCfgHandle, but like
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * iInstance it's expected to be used a bit in this function.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsyncDECLCALLBACK(int) Mouse::drvConstruct(PPDMDRVINS pDrvIns, PCFGMNODE pCfgHandle)
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync PDRVMAINMOUSE pData = PDMINS_2_DATA(pDrvIns, PDRVMAINMOUSE);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync LogFlow(("drvMainMouse_Construct: iInstance=%d\n", pDrvIns->iInstance));
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync * Validate configuration.
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync int rc = pDrvIns->pDrvHlp->pfnAttach(pDrvIns, &pBaseIgnore);
d80c85a1bc7317da7d0cd1254fae6a20db039c8cvboxsync AssertMsgFailed(("Configuration error: Not possible to attach anything to this driver!\n"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync pDrvIns->IBase.pfnQueryInterface = Mouse::drvQueryInterface;
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Get the IMousePort interface of the above driver/device.
16a9adc14900ca18e6909679a579f6833425e030vboxsync pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUSE_PORT);
16a9adc14900ca18e6909679a579f6833425e030vboxsync AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
16a9adc14900ca18e6909679a579f6833425e030vboxsync * Get the Mouse object pointer and update the mpDrv member.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync AssertMsgFailed(("Configuration error: No/bad \"Object\" value! rc=%Rrc\n", rc));
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync pData->mpDrv = (Mouse*)pv; /** @todo Check this cast! */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync * Main mouse driver registration record.
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* u32Version */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* szDriverName */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync "MainMouse",
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pszDescription */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync "Main mouse driver (Main as in the API).",
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* fFlags */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* fClass. */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* cMaxInstances */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* cbInstance */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnConstruct */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnDestruct */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnIOCtl */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnPowerOn */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnReset */
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync /* pfnSuspend */
a9d49c8f2b28a72e6a4db86eee91e4569290157bvboxsync /* pfnResume */
1bf495e3eec00dd79cecb6b36ef2a97f422c3737vboxsync /* pfnDetach */