VirtualBox

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

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

Additions: whitespace cleanup

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 9.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 <mipointer.h>
56
57#include <xf86Module.h>
58
59#include <errno.h>
60#include <fcntl.h>
61
62static void
63VBoxReadInput(InputInfoPtr pInfo)
64{
65 uint32_t cx, cy, fFeatures;
66
67 /* The first test here is a workaround for an apparent bug in Xorg Server 1.5 */
68 if (
69#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 2
70 miPointerCurrentScreen() != NULL
71#else
72 miPointerGetScreen(pInfo->dev) != NULL
73#endif
74 && RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy))
75 && (fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
76#if ABI_XINPUT_VERSION == SET_ABI_VERSION(2, 0)
77 /* Bug in the 1.4 X server series - conversion_proc was no longer
78 * called, but the server didn't yet do the conversion itself. */
79 cx = (cx * screenInfo.screens[0]->width) / 65535;
80 cy = (cy * screenInfo.screens[0]->height) / 65535;
81#endif
82 /* send absolute movement */
83 xf86PostMotionEvent(pInfo->dev, 1, 0, 2, cx, cy);
84}
85
86static void
87VBoxPtrCtrlProc(DeviceIntPtr device, PtrCtrl *ctrl)
88{
89 /* Nothing to do, dix handles all settings */
90}
91
92static int
93VBoxInit(DeviceIntPtr device)
94{
95 CARD8 map[2] = { 0, 1 };
96 Atom axis_labels[2] = { 0, 0 };
97 Atom button_labels[2] = { 0, 0 };
98 if (!InitPointerDeviceStruct((DevicePtr)device, map, 2,
99#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
100 button_labels,
101#endif
102#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 2
103 miPointerGetMotionEvents, VBoxPtrCtrlProc,
104 miPointerGetMotionBufferSize()
105#elif GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
106 GetMotionHistory, VBoxPtrCtrlProc,
107 GetMotionHistorySize(), 2 /* Number of axes */
108
109#elif GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 3
110 VBoxPtrCtrlProc, GetMotionHistorySize(),
111 2 /* Number of axes */
112#else
113# error Unsupported version of X.Org
114#endif
115#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
116 , axis_labels
117#endif
118 ))
119 return !Success;
120
121 /* Tell the server about the range of axis values we report */
122#if ABI_XINPUT_VERSION <= SET_ABI_VERSION(2, 0)
123 xf86InitValuatorAxisStruct(device, 0, 0, -1, 1, 0, 1);
124 xf86InitValuatorAxisStruct(device, 1, 0, -1, 1, 0, 1);
125#else
126 xf86InitValuatorAxisStruct(device, 0,
127# if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
128 axis_labels[0],
129# endif
130 0 /* min X */, 65536 /* max X */,
131 10000, 0, 10000);
132
133 xf86InitValuatorAxisStruct(device, 1,
134# if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
135 axis_labels[1],
136# endif
137 0 /* min Y */, 65536 /* max Y */,
138 10000, 0, 10000);
139#endif
140 xf86InitValuatorDefaults(device, 0);
141 xf86InitValuatorDefaults(device, 1);
142 xf86MotionHistoryAllocate(device->public.devicePrivate);
143
144 return Success;
145}
146
147static int
148VBoxProc(DeviceIntPtr device, int what)
149{
150 InputInfoPtr pInfo;
151 int rc, xrc;
152 uint32_t fFeatures = 0;
153
154 pInfo = device->public.devicePrivate;
155
156 switch (what)
157 {
158 case DEVICE_INIT:
159 xrc = VBoxInit(device);
160 if (xrc != Success) {
161 VbglR3Term();
162 return xrc;
163 }
164 break;
165
166 case DEVICE_ON:
167 xf86Msg(X_INFO, "%s: On.\n", pInfo->name);
168 if (device->public.on)
169 break;
170 /* Tell the host that we want absolute co-ordinates */
171 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
172 if (RT_SUCCESS(rc))
173 rc = VbglR3SetMouseStatus( fFeatures
174 | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
175 | VMMDEV_MOUSE_GUEST_USES_VMMDEV);
176 if (!RT_SUCCESS(rc)) {
177 xf86Msg(X_ERROR, "%s: Failed to switch guest mouse into absolute mode\n",
178 pInfo->name);
179 return !Success;
180 }
181
182 xf86AddEnabledDevice(pInfo);
183 device->public.on = TRUE;
184 break;
185
186 case DEVICE_OFF:
187 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
188 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
189 if (RT_SUCCESS(rc))
190 rc = VbglR3SetMouseStatus( fFeatures
191 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
192 & ~VMMDEV_MOUSE_GUEST_USES_VMMDEV);
193 xf86RemoveEnabledDevice(pInfo);
194 device->public.on = FALSE;
195 break;
196
197 case DEVICE_CLOSE:
198 VbglR3Term();
199 xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
200 break;
201 }
202
203 return Success;
204}
205
206static int
207VBoxProbe(InputInfoPtr pInfo)
208{
209 int rc = VbglR3Init();
210 if (!RT_SUCCESS(rc)) {
211 xf86Msg(X_ERROR, "%s: Failed to open the VirtualBox device (error %d)\n",
212 pInfo->name, rc);
213 return !Success;
214 }
215
216 return Success;
217}
218
219static Bool
220VBoxConvert(InputInfoPtr pInfo, int first, int num, int v0, int v1, int v2,
221 int v3, int v4, int v5, int *x, int *y)
222{
223 if (first == 0) {
224 *x = xf86ScaleAxis(v0, 0, screenInfo.screens[0]->width, 0, 65536);
225 *y = xf86ScaleAxis(v1, 0, screenInfo.screens[0]->height, 0, 65536);
226 return TRUE;
227 } else
228 return FALSE;
229}
230
231static InputInfoPtr
232VBoxPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
233{
234 InputInfoPtr pInfo;
235 const char *device;
236
237 if (!(pInfo = xf86AllocateInput(drv, 0)))
238 return NULL;
239
240 /* Initialise the InputInfoRec. */
241 pInfo->name = dev->identifier;
242 pInfo->device_control = VBoxProc;
243 pInfo->read_input = VBoxReadInput;
244 pInfo->conf_idev = dev;
245 /* Unlike evdev, we set this unconditionally, as we don't handle keyboards. */
246 pInfo->type_name = XI_MOUSE;
247 pInfo->conversion_proc = VBoxConvert;
248 pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
249 XI86_ALWAYS_CORE;
250
251 xf86CollectInputOptions(pInfo, NULL, NULL);
252 xf86ProcessCommonOptions(pInfo, pInfo->options);
253
254 device = xf86CheckStrOption(dev->commonOptions, "Device",
255 "/dev/vboxguest");
256
257 xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
258 do {
259 pInfo->fd = open(device, O_RDWR, 0);
260 }
261 while (pInfo->fd < 0 && errno == EINTR);
262
263 if (pInfo->fd < 0) {
264 xf86Msg(X_ERROR, "Unable to open VirtualBox device \"%s\".\n", device);
265 xf86DeleteInput(pInfo, 0);
266 return NULL;
267 }
268
269 if (VBoxProbe(pInfo) != Success) {
270 xf86DeleteInput(pInfo, 0);
271 return NULL;
272 }
273
274 pInfo->flags |= XI86_CONFIGURED;
275 return pInfo;
276}
277
278_X_EXPORT InputDriverRec VBOXMOUSE = {
279 1,
280 "vboxmouse",
281 NULL,
282 VBoxPreInit,
283 NULL,
284 NULL,
285 0
286};
287
288static pointer
289VBoxPlug(pointer module,
290 pointer options,
291 int *errmaj,
292 int *errmin)
293{
294 xf86AddInputDriver(&VBOXMOUSE, module, 0);
295 xf86Msg(X_CONFIG, "Load address of symbol \"VBOXMOUSE\" is %p\n",
296 (void *)&VBOXMOUSE);
297 return module;
298}
299
300static XF86ModuleVersionInfo VBoxVersionRec =
301{
302 "vboxmouse",
303 "Sun Microsystems Inc.",
304 MODINFOSTRING1,
305 MODINFOSTRING2,
306 0, /* Missing from SDK: XORG_VERSION_CURRENT, */
307 1, 0, 0,
308 ABI_CLASS_XINPUT,
309 ABI_XINPUT_VERSION,
310 MOD_CLASS_XINPUT,
311 {0, 0, 0, 0}
312};
313
314_X_EXPORT XF86ModuleData vboxmouseModuleData =
315{
316 &VBoxVersionRec,
317 VBoxPlug,
318 NULL
319};
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