From cd6c768f6a4f65a65bd44bdec0638b7fd861ceb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dennis=20W=C3=B6lfing?= Date: Tue, 20 Jul 2021 16:39:41 +0200 Subject: [PATCH 1/6] ui/gtk: Fix relative mouse with multiple monitors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit To handle relative mouse input the event handler needs to move the mouse away from the screen edges. Failing to do so results in the mouse getting stuck at invisible walls. However the current implementation for this is broken on hosts with multiple monitors. With multiple monitors the mouse can be located outside of the current monitor which is not handled by the current code. Also the monitor itself might be located at coordinates different from (0, 0). Signed-off-by: Dennis Wölfing Reviewed-by: Marc-André Lureau Message-Id: <20210720143940.291413-1-denniswoelfing@gmx.de> Signed-off-by: Gerd Hoffmann --- ui/gtk.c | 26 +++++++------------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/ui/gtk.c b/ui/gtk.c index 376b4d528d..18542c7633 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -865,37 +865,25 @@ static gboolean gd_motion_event(GtkWidget *widget, GdkEventMotion *motion, GdkWindow *win = gtk_widget_get_window(widget); GdkMonitor *monitor = gdk_display_get_monitor_at_window(dpy, win); GdkRectangle geometry; - int screen_width, screen_height; int x = (int)motion->x_root; int y = (int)motion->y_root; gdk_monitor_get_geometry(monitor, &geometry); - screen_width = geometry.width; - screen_height = geometry.height; /* 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 + * one of the monitor edges, and if so move it back to the + * center of the monitor. This is important because the pointer * in the server doesn't correspond 1-for-1, and so * may still be only half way across the screen. Without * this warp, the server pointer would thus appear to hit * an invisible wall */ - if (x == 0) { - x += 200; - } - if (y == 0) { - y += 200; - } - if (x == (screen_width - 1)) { - x -= 200; - } - if (y == (screen_height - 1)) { - y -= 200; - } - - if (x != (int)motion->x_root || y != (int)motion->y_root) { + if (x <= geometry.x || x - geometry.x >= geometry.width - 1 || + y <= geometry.y || y - geometry.y >= geometry.height - 1) { GdkDevice *dev = gdk_event_get_device((GdkEvent *)motion); + x = geometry.x + geometry.width / 2; + y = geometry.y + geometry.height / 2; + gdk_device_warp(dev, screen, x, y); s->last_set = FALSE; return FALSE; From 9a6c69d389c0492a57c439dc3babbd0f9da2555e Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Wed, 14 Jul 2021 14:57:35 +0900 Subject: [PATCH 2/6] ui/spice: Use HAVE_SPICE_GL for OpenGL checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some code in ui/spice used CONFIG_OPENGL for OpenGL conditionals, but SPICE also depends on CONFIG_GBM and SPICE server whose version is 0.13.1 or later for OpenGL. Always use HAVE_SPICE_GL, which defines the precise condition. Signed-off-by: Akihiko Odaki Reviewed-by: Marc-André Lureau Message-Id: <20210714055735.86050-1-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- ui/spice-app.c | 3 ++- ui/spice-core.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/ui/spice-app.c b/ui/spice-app.c index 641f4a9d53..7e71e18da9 100644 --- a/ui/spice-app.c +++ b/ui/spice-app.c @@ -27,6 +27,7 @@ #include #include "ui/console.h" +#include "ui/spice-display.h" #include "qemu/config-file.h" #include "qemu/option.h" #include "qemu/cutils.h" @@ -175,7 +176,7 @@ static void spice_app_display_early_init(DisplayOptions *opts) qemu_opt_set(qopts, "addr", sock_path, &error_abort); qemu_opt_set(qopts, "image-compression", "off", &error_abort); qemu_opt_set(qopts, "streaming-video", "off", &error_abort); -#ifdef CONFIG_OPENGL +#ifdef HAVE_SPICE_GL qemu_opt_set(qopts, "gl", opts->has_gl ? "on" : "off", &error_abort); display_opengl = opts->has_gl; #endif diff --git a/ui/spice-core.c b/ui/spice-core.c index 86d43783ac..0371055e6c 100644 --- a/ui/spice-core.c +++ b/ui/spice-core.c @@ -1039,6 +1039,6 @@ static void spice_register_config(void) opts_init(spice_register_config); module_opts("spice"); -#ifdef CONFIG_OPENGL +#ifdef HAVE_SPICE_GL module_dep("ui-opengl"); #endif From 074c0653c25bbd2f3978699099051d2343f34c57 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Wed, 14 Jul 2021 14:56:46 +0900 Subject: [PATCH 3/6] ui/egl-headless: Remove a check for CONFIG_OPENGL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ui/egl-headless is only built when CONFIG_OPENGL is defined because it depends on CONFIG_OPENGL without condition. Remove a redundant conditonal in ui/egl-headless.c Signed-off-by: Akihiko Odaki Reviewed-by: Marc-André Lureau Message-Id: <20210714055646.85952-1-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- ui/egl-headless.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/ui/egl-headless.c b/ui/egl-headless.c index 75404e0e87..a26a2520c4 100644 --- a/ui/egl-headless.c +++ b/ui/egl-headless.c @@ -214,6 +214,4 @@ static void register_egl(void) type_init(register_egl); -#ifdef CONFIG_OPENGL module_dep("ui-opengl"); -#endif From 40a9aadbc9900f8b50fffe485df7cc0bfb9ec01c Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Fri, 9 Jul 2021 01:56:19 +0900 Subject: [PATCH 4/6] ui/cocoa: Fix the type of main's argv Signed-off-by: Akihiko Odaki Reviewed-by: Peter Maydell Message-Id: <20210708165619.29299-1-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- ui/cocoa.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 9f72844b07..68a6302184 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1888,12 +1888,12 @@ static void *call_qemu_main(void *opaque) exit(status); } -int main (int argc, const char * argv[]) { +int main (int argc, char **argv) { QemuThread thread; COCOA_DEBUG("Entered main()\n"); gArgc = argc; - gArgv = (char **)argv; + gArgv = argv; qemu_sem_init(&display_init_sem, 0); qemu_sem_init(&app_started_sem, 0); From d4a121048095f276913dca977bb21bcbab02c44c Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Mon, 5 Jul 2021 16:59:12 +0900 Subject: [PATCH 5/6] ui: update keycodemapdb submodule commit The change of ui/keycodemapdb effective on QEMU is only commit d21009b1c9f94b740ea66be8e48a1d8ad8124023, which adds mappings for key codes added in commit d7696ff884e35c6dacf83a7cbe3355e3b0a90125. d21009b1c9f94b740ea66be8e48a1d8ad8124023 Add QEMU QKeyCode "lang1" and "lang2" 320f92c36a80bfafc5d57834592a7be5fd79f104 rust: fix cargo clippy e62d42f0fd76f7bb8bf78385a83c060e66ff52b0 tests: add rust test 3e25e1ca1772fc3f2039f739f8f920450dc68e50 gen: add --lang rust 9133a0b8022d1fb063a81cc2ba3b627c14ccdfd1 tests: fix argument order Signed-off-by: Akihiko Odaki Message-Id: <20210705075912.2280-1-akihiko.odaki@gmail.com> Signed-off-by: Gerd Hoffmann --- ui/keycodemapdb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/keycodemapdb b/ui/keycodemapdb index 6119e6e19a..d21009b1c9 160000 --- a/ui/keycodemapdb +++ b/ui/keycodemapdb @@ -1 +1 @@ -Subproject commit 6119e6e19a050df847418de7babe5166779955e4 +Subproject commit d21009b1c9f94b740ea66be8e48a1d8ad8124023 From 584af1f1d955476aacba3350c4efb5865fc91c09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Volker=20R=C3=BCmelin?= Date: Sun, 25 Jul 2021 18:50:39 +0200 Subject: [PATCH 6/6] ui/gtk: add a keyboard fifo to the VTE consoles MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since commit 8eb13bbbac ("ui/gtk: vte: fix sending multiple characeters") it's very easy to lock up QEMU with the GTK ui. If you configure a guest with a serial device and the guest doesn't listen on this device, QEMU will lock up after entering two characters in the serial console. That's because current code uses a busy loop for the chardev write retries and the busy loop doesn't terminate in this case. To fix this problem add a fifo to the VTE consoles and use the chr_accept_input() callback function to write the remaining characters in the queue to the chardev. The fifo has a size of 4096 bytes, so one can copy and paste a fairly large URL or file path. Fixes: 8eb13bbbac ("ui/gtk: vte: fix sending multiple characeters") Signed-off-by: Volker Rümelin Message-Id: <20210725165039.5242-1-vr_qemu@t-online.de> Signed-off-by: Gerd Hoffmann --- include/ui/gtk.h | 4 ++++ ui/gtk.c | 42 +++++++++++++++++++++++++++++++++--------- 2 files changed, 37 insertions(+), 9 deletions(-) diff --git a/include/ui/gtk.h b/include/ui/gtk.h index 9516670ebc..80d6bbd9b5 100644 --- a/include/ui/gtk.h +++ b/include/ui/gtk.h @@ -25,6 +25,9 @@ #include "ui/egl-helpers.h" #include "ui/egl-context.h" #endif +#ifdef CONFIG_VTE +#include "qemu/fifo8.h" +#endif #define MAX_VCS 10 @@ -62,6 +65,7 @@ typedef struct VirtualVteConsole { GtkWidget *scrollbar; GtkWidget *terminal; Chardev *chr; + Fifo8 out_fifo; bool echo; } VirtualVteConsole; #endif diff --git a/ui/gtk.c b/ui/gtk.c index 18542c7633..974e4dfc0b 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -1640,6 +1640,25 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque) } } +static void gd_vc_send_chars(VirtualConsole *vc) +{ + uint32_t len, avail; + + len = qemu_chr_be_can_write(vc->vte.chr); + avail = fifo8_num_used(&vc->vte.out_fifo); + if (len > avail) { + len = avail; + } + while (len > 0) { + const uint8_t *buf; + uint32_t size; + + buf = fifo8_pop_buf(&vc->vte.out_fifo, len, &size); + qemu_chr_be_write(vc->vte.chr, (uint8_t *)buf, size); + len -= size; + } +} + static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len) { VCChardev *vcd = VC_CHARDEV(chr); @@ -1649,6 +1668,14 @@ static int gd_vc_chr_write(Chardev *chr, const uint8_t *buf, int len) return len; } +static void gd_vc_chr_accept_input(Chardev *chr) +{ + VCChardev *vcd = VC_CHARDEV(chr); + VirtualConsole *vc = vcd->console; + + gd_vc_send_chars(vc); +} + static void gd_vc_chr_set_echo(Chardev *chr, bool echo) { VCChardev *vcd = VC_CHARDEV(chr); @@ -1688,6 +1715,7 @@ static void char_gd_vc_class_init(ObjectClass *oc, void *data) cc->parse = qemu_chr_parse_vc; cc->open = gd_vc_open; cc->chr_write = gd_vc_chr_write; + cc->chr_accept_input = gd_vc_chr_accept_input; cc->chr_set_echo = gd_vc_chr_set_echo; } @@ -1702,6 +1730,7 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, gpointer user_data) { VirtualConsole *vc = user_data; + uint32_t free; if (vc->vte.echo) { VteTerminal *term = VTE_TERMINAL(vc->vte.terminal); @@ -1721,16 +1750,10 @@ static gboolean gd_vc_in(VteTerminal *terminal, gchar *text, guint size, } } - int remaining = size; - uint8_t* p = (uint8_t *)text; - while (remaining > 0) { - int can_write = qemu_chr_be_can_write(vc->vte.chr); - int written = MIN(remaining, can_write); - qemu_chr_be_write(vc->vte.chr, p, written); + free = fifo8_num_free(&vc->vte.out_fifo); + fifo8_push_all(&vc->vte.out_fifo, (uint8_t *)text, MIN(free, size)); + gd_vc_send_chars(vc); - remaining -= written; - p += written; - } return TRUE; } @@ -1747,6 +1770,7 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, vc->s = s; vc->vte.echo = vcd->echo; vc->vte.chr = chr; + fifo8_create(&vc->vte.out_fifo, 4096); vcd->console = vc; snprintf(buffer, sizeof(buffer), "vc%d", idx);