VirtualBox

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

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

Additions/x11: print the address of well know symbols to the Xorg log when our drivers are loaded to help with debugging crashes

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