2

I am writing a program to remotely control an arm based device which doesn't have X server running on it. I have a written a small utility to capture mouse events that are sent from the client side and emulate them on the device. For this purpose I am using uinput.

The problem I am facing is that, the cursor on the arm device is at,say (300,300), initially. When I am connecting to the device(using VNC plugin in chrome), the client's mouse pointer on the browser is at, say (100, 100). The gap between the two mouse pointer positions(on the browser and on the device) is 200px diagonally. This gap is maintained all the time. If i move the pointer to the right by 10px (from 100,100 to 110, 100), the mouse pointer on the device is moved from 300,300 to 310,300. I am not sure what could be the reason for it. The only time this issue doesn't happen is when I make sure that both mouse pointers start from the same coordinates initially(like starting from any one corner of the window.

Here is all the uinput related code:

    static char TOUCH_DEVICE[256] = "/dev/uinput";
    struct uinput_user_dev touch_uidev;
    struct input_event moveev[2];
    struct input_event touchev;
    static int touchfd = -1;

    // Opening device
    if((touchfd = open(TOUCH_DEVICE, O_WRONLY | O_NONBLOCK)) == -1)
    {
        printf("cannot open touch device %s\n", TOUCH_DEVICE);
        exit(EXIT_FAILURE);
    }

    printf("Registering event types...\n");
    if(ioctl(touchfd, UI_SET_EVBIT, EV_SYN) < 0)
        die("error: ioctl");
    if(ioctl(touchfd, UI_SET_EVBIT, EV_ABS) < 0)
        die("error: ioctl");
    if(ioctl(touchfd, UI_SET_ABSBIT, ABS_X) < 0)
        die("error: ioctl");
    if(ioctl(touchfd, UI_SET_ABSBIT, ABS_Y) < 0)
        die("error: ioctl");

    memset(&touch_uidev, 0, sizeof(touch_uidev));
    snprintf(touch_uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-mouse");
    touch_uidev.id.bustype = BUS_USB;
    touch_uidev.id.vendor  = 0x1;
    touch_uidev.id.product = 0x1;
    touch_uidev.id.version = 1;
    touch_uidev.absmin[ABS_X] = 0;
    touch_uidev.absmax[ABS_X] = 640;
    touch_uidev.absmin[ABS_Y] = 0;
    touch_uidev.absmax[ABS_Y] = 480;

    if(write(touchfd, &touch_uidev, sizeof(touch_uidev)) < 0)
        die("error: write");

    if(ioctl(touchfd, UI_DEV_CREATE) < 0)
        die("error: ioctl");
    printf("Mouse fd opened successfully.\n");

    //Injecting events
    memset(moveev, 0, sizeof(moveev));
    moveev[0].type = EV_ABS;
    moveev[0].code = ABS_X;
    moveev[0].value = x;
    moveev[1].type = EV_ABS;
    moveev[1].code = ABS_Y;
    moveev[1].value = y;
    if(write(touchfd, moveev, sizeof(moveev)) < 0)
        die("error: write");

    memset(&touchev, 0, sizeof(touchev));
    touchev.type = EV_SYN;
    touchev.code = 0;
    touchev.value = 0;
    if(write(touchfd, &touchev, sizeof(touchev)) < 0)
        die("error: write");

This issue does not happen when the X server is running. I am curious as to what is causing this. Any help is greatly appreciated. Thanks.

Nithyesh
  • 95
  • 6
  • if i understand you correctly this stmt "The only time this issue doesn't happen is when I make sure that both mouse pointers start from the same coordinates initially(like starting from any one corner of the window." , then why don't you set initially (300,300) coordinate to VNC Client? – DrunkenMaster Jan 04 '17 at 06:12
  • On the device, the mouse pointer can be anywhere initially. I tried to move it to (0,0) by injecting a mouse move event to that location after the device has been created by uinput, but the pointer did not move. – Nithyesh Jan 05 '17 at 05:31

0 Answers0