VirtualBox

Changeset 6594 in vbox


Ignore:
Timestamp:
Jan 30, 2008 11:49:57 AM (17 years ago)
Author:
vboxsync
Message:

Additions/x11: merge the Linux and the Solaris code for the mouse driver

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/x11/xmouse/VBoxUtils.c

    r6494 r6594  
    2525#include "compiler.h"
    2626
    27 #ifndef RT_OS_SOLARIS
    28 #include <asm/ioctl.h>
    29 #endif
    30 
    31 #ifdef RT_OS_SOLARIS        /** @todo later Linux should also use R3 lib for this */
    3227int VBoxMouseInit(void)
    3328{
     
    7772    return rc;
    7873}
    79 #else
    80 /* the vboxadd module file handle */
    81 static int g_vboxaddHandle = -1;
    82 /* the request structure */
    83 static VMMDevReqMouseStatus *g_vmmreqMouseStatus = NULL;
    84 
    85 /**
    86  * Initialise mouse integration.  Returns 0 on success and 1 on failure
    87  * (for example, if the VBox kernel module is not loaded).
    88  */
    89 int VBoxMouseInit(void)
    90 {
    91     VMMDevReqMouseStatus req;
    92 
    93     /* return immediately if already initialized */
    94     if (g_vboxaddHandle != -1)
    95         return 0;
    96 
    97     /* open the driver */
    98     g_vboxaddHandle = open(VBOXGUEST_DEVICE_NAME, O_RDWR, 0);
    99     if (g_vboxaddHandle < 0)
    100     {
    101         ErrorF("Unable to open the virtual machine device: %s\n",
    102                strerror(errno));
    103         return 1;
    104     }
    105 
    106     /* prepare the request structure */
    107     g_vmmreqMouseStatus = malloc(vmmdevGetRequestSize(VMMDevReq_GetMouseStatus));
    108     if (!g_vmmreqMouseStatus)
    109     {
    110         ErrorF("Ran out of memory while querying the virtual machine for the mouse capabilities.\n");
    111         return 1;
    112     }
    113     vmmdevInitRequest((VMMDevRequestHeader*)g_vmmreqMouseStatus, VMMDevReq_GetMouseStatus);
    114 
    115     /* tell the host that we want absolute coordinates */
    116     vmmdevInitRequest((VMMDevRequestHeader*)&req, VMMDevReq_SetMouseStatus);
    117     req.mouseFeatures = VBOXGUEST_MOUSE_GUEST_CAN_ABSOLUTE | VBOXGUEST_MOUSE_GUEST_NEEDS_HOST_CURSOR;
    118     req.pointerXPos = 0;
    119     req.pointerYPos = 0;
    120     if (ioctl(g_vboxaddHandle, IOCTL_VBOXGUEST_VMMREQUEST, (void*)&req) < 0)
    121     {
    122         ErrorF("Error sending mouse pointer capabilities to VMM! rc = %d (%s)\n",
    123                errno, strerror(errno));
    124         return 1;
    125     }
    126     /* everything is fine, put out some branding */
    127     xf86Msg(X_INFO, "VirtualBox mouse pointer integration available.\n");
    128     return 0;
    129 }
    130 
    131 /**
    132  * Queries the absolute mouse position from the host.
    133  *
    134  * Returns 0 on success.
    135  * Returns 1 when the host doesn't want absolute coordinates (no coordinates returned)
    136  * Otherwise > 1 which means unsuccessful.
    137  */
    138 int VBoxMouseQueryPosition(unsigned int *abs_x, unsigned int *abs_y)
    139 {
    140     /* If we failed to initialise, say that we don't want absolute co-ordinates. */
    141     if (g_vboxaddHandle < 0)
    142         return 1;
    143     /* perform VMM request */
    144     if (ioctl(g_vboxaddHandle, IOCTL_VBOXGUEST_VMMREQUEST, (void*)g_vmmreqMouseStatus) >= 0)
    145     {
    146         if (VBOX_SUCCESS(g_vmmreqMouseStatus->header.rc))
    147         {
    148             /* does the host want absolute coordinates? */
    149             if (g_vmmreqMouseStatus->mouseFeatures & VBOXGUEST_MOUSE_HOST_CAN_ABSOLUTE)
    150             {
    151                 *abs_x = g_vmmreqMouseStatus->pointerXPos;
    152                 *abs_y = g_vmmreqMouseStatus->pointerYPos;
    153                 return 0;
    154             }
    155             else
    156                 return 1;
    157         }
    158         else
    159         {
    160             ErrorF("Error querying host mouse position! header.rc = %d\n", g_vmmreqMouseStatus->header.rc);
    161         }
    162     }
    163     else
    164     {
    165         ErrorF("Error performing VMM request! errno = %d (%s)\n",
    166                errno, strerror(errno));
    167     }
    168     /* error! */
    169     return 2;
    170 }
    171 
    172 int VBoxMouseFini(void)
    173 {
    174     VMMDevReqMouseStatus req;
    175     /* If we are not initialised, there is nothing to do */
    176     if (g_vboxaddHandle < 0)
    177         return 0;
    178     /* tell VMM that we no longer support absolute mouse handling */
    179     vmmdevInitRequest((VMMDevRequestHeader*)&req, VMMDevReq_SetMouseStatus);
    180     req.mouseFeatures = 0;
    181     req.pointerXPos = 0;
    182     req.pointerYPos = 0;
    183     if (ioctl(g_vboxaddHandle, IOCTL_VBOXGUEST_VMMREQUEST, (void*)&req) < 0)
    184     {
    185         ErrorF("ioctl to vboxadd module failed, rc = %d (%s)\n",
    186                errno, strerror(errno));
    187     }
    188 
    189     free(g_vmmreqMouseStatus);
    190     g_vmmreqMouseStatus = NULL;
    191     close(g_vboxaddHandle);
    192     g_vboxaddHandle = -1;
    193     return 0;
    194 }
    195 #endif  /* !RT_OS_SOLARIS */
    196 
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette