VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxmouse/VBoxUtils_68.c@ 34310

Last change on this file since 34310 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: 6.0 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 <VBox/VMMDev.h>
20#include <VBox/VBoxGuest.h>
21#include <VBox/VBoxGuestLib.h>
22#include "VBoxUtils.h"
23
24#include "xf86.h"
25#define NEED_XF86_TYPES
26#include "xf86_ansic.h"
27#include "compiler.h"
28
29#ifndef RT_OS_SOLARIS
30# include <asm/ioctl.h>
31#endif
32
33#ifndef RT_OS_LINUX /** @todo later Linux should also use R3 lib for this */
34int VBoxMouseInit(void)
35{
36 int rc = VbglR3Init();
37 if (RT_FAILURE(rc))
38 {
39 ErrorF("VbglR3Init failed.\n");
40 return 1;
41 }
42
43 rc = VbglR3SetMouseStatus(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE | VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR);
44 if (RT_FAILURE(rc))
45 {
46 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
47 errno, strerror(errno));
48 return 1;
49 }
50 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
51 return 0;
52}
53
54
55int VBoxMouseQueryPosition(unsigned int *puAbsXPos, unsigned int *puAbsYPos)
56{
57 int rc;
58 uint32_t pointerXPos;
59 uint32_t pointerYPos;
60
61 AssertPtrReturn(puAbsXPos, VERR_INVALID_PARAMETER);
62 AssertPtrReturn(puAbsYPos, VERR_INVALID_PARAMETER);
63 rc = VbglR3GetMouseStatus(NULL, &pointerXPos, &pointerYPos);
64 if (RT_SUCCESS(rc))
65 {
66 *puAbsXPos = pointerXPos;
67 *puAbsYPos = pointerYPos;
68 return 0;
69 }
70 return 2;
71}
72
73
74int VBoxMouseFini(void)
75{
76 int rc = VbglR3SetMouseStatus(0);
77 VbglR3Term();
78 return rc;
79}
80#else /* RT_OS_LINUX */
81/* the vboxguest module file handle */
82static int g_vboxguestHandle = -1;
83/* the request structure */
84static VMMDevReqMouseStatus *g_vmmreqMouseStatus = NULL;
85
86/**
87 * Initialise mouse integration. Returns 0 on success and 1 on failure
88 * (for example, if the VBox kernel module is not loaded).
89 */
90int VBoxMouseInit(void)
91{
92 VMMDevReqMouseStatus req;
93
94 /* return immediately if already initialized */
95 if (g_vboxguestHandle != -1)
96 return 0;
97
98 /* open the driver */
99 g_vboxguestHandle = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
100 if (g_vboxguestHandle < 0)
101 {
102 ErrorF("Unable to open the virtual machine device: %s\n",
103 strerror(errno));
104 return 1;
105 }
106
107 /* prepare the request structure */
108 g_vmmreqMouseStatus = malloc(vmmdevGetRequestSize(VMMDevReq_GetMouseStatus));
109 if (!g_vmmreqMouseStatus)
110 {
111 ErrorF("Ran out of memory while querying the virtual machine for the mouse capabilities.\n");
112 return 1;
113 }
114 vmmdevInitRequest((VMMDevRequestHeader*)g_vmmreqMouseStatus, VMMDevReq_GetMouseStatus);
115
116 /* tell the host that we want absolute coordinates */
117 vmmdevInitRequest((VMMDevRequestHeader*)&req, VMMDevReq_SetMouseStatus);
118 req.mouseFeatures = VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE | VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR;
119 req.pointerXPos = 0;
120 req.pointerYPos = 0;
121/** @todo r=bird: Michael, I thought we decided a long time ago that all these should be replaced by VbglR3. I assume this is just a leftover... */
122 if (ioctl(g_vboxguestHandle, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(req)), (void*)&req) < 0)
123 {
124 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
125 errno, strerror(errno));
126 return 1;
127 }
128 /* everything is fine, put out some branding */
129 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
130 return 0;
131}
132
133/**
134 * Queries the absolute mouse position from the host.
135 *
136 * Returns 0 on success.
137 * Returns 1 when the host doesn't want absolute coordinates (no coordinates returned)
138 * Otherwise > 1 which means unsuccessful.
139 */
140int VBoxMouseQueryPosition(unsigned int *abs_x, unsigned int *abs_y)
141{
142 /* If we failed to initialise, say that we don't want absolute co-ordinates. */
143 if (g_vboxguestHandle < 0)
144 return 1;
145 /* perform VMM request */
146/** @todo r=bird: Michael, ditto. */
147 if (ioctl(g_vboxguestHandle, VBOXGUEST_IOCTL_VMMREQUEST(vmmdevGetRequestSize(VMMDevReq_GetMouseStatus)), (void*)g_vmmreqMouseStatus) >= 0)
148 {
149 if (RT_SUCCESS(g_vmmreqMouseStatus->header.rc))
150 {
151 /* does the host want absolute coordinates? */
152 if (g_vmmreqMouseStatus->mouseFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE)
153 {
154 *abs_x = g_vmmreqMouseStatus->pointerXPos;
155 *abs_y = g_vmmreqMouseStatus->pointerYPos;
156 return 0;
157 }
158 return 1;
159 }
160 ErrorF("Error querying host mouse position! header.rc = %d\n", g_vmmreqMouseStatus->header.rc);
161 }
162 else
163 {
164 ErrorF("Error performing VMM request! errno = %d (%s)\n",
165 errno, strerror(errno));
166 }
167 /* error! */
168 return 2;
169}
170
171int VBoxMouseFini(void)
172{
173 VMMDevReqMouseStatus req;
174 /* If we are not initialised, there is nothing to do */
175 if (g_vboxguestHandle < 0)
176 return 0;
177 /* tell VMM that we no longer support absolute mouse handling */
178 vmmdevInitRequest((VMMDevRequestHeader*)&req, VMMDevReq_SetMouseStatus);
179 req.mouseFeatures = 0;
180 req.pointerXPos = 0;
181 req.pointerYPos = 0;
182/** @todo r=bird: Michael, ditto. */
183 if (ioctl(g_vboxguestHandle, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(req)), (void*)&req) < 0)
184 {
185 ErrorF("ioctl to vboxguest module failed, rc = %d (%s)\n",
186 errno, strerror(errno));
187 }
188
189 free(g_vmmreqMouseStatus);
190 g_vmmreqMouseStatus = NULL;
191 close(g_vboxguestHandle);
192 g_vboxguestHandle = -1;
193 return 0;
194}
195#endif /* RT_OS_LINUX */
196
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