[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH 15/15] input: mouse: switch sdl ui to new core
From: |
Gerd Hoffmann |
Subject: |
[Qemu-devel] [RFC PATCH 15/15] input: mouse: switch sdl ui to new core |
Date: |
Thu, 28 Nov 2013 15:30:10 +0100 |
Signed-off-by: Gerd Hoffmann <address@hidden>
---
ui/sdl.c | 65 +++++++++++++++++++++++++++++++++-------------------------------
1 file changed, 34 insertions(+), 31 deletions(-)
diff --git a/ui/sdl.c b/ui/sdl.c
index 1b1224a..13076e3 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -357,7 +357,7 @@ static void sdl_hide_cursor(void)
if (!cursor_hide)
return;
- if (kbd_mouse_is_absolute()) {
+ if (qemu_input_is_absolute()) {
SDL_ShowCursor(1);
SDL_SetCursor(sdl_cursor_hidden);
} else {
@@ -370,10 +370,10 @@ static void sdl_show_cursor(void)
if (!cursor_hide)
return;
- if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+ if (!qemu_input_is_absolute() || !qemu_console_is_graphic(NULL)) {
SDL_ShowCursor(1);
if (guest_cursor &&
- (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+ (gui_grab || qemu_input_is_absolute() || absolute_enabled))
SDL_SetCursor(guest_sprite);
else
SDL_SetCursor(sdl_cursor_normal);
@@ -392,8 +392,9 @@ static void sdl_grab_start(void)
}
if (guest_cursor) {
SDL_SetCursor(guest_sprite);
- if (!kbd_mouse_is_absolute() && !absolute_enabled)
+ if (!qemu_input_is_absolute() && !absolute_enabled) {
SDL_WarpMouse(guest_x, guest_y);
+ }
} else
sdl_hide_cursor();
SDL_WM_GrabInput(SDL_GRAB_ON);
@@ -422,7 +423,7 @@ static void absolute_mouse_grab(void)
static void sdl_mouse_mode_change(Notifier *notify, void *data)
{
- if (kbd_mouse_is_absolute()) {
+ if (qemu_input_is_absolute()) {
if (!absolute_enabled) {
absolute_enabled = 1;
if (qemu_console_is_graphic(NULL)) {
@@ -439,31 +440,32 @@ static void sdl_mouse_mode_change(Notifier *notify, void
*data)
static void sdl_send_mouse_event(int dx, int dy, int dz, int x, int y, int
state)
{
- int buttons = 0;
-
- if (state & SDL_BUTTON(SDL_BUTTON_LEFT)) {
- buttons |= MOUSE_EVENT_LBUTTON;
- }
- if (state & SDL_BUTTON(SDL_BUTTON_RIGHT)) {
- buttons |= MOUSE_EVENT_RBUTTON;
- }
- if (state & SDL_BUTTON(SDL_BUTTON_MIDDLE)) {
- buttons |= MOUSE_EVENT_MBUTTON;
- }
-
- if (kbd_mouse_is_absolute()) {
- dx = x * 0x7FFF / (real_screen->w - 1);
- dy = y * 0x7FFF / (real_screen->h - 1);
+ static uint32_t bmap[INPUT_BUTTON_MAX] = {
+ [INPUT_BUTTON_LEFT] = SDL_BUTTON(SDL_BUTTON_LEFT),
+ [INPUT_BUTTON_MIDDLE] = SDL_BUTTON(SDL_BUTTON_MIDDLE),
+ [INPUT_BUTTON_RIGHT] = SDL_BUTTON(SDL_BUTTON_RIGHT),
+ };
+ static uint32_t prev_state;
+
+ if (prev_state != state) {
+ qemu_input_update_buttons(dcl->con, bmap, prev_state, state);
+ prev_state = state;
+ }
+
+ if (qemu_input_is_absolute()) {
+ qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, x,
+ real_screen->w);
+ qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, y,
+ real_screen->h);
} else if (guest_cursor) {
x -= guest_x;
y -= guest_y;
guest_x += x;
guest_y += y;
- dx = x;
- dy = y;
+ qemu_input_queue_rel(dcl->con, INPUT_AXIS_X, x);
+ qemu_input_queue_rel(dcl->con, INPUT_AXIS_Y, y);
}
-
- kbd_mouse_event(dx, dy, dz, buttons);
+ qemu_input_event_sync();
}
static void sdl_scale(int width, int height)
@@ -691,7 +693,7 @@ static void handle_mousemotion(SDL_Event *ev)
int max_x, max_y;
if (qemu_console_is_graphic(NULL) &&
- (kbd_mouse_is_absolute() || absolute_enabled)) {
+ (qemu_input_is_absolute() || absolute_enabled)) {
max_x = real_screen->w - 1;
max_y = real_screen->h - 1;
if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 ||
@@ -704,7 +706,7 @@ static void handle_mousemotion(SDL_Event *ev)
sdl_grab_start();
}
}
- if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+ if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
ev->motion.x, ev->motion.y, ev->motion.state);
}
@@ -721,7 +723,7 @@ static void handle_mousebutton(SDL_Event *ev)
}
bev = &ev->button;
- if (!gui_grab && !kbd_mouse_is_absolute()) {
+ if (!gui_grab && !qemu_input_is_absolute()) {
if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
/* start grabbing all events */
sdl_grab_start();
@@ -757,7 +759,7 @@ static void handle_activation(SDL_Event *ev)
}
#endif
if (!gui_grab && ev->active.gain && qemu_console_is_graphic(NULL) &&
- (kbd_mouse_is_absolute() || absolute_enabled)) {
+ (qemu_input_is_absolute() || absolute_enabled)) {
absolute_mouse_grab();
}
if (ev->active.state & SDL_APPACTIVE) {
@@ -829,10 +831,11 @@ static void sdl_mouse_warp(DisplayChangeListener *dcl,
if (on) {
if (!guest_cursor)
sdl_show_cursor();
- if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+ if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
SDL_SetCursor(guest_sprite);
- if (!kbd_mouse_is_absolute() && !absolute_enabled)
+ if (!qemu_input_is_absolute() && !absolute_enabled) {
SDL_WarpMouse(x, y);
+ }
}
} else if (gui_grab)
sdl_hide_cursor();
@@ -860,7 +863,7 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
g_free(mask);
if (guest_cursor &&
- (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+ (gui_grab || qemu_input_is_absolute() || absolute_enabled))
SDL_SetCursor(guest_sprite);
}
--
1.8.3.1
- [Qemu-devel] [RFC PATCH 00/15] input: rewrite qemu input layer, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 03/15] input: define event types using qapi, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 13/15] input: mouse: switch legacy handlers to new core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 02/15] input: rename file to legacy, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 01/15] console: export QemuConsole index, width, height, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 05/15] input: keyboard: add helper functions to core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 06/15] input: keyboard: switch legacy handlers to new core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 07/15] input: keyboard: switch qmp_send_key() to new core., Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 15/15] input: mouse: switch sdl ui to new core,
Gerd Hoffmann <=
- [Qemu-devel] [RFC PATCH 10/15] input: mouse: add helpers functions to core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 09/15] input: keyboard: switch sdl ui to new core [wip], Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 12/15] input: mouse: add qemu_input_is_absolute(), Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 14/15] input: mouse: switch gtk ui to new core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 08/15] input: keyboard: switch gtk ui to new core, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 04/15] input: add core bits of the new input layer, Gerd Hoffmann, 2013/11/28
- [Qemu-devel] [RFC PATCH 11/15] input: mouse: add graphic_rotate support, Gerd Hoffmann, 2013/11/28