VBoxUtils.c revision c98fb3e16fcd571a790eab772c0c66173d225205
/** @file
*
* VirtualBox Linux Additions mouse driver utility functions
*/
/*
* Copyright (C) 2006-2007 innotek GmbH
*
* 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 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 <VBox/VBoxGuest.h>
#include "VBoxUtils.h"
#include "xf86.h"
#define NEED_XF86_TYPES
#include "xf86_ansic.h"
#include "compiler.h"
/* 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;
}