VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxmouse/vboxmouse_15.c@ 21868

Last change on this file since 21868 was 21868, checked in by vboxsync, 15 years ago

Additions/x11: don't report absolute mouse movements to the guest unless mouse integration is enabled

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.6 KB
Line 
1/** @file
2 * VirtualBox X11 Guest Additions, mouse driver for X.Org server 1.5
3 */
4
5/*
6 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
7 *
8 * This file is part of VirtualBox Open Source Edition (OSE), as
9 * available from http://www.virtualbox.org. This file is free software;
10 * you can redistribute it and/or modify it under the terms of the GNU
11 * General Public License (GPL) as published by the Free Software
12 * Foundation, in version 2 as it comes in the "COPYING" file of the
13 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
14 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
15 *
16 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
17 * Clara, CA 95054 USA or visit http://www.sun.com if you need
18 * additional information or have any questions.
19 * --------------------------------------------------------------------
20 *
21 * This code is based on evdev.c from X.Org with the following copyright
22 * and permission notice:
23 *
24 * Copyright © 2004-2008 Red Hat, Inc.
25 *
26 * Permission to use, copy, modify, distribute, and sell this software
27 * and its documentation for any purpose is hereby granted without
28 * fee, provided that the above copyright notice appear in all copies
29 * and that both that copyright notice and this permission notice
30 * appear in supporting documentation, and that the name of Red Hat
31 * not be used in advertising or publicity pertaining to distribution
32 * of the software without specific, written prior permission. Red
33 * Hat makes no representations about the suitability of this software
34 * for any purpose. It is provided "as is" without express or implied
35 * warranty.
36 *
37 * THE AUTHORS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
38 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
39 * NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY SPECIAL, INDIRECT OR
40 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
41 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
42 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
43 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
44 *
45 * Authors:
46 * Kristian Høgsberg ([email protected])
47 * Adam Jackson ([email protected])
48 */
49
50#include <VBox/VMMDev.h>
51#include <VBox/VBoxGuestLib.h>
52#include <iprt/err.h>
53#include <xf86.h>
54#include <xf86Xinput.h>
55#include <exevents.h>
56#include <mipointer.h>
57
58#include <xf86Module.h>
59
60#include <errno.h>
61#include <fcntl.h>
62
63static void
64VBoxReadInput(InputInfoPtr pInfo)
65{
66 uint32_t cx, cy, fFeatures;
67
68 /* The first test here is a workaround for an apparant bug in Xorg Server 1.5 */
69 if ( miPointerGetScreen(pInfo->dev) != NULL
70 && RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy))
71 && (fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
72 /* send absolute movement */
73 xf86PostMotionEvent(pInfo->dev, 1, 0, 2, cx, cy);
74}
75
76static int
77VBoxInit(DeviceIntPtr device)
78{
79 CARD8 map[2] = { 0, 1 };
80 InputInfoPtr pInfo;
81
82 pInfo = device->public.devicePrivate;
83
84 if (!InitValuatorClassDeviceStruct(device, 2,
85#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
86 GetMotionHistory,
87#endif
88 GetMotionHistorySize(), Absolute))
89 return !Success;
90
91 /* Pretend we have buttons so the server accepts us as a pointing device. */
92 if (!InitButtonClassDeviceStruct(device, 2 /* number of buttons */, map))
93 return !Success;
94
95 /* Tell the server about the range of axis values we report */
96 xf86InitValuatorAxisStruct(device, 0, 0 /* min X */, 65536 /* max X */,
97 10000, 0, 10000);
98 xf86InitValuatorDefaults(device, 0);
99
100 xf86InitValuatorAxisStruct(device, 1, 0 /* min Y */, 65536 /* max Y */,
101 10000, 0, 10000);
102 xf86InitValuatorDefaults(device, 1);
103 xf86MotionHistoryAllocate(pInfo);
104
105 return Success;
106}
107
108static int
109VBoxProc(DeviceIntPtr device, int what)
110{
111 InputInfoPtr pInfo;
112 int rc, xrc;
113
114 pInfo = device->public.devicePrivate;
115
116 switch (what)
117 {
118 case DEVICE_INIT:
119 xrc = VBoxInit(device);
120 if (xrc != Success) {
121 VbglR3Term();
122 return xrc;
123 }
124 xf86Msg(X_CONFIG, "%s: Mouse Integration associated with screen %d\n",
125 pInfo->name,
126 xf86SetIntOption(pInfo->options, "ScreenNumber", 0));
127 break;
128
129 case DEVICE_ON:
130 xf86Msg(X_INFO, "%s: On.\n", pInfo->name);
131 if (device->public.on)
132 break;
133 /* Tell the host that we want absolute co-ordinates */
134 rc = VbglR3SetMouseStatus( VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
135 | VMMDEV_MOUSE_GUEST_USES_VMMDEV);
136 if (!RT_SUCCESS(rc)) {
137 xf86Msg(X_ERROR, "%s: Failed to switch guest mouse into absolute mode\n",
138 pInfo->name);
139 return !Success;
140 }
141
142 xf86AddEnabledDevice(pInfo);
143 device->public.on = TRUE;
144 break;
145
146 case DEVICE_OFF:
147 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
148 VbglR3SetMouseStatus(0);
149 xf86RemoveEnabledDevice(pInfo);
150 device->public.on = FALSE;
151 break;
152
153 case DEVICE_CLOSE:
154 VbglR3Term();
155 xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
156 break;
157 }
158
159 return Success;
160}
161
162static int
163VBoxProbe(InputInfoPtr pInfo)
164{
165 int rc = VbglR3Init();
166 if (!RT_SUCCESS(rc)) {
167 xf86Msg(X_ERROR, "%s: Failed to open the VirtualBox device (error %d)\n",
168 pInfo->name, rc);
169 return !Success;
170 }
171
172 return Success;
173}
174
175static InputInfoPtr
176VBoxPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
177{
178 InputInfoPtr pInfo;
179 const char *device;
180
181 if (!(pInfo = xf86AllocateInput(drv, 0)))
182 return NULL;
183
184 /* Initialise the InputInfoRec. */
185 pInfo->name = dev->identifier;
186 pInfo->device_control = VBoxProc;
187 pInfo->read_input = VBoxReadInput;
188 pInfo->conf_idev = dev;
189 /* Unlike evdev, we set this unconditionally, as we don't handle keyboards. */
190 pInfo->type_name = XI_MOUSE;
191 pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
192 XI86_ALWAYS_CORE;
193
194 xf86CollectInputOptions(pInfo, NULL, NULL);
195 xf86ProcessCommonOptions(pInfo, pInfo->options);
196
197 device = xf86CheckStrOption(dev->commonOptions, "Device",
198 "/dev/vboxguest");
199
200 xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
201 do {
202 pInfo->fd = open(device, O_RDWR, 0);
203 }
204 while (pInfo->fd < 0 && errno == EINTR);
205
206 if (pInfo->fd < 0) {
207 xf86Msg(X_ERROR, "Unable to open VirtualBox device \"%s\".\n", device);
208 xf86DeleteInput(pInfo, 0);
209 return NULL;
210 }
211
212 if (VBoxProbe(pInfo) != Success) {
213 xf86DeleteInput(pInfo, 0);
214 return NULL;
215 }
216
217 pInfo->flags |= XI86_CONFIGURED;
218 return pInfo;
219}
220
221_X_EXPORT InputDriverRec VBOXMOUSE = {
222 1,
223 "vboxmouse",
224 NULL,
225 VBoxPreInit,
226 NULL,
227 NULL,
228 0
229};
230
231static pointer
232VBoxPlug(pointer module,
233 pointer options,
234 int *errmaj,
235 int *errmin)
236{
237 xf86AddInputDriver(&VBOXMOUSE, module, 0);
238 xf86Msg(X_CONFIG, "Load address of symbol \"VBOXMOUSE\" is %p\n",
239 (void *)&VBOXMOUSE);
240 return module;
241}
242
243static XF86ModuleVersionInfo VBoxVersionRec =
244{
245 "vboxmouse",
246 "Sun Microsystems Inc.",
247 MODINFOSTRING1,
248 MODINFOSTRING2,
249 0, /* Missing from SDK: XORG_VERSION_CURRENT, */
250 1, 0, 0,
251 ABI_CLASS_XINPUT,
252 ABI_XINPUT_VERSION,
253 MOD_CLASS_XINPUT,
254 {0, 0, 0, 0}
255};
256
257_X_EXPORT XF86ModuleData vboxmouseModuleData =
258{
259 &VBoxVersionRec,
260 VBoxPlug,
261 NULL
262};
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