kvm-guest-drivers-windows icon indicating copy to clipboard operation
kvm-guest-drivers-windows copied to clipboard

Trouble with touchscreen coordinate offset on Windows

Open vitoo opened this issue 1 year ago • 3 comments

Hello,

It's not a bug, i just need help to understand what i am doing wrong. i use a home made web browser spice client to connect to KVM (version 7) virtual machine I send touchscreen coordinate (mono or multi touch depending on the device i use) with virtio_input_send to a virtio-touchscreen-pci device present on the machine

On windows 10, i installed the virtio driver version : virtio-win-0.1.229 (found on fedora) I can see the "touchscreen device" (ecran tactile in french) in windows devices :

image

Here is the coordinate gap that happen :

https://github.com/virtio-win/kvm-guest-drivers-windows/assets/995694/a507f235-0eb1-4d50-8bb1-8e0394d73f10

How i send the coordinate to the driver :

static void _mts_touch_down(MTSState* mts_state , int tracking_id , int x , int y , int pressure) {
    /* Get first available slot for the new pointer. */
    const int slot_index = _get_available_touch_index();

    /* Make sure there is a place for the pointer. */
    if (slot_index >= 0) {
        /* Initialize pointer's entry. */
        mts_state->tracked_ptr_num++;
        mts_state->tracked_touches[slot_index].tracking_id = tracking_id;
        mts_state->tracked_touches[slot_index].x = x;
        mts_state->tracked_touches[slot_index].y = y;
        mts_state->tracked_touches[slot_index].pressure = pressure;

        if (slot_index != mts_state->current_slot) {
            mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_SLOT , slot_index);
            mts_state->current_slot = slot_index;
        }
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_TRACKING_ID , slot_index);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_POSITION_X , x);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_POSITION_Y , y);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_TOOL_TYPE , MT_TOOL_FINGER);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_PRESSURE , pressure);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_ORIENTATION , 0);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_TOUCH_MAJOR , MTS_TOUCH_AXIS_DEFAULT);
        mt_virtio_input_send(EV_ABS , LINUX_ABS_MT_TOUCH_MINOR , MTS_TOUCH_AXIS_DEFAULT);
    }
    else {
        // DEBUG_INFO("MTS touch count is exceeded.");
        return;
    }
}
/* ----------------------------------------------------------------- */
// Send VirtIO input atomic events
/* ----------------------------------------------------------------- */
int mt_virtio_input_send(unsigned short type , unsigned short code , unsigned int value) {
    if (type != EV_ABS && type != EV_KEY && type != EV_SYN && type != EV_SW) {
        return 0;
    }

    // DEBUG_INFO("android_virtio_input_send: pointer %d active %d",(int)(s_virtio_input_multi_touch!=NULL),s_virtio_input_multi_touch->active);
    if (s_virtio_input_multi_touch) {
        virtio_input_event event;
        event.type = type;
        event.code = code;
        event.value = value;
        // DEBUG_INFO("android_virtio_input_send: type = %d, code = %d, value = %d" , type , code , value);
        virtio_input_send(s_virtio_input_multi_touch , &event);
    }
    return 1;
}

The coordinate were correct on qemu version 5, but only in resolution 720p or under, on qemu 7 there is this offset issue in every resolution

If you have any idea of what i am doing wrong, maybe you can help me Can i find driver logs somewhere? maybe i can add log to the driver and build it ? Thanks a lot !

vitoo avatar Nov 03 '23 16:11 vitoo

@kostyanf14 @ybendito - guys, do you know how to help?

YanVugenfirer avatar Nov 05 '23 14:11 YanVugenfirer

@ivellioscolin maybe you have an idea ? As you worked on the multi-touch

thanks

vitoo avatar Nov 28 '23 14:11 vitoo

@ivellioscolin maybe you have an idea ? As you worked on the multi-touch

thanks

There're several places you may want to check:

  • What's returned from GetAbsAxisInfo.
  • logical/physical min/max, unit, unit exponent on linux host side, if you operate the touch on host.
  • If DPI scaling not 100% on you Windows, how you app handles DPI?
  • Also you could debug in this way:
    • Set same resolution on host (as you did in the guest), move your touch finger to certain place (like bottom, right), see how the descriptor reported.
    • Do the same in guest.
    • Compare the value with the reported to Windows, see if can find any clue.

ivellioscolin avatar Nov 30 '23 05:11 ivellioscolin