VirtualBox

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

Last change on this file since 22589 was 22589, checked in by vboxsync, 16 years ago

Additions/x11/vboxmouse: adjust mouse driver vor XInput 2, contributed by Lubomir Rintel

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 8.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 Atom axis_labels[2] = { 0, 0 };
84 Atom button_labels[2] = { 0, 0 };
85
86 if (!InitValuatorClassDeviceStruct(device, 2,
87#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
88 GetMotionHistory,
89#elif GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
90 axis_labels,
91#endif
92 GetMotionHistorySize(), Absolute))
93 return !Success;
94
95 /* Pretend we have buttons so the server accepts us as a pointing device. */
96 if (!InitButtonClassDeviceStruct(device, 2, /* number of buttons */
97#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
98 button_labels,
99#endif
100 map))
101 return !Success;
102
103 /* Tell the server about the range of axis values we report */
104 xf86InitValuatorAxisStruct(device, 0,
105#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
106 axis_labels[0],
107#endif
108 0 /* min X */, 65536 /* max X */,
109 10000, 0, 10000);
110 xf86InitValuatorDefaults(device, 0);
111
112 xf86InitValuatorAxisStruct(device, 1,
113#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) >= 7
114 axis_labels[1],
115#endif
116 0 /* min Y */, 65536 /* max Y */,
117 10000, 0, 10000);
118 xf86InitValuatorDefaults(device, 1);
119 xf86MotionHistoryAllocate(pInfo);
120
121 return Success;
122}
123
124static int
125VBoxProc(DeviceIntPtr device, int what)
126{
127 InputInfoPtr pInfo;
128 int rc, xrc;
129 uint32_t fFeatures = 0;
130
131 pInfo = device->public.devicePrivate;
132
133 switch (what)
134 {
135 case DEVICE_INIT:
136 xrc = VBoxInit(device);
137 if (xrc != Success) {
138 VbglR3Term();
139 return xrc;
140 }
141 xf86Msg(X_CONFIG, "%s: Mouse Integration associated with screen %d\n",
142 pInfo->name,
143 xf86SetIntOption(pInfo->options, "ScreenNumber", 0));
144 break;
145
146 case DEVICE_ON:
147 xf86Msg(X_INFO, "%s: On.\n", pInfo->name);
148 if (device->public.on)
149 break;
150 /* Tell the host that we want absolute co-ordinates */
151 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
152 if (RT_SUCCESS(rc))
153 rc = VbglR3SetMouseStatus( fFeatures
154 | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
155 | VMMDEV_MOUSE_GUEST_USES_VMMDEV);
156 if (!RT_SUCCESS(rc)) {
157 xf86Msg(X_ERROR, "%s: Failed to switch guest mouse into absolute mode\n",
158 pInfo->name);
159 return !Success;
160 }
161
162 xf86AddEnabledDevice(pInfo);
163 device->public.on = TRUE;
164 break;
165
166 case DEVICE_OFF:
167 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
168 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
169 if (RT_SUCCESS(rc))
170 rc = VbglR3SetMouseStatus( fFeatures
171 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
172 & ~VMMDEV_MOUSE_GUEST_USES_VMMDEV);
173 VbglR3SetMouseStatus(0);
174 xf86RemoveEnabledDevice(pInfo);
175 device->public.on = FALSE;
176 break;
177
178 case DEVICE_CLOSE:
179 VbglR3Term();
180 xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
181 break;
182 }
183
184 return Success;
185}
186
187static int
188VBoxProbe(InputInfoPtr pInfo)
189{
190 int rc = VbglR3Init();
191 if (!RT_SUCCESS(rc)) {
192 xf86Msg(X_ERROR, "%s: Failed to open the VirtualBox device (error %d)\n",
193 pInfo->name, rc);
194 return !Success;
195 }
196
197 return Success;
198}
199
200static InputInfoPtr
201VBoxPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
202{
203 InputInfoPtr pInfo;
204 const char *device;
205
206 if (!(pInfo = xf86AllocateInput(drv, 0)))
207 return NULL;
208
209 /* Initialise the InputInfoRec. */
210 pInfo->name = dev->identifier;
211 pInfo->device_control = VBoxProc;
212 pInfo->read_input = VBoxReadInput;
213 pInfo->conf_idev = dev;
214 /* Unlike evdev, we set this unconditionally, as we don't handle keyboards. */
215 pInfo->type_name = XI_MOUSE;
216 pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
217 XI86_ALWAYS_CORE;
218
219 xf86CollectInputOptions(pInfo, NULL, NULL);
220 xf86ProcessCommonOptions(pInfo, pInfo->options);
221
222 device = xf86CheckStrOption(dev->commonOptions, "Device",
223 "/dev/vboxguest");
224
225 xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
226 do {
227 pInfo->fd = open(device, O_RDWR, 0);
228 }
229 while (pInfo->fd < 0 && errno == EINTR);
230
231 if (pInfo->fd < 0) {
232 xf86Msg(X_ERROR, "Unable to open VirtualBox device \"%s\".\n", device);
233 xf86DeleteInput(pInfo, 0);
234 return NULL;
235 }
236
237 if (VBoxProbe(pInfo) != Success) {
238 xf86DeleteInput(pInfo, 0);
239 return NULL;
240 }
241
242 pInfo->flags |= XI86_CONFIGURED;
243 return pInfo;
244}
245
246_X_EXPORT InputDriverRec VBOXMOUSE = {
247 1,
248 "vboxmouse",
249 NULL,
250 VBoxPreInit,
251 NULL,
252 NULL,
253 0
254};
255
256static pointer
257VBoxPlug(pointer module,
258 pointer options,
259 int *errmaj,
260 int *errmin)
261{
262 xf86AddInputDriver(&VBOXMOUSE, module, 0);
263 xf86Msg(X_CONFIG, "Load address of symbol \"VBOXMOUSE\" is %p\n",
264 (void *)&VBOXMOUSE);
265 return module;
266}
267
268static XF86ModuleVersionInfo VBoxVersionRec =
269{
270 "vboxmouse",
271 "Sun Microsystems Inc.",
272 MODINFOSTRING1,
273 MODINFOSTRING2,
274 0, /* Missing from SDK: XORG_VERSION_CURRENT, */
275 1, 0, 0,
276 ABI_CLASS_XINPUT,
277 ABI_XINPUT_VERSION,
278 MOD_CLASS_XINPUT,
279 {0, 0, 0, 0}
280};
281
282_X_EXPORT XF86ModuleData vboxmouseModuleData =
283{
284 &VBoxVersionRec,
285 VBoxPlug,
286 NULL
287};
Note: See TracBrowser for help on using the repository browser.

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