MouseImpl.cpp revision 13d7da5a8024cf0b129e07b522d434287013a0d9
/* $Id$ */
/** @file
*
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2008 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#include "MouseImpl.h"
#include "DisplayImpl.h"
#include "VMMDev.h"
#include "Logging.h"
/**
* Mouse driver instance data.
*/
typedef struct DRVMAINMOUSE
{
/** Pointer to the mouse object. */
/** Pointer to the driver instance structure. */
/** Our mouse connector interface. */
/** Converts PDMIMOUSECONNECTOR pointer to a DRVMAINMOUSE pointer. */
#define PDMIMOUSECONNECTOR_2_MAINMOUSE(pInterface) ( (PDRVMAINMOUSE) ((uintptr_t)pInterface - OFFSETOF(DRVMAINMOUSE, Connector)) )
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
mLastAbsX = 0;
mLastAbsY = 0;
return S_OK;
}
void Mouse::FinalRelease()
{
uninit();
}
// public methods only for internal purposes
/////////////////////////////////////////////////////////////////////////////
/**
* Initializes the mouse object.
*
* @returns COM result indicator
* @param parent handle of our parent object
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition NotReady->InInit->Ready */
AutoInitSpan autoInitSpan(this);
#ifdef RT_OS_L4
/* L4 console has no own mouse cursor */
#else
uHostCaps = 0;
#endif
/* Confirm a successful initialization */
return S_OK;
}
/**
* Uninitializes the instance and sets the ready flag to FALSE.
* Called either from FinalRelease() or by the parent when it gets destroyed.
*/
{
LogFlowThisFunc(("\n"));
/* Enclose the state transition Ready->InUninit->NotReady */
AutoUninitSpan autoUninitSpan(this);
if (autoUninitSpan.uninitDone())
return;
if (mpDrv)
}
// IMouse properties
/////////////////////////////////////////////////////////////////////////////
/**
* Returns whether the current setup can accept absolute mouse
* events.
*
* @returns COM status code
* @param absoluteSupported address of result variable
*/
{
if (!absoluteSupported)
return E_POINTER;
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
mParent->getVMMDev()->getVMMDevPort()->pfnQueryMouseCapabilities(mParent->getVMMDev()->getVMMDevPort(), &mouseCaps);
return S_OK;
}
/**
* Returns whether the current setup can accept relative mouse
* events.
*
* @returns COM status code
* @param absoluteSupported address of result variable
*/
{
if (!needsHostCursor)
return E_POINTER;
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
*needsHostCursor = FALSE;
mParent->getVMMDev()->getVMMDevPort()->pfnQueryMouseCapabilities(mParent->getVMMDev()->getVMMDevPort(), &mouseCaps);
return S_OK;
}
// IMouse methods
/////////////////////////////////////////////////////////////////////////////
/**
* Send a mouse event.
*
* @returns COM status code
* @param dx X movement
* @param dy Y movement
* @param dz Z movement
* @param buttonState The mouse button state
*/
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
&mouseCaps);
/*
* This method being called implies that the host no
* longer wants to use absolute coordinates. If the VMM
* device isn't aware of that yet, tell it.
*/
{
}
if (RT_FAILURE(vrc))
tr ("Could not send the mouse event to the virtual mouse (%Rrc)"),
vrc);
return rc;
}
/**
* Send an absolute mouse event to the VM. This only works
* when the required guest support has been installed.
*
* @returns COM status code
* @param x X position (pixel)
* @param y Y position (pixel)
* @param dz Z movement
* @param buttonState The mouse button state
*/
{
AutoCaller autoCaller(this);
AutoWriteLock alock(this);
&mouseCaps);
/*
* This method being called implies that the host wants
* to use absolute coordinates. If the VMM device isn't
* aware of that yet, tell it.
*/
if (!(mouseCaps & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
{
}
/*
* Send the absolute mouse position to the VMM device.
*/
// Check if the guest actually wants absolute mouse positions.
{
/* This is a workaround. In order to alert the Guest Additions to the
* fact that the absolute pointer position has changed, we send a
* a minute movement event to the PS/2 mouse device. But in order
* to avoid the mouse jiggling every time the use clicks, we check to
* see if the position has really changed since the last mouse event.
*/
fButtons);
else
fButtons);
if (RT_FAILURE(vrc))
tr ("Could not send the mouse event to the virtual mouse (%Rrc)"),
vrc);
}
return rc;
}
// private methods
/////////////////////////////////////////////////////////////////////////////
/**
* Queries an interface to the driver.
*
* @returns Pointer to interface.
* @returns NULL if the interface was not supported by the driver.
* @param pInterface Pointer to this interface structure.
* @param enmInterface The requested interface identification.
*/
{
switch (enmInterface)
{
case PDMINTERFACE_BASE:
default:
return NULL;
}
}
/**
* Destruct a mouse driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
{
{
}
}
/**
* Construct a mouse driver instance.
*
* @copydoc FNPDMDRVCONSTRUCT
*/
{
/*
* Validate configuration.
*/
("Configuration error: Not possible to attach anything to this driver!\n"),
/*
* IBase.
*/
/*
*/
pData->pUpPort = (PPDMIMOUSEPORT)pDrvIns->pUpBase->pfnQueryInterface(pDrvIns->pUpBase, PDMINTERFACE_MOUSE_PORT);
{
AssertMsgFailed(("Configuration error: No mouse port interface above!\n"));
return VERR_PDM_MISSING_INTERFACE_ABOVE;
}
/*
* Get the Mouse object pointer and update the mpDrv member.
*/
void *pv;
if (RT_FAILURE(rc))
{
return rc;
}
return VINF_SUCCESS;
}
/**
* Main mouse driver registration record.
*/
{
/* u32Version */
/* szDriverName */
"MainMouse",
/* pszDescription */
"Main mouse driver (Main as in the API).",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVMAINMOUSE),
/* pfnConstruct */
/* pfnDestruct */
/* pfnIOCtl */
NULL,
/* pfnPowerOn */
NULL,
/* pfnReset */
NULL,
/* pfnSuspend */
NULL,
/* pfnResume */
NULL,
/* pfnAttach */
NULL,
/* pfnDetach */
NULL,
/* pfnPowerOff */
NULL,
/* pfnSoftReset */
NULL,
/* u32EndVersion */
};
/* vi: set tabstop=4 shiftwidth=4 expandtab: */