MouseImpl.cpp revision 18b7c7af4829f4a9add1d070499b96b8e1e96fdb
/* $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 "AutoCaller.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. */
// 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
uDevCaps = 0;
/* 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);
if (uDevCaps & MOUSE_DEVCAP_ABSOLUTE)
else
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);
if (uDevCaps & MOUSE_DEVCAP_RELATIVE)
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
*/
{
{
if (RT_FAILURE(vrc))
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
*/
{
|| dz
|| dw
|| fButtons != mLastButtons)
{
if (RT_FAILURE(vrc))
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))
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);
if (!(uDevCaps & MOUSE_DEVCAP_ABSOLUTE))
{
/*
* 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 to a value from 0 to 0xffff
*
* @returns COM status value
*/
{
return S_OK;
}
/**
* Convert a Y value in screen co-ordinates 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)
* @param y Y position (pixel)
* @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",
if (mouseXAbs > 0xffff)
if (mouseYAbs > 0xffff)
/* Older guest additions rely on a small phony movement event on the
* PS/2 device to notice absolute events. */
bool fNeedsJiggle = false;
if (uDevCaps & MOUSE_DEVCAP_ABSOLUTE)
else
{
/*
* 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.
*/
}
if (!(uDevCaps & MOUSE_DEVCAP_ABSOLUTE))
{
/* We may need to send a relative event for button information or to
* wake the guest up 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);
}
}
return rc;
}
// private methods
/////////////////////////////////////////////////////////////////////////////
void Mouse::sendMouseCapsCallback(void)
{
? true : fVMMDevCanAbs;
mParent->onMouseCapabilityChange(fAbsSupported, uDevCaps & MOUSE_DEVCAP_RELATIVE, fVMMDevNeedsHostCursor);
}
/**
* @interface_method_impl{PDMIMOUSECONNECTOR,pfnAbsModeChange}
*/
{
if (fEnabled)
else
}
/**
* @interface_method_impl{PDMIBASE,pfnQueryInterface}
*/
{
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, 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;
}
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: */