1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync/* $Revision$ */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync/** @file
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * VBoxGuestLibR0 - Mouse Integration.
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync/*
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * Copyright (C) 2012 Oracle Corporation
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * available from http://www.virtualbox.org. This file is free software;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * you can redistribute it and/or modify it under the terms of the GNU
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * General Public License (GPL) as published by the Free Software
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * The contents of this file may alternatively be used under the terms
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * of the Common Development and Distribution License Version 1.0
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * VirtualBox OSE distribution, in which case the provisions of the
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * CDDL are applicable instead of those of the GPL.
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * You may elect to license modified versions of this file under the
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync * terms and conditions of either the GPL or the CDDL or both.
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync#include "VBGLInternal.h"
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync/**
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * Sets the function which is called back on each mouse pointer event. Only
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * one callback can be active at once, so if you need several for any reason
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * you must multiplex yourself. Call backs can be disabled by passing NULL
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * as the function pointer.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @remarks Ring-0.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @returns iprt status code.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @returns VERR_TRY_AGAIN if the main guest driver hasn't finished
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * initialising.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param pfnNotify the function to call back. NULL to disable call backs.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param pvUser user supplied data/cookie to be passed to the function.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsyncDECLVBGL(int) VbglSetMouseNotifyCallback(PFNVBOXGUESTMOUSENOTIFY pfnNotify,
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync void *pvUser)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync{
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync VBoxGuestMouseSetNotifyCallback NotifyCallback;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync VBGLDRIVER *pDriver;
32d32b685d3e1763aedbad8b3680e5ad562f2314vboxsync int rc = vbglGetDriver(&pDriver);
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (RT_FAILURE(rc))
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync NotifyCallback.pfnNotify = pfnNotify;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync NotifyCallback.pvUser = pvUser;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_NOTIFY_CALLBACK,
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync &NotifyCallback, sizeof(NotifyCallback));
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync}
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync/**
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * Retrieve mouse coordinates and features from the host.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @remarks Ring-0.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @returns VBox status code.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param pfFeatures Where to store the mouse features.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param px Where to store the X co-ordinate.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param py Where to store the Y co-ordinate.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsyncDECLVBGL(int) VbglGetMouseStatus(uint32_t *pfFeatures, uint32_t *px,
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync uint32_t *py)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync{
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync VMMDevReqMouseStatus Req;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync VBGLDRIVER *pDriver;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync int rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync rc = vbglGetDriver(&pDriver);
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (RT_FAILURE(rc))
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync vmmdevInitRequest(&Req.header, VMMDevReq_GetMouseStatus);
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync Req.mouseFeatures = 0;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync Req.pointerXPos = 0;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync Req.pointerYPos = 0;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync rc = vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_VMMREQUEST(sizeof(Req)),
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync &Req.header, sizeof(Req));
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (RT_FAILURE(rc))
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return rc;
32d32b685d3e1763aedbad8b3680e5ad562f2314vboxsync if (RT_FAILURE(Req.header.rc))
32d32b685d3e1763aedbad8b3680e5ad562f2314vboxsync return Req.header.rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (pfFeatures)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *pfFeatures = Req.mouseFeatures;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (px)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *px = Req.pointerXPos;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (py)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync *py = Req.pointerYPos;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return VINF_SUCCESS;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync}
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync/**
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * Send mouse features to the host.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @remarks Ring-0.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @returns VBox status code.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync *
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * @param fFeatures Supported mouse pointer features. The main guest driver
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * will mediate different callers and show the host any
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync * feature enabled by any guest caller.
ef78fcbc798650f56698f8978bd4194fcfc55a78vboxsync */
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsyncDECLVBGL(int) VbglSetMouseStatus(uint32_t fFeatures)
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync{
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync VBGLDRIVER *pDriver;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync int rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync rc = vbglGetDriver(&pDriver);
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync if (RT_FAILURE(rc))
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return rc;
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync return vbglDriverIOCtl(pDriver, VBOXGUEST_IOCTL_SET_MOUSE_STATUS,
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync &fFeatures, sizeof(fFeatures));
1b9094e9e0e2b6dc15ba937a7d4b14736aea339evboxsync}