Revision 47e699dc hw/usb-hid.c

b/hw/usb-hid.c
67 67
    int protocol;
68 68
    int idle;
69 69
    int changed;
70
    void *datain_opaque;
71
    void (*datain)(void *);
70 72
} USBHIDState;
71 73

  
72 74
/* mostly the same values as the Bochs USB Mouse device */
......
402 404
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
403 405
};
404 406

  
407
static void usb_hid_changed(USBHIDState *hs)
408
{
409
    hs->changed = 1;
410

  
411
    if (hs->datain)
412
        hs->datain(hs->datain_opaque);
413
}
414

  
405 415
static void usb_mouse_event(void *opaque,
406 416
                            int dx1, int dy1, int dz1, int buttons_state)
407 417
{
......
412 422
    s->dy += dy1;
413 423
    s->dz += dz1;
414 424
    s->buttons_state = buttons_state;
415
    hs->changed = 1;
425

  
426
    usb_hid_changed(hs);
416 427
}
417 428

  
418 429
static void usb_tablet_event(void *opaque,
......
425 436
    s->y = y;
426 437
    s->dz += dz;
427 438
    s->buttons_state = buttons_state;
428
    hs->changed = 1;
439

  
440
    usb_hid_changed(hs);
429 441
}
430 442

  
431 443
static void usb_keyboard_event(void *opaque, int keycode)
......
439 451
    hid_code = usb_hid_usage_keys[key | ((s->modifiers >> 1) & (1 << 7))];
440 452
    s->modifiers &= ~(1 << 8);
441 453

  
442
    hs->changed = 1;
443

  
444 454
    switch (hid_code) {
445 455
    case 0x00:
446 456
        return;
......
465 475
            if (s->key[i] == hid_code) {
466 476
                s->key[i] = s->key[-- s->keys];
467 477
                s->key[s->keys] = 0x00;
468
                return;
478
                usb_hid_changed(hs);
479
                break;
469 480
            }
481
        if (i < 0)
482
            return;
470 483
    } else {
471 484
        for (i = s->keys - 1; i >= 0; i --)
472 485
            if (s->key[i] == hid_code)
473
                return;
474
        if (s->keys < sizeof(s->key))
475
            s->key[s->keys ++] = hid_code;
486
                break;
487
        if (i < 0) {
488
            if (s->keys < sizeof(s->key))
489
                s->key[s->keys ++] = hid_code;
490
        } else
491
            return;
476 492
    }
493

  
494
    usb_hid_changed(hs);
477 495
}
478 496

  
479 497
static inline int int_clamp(int val, int vmin, int vmax)
......
894 912

  
895 913
    return (USBDevice *) s;
896 914
}
915

  
916
void usb_hid_datain_cb(USBDevice *dev, void *opaque, void (*datain)(void *))
917
{
918
    USBHIDState *s = (USBHIDState *)dev;
919

  
920
    s->datain_opaque = opaque;
921
    s->datain = datain;
922
}

Also available in: Unified diff