spice-input.c (de8f580b2360706d644296c690bb187ece6dc4c1) | spice-input.c (f100db385d604d43332b2aece2db6645c4185e06) |
---|---|
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 * --- 84 unchanged lines hidden (view full) --- 93 spice_server_kbd_leds(&kbd->sin, ledstate); 94} 95 96/* mouse bits */ 97 98typedef struct QemuSpicePointer { 99 SpiceMouseInstance mouse; 100 SpiceTabletInstance tablet; | 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 * --- 84 unchanged lines hidden (view full) --- 93 spice_server_kbd_leds(&kbd->sin, ledstate); 94} 95 96/* mouse bits */ 97 98typedef struct QemuSpicePointer { 99 SpiceMouseInstance mouse; 100 SpiceTabletInstance tablet; |
101 int width, height, x, y; | 101 int width, height; 102 uint32_t last_bmask; |
102 Notifier mouse_mode; 103 bool absolute; 104} QemuSpicePointer; 105 | 103 Notifier mouse_mode; 104 bool absolute; 105} QemuSpicePointer; 106 |
106static int map_buttons(int spice_buttons) | 107static void spice_update_buttons(QemuSpicePointer *pointer, 108 int wheel, uint32_t button_mask) |
107{ | 109{ |
108 int qemu_buttons = 0; | 110 static uint32_t bmap[INPUT_BUTTON_MAX] = { 111 [INPUT_BUTTON_LEFT] = 0x01, 112 [INPUT_BUTTON_MIDDLE] = 0x04, 113 [INPUT_BUTTON_RIGHT] = 0x02, 114 [INPUT_BUTTON_WHEEL_UP] = 0x10, 115 [INPUT_BUTTON_WHEEL_DOWN] = 0x20, 116 }; |
109 | 117 |
110 /* 111 * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this 112 * isn't what we get passed in via interface callbacks for the 113 * middle and right button ... 114 */ 115 if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_LEFT) { 116 qemu_buttons |= MOUSE_EVENT_LBUTTON; | 118 if (wheel < 0) { 119 button_mask |= 0x10; |
117 } | 120 } |
118 if (spice_buttons & 0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) { 119 qemu_buttons |= MOUSE_EVENT_MBUTTON; | 121 if (wheel > 0) { 122 button_mask |= 0x20; |
120 } | 123 } |
121 if (spice_buttons & 0x02 /* SPICE_MOUSE_BUTTON_MASK_RIGHT */) { 122 qemu_buttons |= MOUSE_EVENT_RBUTTON; | 124 125 if (pointer->last_bmask == button_mask) { 126 return; |
123 } | 127 } |
124 return qemu_buttons; | 128 qemu_input_update_buttons(NULL, bmap, pointer->last_bmask, button_mask); 129 pointer->last_bmask = button_mask; |
125} 126 127static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz, 128 uint32_t buttons_state) 129{ | 130} 131 132static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz, 133 uint32_t buttons_state) 134{ |
130 kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state)); | 135 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse); 136 spice_update_buttons(pointer, dz, buttons_state); 137 qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx); 138 qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy); 139 qemu_input_event_sync(); |
131} 132 133static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state) 134{ | 140} 141 142static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state) 143{ |
135 kbd_mouse_event(0, 0, 0, map_buttons(buttons_state)); | 144 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse); 145 spice_update_buttons(pointer, 0, buttons_state); 146 qemu_input_event_sync(); |
136} 137 138static const SpiceMouseInterface mouse_interface = { 139 .base.type = SPICE_INTERFACE_MOUSE, 140 .base.description = "mouse", 141 .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR, 142 .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR, 143 .motion = mouse_motion, --- 14 unchanged lines hidden (view full) --- 158 pointer->height = height; 159} 160 161static void tablet_position(SpiceTabletInstance* sin, int x, int y, 162 uint32_t buttons_state) 163{ 164 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 165 | 147} 148 149static const SpiceMouseInterface mouse_interface = { 150 .base.type = SPICE_INTERFACE_MOUSE, 151 .base.description = "mouse", 152 .base.major_version = SPICE_INTERFACE_MOUSE_MAJOR, 153 .base.minor_version = SPICE_INTERFACE_MOUSE_MINOR, 154 .motion = mouse_motion, --- 14 unchanged lines hidden (view full) --- 169 pointer->height = height; 170} 171 172static void tablet_position(SpiceTabletInstance* sin, int x, int y, 173 uint32_t buttons_state) 174{ 175 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 176 |
166 pointer->x = x * 0x7FFF / (pointer->width - 1); 167 pointer->y = y * 0x7FFF / (pointer->height - 1); 168 kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state)); | 177 spice_update_buttons(pointer, 0, buttons_state); 178 qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, pointer->width); 179 qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, pointer->width); 180 qemu_input_event_sync(); |
169} 170 171 172static void tablet_wheel(SpiceTabletInstance* sin, int wheel, 173 uint32_t buttons_state) 174{ 175 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 176 | 181} 182 183 184static void tablet_wheel(SpiceTabletInstance* sin, int wheel, 185 uint32_t buttons_state) 186{ 187 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 188 |
177 kbd_mouse_event(pointer->x, pointer->y, wheel, map_buttons(buttons_state)); | 189 spice_update_buttons(pointer, wheel, buttons_state); 190 qemu_input_event_sync(); |
178} 179 180static void tablet_buttons(SpiceTabletInstance *sin, 181 uint32_t buttons_state) 182{ 183 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 184 | 191} 192 193static void tablet_buttons(SpiceTabletInstance *sin, 194 uint32_t buttons_state) 195{ 196 QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet); 197 |
185 kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state)); | 198 spice_update_buttons(pointer, 0, buttons_state); 199 qemu_input_event_sync(); |
186} 187 188static const SpiceTabletInterface tablet_interface = { 189 .base.type = SPICE_INTERFACE_TABLET, 190 .base.description = "tablet", 191 .base.major_version = SPICE_INTERFACE_TABLET_MAJOR, 192 .base.minor_version = SPICE_INTERFACE_TABLET_MINOR, 193 .set_logical_size = tablet_set_logical_size, 194 .position = tablet_position, 195 .wheel = tablet_wheel, 196 .buttons = tablet_buttons, 197}; 198 199static void mouse_mode_notifier(Notifier *notifier, void *data) 200{ 201 QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode); | 200} 201 202static const SpiceTabletInterface tablet_interface = { 203 .base.type = SPICE_INTERFACE_TABLET, 204 .base.description = "tablet", 205 .base.major_version = SPICE_INTERFACE_TABLET_MAJOR, 206 .base.minor_version = SPICE_INTERFACE_TABLET_MINOR, 207 .set_logical_size = tablet_set_logical_size, 208 .position = tablet_position, 209 .wheel = tablet_wheel, 210 .buttons = tablet_buttons, 211}; 212 213static void mouse_mode_notifier(Notifier *notifier, void *data) 214{ 215 QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode); |
202 bool is_absolute = kbd_mouse_is_absolute(); | 216 bool is_absolute = qemu_input_is_absolute(); |
203 204 if (pointer->absolute == is_absolute) { 205 return; 206 } 207 208 if (is_absolute) { 209 qemu_spice_add_interface(&pointer->tablet.base); 210 } else { --- 25 unchanged lines hidden --- | 217 218 if (pointer->absolute == is_absolute) { 219 return; 220 } 221 222 if (is_absolute) { 223 qemu_spice_add_interface(&pointer->tablet.base); 224 } else { --- 25 unchanged lines hidden --- |