VirtualBox

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

Last change on this file since 19015 was 18829, checked in by vboxsync, 16 years ago

undo 45832

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.3 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 (krh@redhat.com)
47 * Adam Jackson (ajax@redhat.com)
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 if (!RT_SUCCESS(rc)) {
133 xf86Msg(X_ERROR, "%s: Failed to switch guest mouse into absolute mode\n",
134 pInfo->name);
135 return !Success;
136 }
137
138 xf86AddEnabledDevice(pInfo);
139 device->public.on = TRUE;
140 break;
141
142 case DEVICE_OFF:
143 xf86Msg(X_INFO, "%s: Off.\n", pInfo->name);
144 VbglR3SetMouseStatus(0);
145 xf86RemoveEnabledDevice(pInfo);
146 device->public.on = FALSE;
147 break;
148
149 case DEVICE_CLOSE:
150 VbglR3Term();
151 xf86Msg(X_INFO, "%s: Close\n", pInfo->name);
152 break;
153 }
154
155 return Success;
156}
157
158static int
159VBoxProbe(InputInfoPtr pInfo)
160{
161 int rc = VbglR3Init();
162 if (!RT_SUCCESS(rc)) {
163 xf86Msg(X_ERROR, "%s: Failed to open the VirtualBox device (error %d)\n",
164 pInfo->name, rc);
165 return !Success;
166 }
167
168 return Success;
169}
170
171static InputInfoPtr
172VBoxPreInit(InputDriverPtr drv, IDevPtr dev, int flags)
173{
174 InputInfoPtr pInfo;
175 const char *device;
176
177 if (!(pInfo = xf86AllocateInput(drv, 0)))
178 return NULL;
179
180 /* Initialise the InputInfoRec. */
181 pInfo->name = dev->identifier;
182 pInfo->device_control = VBoxProc;
183 pInfo->read_input = VBoxReadInput;
184 pInfo->conf_idev = dev;
185 /* Unlike evdev, we set this unconditionally, as we don't handle keyboards. */
186 pInfo->type_name = XI_MOUSE;
187 pInfo->flags = XI86_POINTER_CAPABLE | XI86_SEND_DRAG_EVENTS |
188 XI86_ALWAYS_CORE;
189
190 xf86CollectInputOptions(pInfo, NULL, NULL);
191 xf86ProcessCommonOptions(pInfo, pInfo->options);
192
193 device = xf86CheckStrOption(dev->commonOptions, "Device",
194 "/dev/vboxadd");
195
196 xf86Msg(X_CONFIG, "%s: Device: \"%s\"\n", pInfo->name, device);
197 do {
198 pInfo->fd = open(device, O_RDWR, 0);
199 }
200 while (pInfo->fd < 0 && errno == EINTR);
201
202 if (pInfo->fd < 0) {
203 xf86Msg(X_ERROR, "Unable to open VirtualBox device \"%s\".\n", device);
204 xf86DeleteInput(pInfo, 0);
205 return NULL;
206 }
207
208 if (VBoxProbe(pInfo) != Success) {
209 xf86DeleteInput(pInfo, 0);
210 return NULL;
211 }
212
213 pInfo->flags |= XI86_CONFIGURED;
214 return pInfo;
215}
216
217_X_EXPORT InputDriverRec VBOXMOUSE = {
218 1,
219 "vboxmouse",
220 NULL,
221 VBoxPreInit,
222 NULL,
223 NULL,
224 0
225};
226
227static pointer
228VBoxPlug(pointer module,
229 pointer options,
230 int *errmaj,
231 int *errmin)
232{
233 xf86AddInputDriver(&VBOXMOUSE, module, 0);
234 return module;
235}
236
237static XF86ModuleVersionInfo VBoxVersionRec =
238{
239 "vboxmouse",
240 "Sun Microsystems Inc.",
241 MODINFOSTRING1,
242 MODINFOSTRING2,
243 0, /* Missing from SDK: XORG_VERSION_CURRENT, */
244 1, 0, 0,
245 ABI_CLASS_XINPUT,
246 ABI_XINPUT_VERSION,
247 MOD_CLASS_XINPUT,
248 {0, 0, 0, 0}
249};
250
251_X_EXPORT XF86ModuleData vboxmouseModuleData =
252{
253 &VBoxVersionRec,
254 VBoxPlug,
255 NULL
256};
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