VBoxUtils_68.c revision b357df727b216b85d4517efecf466a7b14c2e80c
/** @file
*
* VirtualBox X11 Additions mouse driver utility functions
*/
/*
* Copyright (C) 2006-2007 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 <VBox/VBoxGuest.h>
#include "VBoxUtils.h"
#include "xf86.h"
#define NEED_XF86_TYPES
#include "xf86_ansic.h"
#include "compiler.h"
#ifndef RT_OS_SOLARIS
#endif
#ifdef RT_OS_SOLARIS /** @todo later Linux should also use R3 lib for this */
int VBoxMouseInit(void)
{
int rc = VbglR3Init();
if (RT_FAILURE(rc))
{
ErrorF("VbglR3Init failed.\n");
return 1;
}
rc = VbglR3SetMouseStatus(VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE | VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR);
if (VBOX_FAILURE(rc))
{
ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
return 1;
}
return 0;
}
{
int rc;
if (VBOX_SUCCESS(rc))
{
*puAbsXPos = pointerXPos;
*puAbsYPos = pointerYPos;
return 0;
}
return 2;
}
int VBoxMouseFini(void)
{
int rc = VbglR3SetMouseStatus(0);
VbglR3Term();
return rc;
}
#else
/* the vboxadd module file handle */
static int g_vboxaddHandle = -1;
/* the request structure */
/**
* Initialise mouse integration. Returns 0 on success and 1 on failure
* (for example, if the VBox kernel module is not loaded).
*/
int VBoxMouseInit(void)
{
/* return immediately if already initialized */
if (g_vboxaddHandle != -1)
return 0;
/* open the driver */
if (g_vboxaddHandle < 0)
{
ErrorF("Unable to open the virtual machine device: %s\n",
return 1;
}
/* prepare the request structure */
if (!g_vmmreqMouseStatus)
{
ErrorF("Ran out of memory while querying the virtual machine for the mouse capabilities.\n");
return 1;
}
/* tell the host that we want absolute coordinates */
req.pointerXPos = 0;
req.pointerYPos = 0;
{
ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
return 1;
}
/* everything is fine, put out some branding */
return 0;
}
/**
* Queries the absolute mouse position from the host.
*
* Returns 0 on success.
* Returns 1 when the host doesn't want absolute coordinates (no coordinates returned)
* Otherwise > 1 which means unsuccessful.
*/
{
/* If we failed to initialise, say that we don't want absolute co-ordinates. */
if (g_vboxaddHandle < 0)
return 1;
/* perform VMM request */
{
{
/* does the host want absolute coordinates? */
{
return 0;
}
else
return 1;
}
else
{
}
}
else
{
ErrorF("Error performing VMM request! errno = %d (%s)\n",
}
/* error! */
return 2;
}
int VBoxMouseFini(void)
{
/* If we are not initialised, there is nothing to do */
if (g_vboxaddHandle < 0)
return 0;
/* tell VMM that we no longer support absolute mouse handling */
req.mouseFeatures = 0;
req.pointerXPos = 0;
req.pointerYPos = 0;
{
ErrorF("ioctl to vboxadd module failed, rc = %d (%s)\n",
}
g_vboxaddHandle = -1;
return 0;
}
#endif /* !RT_OS_SOLARIS */