VirtualBox

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

Last change on this file since 38824 was 38648, checked in by vboxsync, 14 years ago

Additions/common and X11: more VBOXGUEST_IOCTL_SET_MOUSE_STATUS adjustments

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