From 0fb7c8828a785d47027fd12807df7226937ca31f Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 23 Oct 2016 21:54:31 +0200 Subject: [PATCH 1/6] Add dots keypresses support to the baum braille device Signed-off-by: Samuel Thibault Signed-off-by: Gerd Hoffmann --- backends/baum.c | 224 +++++++++++++++++++++++++++--------------------- 1 file changed, 125 insertions(+), 99 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index 919844e7f0..dedc520ef6 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -1,7 +1,7 @@ /* * QEMU Baum Braille Device * - * Copyright (c) 2008 Samuel Thibault + * Copyright (c) 2008, 2010-2011, 2016 Samuel Thibault * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -102,8 +102,11 @@ typedef struct { } BaumDriverState; /* Let's assume NABCC by default */ -static const uint8_t nabcc_translation[256] = { - [0] = ' ', +enum way { + DOTS2ASCII, + ASCII2DOTS +}; +static const uint8_t nabcc_translation[2][256] = { #ifndef BRLAPI_DOTS #define BRLAPI_DOTS(d1,d2,d3,d4,d5,d6,d7,d8) \ ((d1?BRLAPI_DOT1:0)|\ @@ -115,105 +118,109 @@ static const uint8_t nabcc_translation[256] = { (d7?BRLAPI_DOT7:0)|\ (d8?BRLAPI_DOT8:0)) #endif - [BRLAPI_DOTS(1,0,0,0,0,0,0,0)] = 'a', - [BRLAPI_DOTS(1,1,0,0,0,0,0,0)] = 'b', - [BRLAPI_DOTS(1,0,0,1,0,0,0,0)] = 'c', - [BRLAPI_DOTS(1,0,0,1,1,0,0,0)] = 'd', - [BRLAPI_DOTS(1,0,0,0,1,0,0,0)] = 'e', - [BRLAPI_DOTS(1,1,0,1,0,0,0,0)] = 'f', - [BRLAPI_DOTS(1,1,0,1,1,0,0,0)] = 'g', - [BRLAPI_DOTS(1,1,0,0,1,0,0,0)] = 'h', - [BRLAPI_DOTS(0,1,0,1,0,0,0,0)] = 'i', - [BRLAPI_DOTS(0,1,0,1,1,0,0,0)] = 'j', - [BRLAPI_DOTS(1,0,1,0,0,0,0,0)] = 'k', - [BRLAPI_DOTS(1,1,1,0,0,0,0,0)] = 'l', - [BRLAPI_DOTS(1,0,1,1,0,0,0,0)] = 'm', - [BRLAPI_DOTS(1,0,1,1,1,0,0,0)] = 'n', - [BRLAPI_DOTS(1,0,1,0,1,0,0,0)] = 'o', - [BRLAPI_DOTS(1,1,1,1,0,0,0,0)] = 'p', - [BRLAPI_DOTS(1,1,1,1,1,0,0,0)] = 'q', - [BRLAPI_DOTS(1,1,1,0,1,0,0,0)] = 'r', - [BRLAPI_DOTS(0,1,1,1,0,0,0,0)] = 's', - [BRLAPI_DOTS(0,1,1,1,1,0,0,0)] = 't', - [BRLAPI_DOTS(1,0,1,0,0,1,0,0)] = 'u', - [BRLAPI_DOTS(1,1,1,0,0,1,0,0)] = 'v', - [BRLAPI_DOTS(0,1,0,1,1,1,0,0)] = 'w', - [BRLAPI_DOTS(1,0,1,1,0,1,0,0)] = 'x', - [BRLAPI_DOTS(1,0,1,1,1,1,0,0)] = 'y', - [BRLAPI_DOTS(1,0,1,0,1,1,0,0)] = 'z', +#define DO(dots, ascii) \ + [DOTS2ASCII][dots] = ascii, \ + [ASCII2DOTS][ascii] = dots + DO(0, ' '), + DO(BRLAPI_DOTS(1, 0, 0, 0, 0, 0, 0, 0), 'a'), + DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 0, 0, 0), 'b'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 0, 0, 0), 'c'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 1, 0, 0, 0), 'd'), + DO(BRLAPI_DOTS(1, 0, 0, 0, 1, 0, 0, 0), 'e'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 0, 0, 0), 'f'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 0, 0, 0), 'g'), + DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 0, 0, 0), 'h'), + DO(BRLAPI_DOT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 'G', - [BRLAPI_DOTS(1,1,0,0,1,0,1,0)] = 'H', - [BRLAPI_DOTS(0,1,0,1,0,0,1,0)] = 'I', - [BRLAPI_DOTS(0,1,0,1,1,0,1,0)] = 'J', - [BRLAPI_DOTS(1,0,1,0,0,0,1,0)] = 'K', - [BRLAPI_DOTS(1,1,1,0,0,0,1,0)] = 'L', - [BRLAPI_DOTS(1,0,1,1,0,0,1,0)] = 'M', - [BRLAPI_DOTS(1,0,1,1,1,0,1,0)] = 'N', - [BRLAPI_DOTS(1,0,1,0,1,0,1,0)] = 'O', - [BRLAPI_DOTS(1,1,1,1,0,0,1,0)] = 'P', - [BRLAPI_DOTS(1,1,1,1,1,0,1,0)] = 'Q', - [BRLAPI_DOTS(1,1,1,0,1,0,1,0)] = 'R', - [BRLAPI_DOTS(0,1,1,1,0,0,1,0)] = 'S', - [BRLAPI_DOTS(0,1,1,1,1,0,1,0)] = 'T', - [BRLAPI_DOTS(1,0,1,0,0,1,1,0)] = 'U', - [BRLAPI_DOTS(1,1,1,0,0,1,1,0)] = 'V', - [BRLAPI_DOTS(0,1,0,1,1,1,1,0)] = 'W', - [BRLAPI_DOTS(1,0,1,1,0,1,1,0)] = 'X', - [BRLAPI_DOTS(1,0,1,1,1,1,1,0)] = 'Y', - [BRLAPI_DOTS(1,0,1,0,1,1,1,0)] = 'Z', + DO(BRLAPI_DOTS(1, 0, 0, 0, 0, 0, 1, 0), 'A'), + DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 0, 1, 0), 'B'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 0, 1, 0), 'C'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 1, 0, 1, 0), 'D'), + DO(BRLAPI_DOTS(1, 0, 0, 0, 1, 0, 1, 0), 'E'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 0, 1, 0), 'F'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 0, 1, 0), 'G'), + DO(BRLAPI_DOTS(1, 1, 0, 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- [BRLAPI_DOTS(0,1,1,0,1,0,0,0)] = '6', - [BRLAPI_DOTS(0,1,1,0,1,1,0,0)] = '7', - [BRLAPI_DOTS(0,1,1,0,0,1,0,0)] = '8', - [BRLAPI_DOTS(0,0,1,0,1,0,0,0)] = '9', + DO(BRLAPI_DOTS(0, 0, 1, 0, 1, 1, 0, 0), '0'), + DO(BRLAPI_DOTS(0, 1, 0, 0, 0, 0, 0, 0), '1'), + DO(BRLAPI_DOTS(0, 1, 1, 0, 0, 0, 0, 0), '2'), + DO(BRLAPI_DOTS(0, 1, 0, 0, 1, 0, 0, 0), '3'), + DO(BRLAPI_DOTS(0, 1, 0, 0, 1, 1, 0, 0), '4'), + DO(BRLAPI_DOTS(0, 1, 0, 0, 0, 1, 0, 0), '5'), + DO(BRLAPI_DOTS(0, 1, 1, 0, 1, 0, 0, 0), '6'), + DO(BRLAPI_DOTS(0, 1, 1, 0, 1, 1, 0, 0), '7'), + DO(BRLAPI_DOTS(0, 1, 1, 0, 0, 1, 0, 0), '8'), + DO(BRLAPI_DOTS(0, 0, 1, 0, 1, 0, 0, 0), '9'), - [BRLAPI_DOTS(0,0,0,1,0,1,0,0)] = '.', - [BRLAPI_DOTS(0,0,1,1,0,1,0,0)] = '+', - [BRLAPI_DOTS(0,0,1,0,0,1,0,0)] = '-', - [BRLAPI_DOTS(1,0,0,0,0,1,0,0)] = '*', - [BRLAPI_DOTS(0,0,1,1,0,0,0,0)] = '/', - [BRLAPI_DOTS(1,1,1,0,1,1,0,0)] = '(', - [BRLAPI_DOTS(0,1,1,1,1,1,0,0)] = ')', + DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 1, 0, 0), '.'), + DO(BRLAPI_DOTS(0, 0, 1, 1, 0, 1, 0, 0), '+'), + DO(BRLAPI_DOTS(0, 0, 1, 0, 0, 1, 0, 0), '-'), + DO(BRLAPI_DOTS(1, 0, 0, 0, 0, 1, 0, 0), '*'), + DO(BRLAPI_DOTS(0, 0, 1, 1, 0, 0, 0, 0), '/'), + DO(BRLAPI_DOTS(1, 1, 1, 0, 1, 1, 0, 0), '('), + DO(BRLAPI_DOTS(0, 1, 1, 1, 1, 1, 0, 0), ')'), - [BRLAPI_DOTS(1,1,1,1,0,1,0,0)] = '&', - [BRLAPI_DOTS(0,0,1,1,1,1,0,0)] = '#', + DO(BRLAPI_DOTS(1, 1, 1, 1, 0, 1, 0, 0), '&'), + DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 1, 0, 0), '#'), - [BRLAPI_DOTS(0,0,0,0,0,1,0,0)] = ',', - [BRLAPI_DOTS(0,0,0,0,1,1,0,0)] = ';', - [BRLAPI_DOTS(1,0,0,0,1,1,0,0)] = ':', - [BRLAPI_DOTS(0,1,1,1,0,1,0,0)] = '!', - [BRLAPI_DOTS(1,0,0,1,1,1,0,0)] = '?', - [BRLAPI_DOTS(0,0,0,0,1,0,0,0)] = '"', - [BRLAPI_DOTS(0,0,1,0,0,0,0,0)] ='\'', - [BRLAPI_DOTS(0,0,0,1,0,0,0,0)] = '`', - [BRLAPI_DOTS(0,0,0,1,1,0,1,0)] = '^', - [BRLAPI_DOTS(0,0,0,1,1,0,0,0)] = '~', - [BRLAPI_DOTS(0,1,0,1,0,1,1,0)] = '[', - [BRLAPI_DOTS(1,1,0,1,1,1,1,0)] = ']', - [BRLAPI_DOTS(0,1,0,1,0,1,0,0)] = '{', - [BRLAPI_DOTS(1,1,0,1,1,1,0,0)] = '}', - [BRLAPI_DOTS(1,1,1,1,1,1,0,0)] = '=', - [BRLAPI_DOTS(1,1,0,0,0,1,0,0)] = '<', - [BRLAPI_DOTS(0,0,1,1,1,0,0,0)] = '>', - [BRLAPI_DOTS(1,1,0,1,0,1,0,0)] = '$', - [BRLAPI_DOTS(1,0,0,1,0,1,0,0)] = '%', - [BRLAPI_DOTS(0,0,0,1,0,0,1,0)] = '@', - [BRLAPI_DOTS(1,1,0,0,1,1,0,0)] = '|', - [BRLAPI_DOTS(1,1,0,0,1,1,1,0)] ='\\', - [BRLAPI_DOTS(0,0,0,1,1,1,0,0)] = '_', + DO(BRLAPI_DOTS(0, 0, 0, 0, 0, 1, 0, 0), ','), + DO(BRLAPI_DOTS(0, 0, 0, 0, 1, 1, 0, 0), ';'), + DO(BRLAPI_DOTS(1, 0, 0, 0, 1, 1, 0, 0), ':'), + DO(BRLAPI_DOTS(0, 1, 1, 1, 0, 1, 0, 0), '!'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 1, 1, 0, 0), '?'), + DO(BRLAPI_DOTS(0, 0, 0, 0, 1, 0, 0, 0), '"'), + DO(BRLAPI_DOTS(0, 0, 1, 0, 0, 0, 0, 0), '\''), + DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 0, 0), '`'), + DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 0, 1, 0), '^'), + DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 0, 0, 0), '~'), + DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 1, 0), '['), + DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 1, 0), ']'), + DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 0, 0), '{'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 0, 0), '}'), + DO(BRLAPI_DOTS(1, 1, 1, 1, 1, 1, 0, 0), '='), + DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 1, 0, 0), '<'), + DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 0, 0, 0), '>'), + DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 1, 0, 0), '$'), + DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 1, 0, 0), '%'), + DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 1, 0), '@'), + DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 0, 0), '|'), + DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 1, 0), '\\'), + DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'), }; /* The serial port can receive more of our data */ @@ -346,8 +353,10 @@ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len) cursor = i + 1; c &= ~(BRLAPI_DOT7|BRLAPI_DOT8); } - if (!(c = nabcc_translation[c])) + c = nabcc_translation[DOTS2ASCII][c]; + if (!c) { c = '?'; + } text[i] = c; } timer_del(baum->cellCount_timer); @@ -476,6 +485,13 @@ static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) { baum_write_packet(baum, packet, sizeof(packet)); } +static void baum_send_key2(BaumDriverState *baum, uint8_t type, uint8_t value, + uint8_t value2) { + uint8_t packet[] = { type, value, value2 }; + DPRINTF("writing key %x %x\n", type, value); + baum_write_packet(baum, packet, sizeof(packet)); +} + /* We got some data on the BrlAPI socket */ static void baum_chr_read(void *opaque) { @@ -540,7 +556,17 @@ static void baum_chr_read(void *opaque) } break; case BRLAPI_KEY_TYPE_SYM: - break; + { + brlapi_keyCode_t keysym = code & BRLAPI_KEY_CODE_MASK; + if (keysym < 0x100) { + uint8_t dots = nabcc_translation[ASCII2DOTS][keysym]; + if (dots) { + baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, dots); + baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, 0); + } + } + break; + } } } if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) { From cb78d4a1efb177f093b9b9c2e3336a3b658af467 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 23 Oct 2016 21:54:32 +0200 Subject: [PATCH 2/6] Defer BrlAPI tty acquisition to when guest starts using device We do not want to catch the BrlAPI input/ouput immediately, but only when the guest has started discussing withour virtual device. This notably fixes input before the guest driver has started. Signed-off-by: Samuel Thibault Signed-off-by: Gerd Hoffmann --- backends/baum.c | 81 ++++++++++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 32 deletions(-) diff --git a/backends/baum.c b/backends/baum.c index dedc520ef6..b92369d840 100644 --- a/backends/baum.c +++ b/backends/baum.c @@ -92,6 +92,7 @@ typedef struct { brlapi_handle_t *brlapi; int brlapi_fd; unsigned int x, y; + bool deferred_init; uint8_t in_buf[BUF_SIZE]; uint8_t in_buf_used; @@ -223,6 +224,49 @@ static const uint8_t nabcc_translation[2][256] = { DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'), }; +/* The guest OS has started discussing with us, finish initializing BrlAPI */ +static int baum_deferred_init(BaumDriverState *baum) +{ +#if defined(CONFIG_SDL) +#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) + SDL_SysWMinfo info; +#endif +#endif + int tty; + + if (baum->deferred_init) { + return 1; + } + + if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) { + brlapi_perror("baum: brlapi__getDisplaySize"); + return 0; + } + +#if defined(CONFIG_SDL) +#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) + memset(&info, 0, sizeof(info)); + SDL_VERSION(&info.version); + if (SDL_GetWMInfo(&info)) { + tty = info.info.x11.wmwindow; + } else { +#endif +#endif + tty = BRLAPI_TTY_DEFAULT; +#if defined(CONFIG_SDL) +#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) + } +#endif +#endif + + if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) { + brlapi_perror("baum: brlapi__enterTtyMode"); + return 0; + } + baum->deferred_init = 1; + return 1; +} + /* The serial port can receive more of our data */ static void baum_accept_input(struct CharDriverState *chr) { @@ -449,6 +493,8 @@ static int baum_write(CharDriverState *chr, const uint8_t *buf, int len) return 0; if (!baum->brlapi) return len; + if (!baum_deferred_init(baum)) + return len; while (len) { /* Complete our buffer as much as possible */ @@ -500,6 +546,8 @@ static void baum_chr_read(void *opaque) int ret; if (!baum->brlapi) return; + if (!baum_deferred_init(baum)) + return; while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code); /* Emulate */ @@ -599,12 +647,6 @@ static CharDriverState *chr_baum_init(const char *id, BaumDriverState *baum; CharDriverState *chr; brlapi_handle_t *handle; -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - SDL_SysWMinfo info; -#endif -#endif - int tty; chr = qemu_chr_alloc(common, errp); if (!chr) { @@ -627,39 +669,14 @@ static CharDriverState *chr_baum_init(const char *id, brlapi_strerror(brlapi_error_location())); goto fail_handle; } + baum->deferred_init = 0; baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); - if (brlapi__getDisplaySize(handle, &baum->x, &baum->y) == -1) { - error_setg(errp, "brlapi__getDisplaySize: %s", - brlapi_strerror(brlapi_error_location())); - goto fail; - } - -#if defined(CONFIG_SDL) -#if SDL_COMPILEDVERSION < SDL_VERSIONNUM(2, 0, 0) - memset(&info, 0, sizeof(info)); - SDL_VERSION(&info.version); - if (SDL_GetWMInfo(&info)) - tty = info.info.x11.wmwindow; - else -#endif -#endif - tty = BRLAPI_TTY_DEFAULT; - - if (brlapi__enterTtyMode(handle, tty, NULL) == -1) { - error_setg(errp, "brlapi__enterTtyMode: %s", - brlapi_strerror(brlapi_error_location())); - goto fail; - } - qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); return chr; -fail: - timer_free(baum->cellCount_timer); - brlapi__closeConnection(handle); fail_handle: g_free(handle); g_free(chr); From 76d8f93b4a72d02f6af6ff4eda36b7630cd8417b Mon Sep 17 00:00:00 2001 From: Alberto Garcia Date: Wed, 26 Oct 2016 18:21:08 +0300 Subject: [PATCH 3/6] gtk: fix compilation warning with gtk 3.22.2 gdk_screen_get_width() is deprecated since gtk 3.22.2, use gdk_monitor_get_geometry() instead if it's available. Signed-off-by: Alberto Garcia Message-id: 20161026152108.12364-1-berto@igalia.com Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 25e6d9969d..dd13982b1a 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -912,9 +912,28 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, if (!qemu_input_is_absolute() && s->ptr_owner == vc) { GdkScreen *screen = gtk_widget_get_screen(vc->gfx.drawing_area); + int screen_width, screen_height; + int x = (int)motion->x_root; int y = (int)motion->y_root; +#if GTK_CHECK_VERSION(3, 22, 0) + { + GdkDisplay *dpy = gtk_widget_get_display(widget); + GdkWindow *win = gtk_widget_get_window(widget); + GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); + GdkRectangle geometry; + gdk_monitor_get_geometry(monitor, &geometry); + screen_width = geometry.width; + screen_height = geometry.height; + } +#else + { + screen_width = gdk_screen_get_width(screen); + screen_height = gdk_screen_get_height(screen); + } +#endif + /* In relative mode check to see if client pointer hit * one of the screen edges, and if so move it back by * 200 pixels. This is important because the pointer @@ -928,10 +947,10 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, if (y == 0) { y += 200; } - if (x == (gdk_screen_get_width(screen) - 1)) { + if (x == (screen_width - 1)) { x -= 200; } - if (y == (gdk_screen_get_height(screen) - 1)) { + if (y == (screen_height - 1)) { y -= 200; } From 856178852032404dee69665c2dcb65f00b4bb48e Mon Sep 17 00:00:00 2001 From: Thomas Huth Date: Thu, 27 Oct 2016 14:17:27 +0200 Subject: [PATCH 4/6] ui/gtk: Fix non-working DELETE key GTK generates key events for the delete key with key->string[0] = 0x7f ... but this does not work right with the readline_handle_byte() function in util/readline.c, since this treats the keycode 127 as backspace. So let's add a special case for the GTK delete key to make this key behave right in the monitor interface of the GTK ui. Buglink: https://bugs.launchpad.net/qemu/+bug/1619438 Signed-off-by: Thomas Huth Message-id: 1477570647-7100-1-git-send-email-thuth@redhat.com Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ui/gtk.c b/ui/gtk.c index dd13982b1a..ca737c48d9 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1070,7 +1070,9 @@ static gboolean gd_text_key_down(GtkWidget *widget, VirtualConsole *vc = opaque; QemuConsole *con = vc->gfx.dcl.con; - if (key->length) { + if (key->keyval == GDK_KEY_Delete) { + kbd_put_qcode_console(con, Q_KEY_CODE_DELETE); + } else if (key->length) { kbd_put_string_console(con, key->string, key->length); } else { int num = gd_map_keycode(vc->s, gtk_widget_get_display(widget), From 697783a736b99e8666baf9a0f81fc483ac5f31a5 Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 15 Oct 2016 21:53:04 +0200 Subject: [PATCH 5/6] curses: fix left/right arrow translation In default VGA font, left/right arrow are glyphs 0x1a and 0x1b, not 0x0a and 0x0b. Signed-off-by: Samuel Thibault Message-id: 20161015195308.20473-2-samuel.thibault@ens-lyon.org Signed-off-by: Gerd Hoffmann --- ui/curses.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/curses.c b/ui/curses.c index d06f724879..2e132a7bfa 100644 --- a/ui/curses.c +++ b/ui/curses.c @@ -369,10 +369,10 @@ static void curses_setup(void) /* ACS_* is not constant. So, we can't initialize statically. */ vga_to_curses['\0'] = ' '; vga_to_curses[0x04] = ACS_DIAMOND; - vga_to_curses[0x0a] = ACS_RARROW; - vga_to_curses[0x0b] = ACS_LARROW; vga_to_curses[0x18] = ACS_UARROW; vga_to_curses[0x19] = ACS_DARROW; + vga_to_curses[0x1a] = ACS_RARROW; + vga_to_curses[0x1b] = ACS_LARROW; vga_to_curses[0x9c] = ACS_STERLING; vga_to_curses[0xb0] = ACS_BOARD; vga_to_curses[0xb1] = ACS_CKBOARD; From 8ddc5bf9e5de51c2a4842c01dd3a97f5591776fd Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sat, 15 Oct 2016 21:53:05 +0200 Subject: [PATCH 6/6] curses: Use cursesw instead of curses Use ncursesw package instead of curses on non-mingw, and check a few functions. Also take cflags from pkg-config, since cursesw headers may be in a separate, non-default directory. Signed-off-by: Samuel Thibault Message-id: 20161015195308.20473-3-samuel.thibault@ens-lyon.org Signed-off-by: Gerd Hoffmann --- configure | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 8e10059607..5e444692b4 100755 --- a/configure +++ b/configure @@ -2917,27 +2917,38 @@ fi # curses probe if test "$curses" != "no" ; then if test "$mingw32" = "yes" ; then - curses_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses" + curses_inc_list="$($pkg_config --cflags ncurses 2>/dev/null):" + curses_lib_list="$($pkg_config --libs ncurses 2>/dev/null):-lpdcurses" else - curses_list="$($pkg_config --libs ncurses 2>/dev/null):-lncurses:-lcurses" + curses_inc_list="$($pkg_config --cflags ncursesw 2>/dev/null):" + curses_lib_list="$($pkg_config --libs ncursesw 2>/dev/null):-lncursesw:-lcursesw" fi curses_found=no cat > $TMPC << EOF +#include #include +#include int main(void) { const char *s = curses_version(); + wchar_t wch = L'w'; + setlocale(LC_ALL, ""); resize_term(0, 0); + addwstr(L"wide chars\n"); + addnwstr(&wch, 1); return s != 0; } EOF IFS=: - for curses_lib in $curses_list; do - unset IFS - if compile_prog "" "$curses_lib" ; then - curses_found=yes - libs_softmmu="$curses_lib $libs_softmmu" - break - fi + for curses_inc in $curses_inc_list; do + for curses_lib in $curses_lib_list; do + unset IFS + if compile_prog "$curses_inc" "$curses_lib" ; then + curses_found=yes + QEMU_CFLAGS="$curses_inc $QEMU_CFLAGS" + libs_softmmu="$curses_lib $libs_softmmu" + break + fi + done done unset IFS if test "$curses_found" = "yes" ; then