VirtualBox

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

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

Additions: Use VBoxGuestLib.h instead of VBoxGuest.h where applicable.

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