VirtualBox

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

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

Additions/x11/vboxmouse: don't overwrite mouse status flags we don't change ourselves (X.Org 7.0 to 1.4)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 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 uint32_t fFeatures = 0;
50 if (gDeviceOpenFailed)
51 return 1;
52 rc = VbglR3Init();
53 if (RT_FAILURE(rc))
54 {
55 ErrorF("Failed to open the VirtualBox device, falling back to compatibility mouse mode.\n");
56 gDeviceOpenFailed = TRUE;
57 return 1;
58 }
59
60 rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
61 if (RT_SUCCESS(rc))
62 rc = VbglR3SetMouseStatus( fFeatures
63 | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
64 if (RT_FAILURE(rc))
65 {
66 ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
67 errno, strerror(errno));
68 gDeviceOpenFailed = TRUE;
69 VbglR3Term();
70 return 1;
71 }
72 xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
73 return 0;
74}
75
76
77/**
78 * Query the absolute mouse position from the host
79 * @returns VINF_SUCCESS or iprt error if the absolute values could not
80 * be queried, or the host wished to use relative coordinates
81 * @param pcx where to return the pointer X coordinate
82 * @param pxy where to return the pointer Y coordinate
83 */
84int VBoxMouseQueryPosition(unsigned int *pcx, unsigned int *pcy)
85{
86 int rc = VINF_SUCCESS;
87 uint32_t cx, cy, fFeatures;
88
89 AssertPtrReturn(pcx, VERR_INVALID_PARAMETER);
90 AssertPtrReturn(pcy, VERR_INVALID_PARAMETER);
91 if (gDeviceOpenFailed)
92 rc = VERR_ACCESS_DENIED;
93 if (RT_SUCCESS(rc))
94 rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy);
95 if ( RT_SUCCESS(rc)
96 && !(fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
97 rc = VERR_NOT_SUPPORTED;
98 if (RT_SUCCESS(rc))
99 {
100 *pcx = cx;
101 *pcy = cy;
102 }
103 return rc;
104}
105
106
107int VBoxMouseFini(void)
108{
109 if (gDeviceOpenFailed)
110 return VINF_SUCCESS;
111 uint32_t fFeatures;
112 int rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
113 if (RT_SUCCESS(rc))
114 rc = VbglR3SetMouseStatus( fFeatures
115 & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE);
116 VbglR3Term();
117 return rc;
118}
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