spice-input.c (78dd9ac1ca5130ae144a6abe8361a59483a5464b) spice-input.c (869564a9c0f78b1972e1ac51e69cb2016af3b060)
1/*
2 * Copyright (C) 2010 Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) version 3 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdlib.h>
19#include <stdio.h>
1/*
2 * Copyright (C) 2010 Red Hat, Inc.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 or
7 * (at your option) version 3 of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include <stdlib.h>
19#include <stdio.h>
20#include <stdbool.h>
20#include <string.h>
21
22#include <spice.h>
23#include <spice/enums.h>
24
25#include "qemu-common.h"
26#include "qemu-spice.h"
27#include "console.h"

--- 43 unchanged lines hidden (view full) ---

71 if (ledstate & QEMU_CAPS_LOCK_LED) {
72 kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK;
73 }
74 spice_server_kbd_leds(&kbd->sin, ledstate);
75}
76
77/* mouse bits */
78
21#include <string.h>
22
23#include <spice.h>
24#include <spice/enums.h>
25
26#include "qemu-common.h"
27#include "qemu-spice.h"
28#include "console.h"

--- 43 unchanged lines hidden (view full) ---

72 if (ledstate & QEMU_CAPS_LOCK_LED) {
73 kbd->ledstate |= SPICE_KEYBOARD_MODIFIER_FLAGS_CAPS_LOCK;
74 }
75 spice_server_kbd_leds(&kbd->sin, ledstate);
76}
77
78/* mouse bits */
79
79typedef struct QemuSpiceMouse {
80 SpiceMouseInstance sin;
81} QemuSpiceMouse;
80typedef struct QemuSpicePointer {
81 SpiceMouseInstance mouse;
82 SpiceTabletInstance tablet;
83 int width, height, x, y;
84 Notifier mouse_mode;
85 bool absolute;
86} QemuSpicePointer;
82
83static 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

--- 26 unchanged lines hidden (view full) ---

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
87
88static int map_buttons(int spice_buttons)
89{
90 int qemu_buttons = 0;
91
92 /*
93 * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this
94 * isn't what we get passed in via interface callbacks for the

--- 26 unchanged lines hidden (view full) ---

121 .base.type = SPICE_INTERFACE_MOUSE,
122 .base.description = "mouse",
123 .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR,
124 .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR,
125 .motion = mouse_motion,
126 .buttons = mouse_buttons,
127};
128
129static 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
143static 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
154static 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
162static 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
170static 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
181static 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
124void qemu_spice_input_init(void)
125{
126 QemuSpiceKbd *kbd;
198void qemu_spice_input_init(void)
199{
200 QemuSpiceKbd *kbd;
127 QemuSpiceMouse *mouse;
201 QemuSpicePointer *pointer;
128
129 kbd = qemu_mallocz(sizeof(*kbd));
130 kbd->sin.base.sif = &kbd_interface.base;
131 qemu_spice_add_interface(&kbd->sin.base);
132 qemu_add_led_event_handler(kbd_leds, kbd);
133
202
203 kbd = qemu_mallocz(sizeof(*kbd));
204 kbd->sin.base.sif = &kbd_interface.base;
205 qemu_spice_add_interface(&kbd->sin.base);
206 qemu_add_led_event_handler(kbd_leds, kbd);
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}