VirtualBox

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

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

Additions/x11/vboxmouse: only unset our own mouse status flags on unload

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