Skip to content

Commit 8e8e844

Browse files
committed
softmmu/vl: Add a "grab-mod" parameter to the -display sdl option
The -display sdl option is not using QAPI internally yet, and uses hand- crafted parsing instead (see parse_display() in vl.c), which is quite ugly, since most of the other code is using the QAPIfied DisplayOption already. Unfortunately, the "alt_grab" and "ctrl_grab" use underscores in their names which has recently been forbidden in new QAPI code, so a straight conversion is not possible. While we could add some exceptions to the QAPI schema parser for this, the way these parameters have been designed was maybe a bad idea anyway: First, it's not possible to enable both parameters at the same time, thus instead of two boolean parameters it would be better to have only one multi-choice parameter instead. Second, the naming is also somewhat unfortunate since the "alt_grab" parameter is not about the ALT key, but rather about the left SHIFT key that has to be used additionally when the parameter is enabled. So instead of trying to QAPIfy "alt_grab" and "ctrl_grab", let's rather introduce an alternative to these parameters instead, a new parameter called "grab-mod" which can either be set to "lshift-lctrl-lalt" or to "rctrl". In case we ever want to support additional modes later, we can then also simply extend the list of supported strings here. Message-Id: <[email protected]> Reviewed-by: Gerd Hoffmann <[email protected]> Signed-off-by: Thomas Huth <[email protected]>
1 parent bf6a618 commit 8e8e844

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

qemu-options.hx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ DEF("display", HAS_ARG, QEMU_OPTION_display,
18341834
#endif
18351835
#if defined(CONFIG_SDL)
18361836
"-display sdl[,alt_grab=on|off][,ctrl_grab=on|off][,gl=on|core|es|off]\n"
1837-
" [,show-cursor=on|off][,window-close=on|off]\n"
1837+
" [,grab-mod=<mod>][,show-cursor=on|off][,window-close=on|off]\n"
18381838
#endif
18391839
#if defined(CONFIG_GTK)
18401840
"-display gtk[,full-screen=on|off][,gl=on|off][,grab-on-hover=on|off]\n"
@@ -1880,6 +1880,10 @@ SRST
18801880
window; see the SDL documentation for other possibilities).
18811881
Valid parameters are:
18821882

1883+
``grab-mod=<mods>`` : Used to select the modifier keys for toggling
1884+
the mouse grabbing in conjunction with the "g" key. `<mods>` can be
1885+
either `lshift-lctrl-lalt` or `rctrl`.
1886+
18831887
``alt_grab=on|off`` : Use Control+Alt+Shift-g to toggle mouse grabbing
18841888

18851889
``ctrl_grab=on|off`` : Use Right-Control-g to toggle mouse grabbing

softmmu/vl.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,15 +1017,24 @@ static void parse_display(const char *p)
10171017
* parse_display_qapi() due to some options not in
10181018
* DisplayOptions, specifically:
10191019
* - ctrl_grab + alt_grab
1020-
* Not clear yet what happens to them long-term. Should
1021-
* replaced by something better or deprecated and dropped.
1020+
* They can't be moved into the QAPI since they use underscores,
1021+
* thus they will get replaced by "grab-mod" in the long term
10221022
*/
10231023
#if defined(CONFIG_SDL)
10241024
dpy.type = DISPLAY_TYPE_SDL;
10251025
while (*opts) {
10261026
const char *nextopt;
10271027

1028-
if (strstart(opts, ",alt_grab=", &nextopt)) {
1028+
if (strstart(opts, ",grab-mod=", &nextopt)) {
1029+
opts = nextopt;
1030+
if (strstart(opts, "lshift-lctrl-lalt", &nextopt)) {
1031+
alt_grab = 1;
1032+
} else if (strstart(opts, "rctrl", &nextopt)) {
1033+
ctrl_grab = 1;
1034+
} else {
1035+
goto invalid_sdl_args;
1036+
}
1037+
} else if (strstart(opts, ",alt_grab=", &nextopt)) {
10291038
opts = nextopt;
10301039
if (strstart(opts, "on", &nextopt)) {
10311040
alt_grab = 1;

0 commit comments

Comments
 (0)