Linuxwacom has swapped CW and CCW definitions

Fuzzy Lai
2009-04-03
2013-05-08
  • Fuzzy  Lai

    Fuzzy Lai - 2009-04-03

    Dear Sir:

    I have installed the latest release on my tablet(Fujitsu T2020, ubuntu 9.04/64bit). Everything seems fine. However, the calibration never hold after installation of the latest development release of Linuxwacom. This is because CW and CCW are swapped to match the definitions of XServer.

    Please refer to https://sourceforge.net/forum/forum.php?thread_id=3157171&forum_id=236871

    I would suggest the following patch:

    --- fjbtndrv-2.0/src/wacom.c    2009-03-18 07:15:15.000000000 +0800
    +++ fjbtndrv-2.0.fuzzylai/src/wacom.c    2009-03-31 14:16:43.806713524 +0800
    @@ -61,6 +61,51 @@
    static WACOMCONFIG *wacom_config;
    static char *devname;

    +#include <stdio.h>
    +#include <stdbool.h>
    +static int wacom_calibrate()
    +{
    +    if(!wacom_config || !devname)
    +        return -1;
    +
    +    char buf[128];
    +    const char *home = getenv("HOME");
    +    sprintf(buf, "%s/.xinitrc", home);
    +    FILE *xinitrc = fopen(buf, "r");
    +    if(!xinitrc) {
    +        debug("[%s] fail to open ~/.xinitrc", __func__);
    +        return -1;
    +    }
    +
    +    bool isCalibrated = false;
    +    int TopX, TopY, BottomX, BottomY;
    +    while(fgets(buf, sizeof(buf) - 1, xinitrc)) {
    +        buf[sizeof(buf) - 1] = '\0';
    +        if(sscanf(buf, "xsetwacom set Stylus topx \&quot;%d\&quot;", &TopX) ||
    +                sscanf(buf, "xsetwacom set Stylus topy \&quot;%d\&quot;", &TopY) ||
    +                sscanf(buf, "xsetwacom set Stylus bottomx \&quot;%d\&quot;", &BottomX) ||
    +                sscanf(buf, "xsetwacom set Stylus bottomy \&quot;%d\&quot;", &BottomY)) {
    +            isCalibrated = true;
    +            continue;
    +        }
    +    }
    +
    +    if(!isCalibrated)
    +        return -1;
    +       
    +    debug("[%s] calibration from .xinitrc has TopX: %u, TopY: %d, BottomX: %d, BottomY: %d", __func__, TopX, TopY, BottomX, BottomY);
    +    WACOMDEVICE * d = CALL(WacomConfigOpenDevice, wacom_config, devname);
    +    if(!d)
    +        return -1;
    +
    +    CALL(WacomConfigSetRawParam, d, XWACOM_PARAM_TOPX, TopX, 0);
    +    CALL(WacomConfigSetRawParam, d, XWACOM_PARAM_TOPY, TopY, 0);
    +    CALL(WacomConfigSetRawParam, d, XWACOM_PARAM_BOTTOMX, BottomX, 0);
    +    CALL(WacomConfigSetRawParam, d, XWACOM_PARAM_BOTTOMY, BottomY, 0);
    +    CALL(WacomConfigCloseDevice, d);
    +    return 0;
    +}
    +
    int wacom_init(Display *display)
    {
         Atom a;
    @@ -128,7 +173,8 @@
             debug("failed to init wacomcfg");
             return -1;
         }
    -
    +   
    +    wacom_calibrate();
         return 0;
    }

    @@ -158,16 +204,16 @@

         switch(rr_rotation) {
             case RR_Rotate_0:
    -            rotation = 0; /* XWACOM_VALUE_ROTATE_NONE */
    +            rotation = ROTATE_NONE; /* XWACOM_VALUE_ROTATE_NONE */
                 break;
             case RR_Rotate_90:
    -            rotation = 2; /* XWACOM_VALUE_ROTATE_CCW */
    +            rotation = ROTATE_CW;     /* XWACOM_VALUE_ROTATE_CW */
                 break;
             case RR_Rotate_180:
    -            rotation = 3; /* XWACOM_VALUE_ROTATE_HALF */
    +            rotation = ROTATE_HALF; /* XWACOM_VALUE_ROTATE_HALF */
                 break;
             case RR_Rotate_270:
    -            rotation = 1; /* XWACOM_VALUE_ROTATE_CW */
    +            rotation = ROTATE_CCW;     /* XWACOM_VALUE_ROTATE_CCW */
                 break;
             default:
                 return;

    ---------------------------------------------------------------------------------------------------------------------------------

    BTW, since some distributions such as gnome/ubuntu never read ~/.xinitrc to reset the calibration(written by wacomcpl), it would be helpful if fscd or fsrotd reads to reset the calibration in wacom_init().

    Besides, including the following script to save and reload calibration before/after suspend/hibernate/resume in the package distribution and install it as /etc/pm/sleep.d/03calibrate.sh(chmod +x) is also a great help. Otherwise, the calibration may got lost at the status of rotation CW on resume from suspend or hibernate.

    #!/usr/bin/env bash
    IFS=$'\n'
    FILE=/tmp/calibration.tmp
    USER=`ps aux | grep "x-session-manager" | grep -v grep | cut -d" " -f1 | head -n 1`
    DISPLAY=:0.0
    XSETWACOM=xsetwacom
    DEVS=`su $USER -c "$XSETWACOM --display $DISPLAY list dev | sed -e 's/ *$//g' -e 's/\(.*\) .*/\1/g' -e 's/ *$//g'"`

    function store_value()
    {
        value=`su $USER -c "$XSETWACOM --display $DISPLAY get $1 $2"`
        echo "$XSETWACOM --display $DISPLAY set $1 $2 $value" >> $FILE
    }

    # Store calibration of all devices
    function store_devices_calibration()
    {
        >$FILE
        for DEV in $DEVS; do
          store_value $DEV "TopX"
          store_value $DEV "TopY"
          store_value $DEV "BottomX"
          store_value $DEV "BottomY"
        done
    }

    # Store calibration of all devices
    function restore_devices_calibration()
    {
        if [[ -e $FILE ]]
        then
        ( sleep 2; su $USER -c "source $FILE")&
        fi
    }

    MODE=$1
    case "$MODE" in
        hibernate|suspend)
        store_devices_calibration
        ;;
        thaw|resume)
        restore_devices_calibration
        ;;
        *) exit $NA
            ;;
    esac

    BR
    Fuzzy Lai

     
    • Fuzzy  Lai

      Fuzzy Lai - 2009-04-05

      Well, about the definitions of CW and CCW, the author of Linuxwacom will deliberate until the next release.
      Just wait...

       
    • Robert Gerlach

      Robert Gerlach - 2009-04-06

      Many Thanks. But I currently thinking of removing the linuxwacom stuff, because the the API is not stable and Debian/Ubuntu don't provide a development package (and won't fix it). It should be possible to handle the wacom rotation by the hook scripts.

      I think it easier to call the calibration stuff by the hook scripts too (and/or by a autostart file). Do you tried it?

      Robert

      PS: I'm a bit busy at the moment, so please     excuse the delays.

       
    • Fuzzy  Lai

      Fuzzy Lai - 2009-04-17

      Yes, the calibration can be read and set with xsetwacom in an autostart file.

      Actually, I think it is the responsibility of Linuxwacom.

      All I wanna do is to organize the tablet related stuff into a user-friendly package for Linux. If all the contributions are always distributed, Linux is never a tablet friendly OS.

      Thanks for your great package.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks