Skip to contentSkip to conversation

ui: rework -show-cursor option

PATCH In review Gerd Hoffmann 4 participants 12 messages Feb 7, 2020 – Feb 12, 2020

lore
Share & tools
lore
#0 lore raw

v3 cover ui: rework -show-cursor option

Add -display {sdl,gtk,cocoa},show-cursor=on as replacement for -show-cursor. sdl + cocoa are switched over (no change in behavior), gtk support is added.

Gerd Hoffmann (7):
ui: add show-cursor option
ui: wire up legacy -show-cursor option
ui/sdl: switch to new show-cursor option
ui/cocoa: switch to new show-cursor option
ui/gtk: implement show-cursor option
ui: drop curor_hide global variable.
ui: deprecate legacy -show-cursor option

 include/sysemu/sysemu.h |  1 -
 ui/gtk.c                |  8 ++++++--
 ui/sdl2.c               | 16 ++++++++--------
 vl.c                    | 16 ++++++++++++++--
 qapi/ui.json            |  3 +++
 qemu-deprecated.texi    |  5 +++++
 ui/cocoa.m              |  4 ++++
 7 files changed, 40 insertions(+), 13 deletions(-)
Signature · 1 line
2.18.1
#1 lore raw

PATCH v3 1/7 ui: add show-cursor option

When enabled, this forces showing the mouse cursor, i.e. do not hide the pointer on mouse grabs. Defaults to off.

---
 qapi/ui.json | 3 +++
 1 file changed, 3 insertions(+)
qapi/ui.json +3 -0
index e04525d8b44b..b9df7fe7b5cb 100644
@@ -1144,6 +1144,8 @@
 # @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).
+#                 Since: 5.0
 # @gl:            Enable OpenGL support (default: off).
 #
 # Since: 2.12
@@ -1153,6 +1155,7 @@
   'base'    : { 'type'           : 'DisplayType',
                 '*full-screen'   : 'bool',
                 '*window-close'  : 'bool',
+                '*show-cursor'   : 'bool',
                 '*gl'            : 'DisplayGLMode' },
   'discriminator' : 'type',
   'data'    : { 'gtk'            : 'DisplayGTK',
Signature · 1 line
2.18.1
Reviewed-by on v3 1/7
#2 lore raw

Re: [PATCH v3 1/7] ui: add show-cursor option

Quoted 14 lines · Gerd Hoffmann

When enabled, this forces showing the mouse cursor, i.e. do not hide the pointer on mouse grabs. Defaults to off.

---
 qapi/ui.json | 3 +++
 1 file changed, 3 insertions(+)
qapi/ui.json +0 -0
index e04525d8b44b..b9df7fe7b5cb 100644

qapi/ui.json line 1148

Quoted 5 lines
qapi/ui.json +2 -0
@@ -1144,6 +1144,8 @@
 # @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).
+#                 Since: 5.0

By convention, we use

# Since: 5.0

for top-level definitions, and

# (since 5.0)

for members and such. See docs/devel/qapi-code-gen.txt section "Definition documentation".

qapi/ui.json line 1161

Quoted 11 lines
qapi/ui.json +1 -0
 # @gl:            Enable OpenGL support (default: off).
 #
 # Since: 2.12
@@ -1153,6 +1155,7 @@
   'base'    : { 'type'           : 'DisplayType',
                 '*full-screen'   : 'bool',
                 '*window-close'  : 'bool',
+                '*show-cursor'   : 'bool',
                 '*gl'            : 'DisplayGLMode' },
   'discriminator' : 'type',
   'data'    : { 'gtk'            : 'DisplayGTK',

With the doc comment tidied up:

#3 lore raw

PATCH v3 2/7 ui: wire up legacy -show-cursor option

In reply to Gerd Hoffmann

Set new show-cursor display option when legacy -show-cursor is specified on the command line.

---
 vl.c | 2 ++
 1 file changed, 2 insertions(+)
vl.c +2 -0
index 7dcb0879c497..5419b3d68200 100644
@@ -3554,6 +3554,8 @@ int main(int argc, char **argv, char **envp)
                 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) {
Signature · 1 line
2.18.1
#4 lore raw

PATCH v3 3/7 ui/sdl: switch to new show-cursor option

In reply to Gerd Hoffmann

Use DisplayOpts settings instead of cursor_hide global variable. Also make "-display sdl,show-cursor=on" work.

---
 ui/sdl2.c | 16 ++++++++--------
 vl.c      | 10 ++++++++++
 2 files changed, 18 insertions(+), 8 deletions(-)
ui/sdl2.c +8 -8
index 9030f1c42efb..3c9424eb42c3 100644
@@ -161,9 +161,9 @@ 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) {
+    if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
         return;
     }
 
@@ -175,9 +175,9 @@ static void sdl_hide_cursor(void)
     }
 }
 
-static void sdl_show_cursor(void)
+static void sdl_show_cursor(struct sdl2_console *scon)
 {
-    if (!cursor_hide) {
+    if (scon->opts->has_show_cursor && scon->opts->show_cursor) {
         return;
     }
 
@@ -216,7 +216,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 +227,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 +658,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 +667,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;
vl.c +10 -0
index 5419b3d68200..0a13cf2b1724 100644
@@ -1931,6 +1931,16 @@ static void parse_display(const char *p)
                 } else {
                     goto invalid_sdl_args;
                 }
+            } else if (strstart(opts, ",show-cursor=", &nextopt)) {
+                opts = nextopt;
+                dpy.has_show_cursor = true;
+                if (strstart(opts, "on", &nextopt)) {
+                    dpy.show_cursor = true;
+                } else if (strstart(opts, "off", &nextopt)) {
+                    dpy.show_cursor = false;
+                } else {
+                    goto invalid_sdl_args;
+                }
             } else if (strstart(opts, ",gl=", &nextopt)) {
                 opts = nextopt;
                 dpy.has_gl = true;
Signature · 1 line
2.18.1
#5 lore raw

PATCH v3 4/7 ui/cocoa: switch to new show-cursor option

In reply to Gerd Hoffmann

Use DisplayOpts settings to set the new file-global cursor_hide variable, stop using the qemu-global cursor_hide variable.

---
 ui/cocoa.m | 4 ++++
 1 file changed, 4 insertions(+)
ui/cocoa.m +4 -0
index fbb5b1b45f81..f7b323044582 100644
@@ -125,6 +125,7 @@ typedef struct {
 NSWindow *normalWindow, *about_window;
 static DisplayChangeListener *dcl;
 static int last_buttons;
+static int cursor_hide = 1;
 
 int gArgc;
 char **gArgv;
@@ -1918,6 +1919,9 @@ static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
             [(QemuCocoaAppController *)[[NSApplication sharedApplication] delegate] toggleFullScreen: nil];
         });
     }
+    if (opts->has_show_cursor && opts->show_cursor) {
+        cursor_hide = 0;
+    }
 
     dcl = g_malloc0(sizeof(DisplayChangeListener));
 
Signature · 1 line
2.18.1
#6 lore raw

PATCH v3 5/7 ui/gtk: implement show-cursor option

In reply to Gerd Hoffmann

When specified just set null_cursor to NULL so we get the default pointer instead of a blank pointer.

---
 ui/gtk.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
ui/gtk.c +6 -2
index d18892d1de61..a685d1ae0848 100644
@@ -2243,8 +2243,12 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
     textdomain("qemu");
 
     window_display = gtk_widget_get_display(s->window);
-    s->null_cursor = gdk_cursor_new_for_display(window_display,
-                                                GDK_BLANK_CURSOR);
+    if (s->opts->has_show_cursor && s->opts->show_cursor) {
+        s->null_cursor = NULL; /* default pointer */
+    } else {
+        s->null_cursor = gdk_cursor_new_for_display(window_display,
+                                                    GDK_BLANK_CURSOR);
+    }
 
     s->mouse_mode_notifier.notify = gd_mouse_mode_change;
     qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier);
Signature · 1 line
2.18.1
#7 lore raw

Re: [PATCH v3 5/7] ui/gtk: implement show-cursor option

Quoted 14 lines · Gerd Hoffmann

When specified just set null_cursor to NULL so we get the default pointer instead of a blank pointer.

---
  ui/gtk.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
ui/gtk.c +0 -0
index d18892d1de61..a685d1ae0848 100644
@@ -2243,8 +2243,12 @@ static void gtk_display_init(DisplayState *ds, DisplayOptions *opts)
      textdomain("qemu");

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2251

Quoted 10 lines
ui/gtk.c +6 -2
 
      window_display = gtk_widget_get_display(s->window);
-    s->null_cursor = gdk_cursor_new_for_display(window_display,
-                                                GDK_BLANK_CURSOR);
+    if (s->opts->has_show_cursor && s->opts->show_cursor) {
+        s->null_cursor = NULL; /* default pointer */
+    } else {
+        s->null_cursor = gdk_cursor_new_for_display(window_display,
+                                                    GDK_BLANK_CURSOR);
+    }

I think it would make more sense to have all the logic related to what cursor is used in the same location, instead of split up between here and gd_update_cursor(). This would also match the behavior of the SDL and cocoa backends a little better.

Quoted 3 lines
ui/gtk.c +0 -0
      s->mouse_mode_notifier.notify = gd_mouse_mode_change;
      qemu_add_mouse_mode_change_notifier(&s->mouse_mode_notifier);
#8 lore raw

Re: [PATCH v3 5/7] ui/gtk: implement show-cursor option

Quoted 10 lines

ui/gtk.c static void gtk_display_init(DisplayState *ds, DisplayOptions *opts) · line 2251

Quoted 6 lines
ui/gtk.c +6 -0
+    if (s->opts->has_show_cursor && s->opts->show_cursor) {
+        s->null_cursor = NULL; /* default pointer */
+    } else {
+        s->null_cursor = gdk_cursor_new_for_display(window_display,
+                                                    GDK_BLANK_CURSOR);
+    }

I think it would make more sense to have all the logic related to what cursor is used in the same location, instead of split up between here and gd_update_cursor().

Note that it isn't that simple. There are a few more places in gd_grab_*() which use s->null_cursor and would need adaption.

cheers,
Gerd

#9 lore raw

PATCH v3 6/7 ui: drop curor_hide global variable.

In reply to Gerd Hoffmann

No users left.

---
 include/sysemu/sysemu.h | 1 -
 vl.c                    | 2 --
 2 files changed, 3 deletions(-)
include/sysemu/sysemu.h +0 -1
index 6358a324a711..7956e9054ade 100644
@@ -41,7 +41,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_shutdown;
 extern int old_param;
vl.c +0 -2
index 0a13cf2b1724..62efcd15c0bf 100644
@@ -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];
@@ -3563,7 +3562,6 @@ 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;
Signature · 1 line
2.18.1
#10 lore raw

PATCH v3 7/7 ui: deprecate legacy -show-cursor option

In reply to Gerd Hoffmann
---
 vl.c                 | 2 ++
 qemu-deprecated.texi | 5 +++++
 2 files changed, 7 insertions(+)
vl.c +2 -0
index 62efcd15c0bf..001be469c2e9 100644
@@ -3562,6 +3562,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;
qemu-deprecated.texi +5 -0
index ea3e10bde398..c1444d1839bd 100644
@@ -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)
Signature · 1 line
2.18.1
Reviewed-by on the v3 series
#11 lore raw
In reply to Gerd Hoffmann
Quoted 13 lines · Gerd Hoffmann

Add -display {sdl,gtk,cocoa},show-cursor=on as replacement for -show-cursor. sdl + cocoa are switched over (no change in behavior), gtk support is added.

Gerd Hoffmann (7):
ui: add show-cursor option
ui: wire up legacy -show-cursor option
ui/sdl: switch to new show-cursor option
ui/cocoa: switch to new show-cursor option
ui/gtk: implement show-cursor option
ui: drop curor_hide global variable.
ui: deprecate legacy -show-cursor option

Quoted 9 lines
include/sysemu/sysemu.h |  1 -
ui/gtk.c                |  8 ++++++--
ui/sdl2.c               | 16 ++++++++--------
vl.c                    | 16 ++++++++++++++--
qapi/ui.json            |  3 +++
qemu-deprecated.texi    |  5 +++++
ui/cocoa.m              |  4 ++++
7 files changed, 40 insertions(+), 13 deletions(-)

Series:

Jano