MouseImpl.cpp revision a126a5a0d184e3245a585414758011d1d095b35f
/* $Id$ */
/** @file
* VirtualBox COM class implementation
*/
/*
* Copyright (C) 2006-2008 Oracle Corporation
*
* 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.
*/
#include "MouseImpl.h"
#include "DisplayImpl.h"
#include "VMMDev.h"
#include "AutoCaller.h"
#include "Logging.h"
/** @name Mouse device capabilities bitfield
* @{ */
enum
{
/** The mouse device can do relative reporting */
/** The mouse device can do absolute reporting */
};
/** @} */
/**
* Mouse driver instance data.
*/
struct DRVMAINMOUSE
{
/** Pointer to the mouse object. */
/** Pointer to the driver instance structure. */
/** Our mouse connector interface. */
/** The capabilities of this device. */
};
// constructor / destructor
/////////////////////////////////////////////////////////////////////////////
{
}
{
}
{
fVMMDevCanAbs = false;
fVMMDevNeedsHostCursor = false;
mLastAbsX = 0x8000;
mLastAbsY = 0x8000;
mLastButtons = 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;
for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
{
if (mpDrv[i])
}
#ifdef VBOXBFE_WITHOUT_COM
#else
#endif
}
// 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);
bool fAbs = false;
if (fVMMDevCanAbs)
for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
return S_OK;
}
/**
* Returns whether the current setup can accept relative mouse
* events.
*
* @returns COM status code
* @param relativeSupported address of result variable
*/
{
if (!relativeSupported)
return E_POINTER;
AutoCaller autoCaller(this);
bool fRel = false;
for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
return S_OK;
}
/**
* Returns whether the guest can currently draw the mouse cursor itself.
*
* @returns COM status code
* @param pfNeedsHostCursor address of result variable
*/
{
if (!pfNeedsHostCursor)
return E_POINTER;
AutoCaller autoCaller(this);
return S_OK;
}
// IMouse methods
/////////////////////////////////////////////////////////////////////////////
{
return fButtons;
}
/**
* Send a relative event to the mouse device.
*
* @returns COM status code
*/
{
{
for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
{
}
if (!pUpPort)
return S_OK;
if (RT_FAILURE(vrc))
return setError(VBOX_E_IPRT_ERROR,
tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
vrc);
}
return S_OK;
}
/**
* Send an absolute position event to the mouse device.
*
* @returns COM status code
*/
{
{
for (unsigned i = 0; !pUpPort && i < MOUSE_MAX_DEVICES; ++i)
{
}
if (!pUpPort)
return S_OK;
if (RT_FAILURE(vrc))
return setError(VBOX_E_IPRT_ERROR,
tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
vrc);
}
return S_OK;
}
/**
* Send an absolute position event to the VMM device.
*
* @returns COM status code
*/
{
{
if (RT_FAILURE(vrc))
return setError(VBOX_E_IPRT_ERROR,
tr("Could not send the mouse event to the virtual mouse (%Rrc)"),
vrc);
}
return S_OK;
}
/**
* 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);
/*
* 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.
*/
{
}
return rc;
}
/**
* Convert an X value in screen co-ordinates (starting from 1) to a value
* from 0 to 0xffff.
*
* @returns COM status value
*/
{
return S_OK;
}
/**
* Convert a Y value in screen co-ordinates (starting from 1) to a value
* from 0 to 0xffff.
*
* @returns COM status value
*/
{
return S_OK;
}
/**
* 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), starting from 1
* @param y Y position (pixel), starting from 1
* @param dz Z movement
* @param buttonState The mouse button state
*/
{
AutoCaller autoCaller(this);
LogRel3(("%s: x=%d, y=%d, dz=%d, dw=%d, buttonState=0x%x\n",
/** @todo the front end should do this conversion to avoid races */
/**
* @todo multi-monitor Windows guests expect this to be unbounded.
* Understand the issues involved and fix for the rest.
*/
/* if (mouseXAbs > 0xffff)
mouseXAbs = mLastAbsX; */
/* if (mouseYAbs > 0xffff)
mouseYAbs = mLastAbsY; */
/*
* 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))
{
}
if (fVMMDevCanAbs)
{
/*
* Send the absolute mouse position to the VMM device.
*/
/* We may need to send an additional event for button information or
* to wake up older guests to the changed absolute co-ordinates. If
* the event is a pure wake up one, we make sure it contains some
* (possibly phony) event data to make sure it isn't just discarded
* on the way. */
{
fButtons);
}
}
else
return rc;
}
// private methods
/////////////////////////////////////////////////////////////////////////////
void Mouse::sendMouseCapsNotifications(void)
{
bool fAbsDev = false;
bool fRelDev = false;
for (unsigned i = 0; i < MOUSE_MAX_DEVICES; ++i)
if (mpDrv[i])
{
fAbsDev = true;
fRelDev = true;
}
&& fRelDev;
else
fVMMDevCanAbs = false;
/** @todo if this gets called during device initialisation we get an
* error due to VMMDev not being initialised yet. */
}
/**
* @interface_method_impl{PDMIMOUSECONNECTOR,pfnReportModes}
*/
{
if (fRel)
else
if (fAbs)
else
}
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
{
return NULL;
}
/**
* Destruct a mouse driver instance.
*
* @returns VBox status.
* @param pDrvIns The driver instance data.
*/
{
{
{
break;
}
}
}
/**
* 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, PDMIMOUSEPORT_IID);
{
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;
}
unsigned cDev;
{
break;
}
if (cDev == MOUSE_MAX_DEVICES)
return VERR_NO_MORE_HANDLES;
return VINF_SUCCESS;
}
/**
* Main mouse driver registration record.
*/
{
/* u32Version */
/* szName */
"MainMouse",
/* szRCMod */
"",
/* szR0Mod */
"",
/* pszDescription */
"Main mouse driver (Main as in the API).",
/* fFlags */
/* fClass. */
/* cMaxInstances */
~0,
/* cbInstance */
sizeof(DRVMAINMOUSE),
/* pfnConstruct */
/* pfnDestruct */
/* pfnRelocate */
NULL,
/* 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: */