VirtualBox

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

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

VMMDev.h: cleanup.

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