VirtualBox

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

Last change on this file since 21836 was 21227, checked in by vboxsync, 16 years ago

VBoxGuest.h/VMMDev.h/VBoxGuestLib.h usage cleanup.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.1 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 <iprt/err.h>
24#include <VBox/VMMDev.h>
25#include <VBox/VBoxGuestLib.h>
26#include "VBoxUtils.h"
27
28#include "xf86.h"
29#define NEED_XF86_TYPES
30#ifdef NO_ANSIC
31# include <errno.h>
32# include <string.h>
33#else
34# include "xf86_ansic.h"
35#endif
36#include "compiler.h"
37
38/**
39 * Have we ever failed to open the VBox device? This is an ugly hack
40 * to prevent the driver from being accessed when it is not open, as
41 * I can't see anywhere good to store additional information in the driver
42 * private data.
43 */
44static Bool gDeviceOpenFailed = FALSE;
45
46int VBoxMouseInit(void)
47{
48 int rc;
49 if (gDeviceOpenFailed)
50 return 1;
51 rc = VbglR3Init();
52 if (RT_FAILURE(rc))
53 {
54 ErrorF("Failed to open the VirtualBox device, falling back to compatibility mouse mode.\n");
55 gDeviceOpenFailed = TRUE;
56 return 1;
57 }
58
59 rc = VbglR3SetMouseStatus(VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE /* | VMMDEV_MOUSE_GUEST_NEEDS_HOST_CURSOR */);
60 if (RT_FAILURE(rc))
61 {
62 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
63 errno, strerror(errno));
64 gDeviceOpenFailed = TRUE;
65 VbglR3Term();
66 return 1;
67 }
68 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
69 return 0;
70}
71
72
73/**
74 * Query the absolute mouse position from the host
75 * @returns VINF_SUCCESS or iprt error if the absolute values could not
76 * be queried, or the host wished to use relative coordinates
77 * @param pcx where to return the pointer X coordinate
78 * @param pxy where to return the pointer Y coordinate
79 */
80int VBoxMouseQueryPosition(unsigned int *pcx, unsigned int *pcy)
81{
82 int rc = VINF_SUCCESS;
83 uint32_t cx, cy, fFeatures;
84
85 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
86 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
87 if (gDeviceOpenFailed)
88 rc = VERR_ACCESS_DENIED;
89 if (RT_SUCCESS(rc))
90 rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy);
91 if ( RT_SUCCESS(rc)
92 && !(fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
93 rc = VERR_NOT_SUPPORTED;
94 if (RT_SUCCESS(rc))
95 {
96 *pcx = cx;
97 *pcy = cy;
98 }
99 return rc;
100}
101
102
103int VBoxMouseFini(void)
104{
105 if (gDeviceOpenFailed)
106 return VINF_SUCCESS;
107 int rc = VbglR3SetMouseStatus(0);
108 VbglR3Term();
109 return rc;
110}
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