1 | /* $Id: VBoxGuestR0LibMouse.cpp 69498 2017-10-28 15:07:25Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxGuestLibR0 - Mouse Integration.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2012-2016 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 |
|
---|
28 | /*********************************************************************************************************************************
|
---|
29 | * Header Files *
|
---|
30 | *********************************************************************************************************************************/
|
---|
31 | #include "VBoxGuestR0LibInternal.h"
|
---|
32 | #ifdef VBGL_VBOXGUEST
|
---|
33 | # error "This file shouldn't be part of the VBoxGuestR0LibBase library that is linked into VBoxGuest. It's client code."
|
---|
34 | #endif
|
---|
35 |
|
---|
36 |
|
---|
37 | /**
|
---|
38 | * Sets the function which is called back on each mouse pointer event. Only
|
---|
39 | * one callback can be active at once, so if you need several for any reason
|
---|
40 | * you must multiplex yourself. Call backs can be disabled by passing NULL
|
---|
41 | * as the function pointer.
|
---|
42 | *
|
---|
43 | * @remarks Ring-0.
|
---|
44 | * @returns iprt status code.
|
---|
45 | * @returns VERR_TRY_AGAIN if the main guest driver hasn't finished
|
---|
46 | * initialising.
|
---|
47 | *
|
---|
48 | * @param pfnNotify the function to call back. NULL to disable call backs.
|
---|
49 | * @param pvUser user supplied data/cookie to be passed to the function.
|
---|
50 | */
|
---|
51 | DECLR0VBGL(int) VbglR0SetMouseNotifyCallback(PFNVBOXGUESTMOUSENOTIFY pfnNotify, void *pvUser)
|
---|
52 | {
|
---|
53 | PVBGLIDCHANDLE pIdcHandle;
|
---|
54 | int rc = vbglR0QueryIdcHandle(&pIdcHandle);
|
---|
55 | if (RT_SUCCESS(rc))
|
---|
56 | {
|
---|
57 | VBGLIOCSETMOUSENOTIFYCALLBACK NotifyCallback;
|
---|
58 | VBGLREQHDR_INIT(&NotifyCallback.Hdr, SET_MOUSE_NOTIFY_CALLBACK);
|
---|
59 | NotifyCallback.u.In.pfnNotify = pfnNotify;
|
---|
60 | NotifyCallback.u.In.pvUser = pvUser;
|
---|
61 | rc = VbglR0IdcCall(pIdcHandle, VBGL_IOCTL_SET_MOUSE_NOTIFY_CALLBACK, &NotifyCallback.Hdr, sizeof(NotifyCallback));
|
---|
62 | }
|
---|
63 | return rc;
|
---|
64 | }
|
---|
65 |
|
---|
66 |
|
---|
67 | /**
|
---|
68 | * Retrieve mouse coordinates and features from the host.
|
---|
69 | *
|
---|
70 | * @remarks Ring-0.
|
---|
71 | * @returns VBox status code.
|
---|
72 | *
|
---|
73 | * @param pfFeatures Where to store the mouse features.
|
---|
74 | * @param px Where to store the X co-ordinate.
|
---|
75 | * @param py Where to store the Y co-ordinate.
|
---|
76 | */
|
---|
77 | DECLR0VBGL(int) VbglR0GetMouseStatus(uint32_t *pfFeatures, uint32_t *px, uint32_t *py)
|
---|
78 | {
|
---|
79 | PVBGLIDCHANDLE pIdcHandle;
|
---|
80 | int rc = vbglR0QueryIdcHandle(&pIdcHandle);
|
---|
81 | if (RT_SUCCESS(rc))
|
---|
82 | {
|
---|
83 | VMMDevReqMouseStatus Req;
|
---|
84 | VMMDEV_REQ_HDR_INIT(&Req.header, sizeof(Req), VMMDevReq_GetMouseStatus);
|
---|
85 | Req.mouseFeatures = 0;
|
---|
86 | Req.pointerXPos = 0;
|
---|
87 | Req.pointerYPos = 0;
|
---|
88 | rc = VbglR0IdcCall(pIdcHandle, VBGL_IOCTL_VMMDEV_REQUEST(sizeof(Req)), (PVBGLREQHDR)&Req.header, sizeof(Req));
|
---|
89 | if (RT_SUCCESS(rc))
|
---|
90 | {
|
---|
91 | if (pfFeatures)
|
---|
92 | *pfFeatures = Req.mouseFeatures;
|
---|
93 | if (px)
|
---|
94 | *px = Req.pointerXPos;
|
---|
95 | if (py)
|
---|
96 | *py = Req.pointerYPos;
|
---|
97 | }
|
---|
98 | }
|
---|
99 | return rc;
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Send mouse features to the host.
|
---|
105 | *
|
---|
106 | * @remarks Ring-0.
|
---|
107 | * @returns VBox status code.
|
---|
108 | *
|
---|
109 | * @param fFeatures Supported mouse pointer features. The main guest driver
|
---|
110 | * will mediate different callers and show the host any
|
---|
111 | * feature enabled by any guest caller.
|
---|
112 | */
|
---|
113 | DECLR0VBGL(int) VbglR0SetMouseStatus(uint32_t fFeatures)
|
---|
114 | {
|
---|
115 | PVBGLIDCHANDLE pIdcHandle;
|
---|
116 | int rc = vbglR0QueryIdcHandle(&pIdcHandle);
|
---|
117 | if (RT_SUCCESS(rc))
|
---|
118 | {
|
---|
119 | VBGLIOCSETMOUSESTATUS Req;
|
---|
120 | VBGLREQHDR_INIT(&Req.Hdr, SET_MOUSE_STATUS);
|
---|
121 | Req.u.In.fStatus = fFeatures;
|
---|
122 | rc = VbglR0IdcCall(pIdcHandle, VBGL_IOCTL_SET_MOUSE_STATUS, &Req.Hdr, sizeof(Req));
|
---|
123 | }
|
---|
124 | return rc;
|
---|
125 | }
|
---|
126 |
|
---|