Revision 869564a9

b/ui/spice-display.c
180 180
    surface.width      = ds_get_width(ssd->ds);
181 181
    surface.height     = ds_get_height(ssd->ds);
182 182
    surface.stride     = -surface.width * 4;
183
    surface.mouse_mode = 0;
183
    surface.mouse_mode = true;
184 184
    surface.flags      = 0;
185 185
    surface.type       = 0;
186 186
    surface.mem        = (intptr_t)ssd->buf;
b/ui/spice-input.c
17 17

  
18 18
#include <stdlib.h>
19 19
#include <stdio.h>
20
#include <stdbool.h>
20 21
#include <string.h>
21 22

  
22 23
#include <spice.h>
......
76 77

  
77 78
/* mouse bits */
78 79

  
79
typedef struct QemuSpiceMouse {
80
    SpiceMouseInstance sin;
81
} QemuSpiceMouse;
80
typedef struct QemuSpicePointer {
81
    SpiceMouseInstance  mouse;
82
    SpiceTabletInstance tablet;
83
    int width, height, x, y;
84
    Notifier mouse_mode;
85
    bool absolute;
86
} QemuSpicePointer;
82 87

  
83 88
static int map_buttons(int spice_buttons)
84 89
{
......
121 126
    .buttons            = mouse_buttons,
122 127
};
123 128

  
129
static void tablet_set_logical_size(SpiceTabletInstance* sin, int width, int height)
130
{
131
    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
132

  
133
    if (height < 16) {
134
        height = 16;
135
    }
136
    if (width < 16) {
137
        width = 16;
138
    }
139
    pointer->width  = width;
140
    pointer->height = height;
141
}
142

  
143
static void tablet_position(SpiceTabletInstance* sin, int x, int y,
144
                            uint32_t buttons_state)
145
{
146
    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
147

  
148
    pointer->x = x * 0x7FFF / (pointer->width - 1);
149
    pointer->y = y * 0x7FFF / (pointer->height - 1);
150
    kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state));
151
}
152

  
153

  
154
static void tablet_wheel(SpiceTabletInstance* sin, int wheel,
155
                         uint32_t buttons_state)
156
{
157
    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
158

  
159
    kbd_mouse_event(pointer->x, pointer->y, wheel, map_buttons(buttons_state));
160
}
161

  
162
static void tablet_buttons(SpiceTabletInstance *sin,
163
                           uint32_t buttons_state)
164
{
165
    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
166

  
167
    kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state));
168
}
169

  
170
static const SpiceTabletInterface tablet_interface = {
171
    .base.type          = SPICE_INTERFACE_TABLET,
172
    .base.description   = "tablet",
173
    .base.major_version = SPICE_INTERFACE_TABLET_MAJOR,
174
    .base.minor_version = SPICE_INTERFACE_TABLET_MINOR,
175
    .set_logical_size   = tablet_set_logical_size,
176
    .position           = tablet_position,
177
    .wheel              = tablet_wheel,
178
    .buttons            = tablet_buttons,
179
};
180

  
181
static void mouse_mode_notifier(Notifier *notifier)
182
{
183
    QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode);
184
    bool is_absolute  = kbd_mouse_is_absolute();
185

  
186
    if (pointer->absolute == is_absolute) {
187
        return;
188
    }
189

  
190
    if (is_absolute) {
191
        qemu_spice_add_interface(&pointer->tablet.base);
192
    } else {
193
        spice_server_remove_interface(&pointer->tablet.base);
194
    }
195
    pointer->absolute = is_absolute;
196
}
197

  
124 198
void qemu_spice_input_init(void)
125 199
{
126 200
    QemuSpiceKbd *kbd;
127
    QemuSpiceMouse *mouse;
201
    QemuSpicePointer *pointer;
128 202

  
129 203
    kbd = qemu_mallocz(sizeof(*kbd));
130 204
    kbd->sin.base.sif = &kbd_interface.base;
131 205
    qemu_spice_add_interface(&kbd->sin.base);
132 206
    qemu_add_led_event_handler(kbd_leds, kbd);
133 207

  
134
    mouse = qemu_mallocz(sizeof(*mouse));
135
    mouse->sin.base.sif = &mouse_interface.base;
136
    qemu_spice_add_interface(&mouse->sin.base);
208
    pointer = qemu_mallocz(sizeof(*pointer));
209
    pointer->mouse.base.sif  = &mouse_interface.base;
210
    pointer->tablet.base.sif = &tablet_interface.base;
211
    qemu_spice_add_interface(&pointer->mouse.base);
212

  
213
    pointer->absolute = false;
214
    pointer->mouse_mode.notify = mouse_mode_notifier;
215
    qemu_add_mouse_mode_change_notifier(&pointer->mouse_mode);
216
    mouse_mode_notifier(&pointer->mouse_mode);
137 217
}

Also available in: Unified diff