[PATCH 0/5] ui: rework -show-cursor option

Gerd Hoffmann (5): ui: add show-cursor option ui/gtk: implement show-cursor option ui/sdl: implement show-cursor option ui: wire up legacy -show-cursor option ui: deprecate legacy -show-cursor option include/sysemu/sysemu.h | 1 - ui/gtk.c | 8 +++++++- ui/sdl2.c | 28 ++++++++++++++++++++-------- vl.c | 6 ++++-- qapi/ui.json | 2 ++ qemu-deprecated.texi | 5 +++++ 6 files changed, 38 insertions(+), 12 deletions(-) -- 2.18.1

When enabled forces showing a the mouse cursor, i.e. do nowallow the guest to hide it. Defaults to off. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- qapi/ui.json | 2 ++ 1 file changed, 2 insertions(+) diff --git a/qapi/ui.json b/qapi/ui.json index e04525d8b44b..7c516a455631 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1144,6 +1144,7 @@ # @type: Which DisplayType qemu should use. # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). +# @show-cursor: Force showing the mouse cursor (default: off). # @gl: Enable OpenGL support (default: off). # # Since: 2.12 @@ -1153,6 +1154,7 @@ 'base' : { 'type' : 'DisplayType', '*full-screen' : 'bool', '*window-close' : 'bool', + '*show-cursor' : 'bool', '*gl' : 'DisplayGLMode' }, 'discriminator' : 'type', 'data' : { 'gtk' : 'DisplayGTK', -- 2.18.1

On 2/5/20 5:03 AM, Gerd Hoffmann wrote:
When enabled forces showing a the mouse cursor, i.e. do
When enabled, this forces showing the mouse...
nowallow the guest to hide it. Defaults to off.
s/nowallow/not allow/
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- qapi/ui.json | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/qapi/ui.json b/qapi/ui.json index e04525d8b44b..7c516a455631 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1144,6 +1144,7 @@ # @type: Which DisplayType qemu should use. # @full-screen: Start user interface in fullscreen mode (default: off). # @window-close: Allow to quit qemu with window close button (default: on). +# @show-cursor: Force showing the mouse cursor (default: off). # @gl: Enable OpenGL support (default: off). # # Since: 2.12
Missing a '(since 5.0)' tag.
@@ -1153,6 +1154,7 @@ 'base' : { 'type' : 'DisplayType', '*full-screen' : 'bool', '*window-close' : 'bool', + '*show-cursor' : 'bool', '*gl' : 'DisplayGLMode' }, 'discriminator' : 'type', 'data' : { 'gtk' : 'DisplayGTK',
-- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3226 Virtualization: qemu.org | libvirt.org

On Wed, Feb 05, 2020 at 12:03:52PM +0100, Gerd Hoffmann wrote:
When enabled forces showing a the mouse cursor, i.e. do nowallow the guest to hide it. Defaults to off.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- qapi/ui.json | 2 ++ 1 file changed, 2 insertions(+)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- ui/gtk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ui/gtk.c b/ui/gtk.c index d18892d1de61..78b197ade4c1 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -247,6 +247,7 @@ static void gd_update_cursor(VirtualConsole *vc) { GtkDisplayState *s = vc->s; GdkWindow *window; + bool allow_hide_cursor = true; if (vc->type != GD_VC_GFX || !qemu_console_is_graphic(vc->gfx.dcl.con)) { @@ -257,8 +258,13 @@ static void gd_update_cursor(VirtualConsole *vc) return; } + if (s->opts->has_show_cursor && s->opts->show_cursor) { + allow_hide_cursor = false; + } + window = gtk_widget_get_window(GTK_WIDGET(vc->gfx.drawing_area)); - if (s->full_screen || qemu_input_is_absolute() || s->ptr_owner == vc) { + if (allow_hide_cursor && + (s->full_screen || qemu_input_is_absolute() || s->ptr_owner == vc)) { gdk_window_set_cursor(window, s->null_cursor); } else { gdk_window_set_cursor(window, NULL); -- 2.18.1

On Wed, Feb 05, 2020 at 12:03:53PM +0100, Gerd Hoffmann wrote:
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- ui/gtk.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- ui/sdl2.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/ui/sdl2.c b/ui/sdl2.c index 9030f1c42efb..e18555b10a42 100644 --- a/ui/sdl2.c +++ b/ui/sdl2.c @@ -161,9 +161,15 @@ static void sdl_update_caption(struct sdl2_console *scon) } } -static void sdl_hide_cursor(void) +static void sdl_hide_cursor(struct sdl2_console *scon) { - if (!cursor_hide) { + bool allow_hide_cursor = true; + + if (scon->opts->has_show_cursor && scon->opts->show_cursor) { + allow_hide_cursor = false; + } + + if (!allow_hide_cursor) { return; } @@ -175,9 +181,15 @@ static void sdl_hide_cursor(void) } } -static void sdl_show_cursor(void) +static void sdl_show_cursor(struct sdl2_console *scon) { - if (!cursor_hide) { + bool allow_hide_cursor = true; + + if (scon->opts->has_show_cursor && scon->opts->show_cursor) { + allow_hide_cursor = false; + } + + if (!allow_hide_cursor) { return; } @@ -216,7 +228,7 @@ static void sdl_grab_start(struct sdl2_console *scon) SDL_WarpMouseInWindow(scon->real_window, guest_x, guest_y); } } else { - sdl_hide_cursor(); + sdl_hide_cursor(scon); } SDL_SetWindowGrab(scon->real_window, SDL_TRUE); gui_grab = 1; @@ -227,7 +239,7 @@ static void sdl_grab_end(struct sdl2_console *scon) { SDL_SetWindowGrab(scon->real_window, SDL_FALSE); gui_grab = 0; - sdl_show_cursor(); + sdl_show_cursor(scon); sdl_update_caption(scon); } @@ -658,7 +670,7 @@ static void sdl_mouse_warp(DisplayChangeListener *dcl, if (on) { if (!guest_cursor) { - sdl_show_cursor(); + sdl_show_cursor(scon); } if (gui_grab || qemu_input_is_absolute() || absolute_enabled) { SDL_SetCursor(guest_sprite); @@ -667,7 +679,7 @@ static void sdl_mouse_warp(DisplayChangeListener *dcl, } } } else if (gui_grab) { - sdl_hide_cursor(); + sdl_hide_cursor(scon); } guest_cursor = on; guest_x = x, guest_y = y; -- 2.18.1

On Wed, Feb 05, 2020 at 12:03:54PM +0100, Gerd Hoffmann wrote:
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- ui/sdl2.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-)
Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- include/sysemu/sysemu.h | 1 - vl.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/include/sysemu/sysemu.h b/include/sysemu/sysemu.h index 80c57fdc4e64..da2f87c3e63a 100644 --- a/include/sysemu/sysemu.h +++ b/include/sysemu/sysemu.h @@ -42,7 +42,6 @@ extern const char *keyboard_layout; extern int win2k_install_hack; extern int alt_grab; extern int ctrl_grab; -extern int cursor_hide; extern int graphic_rotate; extern int no_quit; extern int no_shutdown; diff --git a/vl.c b/vl.c index 24951b51a94b..0db0aa0fa040 100644 --- a/vl.c +++ b/vl.c @@ -168,7 +168,6 @@ int no_hpet = 0; int fd_bootchk = 1; static int no_reboot; int no_shutdown = 0; -int cursor_hide = 1; int graphic_rotate = 0; const char *watchdog; QEMUOptionRom option_rom[MAX_OPTION_ROMS]; @@ -3553,7 +3552,8 @@ int main(int argc, char **argv, char **envp) no_shutdown = 1; break; case QEMU_OPTION_show_cursor: - cursor_hide = 0; + dpy.has_show_cursor = true; + dpy.show_cursor = true; break; case QEMU_OPTION_uuid: if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { -- 2.18.1

On Wed, Feb 05, 2020 at 12:03:55PM +0100, Gerd Hoffmann wrote:
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- include/sysemu/sysemu.h | 1 - vl.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/vl.c b/vl.c index 24951b51a94b..0db0aa0fa040 100644 --- a/vl.c +++ b/vl.c @@ -3553,7 +3552,8 @@ int main(int argc, char **argv, char **envp) no_shutdown = 1; break; case QEMU_OPTION_show_cursor: - cursor_hide = 0;
Since commit 13aefd303cf996c2d183e94082413885bf1d15bf cursor_hide is also used in ui/cocoa.m Jano
+ dpy.has_show_cursor = true; + dpy.show_cursor = true; break; case QEMU_OPTION_uuid: if (qemu_uuid_parse(optarg, &qemu_uuid) < 0) { -- 2.18.1

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- vl.c | 2 ++ qemu-deprecated.texi | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/vl.c b/vl.c index 0db0aa0fa040..71d040257b34 100644 --- a/vl.c +++ b/vl.c @@ -3552,6 +3552,8 @@ int main(int argc, char **argv, char **envp) no_shutdown = 1; break; case QEMU_OPTION_show_cursor: + warn_report("The -show-cursor option is deprecated, " + "use -display {sdl,gtk},show-cursor=on instead"); dpy.has_show_cursor = true; dpy.show_cursor = true; break; diff --git a/qemu-deprecated.texi b/qemu-deprecated.texi index 3d2a8ff54bae..ea4c5ca27f8e 100644 --- a/qemu-deprecated.texi +++ b/qemu-deprecated.texi @@ -148,6 +148,11 @@ QEMU 5.0 introduced an alternative syntax to specify the size of the translation block cache, @option{-accel tcg,tb-size=}. The new syntax deprecates the previously available @option{-tb-size} option. +@subsection -show-cursor option (since 5.0) + +Use @option{-display sdl,show-cursor=on} or + @option{-display gtk,show-cursor=on} instead. + @section QEMU Machine Protocol (QMP) commands @subsection change (since 2.5.0) -- 2.18.1

On Wed, Feb 05, 2020 at 12:03:56PM +0100, Gerd Hoffmann wrote:
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com> --- vl.c | 2 ++ qemu-deprecated.texi | 5 +++++ 2 files changed, 7 insertions(+)
libvirt does not use -show-cursor Reviewed-by: Ján Tomko <jtomko@redhat.com> Jano
participants (3)
-
Eric Blake
-
Gerd Hoffmann
-
Ján Tomko