VirtualBox

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

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

Additions/x11/vboxmouse: don't overwrite mouse status flags we don't change ourselves

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