1 | /* $Revision: 42227 $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLibR0 - Mouse Integration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012 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 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | #include "VBGLInternal.h"
|
---|
28 |
|
---|
29 | /**
|
---|
30 | * Sets the function which is called back on each mouse pointer event. Only
|
---|
31 | * one callback can be active at once, so if you need several for any reason
|
---|
32 | * you must multiplex yourself. Call backs can be disabled by passing NULL
|
---|
33 | * as the function pointer.
|
---|
34 | *
|
---|
35 | * @remarks Ring-0.
|
---|
36 | * @returns iprt status code.
|
---|
37 | * @returns VERR_TRY_AGAIN if the main guest driver hasn't finished
|
---|
38 | * initialising.
|
---|
39 | *
|
---|
40 | * @param pfnNotify the function to call back. NULL to disable call backs.
|
---|
41 | * @param pvUser user supplied data/cookie to be passed to the function.
|
---|
42 | */
|
---|
43 | DECLVBGL(int) VbglSetMouseNotifyCallback(PFNVBOXGUESTMOUSENOTIFY pfnNotify,
|
---|
44 | void *pvUser)
|
---|
45 | {
|
---|
46 | VBoxGuestMouseSetNotifyCallback NotifyCallback;
|
---|
47 | VBGLDRIVER *pDriver;
|
---|
48 | int rc;
|
---|
49 |
|
---|
50 | rc = vbglGetDriver(&pDriver);
|
---|
51 | if (RT_FAILURE(rc))
|
---|
52 | return rc;
|
---|
53 | NotifyCallback.pfnNotify = pfnNotify;
|
---|
54 | NotifyCallback.pvUser = pvUser;
|
---|
55 | return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK,
|
---|
56 | &NotifyCallback, sizeof(NotifyCallback));
|
---|
57 | }
|
---|
58 |
|
---|
59 | /**
|
---|
60 | * Retrieve mouse coordinates and features from the host.
|
---|
61 | *
|
---|
62 | * @remarks Ring-0.
|
---|
63 | * @returns VBox status code.
|
---|
64 | *
|
---|
65 | * @param pfFeatures Where to store the mouse features.
|
---|
66 | * @param px Where to store the X co-ordinate.
|
---|
67 | * @param py Where to store the Y co-ordinate.
|
---|
68 | */
|
---|
69 | DECLVBGL(int) VbglGetMouseStatus(uint32_t *pfFeatures, uint32_t *px,
|
---|
70 | uint32_t *py)
|
---|
71 | {
|
---|
72 | VMMDevReqMouseStatus Req;
|
---|
73 | VBGLDRIVER *pDriver;
|
---|
74 | int rc;
|
---|
75 |
|
---|
76 | rc = vbglGetDriver(&pDriver);
|
---|
77 | if (RT_FAILURE(rc))
|
---|
78 | return rc;
|
---|
79 | vmmdevInitRequest(&Req.header, VMMDevReq_GetMouseStatus);
|
---|
80 | Req.mouseFeatures = 0;
|
---|
81 | Req.pointerXPos = 0;
|
---|
82 | Req.pointerYPos = 0;
|
---|
83 | rc = vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(Req)),
|
---|
84 | &Req.header, sizeof(Req));
|
---|
85 | if (RT_FAILURE(rc))
|
---|
86 | return rc;
|
---|
87 | if (pfFeatures)
|
---|
88 | *pfFeatures = Req.mouseFeatures;
|
---|
89 | if (px)
|
---|
90 | *px = Req.pointerXPos;
|
---|
91 | if (py)
|
---|
92 | *py = Req.pointerYPos;
|
---|
93 | return VINF_SUCCESS;
|
---|
94 | }
|
---|
95 |
|
---|
96 | /**
|
---|
97 | * Send mouse features to the host.
|
---|
98 | *
|
---|
99 | * @remarks Ring-0.
|
---|
100 | * @returns VBox status code.
|
---|
101 | *
|
---|
102 | * @param fFeatures Supported mouse pointer features. The main guest driver
|
---|
103 | * will mediate different callers and show the host any
|
---|
104 | * feature enabled by any guest caller.
|
---|
105 | */
|
---|
106 | DECLVBGL(int) VbglSetMouseStatus(uint32_t fFeatures)
|
---|
107 | {
|
---|
108 | VBGLDRIVER *pDriver;
|
---|
109 | int rc;
|
---|
110 |
|
---|
111 | rc = vbglGetDriver(&pDriver);
|
---|
112 | if (RT_FAILURE(rc))
|
---|
113 | return rc;
|
---|
114 | return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_STATUS,
|
---|
115 | &fFeatures, sizeof(fFeatures));
|
---|
116 | }
|
---|