VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxmouse/VBoxUtils.c@ 34079

Last change on this file since 34079 was 32831, checked in by vboxsync, 14 years ago

VMMDev: renamed two capabilities

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.2 KB
Line 
1/** @file
2 *
3 * VirtualBox X11 Additions mouse driver utility functions
4 */
5
6/*
7 * Copyright (C) 2006-2007 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18#include <iprt/assert.h>
19#include <iprt/err.h>
20#include <VBox/VMMDev.h>
21#include <VBox/VBoxGuestLib.h>
22#include "VBoxUtils.h"
23
24#include "xf86.h"
25#define NEED_XF86_TYPES
26#ifdef NO_ANSIC
27# include <errno.h>
28# include <string.h>
29#else
30# include "xf86_ansic.h"
31#endif
32#include "compiler.h"
33
34/**
35 * Have we ever failed to open the VBox device? This is an ugly hack
36 * to prevent the driver from being accessed when it is not open, as
37 * I can't see anywhere good to store additional information in the driver
38 * private data.
39 */
40static Bool gDeviceOpenFailed = FALSE;
41
42int VBoxMouseInit(void)
43{
44 int rc;
45 uint32_t fFeatures = 0;
46 if (gDeviceOpenFailed)
47 return 1;
48 rc = VbglR3Init();
49 if (RT_FAILURE(rc))
50 {
51 ErrorF("Failed to open the VirtualBox device, falling back to compatibility mouse mode.\n");
52 gDeviceOpenFailed = TRUE;
53 return 1;
54 }
55
56 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
57 if (RT_SUCCESS(rc))
58 rc = VbglR3SetMouseStatus( fFeatures
59 | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
60 if (RT_FAILURE(rc))
61 {
62 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
63 errno, strerror(errno));
64 gDeviceOpenFailed = TRUE;
65 VbglR3Term();
66 return 1;
67 }
68 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
69 return 0;
70}
71
72
73/**
74 * Query the absolute mouse position from the host
75 * @returns VINF_SUCCESS or iprt error if the absolute values could not
76 * be queried, or the host wished to use relative coordinates
77 * @param pcx where to return the pointer X coordinate
78 * @param pxy where to return the pointer Y coordinate
79 */
80int VBoxMouseQueryPosition(unsigned int *pcx, unsigned int *pcy)
81{
82 int rc = VINF_SUCCESS;
83 uint32_t cx, cy, fFeatures;
84
85 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
86 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
87 if (gDeviceOpenFailed)
88 rc = VERR_ACCESS_DENIED;
89 if (RT_SUCCESS(rc))
90 rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy);
91 if ( RT_SUCCESS(rc)
92 && !(fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE))
93 rc = VERR_NOT_SUPPORTED;
94 if (RT_SUCCESS(rc))
95 {
96 *pcx = cx;
97 *pcy = cy;
98 }
99 return rc;
100}
101
102
103int VBoxMouseFini(void)
104{
105 if (gDeviceOpenFailed)
106 return VINF_SUCCESS;
107 uint32_t fFeatures;
108 int rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
109 if (RT_SUCCESS(rc))
110 rc = VbglR3SetMouseStatus( fFeatures
111 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
112 VbglR3Term();
113 return rc;
114}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette