VirtualBox

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

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

Additions/X.Org 1.5+: report that we can read mouse movement events from VMMDev

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.4 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/VBoxGuest.h>
51#include <xf86.h>
52#include <xf86Xinput.h>
53#include <exevents.h>
54#include <mipointer.h>
55
56#include <xf86Module.h>
57
58#include <errno.h>
59#include <fcntl.h>
60
61static void
62VBoxReadInput(InputInfoPtr pInfo)
63{
64 uint32_t cx, cy, fFeatures;
65
66 /* The first test here is a workaround for an apparant bug in Xorg Server 1.5 */
67 if ( miPointerGetScreen(pInfo->dev) != NULL
68 && RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy)))
69 /* send absolute movement */
70 xf86PostMotionEvent(pInfo->dev, 1, 0, 2, cx, cy);
71}
72
73static int
74VBoxInit(DeviceIntPtr device)
75{
76 CARD8 map[2] = { 0, 1 };
77 InputInfoPtr pInfo;
78
79 pInfo = device->public.devicePrivate;
80
81 if (!InitValuatorClassDeviceStruct(device, 2,
82#if GET_ABI_MAJOR(ABI_XINPUT_VERSION) < 3
83 GetMotionHistory,
84#endif
85 GetMotionHistorySize(), Absolute))
86 return !Success;
87
88 /* Pretend we have buttons so the server accepts us as a pointing device. */
89 if (!InitButtonClassDeviceStruct(device, 2 /* number of buttons */, map))
90 return !Success;
91
92 /* Tell the server about the range of axis values we report */
93 xf86InitValuatorAxisStruct(device, 0, 0 /* min X */, 65536 /* max X */,
94 10000, 0, 10000);
95 xf86InitValuatorDefaults(device, 0);
96
97 xf86InitValuatorAxisStruct(device, 1, 0 /* min Y */, 65536 /* max Y */,
98 10000, 0, 10000);
99 xf86InitValuatorDefaults(device, 1);
100 xf86MotionHistoryAllocate(pInfo);
101
102 return Success;
103}
104
105static int
106VBoxProc(DeviceIntPtr device, int what)
107{
108 InputInfoPtr pInfo;
109 int rc, xrc;
110
111 pInfo = device->public.devicePrivate;
112
113 switch (what)
114 {
115 case DEVICE_INIT:
116 xrc = VBoxInit(device);
117 if (xrc != Success) {
118 VbglR3Term();
119 return xrc;
120 }
121 xf86Msg(X_CONFIG, "%s: Mouse Integration associated with screen %d\n",
122 pInfo->name,
123 xf86SetIntOption(pInfo->options, "ScreenNumber", 0));
124 break;
125
126 case DEVICE_ON:
127 xf86Msg(X_INFO, "%s: On.\n", pInfo->name);
128 if (device->public.on)
129 break;
130 /* Tell the host that we want absolute co-ordinates */
131 rc = VbglR3SetMouseStatus( VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE
132 | VBOXGUEST_MOUSE_GUEST_USES_VMMDEV);
133 if (!RT_SUCCESS(rc)) {
134 xf86Msg(X_ERROR, "%s: Failed to switch guest mouse into absolute mode\n",
135 pInfo->name);
136 return !Success;
137 }
138
139 xf86AddEnabledDevice(pInfo);
140 device->public.on = TRUE;
141 break;
142
143 case DEVICE_OFF:
144 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
145 VbglR3SetMouseStatus(0);
146 xf86RemoveEnabledDevice(pInfo);
147 device->public.on = FALSE;
148 break;
149
150 case DEVICE_CLOSE:
151 VbglR3Term();
152 xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
153 break;
154 }
155
156 return Success;
157}
158
159static int
160VBoxProbe(InputInfoPtr pInfo)
161{
162 int rc = VbglR3Init();
163 if (!RT_SUCCESS(rc)) {
164 xf86Msg(X_ERROR, "%s: Failed to open the VirtualBox device (error %d)\n",
165 pInfo->name, rc);
166 return !Success;
167 }
168
169 return Success;
170}
171
172static InputInfoPtr
173VBoxPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
174{
175 InputInfoPtr pInfo;
176 const char *device;
177
178 if (!(pInfo = xf86AllocateInput(drv, 0)))
179 return NULL;
180
181 /* Initialise the InputInfoRec. */
182 pInfo->name = dev->identifier;
183 pInfo->device_control = VBoxProc;
184 pInfo->read_input = VBoxReadInput;
185 pInfo->conf_idev = dev;
186 /* Unlike evdev, we set this unconditionally, as we don't handle keyboards. */
187 pInfo->type_name = XI_MOUSE;
188 pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
189 XI86_ALWAYS_CORE;
190
191 xf86CollectInputOptions(pInfo, NULL, NULL);
192 xf86ProcessCommonOptions(pInfo, pInfo->options);
193
194 device = xf86CheckStrOption(dev->commonOptions, "Device",
195 "/dev/vboxadd");
196
197 xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
198 do {
199 pInfo->fd = open(device, O_RDWR, 0);
200 }
201 while (pInfo->fd < 0 && errno == EINTR);
202
203 if (pInfo->fd < 0) {
204 xf86Msg(X_ERROR, "Unable to open VirtualBox device \"%s\".\n", device);
205 xf86DeleteInput(pInfo, 0);
206 return NULL;
207 }
208
209 if (VBoxProbe(pInfo) != Success) {
210 xf86DeleteInput(pInfo, 0);
211 return NULL;
212 }
213
214 pInfo->flags |= XI86_CONFIGURED;
215 return pInfo;
216}
217
218_X_EXPORT InputDriverRec VBOXMOUSE = {
219 1,
220 "vboxmouse",
221 NULL,
222 VBoxPreInit,
223 NULL,
224 NULL,
225 0
226};
227
228static pointer
229VBoxPlug(pointer module,
230 pointer options,
231 int *errmaj,
232 int *errmin)
233{
234 xf86AddInputDriver(&VBOXMOUSE, module, 0);
235 return module;
236}
237
238static XF86ModuleVersionInfo VBoxVersionRec =
239{
240 "vboxmouse",
241 "Sun Microsystems Inc.",
242 MODINFOSTRING1,
243 MODINFOSTRING2,
244 0, /* Missing from SDK: XORG_VERSION_CURRENT, */
245 1, 0, 0,
246 ABI_CLASS_XINPUT,
247 ABI_XINPUT_VERSION,
248 MOD_CLASS_XINPUT,
249 {0, 0, 0, 0}
250};
251
252_X_EXPORT XF86ModuleData vboxmouseModuleData =
253{
254 &VBoxVersionRec,
255 VBoxPlug,
256 NULL
257};
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