VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/vboxmouse/VBoxUtils.c@ 19276

Last change on this file since 19276 was 17155, checked in by vboxsync, 16 years ago

Additions/x11/vboxmouse: don't spam the X server log if we can't access the VBox device

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.0 KB
Line 
1/** @file
2 *
3 * VirtualBox X11 Additions mouse driver utility functions
4 */
5
6/*
7 * Copyright (C) 2006-2007 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#include <iprt/assert.h>
23#include <VBox/VBoxGuest.h>
24#include "VBoxUtils.h"
25
26#include "xf86.h"
27#define NEED_XF86_TYPES
28#ifdef NO_ANSIC
29# include <errno.h>
30# include <string.h>
31#else
32# include "xf86_ansic.h"
33#endif
34#include "compiler.h"
35
36/**
37 * Have we ever failed to open the VBox device? This is an ugly hack
38 * to prevent the driver from being accessed when it is not open, as
39 * I can't see anywhere good to store additional information in the driver
40 * private data.
41 */
42static Bool gDeviceOpenFailed = FALSE;
43
44int VBoxMouseInit(void)
45{
46 int rc;
47 if (gDeviceOpenFailed)
48 return 1;
49 rc = VbglR3Init();
50 if (RT_FAILURE(rc))
51 {
52 ErrorF("Failed to open the VirtualBox device, falling back to compatibility mouse mode.\n");
53 gDeviceOpenFailed = TRUE;
54 return 1;
55 }
56
57 rc = VbglR3SetMouseStatus(VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE /* | VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR */);
58 if (RT_FAILURE(rc))
59 {
60 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
61 errno, strerror(errno));
62 gDeviceOpenFailed = TRUE;
63 VbglR3Term();
64 return 1;
65 }
66 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
67 return 0;
68}
69
70
71/**
72 * Query the absolute mouse position from the host
73 * @returns VINF_SUCCESS or iprt error if the absolute values could not
74 * be queried, or the host wished to use relative coordinates
75 * @param pcx where to return the pointer X coordinate
76 * @param pxy where to return the pointer Y coordinate
77 */
78int VBoxMouseQueryPosition(unsigned int *pcx, unsigned int *pcy)
79{
80 int rc = VINF_SUCCESS;
81 uint32_t cx, cy, fFeatures;
82
83 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
84 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
85 if (gDeviceOpenFailed)
86 rc = VERR_ACCESS_DENIED;
87 if (RT_SUCCESS(rc))
88 rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy);
89 if ( RT_SUCCESS(rc)
90 && !(fFeatures & VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE))
91 rc = VERR_NOT_SUPPORTED;
92 if (RT_SUCCESS(rc))
93 {
94 *pcx = cx;
95 *pcy = cy;
96 }
97 return rc;
98}
99
100
101int VBoxMouseFini(void)
102{
103 if (gDeviceOpenFailed)
104 return VINF_SUCCESS;
105 int rc = VbglR3SetMouseStatus(0);
106 VbglR3Term();
107 return rc;
108}
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