All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support
@ 2013-12-16 10:48 Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann
                   ` (41 more replies)
  0 siblings, 42 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  Hi,

This patch series features a reworked input layer and sdl2 support.

The input layer moves to a model modeled roughly after the linux
event layer.  It also uses qapi to create all the data types needed.
First, because it is convinient to have all the support code generated,
and also to make it easier to integrate with qmp some day.

Porting work has only be done on the UI side so far.  Input device
emulation is still to be done.

cocoa ui code has been updated, but is totally untested (not even
compiled).  Would be great if someone with macos hardware can give
it a spin, and send fixup patches if needed.

SDL2 consists of dave's original patch with a bunch of cleanups on
top.  Some of the cleanups depend on the new input layer code, thus
the incremental patches are sprinkled all over the patch series for
bisectability reasons.

please review & test,
  Gerd

Dave Airlie (1):
  ui/sdl2 : initial port to SDL 2.0 (v2.0)

Gerd Hoffmann (41):
  sdl2: baum build fix
  sdl2: remove text console logic
  console: export QemuConsole index,width,height
  input: rename file to legacy
  input: qapi: define event types
  input: qapi: add unmapped key
  input: qapi: add pause key
  input: add core bits of the new input layer
  input: keyboard: add helper functions to core
  input: keyboard: switch legacy handlers to new core
  input: keyboard: switch qmp_send_key() to new core.
  input: keyboard: switch gtk ui to new core
  input: keyboard: switch sdl ui to new core
  sdl2: switch keyboard handling to new core
  input: keyboard: switch vnc ui to new core
  input: keyboard: switch spice ui to new core
  input: keyboard: switch curses ui to new core
  input: mouse: add helpers functions to core
  input: mouse: add graphic_rotate support
  input: mouse: add qemu_input_is_absolute()
  input: mouse: switch legacy handlers to new core
  input: mouse: switch gtk ui to new core
  input: mouse: switch sdl ui to new core
  sdl2: switch mouse handling to new core
  input: mouse: switch vnc ui to new core
  input: mouse: switch spice ui to new core
  input: mouse: switch monitor to new core
  input: keyboard: switch cocoa ui to new core [untested]
  input: mouse: switch cocoa ui to new core [untested]
  input: trace events
  input-legacy: remove kbd_put_keycode
  input-legacy: remove kbd_mouse_has_absolute
  input-legacy: remove kbd_mouse_is_absolute
  input-legacy: remove kbd_mouse_event
  input: move mouse mode notifier to new core
  input: add input_mouse_mode tracepoint
  sdl2: simplify keymap handling
  sdl2: codestyle fixups
  input: move qmp_query_mice to new core
  input: move do_mouse_set to new core
  input: remove index_from_keycode (no users)

 backends/baum.c      |   4 +-
 configure            |  23 +-
 include/ui/console.h |  16 +-
 include/ui/input.h   |  56 ++++
 monitor.c            |  31 +-
 qapi-schema.json     |  81 ++++-
 trace-events         |   9 +
 ui/Makefile.objs     |   6 +-
 ui/cocoa.m           |  81 +++--
 ui/console.c         |  24 ++
 ui/curses.c          |  47 +--
 ui/gtk.c             |  77 ++---
 ui/input-legacy.c    | 453 ++++++++++++++++++++++++++++
 ui/input.c           | 684 +++++++++++++++---------------------------
 ui/sdl.c             | 114 ++++---
 ui/sdl2-keymap.h     | 266 +++++++++++++++++
 ui/sdl2.c            | 829 +++++++++++++++++++++++++++++++++++++++++++++++++++
 ui/sdl_keysym.h      |   3 +-
 ui/spice-input.c     |  84 ++++--
 ui/vnc.c             |  71 ++---
 ui/vnc.h             |   1 +
 21 files changed, 2249 insertions(+), 711 deletions(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input-legacy.c
 create mode 100644 ui/sdl2-keymap.h
 create mode 100644 ui/sdl2.c

-- 
1.8.3.1

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0)
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 22:12   ` Stefan Weil
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 02/42] sdl2: baum build fix Gerd Hoffmann
                   ` (40 subsequent siblings)
  41 siblings, 1 reply; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Dave Airlie, Gerd Hoffmann, Anthony Liguori

From: Dave Airlie <airlied@redhat.com>

I've ported the SDL1.2 code over, and rewritten it to use the SDL2 interface.

The biggest changes were in the input handling, where SDL2 has done a major
overhaul, and I've had to include a generated translation file to get from
SDL2 codes back to qemu compatible ones. I'm still not sure how the keyboard
layout code works in qemu, so there may be further work if someone can point
me a test case that works with SDL1.2 and doesn't with SDL2.

Some SDL env vars we used to set are no longer used by SDL2,
Windows, OSX support is untested,

I don't think we can link to SDL1.2 and SDL2 at the same time, so I felt
using --with-sdlabi=2.0 to select the new code should be fine, like how
gtk does it.

v1.1: fix keys in text console
v1.2: fix shutdown, cleanups a bit of code, support ARGB cursor

v2.0: merge the SDL multihead patch into this, g_new the number of consoles
needed, wrap DCL inside per-console structure.

Signed-off-by: Dave Airlie <airlied@redhat.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 configure                    |  23 +-
 ui/Makefile.objs             |   4 +-
 ui/sdl.c                     |   3 +
 ui/sdl2.c                    | 981 +++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2_scancode_translate.h | 260 ++++++++++++
 ui/sdl_keysym.h              |   3 +-
 6 files changed, 1267 insertions(+), 7 deletions(-)
 create mode 100644 ui/sdl2.c
 create mode 100644 ui/sdl2_scancode_translate.h

diff --git a/configure b/configure
index edfea95..88080cc 100755
--- a/configure
+++ b/configure
@@ -172,6 +172,7 @@ fdt=""
 netmap="no"
 pixman=""
 sdl=""
+sdlabi="1.2"
 virtfs=""
 vnc="yes"
 sparse="no"
@@ -323,6 +324,7 @@ query_pkg_config() {
 }
 pkg_config=query_pkg_config
 sdl_config="${SDL_CONFIG-${cross_prefix}sdl-config}"
+sdl2_config="${SDL2_CONFIG-${cross_prefix}sdl2-config}"
 
 # If the user hasn't specified ARFLAGS, default to 'rv', just as make does.
 ARFLAGS="${ARFLAGS-rv}"
@@ -729,6 +731,8 @@ for opt do
   ;;
   --enable-sdl) sdl="yes"
   ;;
+  --with-sdlabi=*) sdlabi="$optarg"
+  ;;
   --disable-qom-cast-debug) qom_cast_debug="no"
   ;;
   --enable-qom-cast-debug) qom_cast_debug="yes"
@@ -1119,6 +1123,7 @@ echo "  --disable-strip          disable stripping binaries"
 echo "  --disable-werror         disable compilation abort on warning"
 echo "  --disable-sdl            disable SDL"
 echo "  --enable-sdl             enable SDL"
+echo "  --with-sdlabi            select preferred SDL ABI 1.2 or 2.0"
 echo "  --disable-gtk            disable gtk UI"
 echo "  --enable-gtk             enable gtk UI"
 echo "  --disable-virtfs         disable VirtFS"
@@ -1789,12 +1794,22 @@ fi
 
 # Look for sdl configuration program (pkg-config or sdl-config).  Try
 # sdl-config even without cross prefix, and favour pkg-config over sdl-config.
-if test "`basename $sdl_config`" != sdl-config && ! has ${sdl_config}; then
-  sdl_config=sdl-config
+
+if test $sdlabi == "2.0"; then
+    sdl_config=$sdl2_config
+    sdlname=sdl2
+    sdlconfigname=sdl2_config
+else
+    sdlname=sdl
+    sdlconfigname=sdl_config
+fi
+
+if test "`basename $sdl_config`" != $sdlconfigname && ! has ${sdl_config}; then
+  sdl_config=$sdlconfigname
 fi
 
-if $pkg_config sdl --exists; then
-  sdlconfig="$pkg_config sdl"
+if $pkg_config $sdlname --exists; then
+  sdlconfig="$pkg_config $sdlname"
   _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
 elif has ${sdl_config}; then
   sdlconfig="$sdl_config"
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index f33be47..721ad37 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -9,12 +9,12 @@ vnc-obj-y += vnc-jobs.o
 
 common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
-common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o
+common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
 common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
 
-$(obj)/sdl.o $(obj)/sdl_zoom.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
+$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
 
 $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS)
diff --git a/ui/sdl.c b/ui/sdl.c
index 9d8583c..736bb95 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -26,6 +26,8 @@
 #undef WIN32_LEAN_AND_MEAN
 
 #include <SDL.h>
+
+#if SDL_MAJOR_VERSION == 1
 #include <SDL_syswm.h>
 
 #include "qemu-common.h"
@@ -966,3 +968,4 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 
     atexit(sdl_cleanup);
 }
+#endif
diff --git a/ui/sdl2.c b/ui/sdl2.c
new file mode 100644
index 0000000..2eb3e9c
--- /dev/null
+++ b/ui/sdl2.c
@@ -0,0 +1,981 @@
+/*
+ * QEMU SDL display driver
+ *
+ * Copyright (c) 2003 Fabrice Bellard
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+/* Ported SDL 1.2 code to 2.0 by Dave Airlie. */
+
+/* Avoid compiler warning because macro is redefined in SDL_syswm.h. */
+#undef WIN32_LEAN_AND_MEAN
+
+#include <SDL.h>
+
+#if SDL_MAJOR_VERSION == 2
+#include <SDL_syswm.h>
+
+#include "qemu-common.h"
+#include "ui/console.h"
+#include "sysemu/sysemu.h"
+#include "x_keymap.h"
+#include "sdl_zoom.h"
+
+#include "sdl2_scancode_translate.h"
+
+static int sdl2_num_outputs;
+static struct sdl2_console_state {
+    DisplayChangeListener dcl;
+    DisplaySurface *surface;
+    SDL_Texture *texture;
+    SDL_Window *real_window;
+    SDL_Renderer *real_renderer;
+    int idx;
+    int last_vm_running; /* per console for caption reasons */
+    int x, y;
+} *sdl2_console;
+
+static SDL_Surface *guest_sprite_surface;
+static int gui_grab; /* if true, all keyboard/mouse events are grabbed */
+
+static bool gui_saved_scaling;
+static int gui_saved_width;
+static int gui_saved_height;
+static int gui_saved_grab;
+static int gui_fullscreen;
+static int gui_noframe;
+static int gui_key_modifier_pressed;
+static int gui_keysym;
+static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
+static uint8_t modifiers_state[256];
+static SDL_Cursor *sdl_cursor_normal;
+static SDL_Cursor *sdl_cursor_hidden;
+static int absolute_enabled = 0;
+static int guest_cursor = 0;
+static int guest_x, guest_y;
+static SDL_Cursor *guest_sprite = NULL;
+static int scaling_active = 0;
+static Notifier mouse_mode_notifier;
+
+static void sdl_update_caption(struct sdl2_console_state *scon);
+
+static struct sdl2_console_state *get_scon_from_window(uint32_t window_id)
+{
+    int i;
+    for (i = 0; i < sdl2_num_outputs; i++) {
+        if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id))
+            return &sdl2_console[i];
+    }
+    return NULL;
+}
+
+static void sdl_update(DisplayChangeListener *dcl,
+                       int x, int y, int w, int h)
+{
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    SDL_Rect rect;
+    DisplaySurface *surf = qemu_console_surface(dcl->con);
+
+    if (!surf)
+        return;
+    if (!scon->texture)
+        return;
+
+    rect.x = x;
+    rect.y = y;
+    rect.w = w;
+    rect.h = h;
+
+    SDL_UpdateTexture(scon->texture, NULL, surface_data(surf),
+                      surface_stride(surf));
+    SDL_RenderCopy(scon->real_renderer, scon->texture, &rect, &rect);
+    SDL_RenderPresent(scon->real_renderer);
+}
+
+static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height, int bpp)
+{
+    int flags;
+
+    if (scon->real_window && scon->real_renderer) {
+        if (width && height) {
+            SDL_RenderSetLogicalSize(scon->real_renderer, width, height);
+       
+            SDL_SetWindowSize(scon->real_window, width, height);
+        } else {
+            SDL_DestroyRenderer(scon->real_renderer);
+            SDL_DestroyWindow(scon->real_window);
+            scon->real_renderer = NULL;
+            scon->real_window = NULL;
+        }
+    } else {
+        if (!width || !height) {
+            return;
+        }
+        flags = 0;
+        if (gui_fullscreen)
+            flags |= SDL_WINDOW_FULLSCREEN;
+        else
+            flags |= SDL_WINDOW_RESIZABLE;
+
+        scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,
+                                             SDL_WINDOWPOS_UNDEFINED,
+                                             width, height, flags);
+        scon->real_renderer = SDL_CreateRenderer(scon->real_window, -1, 0);
+        sdl_update_caption(scon);
+    }
+}
+
+static void sdl_switch(DisplayChangeListener *dcl,
+                       DisplaySurface *new_surface)
+{
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    int format = 0;
+    int idx = scon->idx;
+    DisplaySurface *old_surface = scon->surface;
+
+    /* temporary hack: allows to call sdl_switch to handle scaling changes */
+    if (new_surface) {
+        scon->surface = new_surface;
+    }
+
+    if (!new_surface && idx > 0)
+        scon->surface = NULL;
+
+    if (new_surface == NULL)
+        do_sdl_resize(scon, 0, 0, 0);
+    else
+        do_sdl_resize(scon, surface_width(scon->surface), surface_height(scon->surface), 0);
+
+    if (old_surface && scon->texture) {
+        SDL_DestroyTexture(scon->texture);
+        scon->texture = NULL;
+    }
+
+    if (new_surface) {
+        if (!scon->texture) {
+            if (surface_bits_per_pixel(scon->surface) == 16)
+                format = SDL_PIXELFORMAT_RGB565;
+            else if (surface_bits_per_pixel(scon->surface) == 32)
+                format = SDL_PIXELFORMAT_ARGB8888;
+
+            scon->texture = SDL_CreateTexture(scon->real_renderer, format,
+                                              SDL_TEXTUREACCESS_STREAMING,
+                                              surface_width(new_surface), surface_height(new_surface));
+        }
+    }
+}
+
+/* generic keyboard conversion */
+
+#include "sdl_keysym.h"
+
+static kbd_layout_t *kbd_layout = NULL;
+
+static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
+{
+    int keysym;
+    /* workaround for X11+SDL bug with AltGR */
+    keysym = ev->keysym.sym;
+    if (keysym == 0 && ev->keysym.scancode == 113)
+        keysym = SDLK_MODE;
+    /* For Japanese key '\' and '|' */
+    if (keysym == 92 && ev->keysym.scancode == 133) {
+        keysym = 0xa5;
+    }
+    return keysym2scancode(kbd_layout, keysym) & SCANCODE_KEYMASK;
+}
+
+/* specific keyboard conversions from scan codes */
+
+#if defined(_WIN32)
+
+static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
+{
+    int keycode;
+
+    keycode = ev->keysym.scancode;
+    keycode = sdl2_scancode_to_keycode[keycode];
+    return keycode;
+}
+
+#else
+
+static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
+{
+    int keycode;
+
+    keycode = ev->keysym.scancode;
+
+    keycode = sdl2_scancode_to_keycode[keycode];
+    if (keycode >= 89 && keycode < 150) {
+        keycode = translate_evdev_keycode(keycode - 89);
+    }
+    return keycode;
+}
+
+#endif
+
+static void reset_keys(void)
+{
+    int i;
+    for(i = 0; i < 256; i++) {
+        if (modifiers_state[i]) {
+            if (i & SCANCODE_GREY)
+                kbd_put_keycode(SCANCODE_EMUL0);
+            kbd_put_keycode(i | SCANCODE_UP);
+            modifiers_state[i] = 0;
+        }
+    }
+}
+
+static void sdl_process_key(SDL_KeyboardEvent *ev)
+{
+    int keycode, v;
+
+    if (ev->keysym.sym == SDLK_PAUSE) {
+        /* specific case */
+        v = 0;
+        if (ev->type == SDL_KEYUP)
+            v |= SCANCODE_UP;
+        kbd_put_keycode(0xe1);
+        kbd_put_keycode(0x1d | v);
+        kbd_put_keycode(0x45 | v);
+        return;
+    }
+
+    if (kbd_layout) {
+        keycode = sdl_keyevent_to_keycode_generic(ev);
+    } else {
+        keycode = sdl_keyevent_to_keycode(ev);
+    }
+
+    switch(keycode) {
+    case 0x00:
+        /* sent when leaving window: reset the modifiers state */
+        reset_keys();
+        return;
+    case 0x2a:                          /* Left Shift */
+    case 0x36:                          /* Right Shift */
+    case 0x1d:                          /* Left CTRL */
+    case 0x9d:                          /* Right CTRL */
+    case 0x38:                          /* Left ALT */
+    case 0xb8:                         /* Right ALT */
+        if (ev->type == SDL_KEYUP)
+            modifiers_state[keycode] = 0;
+        else
+            modifiers_state[keycode] = 1;
+        break;
+    case 0x45: /* num lock */
+    case 0x3a: /* caps lock */
+        /* SDL does not send the key up event, so we generate it */
+        kbd_put_keycode(keycode);
+        kbd_put_keycode(keycode | SCANCODE_UP);
+        return;
+    }
+
+    /* now send the key code */
+    if (keycode & SCANCODE_GREY)
+        kbd_put_keycode(SCANCODE_EMUL0);
+    if (ev->type == SDL_KEYUP)
+        kbd_put_keycode(keycode | SCANCODE_UP);
+    else
+        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+}
+
+static void sdl_update_caption(struct sdl2_console_state *scon)
+{
+    char win_title[1024];
+    char icon_title[1024];
+    const char *status = "";
+
+    if (!runstate_is_running())
+        status = " [Stopped]";
+    else if (gui_grab) {
+        if (alt_grab)
+            status = " - Press Ctrl-Alt-Shift to exit mouse grab";
+        else if (ctrl_grab)
+            status = " - Press Right-Ctrl to exit mouse grab";
+        else
+            status = " - Press Ctrl-Alt to exit mouse grab";
+    }
+
+    if (qemu_name) {
+        snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name, scon->idx, status);
+        snprintf(icon_title, sizeof(icon_title), "QEMU (%s)", qemu_name);
+    } else {
+        snprintf(win_title, sizeof(win_title), "QEMU%s", status);
+        snprintf(icon_title, sizeof(icon_title), "QEMU");
+    }
+
+    if (scon->real_window)
+        SDL_SetWindowTitle(scon->real_window, win_title);
+}
+
+static void sdl_hide_cursor(void)
+{
+    if (!cursor_hide)
+        return;
+
+    if (kbd_mouse_is_absolute()) {
+        SDL_ShowCursor(1);
+        SDL_SetCursor(sdl_cursor_hidden);
+    } else {
+        SDL_ShowCursor(0);
+    }
+}
+
+static void sdl_show_cursor(void)
+{
+    if (!cursor_hide)
+        return;
+
+    if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+        SDL_ShowCursor(1);
+        if (guest_cursor &&
+            (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+            SDL_SetCursor(guest_sprite);
+        else
+            SDL_SetCursor(sdl_cursor_normal);
+    }
+}
+
+static void sdl_grab_start(struct sdl2_console_state *scon)
+{
+    /*
+     * If the application is not active, do not try to enter grab state. This
+     * prevents 'SDL_WM_GrabInput(SDL_GRAB_ON)' from blocking all the
+     * application (SDL bug).
+     */
+    if (!(SDL_GetWindowFlags(scon->real_window) & SDL_WINDOW_INPUT_FOCUS)) {
+        return;
+    }
+    if (guest_cursor) {
+        SDL_SetCursor(guest_sprite);
+        if (!kbd_mouse_is_absolute() && !absolute_enabled) {
+            SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
+        }
+    } else
+        sdl_hide_cursor();
+    SDL_SetWindowGrab(scon->real_window, SDL_TRUE);
+    gui_grab = 1;
+    sdl_update_caption(scon);
+}
+
+static void sdl_grab_end(struct sdl2_console_state *scon)
+{
+    SDL_SetWindowGrab(scon->real_window, SDL_FALSE);
+    gui_grab = 0;
+    sdl_show_cursor();
+    sdl_update_caption(scon);
+}
+
+static void absolute_mouse_grab(struct sdl2_console_state *scon)
+{
+    int mouse_x, mouse_y;
+    int scr_w, scr_h;
+    SDL_GetMouseState(&mouse_x, &mouse_y);
+    SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
+    if (mouse_x > 0 && mouse_x < scr_w - 1 &&
+        mouse_y > 0 && mouse_y < scr_h - 1) {
+        sdl_grab_start(scon);
+    }
+}
+
+static void sdl_mouse_mode_change(Notifier *notify, void *data)
+{
+    if (kbd_mouse_is_absolute()) {
+        if (!absolute_enabled) {
+            absolute_enabled = 1;
+            if (qemu_console_is_graphic(NULL)) {
+                absolute_mouse_grab(&sdl2_console[0]);
+            }
+        }
+    } else if (absolute_enabled) {
+        if (!gui_fullscreen) {
+            sdl_grab_end(&sdl2_console[0]);
+        }
+        absolute_enabled = 0;
+    }
+}
+
+static void sdl_send_mouse_event(struct sdl2_console_state *scon, 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()) {
+        int scr_w, scr_h;
+        int max_w = 0, max_h = 0;
+        int off_x = 0, off_y = 0;
+        int cur_off_x = 0, cur_off_y = 0;
+        int i;
+
+        for (i = 0; i < sdl2_num_outputs; i++) {
+            struct sdl2_console_state *thiscon = &sdl2_console[i];
+            if (thiscon->real_window && thiscon->surface) {
+                SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h);
+                cur_off_x = thiscon->x;
+                cur_off_y = thiscon->y;
+                if (scr_w + cur_off_x > max_w)
+                    max_w = scr_w + cur_off_x;
+                if (scr_h + cur_off_y > max_h)
+                    max_h = scr_h + cur_off_y;
+                if (i == scon->idx) {
+                    off_x = cur_off_x;
+                    off_y = cur_off_y;
+                }
+            }
+        }
+
+        dx = (off_x + x) * 0x7FFF / (max_w - 1);
+        dy = (off_y + y) * 0x7FFF / (max_h - 1);
+    } else if (guest_cursor) {
+        x -= guest_x;
+        y -= guest_y;
+        guest_x += x;
+        guest_y += y;
+        dx = x;
+        dy = y;
+    }
+
+    kbd_mouse_event(dx, dy, dz, buttons);
+}
+
+static void sdl_scale(struct sdl2_console_state *scon, int width, int height)
+{
+    int bpp = 0;
+    do_sdl_resize(scon, width, height, bpp);
+    scaling_active = 1;
+}
+
+static void toggle_full_screen(struct sdl2_console_state *scon)
+{
+    int width = surface_width(scon->surface);
+    int height = surface_height(scon->surface);
+    int bpp = surface_bits_per_pixel(scon->surface);
+
+    gui_fullscreen = !gui_fullscreen;
+    if (gui_fullscreen) {
+        SDL_GetWindowSize(scon->real_window, &gui_saved_width, &gui_saved_height);
+        gui_saved_scaling = scaling_active;
+
+        do_sdl_resize(scon, width, height, bpp);
+        scaling_active = 0;
+
+        gui_saved_grab = gui_grab;
+        sdl_grab_start(scon);
+    } else {
+        if (gui_saved_scaling) {
+            sdl_scale(scon, gui_saved_width, gui_saved_height);
+        } else {
+            do_sdl_resize(scon, width, height, 0);
+        }
+        if (!gui_saved_grab || !qemu_console_is_graphic(NULL)) {
+            sdl_grab_end(scon);
+        }
+    }
+    graphic_hw_invalidate(scon->dcl.con);
+    graphic_hw_update(scon->dcl.con);
+}
+
+static void handle_keydown(SDL_Event *ev)
+{
+    int mod_state;
+    int keycode;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+
+    if (alt_grab) {
+        mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
+            (gui_grab_code | KMOD_LSHIFT);
+    } else if (ctrl_grab) {
+        mod_state = (SDL_GetModState() & KMOD_RCTRL) == KMOD_RCTRL;
+    } else {
+        mod_state = (SDL_GetModState() & gui_grab_code) == gui_grab_code;
+    }
+    gui_key_modifier_pressed = mod_state;
+
+    if (gui_key_modifier_pressed) {
+        keycode = sdl_keyevent_to_keycode(&ev->key);
+        switch (keycode) {
+        case 0x21: /* 'f' key on US keyboard */
+            toggle_full_screen(scon);
+            gui_keysym = 1;
+            break;
+        case 0x16: /* 'u' key on US keyboard */
+            if (scaling_active) {
+                scaling_active = 0;
+                sdl_switch(&scon->dcl, NULL);
+                graphic_hw_invalidate(scon->dcl.con);
+                graphic_hw_update(scon->dcl.con);
+            }
+            gui_keysym = 1;
+            break;
+        case 0x02 ... 0x0a: /* '1' to '9' keys */
+            /* Reset the modifiers sent to the current console */
+            reset_keys();
+            console_select(keycode - 0x02);
+            gui_keysym = 1;
+            if (gui_fullscreen) {
+                break;
+            }
+            if (!qemu_console_is_graphic(NULL)) {
+                /* release grab if going to a text console */
+                if (gui_grab) {
+                    sdl_grab_end(scon);
+                } else if (absolute_enabled) {
+                    sdl_show_cursor();
+                }
+            } else if (absolute_enabled) {
+                sdl_hide_cursor();
+                absolute_mouse_grab(scon);
+            }
+            break;
+        case 0x1b: /* '+' */
+        case 0x35: /* '-' */
+            if (!gui_fullscreen) {
+                int scr_w, scr_h;
+                int width, height;
+                SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
+
+                width = MAX(scr_w + (keycode == 0x1b ? 50 : -50),
+                            160);
+                height = (surface_height(scon->surface) * width) /
+                    surface_width(scon->surface);
+
+                sdl_scale(scon, width, height);
+                graphic_hw_invalidate(NULL);
+                graphic_hw_update(NULL);
+                gui_keysym = 1;
+            }
+        default:
+            break;
+        }
+    } else if (!qemu_console_is_graphic(NULL)) {
+        int keysym = ev->key.keysym.sym;
+
+        if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
+            switch (ev->key.keysym.sym) {
+            case SDLK_UP:
+                keysym = QEMU_KEY_CTRL_UP;
+                break;
+            case SDLK_DOWN:
+                keysym = QEMU_KEY_CTRL_DOWN;
+                break;
+            case SDLK_LEFT:
+                keysym = QEMU_KEY_CTRL_LEFT;
+                break;
+            case SDLK_RIGHT:
+                keysym = QEMU_KEY_CTRL_RIGHT;
+                break;
+            case SDLK_HOME:
+                keysym = QEMU_KEY_CTRL_HOME;
+                break;
+            case SDLK_END:
+                keysym = QEMU_KEY_CTRL_END;
+                break;
+            case SDLK_PAGEUP:
+                keysym = QEMU_KEY_CTRL_PAGEUP;
+                break;
+            case SDLK_PAGEDOWN:
+                keysym = QEMU_KEY_CTRL_PAGEDOWN;
+                break;
+            default:
+                break;
+            }
+        } else {
+            switch (ev->key.keysym.sym) {
+            case SDLK_UP:
+                keysym = QEMU_KEY_UP;
+                break;
+            case SDLK_DOWN:
+                keysym = QEMU_KEY_DOWN;
+                break;
+            case SDLK_LEFT:
+                keysym = QEMU_KEY_LEFT;
+                break;
+            case SDLK_RIGHT:
+                keysym = QEMU_KEY_RIGHT;
+                break;
+            case SDLK_HOME:
+                keysym = QEMU_KEY_HOME;
+                break;
+            case SDLK_END:
+                keysym = QEMU_KEY_END;
+                break;
+            case SDLK_PAGEUP:
+                keysym = QEMU_KEY_PAGEUP;
+                break;
+            case SDLK_PAGEDOWN:
+                keysym = QEMU_KEY_PAGEDOWN;
+                break;
+            case SDLK_BACKSPACE:
+                keysym = QEMU_KEY_BACKSPACE;
+                break;
+            case SDLK_DELETE:
+                keysym = QEMU_KEY_DELETE;
+                break;
+            default:
+                break;
+            }
+        }
+        if (keysym) {
+            kbd_put_keysym(keysym);
+        }
+    }
+    if (qemu_console_is_graphic(NULL) && !gui_keysym) {
+        sdl_process_key(&ev->key);
+    }
+}
+
+static void handle_keyup(SDL_Event *ev)
+{
+    int mod_state;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+
+    if (!alt_grab) {
+        mod_state = (ev->key.keysym.mod & gui_grab_code);
+    } else {
+        mod_state = (ev->key.keysym.mod & (gui_grab_code | KMOD_LSHIFT));
+    }
+    if (!mod_state && gui_key_modifier_pressed) {
+        gui_key_modifier_pressed = 0;
+        if (gui_keysym == 0) {
+            /* exit/enter grab if pressing Ctrl-Alt */
+            if (!gui_grab) {
+                if (qemu_console_is_graphic(NULL)) {
+                    sdl_grab_start(scon);
+                }
+            } else if (!gui_fullscreen) {
+                sdl_grab_end(scon);
+            }
+            /* SDL does not send back all the modifiers key, so we must
+             * correct it. */
+            reset_keys();
+            return;
+        }
+        gui_keysym = 0;
+    }
+    if (qemu_console_is_graphic(NULL) && !gui_keysym) {
+        sdl_process_key(&ev->key);
+    }
+}
+
+static void handle_mousemotion(SDL_Event *ev)
+{
+    int max_x, max_y;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+
+    if (qemu_console_is_graphic(NULL) &&
+        (kbd_mouse_is_absolute() || absolute_enabled)) {
+        int scr_w, scr_h;
+        SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
+        max_x = scr_w - 1;
+        max_y = scr_h - 1;
+        if (gui_grab && (ev->motion.x == 0 || ev->motion.y == 0 ||
+                         ev->motion.x == max_x || ev->motion.y == max_y)) {
+            sdl_grab_end(scon);
+        }
+        if (!gui_grab &&
+            (ev->motion.x > 0 && ev->motion.x < max_x &&
+             ev->motion.y > 0 && ev->motion.y < max_y)) {
+            sdl_grab_start(scon);
+        }
+    }
+    if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+        sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel, 0,
+                             ev->motion.x, ev->motion.y, ev->motion.state);
+    }
+}
+
+static void handle_mousebutton(SDL_Event *ev)
+{
+    int buttonstate = SDL_GetMouseState(NULL, NULL);
+    SDL_MouseButtonEvent *bev;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    int dz;
+
+    if (!qemu_console_is_graphic(NULL)) {
+        return;
+    }
+
+    bev = &ev->button;
+    if (!gui_grab && !kbd_mouse_is_absolute()) {
+        if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
+            /* start grabbing all events */
+            sdl_grab_start(scon);
+        }
+    } else {
+        dz = 0;
+        if (ev->type == SDL_MOUSEBUTTONDOWN) {
+            buttonstate |= SDL_BUTTON(bev->button);
+        } else {
+            buttonstate &= ~SDL_BUTTON(bev->button);
+        }
+#ifdef SDL_BUTTON_WHEELUP
+        if (bev->button == SDL_BUTTON_WHEELUP &&
+            ev->type == SDL_MOUSEBUTTONDOWN) {
+            dz = -1;
+        } else if (bev->button == SDL_BUTTON_WHEELDOWN &&
+                   ev->type == SDL_MOUSEBUTTONDOWN) {
+            dz = 1;
+        }
+#endif
+        sdl_send_mouse_event(scon, 0, 0, dz, bev->x, bev->y, buttonstate);
+    }
+}
+
+static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
+{
+    int w, h;
+    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+
+    switch (ev->window.event) {
+    case SDL_WINDOWEVENT_RESIZED:
+        sdl_scale(scon, ev->window.data1, ev->window.data2);
+        graphic_hw_invalidate(scon->dcl.con);
+        graphic_hw_update(scon->dcl.con);
+        break;
+    case SDL_WINDOWEVENT_EXPOSED:
+        SDL_GetWindowSize(SDL_GetWindowFromID(ev->window.windowID), &w, &h);
+        sdl_update(dcl, 0, 0, w, h);
+        break;
+    case SDL_WINDOWEVENT_FOCUS_GAINED:
+    case SDL_WINDOWEVENT_ENTER:
+        if (!gui_grab && qemu_console_is_graphic(NULL) &&
+            (kbd_mouse_is_absolute() || absolute_enabled)) {
+            absolute_mouse_grab(scon);
+        }
+        break;
+    case SDL_WINDOWEVENT_FOCUS_LOST:
+        if (gui_grab && !gui_fullscreen)
+            sdl_grab_end(scon);
+        break;
+    case SDL_WINDOWEVENT_RESTORED:
+        update_displaychangelistener(dcl, GUI_REFRESH_INTERVAL_DEFAULT);
+        break;
+    case SDL_WINDOWEVENT_MINIMIZED:
+        update_displaychangelistener(dcl, 500);
+        break;
+    case SDL_WINDOWEVENT_CLOSE:
+        if (!no_quit) {
+            no_shutdown = 0;
+            qemu_system_shutdown_request();
+        }
+        break;
+    }
+}
+
+static void sdl_refresh(DisplayChangeListener *dcl)
+{
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    SDL_Event ev1, *ev = &ev1;
+
+    if (scon->last_vm_running != runstate_is_running()) {
+        scon->last_vm_running = runstate_is_running();
+        sdl_update_caption(scon);
+    }
+
+    graphic_hw_update(dcl->con);
+
+    while (SDL_PollEvent(ev)) {
+        switch (ev->type) {
+        case SDL_KEYDOWN:
+            handle_keydown(ev);
+            break;
+        case SDL_KEYUP:
+            handle_keyup(ev);
+            break;
+        case SDL_QUIT:
+            if (!no_quit) {
+                no_shutdown = 0;
+                qemu_system_shutdown_request();
+            }
+            break;
+        case SDL_MOUSEMOTION:
+            handle_mousemotion(ev);
+            break;
+        case SDL_MOUSEBUTTONDOWN:
+        case SDL_MOUSEBUTTONUP:
+            handle_mousebutton(ev);
+            break;
+        case SDL_WINDOWEVENT:
+            handle_windowevent(dcl, ev);
+            break;
+        default:
+            break;
+        }
+    }
+}
+
+static void sdl_mouse_warp(DisplayChangeListener *dcl,
+                           int x, int y, int on)
+{
+    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    if (on) {
+        if (!guest_cursor)
+            sdl_show_cursor();
+        if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+            SDL_SetCursor(guest_sprite);
+            if (!kbd_mouse_is_absolute() && !absolute_enabled) {
+                SDL_WarpMouseInWindow(scon->real_window, x, y);
+            }
+        }
+    } else if (gui_grab)
+        sdl_hide_cursor();
+    guest_cursor = on;
+    guest_x = x, guest_y = y;
+}
+
+static void sdl_mouse_define(DisplayChangeListener *dcl,
+                             QEMUCursor *c)
+{
+
+    if (guest_sprite)
+        SDL_FreeCursor(guest_sprite);
+
+    if (guest_sprite_surface)
+        SDL_FreeSurface(guest_sprite_surface);
+
+    guest_sprite_surface = SDL_CreateRGBSurfaceFrom(c->data,
+                                                    c->width, c->height, 32, c->width * 4, 0xff0000,
+                                                    0x00ff00, 0xff, 0xff000000);
+
+    if (!guest_sprite_surface) {
+        fprintf(stderr, "Failed to make rgb surface from %p\n", c);
+        return;
+    }
+    guest_sprite = SDL_CreateColorCursor(guest_sprite_surface,
+                                         c->hot_x, c->hot_y);
+    if (!guest_sprite) {
+        fprintf(stderr, "Failed to make color cursor from %p\n", c);
+        return;
+    }
+    if (guest_cursor &&
+        (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
+        SDL_SetCursor(guest_sprite);
+}
+
+static void sdl_cleanup(void)
+{
+    if (guest_sprite)
+        SDL_FreeCursor(guest_sprite);
+    SDL_QuitSubSystem(SDL_INIT_VIDEO);
+}
+
+static const DisplayChangeListenerOps dcl_ops = {
+    .dpy_name          = "sdl",
+    .dpy_gfx_update    = sdl_update,
+    .dpy_gfx_switch    = sdl_switch,
+    .dpy_refresh       = sdl_refresh,
+    .dpy_mouse_set     = sdl_mouse_warp,
+    .dpy_cursor_define = sdl_mouse_define,
+};
+
+void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
+{
+    int flags;
+    uint8_t data = 0;
+    char *filename;
+    int i;
+#if defined(__APPLE__)
+    /* always use generic keymaps */
+    if (!keyboard_layout)
+        keyboard_layout = "en-us";
+#endif
+    if(keyboard_layout) {
+        kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
+        if (!kbd_layout)
+            exit(1);
+    }
+
+    if (no_frame)
+        gui_noframe = 1;
+
+#ifdef __linux__
+    /* on Linux, SDL may use fbcon|directfb|svgalib when run without
+     * accessible $DISPLAY to open X11 window.  This is often the case
+     * when qemu is run using sudo.  But in this case, and when actually
+     * run in X11 environment, SDL fights with X11 for the video card,
+     * making current display unavailable, often until reboot.
+     * So make x11 the default SDL video driver if this variable is unset.
+     * This is a bit hackish but saves us from bigger problem.
+     * Maybe it's a good idea to fix this in SDL instead.
+     */
+    setenv("SDL_VIDEODRIVER", "x11", 0);
+#endif
+
+    flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
+    if (SDL_Init (flags)) {
+        fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
+                SDL_GetError());
+        exit(1);
+    }
+
+    for (i = 0;; i++) {
+        QemuConsole *con = qemu_console_lookup_by_index(i);
+        if (!con || !qemu_console_is_graphic(con))
+            break;
+    }
+    sdl2_num_outputs = i;
+    sdl2_console = g_new0(struct sdl2_console_state, sdl2_num_outputs);
+    for (i = 0; i < sdl2_num_outputs; i++) {
+        QemuConsole *con = qemu_console_lookup_by_index(i);
+        sdl2_console[i].dcl.ops = &dcl_ops;
+        sdl2_console[i].dcl.con = con;
+        register_displaychangelistener(&sdl2_console[i].dcl);
+        sdl2_console[i].idx = i;
+    }
+
+    /* Load a 32x32x4 image. White pixels are transparent. */
+    filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, "qemu-icon.bmp");
+    if (filename) {
+        SDL_Surface *image = SDL_LoadBMP(filename);
+        if (image) {
+            uint32_t colorkey = SDL_MapRGB(image->format, 255, 255, 255);
+            SDL_SetColorKey(image, SDL_TRUE, colorkey);
+            SDL_SetWindowIcon(sdl2_console[0].real_window, image);
+        }
+        g_free(filename);
+    }
+
+    if (full_screen) {
+        gui_fullscreen = 1;
+        sdl_grab_start(0);
+    }
+
+    mouse_mode_notifier.notify = sdl_mouse_mode_change;
+    qemu_add_mouse_mode_change_notifier(&mouse_mode_notifier);
+
+    gui_grab = 0;
+
+    sdl_cursor_hidden = SDL_CreateCursor(&data, &data, 8, 1, 0, 0);
+    sdl_cursor_normal = SDL_GetCursor();
+
+    atexit(sdl_cleanup);
+}
+#endif
diff --git a/ui/sdl2_scancode_translate.h b/ui/sdl2_scancode_translate.h
new file mode 100644
index 0000000..1bd4953
--- /dev/null
+++ b/ui/sdl2_scancode_translate.h
@@ -0,0 +1,260 @@
+/* generated from a back translation of the SDL2 linux_scancodes file.
+   this translates SDL2 scancodes into Linux evdev keycodes,
+   these need to be translated again to go into qemu keys. */
+static uint8_t const sdl2_scancode_to_keycode[] = {
+235,
+0,
+0,
+0,
+30,
+48,
+46,
+32,
+18,
+33,
+34,
+35,
+23,
+36,
+37,
+38,
+50,
+49,
+24,
+25,
+16,
+19,
+31,
+20,
+22,
+47,
+17,
+45,
+21,
+44,
+2,
+3,
+4,
+5,
+6,
+7,
+8,
+9,
+10,
+11,
+28,
+1,
+14,
+15,
+57,
+12,
+13,
+26,
+27,
+43,
+0,
+39,
+40,
+41,
+51,
+52,
+53,
+58,
+59,
+60,
+61,
+62,
+63,
+64,
+65,
+66,
+67,
+68,
+87,
+88,
+0,
+70,
+119,
+110,
+102,
+104,
+111,
+107,
+109,
+106,
+105,
+108,
+103,
+69,
+98,
+55,
+74,
+78,
+96,
+79,
+80,
+81,
+75,
+76,
+77,
+71,
+72,
+73,
+82,
+83,
+86,
+0,
+116,
+117,
+183,
+184,
+185,
+186,
+187,
+188,
+189,
+190,
+191,
+192,
+193,
+194,
+0,
+138,
+139,
+0,
+128,
+129,
+131,
+137,
+133,
+135,
+136,
+113,
+115,
+114,
+0,
+0,
+0,
+121,
+0,
+89,
+93,
+124,
+92,
+95,
+0,
+0,
+0,
+0,
+122,
+123,
+90,
+91,
+0,
+0,
+0,
+0,
+0,
+221,
+99,
+222,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+179,
+180,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+118,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+29,
+42,
+56,
+125,
+97,
+54,
+100,
+126,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+0,
+};
diff --git a/ui/sdl_keysym.h b/ui/sdl_keysym.h
index ee90480..599d9fc 100644
--- a/ui/sdl_keysym.h
+++ b/ui/sdl_keysym.h
@@ -200,6 +200,7 @@ static const name2keysym_t name2keysym[]={
 { "yacute",               0x0fd},
 { "thorn",                0x0fe},
 { "ydiaeresis",           0x0ff},
+#if SDL_MAJOR_VERSION == 1
 {"EuroSign", SDLK_EURO},
 
     /* modifiers */
@@ -272,6 +273,6 @@ static const name2keysym_t name2keysym[]={
 {"Num_Lock", SDLK_NUMLOCK},
 {"Pause", SDLK_PAUSE},
 {"Escape", SDLK_ESCAPE},
-
+#endif
 {NULL, 0},
 };
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 02/42] sdl2: baum build fix
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 03/42] sdl2: remove text console logic Gerd Hoffmann
                   ` (39 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

---
 backends/baum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/backends/baum.c b/backends/baum.c
index 1132899..665107f 100644
--- a/backends/baum.c
+++ b/backends/baum.c
@@ -566,7 +566,7 @@ CharDriverState *chr_baum_init(void)
     BaumDriverState *baum;
     CharDriverState *chr;
     brlapi_handle_t *handle;
-#ifdef CONFIG_SDL
+#if defined(CONFIG_SDL) && SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
     SDL_SysWMinfo info;
 #endif
     int tty;
@@ -595,7 +595,7 @@ CharDriverState *chr_baum_init(void)
         goto fail;
     }
 
-#ifdef CONFIG_SDL
+#if defined(CONFIG_SDL) && SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0)
     memset(&info, 0, sizeof(info));
     SDL_VERSION(&info.version);
     if (SDL_GetWMInfo(&info))
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 03/42] sdl2: remove text console logic
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 02/42] sdl2: baum build fix Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 04/42] console: export QemuConsole index, width, height Gerd Hoffmann
                   ` (38 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

sdl2 explicitly binds windows to graphics consoles.
No need to handle non-graphic consoles anywhere.
Also console switching is pointless.  Zap code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/sdl2.c | 117 +++++---------------------------------------------------------
 1 file changed, 8 insertions(+), 109 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index 2eb3e9c..e7a30b3 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -345,7 +345,7 @@ static void sdl_show_cursor(void)
     if (!cursor_hide)
         return;
 
-    if (!kbd_mouse_is_absolute() || !qemu_console_is_graphic(NULL)) {
+    if (!kbd_mouse_is_absolute()) {
         SDL_ShowCursor(1);
         if (guest_cursor &&
             (gui_grab || kbd_mouse_is_absolute() || absolute_enabled))
@@ -402,9 +402,7 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
     if (kbd_mouse_is_absolute()) {
         if (!absolute_enabled) {
             absolute_enabled = 1;
-            if (qemu_console_is_graphic(NULL)) {
-                absolute_mouse_grab(&sdl2_console[0]);
-            }
+            absolute_mouse_grab(&sdl2_console[0]);
         }
     } else if (absolute_enabled) {
         if (!gui_fullscreen) {
@@ -495,7 +493,7 @@ static void toggle_full_screen(struct sdl2_console_state *scon)
         } else {
             do_sdl_resize(scon, width, height, 0);
         }
-        if (!gui_saved_grab || !qemu_console_is_graphic(NULL)) {
+        if (!gui_saved_grab) {
             sdl_grab_end(scon);
         }
     }
@@ -535,26 +533,6 @@ static void handle_keydown(SDL_Event *ev)
             }
             gui_keysym = 1;
             break;
-        case 0x02 ... 0x0a: /* '1' to '9' keys */
-            /* Reset the modifiers sent to the current console */
-            reset_keys();
-            console_select(keycode - 0x02);
-            gui_keysym = 1;
-            if (gui_fullscreen) {
-                break;
-            }
-            if (!qemu_console_is_graphic(NULL)) {
-                /* release grab if going to a text console */
-                if (gui_grab) {
-                    sdl_grab_end(scon);
-                } else if (absolute_enabled) {
-                    sdl_show_cursor();
-                }
-            } else if (absolute_enabled) {
-                sdl_hide_cursor();
-                absolute_mouse_grab(scon);
-            }
-            break;
         case 0x1b: /* '+' */
         case 0x35: /* '-' */
             if (!gui_fullscreen) {
@@ -575,79 +553,8 @@ static void handle_keydown(SDL_Event *ev)
         default:
             break;
         }
-    } else if (!qemu_console_is_graphic(NULL)) {
-        int keysym = ev->key.keysym.sym;
-
-        if (ev->key.keysym.mod & (KMOD_LCTRL | KMOD_RCTRL)) {
-            switch (ev->key.keysym.sym) {
-            case SDLK_UP:
-                keysym = QEMU_KEY_CTRL_UP;
-                break;
-            case SDLK_DOWN:
-                keysym = QEMU_KEY_CTRL_DOWN;
-                break;
-            case SDLK_LEFT:
-                keysym = QEMU_KEY_CTRL_LEFT;
-                break;
-            case SDLK_RIGHT:
-                keysym = QEMU_KEY_CTRL_RIGHT;
-                break;
-            case SDLK_HOME:
-                keysym = QEMU_KEY_CTRL_HOME;
-                break;
-            case SDLK_END:
-                keysym = QEMU_KEY_CTRL_END;
-                break;
-            case SDLK_PAGEUP:
-                keysym = QEMU_KEY_CTRL_PAGEUP;
-                break;
-            case SDLK_PAGEDOWN:
-                keysym = QEMU_KEY_CTRL_PAGEDOWN;
-                break;
-            default:
-                break;
-            }
-        } else {
-            switch (ev->key.keysym.sym) {
-            case SDLK_UP:
-                keysym = QEMU_KEY_UP;
-                break;
-            case SDLK_DOWN:
-                keysym = QEMU_KEY_DOWN;
-                break;
-            case SDLK_LEFT:
-                keysym = QEMU_KEY_LEFT;
-                break;
-            case SDLK_RIGHT:
-                keysym = QEMU_KEY_RIGHT;
-                break;
-            case SDLK_HOME:
-                keysym = QEMU_KEY_HOME;
-                break;
-            case SDLK_END:
-                keysym = QEMU_KEY_END;
-                break;
-            case SDLK_PAGEUP:
-                keysym = QEMU_KEY_PAGEUP;
-                break;
-            case SDLK_PAGEDOWN:
-                keysym = QEMU_KEY_PAGEDOWN;
-                break;
-            case SDLK_BACKSPACE:
-                keysym = QEMU_KEY_BACKSPACE;
-                break;
-            case SDLK_DELETE:
-                keysym = QEMU_KEY_DELETE;
-                break;
-            default:
-                break;
-            }
-        }
-        if (keysym) {
-            kbd_put_keysym(keysym);
-        }
     }
-    if (qemu_console_is_graphic(NULL) && !gui_keysym) {
+    if (!gui_keysym) {
         sdl_process_key(&ev->key);
     }
 }
@@ -667,9 +574,7 @@ static void handle_keyup(SDL_Event *ev)
         if (gui_keysym == 0) {
             /* exit/enter grab if pressing Ctrl-Alt */
             if (!gui_grab) {
-                if (qemu_console_is_graphic(NULL)) {
-                    sdl_grab_start(scon);
-                }
+                sdl_grab_start(scon);
             } else if (!gui_fullscreen) {
                 sdl_grab_end(scon);
             }
@@ -680,7 +585,7 @@ static void handle_keyup(SDL_Event *ev)
         }
         gui_keysym = 0;
     }
-    if (qemu_console_is_graphic(NULL) && !gui_keysym) {
+    if (!gui_keysym) {
         sdl_process_key(&ev->key);
     }
 }
@@ -690,8 +595,7 @@ static void handle_mousemotion(SDL_Event *ev)
     int max_x, max_y;
     struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
-    if (qemu_console_is_graphic(NULL) &&
-        (kbd_mouse_is_absolute() || absolute_enabled)) {
+    if (kbd_mouse_is_absolute() || absolute_enabled) {
         int scr_w, scr_h;
         SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
         max_x = scr_w - 1;
@@ -719,10 +623,6 @@ static void handle_mousebutton(SDL_Event *ev)
     struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
     int dz;
 
-    if (!qemu_console_is_graphic(NULL)) {
-        return;
-    }
-
     bev = &ev->button;
     if (!gui_grab && !kbd_mouse_is_absolute()) {
         if (ev->type == SDL_MOUSEBUTTONUP && bev->button == SDL_BUTTON_LEFT) {
@@ -766,8 +666,7 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
         break;
     case SDL_WINDOWEVENT_FOCUS_GAINED:
     case SDL_WINDOWEVENT_ENTER:
-        if (!gui_grab && qemu_console_is_graphic(NULL) &&
-            (kbd_mouse_is_absolute() || absolute_enabled)) {
+        if (!gui_grab && (kbd_mouse_is_absolute() || absolute_enabled)) {
             absolute_mouse_grab(scon);
         }
         break;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 04/42] console: export QemuConsole index, width, height
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 03/42] sdl2: remove text console logic Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 05/42] input: rename file to legacy Gerd Hoffmann
                   ` (37 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Add functions to query QemuConsole properties.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  3 +++
 ui/console.c         | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)

diff --git a/include/ui/console.h b/include/ui/console.h
index 4156a87..8543d18 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -289,6 +289,9 @@ QemuConsole *qemu_console_lookup_by_device(DeviceState *dev);
 bool qemu_console_is_visible(QemuConsole *con);
 bool qemu_console_is_graphic(QemuConsole *con);
 bool qemu_console_is_fixedsize(QemuConsole *con);
+int qemu_console_get_index(QemuConsole *con);
+int qemu_console_get_width(QemuConsole *con, int fallback);
+int qemu_console_get_height(QemuConsole *con, int fallback);
 
 void text_consoles_set_display(DisplayState *ds);
 void console_select(unsigned int index);
diff --git a/ui/console.c b/ui/console.c
index 502e160..0bbefe5 100644
--- a/ui/console.c
+++ b/ui/console.c
@@ -1641,6 +1641,30 @@ bool qemu_console_is_fixedsize(QemuConsole *con)
     return con && (con->console_type != TEXT_CONSOLE);
 }
 
+int qemu_console_get_index(QemuConsole *con)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? con->index : -1;
+}
+
+int qemu_console_get_width(QemuConsole *con, int fallback)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? surface_width(con->surface) : fallback;
+}
+
+int qemu_console_get_height(QemuConsole *con, int fallback)
+{
+    if (con == NULL) {
+        con = active_console;
+    }
+    return con ? surface_height(con->surface) : fallback;
+}
+
 static void text_console_set_echo(CharDriverState *chr, bool echo)
 {
     QemuConsole *s = chr->opaque;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 05/42] input: rename file to legacy
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 04/42] console: export QemuConsole index, width, height Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 06/42] input: qapi: define event types Gerd Hoffmann
                   ` (36 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Rename ui/input.c to ui/input-legacy.c.
We are going to replace it step by step.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/Makefile.objs               | 2 +-
 ui/{input.c => input-legacy.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename ui/{input.c => input-legacy.c} (100%)

diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 721ad37..16db07a 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input.c b/ui/input-legacy.c
similarity index 100%
rename from ui/input.c
rename to ui/input-legacy.c
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 06/42] input: qapi: define event types
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 05/42] input: rename file to legacy Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key Gerd Hoffmann
                   ` (35 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Gerd Hoffmann, Luiz Capitulino

Define input event types, using qapi.  So we get nicely autogenerated
types for our input events.  And when it comes to qmp support some day
things will be alot easier.

Types are modeled after the linux input layer.  There are separate
event types for each value.  There is a sync to indicate the end
of a event group.

Mouse events are splitted into motion events (one for each axis) and
button events, which are grouped by sync.

Keyboard events are using the existing KeyValue type.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qapi-schema.json | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 76 insertions(+)

diff --git a/qapi-schema.json b/qapi-schema.json
index d6f8615..0316cb4 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -4235,3 +4235,79 @@
 # Since: 1.7
 ##
 { 'command': 'blockdev-add', 'data': { 'options': 'BlockdevOptions' } }
+
+##
+# @InputButton
+#
+# Button of a pointer input device (mouse, tablet).
+#
+# Since: 2.0
+##
+{ 'enum'  : 'InputButton',
+  'data'  : [ 'Left', 'Middle', 'Right', 'WheelUp', 'WheelDown' ] }
+
+##
+# @InputButton
+#
+# Position axis of a pointer input device (mouse, tablet).
+#
+# Since: 2.0
+##
+{ 'enum'  : 'InputAxis',
+  'data'  : [ 'X', 'Y' ] }
+
+##
+# @InputKeyEvent
+#
+# Keyboard input event.
+#
+# @key:    Which key this event is for.
+# @down:   True for key-down and false for key-up events.
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputKeyEvent',
+  'data'  : { 'key'     : 'KeyValue',
+              'down'    : 'bool' } }
+
+##
+# @InputBtnEvent
+#
+# Pointer button input event.
+#
+# @button: Which button this event is for.
+# @down:   True for key-down and false for key-up events.
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputBtnEvent',
+  'data'  : { 'button'  : 'InputButton',
+              'down'    : 'bool' } }
+
+##
+# @InputMoveEvent
+#
+# Pointer motion input event.
+#
+# @axis:   Which axis is referenced by @value.
+# @value:  Pointer position.  For absolute coordinates the
+#          valid range is 0 -> 0x7ffff
+#
+# Since: 2.0
+##
+{ 'type'  : 'InputMoveEvent',
+  'data'  : { 'axis'    : 'InputAxis',
+              'value'   : 'int' } }
+
+##
+# @InputEvent
+#
+# Input event union.
+#
+# Since: 2.0
+##
+{ 'union' : 'InputEvent',
+  'data'  : { 'key'     : 'InputKeyEvent',
+              'btn'     : 'InputBtnEvent',
+              'rel'     : 'InputMoveEvent',
+              'abs'     : 'InputMoveEvent' } }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 06/42] input: qapi: define event types Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-17 21:06   ` Eric Blake
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 08/42] input: qapi: add pause key Gerd Hoffmann
                   ` (34 subsequent siblings)
  41 siblings, 1 reply; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Gerd Hoffmann, Luiz Capitulino

Simplifies building something -> QkeyCode mapping tables.
Uninitialized entries can easily identified then.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qapi-schema.json | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 0316cb4..89d8060 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3357,7 +3357,8 @@
 # Since: 1.3.0
 ##
 { 'enum': 'QKeyCode',
-  'data': [ 'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
+  'data': [ 'unmapped',
+            'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
             'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8',
             '9', '0', 'minus', 'equal', 'backspace', 'tab', 'q', 'w', 'e',
             'r', 't', 'y', 'u', 'i', 'o', 'p', 'bracket_left', 'bracket_right',
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 08/42] input: qapi: add pause key
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-17 21:06   ` Eric Blake
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer Gerd Hoffmann
                   ` (33 subsequent siblings)
  41 siblings, 1 reply; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Markus Armbruster, Gerd Hoffmann, Luiz Capitulino

It's missing.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 qapi-schema.json | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/qapi-schema.json b/qapi-schema.json
index 89d8060..56981d9 100644
--- a/qapi-schema.json
+++ b/qapi-schema.json
@@ -3372,7 +3372,7 @@
             'kp_9', 'less', 'f11', 'f12', 'print', 'home', 'pgup', 'pgdn', 'end',
             'left', 'up', 'down', 'right', 'insert', 'delete', 'stop', 'again',
             'props', 'undo', 'front', 'copy', 'open', 'paste', 'find', 'cut',
-             'lf', 'help', 'meta_l', 'meta_r', 'compose' ] }
+             'lf', 'help', 'meta_l', 'meta_r', 'compose', 'pause' ] }
 
 ##
 # @KeyValue
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (7 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 08/42] input: qapi: add pause key Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 10/42] input: keyboard: add helper functions to core Gerd Hoffmann
                   ` (32 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Register and unregister handlers.
Event dispatcher code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h | 32 +++++++++++++++++++++
 ui/Makefile.objs   |  2 +-
 ui/input.c         | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input.c

diff --git a/include/ui/input.h b/include/ui/input.h
new file mode 100644
index 0000000..3cf3641
--- /dev/null
+++ b/include/ui/input.h
@@ -0,0 +1,32 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include "qapi-types.h"
+
+#define INPUT_EVENT_MASK_KEY   (1<<INPUT_EVENT_KIND_KEY)
+#define INPUT_EVENT_MASK_BTN   (1<<INPUT_EVENT_KIND_BTN)
+#define INPUT_EVENT_MASK_REL   (1<<INPUT_EVENT_KIND_REL)
+#define INPUT_EVENT_MASK_ABS   (1<<INPUT_EVENT_KIND_ABS)
+
+typedef struct QemuInputHandler QemuInputHandler;
+typedef struct QemuInputHandlerState QemuInputHandlerState;
+
+typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src,
+                                      InputEvent *evt);
+typedef void (*QemuInputHandlerSync)(DeviceState *dev);
+
+struct QemuInputHandler {
+    const char             *name;
+    uint32_t               mask;
+    QemuInputHandlerEvent  event;
+    QemuInputHandlerSync   sync;
+};
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+                                                   QemuInputHandler *handler);
+void qemu_input_handler_activate(QemuInputHandlerState *s);
+void qemu_input_handler_unregister(QemuInputHandlerState *s);
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
+void qemu_input_event_sync(void);
+
+#endif /* INPUT_H */
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 16db07a..e6a5ec1 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input.c b/ui/input.c
new file mode 100644
index 0000000..23c84f7
--- /dev/null
+++ b/ui/input.c
@@ -0,0 +1,83 @@
+#include "sysemu/sysemu.h"
+#include "qapi-types.h"
+#include "ui/input.h"
+
+struct QemuInputHandlerState {
+    DeviceState       *dev;
+    QemuInputHandler  *handler;
+    int               id;
+    int               events;
+    QTAILQ_ENTRY(QemuInputHandlerState) node;
+};
+static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
+    QTAILQ_HEAD_INITIALIZER(handlers);
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+                                                   QemuInputHandler *handler)
+{
+    QemuInputHandlerState *s = g_new0(QemuInputHandlerState, 1);
+    static int id = 1;
+
+    s->dev = dev;
+    s->handler = handler;
+    s->id = id++;
+    QTAILQ_INSERT_TAIL(&handlers, s, node);
+    return s;
+}
+
+void qemu_input_handler_activate(QemuInputHandlerState *s)
+{
+    QTAILQ_REMOVE(&handlers, s, node);
+    QTAILQ_INSERT_HEAD(&handlers, s, node);
+}
+
+void qemu_input_handler_unregister(QemuInputHandlerState *s)
+{
+    QTAILQ_REMOVE(&handlers, s, node);
+    g_free(s);
+}
+
+static QemuInputHandlerState*
+qemu_input_find_handler(uint32_t mask)
+{
+    QemuInputHandlerState *s;
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (mask & s->handler->mask) {
+            return s;
+        }
+    }
+    return NULL;
+}
+
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
+{
+    QemuInputHandlerState *s;
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        return;
+    }
+
+    s = qemu_input_find_handler(1 << evt->kind);
+    s->handler->event(s->dev, src, evt);
+    s->events++;
+}
+
+void qemu_input_event_sync(void)
+{
+    QemuInputHandlerState *s;
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        return;
+    }
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (!s->events) {
+            continue;
+        }
+        if (s->handler->sync) {
+            s->handler->sync(s->dev);
+        }
+        s->events = 0;
+    }
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 10/42] input: keyboard: add helper functions to core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (8 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 11/42] input: keyboard: switch legacy handlers to new core Gerd Hoffmann
                   ` (31 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

A bunch of helper functions to manage keyboard events,
to make life simpler for the ui code when submitting
keyboard events.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h |  5 +++++
 ui/input.c         | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/ui/input.h b/include/ui/input.h
index 3cf3641..189f131 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -29,4 +29,9 @@ void qemu_input_handler_unregister(QemuInputHandlerState *s);
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
 void qemu_input_event_sync(void);
 
+InputEvent *qemu_input_event_new_key(KeyValue *key, bool down);
+void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down);
+void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down);
+void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down);
+
 #endif /* INPUT_H */
diff --git a/ui/input.c b/ui/input.c
index 23c84f7..61c8089 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -81,3 +81,38 @@ void qemu_input_event_sync(void)
         s->events = 0;
     }
 }
+
+InputEvent *qemu_input_event_new_key(KeyValue *key, bool down)
+{
+    InputEvent *evt = g_new0(InputEvent, 1);
+    evt->key = g_new0(InputKeyEvent, 1);
+    evt->kind = INPUT_EVENT_KIND_KEY;
+    evt->key->key = key;
+    evt->key->down = down;
+    return evt;
+}
+
+void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down)
+{
+    InputEvent *evt;
+    evt = qemu_input_event_new_key(key, down);
+    qemu_input_event_send(src, evt);
+    qemu_input_event_sync();
+    qapi_free_InputEvent(evt);
+}
+
+void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down)
+{
+    KeyValue *key = g_new0(KeyValue, 1);
+    key->kind = KEY_VALUE_KIND_NUMBER;
+    key->number = num;
+    qemu_input_event_send_key(src, key, down);
+}
+
+void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down)
+{
+    KeyValue *key = g_new0(KeyValue, 1);
+    key->kind = KEY_VALUE_KIND_QCODE;
+    key->qcode = q;
+    qemu_input_event_send_key(src, key, down);
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 11/42] input: keyboard: switch legacy handlers to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (9 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 10/42] input: keyboard: add helper functions to core Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 12/42] input: keyboard: switch qmp_send_key() " Gerd Hoffmann
                   ` (30 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

legacy kbd event handlers are registered in the new core,
so they receive events from the new input core code.
keycode -> scancode translation needed here.

legacy kbd_put_keycode() sends events to the new core.
scancode -> keycode translation needed here.

So with this patch the new input core is fully functional
for keyboard events.  New + legacy interfaces can be mixed
in any way.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 56 insertions(+), 10 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 1c70f60..80f4f5c 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -29,6 +29,7 @@
 #include "qmp-commands.h"
 #include "qapi-types.h"
 #include "ui/keymaps.h"
+#include "ui/input.h"
 
 struct QEMUPutMouseEntry {
     QEMUPutMouseEvent *qemu_put_mouse_event;
@@ -45,7 +46,7 @@ struct QEMUPutMouseEntry {
 struct QEMUPutKbdEntry {
     QEMUPutKBDEvent *put_kbd;
     void *opaque;
-    QTAILQ_ENTRY(QEMUPutKbdEntry) next;
+    QemuInputHandlerState *s;
 };
 
 struct QEMUPutLEDEntry {
@@ -56,8 +57,6 @@ struct QEMUPutLEDEntry {
 
 static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
     QTAILQ_HEAD_INITIALIZER(led_handlers);
-static QTAILQ_HEAD(, QEMUPutKbdEntry) kbd_handlers =
-    QTAILQ_HEAD_INITIALIZER(kbd_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
     QTAILQ_HEAD_INITIALIZER(mouse_handlers);
 static NotifierList mouse_mode_notifiers =
@@ -312,20 +311,56 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
                    muldiv64(get_ticks_per_sec(), hold_time, 1000));
 }
 
+static void legacy_kbd_event(DeviceState *dev, QemuConsole *src,
+                             InputEvent *evt)
+{
+    QEMUPutKbdEntry *entry = (QEMUPutKbdEntry *)dev;
+    int keycode = keycode_from_keyvalue(evt->key->key);
+
+    if (!entry || !entry->put_kbd) {
+        return;
+    }
+    if (evt->key->key->kind == KEY_VALUE_KIND_QCODE &&
+        evt->key->key->qcode == Q_KEY_CODE_PAUSE) {
+        /* specific case */
+        int v = evt->key->down ? 0 : 0x80;
+        entry->put_kbd(entry->opaque, 0xe1);
+        entry->put_kbd(entry->opaque, 0x1d | v);
+        entry->put_kbd(entry->opaque, 0x45 | v);
+        return;
+    }
+    if (keycode & SCANCODE_GREY) {
+        entry->put_kbd(entry->opaque, SCANCODE_EMUL0);
+        keycode &= ~SCANCODE_GREY;
+    }
+    if (!evt->key->down) {
+        keycode |= SCANCODE_UP;
+    }
+    entry->put_kbd(entry->opaque, keycode);
+}
+
+static QemuInputHandler legacy_kbd_handler = {
+    .name  = "legacy-kbd",
+    .mask  = INPUT_EVENT_MASK_KEY,
+    .event = legacy_kbd_event,
+};
+
 QEMUPutKbdEntry *qemu_add_kbd_event_handler(QEMUPutKBDEvent *func, void *opaque)
 {
     QEMUPutKbdEntry *entry;
 
-    entry = g_malloc0(sizeof(QEMUPutKbdEntry));
+    entry = g_new0(QEMUPutKbdEntry, 1);
     entry->put_kbd = func;
     entry->opaque = opaque;
-    QTAILQ_INSERT_HEAD(&kbd_handlers, entry, next);
+    entry->s = qemu_input_handler_register((DeviceState *)entry,
+                                           &legacy_kbd_handler);
     return entry;
 }
 
 void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 {
-    QTAILQ_REMOVE(&kbd_handlers, entry, next);
+    qemu_input_handler_unregister(entry->s);
+    g_free(entry);
 }
 
 static void check_mode_change(void)
@@ -409,14 +444,25 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
 
 void kbd_put_keycode(int keycode)
 {
-    QEMUPutKbdEntry *entry = QTAILQ_FIRST(&kbd_handlers);
+    static bool emul0;
+    bool up;
 
-    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+    if (keycode == SCANCODE_EMUL0) {
+        emul0 = true;
         return;
     }
-    if (entry && entry->put_kbd) {
-        entry->put_kbd(entry->opaque, keycode);
+    if (keycode & SCANCODE_UP) {
+        keycode &= ~SCANCODE_UP;
+        up = true;
+    } else {
+        up = false;
+    }
+    if (emul0) {
+        keycode |= SCANCODE_GREY;
+        emul0 = false;
     }
+
+    qemu_input_event_send_key_number(NULL, keycode, !up);
 }
 
 void kbd_put_ledstate(int ledstate)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 12/42] input: keyboard: switch qmp_send_key() to new core.
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (10 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 11/42] input: keyboard: switch legacy handlers to new core Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui " Gerd Hoffmann
                   ` (29 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 80f4f5c..a4006cc 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -260,10 +260,8 @@ static void free_keycodes(void)
 static void release_keys(void *opaque)
 {
     while (keycodes_size > 0) {
-        if (keycodes[--keycodes_size] & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycodes[keycodes_size] | SCANCODE_UP);
+        qemu_input_event_send_key_number(NULL, keycodes[--keycodes_size],
+                                         false);
     }
 
     free_keycodes();
@@ -297,10 +295,7 @@ void qmp_send_key(KeyValueList *keys, bool has_hold_time, int64_t hold_time,
             return;
         }
 
-        if (keycode & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+        qemu_input_event_send_key_number(NULL, keycode, true);
 
         keycodes = g_realloc(keycodes, sizeof(int) * (keycodes_size + 1));
         keycodes[keycodes_size++] = keycode;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (11 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 12/42] input: keyboard: switch qmp_send_key() " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 14/42] input: keyboard: switch sdl " Gerd Hoffmann
                   ` (28 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 19 ++++---------------
 1 file changed, 4 insertions(+), 15 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 6316f5b..993a9b5 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -55,6 +55,7 @@
 
 #include "trace.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "qmp-commands.h"
 #include "x_keymap.h"
@@ -276,10 +277,7 @@ static void gtk_release_modifiers(GtkDisplayState *s)
         if (!s->modifier_pressed[i]) {
             continue;
         }
-        if (keycode & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key_number(s->dcl.con, keycode, false);
         s->modifier_pressed[i] = false;
     }
 }
@@ -733,17 +731,8 @@ static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
         }
     }
 
-    if (qemu_keycode & SCANCODE_GREY) {
-        kbd_put_keycode(SCANCODE_EMUL0);
-    }
-
-    if (key->type == GDK_KEY_PRESS) {
-        kbd_put_keycode(qemu_keycode & SCANCODE_KEYCODEMASK);
-    } else if (key->type == GDK_KEY_RELEASE) {
-        kbd_put_keycode(qemu_keycode | SCANCODE_UP);
-    } else {
-        g_assert_not_reached();
-    }
+    qemu_input_event_send_key_number(s->dcl.con, qemu_keycode,
+                                     key->type == GDK_KEY_PRESS);
 
     return TRUE;
 }
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 14/42] input: keyboard: switch sdl ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (12 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 15/42] sdl2: switch keyboard handling " Gerd Hoffmann
                   ` (27 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/sdl.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index 736bb95..c3b8036 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -32,6 +32,7 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "x_keymap.h"
 #include "sdl_zoom.h"
@@ -263,9 +264,7 @@ static void reset_keys(void)
     int i;
     for(i = 0; i < 256; i++) {
         if (modifiers_state[i]) {
-            if (i & SCANCODE_GREY)
-                kbd_put_keycode(SCANCODE_EMUL0);
-            kbd_put_keycode(i | SCANCODE_UP);
+            qemu_input_event_send_key_number(dcl->con, i, false);
             modifiers_state[i] = 0;
         }
     }
@@ -273,16 +272,12 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-    int keycode, v;
+    int keycode;
 
     if (ev->keysym.sym == SDLK_PAUSE) {
         /* specific case */
-        v = 0;
-        if (ev->type == SDL_KEYUP)
-            v |= SCANCODE_UP;
-        kbd_put_keycode(0xe1);
-        kbd_put_keycode(0x1d | v);
-        kbd_put_keycode(0x45 | v);
+        qemu_input_event_send_key_qcode(dcl->con, Q_KEY_CODE_PAUSE,
+                                        ev->type == SDL_KEYDOWN);
         return;
     }
 
@@ -314,19 +309,15 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     case 0x45: /* num lock */
     case 0x3a: /* caps lock */
         /* SDL does not send the key up event, so we generate it */
-        kbd_put_keycode(keycode);
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key_number(dcl->con, keycode, true);
+        qemu_input_event_send_key_number(dcl->con, keycode, false);
         return;
 #endif
     }
 
     /* now send the key code */
-    if (keycode & SCANCODE_GREY)
-        kbd_put_keycode(SCANCODE_EMUL0);
-    if (ev->type == SDL_KEYUP)
-        kbd_put_keycode(keycode | SCANCODE_UP);
-    else
-        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+    qemu_input_event_send_key_number(dcl->con, keycode,
+                                     ev->type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(void)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 15/42] sdl2: switch keyboard handling to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (13 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 14/42] input: keyboard: switch sdl " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui " Gerd Hoffmann
                   ` (26 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 ui/sdl2.c | 23 ++++++++++-------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index e7a30b3..ac3ac19 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -33,6 +33,7 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 #include "x_keymap.h"
 #include "sdl_zoom.h"
@@ -236,9 +237,7 @@ static void reset_keys(void)
     int i;
     for(i = 0; i < 256; i++) {
         if (modifiers_state[i]) {
-            if (i & SCANCODE_GREY)
-                kbd_put_keycode(SCANCODE_EMUL0);
-            kbd_put_keycode(i | SCANCODE_UP);
+            qemu_input_event_send_key_number(NULL, i, false);
             modifiers_state[i] = 0;
         }
     }
@@ -246,11 +245,12 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-    int keycode, v;
+    int keycode;
 
+#if 0
     if (ev->keysym.sym == SDLK_PAUSE) {
         /* specific case */
-        v = 0;
+        int v = 0;
         if (ev->type == SDL_KEYUP)
             v |= SCANCODE_UP;
         kbd_put_keycode(0xe1);
@@ -258,6 +258,7 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
         kbd_put_keycode(0x45 | v);
         return;
     }
+#endif
 
     if (kbd_layout) {
         keycode = sdl_keyevent_to_keycode_generic(ev);
@@ -284,18 +285,14 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     case 0x45: /* num lock */
     case 0x3a: /* caps lock */
         /* SDL does not send the key up event, so we generate it */
-        kbd_put_keycode(keycode);
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key_number(NULL, keycode, true);
+        qemu_input_event_send_key_number(NULL, keycode, false);
         return;
     }
 
     /* now send the key code */
-    if (keycode & SCANCODE_GREY)
-        kbd_put_keycode(SCANCODE_EMUL0);
-    if (ev->type == SDL_KEYUP)
-        kbd_put_keycode(keycode | SCANCODE_UP);
-    else
-        kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
+    qemu_input_event_send_key_number(NULL, keycode,
+                                     ev->type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(struct sdl2_console_state *scon)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (14 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 15/42] sdl2: switch keyboard handling " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 17/42] input: keyboard: switch spice " Gerd Hoffmann
                   ` (25 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 ui/vnc.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 5601cc3..4658559 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -33,6 +33,7 @@
 #include "qapi/qmp/types.h"
 #include "qmp-commands.h"
 #include "qemu/osdep.h"
+#include "ui/input.h"
 
 #define VNC_REFRESH_INTERVAL_BASE GUI_REFRESH_INTERVAL_DEFAULT
 #define VNC_REFRESH_INTERVAL_INC  50
@@ -1542,9 +1543,7 @@ static void reset_keys(VncState *vs)
     int i;
     for(i = 0; i < 256; i++) {
         if (vs->modifiers_state[i]) {
-            if (i & SCANCODE_GREY)
-                kbd_put_keycode(SCANCODE_EMUL0);
-            kbd_put_keycode(i | SCANCODE_UP);
+            qemu_input_event_send_key_number(vs->vd->dcl.con, i, false);
             vs->modifiers_state[i] = 0;
         }
     }
@@ -1553,12 +1552,8 @@ static void reset_keys(VncState *vs)
 static void press_key(VncState *vs, int keysym)
 {
     int keycode = keysym2scancode(vs->vd->kbd_layout, keysym) & SCANCODE_KEYMASK;
-    if (keycode & SCANCODE_GREY)
-        kbd_put_keycode(SCANCODE_EMUL0);
-    kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
-    if (keycode & SCANCODE_GREY)
-        kbd_put_keycode(SCANCODE_EMUL0);
-    kbd_put_keycode(keycode | SCANCODE_UP);
+    qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, true);
+    qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
 }
 
 static int current_led_state(VncState *vs)
@@ -1700,12 +1695,7 @@ static void do_key_event(VncState *vs, int down, int keycode, int sym)
     }
 
     if (qemu_console_is_graphic(NULL)) {
-        if (keycode & SCANCODE_GREY)
-            kbd_put_keycode(SCANCODE_EMUL0);
-        if (down)
-            kbd_put_keycode(keycode & SCANCODE_KEYCODEMASK);
-        else
-            kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, down);
     } else {
         bool numlock = vs->modifiers_state[0x45];
         bool control = (vs->modifiers_state[0x1d] ||
@@ -1826,10 +1816,7 @@ static void vnc_release_modifiers(VncState *vs)
         if (!vs->modifiers_state[keycode]) {
             continue;
         }
-        if (keycode & SCANCODE_GREY) {
-            kbd_put_keycode(SCANCODE_EMUL0);
-        }
-        kbd_put_keycode(keycode | SCANCODE_UP);
+        qemu_input_event_send_key_number(vs->vd->dcl.con, keycode, false);
     }
 }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 17/42] input: keyboard: switch spice ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (15 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 18/42] input: keyboard: switch curses " Gerd Hoffmann
                   ` (24 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 ui/spice-input.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/ui/spice-input.c b/ui/spice-input.c
index 3beb8de..c9df699 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -26,12 +26,15 @@
 #include "qemu-common.h"
 #include "ui/qemu-spice.h"
 #include "ui/console.h"
+#include "ui/keymaps.h"
+#include "ui/input.h"
 
 /* keyboard bits */
 
 typedef struct QemuSpiceKbd {
     SpiceKbdInstance sin;
     int ledstate;
+    bool emul0;
 } QemuSpiceKbd;
 
 static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag);
@@ -47,9 +50,24 @@ static const SpiceKbdInterface kbd_interface = {
     .get_leds           = kbd_get_leds,
 };
 
-static void kbd_push_key(SpiceKbdInstance *sin, uint8_t frag)
+static void kbd_push_key(SpiceKbdInstance *sin, uint8_t scancode)
 {
-    kbd_put_keycode(frag);
+    QemuSpiceKbd *kbd = container_of(sin, QemuSpiceKbd, sin);
+    int keycode;
+    bool up;
+
+    if (scancode == SCANCODE_EMUL0) {
+        kbd->emul0 = true;
+        return;
+    }
+    keycode = scancode & ~SCANCODE_UP;
+    up = scancode & SCANCODE_UP;
+    if (kbd->emul0) {
+        kbd->emul0 = false;
+        keycode |= SCANCODE_GREY;
+    }
+
+    qemu_input_event_send_key_number(NULL, keycode, !up);
 }
 
 static uint8_t kbd_get_leds(SpiceKbdInstance *sin)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 18/42] input: keyboard: switch curses ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (16 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 17/42] input: keyboard: switch spice " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core Gerd Hoffmann
                   ` (23 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 ui/curses.c | 47 +++++++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 22 deletions(-)

diff --git a/ui/curses.c b/ui/curses.c
index dbc3d5e..b044790 100644
--- a/ui/curses.c
+++ b/ui/curses.c
@@ -30,6 +30,7 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 
 #define FONT_HEIGHT 16
@@ -274,32 +275,34 @@ static void curses_refresh(DisplayChangeListener *dcl)
         if (qemu_console_is_graphic(NULL)) {
             /* since terminals don't know about key press and release
              * events, we need to emit both for each key received */
-            if (keycode & SHIFT)
-                kbd_put_keycode(SHIFT_CODE);
-            if (keycode & CNTRL)
-                kbd_put_keycode(CNTRL_CODE);
-            if (keycode & ALT)
-                kbd_put_keycode(ALT_CODE);
+            if (keycode & SHIFT) {
+                qemu_input_event_send_key_number(NULL, SHIFT_CODE, true);
+            }
+            if (keycode & CNTRL) {
+                qemu_input_event_send_key_number(NULL, CNTRL_CODE, true);
+            }
+            if (keycode & ALT) {
+                qemu_input_event_send_key_number(NULL, ALT_CODE, true);
+            }
             if (keycode & ALTGR) {
-                kbd_put_keycode(SCANCODE_EMUL0);
-                kbd_put_keycode(ALT_CODE);
+                qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
             }
-            if (keycode & GREY)
-                kbd_put_keycode(GREY_CODE);
-            kbd_put_keycode(keycode & KEY_MASK);
-            if (keycode & GREY)
-                kbd_put_keycode(GREY_CODE);
-            kbd_put_keycode((keycode & KEY_MASK) | KEY_RELEASE);
+
+            qemu_input_event_send_key_number(NULL, keycode, true);
+            qemu_input_event_send_key_number(NULL, keycode, false);
+
             if (keycode & ALTGR) {
-                kbd_put_keycode(SCANCODE_EMUL0);
-                kbd_put_keycode(ALT_CODE | KEY_RELEASE);
+                qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
+            }
+            if (keycode & ALT) {
+                qemu_input_event_send_key_number(NULL, ALT_CODE, false);
+            }
+            if (keycode & CNTRL) {
+                qemu_input_event_send_key_number(NULL, CNTRL_CODE, false);
+            }
+            if (keycode & SHIFT) {
+                qemu_input_event_send_key_number(NULL, SHIFT_CODE, false);
             }
-            if (keycode & ALT)
-                kbd_put_keycode(ALT_CODE | KEY_RELEASE);
-            if (keycode & CNTRL)
-                kbd_put_keycode(CNTRL_CODE | KEY_RELEASE);
-            if (keycode & SHIFT)
-                kbd_put_keycode(SHIFT_CODE | KEY_RELEASE);
         } else {
             keysym = curses2qemu[chr];
             if (keysym == -1)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (17 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 18/42] input: keyboard: switch curses " Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support Gerd Hoffmann
                   ` (22 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Likewise a bunch of helper functions to manage mouse button
and movement events, again to make life easier for the ui code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h | 14 +++++++++++
 ui/input.c         | 71 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 85 insertions(+)

diff --git a/include/ui/input.h b/include/ui/input.h
index 189f131..c6f50c2 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -8,6 +8,8 @@
 #define INPUT_EVENT_MASK_REL   (1<<INPUT_EVENT_KIND_REL)
 #define INPUT_EVENT_MASK_ABS   (1<<INPUT_EVENT_KIND_ABS)
 
+#define INPUT_EVENT_ABS_SIZE   0x8000
+
 typedef struct QemuInputHandler QemuInputHandler;
 typedef struct QemuInputHandlerState QemuInputHandlerState;
 
@@ -34,4 +36,16 @@ void qemu_input_event_send_key(QemuConsole *src, KeyValue *key, bool down);
 void qemu_input_event_send_key_number(QemuConsole *src, int num, bool down);
 void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down);
 
+InputEvent *qemu_input_event_new_btn(InputButton btn, bool down);
+void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
+void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
+                               uint32_t button_old, uint32_t button_new);
+
+int qemu_input_scale_axis(int value, int size_in, int size_out);
+InputEvent *qemu_input_event_new_move(InputEventKind kind,
+                                      InputAxis axis, int value);
+void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value);
+void qemu_input_queue_abs(QemuConsole *src, InputAxis axis,
+                          int value, int size);
+
 #endif /* INPUT_H */
diff --git a/ui/input.c b/ui/input.c
index 61c8089..a02172e 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -116,3 +116,74 @@ void qemu_input_event_send_key_qcode(QemuConsole *src, QKeyCode q, bool down)
     key->qcode = q;
     qemu_input_event_send_key(src, key, down);
 }
+
+InputEvent *qemu_input_event_new_btn(InputButton btn, bool down)
+{
+    InputEvent *evt = g_new0(InputEvent, 1);
+    evt->btn = g_new0(InputBtnEvent, 1);
+    evt->kind = INPUT_EVENT_KIND_BTN;
+    evt->btn->button = btn;
+    evt->btn->down = down;
+    return evt;
+}
+
+void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down)
+{
+    InputEvent *evt;
+    evt = qemu_input_event_new_btn(btn, down);
+    qemu_input_event_send(src, evt);
+    qapi_free_InputEvent(evt);
+}
+
+void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
+                               uint32_t button_old, uint32_t button_new)
+{
+    InputButton btn;
+    uint32_t mask;
+
+    for (btn = 0; btn < INPUT_BUTTON_MAX; btn++) {
+        mask = button_map[btn];
+        if ((button_old & mask) == (button_new & mask)) {
+            continue;
+        }
+        qemu_input_queue_btn(src, btn, button_new & mask);
+    }
+}
+
+int qemu_input_scale_axis(int value, int size_in, int size_out)
+{
+    if (size_in < 2) {
+        return size_out / 2;
+    }
+    return (int64_t)value * (size_out - 1) / (size_in - 1);
+}
+
+InputEvent *qemu_input_event_new_move(InputEventKind kind,
+                                      InputAxis axis, int value)
+{
+    InputEvent *evt = g_new0(InputEvent, 1);
+    InputMoveEvent *move = g_new0(InputMoveEvent, 1);
+
+    evt->kind = kind;
+    evt->data = move;
+    move->axis = axis;
+    move->value = value;
+    return evt;
+}
+
+void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value)
+{
+    InputEvent *evt;
+    evt = qemu_input_event_new_move(INPUT_EVENT_KIND_REL, axis, value);
+    qemu_input_event_send(src, evt);
+    qapi_free_InputEvent(evt);
+}
+
+void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size)
+{
+    InputEvent *evt;
+    int scaled = qemu_input_scale_axis(value, size, INPUT_EVENT_ABS_SIZE);
+    evt = qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled);
+    qemu_input_event_send(src, evt);
+    qapi_free_InputEvent(evt);
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (18 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 21/42] input: mouse: add qemu_input_is_absolute() Gerd Hoffmann
                   ` (21 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Transform absolute mouse events according to graphic_rotate.

Legacy input code does it for both absolute and relative events,
but the logic is broken for relative coordinates, so this is
most likely not used anyway.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/ui/input.c b/ui/input.c
index a02172e..2c4d4d6 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -50,6 +50,33 @@ qemu_input_find_handler(uint32_t mask)
     return NULL;
 }
 
+static void qemu_input_transform_abs_rotate(InputEvent *evt)
+{
+    switch (graphic_rotate) {
+    case 90:
+        if (evt->abs->axis == INPUT_AXIS_X) {
+            evt->abs->axis = INPUT_AXIS_Y;
+        }
+        if (evt->abs->axis == INPUT_AXIS_Y) {
+            evt->abs->axis = INPUT_AXIS_X;
+            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        }
+        break;
+    case 180:
+        evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        break;
+    case 270:
+        if (evt->abs->axis == INPUT_AXIS_X) {
+            evt->abs->axis = INPUT_AXIS_Y;
+            evt->abs->axis = INPUT_EVENT_ABS_SIZE - 1 - evt->abs->axis;
+        }
+        if (evt->abs->axis == INPUT_AXIS_Y) {
+            evt->abs->axis = INPUT_AXIS_X;
+        }
+        break;
+    }
+}
+
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 {
     QemuInputHandlerState *s;
@@ -58,6 +85,12 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
         return;
     }
 
+    /* pre processing */
+    if (graphic_rotate && (evt->kind == INPUT_EVENT_KIND_ABS)) {
+            qemu_input_transform_abs_rotate(evt);
+    }
+
+    /* send event */
     s = qemu_input_find_handler(1 << evt->kind);
     s->handler->event(s->dev, src, evt);
     s->events++;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 21/42] input: mouse: add qemu_input_is_absolute()
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (19 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core Gerd Hoffmann
                   ` (20 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Same as kbd_mouse_is_absolute(), but using new input core.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h | 1 +
 ui/input.c         | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/ui/input.h b/include/ui/input.h
index c6f50c2..28afc45 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -41,6 +41,7 @@ void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
 void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
                                uint32_t button_old, uint32_t button_new);
 
+bool qemu_input_is_absolute(void);
 int qemu_input_scale_axis(int value, int size_in, int size_out);
 InputEvent *qemu_input_event_new_move(InputEventKind kind,
                                       InputAxis axis, int value);
diff --git a/ui/input.c b/ui/input.c
index 2c4d4d6..30a5b70 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -183,6 +183,14 @@ void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
     }
 }
 
+bool qemu_input_is_absolute(void)
+{
+    QemuInputHandlerState *s;
+
+    s = qemu_input_find_handler(INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS);
+    return (s != NULL) && (s->handler->mask & INPUT_EVENT_MASK_ABS);
+}
+
 int qemu_input_scale_axis(int value, int size_in, int size_out)
 {
     if (size_in < 2) {
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (20 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 21/42] input: mouse: add qemu_input_is_absolute() Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 23/42] input: mouse: switch gtk ui " Gerd Hoffmann
                   ` (19 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

legacy mouse event handlers are registered in the new core,
so they receive events submitted to the new input core.

legacy kbd_mouse_event() continues to use the old code paths.
So new-core event handlers wouldn't see events submitted via
kbd_mouse_event.

This leads to the constrain that we we must transition all
kbd_mouse_event() users first to keep things working.  But
that is easier to handle than translating legacy mouse events
into new-core mouse events ;)

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 63 insertions(+)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index a4006cc..dd2dec3 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -41,6 +41,12 @@ struct QEMUPutMouseEntry {
 
     /* used internally by qemu for handling mice */
     QTAILQ_ENTRY(QEMUPutMouseEntry) node;
+
+    /* new input core */
+    QemuInputHandler h;
+    QemuInputHandlerState *s;
+    int axis[INPUT_AXIS_MAX];
+    int buttons;
 };
 
 struct QEMUPutKbdEntry {
@@ -376,6 +382,51 @@ static void check_mode_change(void)
     current_has_absolute = has_absolute;
 }
 
+static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
+                               InputEvent *evt)
+{
+    static const int bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]   = MOUSE_EVENT_LBUTTON,
+        [INPUT_BUTTON_MIDDLE] = MOUSE_EVENT_MBUTTON,
+        [INPUT_BUTTON_RIGHT]  = MOUSE_EVENT_RBUTTON,
+    };
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    switch (evt->kind) {
+    case INPUT_EVENT_KIND_BTN:
+        if (evt->btn->down) {
+            s->buttons |= bmap[evt->btn->button];
+        } else {
+            s->buttons &= ~bmap[evt->btn->button];
+        }
+        break;
+    case INPUT_EVENT_KIND_ABS:
+        s->axis[evt->abs->axis] = evt->abs->value;
+        break;
+    case INPUT_EVENT_KIND_REL:
+        s->axis[evt->rel->axis] += evt->rel->value;
+        break;
+    default:
+        break;
+    }
+}
+
+static void legacy_mouse_sync(DeviceState *dev)
+{
+    QEMUPutMouseEntry *s = (QEMUPutMouseEntry *)dev;
+
+    s->qemu_put_mouse_event(s->qemu_put_mouse_event_opaque,
+                            s->axis[INPUT_AXIS_X],
+                            s->axis[INPUT_AXIS_Y],
+                            0,
+                            s->buttons);
+
+    if (!s->qemu_put_mouse_event_absolute) {
+        s->axis[INPUT_AXIS_X] = 0;
+        s->axis[INPUT_AXIS_Y] = 0;
+    }
+}
+
 QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 void *opaque, int absolute,
                                                 const char *name)
@@ -393,6 +444,14 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
     QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
 
+    s->h.name = name;
+    s->h.mask = INPUT_EVENT_MASK_BTN |
+        (absolute ? INPUT_EVENT_MASK_ABS : INPUT_EVENT_MASK_REL);
+    s->h.event = legacy_mouse_event;
+    s->h.sync = legacy_mouse_sync;
+    s->s = qemu_input_handler_register((DeviceState *)s,
+                                       &s->h);
+
     check_mode_change();
 
     return s;
@@ -403,6 +462,8 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
     QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
 
+    qemu_input_handler_activate(entry->s);
+
     check_mode_change();
 }
 
@@ -410,6 +471,8 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
     QTAILQ_REMOVE(&mouse_handlers, entry, node);
 
+    qemu_input_handler_unregister(entry->s);
+
     g_free(entry->qemu_put_mouse_event_name);
     g_free(entry);
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 23/42] input: mouse: switch gtk ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (21 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core Gerd Hoffmann
@ 2013-12-16 10:48 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 24/42] input: mouse: switch sdl " Gerd Hoffmann
                   ` (18 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:48 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/gtk.c | 58 +++++++++++++++++++---------------------------------------
 1 file changed, 19 insertions(+), 39 deletions(-)

diff --git a/ui/gtk.c b/ui/gtk.c
index 993a9b5..64a0228 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -190,7 +190,7 @@ static void gd_update_cursor(GtkDisplayState *s, gboolean override)
     on_vga = gd_on_vga(s);
 
     if ((override || on_vga) &&
-        (s->full_screen || kbd_mouse_is_absolute() || gd_is_grab_active(s))) {
+        (s->full_screen || qemu_input_is_absolute() || gd_is_grab_active(s))) {
         gdk_window_set_cursor(window, s->null_cursor);
     } else {
         gdk_window_set_cursor(window, NULL);
@@ -576,7 +576,6 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
                                 void *opaque)
 {
     GtkDisplayState *s = opaque;
-    int dx, dy;
     int x, y;
     int mx, my;
     int fbh, fbw;
@@ -604,25 +603,21 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion,
         return TRUE;
     }
 
-    if (kbd_mouse_is_absolute()) {
-        dx = x * 0x7FFF / (surface_width(s->ds) - 1);
-        dy = y * 0x7FFF / (surface_height(s->ds) - 1);
-    } else if (s->last_x == -1 || s->last_y == -1) {
-        dx = 0;
-        dy = 0;
-    } else {
-        dx = x - s->last_x;
-        dy = y - s->last_y;
+    if (qemu_input_is_absolute()) {
+        qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_X, x,
+                             surface_width(s->ds));
+        qemu_input_queue_abs(s->dcl.con, INPUT_AXIS_Y, y,
+                             surface_height(s->ds));
+        qemu_input_event_sync();
+    } else if (s->last_x != -1 && s->last_y != -1 && gd_is_grab_active(s)) {
+        qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_X, x - s->last_x);
+        qemu_input_queue_rel(s->dcl.con, INPUT_AXIS_Y, y - s->last_y);
+        qemu_input_event_sync();
     }
-
     s->last_x = x;
     s->last_y = y;
 
-    if (kbd_mouse_is_absolute() || gd_is_grab_active(s)) {
-        kbd_mouse_event(dx, dy, 0, s->button_mask);
-    }
-
-    if (!kbd_mouse_is_absolute() && gd_is_grab_active(s)) {
+    if (!qemu_input_is_absolute() && gd_is_grab_active(s)) {
         GdkScreen *screen = gtk_widget_get_screen(s->drawing_area);
         int x = (int)motion->x_root;
         int y = (int)motion->y_root;
@@ -667,35 +662,20 @@ static gboolean gd_button_event(GtkWidget *widget, GdkEventButton *button,
                                 void *opaque)
 {
     GtkDisplayState *s = opaque;
-    int dx, dy;
-    int n;
+    InputButton btn;
 
     if (button->button == 1) {
-        n = 0x01;
+        btn = INPUT_BUTTON_LEFT;
     } else if (button->button == 2) {
-        n = 0x04;
+        btn = INPUT_BUTTON_MIDDLE;
     } else if (button->button == 3) {
-        n = 0x02;
-    } else {
-        n = 0x00;
-    }
-
-    if (button->type == GDK_BUTTON_PRESS) {
-        s->button_mask |= n;
-    } else if (button->type == GDK_BUTTON_RELEASE) {
-        s->button_mask &= ~n;
-    }
-
-    if (kbd_mouse_is_absolute()) {
-        dx = s->last_x * 0x7FFF / (surface_width(s->ds) - 1);
-        dy = s->last_y * 0x7FFF / (surface_height(s->ds) - 1);
+        btn = INPUT_BUTTON_RIGHT;
     } else {
-        dx = 0;
-        dy = 0;
+        return TRUE;
     }
 
-    kbd_mouse_event(dx, dy, 0, s->button_mask);
-        
+    qemu_input_queue_btn(s->dcl.con, btn, button->type == GDK_BUTTON_PRESS);
+    qemu_input_event_sync();
     return TRUE;
 }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 24/42] input: mouse: switch sdl ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (22 preceding siblings ...)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 23/42] input: mouse: switch gtk ui " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 25/42] sdl2: switch mouse handling " Gerd Hoffmann
                   ` (17 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/sdl.c | 84 ++++++++++++++++++++++++++++++----------------------------------
 1 file changed, 39 insertions(+), 45 deletions(-)

diff --git a/ui/sdl.c b/ui/sdl.c
index c3b8036..c1a16be 100644
--- a/ui/sdl.c
+++ b/ui/sdl.c
@@ -353,7 +353,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 {
@@ -366,10 +366,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);
@@ -388,8 +388,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);
@@ -418,7 +419,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)) {
@@ -433,33 +434,36 @@ 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)
+static void sdl_send_mouse_event(int dx, int dy, 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),
+        [INPUT_BUTTON_WHEEL_UP]   = SDL_BUTTON(SDL_BUTTON_WHEELUP),
+        [INPUT_BUTTON_WHEEL_DOWN] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN),
+    };
+    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)
@@ -687,7 +691,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 ||
@@ -700,8 +704,8 @@ static void handle_mousemotion(SDL_Event *ev)
             sdl_grab_start();
         }
     }
-    if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
-        sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel, 0,
+    if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
+        sdl_send_mouse_event(ev->motion.xrel, ev->motion.yrel,
                              ev->motion.x, ev->motion.y, ev->motion.state);
     }
 }
@@ -710,35 +714,24 @@ static void handle_mousebutton(SDL_Event *ev)
 {
     int buttonstate = SDL_GetMouseState(NULL, NULL);
     SDL_MouseButtonEvent *bev;
-    int dz;
 
     if (!qemu_console_is_graphic(NULL)) {
         return;
     }
 
     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();
         }
     } else {
-        dz = 0;
         if (ev->type == SDL_MOUSEBUTTONDOWN) {
             buttonstate |= SDL_BUTTON(bev->button);
         } else {
             buttonstate &= ~SDL_BUTTON(bev->button);
         }
-#ifdef SDL_BUTTON_WHEELUP
-        if (bev->button == SDL_BUTTON_WHEELUP &&
-            ev->type == SDL_MOUSEBUTTONDOWN) {
-            dz = -1;
-        } else if (bev->button == SDL_BUTTON_WHEELDOWN &&
-                   ev->type == SDL_MOUSEBUTTONDOWN) {
-            dz = 1;
-        }
-#endif
-        sdl_send_mouse_event(0, 0, dz, bev->x, bev->y, buttonstate);
+        sdl_send_mouse_event(0, 0, bev->x, bev->y, buttonstate);
     }
 }
 
@@ -753,7 +746,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) {
@@ -825,10 +818,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();
@@ -856,7 +850,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

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 25/42] sdl2: switch mouse handling to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (23 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 24/42] input: mouse: switch sdl " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 26/42] input: mouse: switch vnc ui " Gerd Hoffmann
                   ` (16 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/sdl2.c | 60 +++++++++++++++++++++++++++++++-----------------------------
 1 file changed, 31 insertions(+), 29 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index ac3ac19..e841424 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -329,7 +329,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 {
@@ -342,10 +342,10 @@ static void sdl_show_cursor(void)
     if (!cursor_hide)
         return;
 
-    if (!kbd_mouse_is_absolute()) {
+    if (!qemu_input_is_absolute()) {
         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);
@@ -364,7 +364,7 @@ static void sdl_grab_start(struct sdl2_console_state *scon)
     }
     if (guest_cursor) {
         SDL_SetCursor(guest_sprite);
-        if (!kbd_mouse_is_absolute() && !absolute_enabled) {
+        if (!qemu_input_is_absolute() && !absolute_enabled) {
             SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
         }
     } else
@@ -396,7 +396,7 @@ static void absolute_mouse_grab(struct sdl2_console_state *scon)
 
 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;
             absolute_mouse_grab(&sdl2_console[0]);
@@ -411,19 +411,23 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
 
 static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy, int dz, int x, int y, int state)
 {
-    int buttons = 0;
+    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),
+#if 0
+        [INPUT_BUTTON_WHEEL_UP]   = SDL_BUTTON(SDL_BUTTON_WHEELUP),
+        [INPUT_BUTTON_WHEEL_DOWN] = SDL_BUTTON(SDL_BUTTON_WHEELDOWN),
+#endif
+    };
+    static uint32_t prev_state;
 
-    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 (prev_state != state) {
+        qemu_input_update_buttons(scon->dcl.con, bmap, prev_state, state);
+        prev_state = state;
     }
 
-    if (kbd_mouse_is_absolute()) {
+    if (qemu_input_is_absolute()) {
         int scr_w, scr_h;
         int max_w = 0, max_h = 0;
         int off_x = 0, off_y = 0;
@@ -446,19 +450,17 @@ static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy
                 }
             }
         }
-
-        dx = (off_x + x) * 0x7FFF / (max_w - 1);
-        dy = (off_y + y) * 0x7FFF / (max_h - 1);
+        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_X, off_x + x, max_w);
+        qemu_input_queue_abs(scon->dcl.con, INPUT_AXIS_Y, off_y + y, max_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(scon->dcl.con, INPUT_AXIS_X, x);
+        qemu_input_queue_rel(scon->dcl.con, INPUT_AXIS_Y, y);
     }
-
-    kbd_mouse_event(dx, dy, dz, buttons);
+    qemu_input_event_sync();
 }
 
 static void sdl_scale(struct sdl2_console_state *scon, int width, int height)
@@ -592,7 +594,7 @@ static void handle_mousemotion(SDL_Event *ev)
     int max_x, max_y;
     struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
-    if (kbd_mouse_is_absolute() || absolute_enabled) {
+    if (qemu_input_is_absolute() || absolute_enabled) {
         int scr_w, scr_h;
         SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
         max_x = scr_w - 1;
@@ -607,7 +609,7 @@ static void handle_mousemotion(SDL_Event *ev)
             sdl_grab_start(scon);
         }
     }
-    if (gui_grab || kbd_mouse_is_absolute() || absolute_enabled) {
+    if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
         sdl_send_mouse_event(scon, ev->motion.xrel, ev->motion.yrel, 0,
                              ev->motion.x, ev->motion.y, ev->motion.state);
     }
@@ -621,7 +623,7 @@ static void handle_mousebutton(SDL_Event *ev)
     int dz;
 
     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(scon);
@@ -663,7 +665,7 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
         break;
     case SDL_WINDOWEVENT_FOCUS_GAINED:
     case SDL_WINDOWEVENT_ENTER:
-        if (!gui_grab && (kbd_mouse_is_absolute() || absolute_enabled)) {
+        if (!gui_grab && (qemu_input_is_absolute() || absolute_enabled)) {
             absolute_mouse_grab(scon);
         }
         break;
@@ -735,9 +737,9 @@ 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_WarpMouseInWindow(scon->real_window, x, y);
             }
         }
@@ -772,7 +774,7 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
         return;
     }
     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

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 26/42] input: mouse: switch vnc ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (24 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 25/42] sdl2: switch mouse handling " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 27/42] input: mouse: switch spice " Gerd Hoffmann
                   ` (15 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/vnc.c | 46 ++++++++++++++++++++++------------------------
 ui/vnc.h |  1 +
 2 files changed, 23 insertions(+), 24 deletions(-)

diff --git a/ui/vnc.c b/ui/vnc.c
index 4658559..7dfc94a 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -1484,7 +1484,7 @@ static void client_cut_text(VncState *vs, size_t len, uint8_t *text)
 static void check_pointer_type_change(Notifier *notifier, void *data)
 {
     VncState *vs = container_of(notifier, VncState, mouse_mode_notifier);
-    int absolute = kbd_mouse_is_absolute();
+    int absolute = qemu_input_is_absolute();
 
     if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE) && vs->absolute != absolute) {
         vnc_lock_output(vs);
@@ -1503,39 +1503,37 @@ static void check_pointer_type_change(Notifier *notifier, void *data)
 
 static void pointer_event(VncState *vs, int button_mask, int x, int y)
 {
-    int buttons = 0;
-    int dz = 0;
+    static uint32_t bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]       = 0x01,
+        [INPUT_BUTTON_MIDDLE]     = 0x02,
+        [INPUT_BUTTON_RIGHT]      = 0x04,
+        [INPUT_BUTTON_WHEEL_UP]   = 0x08,
+        [INPUT_BUTTON_WHEEL_DOWN] = 0x10,
+    };
+    QemuConsole *con = vs->vd->dcl.con;
     int width = surface_width(vs->vd->ds);
     int height = surface_height(vs->vd->ds);
 
-    if (button_mask & 0x01)
-        buttons |= MOUSE_EVENT_LBUTTON;
-    if (button_mask & 0x02)
-        buttons |= MOUSE_EVENT_MBUTTON;
-    if (button_mask & 0x04)
-        buttons |= MOUSE_EVENT_RBUTTON;
-    if (button_mask & 0x08)
-        dz = -1;
-    if (button_mask & 0x10)
-        dz = 1;
+    if (vs->last_bmask != button_mask) {
+        qemu_input_update_buttons(con, bmap, vs->last_bmask, button_mask);
+        vs->last_bmask = button_mask;
+    }
 
     if (vs->absolute) {
-        kbd_mouse_event(width  > 1 ? x * 0x7FFF / (width  - 1) : 0x4000,
-                        height > 1 ? y * 0x7FFF / (height - 1) : 0x4000,
-                        dz, buttons);
+        qemu_input_queue_abs(con, INPUT_AXIS_X, x, width);
+        qemu_input_queue_abs(con, INPUT_AXIS_Y, y, height);
     } else if (vnc_has_feature(vs, VNC_FEATURE_POINTER_TYPE_CHANGE)) {
-        x -= 0x7FFF;
-        y -= 0x7FFF;
-
-        kbd_mouse_event(x, y, dz, buttons);
+        qemu_input_queue_rel(con, INPUT_AXIS_X, x - 0x7FFF);
+        qemu_input_queue_rel(con, INPUT_AXIS_Y, y - 0x7FFF);
     } else {
-        if (vs->last_x != -1)
-            kbd_mouse_event(x - vs->last_x,
-                            y - vs->last_y,
-                            dz, buttons);
+        if (vs->last_x != -1) {
+            qemu_input_queue_rel(con, INPUT_AXIS_X, x - vs->last_x);
+            qemu_input_queue_rel(con, INPUT_AXIS_Y, y - vs->last_y);
+        }
         vs->last_x = x;
         vs->last_y = y;
     }
+    qemu_input_event_sync();
 }
 
 static void reset_keys(VncState *vs)
diff --git a/ui/vnc.h b/ui/vnc.h
index 6e99213..e63c142 100644
--- a/ui/vnc.h
+++ b/ui/vnc.h
@@ -257,6 +257,7 @@ struct VncState
     int absolute;
     int last_x;
     int last_y;
+    uint32_t last_bmask;
     int client_width;
     int client_height;
     VncShareMode share_mode;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 27/42] input: mouse: switch spice ui to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (25 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 26/42] input: mouse: switch vnc ui " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 28/42] input: mouse: switch monitor " Gerd Hoffmann
                   ` (14 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/spice-input.c | 62 ++++++++++++++++++++++++++++++++++----------------------
 1 file changed, 38 insertions(+), 24 deletions(-)

diff --git a/ui/spice-input.c b/ui/spice-input.c
index c9df699..6dab23b 100644
--- a/ui/spice-input.c
+++ b/ui/spice-input.c
@@ -98,41 +98,52 @@ static void kbd_leds(void *opaque, int ledstate)
 typedef struct QemuSpicePointer {
     SpiceMouseInstance  mouse;
     SpiceTabletInstance tablet;
-    int width, height, x, y;
+    int width, height;
+    uint32_t last_bmask;
     Notifier mouse_mode;
     bool absolute;
 } QemuSpicePointer;
 
-static int map_buttons(int spice_buttons)
+static void spice_update_buttons(QemuSpicePointer *pointer,
+                                 int wheel, uint32_t button_mask)
 {
-    int qemu_buttons = 0;
-
-    /*
-     * Note: SPICE_MOUSE_BUTTON_* specifies the wire protocol but this
-     * isn't what we get passed in via interface callbacks for the
-     * middle and right button ...
-     */
-    if (spice_buttons & SPICE_MOUSE_BUTTON_MASK_LEFT) {
-        qemu_buttons |= MOUSE_EVENT_LBUTTON;
+    static uint32_t bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]        = 0x01,
+        [INPUT_BUTTON_MIDDLE]      = 0x04,
+        [INPUT_BUTTON_RIGHT]       = 0x02,
+        [INPUT_BUTTON_WHEEL_UP]    = 0x10,
+        [INPUT_BUTTON_WHEEL_DOWN]  = 0x20,
+    };
+
+    if (wheel < 0) {
+        button_mask |= 0x10;
     }
-    if (spice_buttons & 0x04 /* SPICE_MOUSE_BUTTON_MASK_MIDDLE */) {
-        qemu_buttons |= MOUSE_EVENT_MBUTTON;
+    if (wheel > 0) {
+        button_mask |= 0x20;
     }
-    if (spice_buttons & 0x02 /* SPICE_MOUSE_BUTTON_MASK_RIGHT */) {
-        qemu_buttons |= MOUSE_EVENT_RBUTTON;
+
+    if (pointer->last_bmask == button_mask) {
+        return;
     }
-    return qemu_buttons;
+    qemu_input_update_buttons(NULL, bmap, pointer->last_bmask, button_mask);
+    pointer->last_bmask = button_mask;
 }
 
 static void mouse_motion(SpiceMouseInstance *sin, int dx, int dy, int dz,
                          uint32_t buttons_state)
 {
-    kbd_mouse_event(dx, dy, dz, map_buttons(buttons_state));
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse);
+    spice_update_buttons(pointer, dz, buttons_state);
+    qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
+    qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
+    qemu_input_event_sync();
 }
 
 static void mouse_buttons(SpiceMouseInstance *sin, uint32_t buttons_state)
 {
-    kbd_mouse_event(0, 0, 0, map_buttons(buttons_state));
+    QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, mouse);
+    spice_update_buttons(pointer, 0, buttons_state);
+    qemu_input_event_sync();
 }
 
 static const SpiceMouseInterface mouse_interface = {
@@ -163,9 +174,10 @@ static void tablet_position(SpiceTabletInstance* sin, int x, int y,
 {
     QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-    pointer->x = x * 0x7FFF / (pointer->width - 1);
-    pointer->y = y * 0x7FFF / (pointer->height - 1);
-    kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state));
+    spice_update_buttons(pointer, 0, buttons_state);
+    qemu_input_queue_abs(NULL, INPUT_AXIS_X, x, pointer->width);
+    qemu_input_queue_abs(NULL, INPUT_AXIS_Y, y, pointer->width);
+    qemu_input_event_sync();
 }
 
 
@@ -174,7 +186,8 @@ static void tablet_wheel(SpiceTabletInstance* sin, int wheel,
 {
     QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-    kbd_mouse_event(pointer->x, pointer->y, wheel, map_buttons(buttons_state));
+    spice_update_buttons(pointer, wheel, buttons_state);
+    qemu_input_event_sync();
 }
 
 static void tablet_buttons(SpiceTabletInstance *sin,
@@ -182,7 +195,8 @@ static void tablet_buttons(SpiceTabletInstance *sin,
 {
     QemuSpicePointer *pointer = container_of(sin, QemuSpicePointer, tablet);
 
-    kbd_mouse_event(pointer->x, pointer->y, 0, map_buttons(buttons_state));
+    spice_update_buttons(pointer, 0, buttons_state);
+    qemu_input_event_sync();
 }
 
 static const SpiceTabletInterface tablet_interface = {
@@ -199,7 +213,7 @@ static const SpiceTabletInterface tablet_interface = {
 static void mouse_mode_notifier(Notifier *notifier, void *data)
 {
     QemuSpicePointer *pointer = container_of(notifier, QemuSpicePointer, mouse_mode);
-    bool is_absolute  = kbd_mouse_is_absolute();
+    bool is_absolute  = qemu_input_is_absolute();
 
     if (pointer->absolute == is_absolute) {
         return;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 28/42] input: mouse: switch monitor to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (26 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 27/42] input: mouse: switch spice " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested] Gerd Hoffmann
                   ` (13 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Luiz Capitulino

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 monitor.c | 31 ++++++++++++++++++++++++++-----
 1 file changed, 26 insertions(+), 5 deletions(-)

diff --git a/monitor.c b/monitor.c
index 845f608..d22e720 100644
--- a/monitor.c
+++ b/monitor.c
@@ -39,6 +39,7 @@
 #include "monitor/monitor.h"
 #include "monitor/readline.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/blockdev.h"
 #include "audio/audio.h"
 #include "disas/disas.h"
@@ -1457,23 +1458,43 @@ static int mouse_button_state;
 
 static void do_mouse_move(Monitor *mon, const QDict *qdict)
 {
-    int dx, dy, dz;
+    int dx, dy, dz, button;
     const char *dx_str = qdict_get_str(qdict, "dx_str");
     const char *dy_str = qdict_get_str(qdict, "dy_str");
     const char *dz_str = qdict_get_try_str(qdict, "dz_str");
+
     dx = strtol(dx_str, NULL, 0);
     dy = strtol(dy_str, NULL, 0);
-    dz = 0;
-    if (dz_str)
+    qemu_input_queue_rel(NULL, INPUT_AXIS_X, dx);
+    qemu_input_queue_rel(NULL, INPUT_AXIS_Y, dy);
+
+    if (dz_str) {
         dz = strtol(dz_str, NULL, 0);
-    kbd_mouse_event(dx, dy, dz, mouse_button_state);
+        if (dz != 0) {
+            button = (dz > 0) ? INPUT_BUTTON_WHEEL_UP : INPUT_BUTTON_WHEEL_DOWN;
+            qemu_input_queue_btn(NULL, button, true);
+            qemu_input_event_sync();
+            qemu_input_queue_btn(NULL, button, false);
+        }
+    }
+    qemu_input_event_sync();
 }
 
 static void do_mouse_button(Monitor *mon, const QDict *qdict)
 {
+    static uint32_t bmap[INPUT_BUTTON_MAX] = {
+        [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
+        [INPUT_BUTTON_MIDDLE]     = MOUSE_EVENT_MBUTTON,
+        [INPUT_BUTTON_RIGHT]      = MOUSE_EVENT_RBUTTON,
+    };
     int button_state = qdict_get_int(qdict, "button_state");
+
+    if (mouse_button_state == button_state) {
+        return;
+    }
+    qemu_input_update_buttons(NULL, bmap, mouse_button_state, button_state);
+    qemu_input_event_sync();
     mouse_button_state = button_state;
-    kbd_mouse_event(0, 0, 0, mouse_button_state);
 }
 
 static void do_ioport_read(Monitor *mon, const QDict *qdict)
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested]
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (27 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 28/42] input: mouse: switch monitor " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 30/42] input: mouse: " Gerd Hoffmann
                   ` (12 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Gerd Hoffmann, Anthony Liguori

---
 ui/cocoa.m | 18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/ui/cocoa.m b/ui/cocoa.m
index be49179..a029493 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -496,16 +496,14 @@ QemuCocoaView *cocoaView;
             keycode = cocoa_keycode_to_qemu([event keyCode]);
             if (keycode) {
                 if (keycode == 58 || keycode == 69) { // emulate caps lock and num lock keydown and keyup
-                    kbd_put_keycode(keycode);
-                    kbd_put_keycode(keycode | 0x80);
+                    qemu_input_event_send_key_number(dcl->con, keycode, true);
+                    qemu_input_event_send_key_number(dcl->con, keycode, false);
                 } else if (qemu_console_is_graphic(NULL)) {
-                    if (keycode & 0x80)
-                        kbd_put_keycode(0xe0);
                     if (modifiers_state[keycode] == 0) { // keydown
-                        kbd_put_keycode(keycode & 0x7f);
+                        qemu_input_event_send_key_number(dcl->con, keycode, true);
                         modifiers_state[keycode] = 1;
                     } else { // keyup
-                        kbd_put_keycode(keycode | 0x80);
+                        qemu_input_event_send_key_number(dcl->con, keycode, false);
                         modifiers_state[keycode] = 0;
                     }
                 }
@@ -539,9 +537,7 @@ QemuCocoaView *cocoaView;
 
             // handle keys for graphic console
             } else if (qemu_console_is_graphic(NULL)) {
-                if (keycode & 0x80) //check bit for e0 in front
-                    kbd_put_keycode(0xe0);
-                kbd_put_keycode(keycode & 0x7f); //remove e0 bit in front
+                qemu_input_event_send_key_number(dcl->con, keycode, true);
 
             // handlekeys for Monitor
             } else {
@@ -582,9 +578,7 @@ QemuCocoaView *cocoaView;
         case NSKeyUp:
             keycode = cocoa_keycode_to_qemu([event keyCode]);
             if (qemu_console_is_graphic(NULL)) {
-                if (keycode & 0x80)
-                    kbd_put_keycode(0xe0);
-                kbd_put_keycode(keycode | 0x80); //add 128 to signal release of key
+                qemu_input_event_send_key_number(dcl->con, keycode, false);
             }
             break;
         case NSMouseMoved:
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 30/42] input: mouse: switch cocoa ui to new core [untested]
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (28 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested] Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 31/42] input: trace events Gerd Hoffmann
                   ` (11 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Andreas Färber, Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  2 ++
 ui/cocoa.m           | 63 ++++++++++++++++++++++++++++++++++------------------
 2 files changed, 44 insertions(+), 21 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 8543d18..a3062d0 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -14,6 +14,8 @@
 #define MOUSE_EVENT_LBUTTON 0x01
 #define MOUSE_EVENT_RBUTTON 0x02
 #define MOUSE_EVENT_MBUTTON 0x04
+#define MOUSE_EVENT_WHEELUP 0x08
+#define MOUSE_EVENT_WHEELDN 0x10
 
 /* identical to the ps/2 keyboard bits */
 #define QEMU_SCROLL_LOCK_LED (1 << 0)
diff --git a/ui/cocoa.m b/ui/cocoa.m
index a029493..9cc512f 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -27,6 +27,7 @@
 
 #include "qemu-common.h"
 #include "ui/console.h"
+#include "ui/input.h"
 #include "sysemu/sysemu.h"
 
 #ifndef MAC_OS_X_VERSION_10_4
@@ -49,14 +50,6 @@
 #endif
 
 #define cgrect(nsrect) (*(CGRect *)&(nsrect))
-#define COCOA_MOUSE_EVENT \
-        if (isTabletEnabled) { \
-            kbd_mouse_event((int)(p.x * 0x7FFF / (screen.width - 1)), (int)((screen.height - p.y) * 0x7FFF / (screen.height - 1)), 0, buttons); \
-        } else if (isMouseGrabed) { \
-            kbd_mouse_event((int)[event deltaX], (int)[event deltaY], 0, buttons); \
-        } else { \
-            [NSApp sendEvent:event]; \
-        }
 
 typedef struct {
     int width;
@@ -67,6 +60,7 @@ typedef struct {
 
 NSWindow *normalWindow;
 static DisplayChangeListener *dcl;
+static int last_buttons;
 
 int gArgc;
 char **gArgv;
@@ -489,6 +483,7 @@ QemuCocoaView *cocoaView;
 
     int buttons = 0;
     int keycode;
+    bool mouse_event = false;
     NSPoint p = [event locationInWindow];
 
     switch ([event type]) {
@@ -595,7 +590,7 @@ QemuCocoaView *cocoaView;
                     }
                 }
             }
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSLeftMouseDown:
             if ([event modifierFlags] & NSCommandKeyMask) {
@@ -603,15 +598,15 @@ QemuCocoaView *cocoaView;
             } else {
                 buttons |= MOUSE_EVENT_LBUTTON;
             }
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSRightMouseDown:
             buttons |= MOUSE_EVENT_RBUTTON;
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSOtherMouseDown:
             buttons |= MOUSE_EVENT_MBUTTON;
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSLeftMouseDragged:
             if ([event modifierFlags] & NSCommandKeyMask) {
@@ -619,19 +614,19 @@ QemuCocoaView *cocoaView;
             } else {
                 buttons |= MOUSE_EVENT_LBUTTON;
             }
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSRightMouseDragged:
             buttons |= MOUSE_EVENT_RBUTTON;
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSOtherMouseDragged:
             buttons |= MOUSE_EVENT_MBUTTON;
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSLeftMouseUp:
             if (isTabletEnabled) {
-                    COCOA_MOUSE_EVENT
+                    mouse_event = true;
             } else if (!isMouseGrabed) {
                 if (p.x > -1 && p.x < screen.width && p.y > -1 && p.y < screen.height) {
                     [self grabMouse];
@@ -639,18 +634,20 @@ QemuCocoaView *cocoaView;
                     [NSApp sendEvent:event];
                 }
             } else {
-                COCOA_MOUSE_EVENT
+                mouse_event = true;
             }
             break;
         case NSRightMouseUp:
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSOtherMouseUp:
-            COCOA_MOUSE_EVENT
+            mouse_event = true;
             break;
         case NSScrollWheel:
             if (isTabletEnabled || isMouseGrabed) {
-                kbd_mouse_event(0, 0, -[event deltaY], 0);
+                button |= ([event deltaY] < 0) ?
+                    MOUSE_EVENT_WHEELUP : MOUSE_EVENT_WHEELDN;
+                mouse_event = true;
             } else {
                 [NSApp sendEvent:event];
             }
@@ -658,6 +655,30 @@ QemuCocoaView *cocoaView;
         default:
             [NSApp sendEvent:event];
     }
+
+    if (mouse_event) {
+        if (last_buttons != buttons) {
+            static uint32_t bmap[INPUT_BUTTON_MAX] = {
+                [INPUT_BUTTON_LEFT]       = MOUSE_EVENT_LBUTTON,
+                [INPUT_BUTTON_MIDDLE]     = MOUSE_EVENT_MBUTTON,
+                [INPUT_BUTTON_RIGHT]      = MOUSE_EVENT_RBUTTON,
+                [INPUT_BUTTON_WHEEL_UP]   = MOUSE_EVENT_WHEELUP,
+                [INPUT_BUTTON_WHEEL_DOWN] = MOUSE_EVENT_WHEELDN,
+            };
+            qemu_input_update_buttons(con, bmap, last_buttons, buttons);
+            last_buttons = buttons;
+        }
+        if (isTabletEnabled) {
+            qemu_input_queue_abs(dcl->con, INPUT_AXIS_X, p.x, screen.width);
+            qemu_input_queue_abs(dcl->con, INPUT_AXIS_Y, p.y, screen.height);
+        } else if (isMouseGrabed) {
+            qemu_input_queue_rel(con, INPUT_AXIS_X, (int)[event deltaX]);
+            qemu_input_queue_rel(con, INPUT_AXIS_Y, (int)[event deltaY]);
+        } else {
+            [NSApp sendEvent:event];
+        }
+        qemu_input_event_sync();
+    }
 }
 
 - (void) grabMouse
@@ -992,7 +1013,7 @@ static void cocoa_refresh(DisplayChangeListener *dcl)
 
     COCOA_DEBUG("qemu_cocoa: cocoa_refresh\n");
 
-    if (kbd_mouse_is_absolute()) {
+    if (qemu_input_is_absolute()) {
         if (![cocoaView isAbsoluteEnabled]) {
             if ([cocoaView isMouseGrabed]) {
                 [cocoaView ungrabMouse];
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 31/42] input: trace events
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (29 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 30/42] input: mouse: " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode Gerd Hoffmann
                   ` (10 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 trace-events |  8 ++++++++
 ui/input.c   | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 56 insertions(+)

diff --git a/trace-events b/trace-events
index 9f4456a..a81d71e 100644
--- a/trace-events
+++ b/trace-events
@@ -1019,6 +1019,14 @@ gd_switch(int width, int height) "width=%d, height=%d"
 gd_update(int x, int y, int w, int h) "x=%d, y=%d, w=%d, h=%d"
 gd_key_event(int gdk_keycode, int qemu_keycode, const char *action) "translated GDK keycode %d to QEMU keycode %d (%s)"
 
+# ui/input.c
+input_event_key_number(int conidx, int number, bool down) "con %d, key number 0x%d, down %d"
+input_event_key_qcode(int conidx, const char *qcode, bool down) "con %d, key qcode %s, down %d"
+input_event_btn(int conidx, const char *btn, bool down) "con %d, button %s, down %d"
+input_event_rel(int conidx, const char *axis, int value) "con %d, axis %s, value %d"
+input_event_abs(int conidx, const char *axis, int value) "con %d, axis %s, value 0x%x"
+input_event_sync(void) ""
+
 # hw/display/vmware_vga.c
 vmware_value_read(uint32_t index, uint32_t value) "index %d, value 0x%x"
 vmware_value_write(uint32_t index, uint32_t value) "index %d, value 0x%x"
diff --git a/ui/input.c b/ui/input.c
index 30a5b70..00eef0f 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -1,6 +1,8 @@
 #include "sysemu/sysemu.h"
 #include "qapi-types.h"
+#include "trace.h"
 #include "ui/input.h"
+#include "ui/console.h"
 
 struct QemuInputHandlerState {
     DeviceState       *dev;
@@ -77,6 +79,48 @@ static void qemu_input_transform_abs_rotate(InputEvent *evt)
     }
 }
 
+static void qemu_input_event_trace(QemuConsole *src, InputEvent *evt)
+{
+    const char *name;
+    int idx = -1;
+
+    if (src) {
+        idx = qemu_console_get_index(src);
+    }
+    switch (evt->kind) {
+    case INPUT_EVENT_KIND_KEY:
+        switch (evt->key->key->kind) {
+        case KEY_VALUE_KIND_NUMBER:
+            trace_input_event_key_number(idx, evt->key->key->number,
+                                         evt->key->down);
+            break;
+        case KEY_VALUE_KIND_QCODE:
+            name = QKeyCode_lookup[evt->key->key->qcode];
+            trace_input_event_key_qcode(idx, name, evt->key->down);
+            break;
+        case KEY_VALUE_KIND_MAX:
+            /* keep gcc happy */
+            break;
+        }
+        break;
+    case INPUT_EVENT_KIND_BTN:
+        name = InputButton_lookup[evt->btn->button];
+        trace_input_event_btn(idx, name, evt->btn->down);
+        break;
+    case INPUT_EVENT_KIND_REL:
+        name = InputAxis_lookup[evt->rel->axis];
+        trace_input_event_rel(idx, name, evt->rel->value);
+        break;
+    case INPUT_EVENT_KIND_ABS:
+        name = InputAxis_lookup[evt->abs->axis];
+        trace_input_event_abs(idx, name, evt->abs->value);
+        break;
+    case INPUT_EVENT_KIND_MAX:
+        /* keep gcc happy */
+        break;
+    }
+}
+
 void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
 {
     QemuInputHandlerState *s;
@@ -85,6 +129,8 @@ void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
         return;
     }
 
+    qemu_input_event_trace(src, evt);
+
     /* pre processing */
     if (graphic_rotate && (evt->kind == INPUT_EVENT_KIND_ABS)) {
             qemu_input_transform_abs_rotate(evt);
@@ -104,6 +150,8 @@ void qemu_input_event_sync(void)
         return;
     }
 
+    trace_input_event_sync();
+
     QTAILQ_FOREACH(s, &handlers, node) {
         if (!s->events) {
             continue;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (30 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 31/42] input: trace events Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 33/42] input-legacy: remove kbd_mouse_has_absolute Gerd Hoffmann
                   ` (9 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  1 -
 ui/input-legacy.c    | 23 -----------------------
 2 files changed, 24 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index a3062d0..c7f4e4f 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -46,7 +46,6 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry);
 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque);
 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
-void kbd_put_keycode(int keycode);
 void kbd_put_ledstate(int ledstate);
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index dd2dec3..3ac30e2 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -500,29 +500,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry)
     g_free(entry);
 }
 
-void kbd_put_keycode(int keycode)
-{
-    static bool emul0;
-    bool up;
-
-    if (keycode == SCANCODE_EMUL0) {
-        emul0 = true;
-        return;
-    }
-    if (keycode & SCANCODE_UP) {
-        keycode &= ~SCANCODE_UP;
-        up = true;
-    } else {
-        up = false;
-    }
-    if (emul0) {
-        keycode |= SCANCODE_GREY;
-        emul0 = false;
-    }
-
-    qemu_input_event_send_key_number(NULL, keycode, !up);
-}
-
 void kbd_put_ledstate(int ledstate)
 {
     QEMUPutLEDEntry *cursor;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 33/42] input-legacy: remove kbd_mouse_has_absolute
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (31 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 34/42] input-legacy: remove kbd_mouse_is_absolute Gerd Hoffmann
                   ` (8 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  3 ---
 ui/input-legacy.c    | 21 ++-------------------
 2 files changed, 2 insertions(+), 22 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index c7f4e4f..53e956d 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -54,9 +54,6 @@ int kbd_mouse_is_absolute(void);
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 
-/* Of all the mice, is there one that generates absolute events */
-int kbd_mouse_has_absolute(void);
-
 struct MouseTransformInfo {
     /* Touchscreen resolution */
     int x;
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 3ac30e2..22796fa 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -366,20 +366,16 @@ void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
 
 static void check_mode_change(void)
 {
-    static int current_is_absolute, current_has_absolute;
+    static int current_is_absolute;
     int is_absolute;
-    int has_absolute;
 
     is_absolute = kbd_mouse_is_absolute();
-    has_absolute = kbd_mouse_has_absolute();
 
-    if (is_absolute != current_is_absolute ||
-        has_absolute != current_has_absolute) {
+    if (is_absolute != current_is_absolute) {
         notifier_list_notify(&mouse_mode_notifiers, NULL);
     }
 
     current_is_absolute = is_absolute;
-    current_has_absolute = has_absolute;
 }
 
 static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
@@ -567,19 +563,6 @@ int kbd_mouse_is_absolute(void)
     return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
 }
 
-int kbd_mouse_has_absolute(void)
-{
-    QEMUPutMouseEntry *entry;
-
-    QTAILQ_FOREACH(entry, &mouse_handlers, node) {
-        if (entry->qemu_put_mouse_event_absolute) {
-            return 1;
-        }
-    }
-
-    return 0;
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
     MouseInfoList *mice_list = NULL;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 34/42] input-legacy: remove kbd_mouse_is_absolute
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (32 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 33/42] input-legacy: remove kbd_mouse_has_absolute Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event Gerd Hoffmann
                   ` (7 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 include/ui/console.h |  1 -
 ui/input-legacy.c    | 11 +----------
 2 files changed, 1 insertion(+), 11 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 53e956d..21b32e4 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -50,7 +50,6 @@ void kbd_put_ledstate(int ledstate);
 void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
 /* Does the current mouse generate absolute events */
-int kbd_mouse_is_absolute(void);
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
 void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
 
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 22796fa..412d401 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -369,7 +369,7 @@ static void check_mode_change(void)
     static int current_is_absolute;
     int is_absolute;
 
-    is_absolute = kbd_mouse_is_absolute();
+    is_absolute = qemu_input_is_absolute();
 
     if (is_absolute != current_is_absolute) {
         notifier_list_notify(&mouse_mode_notifiers, NULL);
@@ -554,15 +554,6 @@ void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
     }
 }
 
-int kbd_mouse_is_absolute(void)
-{
-    if (QTAILQ_EMPTY(&mouse_handlers)) {
-        return 0;
-    }
-
-    return QTAILQ_FIRST(&mouse_handlers)->qemu_put_mouse_event_absolute;
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
     MouseInfoList *mice_list = NULL;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (33 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 34/42] input-legacy: remove kbd_mouse_is_absolute Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 36/42] input: move mouse mode notifier to new core Gerd Hoffmann
                   ` (6 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 include/ui/console.h |  1 -
 ui/input-legacy.c    | 49 -------------------------------------------------
 2 files changed, 50 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 21b32e4..71a0da3 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -47,7 +47,6 @@ QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func, void *opaque)
 void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
 void kbd_put_ledstate(int ledstate);
-void kbd_mouse_event(int dx, int dy, int dz, int buttons_state);
 
 /* Does the current mouse generate absolute events */
 void qemu_add_mouse_mode_change_notifier(Notifier *notify);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 412d401..26ff06f 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -505,55 +505,6 @@ void kbd_put_ledstate(int ledstate)
     }
 }
 
-void kbd_mouse_event(int dx, int dy, int dz, int buttons_state)
-{
-    QEMUPutMouseEntry *entry;
-    QEMUPutMouseEvent *mouse_event;
-    void *mouse_event_opaque;
-    int width, height;
-
-    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
-        return;
-    }
-    if (QTAILQ_EMPTY(&mouse_handlers)) {
-        return;
-    }
-
-    entry = QTAILQ_FIRST(&mouse_handlers);
-
-    mouse_event = entry->qemu_put_mouse_event;
-    mouse_event_opaque = entry->qemu_put_mouse_event_opaque;
-
-    if (mouse_event) {
-        if (entry->qemu_put_mouse_event_absolute) {
-            width = 0x7fff;
-            height = 0x7fff;
-        } else {
-            width = graphic_width - 1;
-            height = graphic_height - 1;
-        }
-
-        switch (graphic_rotate) {
-        case 0:
-            mouse_event(mouse_event_opaque,
-                        dx, dy, dz, buttons_state);
-            break;
-        case 90:
-            mouse_event(mouse_event_opaque,
-                        width - dy, dx, dz, buttons_state);
-            break;
-        case 180:
-            mouse_event(mouse_event_opaque,
-                        width - dx, height - dy, dz, buttons_state);
-            break;
-        case 270:
-            mouse_event(mouse_event_opaque,
-                        dy, height - dx, dz, buttons_state);
-            break;
-        }
-    }
-}
-
 MouseInfoList *qmp_query_mice(Error **errp)
 {
     MouseInfoList *mice_list = NULL;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 36/42] input: move mouse mode notifier to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (34 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 37/42] input: add input_mouse_mode tracepoint Gerd Hoffmann
                   ` (5 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  4 ----
 include/ui/input.h   |  4 ++++
 ui/input-legacy.c    | 34 +---------------------------------
 ui/input.c           | 30 ++++++++++++++++++++++++++++++
 4 files changed, 35 insertions(+), 37 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 71a0da3..9a282cb 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -48,10 +48,6 @@ void qemu_remove_led_event_handler(QEMUPutLEDEntry *entry);
 
 void kbd_put_ledstate(int ledstate);
 
-/* Does the current mouse generate absolute events */
-void qemu_add_mouse_mode_change_notifier(Notifier *notify);
-void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
-
 struct MouseTransformInfo {
     /* Touchscreen resolution */
     int x;
diff --git a/include/ui/input.h b/include/ui/input.h
index 28afc45..4976f3d 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -49,4 +49,8 @@ void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value);
 void qemu_input_queue_abs(QemuConsole *src, InputAxis axis,
                           int value, int size);
 
+void qemu_input_check_mode_change(void);
+void qemu_add_mouse_mode_change_notifier(Notifier *notify);
+void qemu_remove_mouse_mode_change_notifier(Notifier *notify);
+
 #endif /* INPUT_H */
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 26ff06f..7f8e72b 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -65,8 +65,6 @@ static QTAILQ_HEAD(, QEMUPutLEDEntry) led_handlers =
     QTAILQ_HEAD_INITIALIZER(led_handlers);
 static QTAILQ_HEAD(, QEMUPutMouseEntry) mouse_handlers =
     QTAILQ_HEAD_INITIALIZER(mouse_handlers);
-static NotifierList mouse_mode_notifiers =
-    NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
 
 static const int key_defs[] = {
     [Q_KEY_CODE_SHIFT] = 0x2a,
@@ -364,20 +362,6 @@ void qemu_remove_kbd_event_handler(QEMUPutKbdEntry *entry)
     g_free(entry);
 }
 
-static void check_mode_change(void)
-{
-    static int current_is_absolute;
-    int is_absolute;
-
-    is_absolute = qemu_input_is_absolute();
-
-    if (is_absolute != current_is_absolute) {
-        notifier_list_notify(&mouse_mode_notifiers, NULL);
-    }
-
-    current_is_absolute = is_absolute;
-}
-
 static void legacy_mouse_event(DeviceState *dev, QemuConsole *src,
                                InputEvent *evt)
 {
@@ -448,8 +432,6 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
     s->s = qemu_input_handler_register((DeviceState *)s,
                                        &s->h);
 
-    check_mode_change();
-
     return s;
 }
 
@@ -459,8 +441,6 @@ void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
     QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
 
     qemu_input_handler_activate(entry->s);
-
-    check_mode_change();
 }
 
 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
@@ -471,8 +451,6 @@ void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
 
     g_free(entry->qemu_put_mouse_event_name);
     g_free(entry);
-
-    check_mode_change();
 }
 
 QEMUPutLEDEntry *qemu_add_led_event_handler(QEMUPutLEDEvent *func,
@@ -551,15 +529,5 @@ void do_mouse_set(Monitor *mon, const QDict *qdict)
         monitor_printf(mon, "Mouse at given index not found\n");
     }
 
-    check_mode_change();
-}
-
-void qemu_add_mouse_mode_change_notifier(Notifier *notify)
-{
-    notifier_list_add(&mouse_mode_notifiers, notify);
-}
-
-void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
-{
-    notifier_remove(notify);
+    qemu_input_check_mode_change();
 }
diff --git a/ui/input.c b/ui/input.c
index 00eef0f..a32bcff 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -13,6 +13,8 @@ struct QemuInputHandlerState {
 };
 static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
     QTAILQ_HEAD_INITIALIZER(handlers);
+static NotifierList mouse_mode_notifiers =
+    NOTIFIER_LIST_INITIALIZER(mouse_mode_notifiers);
 
 QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
                                                    QemuInputHandler *handler)
@@ -24,6 +26,8 @@ QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
     s->handler = handler;
     s->id = id++;
     QTAILQ_INSERT_TAIL(&handlers, s, node);
+
+    qemu_input_check_mode_change();
     return s;
 }
 
@@ -31,12 +35,14 @@ void qemu_input_handler_activate(QemuInputHandlerState *s)
 {
     QTAILQ_REMOVE(&handlers, s, node);
     QTAILQ_INSERT_HEAD(&handlers, s, node);
+    qemu_input_check_mode_change();
 }
 
 void qemu_input_handler_unregister(QemuInputHandlerState *s)
 {
     QTAILQ_REMOVE(&handlers, s, node);
     g_free(s);
+    qemu_input_check_mode_change();
 }
 
 static QemuInputHandlerState*
@@ -276,3 +282,27 @@ void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int size)
     qemu_input_event_send(src, evt);
     qapi_free_InputEvent(evt);
 }
+
+void qemu_input_check_mode_change(void)
+{
+    static int current_is_absolute;
+    int is_absolute;
+
+    is_absolute = qemu_input_is_absolute();
+
+    if (is_absolute != current_is_absolute) {
+        notifier_list_notify(&mouse_mode_notifiers, NULL);
+    }
+
+    current_is_absolute = is_absolute;
+}
+
+void qemu_add_mouse_mode_change_notifier(Notifier *notify)
+{
+    notifier_list_add(&mouse_mode_notifiers, notify);
+}
+
+void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
+{
+    notifier_remove(notify);
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 37/42] input: add input_mouse_mode tracepoint
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (35 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 36/42] input: move mouse mode notifier to new core Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 38/42] sdl2: simplify keymap handling Gerd Hoffmann
                   ` (4 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 trace-events | 1 +
 ui/input.c   | 1 +
 2 files changed, 2 insertions(+)

diff --git a/trace-events b/trace-events
index a81d71e..322ad11 100644
--- a/trace-events
+++ b/trace-events
@@ -1026,6 +1026,7 @@ input_event_btn(int conidx, const char *btn, bool down) "con %d, button %s, down
 input_event_rel(int conidx, const char *axis, int value) "con %d, axis %s, value %d"
 input_event_abs(int conidx, const char *axis, int value) "con %d, axis %s, value 0x%x"
 input_event_sync(void) ""
+input_mouse_mode(int absolute) "absolute %d"
 
 # hw/display/vmware_vga.c
 vmware_value_read(uint32_t index, uint32_t value) "index %d, value 0x%x"
diff --git a/ui/input.c b/ui/input.c
index a32bcff..55449dc 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -291,6 +291,7 @@ void qemu_input_check_mode_change(void)
     is_absolute = qemu_input_is_absolute();
 
     if (is_absolute != current_is_absolute) {
+        trace_input_mouse_mode(is_absolute);
         notifier_list_notify(&mouse_mode_notifiers, NULL);
     }
 
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 38/42] sdl2: simplify keymap handling
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (36 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 37/42] input: add input_mouse_mode tracepoint Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 39/42] sdl2: codestyle fixups Gerd Hoffmann
                   ` (3 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

sdl2 gives us scancodes (i.e. identifies keys by location not by keysym
mapped to it).  We can map them directly to QKeyCodes, pass them on to
the new input core and be done with it.

No need to jump though any keymap hops.  Zap the code.
Also operate directly on SDL scancodes for any hotkeys.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/sdl2-keymap.h             | 266 +++++++++++++++++++++++++++++++++++++++++++
 ui/sdl2.c                    | 147 ++++++------------------
 ui/sdl2_scancode_translate.h | 260 ------------------------------------------
 3 files changed, 298 insertions(+), 375 deletions(-)
 create mode 100644 ui/sdl2-keymap.h
 delete mode 100644 ui/sdl2_scancode_translate.h

diff --git a/ui/sdl2-keymap.h b/ui/sdl2-keymap.h
new file mode 100644
index 0000000..5a12f45
--- /dev/null
+++ b/ui/sdl2-keymap.h
@@ -0,0 +1,266 @@
+
+/* map SDL2 scancodes to QKeyCode */
+
+static const int sdl2_scancode_to_qcode[SDL_NUM_SCANCODES] = {
+    [SDL_SCANCODE_A]                 = Q_KEY_CODE_A,
+    [SDL_SCANCODE_B]                 = Q_KEY_CODE_B,
+    [SDL_SCANCODE_C]                 = Q_KEY_CODE_C,
+    [SDL_SCANCODE_D]                 = Q_KEY_CODE_D,
+    [SDL_SCANCODE_E]                 = Q_KEY_CODE_E,
+    [SDL_SCANCODE_F]                 = Q_KEY_CODE_F,
+    [SDL_SCANCODE_G]                 = Q_KEY_CODE_G,
+    [SDL_SCANCODE_H]                 = Q_KEY_CODE_H,
+    [SDL_SCANCODE_I]                 = Q_KEY_CODE_I,
+    [SDL_SCANCODE_J]                 = Q_KEY_CODE_J,
+    [SDL_SCANCODE_K]                 = Q_KEY_CODE_K,
+    [SDL_SCANCODE_L]                 = Q_KEY_CODE_L,
+    [SDL_SCANCODE_M]                 = Q_KEY_CODE_M,
+    [SDL_SCANCODE_N]                 = Q_KEY_CODE_N,
+    [SDL_SCANCODE_O]                 = Q_KEY_CODE_O,
+    [SDL_SCANCODE_P]                 = Q_KEY_CODE_P,
+    [SDL_SCANCODE_Q]                 = Q_KEY_CODE_Q,
+    [SDL_SCANCODE_R]                 = Q_KEY_CODE_R,
+    [SDL_SCANCODE_S]                 = Q_KEY_CODE_S,
+    [SDL_SCANCODE_T]                 = Q_KEY_CODE_T,
+    [SDL_SCANCODE_U]                 = Q_KEY_CODE_U,
+    [SDL_SCANCODE_V]                 = Q_KEY_CODE_V,
+    [SDL_SCANCODE_W]                 = Q_KEY_CODE_W,
+    [SDL_SCANCODE_X]                 = Q_KEY_CODE_X,
+    [SDL_SCANCODE_Y]                 = Q_KEY_CODE_Y,
+    [SDL_SCANCODE_Z]                 = Q_KEY_CODE_Z,
+
+    [SDL_SCANCODE_1]                 = Q_KEY_CODE_1,
+    [SDL_SCANCODE_2]                 = Q_KEY_CODE_2,
+    [SDL_SCANCODE_3]                 = Q_KEY_CODE_3,
+    [SDL_SCANCODE_4]                 = Q_KEY_CODE_4,
+    [SDL_SCANCODE_5]                 = Q_KEY_CODE_5,
+    [SDL_SCANCODE_6]                 = Q_KEY_CODE_6,
+    [SDL_SCANCODE_7]                 = Q_KEY_CODE_7,
+    [SDL_SCANCODE_8]                 = Q_KEY_CODE_8,
+    [SDL_SCANCODE_9]                 = Q_KEY_CODE_9,
+    [SDL_SCANCODE_0]                 = Q_KEY_CODE_0,
+
+    [SDL_SCANCODE_RETURN]            = Q_KEY_CODE_RET,
+    [SDL_SCANCODE_ESCAPE]            = Q_KEY_CODE_ESC,
+    [SDL_SCANCODE_BACKSPACE]         = Q_KEY_CODE_BACKSPACE,
+    [SDL_SCANCODE_TAB]               = Q_KEY_CODE_TAB,
+    [SDL_SCANCODE_SPACE]             = Q_KEY_CODE_SPC,
+    [SDL_SCANCODE_MINUS]             = Q_KEY_CODE_MINUS,
+    [SDL_SCANCODE_EQUALS]            = Q_KEY_CODE_EQUAL,
+    [SDL_SCANCODE_LEFTBRACKET]       = Q_KEY_CODE_BRACKET_LEFT,
+    [SDL_SCANCODE_RIGHTBRACKET]      = Q_KEY_CODE_BRACKET_RIGHT,
+    [SDL_SCANCODE_BACKSLASH]         = Q_KEY_CODE_BACKSLASH,
+#if 0
+    [SDL_SCANCODE_NONUSHASH]         = Q_KEY_CODE_NONUSHASH,
+#endif
+    [SDL_SCANCODE_SEMICOLON]         = Q_KEY_CODE_SEMICOLON,
+    [SDL_SCANCODE_APOSTROPHE]        = Q_KEY_CODE_APOSTROPHE,
+    [SDL_SCANCODE_GRAVE]             = Q_KEY_CODE_GRAVE_ACCENT,
+    [SDL_SCANCODE_COMMA]             = Q_KEY_CODE_COMMA,
+    [SDL_SCANCODE_PERIOD]            = Q_KEY_CODE_DOT,
+    [SDL_SCANCODE_SLASH]             = Q_KEY_CODE_SLASH,
+    [SDL_SCANCODE_CAPSLOCK]          = Q_KEY_CODE_CAPS_LOCK,
+
+    [SDL_SCANCODE_F1]                = Q_KEY_CODE_F1,
+    [SDL_SCANCODE_F2]                = Q_KEY_CODE_F2,
+    [SDL_SCANCODE_F3]                = Q_KEY_CODE_F3,
+    [SDL_SCANCODE_F4]                = Q_KEY_CODE_F4,
+    [SDL_SCANCODE_F5]                = Q_KEY_CODE_F5,
+    [SDL_SCANCODE_F6]                = Q_KEY_CODE_F6,
+    [SDL_SCANCODE_F7]                = Q_KEY_CODE_F7,
+    [SDL_SCANCODE_F8]                = Q_KEY_CODE_F8,
+    [SDL_SCANCODE_F9]                = Q_KEY_CODE_F9,
+    [SDL_SCANCODE_F10]               = Q_KEY_CODE_F10,
+    [SDL_SCANCODE_F11]               = Q_KEY_CODE_F11,
+    [SDL_SCANCODE_F12]               = Q_KEY_CODE_F12,
+
+    [SDL_SCANCODE_PRINTSCREEN]       = Q_KEY_CODE_PRINT,
+    [SDL_SCANCODE_SCROLLLOCK]        = Q_KEY_CODE_SCROLL_LOCK,
+    [SDL_SCANCODE_PAUSE]             = Q_KEY_CODE_PAUSE,
+    [SDL_SCANCODE_INSERT]            = Q_KEY_CODE_INSERT,
+    [SDL_SCANCODE_HOME]              = Q_KEY_CODE_HOME,
+    [SDL_SCANCODE_PAGEUP]            = Q_KEY_CODE_PGUP,
+    [SDL_SCANCODE_DELETE]            = Q_KEY_CODE_DELETE,
+    [SDL_SCANCODE_END]               = Q_KEY_CODE_END,
+    [SDL_SCANCODE_PAGEDOWN]          = Q_KEY_CODE_PGDN,
+    [SDL_SCANCODE_RIGHT]             = Q_KEY_CODE_RIGHT,
+    [SDL_SCANCODE_LEFT]              = Q_KEY_CODE_LEFT,
+    [SDL_SCANCODE_DOWN]              = Q_KEY_CODE_DOWN,
+    [SDL_SCANCODE_UP]                = Q_KEY_CODE_UP,
+    [SDL_SCANCODE_NUMLOCKCLEAR]      = Q_KEY_CODE_NUM_LOCK,
+
+    [SDL_SCANCODE_KP_DIVIDE]         = Q_KEY_CODE_KP_DIVIDE,
+    [SDL_SCANCODE_KP_MULTIPLY]       = Q_KEY_CODE_KP_MULTIPLY,
+    [SDL_SCANCODE_KP_MINUS]          = Q_KEY_CODE_KP_SUBTRACT,
+    [SDL_SCANCODE_KP_PLUS]           = Q_KEY_CODE_KP_ADD,
+    [SDL_SCANCODE_KP_ENTER]          = Q_KEY_CODE_KP_ENTER,
+    [SDL_SCANCODE_KP_1]              = Q_KEY_CODE_KP_1,
+    [SDL_SCANCODE_KP_2]              = Q_KEY_CODE_KP_2,
+    [SDL_SCANCODE_KP_3]              = Q_KEY_CODE_KP_3,
+    [SDL_SCANCODE_KP_4]              = Q_KEY_CODE_KP_4,
+    [SDL_SCANCODE_KP_5]              = Q_KEY_CODE_KP_5,
+    [SDL_SCANCODE_KP_6]              = Q_KEY_CODE_KP_6,
+    [SDL_SCANCODE_KP_7]              = Q_KEY_CODE_KP_7,
+    [SDL_SCANCODE_KP_8]              = Q_KEY_CODE_KP_8,
+    [SDL_SCANCODE_KP_9]              = Q_KEY_CODE_KP_9,
+    [SDL_SCANCODE_KP_0]              = Q_KEY_CODE_KP_0,
+    [SDL_SCANCODE_KP_PERIOD]         = Q_KEY_CODE_KP_DECIMAL,
+#if 0
+    [SDL_SCANCODE_NONUSBACKSLASH]    = Q_KEY_CODE_NONUSBACKSLASH,
+    [SDL_SCANCODE_APPLICATION]       = Q_KEY_CODE_APPLICATION,
+    [SDL_SCANCODE_POWER]             = Q_KEY_CODE_POWER,
+    [SDL_SCANCODE_KP_EQUALS]         = Q_KEY_CODE_KP_EQUALS,
+
+    [SDL_SCANCODE_F13]               = Q_KEY_CODE_F13,
+    [SDL_SCANCODE_F14]               = Q_KEY_CODE_F14,
+    [SDL_SCANCODE_F15]               = Q_KEY_CODE_F15,
+    [SDL_SCANCODE_F16]               = Q_KEY_CODE_F16,
+    [SDL_SCANCODE_F17]               = Q_KEY_CODE_F17,
+    [SDL_SCANCODE_F18]               = Q_KEY_CODE_F18,
+    [SDL_SCANCODE_F19]               = Q_KEY_CODE_F19,
+    [SDL_SCANCODE_F20]               = Q_KEY_CODE_F20,
+    [SDL_SCANCODE_F21]               = Q_KEY_CODE_F21,
+    [SDL_SCANCODE_F22]               = Q_KEY_CODE_F22,
+    [SDL_SCANCODE_F23]               = Q_KEY_CODE_F23,
+    [SDL_SCANCODE_F24]               = Q_KEY_CODE_F24,
+
+    [SDL_SCANCODE_EXECUTE]           = Q_KEY_CODE_EXECUTE,
+#endif
+    [SDL_SCANCODE_HELP]              = Q_KEY_CODE_HELP,
+    [SDL_SCANCODE_MENU]              = Q_KEY_CODE_MENU,
+#if 0
+    [SDL_SCANCODE_SELECT]            = Q_KEY_CODE_SELECT,
+#endif
+    [SDL_SCANCODE_STOP]              = Q_KEY_CODE_STOP,
+    [SDL_SCANCODE_AGAIN]             = Q_KEY_CODE_AGAIN,
+    [SDL_SCANCODE_UNDO]              = Q_KEY_CODE_UNDO,
+    [SDL_SCANCODE_CUT]               = Q_KEY_CODE_CUT,
+    [SDL_SCANCODE_COPY]              = Q_KEY_CODE_COPY,
+    [SDL_SCANCODE_PASTE]             = Q_KEY_CODE_PASTE,
+    [SDL_SCANCODE_FIND]              = Q_KEY_CODE_FIND,
+#if 0
+    [SDL_SCANCODE_MUTE]              = Q_KEY_CODE_MUTE,
+    [SDL_SCANCODE_VOLUMEUP]          = Q_KEY_CODE_VOLUMEUP,
+    [SDL_SCANCODE_VOLUMEDOWN]        = Q_KEY_CODE_VOLUMEDOWN,
+
+    [SDL_SCANCODE_KP_COMMA]          = Q_KEY_CODE_KP_COMMA,
+    [SDL_SCANCODE_KP_EQUALSAS400]    = Q_KEY_CODE_KP_EQUALSAS400,
+
+    [SDL_SCANCODE_INTERNATIONAL1]    = Q_KEY_CODE_INTERNATIONAL1,
+    [SDL_SCANCODE_INTERNATIONAL2]    = Q_KEY_CODE_INTERNATIONAL2,
+    [SDL_SCANCODE_INTERNATIONAL3]    = Q_KEY_CODE_INTERNATIONAL3,
+    [SDL_SCANCODE_INTERNATIONAL4]    = Q_KEY_CODE_INTERNATIONAL4,
+    [SDL_SCANCODE_INTERNATIONAL5]    = Q_KEY_CODE_INTERNATIONAL5,
+    [SDL_SCANCODE_INTERNATIONAL6]    = Q_KEY_CODE_INTERNATIONAL6,
+    [SDL_SCANCODE_INTERNATIONAL7]    = Q_KEY_CODE_INTERNATIONAL7,
+    [SDL_SCANCODE_INTERNATIONAL8]    = Q_KEY_CODE_INTERNATIONAL8,
+    [SDL_SCANCODE_INTERNATIONAL9]    = Q_KEY_CODE_INTERNATIONAL9,
+    [SDL_SCANCODE_LANG1]             = Q_KEY_CODE_LANG1,
+    [SDL_SCANCODE_LANG2]             = Q_KEY_CODE_LANG2,
+    [SDL_SCANCODE_LANG3]             = Q_KEY_CODE_LANG3,
+    [SDL_SCANCODE_LANG4]             = Q_KEY_CODE_LANG4,
+    [SDL_SCANCODE_LANG5]             = Q_KEY_CODE_LANG5,
+    [SDL_SCANCODE_LANG6]             = Q_KEY_CODE_LANG6,
+    [SDL_SCANCODE_LANG7]             = Q_KEY_CODE_LANG7,
+    [SDL_SCANCODE_LANG8]             = Q_KEY_CODE_LANG8,
+    [SDL_SCANCODE_LANG9]             = Q_KEY_CODE_LANG9,
+    [SDL_SCANCODE_ALTERASE]          = Q_KEY_CODE_ALTERASE,
+#endif
+    [SDL_SCANCODE_SYSREQ]            = Q_KEY_CODE_SYSRQ,
+#if 0
+    [SDL_SCANCODE_CANCEL]            = Q_KEY_CODE_CANCEL,
+    [SDL_SCANCODE_CLEAR]             = Q_KEY_CODE_CLEAR,
+    [SDL_SCANCODE_PRIOR]             = Q_KEY_CODE_PRIOR,
+    [SDL_SCANCODE_RETURN2]           = Q_KEY_CODE_RETURN2,
+    [SDL_SCANCODE_SEPARATOR]         = Q_KEY_CODE_SEPARATOR,
+    [SDL_SCANCODE_OUT]               = Q_KEY_CODE_OUT,
+    [SDL_SCANCODE_OPER]              = Q_KEY_CODE_OPER,
+    [SDL_SCANCODE_CLEARAGAIN]        = Q_KEY_CODE_CLEARAGAIN,
+    [SDL_SCANCODE_CRSEL]             = Q_KEY_CODE_CRSEL,
+    [SDL_SCANCODE_EXSEL]             = Q_KEY_CODE_EXSEL,
+    [SDL_SCANCODE_KP_00]             = Q_KEY_CODE_KP_00,
+    [SDL_SCANCODE_KP_000]            = Q_KEY_CODE_KP_000,
+    [SDL_SCANCODE_THOUSANDSSEPARATOR] = Q_KEY_CODE_THOUSANDSSEPARATOR,
+    [SDL_SCANCODE_DECIMALSEPARATOR]  = Q_KEY_CODE_DECIMALSEPARATOR,
+    [SDL_SCANCODE_CURRENCYUNIT]      = Q_KEY_CODE_CURRENCYUNIT,
+    [SDL_SCANCODE_CURRENCYSUBUNIT]   = Q_KEY_CODE_CURRENCYSUBUNIT,
+    [SDL_SCANCODE_KP_LEFTPAREN]      = Q_KEY_CODE_KP_LEFTPAREN,
+    [SDL_SCANCODE_KP_RIGHTPAREN]     = Q_KEY_CODE_KP_RIGHTPAREN,
+    [SDL_SCANCODE_KP_LEFTBRACE]      = Q_KEY_CODE_KP_LEFTBRACE,
+    [SDL_SCANCODE_KP_RIGHTBRACE]     = Q_KEY_CODE_KP_RIGHTBRACE,
+    [SDL_SCANCODE_KP_TAB]            = Q_KEY_CODE_KP_TAB,
+    [SDL_SCANCODE_KP_BACKSPACE]      = Q_KEY_CODE_KP_BACKSPACE,
+    [SDL_SCANCODE_KP_A]              = Q_KEY_CODE_KP_A,
+    [SDL_SCANCODE_KP_B]              = Q_KEY_CODE_KP_B,
+    [SDL_SCANCODE_KP_C]              = Q_KEY_CODE_KP_C,
+    [SDL_SCANCODE_KP_D]              = Q_KEY_CODE_KP_D,
+    [SDL_SCANCODE_KP_E]              = Q_KEY_CODE_KP_E,
+    [SDL_SCANCODE_KP_F]              = Q_KEY_CODE_KP_F,
+    [SDL_SCANCODE_KP_XOR]            = Q_KEY_CODE_KP_XOR,
+    [SDL_SCANCODE_KP_POWER]          = Q_KEY_CODE_KP_POWER,
+    [SDL_SCANCODE_KP_PERCENT]        = Q_KEY_CODE_KP_PERCENT,
+    [SDL_SCANCODE_KP_LESS]           = Q_KEY_CODE_KP_LESS,
+    [SDL_SCANCODE_KP_GREATER]        = Q_KEY_CODE_KP_GREATER,
+    [SDL_SCANCODE_KP_AMPERSAND]      = Q_KEY_CODE_KP_AMPERSAND,
+    [SDL_SCANCODE_KP_DBLAMPERSAND]   = Q_KEY_CODE_KP_DBLAMPERSAND,
+    [SDL_SCANCODE_KP_VERTICALBAR]    = Q_KEY_CODE_KP_VERTICALBAR,
+    [SDL_SCANCODE_KP_DBLVERTICALBAR] = Q_KEY_CODE_KP_DBLVERTICALBAR,
+    [SDL_SCANCODE_KP_COLON]          = Q_KEY_CODE_KP_COLON,
+    [SDL_SCANCODE_KP_HASH]           = Q_KEY_CODE_KP_HASH,
+    [SDL_SCANCODE_KP_SPACE]          = Q_KEY_CODE_KP_SPACE,
+    [SDL_SCANCODE_KP_AT]             = Q_KEY_CODE_KP_AT,
+    [SDL_SCANCODE_KP_EXCLAM]         = Q_KEY_CODE_KP_EXCLAM,
+    [SDL_SCANCODE_KP_MEMSTORE]       = Q_KEY_CODE_KP_MEMSTORE,
+    [SDL_SCANCODE_KP_MEMRECALL]      = Q_KEY_CODE_KP_MEMRECALL,
+    [SDL_SCANCODE_KP_MEMCLEAR]       = Q_KEY_CODE_KP_MEMCLEAR,
+    [SDL_SCANCODE_KP_MEMADD]         = Q_KEY_CODE_KP_MEMADD,
+    [SDL_SCANCODE_KP_MEMSUBTRACT]    = Q_KEY_CODE_KP_MEMSUBTRACT,
+    [SDL_SCANCODE_KP_MEMMULTIPLY]    = Q_KEY_CODE_KP_MEMMULTIPLY,
+    [SDL_SCANCODE_KP_MEMDIVIDE]      = Q_KEY_CODE_KP_MEMDIVIDE,
+    [SDL_SCANCODE_KP_PLUSMINUS]      = Q_KEY_CODE_KP_PLUSMINUS,
+    [SDL_SCANCODE_KP_CLEAR]          = Q_KEY_CODE_KP_CLEAR,
+    [SDL_SCANCODE_KP_CLEARENTRY]     = Q_KEY_CODE_KP_CLEARENTRY,
+    [SDL_SCANCODE_KP_BINARY]         = Q_KEY_CODE_KP_BINARY,
+    [SDL_SCANCODE_KP_OCTAL]          = Q_KEY_CODE_KP_OCTAL,
+    [SDL_SCANCODE_KP_DECIMAL]        = Q_KEY_CODE_KP_DECIMAL,
+    [SDL_SCANCODE_KP_HEXADECIMAL]    = Q_KEY_CODE_KP_HEXADECIMAL,
+#endif
+    [SDL_SCANCODE_LCTRL]             = Q_KEY_CODE_CTRL,
+    [SDL_SCANCODE_LSHIFT]            = Q_KEY_CODE_SHIFT,
+    [SDL_SCANCODE_LALT]              = Q_KEY_CODE_ALT,
+    [SDL_SCANCODE_LGUI]              = Q_KEY_CODE_META_L,
+    [SDL_SCANCODE_RCTRL]             = Q_KEY_CODE_CTRL_R,
+    [SDL_SCANCODE_RSHIFT]            = Q_KEY_CODE_SHIFT_R,
+    [SDL_SCANCODE_RALT]              = Q_KEY_CODE_ALTGR,
+    [SDL_SCANCODE_RGUI]              = Q_KEY_CODE_META_R,
+#if 0
+    [SDL_SCANCODE_MODE]              = Q_KEY_CODE_MODE,
+    [SDL_SCANCODE_AUDIONEXT]         = Q_KEY_CODE_AUDIONEXT,
+    [SDL_SCANCODE_AUDIOPREV]         = Q_KEY_CODE_AUDIOPREV,
+    [SDL_SCANCODE_AUDIOSTOP]         = Q_KEY_CODE_AUDIOSTOP,
+    [SDL_SCANCODE_AUDIOPLAY]         = Q_KEY_CODE_AUDIOPLAY,
+    [SDL_SCANCODE_AUDIOMUTE]         = Q_KEY_CODE_AUDIOMUTE,
+    [SDL_SCANCODE_MEDIASELECT]       = Q_KEY_CODE_MEDIASELECT,
+    [SDL_SCANCODE_WWW]               = Q_KEY_CODE_WWW,
+    [SDL_SCANCODE_MAIL]              = Q_KEY_CODE_MAIL,
+    [SDL_SCANCODE_CALCULATOR]        = Q_KEY_CODE_CALCULATOR,
+    [SDL_SCANCODE_COMPUTER]          = Q_KEY_CODE_COMPUTER,
+    [SDL_SCANCODE_AC_SEARCH]         = Q_KEY_CODE_AC_SEARCH,
+    [SDL_SCANCODE_AC_HOME]           = Q_KEY_CODE_AC_HOME,
+    [SDL_SCANCODE_AC_BACK]           = Q_KEY_CODE_AC_BACK,
+    [SDL_SCANCODE_AC_FORWARD]        = Q_KEY_CODE_AC_FORWARD,
+    [SDL_SCANCODE_AC_STOP]           = Q_KEY_CODE_AC_STOP,
+    [SDL_SCANCODE_AC_REFRESH]        = Q_KEY_CODE_AC_REFRESH,
+    [SDL_SCANCODE_AC_BOOKMARKS]      = Q_KEY_CODE_AC_BOOKMARKS,
+    [SDL_SCANCODE_BRIGHTNESSDOWN]    = Q_KEY_CODE_BRIGHTNESSDOWN,
+    [SDL_SCANCODE_BRIGHTNESSUP]      = Q_KEY_CODE_BRIGHTNESSUP,
+    [SDL_SCANCODE_DISPLAYSWITCH]     = Q_KEY_CODE_DISPLAYSWITCH,
+    [SDL_SCANCODE_KBDILLUMTOGGLE]    = Q_KEY_CODE_KBDILLUMTOGGLE,
+    [SDL_SCANCODE_KBDILLUMDOWN]      = Q_KEY_CODE_KBDILLUMDOWN,
+    [SDL_SCANCODE_KBDILLUMUP]        = Q_KEY_CODE_KBDILLUMUP,
+    [SDL_SCANCODE_EJECT]             = Q_KEY_CODE_EJECT,
+    [SDL_SCANCODE_SLEEP]             = Q_KEY_CODE_SLEEP,
+    [SDL_SCANCODE_APP1]              = Q_KEY_CODE_APP1,
+    [SDL_SCANCODE_APP2]              = Q_KEY_CODE_APP2,
+#endif
+};
diff --git a/ui/sdl2.c b/ui/sdl2.c
index e841424..5338b90 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -35,10 +35,9 @@
 #include "ui/console.h"
 #include "ui/input.h"
 #include "sysemu/sysemu.h"
-#include "x_keymap.h"
 #include "sdl_zoom.h"
 
-#include "sdl2_scancode_translate.h"
+#include "sdl2-keymap.h"
 
 static int sdl2_num_outputs;
 static struct sdl2_console_state {
@@ -64,7 +63,7 @@ static int gui_noframe;
 static int gui_key_modifier_pressed;
 static int gui_keysym;
 static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
-static uint8_t modifiers_state[256];
+static uint8_t modifiers_state[SDL_NUM_SCANCODES];
 static SDL_Cursor *sdl_cursor_normal;
 static SDL_Cursor *sdl_cursor_hidden;
 static int absolute_enabled = 0;
@@ -182,62 +181,13 @@ static void sdl_switch(DisplayChangeListener *dcl,
     }
 }
 
-/* generic keyboard conversion */
-
-#include "sdl_keysym.h"
-
-static kbd_layout_t *kbd_layout = NULL;
-
-static uint8_t sdl_keyevent_to_keycode_generic(const SDL_KeyboardEvent *ev)
-{
-    int keysym;
-    /* workaround for X11+SDL bug with AltGR */
-    keysym = ev->keysym.sym;
-    if (keysym == 0 && ev->keysym.scancode == 113)
-        keysym = SDLK_MODE;
-    /* For Japanese key '\' and '|' */
-    if (keysym == 92 && ev->keysym.scancode == 133) {
-        keysym = 0xa5;
-    }
-    return keysym2scancode(kbd_layout, keysym) & SCANCODE_KEYMASK;
-}
-
-/* specific keyboard conversions from scan codes */
-
-#if defined(_WIN32)
-
-static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
-{
-    int keycode;
-
-    keycode = ev->keysym.scancode;
-    keycode = sdl2_scancode_to_keycode[keycode];
-    return keycode;
-}
-
-#else
-
-static uint8_t sdl_keyevent_to_keycode(const SDL_KeyboardEvent *ev)
-{
-    int keycode;
-
-    keycode = ev->keysym.scancode;
-
-    keycode = sdl2_scancode_to_keycode[keycode];
-    if (keycode >= 89 && keycode < 150) {
-        keycode = translate_evdev_keycode(keycode - 89);
-    }
-    return keycode;
-}
-
-#endif
-
 static void reset_keys(void)
 {
     int i;
     for(i = 0; i < 256; i++) {
         if (modifiers_state[i]) {
-            qemu_input_event_send_key_number(NULL, i, false);
+            int qcode = sdl2_scancode_to_qcode[i];
+            qemu_input_event_send_key_qcode(NULL, qcode, false);
             modifiers_state[i] = 0;
         }
     }
@@ -245,54 +195,32 @@ static void reset_keys(void)
 
 static void sdl_process_key(SDL_KeyboardEvent *ev)
 {
-    int keycode;
-
-#if 0
-    if (ev->keysym.sym == SDLK_PAUSE) {
-        /* specific case */
-        int v = 0;
-        if (ev->type == SDL_KEYUP)
-            v |= SCANCODE_UP;
-        kbd_put_keycode(0xe1);
-        kbd_put_keycode(0x1d | v);
-        kbd_put_keycode(0x45 | v);
-        return;
-    }
-#endif
-
-    if (kbd_layout) {
-        keycode = sdl_keyevent_to_keycode_generic(ev);
-    } else {
-        keycode = sdl_keyevent_to_keycode(ev);
-    }
+    int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
 
-    switch(keycode) {
-    case 0x00:
-        /* sent when leaving window: reset the modifiers state */
-        reset_keys();
+    switch (ev->keysym.scancode) {
+    case SDL_SCANCODE_NUMLOCKCLEAR:
+    case SDL_SCANCODE_CAPSLOCK:
+        /* SDL does not send the key up event, so we generate it */
+        qemu_input_event_send_key_qcode(NULL, qcode, true);
+        qemu_input_event_send_key_qcode(NULL, qcode, false);
         return;
-    case 0x2a:                          /* Left Shift */
-    case 0x36:                          /* Right Shift */
-    case 0x1d:                          /* Left CTRL */
-    case 0x9d:                          /* Right CTRL */
-    case 0x38:                          /* Left ALT */
-    case 0xb8:                         /* Right ALT */
+    case SDL_SCANCODE_LCTRL:
+    case SDL_SCANCODE_LSHIFT:
+    case SDL_SCANCODE_LALT:
+    case SDL_SCANCODE_LGUI:
+    case SDL_SCANCODE_RCTRL:
+    case SDL_SCANCODE_RSHIFT:
+    case SDL_SCANCODE_RALT:
+    case SDL_SCANCODE_RGUI:
         if (ev->type == SDL_KEYUP)
-            modifiers_state[keycode] = 0;
+            modifiers_state[ev->keysym.scancode] = 0;
         else
-            modifiers_state[keycode] = 1;
-        break;
-    case 0x45: /* num lock */
-    case 0x3a: /* caps lock */
-        /* SDL does not send the key up event, so we generate it */
-        qemu_input_event_send_key_number(NULL, keycode, true);
-        qemu_input_event_send_key_number(NULL, keycode, false);
-        return;
+            modifiers_state[ev->keysym.scancode] = 1;
+        /* fall though */
+    default:
+        qemu_input_event_send_key_qcode(NULL, qcode,
+                                        ev->type == SDL_KEYDOWN);
     }
-
-    /* now send the key code */
-    qemu_input_event_send_key_number(NULL, keycode,
-                                     ev->type == SDL_KEYDOWN);
 }
 
 static void sdl_update_caption(struct sdl2_console_state *scon)
@@ -503,7 +431,6 @@ static void toggle_full_screen(struct sdl2_console_state *scon)
 static void handle_keydown(SDL_Event *ev)
 {
     int mod_state;
-    int keycode;
     struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (alt_grab) {
@@ -517,13 +444,12 @@ static void handle_keydown(SDL_Event *ev)
     gui_key_modifier_pressed = mod_state;
 
     if (gui_key_modifier_pressed) {
-        keycode = sdl_keyevent_to_keycode(&ev->key);
-        switch (keycode) {
-        case 0x21: /* 'f' key on US keyboard */
+        switch (ev->key.keysym.scancode) {
+        case SDL_SCANCODE_F:
             toggle_full_screen(scon);
             gui_keysym = 1;
             break;
-        case 0x16: /* 'u' key on US keyboard */
+        case SDL_SCANCODE_U:
             if (scaling_active) {
                 scaling_active = 0;
                 sdl_switch(&scon->dcl, NULL);
@@ -532,14 +458,15 @@ static void handle_keydown(SDL_Event *ev)
             }
             gui_keysym = 1;
             break;
-        case 0x1b: /* '+' */
-        case 0x35: /* '-' */
+        case SDL_SCANCODE_KP_PLUS:
+        case SDL_SCANCODE_KP_MINUS:
             if (!gui_fullscreen) {
                 int scr_w, scr_h;
                 int width, height;
                 SDL_GetWindowSize(scon->real_window, &scr_w, &scr_h);
 
-                width = MAX(scr_w + (keycode == 0x1b ? 50 : -50),
+                width = MAX(scr_w + (ev->key.keysym.scancode ==
+                                     SDL_SCANCODE_KP_PLUS ? 50 : -50),
                             160);
                 height = (surface_height(scon->surface) * width) /
                     surface_width(scon->surface);
@@ -800,16 +727,6 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     uint8_t data = 0;
     char *filename;
     int i;
-#if defined(__APPLE__)
-    /* always use generic keymaps */
-    if (!keyboard_layout)
-        keyboard_layout = "en-us";
-#endif
-    if(keyboard_layout) {
-        kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
-        if (!kbd_layout)
-            exit(1);
-    }
 
     if (no_frame)
         gui_noframe = 1;
diff --git a/ui/sdl2_scancode_translate.h b/ui/sdl2_scancode_translate.h
deleted file mode 100644
index 1bd4953..0000000
--- a/ui/sdl2_scancode_translate.h
+++ /dev/null
@@ -1,260 +0,0 @@
-/* generated from a back translation of the SDL2 linux_scancodes file.
-   this translates SDL2 scancodes into Linux evdev keycodes,
-   these need to be translated again to go into qemu keys. */
-static uint8_t const sdl2_scancode_to_keycode[] = {
-235,
-0,
-0,
-0,
-30,
-48,
-46,
-32,
-18,
-33,
-34,
-35,
-23,
-36,
-37,
-38,
-50,
-49,
-24,
-25,
-16,
-19,
-31,
-20,
-22,
-47,
-17,
-45,
-21,
-44,
-2,
-3,
-4,
-5,
-6,
-7,
-8,
-9,
-10,
-11,
-28,
-1,
-14,
-15,
-57,
-12,
-13,
-26,
-27,
-43,
-0,
-39,
-40,
-41,
-51,
-52,
-53,
-58,
-59,
-60,
-61,
-62,
-63,
-64,
-65,
-66,
-67,
-68,
-87,
-88,
-0,
-70,
-119,
-110,
-102,
-104,
-111,
-107,
-109,
-106,
-105,
-108,
-103,
-69,
-98,
-55,
-74,
-78,
-96,
-79,
-80,
-81,
-75,
-76,
-77,
-71,
-72,
-73,
-82,
-83,
-86,
-0,
-116,
-117,
-183,
-184,
-185,
-186,
-187,
-188,
-189,
-190,
-191,
-192,
-193,
-194,
-0,
-138,
-139,
-0,
-128,
-129,
-131,
-137,
-133,
-135,
-136,
-113,
-115,
-114,
-0,
-0,
-0,
-121,
-0,
-89,
-93,
-124,
-92,
-95,
-0,
-0,
-0,
-0,
-122,
-123,
-90,
-91,
-0,
-0,
-0,
-0,
-0,
-221,
-99,
-222,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-179,
-180,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-118,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-29,
-42,
-56,
-125,
-97,
-54,
-100,
-126,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-0,
-};
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 39/42] sdl2: codestyle fixups
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (37 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 38/42] sdl2: simplify keymap handling Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 40/42] input: move qmp_query_mice to new core Gerd Hoffmann
                   ` (2 subsequent siblings)
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

---
 ui/Makefile.objs |   2 +-
 ui/sdl2.c        | 173 +++++++++++++++++++++++++++++++++----------------------
 2 files changed, 104 insertions(+), 71 deletions(-)

diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index e6a5ec1..6f2294e 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -15,6 +15,6 @@ common-obj-$(CONFIG_CURSES) += curses.o
 common-obj-$(CONFIG_VNC) += $(vnc-obj-y)
 common-obj-$(CONFIG_GTK) += gtk.o x_keymap.o
 
-$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS) 
+$(obj)/sdl.o $(obj)/sdl_zoom.o $(obj)/sdl2.o: QEMU_CFLAGS += $(SDL_CFLAGS)
 
 $(obj)/gtk.o: QEMU_CFLAGS += $(GTK_CFLAGS) $(VTE_CFLAGS)
diff --git a/ui/sdl2.c b/ui/sdl2.c
index 5338b90..f1532e9 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -40,7 +40,7 @@
 #include "sdl2-keymap.h"
 
 static int sdl2_num_outputs;
-static struct sdl2_console_state {
+static struct sdl2_state {
     DisplayChangeListener dcl;
     DisplaySurface *surface;
     SDL_Texture *texture;
@@ -66,21 +66,22 @@ static int gui_grab_code = KMOD_LALT | KMOD_LCTRL;
 static uint8_t modifiers_state[SDL_NUM_SCANCODES];
 static SDL_Cursor *sdl_cursor_normal;
 static SDL_Cursor *sdl_cursor_hidden;
-static int absolute_enabled = 0;
-static int guest_cursor = 0;
+static int absolute_enabled;
+static int guest_cursor;
 static int guest_x, guest_y;
-static SDL_Cursor *guest_sprite = NULL;
-static int scaling_active = 0;
+static SDL_Cursor *guest_sprite;
+static int scaling_active;
 static Notifier mouse_mode_notifier;
 
-static void sdl_update_caption(struct sdl2_console_state *scon);
+static void sdl_update_caption(struct sdl2_state *scon);
 
-static struct sdl2_console_state *get_scon_from_window(uint32_t window_id)
+static struct sdl2_state *get_scon_from_window(uint32_t window_id)
 {
     int i;
     for (i = 0; i < sdl2_num_outputs; i++) {
-        if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id))
+        if (sdl2_console[i].real_window == SDL_GetWindowFromID(window_id)) {
             return &sdl2_console[i];
+        }
     }
     return NULL;
 }
@@ -88,14 +89,16 @@ static struct sdl2_console_state *get_scon_from_window(uint32_t window_id)
 static void sdl_update(DisplayChangeListener *dcl,
                        int x, int y, int w, int h)
 {
-    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
     SDL_Rect rect;
     DisplaySurface *surf = qemu_console_surface(dcl->con);
 
-    if (!surf)
+    if (!surf) {
         return;
-    if (!scon->texture)
+    }
+    if (!scon->texture) {
         return;
+    }
 
     rect.x = x;
     rect.y = y;
@@ -108,14 +111,14 @@ static void sdl_update(DisplayChangeListener *dcl,
     SDL_RenderPresent(scon->real_renderer);
 }
 
-static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height, int bpp)
+static void do_sdl_resize(struct sdl2_state *scon, int width, int height,
+                          int bpp)
 {
     int flags;
 
     if (scon->real_window && scon->real_renderer) {
         if (width && height) {
             SDL_RenderSetLogicalSize(scon->real_renderer, width, height);
-       
             SDL_SetWindowSize(scon->real_window, width, height);
         } else {
             SDL_DestroyRenderer(scon->real_renderer);
@@ -128,10 +131,11 @@ static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height
             return;
         }
         flags = 0;
-        if (gui_fullscreen)
+        if (gui_fullscreen) {
             flags |= SDL_WINDOW_FULLSCREEN;
-        else
+        } else {
             flags |= SDL_WINDOW_RESIZABLE;
+        }
 
         scon->real_window = SDL_CreateWindow("", SDL_WINDOWPOS_UNDEFINED,
                                              SDL_WINDOWPOS_UNDEFINED,
@@ -144,7 +148,7 @@ static void do_sdl_resize(struct sdl2_console_state *scon, int width, int height
 static void sdl_switch(DisplayChangeListener *dcl,
                        DisplaySurface *new_surface)
 {
-    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
     int format = 0;
     int idx = scon->idx;
     DisplaySurface *old_surface = scon->surface;
@@ -154,13 +158,16 @@ static void sdl_switch(DisplayChangeListener *dcl,
         scon->surface = new_surface;
     }
 
-    if (!new_surface && idx > 0)
+    if (!new_surface && idx > 0) {
         scon->surface = NULL;
+    }
 
-    if (new_surface == NULL)
+    if (new_surface == NULL) {
         do_sdl_resize(scon, 0, 0, 0);
-    else
-        do_sdl_resize(scon, surface_width(scon->surface), surface_height(scon->surface), 0);
+    } else {
+        do_sdl_resize(scon, surface_width(scon->surface),
+                      surface_height(scon->surface), 0);
+    }
 
     if (old_surface && scon->texture) {
         SDL_DestroyTexture(scon->texture);
@@ -169,14 +176,16 @@ static void sdl_switch(DisplayChangeListener *dcl,
 
     if (new_surface) {
         if (!scon->texture) {
-            if (surface_bits_per_pixel(scon->surface) == 16)
+            if (surface_bits_per_pixel(scon->surface) == 16) {
                 format = SDL_PIXELFORMAT_RGB565;
-            else if (surface_bits_per_pixel(scon->surface) == 32)
+            } else if (surface_bits_per_pixel(scon->surface) == 32) {
                 format = SDL_PIXELFORMAT_ARGB8888;
+            }
 
             scon->texture = SDL_CreateTexture(scon->real_renderer, format,
                                               SDL_TEXTUREACCESS_STREAMING,
-                                              surface_width(new_surface), surface_height(new_surface));
+                                              surface_width(new_surface),
+                                              surface_height(new_surface));
         }
     }
 }
@@ -184,7 +193,8 @@ static void sdl_switch(DisplayChangeListener *dcl,
 static void reset_keys(void)
 {
     int i;
-    for(i = 0; i < 256; i++) {
+
+    for (i = 0; i < 256; i++) {
         if (modifiers_state[i]) {
             int qcode = sdl2_scancode_to_qcode[i];
             qemu_input_event_send_key_qcode(NULL, qcode, false);
@@ -198,12 +208,14 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     int qcode = sdl2_scancode_to_qcode[ev->keysym.scancode];
 
     switch (ev->keysym.scancode) {
+#if 0
     case SDL_SCANCODE_NUMLOCKCLEAR:
     case SDL_SCANCODE_CAPSLOCK:
         /* SDL does not send the key up event, so we generate it */
         qemu_input_event_send_key_qcode(NULL, qcode, true);
         qemu_input_event_send_key_qcode(NULL, qcode, false);
         return;
+#endif
     case SDL_SCANCODE_LCTRL:
     case SDL_SCANCODE_LSHIFT:
     case SDL_SCANCODE_LALT:
@@ -212,10 +224,11 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     case SDL_SCANCODE_RSHIFT:
     case SDL_SCANCODE_RALT:
     case SDL_SCANCODE_RGUI:
-        if (ev->type == SDL_KEYUP)
+        if (ev->type == SDL_KEYUP) {
             modifiers_state[ev->keysym.scancode] = 0;
-        else
+        } else {
             modifiers_state[ev->keysym.scancode] = 1;
+        }
         /* fall though */
     default:
         qemu_input_event_send_key_qcode(NULL, qcode,
@@ -223,39 +236,43 @@ static void sdl_process_key(SDL_KeyboardEvent *ev)
     }
 }
 
-static void sdl_update_caption(struct sdl2_console_state *scon)
+static void sdl_update_caption(struct sdl2_state *scon)
 {
     char win_title[1024];
     char icon_title[1024];
     const char *status = "";
 
-    if (!runstate_is_running())
+    if (!runstate_is_running()) {
         status = " [Stopped]";
-    else if (gui_grab) {
-        if (alt_grab)
+    } else if (gui_grab) {
+        if (alt_grab) {
             status = " - Press Ctrl-Alt-Shift to exit mouse grab";
-        else if (ctrl_grab)
+        } else if (ctrl_grab) {
             status = " - Press Right-Ctrl to exit mouse grab";
-        else
+        } else {
             status = " - Press Ctrl-Alt to exit mouse grab";
+        }
     }
 
     if (qemu_name) {
-        snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name, scon->idx, status);
+        snprintf(win_title, sizeof(win_title), "QEMU (%s-%d)%s", qemu_name,
+                 scon->idx, status);
         snprintf(icon_title, sizeof(icon_title), "QEMU (%s)", qemu_name);
     } else {
         snprintf(win_title, sizeof(win_title), "QEMU%s", status);
         snprintf(icon_title, sizeof(icon_title), "QEMU");
     }
 
-    if (scon->real_window)
+    if (scon->real_window) {
         SDL_SetWindowTitle(scon->real_window, win_title);
+    }
 }
 
 static void sdl_hide_cursor(void)
 {
-    if (!cursor_hide)
+    if (!cursor_hide) {
         return;
+    }
 
     if (qemu_input_is_absolute()) {
         SDL_ShowCursor(1);
@@ -267,20 +284,22 @@ static void sdl_hide_cursor(void)
 
 static void sdl_show_cursor(void)
 {
-    if (!cursor_hide)
+    if (!cursor_hide) {
         return;
+    }
 
     if (!qemu_input_is_absolute()) {
         SDL_ShowCursor(1);
         if (guest_cursor &&
-            (gui_grab || qemu_input_is_absolute() || absolute_enabled))
+            (gui_grab || qemu_input_is_absolute() || absolute_enabled)) {
             SDL_SetCursor(guest_sprite);
-        else
+        } else {
             SDL_SetCursor(sdl_cursor_normal);
+        }
     }
 }
 
-static void sdl_grab_start(struct sdl2_console_state *scon)
+static void sdl_grab_start(struct sdl2_state *scon)
 {
     /*
      * If the application is not active, do not try to enter grab state. This
@@ -295,14 +314,15 @@ static void sdl_grab_start(struct sdl2_console_state *scon)
         if (!qemu_input_is_absolute() && !absolute_enabled) {
             SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y);
         }
-    } else
+    } else {
         sdl_hide_cursor();
+    }
     SDL_SetWindowGrab(scon->real_window, SDL_TRUE);
     gui_grab = 1;
     sdl_update_caption(scon);
 }
 
-static void sdl_grab_end(struct sdl2_console_state *scon)
+static void sdl_grab_end(struct sdl2_state *scon)
 {
     SDL_SetWindowGrab(scon->real_window, SDL_FALSE);
     gui_grab = 0;
@@ -310,7 +330,7 @@ static void sdl_grab_end(struct sdl2_console_state *scon)
     sdl_update_caption(scon);
 }
 
-static void absolute_mouse_grab(struct sdl2_console_state *scon)
+static void absolute_mouse_grab(struct sdl2_state *scon)
 {
     int mouse_x, mouse_y;
     int scr_w, scr_h;
@@ -337,7 +357,8 @@ static void sdl_mouse_mode_change(Notifier *notify, void *data)
     }
 }
 
-static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy, int dz, int x, int y, int state)
+static void sdl_send_mouse_event(struct sdl2_state *scon, int dx, int dy,
+                                 int dz, int x, int y, int state)
 {
     static uint32_t bmap[INPUT_BUTTON_MAX] = {
         [INPUT_BUTTON_LEFT]       = SDL_BUTTON(SDL_BUTTON_LEFT),
@@ -363,15 +384,17 @@ static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy
         int i;
 
         for (i = 0; i < sdl2_num_outputs; i++) {
-            struct sdl2_console_state *thiscon = &sdl2_console[i];
+            struct sdl2_state *thiscon = &sdl2_console[i];
             if (thiscon->real_window && thiscon->surface) {
                 SDL_GetWindowSize(thiscon->real_window, &scr_w, &scr_h);
                 cur_off_x = thiscon->x;
                 cur_off_y = thiscon->y;
-                if (scr_w + cur_off_x > max_w)
+                if (scr_w + cur_off_x > max_w) {
                     max_w = scr_w + cur_off_x;
-                if (scr_h + cur_off_y > max_h)
+                }
+                if (scr_h + cur_off_y > max_h) {
                     max_h = scr_h + cur_off_y;
+                }
                 if (i == scon->idx) {
                     off_x = cur_off_x;
                     off_y = cur_off_y;
@@ -391,14 +414,14 @@ static void sdl_send_mouse_event(struct sdl2_console_state *scon, int dx, int dy
     qemu_input_event_sync();
 }
 
-static void sdl_scale(struct sdl2_console_state *scon, int width, int height)
+static void sdl_scale(struct sdl2_state *scon, int width, int height)
 {
     int bpp = 0;
     do_sdl_resize(scon, width, height, bpp);
     scaling_active = 1;
 }
 
-static void toggle_full_screen(struct sdl2_console_state *scon)
+static void toggle_full_screen(struct sdl2_state *scon)
 {
     int width = surface_width(scon->surface);
     int height = surface_height(scon->surface);
@@ -406,7 +429,8 @@ static void toggle_full_screen(struct sdl2_console_state *scon)
 
     gui_fullscreen = !gui_fullscreen;
     if (gui_fullscreen) {
-        SDL_GetWindowSize(scon->real_window, &gui_saved_width, &gui_saved_height);
+        SDL_GetWindowSize(scon->real_window,
+                          &gui_saved_width, &gui_saved_height);
         gui_saved_scaling = scaling_active;
 
         do_sdl_resize(scon, width, height, bpp);
@@ -431,7 +455,7 @@ static void toggle_full_screen(struct sdl2_console_state *scon)
 static void handle_keydown(SDL_Event *ev)
 {
     int mod_state;
-    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (alt_grab) {
         mod_state = (SDL_GetModState() & (gui_grab_code | KMOD_LSHIFT)) ==
@@ -488,7 +512,7 @@ static void handle_keydown(SDL_Event *ev)
 static void handle_keyup(SDL_Event *ev)
 {
     int mod_state;
-    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (!alt_grab) {
         mod_state = (ev->key.keysym.mod & gui_grab_code);
@@ -519,7 +543,7 @@ static void handle_keyup(SDL_Event *ev)
 static void handle_mousemotion(SDL_Event *ev)
 {
     int max_x, max_y;
-    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
 
     if (qemu_input_is_absolute() || absolute_enabled) {
         int scr_w, scr_h;
@@ -546,7 +570,7 @@ static void handle_mousebutton(SDL_Event *ev)
 {
     int buttonstate = SDL_GetMouseState(NULL, NULL);
     SDL_MouseButtonEvent *bev;
-    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
     int dz;
 
     bev = &ev->button;
@@ -578,7 +602,7 @@ static void handle_mousebutton(SDL_Event *ev)
 static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
 {
     int w, h;
-    struct sdl2_console_state *scon = get_scon_from_window(ev->key.windowID);
+    struct sdl2_state *scon = get_scon_from_window(ev->key.windowID);
 
     switch (ev->window.event) {
     case SDL_WINDOWEVENT_RESIZED:
@@ -597,8 +621,9 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
         }
         break;
     case SDL_WINDOWEVENT_FOCUS_LOST:
-        if (gui_grab && !gui_fullscreen)
+        if (gui_grab && !gui_fullscreen) {
             sdl_grab_end(scon);
+        }
         break;
     case SDL_WINDOWEVENT_RESTORED:
         update_displaychangelistener(dcl, GUI_REFRESH_INTERVAL_DEFAULT);
@@ -617,7 +642,7 @@ static void handle_windowevent(DisplayChangeListener *dcl, SDL_Event *ev)
 
 static void sdl_refresh(DisplayChangeListener *dcl)
 {
-    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
     SDL_Event ev1, *ev = &ev1;
 
     if (scon->last_vm_running != runstate_is_running()) {
@@ -660,18 +685,20 @@ static void sdl_refresh(DisplayChangeListener *dcl)
 static void sdl_mouse_warp(DisplayChangeListener *dcl,
                            int x, int y, int on)
 {
-    struct sdl2_console_state *scon = container_of(dcl, struct sdl2_console_state, dcl);
+    struct sdl2_state *scon = container_of(dcl, struct sdl2_state, dcl);
     if (on) {
-        if (!guest_cursor)
+        if (!guest_cursor) {
             sdl_show_cursor();
+        }
         if (gui_grab || qemu_input_is_absolute() || absolute_enabled) {
             SDL_SetCursor(guest_sprite);
             if (!qemu_input_is_absolute() && !absolute_enabled) {
                 SDL_WarpMouseInWindow(scon->real_window, x, y);
             }
         }
-    } else if (gui_grab)
+    } else if (gui_grab) {
         sdl_hide_cursor();
+    }
     guest_cursor = on;
     guest_x = x, guest_y = y;
 }
@@ -680,15 +707,17 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
                              QEMUCursor *c)
 {
 
-    if (guest_sprite)
+    if (guest_sprite) {
         SDL_FreeCursor(guest_sprite);
+    }
 
-    if (guest_sprite_surface)
+    if (guest_sprite_surface) {
         SDL_FreeSurface(guest_sprite_surface);
+    }
 
-    guest_sprite_surface = SDL_CreateRGBSurfaceFrom(c->data,
-                                                    c->width, c->height, 32, c->width * 4, 0xff0000,
-                                                    0x00ff00, 0xff, 0xff000000);
+    guest_sprite_surface =
+        SDL_CreateRGBSurfaceFrom(c->data, c->width, c->height, 32, c->width * 4,
+                                 0xff0000, 0x00ff00, 0xff, 0xff000000);
 
     if (!guest_sprite_surface) {
         fprintf(stderr, "Failed to make rgb surface from %p\n", c);
@@ -701,14 +730,16 @@ static void sdl_mouse_define(DisplayChangeListener *dcl,
         return;
     }
     if (guest_cursor &&
-        (gui_grab || qemu_input_is_absolute() || absolute_enabled))
+        (gui_grab || qemu_input_is_absolute() || absolute_enabled)) {
         SDL_SetCursor(guest_sprite);
+    }
 }
 
 static void sdl_cleanup(void)
 {
-    if (guest_sprite)
+    if (guest_sprite) {
         SDL_FreeCursor(guest_sprite);
+    }
     SDL_QuitSubSystem(SDL_INIT_VIDEO);
 }
 
@@ -728,8 +759,9 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
     char *filename;
     int i;
 
-    if (no_frame)
+    if (no_frame) {
         gui_noframe = 1;
+    }
 
 #ifdef __linux__
     /* on Linux, SDL may use fbcon|directfb|svgalib when run without
@@ -745,7 +777,7 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 #endif
 
     flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE;
-    if (SDL_Init (flags)) {
+    if (SDL_Init(flags)) {
         fprintf(stderr, "Could not initialize SDL(%s) - exiting\n",
                 SDL_GetError());
         exit(1);
@@ -753,11 +785,12 @@ void sdl_display_init(DisplayState *ds, int full_screen, int no_frame)
 
     for (i = 0;; i++) {
         QemuConsole *con = qemu_console_lookup_by_index(i);
-        if (!con || !qemu_console_is_graphic(con))
+        if (!con || !qemu_console_is_graphic(con)) {
             break;
+        }
     }
     sdl2_num_outputs = i;
-    sdl2_console = g_new0(struct sdl2_console_state, sdl2_num_outputs);
+    sdl2_console = g_new0(struct sdl2_state, sdl2_num_outputs);
     for (i = 0; i < sdl2_num_outputs; i++) {
         QemuConsole *con = qemu_console_lookup_by_index(i);
         sdl2_console[i].dcl.ops = &dcl_ops;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 40/42] input: move qmp_query_mice to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (38 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 39/42] sdl2: codestyle fixups Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 41/42] input: move do_mouse_set " Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 42/42] input: remove index_from_keycode (no users) Gerd Hoffmann
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 23 -----------------------
 ui/input.c        | 29 +++++++++++++++++++++++++++++
 2 files changed, 29 insertions(+), 23 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 7f8e72b..7843482 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -483,29 +483,6 @@ void kbd_put_ledstate(int ledstate)
     }
 }
 
-MouseInfoList *qmp_query_mice(Error **errp)
-{
-    MouseInfoList *mice_list = NULL;
-    QEMUPutMouseEntry *cursor;
-    bool current = true;
-
-    QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
-        MouseInfoList *info = g_malloc0(sizeof(*info));
-        info->value = g_malloc0(sizeof(*info->value));
-        info->value->name = g_strdup(cursor->qemu_put_mouse_event_name);
-        info->value->index = cursor->index;
-        info->value->absolute = !!cursor->qemu_put_mouse_event_absolute;
-        info->value->current = current;
-
-        current = false;
-
-        info->next = mice_list;
-        mice_list = info;
-    }
-
-    return mice_list;
-}
-
 void do_mouse_set(Monitor *mon, const QDict *qdict)
 {
     QEMUPutMouseEntry *cursor;
diff --git a/ui/input.c b/ui/input.c
index 55449dc..2945a3c 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -1,5 +1,6 @@
 #include "sysemu/sysemu.h"
 #include "qapi-types.h"
+#include "qmp-commands.h"
 #include "trace.h"
 #include "ui/input.h"
 #include "ui/console.h"
@@ -307,3 +308,31 @@ void qemu_remove_mouse_mode_change_notifier(Notifier *notify)
 {
     notifier_remove(notify);
 }
+
+MouseInfoList *qmp_query_mice(Error **errp)
+{
+    MouseInfoList *mice_list = NULL;
+    MouseInfoList *info;
+    QemuInputHandlerState *s;
+    bool current = true;
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (!(s->handler->mask &
+              (INPUT_EVENT_MASK_REL | INPUT_EVENT_MASK_ABS))) {
+            continue;
+        }
+
+        info = g_new0(MouseInfoList, 1);
+        info->value = g_new0(MouseInfo, 1);
+        info->value->index = s->id;
+        info->value->name = g_strdup(s->handler->name);
+        info->value->absolute = s->handler->mask & INPUT_EVENT_MASK_ABS;
+        info->value->current = current;
+
+        current = false;
+        info->next = mice_list;
+        mice_list = info;
+    }
+
+    return mice_list;
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 41/42] input: move do_mouse_set to new core
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (39 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 40/42] input: move qmp_query_mice to new core Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 42/42] input: remove index_from_keycode (no users) Gerd Hoffmann
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

This removes the last user of the lecagy input mouse handler list,
so we can remove more legacy bits with this.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 ui/input-legacy.c | 43 -------------------------------------------
 ui/input.c        | 21 +++++++++++++++++++++
 2 files changed, 21 insertions(+), 43 deletions(-)

diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index 7843482..b51e6ad 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -35,12 +35,6 @@ struct QEMUPutMouseEntry {
     QEMUPutMouseEvent *qemu_put_mouse_event;
     void *qemu_put_mouse_event_opaque;
     int qemu_put_mouse_event_absolute;
-    char *qemu_put_mouse_event_name;
-
-    int index;
-
-    /* used internally by qemu for handling mice */
-    QTAILQ_ENTRY(QEMUPutMouseEntry) node;
 
     /* new input core */
     QemuInputHandler h;
@@ -412,17 +406,12 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
                                                 const char *name)
 {
     QEMUPutMouseEntry *s;
-    static int mouse_index = 0;
 
     s = g_malloc0(sizeof(QEMUPutMouseEntry));
 
     s->qemu_put_mouse_event = func;
     s->qemu_put_mouse_event_opaque = opaque;
     s->qemu_put_mouse_event_absolute = absolute;
-    s->qemu_put_mouse_event_name = g_strdup(name);
-    s->index = mouse_index++;
-
-    QTAILQ_INSERT_TAIL(&mouse_handlers, s, node);
 
     s->h.name = name;
     s->h.mask = INPUT_EVENT_MASK_BTN |
@@ -437,19 +426,13 @@ QEMUPutMouseEntry *qemu_add_mouse_event_handler(QEMUPutMouseEvent *func,
 
 void qemu_activate_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
-    QTAILQ_REMOVE(&mouse_handlers, entry, node);
-    QTAILQ_INSERT_HEAD(&mouse_handlers, entry, node);
-
     qemu_input_handler_activate(entry->s);
 }
 
 void qemu_remove_mouse_event_handler(QEMUPutMouseEntry *entry)
 {
-    QTAILQ_REMOVE(&mouse_handlers, entry, node);
-
     qemu_input_handler_unregister(entry->s);
 
-    g_free(entry->qemu_put_mouse_event_name);
     g_free(entry);
 }
 
@@ -482,29 +465,3 @@ void kbd_put_ledstate(int ledstate)
         cursor->put_led(cursor->opaque, ledstate);
     }
 }
-
-void do_mouse_set(Monitor *mon, const QDict *qdict)
-{
-    QEMUPutMouseEntry *cursor;
-    int index = qdict_get_int(qdict, "index");
-    int found = 0;
-
-    if (QTAILQ_EMPTY(&mouse_handlers)) {
-        monitor_printf(mon, "No mouse devices connected\n");
-        return;
-    }
-
-    QTAILQ_FOREACH(cursor, &mouse_handlers, node) {
-        if (cursor->index == index) {
-            found = 1;
-            qemu_activate_mouse_event_handler(cursor);
-            break;
-        }
-    }
-
-    if (!found) {
-        monitor_printf(mon, "Mouse at given index not found\n");
-    }
-
-    qemu_input_check_mode_change();
-}
diff --git a/ui/input.c b/ui/input.c
index 2945a3c..575c50e 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -336,3 +336,24 @@ MouseInfoList *qmp_query_mice(Error **errp)
 
     return mice_list;
 }
+
+void do_mouse_set(Monitor *mon, const QDict *qdict)
+{
+    QemuInputHandlerState *s;
+    int index = qdict_get_int(qdict, "index");
+    int found = 0;
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (s->id == index) {
+            found = 1;
+            qemu_input_handler_activate(s);
+            break;
+        }
+    }
+
+    if (!found) {
+        monitor_printf(mon, "Mouse at given index not found\n");
+    }
+
+    qemu_input_check_mode_change();
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 42/42] input: remove index_from_keycode (no users)
  2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
                   ` (40 preceding siblings ...)
  2013-12-16 10:49 ` [Qemu-devel] [PATCH 41/42] input: move do_mouse_set " Gerd Hoffmann
@ 2013-12-16 10:49 ` Gerd Hoffmann
  41 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-16 10:49 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/console.h |  1 -
 ui/input-legacy.c    | 14 --------------
 2 files changed, 15 deletions(-)

diff --git a/include/ui/console.h b/include/ui/console.h
index 9a282cb..3bf69ee 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -329,7 +329,6 @@ void curses_display_init(DisplayState *ds, int full_screen);
 
 /* input.c */
 int index_from_key(const char *key);
-int index_from_keycode(int code);
 
 /* gtk.c */
 void early_gtk_display_init(void);
diff --git a/ui/input-legacy.c b/ui/input-legacy.c
index b51e6ad..f38984b 100644
--- a/ui/input-legacy.c
+++ b/ui/input-legacy.c
@@ -220,20 +220,6 @@ int index_from_key(const char *key)
     return i;
 }
 
-int index_from_keycode(int code)
-{
-    int i;
-
-    for (i = 0; i < Q_KEY_CODE_MAX; i++) {
-        if (key_defs[i] == code) {
-            break;
-        }
-    }
-
-    /* Return Q_KEY_CODE_MAX if the code is invalid */
-    return i;
-}
-
 static int *keycodes;
 static int keycodes_size;
 static QEMUTimer *key_timer;
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

* Re: [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0)
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann
@ 2013-12-16 22:12   ` Stefan Weil
  2013-12-16 22:18     ` Dave Airlie
  2013-12-17 11:16     ` Gerd Hoffmann
  0 siblings, 2 replies; 49+ messages in thread
From: Stefan Weil @ 2013-12-16 22:12 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Dave Airlie, Anthony Liguori

Am 16.12.2013 11:48, schrieb Gerd Hoffmann:
> From: Dave Airlie <airlied@redhat.com>
>
> I've ported the SDL1.2 code over, and rewritten it to use the SDL2 interface.
>
> The biggest changes were in the input handling, where SDL2 has done a major
> overhaul, and I've had to include a generated translation file to get from
> SDL2 codes back to qemu compatible ones. I'm still not sure how the keyboard
> layout code works in qemu, so there may be further work if someone can point
> me a test case that works with SDL1.2 and doesn't with SDL2.
>
> Some SDL env vars we used to set are no longer used by SDL2,
> Windows, OSX support is untested,
>
> I don't think we can link to SDL1.2 and SDL2 at the same time, so I felt
> using --with-sdlabi=2.0 to select the new code should be fine, like how
> gtk does it.
>
> v1.1: fix keys in text console
> v1.2: fix shutdown, cleanups a bit of code, support ARGB cursor
>
> v2.0: merge the SDL multihead patch into this, g_new the number of consoles
> needed, wrap DCL inside per-console structure.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  configure                    |  23 +-
>  ui/Makefile.objs             |   4 +-
>  ui/sdl.c                     |   3 +
>  ui/sdl2.c                    | 981 +++++++++++++++++++++++++++++++++++++++++++
>  ui/sdl2_scancode_translate.h | 260 ++++++++++++
>  ui/sdl_keysym.h              |   3 +-
>  6 files changed, 1267 insertions(+), 7 deletions(-)
>  create mode 100644 ui/sdl2.c
>  create mode 100644 ui/sdl2_scancode_translate.h
>
> diff --git a/configure b/configure
> index edfea95..88080cc 100755
> --- a/configure
> +++ b/configure
[...]
> @@ -1789,12 +1794,22 @@ fi
>  
>  # Look for sdl configuration program (pkg-config or sdl-config).  Try
>  # sdl-config even without cross prefix, and favour pkg-config over sdl-config.
> -if test "`basename $sdl_config`" != sdl-config && ! has ${sdl_config}; then
> -  sdl_config=sdl-config
> +
> +if test $sdlabi == "2.0"; then

Please replace '==' by a single '=' here. dash (and maybe other less
sophisticated shells) don't like '=='.

> +    sdl_config=$sdl2_config
> +    sdlname=sdl2
> +    sdlconfigname=sdl2_config
> +else
> +    sdlname=sdl
> +    sdlconfigname=sdl_config
> +fi
> +
> +if test "`basename $sdl_config`" != $sdlconfigname && ! has ${sdl_config}; then
> +  sdl_config=$sdlconfigname
>  fi
>  
> -if $pkg_config sdl --exists; then
> -  sdlconfig="$pkg_config sdl"
> +if $pkg_config $sdlname --exists; then
> +  sdlconfig="$pkg_config $sdlname"
>    _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
>  elif has ${sdl_config}; then
>    sdlconfig="$sdl_config"
[...]


I know that sdl2.c is based on sdl.c which was coded before the
introduction of the current coding rules, but would you mind if I send a
follow-up patch which fixes the warnings from checkpatch.pl for sdl2.c?
Tools like astyle can do this automatically, and the result is pretty good.

Some of the other patches don't include a Signed-off-by, so those
patches are only ready for local testing.

I was very curious to get test results here in my environment because of
a strange effect which I had noticed recently: booting a Linux system
(Tiny Core Linux) with SDL 1.2 (1:06) takes twice as long as with GTK
(0:33) or curses (0:29). The test was run on a remote Linux x86_64
server (so X display output is slower than normal). The huge difference
is not caused by more activity but simply by delays were the QEMU
process is waiting.

I hoped that SDL 2.0 might do a better job but was disappointed: I had
to abort the test after 10 minutes, the Linux boot made progress, but
very slowly and with lots of timeout errors.

Regards
Stefan

Regards
Stefan

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0)
  2013-12-16 22:12   ` Stefan Weil
@ 2013-12-16 22:18     ` Dave Airlie
  2013-12-17 11:16     ` Gerd Hoffmann
  1 sibling, 0 replies; 49+ messages in thread
From: Dave Airlie @ 2013-12-16 22:18 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Dave Airlie, Gerd Hoffmann, Anthony Liguori, qemu-devel

On Tue, Dec 17, 2013 at 8:12 AM, Stefan Weil <sw@weilnetz.de> wrote:
> Am 16.12.2013 11:48, schrieb Gerd Hoffmann:
>> From: Dave Airlie <airlied@redhat.com>
>>
>> I've ported the SDL1.2 code over, and rewritten it to use the SDL2 interface.
>>
>> The biggest changes were in the input handling, where SDL2 has done a major
>> overhaul, and I've had to include a generated translation file to get from
>> SDL2 codes back to qemu compatible ones. I'm still not sure how the keyboard
>> layout code works in qemu, so there may be further work if someone can point
>> me a test case that works with SDL1.2 and doesn't with SDL2.
>>
>> Some SDL env vars we used to set are no longer used by SDL2,
>> Windows, OSX support is untested,
>>
>> I don't think we can link to SDL1.2 and SDL2 at the same time, so I felt
>> using --with-sdlabi=2.0 to select the new code should be fine, like how
>> gtk does it.
>>
>> v1.1: fix keys in text console
>> v1.2: fix shutdown, cleanups a bit of code, support ARGB cursor
>>
>> v2.0: merge the SDL multihead patch into this, g_new the number of consoles
>> needed, wrap DCL inside per-console structure.
>>
>> Signed-off-by: Dave Airlie <airlied@redhat.com>
>> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
>> ---
>>  configure                    |  23 +-
>>  ui/Makefile.objs             |   4 +-
>>  ui/sdl.c                     |   3 +
>>  ui/sdl2.c                    | 981 +++++++++++++++++++++++++++++++++++++++++++
>>  ui/sdl2_scancode_translate.h | 260 ++++++++++++
>>  ui/sdl_keysym.h              |   3 +-
>>  6 files changed, 1267 insertions(+), 7 deletions(-)
>>  create mode 100644 ui/sdl2.c
>>  create mode 100644 ui/sdl2_scancode_translate.h
>>
>> diff --git a/configure b/configure
>> index edfea95..88080cc 100755
>> --- a/configure
>> +++ b/configure
> [...]
>> @@ -1789,12 +1794,22 @@ fi
>>
>>  # Look for sdl configuration program (pkg-config or sdl-config).  Try
>>  # sdl-config even without cross prefix, and favour pkg-config over sdl-config.
>> -if test "`basename $sdl_config`" != sdl-config && ! has ${sdl_config}; then
>> -  sdl_config=sdl-config
>> +
>> +if test $sdlabi == "2.0"; then
>
> Please replace '==' by a single '=' here. dash (and maybe other less
> sophisticated shells) don't like '=='.
>
>> +    sdl_config=$sdl2_config
>> +    sdlname=sdl2
>> +    sdlconfigname=sdl2_config
>> +else
>> +    sdlname=sdl
>> +    sdlconfigname=sdl_config
>> +fi
>> +
>> +if test "`basename $sdl_config`" != $sdlconfigname && ! has ${sdl_config}; then
>> +  sdl_config=$sdlconfigname
>>  fi
>>
>> -if $pkg_config sdl --exists; then
>> -  sdlconfig="$pkg_config sdl"
>> +if $pkg_config $sdlname --exists; then
>> +  sdlconfig="$pkg_config $sdlname"
>>    _sdlversion=`$sdlconfig --modversion 2>/dev/null | sed 's/[^0-9]//g'`
>>  elif has ${sdl_config}; then
>>    sdlconfig="$sdl_config"
> [...]
>
>
> I know that sdl2.c is based on sdl.c which was coded before the
> introduction of the current coding rules, but would you mind if I send a
> follow-up patch which fixes the warnings from checkpatch.pl for sdl2.c?
> Tools like astyle can do this automatically, and the result is pretty good.
>
> Some of the other patches don't include a Signed-off-by, so those
> patches are only ready for local testing.
>
> I was very curious to get test results here in my environment because of
> a strange effect which I had noticed recently: booting a Linux system
> (Tiny Core Linux) with SDL 1.2 (1:06) takes twice as long as with GTK
> (0:33) or curses (0:29). The test was run on a remote Linux x86_64
> server (so X display output is slower than normal). The huge difference
> is not caused by more activity but simply by delays were the QEMU
> process is waiting.
>
> I hoped that SDL 2.0 might do a better job but was disappointed: I had
> to abort the test after 10 minutes, the Linux boot made progress, but
> very slowly and with lots of timeout errors.

Remote X isn't a scenario SDL is meant for at all, SDL is meant for
fast local screen access.

SDL2 generally uses OpenGL underneath as that is what is most likely
fastest in most scenarios for it. There may be some tuning you can use
to work around this,

I think Gerd has some follow-up patches to clean sdl2.c up a bit as well.

Dave.

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0)
  2013-12-16 22:12   ` Stefan Weil
  2013-12-16 22:18     ` Dave Airlie
@ 2013-12-17 11:16     ` Gerd Hoffmann
  1 sibling, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2013-12-17 11:16 UTC (permalink / raw)
  To: Stefan Weil; +Cc: Dave Airlie, qemu-devel, Anthony Liguori

  Hi,

> > +if test $sdlabi == "2.0"; then
> 
> Please replace '==' by a single '=' here. dash (and maybe other less
> sophisticated shells) don't like '=='.

I'll fix it up.

> I know that sdl2.c is based on sdl.c which was coded before the
> introduction of the current coding rules, but would you mind if I send a
> follow-up patch which fixes the warnings from checkpatch.pl for sdl2.c?

It's in the series already, pretty close to the end, should be easy to
find as it carries "checkpatch" in the $subject.

> Some of the other patches don't include a Signed-off-by, so those
> patches are only ready for local testing.

I'll have a look before sending out the next version (I expect I need at
least one more iteration with cocoa fixes anyway ...).

> I was very curious to get test results here in my environment because of
> a strange effect which I had noticed recently: booting a Linux system
> (Tiny Core Linux) with SDL 1.2 (1:06) takes twice as long as with GTK
> (0:33) or curses (0:29). The test was run on a remote Linux x86_64
> server (so X display output is slower than normal). The huge difference
> is not caused by more activity but simply by delays were the QEMU
> process is waiting.

The SDL API is synchronous.  For remote X11 perform reasonable well you
must operate asynchronously.  So that is a really bad fit.

We might be able to workaround that by running SDL in a thread, so SDL
doing a (blocking) wait on the remote X-Server doesn't disturb the qemu
iothread.

But at the end of the day you are much better off using vnc or spice for
a remote display, even in case SDL runs threaded some day.  For starters
vnc only sends over the parts of the screen which did actually change.
vnc also knows when the network link is saturated and skips frames then.

cheers,
  Gerd

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key Gerd Hoffmann
@ 2013-12-17 21:06   ` Eric Blake
  0 siblings, 0 replies; 49+ messages in thread
From: Eric Blake @ 2013-12-17 21:06 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Markus Armbruster, Luiz Capitulino

[-- Attachment #1: Type: text/plain, Size: 1172 bytes --]

On 12/16/2013 03:48 AM, Gerd Hoffmann wrote:
> Simplifies building something -> QkeyCode mapping tables.
> Uninitialized entries can easily identified then.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  qapi-schema.json | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 0316cb4..89d8060 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3357,7 +3357,8 @@
>  # Since: 1.3.0
>  ##
>  { 'enum': 'QKeyCode',
> -  'data': [ 'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
> +  'data': [ 'unmapped',

Worth documenting that 'unmapped' was added in 2.0 (in contrast to the
rest of the enums in 1.3).

> +            'shift', 'shift_r', 'alt', 'alt_r', 'altgr', 'altgr_r', 'ctrl',
>              'ctrl_r', 'menu', 'esc', '1', '2', '3', '4', '5', '6', '7', '8',
>              '9', '0', 'minus', 'equal', 'backspace', 'tab', 'q', 'w', 'e',
>              'r', 't', 'y', 'u', 'i', 'o', 'p', 'bracket_left', 'bracket_right',
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

^ permalink raw reply	[flat|nested] 49+ messages in thread

* Re: [Qemu-devel] [PATCH 08/42] input: qapi: add pause key
  2013-12-16 10:48 ` [Qemu-devel] [PATCH 08/42] input: qapi: add pause key Gerd Hoffmann
@ 2013-12-17 21:06   ` Eric Blake
  0 siblings, 0 replies; 49+ messages in thread
From: Eric Blake @ 2013-12-17 21:06 UTC (permalink / raw)
  To: Gerd Hoffmann, qemu-devel; +Cc: Markus Armbruster, Luiz Capitulino

[-- Attachment #1: Type: text/plain, Size: 1008 bytes --]

On 12/16/2013 03:48 AM, Gerd Hoffmann wrote:
> It's missing.
> 
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
>  qapi-schema.json | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Another case worth documenting as 'since 2.0', and probably worth
backporting to stable branches.

> 
> diff --git a/qapi-schema.json b/qapi-schema.json
> index 89d8060..56981d9 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -3372,7 +3372,7 @@
>              'kp_9', 'less', 'f11', 'f12', 'print', 'home', 'pgup', 'pgdn', 'end',
>              'left', 'up', 'down', 'right', 'insert', 'delete', 'stop', 'again',
>              'props', 'undo', 'front', 'copy', 'open', 'paste', 'find', 'cut',
> -             'lf', 'help', 'meta_l', 'meta_r', 'compose' ] }
> +             'lf', 'help', 'meta_l', 'meta_r', 'compose', 'pause' ] }
>  
>  ##
>  # @KeyValue
> 

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]

^ permalink raw reply	[flat|nested] 49+ messages in thread

* [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer
  2014-01-28  9:56 [Qemu-devel] [PULL 00/42] rework input handling, sdl2 support Gerd Hoffmann
@ 2014-01-28  9:57 ` Gerd Hoffmann
  0 siblings, 0 replies; 49+ messages in thread
From: Gerd Hoffmann @ 2014-01-28  9:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann, Anthony Liguori

Register and unregister handlers.
Event dispatcher code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 include/ui/input.h | 32 +++++++++++++++++++++
 ui/Makefile.objs   |  2 +-
 ui/input.c         | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 116 insertions(+), 1 deletion(-)
 create mode 100644 include/ui/input.h
 create mode 100644 ui/input.c

diff --git a/include/ui/input.h b/include/ui/input.h
new file mode 100644
index 0000000..3cf3641
--- /dev/null
+++ b/include/ui/input.h
@@ -0,0 +1,32 @@
+#ifndef INPUT_H
+#define INPUT_H
+
+#include "qapi-types.h"
+
+#define INPUT_EVENT_MASK_KEY   (1<<INPUT_EVENT_KIND_KEY)
+#define INPUT_EVENT_MASK_BTN   (1<<INPUT_EVENT_KIND_BTN)
+#define INPUT_EVENT_MASK_REL   (1<<INPUT_EVENT_KIND_REL)
+#define INPUT_EVENT_MASK_ABS   (1<<INPUT_EVENT_KIND_ABS)
+
+typedef struct QemuInputHandler QemuInputHandler;
+typedef struct QemuInputHandlerState QemuInputHandlerState;
+
+typedef void (*QemuInputHandlerEvent)(DeviceState *dev, QemuConsole *src,
+                                      InputEvent *evt);
+typedef void (*QemuInputHandlerSync)(DeviceState *dev);
+
+struct QemuInputHandler {
+    const char             *name;
+    uint32_t               mask;
+    QemuInputHandlerEvent  event;
+    QemuInputHandlerSync   sync;
+};
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+                                                   QemuInputHandler *handler);
+void qemu_input_handler_activate(QemuInputHandlerState *s);
+void qemu_input_handler_unregister(QemuInputHandlerState *s);
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt);
+void qemu_input_event_sync(void);
+
+#endif /* INPUT_H */
diff --git a/ui/Makefile.objs b/ui/Makefile.objs
index 16db07a..e6a5ec1 100644
--- a/ui/Makefile.objs
+++ b/ui/Makefile.objs
@@ -7,7 +7,7 @@ vnc-obj-$(CONFIG_VNC_SASL) += vnc-auth-sasl.o
 vnc-obj-$(CONFIG_VNC_WS) += vnc-ws.o
 vnc-obj-y += vnc-jobs.o
 
-common-obj-y += keymaps.o console.o cursor.o input-legacy.o qemu-pixman.o
+common-obj-y += keymaps.o console.o cursor.o input.o input-legacy.o qemu-pixman.o
 common-obj-$(CONFIG_SPICE) += spice-core.o spice-input.o spice-display.o
 common-obj-$(CONFIG_SDL) += sdl.o sdl_zoom.o x_keymap.o sdl2.o
 common-obj-$(CONFIG_COCOA) += cocoa.o
diff --git a/ui/input.c b/ui/input.c
new file mode 100644
index 0000000..23c84f7
--- /dev/null
+++ b/ui/input.c
@@ -0,0 +1,83 @@
+#include "sysemu/sysemu.h"
+#include "qapi-types.h"
+#include "ui/input.h"
+
+struct QemuInputHandlerState {
+    DeviceState       *dev;
+    QemuInputHandler  *handler;
+    int               id;
+    int               events;
+    QTAILQ_ENTRY(QemuInputHandlerState) node;
+};
+static QTAILQ_HEAD(, QemuInputHandlerState) handlers =
+    QTAILQ_HEAD_INITIALIZER(handlers);
+
+QemuInputHandlerState *qemu_input_handler_register(DeviceState *dev,
+                                                   QemuInputHandler *handler)
+{
+    QemuInputHandlerState *s = g_new0(QemuInputHandlerState, 1);
+    static int id = 1;
+
+    s->dev = dev;
+    s->handler = handler;
+    s->id = id++;
+    QTAILQ_INSERT_TAIL(&handlers, s, node);
+    return s;
+}
+
+void qemu_input_handler_activate(QemuInputHandlerState *s)
+{
+    QTAILQ_REMOVE(&handlers, s, node);
+    QTAILQ_INSERT_HEAD(&handlers, s, node);
+}
+
+void qemu_input_handler_unregister(QemuInputHandlerState *s)
+{
+    QTAILQ_REMOVE(&handlers, s, node);
+    g_free(s);
+}
+
+static QemuInputHandlerState*
+qemu_input_find_handler(uint32_t mask)
+{
+    QemuInputHandlerState *s;
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (mask & s->handler->mask) {
+            return s;
+        }
+    }
+    return NULL;
+}
+
+void qemu_input_event_send(QemuConsole *src, InputEvent *evt)
+{
+    QemuInputHandlerState *s;
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        return;
+    }
+
+    s = qemu_input_find_handler(1 << evt->kind);
+    s->handler->event(s->dev, src, evt);
+    s->events++;
+}
+
+void qemu_input_event_sync(void)
+{
+    QemuInputHandlerState *s;
+
+    if (!runstate_is_running() && !runstate_check(RUN_STATE_SUSPENDED)) {
+        return;
+    }
+
+    QTAILQ_FOREACH(s, &handlers, node) {
+        if (!s->events) {
+            continue;
+        }
+        if (s->handler->sync) {
+            s->handler->sync(s->dev);
+        }
+        s->events = 0;
+    }
+}
-- 
1.8.3.1

^ permalink raw reply related	[flat|nested] 49+ messages in thread

end of thread, other threads:[~2014-01-28  9:58 UTC | newest]

Thread overview: 49+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-12-16 10:48 [Qemu-devel] [PATCH 00/42] rework input handling, sdl2 support Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 01/42] ui/sdl2 : initial port to SDL 2.0 (v2.0) Gerd Hoffmann
2013-12-16 22:12   ` Stefan Weil
2013-12-16 22:18     ` Dave Airlie
2013-12-17 11:16     ` Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 02/42] sdl2: baum build fix Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 03/42] sdl2: remove text console logic Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 04/42] console: export QemuConsole index, width, height Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 05/42] input: rename file to legacy Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 06/42] input: qapi: define event types Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 07/42] input: qapi: add unmapped key Gerd Hoffmann
2013-12-17 21:06   ` Eric Blake
2013-12-16 10:48 ` [Qemu-devel] [PATCH 08/42] input: qapi: add pause key Gerd Hoffmann
2013-12-17 21:06   ` Eric Blake
2013-12-16 10:48 ` [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 10/42] input: keyboard: add helper functions to core Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 11/42] input: keyboard: switch legacy handlers to new core Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 12/42] input: keyboard: switch qmp_send_key() " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 13/42] input: keyboard: switch gtk ui " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 14/42] input: keyboard: switch sdl " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 15/42] sdl2: switch keyboard handling " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 16/42] input: keyboard: switch vnc ui " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 17/42] input: keyboard: switch spice " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 18/42] input: keyboard: switch curses " Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 19/42] input: mouse: add helpers functions to core Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 20/42] input: mouse: add graphic_rotate support Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 21/42] input: mouse: add qemu_input_is_absolute() Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 22/42] input: mouse: switch legacy handlers to new core Gerd Hoffmann
2013-12-16 10:48 ` [Qemu-devel] [PATCH 23/42] input: mouse: switch gtk ui " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 24/42] input: mouse: switch sdl " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 25/42] sdl2: switch mouse handling " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 26/42] input: mouse: switch vnc ui " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 27/42] input: mouse: switch spice " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 28/42] input: mouse: switch monitor " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 29/42] input: keyboard: switch cocoa ui to new core [untested] Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 30/42] input: mouse: " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 31/42] input: trace events Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 32/42] input-legacy: remove kbd_put_keycode Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 33/42] input-legacy: remove kbd_mouse_has_absolute Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 34/42] input-legacy: remove kbd_mouse_is_absolute Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 35/42] input-legacy: remove kbd_mouse_event Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 36/42] input: move mouse mode notifier to new core Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 37/42] input: add input_mouse_mode tracepoint Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 38/42] sdl2: simplify keymap handling Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 39/42] sdl2: codestyle fixups Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 40/42] input: move qmp_query_mice to new core Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 41/42] input: move do_mouse_set " Gerd Hoffmann
2013-12-16 10:49 ` [Qemu-devel] [PATCH 42/42] input: remove index_from_keycode (no users) Gerd Hoffmann
2014-01-28  9:56 [Qemu-devel] [PULL 00/42] rework input handling, sdl2 support Gerd Hoffmann
2014-01-28  9:57 ` [Qemu-devel] [PATCH 09/42] input: add core bits of the new input layer Gerd Hoffmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.