Revision 78dd9ac1

b/ui/spice-input.c
74 74
    spice_server_kbd_leds(&kbd->sin, ledstate);
75 75
}
76 76

  
77
/* mouse bits */
78

  
79
typedef struct QemuSpiceMouse {
80
    SpiceMouseInstance sin;
81
} QemuSpiceMouse;
82

  
83
static int map_buttons(int spice_buttons)
84
{
85
    int qemu_buttons = 0;
86

  
87
    /*
88
     * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this
89
     * isn't what we get passed in via interface callbacks for the
90
     * middle and right button ...
91
     */
92
    if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_LEFT) {
93
        qemu_buttons |= MOUSE_EVENT_LBUTTON;
94
    }
95
    if (spice_buttons & 0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) {
96
        qemu_buttons |= MOUSE_EVENT_MBUTTON;
97
    }
98
    if (spice_buttons & 0x02 /* SPICE_MOUSE_BUTTON_MASK_RIGHT */) {
99
        qemu_buttons |= MOUSE_EVENT_RBUTTON;
100
    }
101
    return qemu_buttons;
102
}
103

  
104
static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
105
                         uint32_t buttons_state)
106
{
107
    kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state));
108
}
109

  
110
static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state)
111
{
112
    kbd_mouse_event(0, 0, 0, map_buttons(buttons_state));
113
}
114

  
115
static const SpiceMouseInterface mouse_interface = {
116
    .base.type          = SPICE_INTERFACE_MOUSE,
117
    .base.description   = "mouse",
118
    .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR,
119
    .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR,
120
    .motion             = mouse_motion,
121
    .buttons            = mouse_buttons,
122
};
123

  
77 124
void qemu_spice_input_init(void)
78 125
{
79 126
    QemuSpiceKbd *kbd;
127
    QemuSpiceMouse *mouse;
80 128

  
81 129
    kbd = qemu_mallocz(sizeof(*kbd));
82 130
    kbd->sin.base.sif = &kbd_interface.base;
83 131
    qemu_spice_add_interface(&kbd->sin.base);
84 132
    qemu_add_led_event_handler(kbd_leds, kbd);
133

  
134
    mouse = qemu_mallocz(sizeof(*mouse));
135
    mouse->sin.base.sif = &mouse_interface.base;
136
    qemu_spice_add_interface(&mouse->sin.base);
85 137
}

Also available in: Unified diff