VirtualBox

Ticket #5791: vboxmouse_fix_for_lenny.diff

File vboxmouse_fix_for_lenny.diff, 3.2 KB (added by Giovanni Toraldo (gionn), 15 years ago)

Patch from Carsten Juttner

  • src/VBox/Additions/x11/vboxmouse/vboxmouse_15.c

    diff --git a/src/VBox/Additions/x11/vboxmouse/vboxmouse_15.c b/src/VBox/Additions/x11/vboxmouse/vboxmouse_15.c
    index 3c9b0e9..f2c4340 100644
    a b  
    5959#include <errno.h>
    6060#include <fcntl.h>
    6161
     62/* replacement for Xorg's xf86ScaleAxis which used to be broken and got the clamp on the
     63   result backwards so all users of this function had to reverse minimum and maximum values.
     64   It was only fixed before Xorg Server 1.6 but was also backported to 1.4 at least by
     65   Debian so there is no safe way to know if the fixed version is in use or not. */
     66static int
     67VBoxScale(InputInfoPtr pInfo, int scaleval, int oMin, int oMax, int iMin, int iMax)
     68{
     69    int iDiff = iMax - iMin;
     70    int oDiff = oMax - oMin;
     71   
     72    /* try to clamp on input already to avoid
     73       incorrect results due to overflow */
     74    if(scaleval > iMax)
     75        return oMax;
     76   
     77    if(scaleval < iMin)
     78        return oMin;
     79
     80   
     81    if(iDiff) {
     82        scaleval = (((scaleval - iMin) * oDiff) / iDiff) + oMin;
     83    } else {
     84        if (pInfo) {
     85            xf86Msg(X_ERROR, "%s:division by zero scaling %d: %d %d on %d %d\n", pInfo->name, scaleval, iMin, iMax, oMin, oMax);
     86        }
     87        scaleval = 0;
     88    }
     89   
     90    if(scaleval > oMax)
     91        scaleval = oMax;
     92   
     93    if(scaleval < oMin)
     94        scaleval = oMin;
     95   
     96    return scaleval;
     97}
     98
    6299static void
    63100VBoxReadInput(InputInfoPtr pInfo)
    64101{
    VBoxReadInput(InputInfoPtr pInfo)  
    72109           miPointerGetScreen(pInfo->dev) != NULL
    73110#endif
    74111        &&  RT_SUCCESS(VbglR3GetMouseStatus(&fFeatures, &cx, &cy))
    75         && (fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE))
     112        && (fFeatures & VMMDEV_MOUSE_HOST_CAN_ABSOLUTE)) {
    76113#if ABI_XINPUT_VERSION == SET_ABI_VERSION(2, 0)
    77         /* Bug in the 1.4 X server series - conversion_proc was no longer
    78          * called, but the server didn't yet do the conversion itself. */
    79         cx = xf86ScaleAxis(cx, 0, screenInfo.screens[0]->width, 0, 65536);
    80         cy = xf86ScaleAxis(cy, 0, screenInfo.screens[0]->height, 0, 65536);
     114            /* Bug in the 1.4 X server series - conversion_proc was no longer
     115             * called, but the server didn't yet do the conversion itself. */
     116            cx = VBoxScale(pInfo, cx, 0, screenInfo.screens[0]->width, 0, 65536);
     117            cy = VBoxScale(pInfo, cy, 0, screenInfo.screens[0]->height, 0, 65536);
    81118#endif
    82         /* send absolute movement */
    83         xf86PostMotionEvent(pInfo->dev, 1, 0, 2, cx, cy);
     119            /* send absolute movement */
     120            xf86PostMotionEvent(pInfo->dev, 1, 0, 2, cx, cy);
     121        }
    84122}
    85123
    86124static void
    VBoxConvert(InputInfoPtr pInfo, int first, int num, int v0, int v1, int v2,  
    229267            int v3, int v4, int v5, int *x, int *y)
    230268{
    231269    if (first == 0) {
    232         *x = xf86ScaleAxis(v0, 0, screenInfo.screens[0]->width, 0, 65536);
    233         *y = xf86ScaleAxis(v1, 0, screenInfo.screens[0]->height, 0, 65536);
     270        *x = VBoxScale(pInfo, v0, 0, screenInfo.screens[0]->width, 0, 65536);
     271        *y = VBoxScale(pInfo, v1, 0, screenInfo.screens[0]->height, 0, 65536);
    234272        return TRUE;
    235273    } else
    236274        return FALSE;

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