* [PATCH 0/1] ui/cocoa: Add option to disable left command and hide cursor on click @ 2021-12-31 17:42 Carwyn Ellis 2021-12-31 17:42 ` [PATCH 1/1] " Carwyn Ellis 0 siblings, 1 reply; 7+ messages in thread From: Carwyn Ellis @ 2021-12-31 17:42 UTC (permalink / raw) To: qemu-devel; +Cc: qemu-trivial, peter.maydell, Carwyn Ellis Apologies for all the spam on what should be a simple change. Still getting the hang of all of this. :/ Please disregard my earlier submissions. After further testing I realised that the calls to cursor hide/unhide weren't balanced which broke the hide/unhide behaviour. I've added an additional static flag to track the cursor state so the cursor state is only updated where this would change the existing cursor state, ensuring the calls are now balanced. Having made the switch to an M1 Mac I needed to switch from VMware back to QEMU in order to run some intel guests. This patch addresses a couple of niggles with the cocoa UI, namely: - Using command-tab to switch between the guest OS and MacOS sends the command keypress to the guest which can be annoying e.g. on a windows guest this may trigger the start menu - Switching between the guest and MacOS sometimes leaves the MacOS mouse cursor visible with no way to hide it without switching windows again To address these issues I've made the following changes - Added a new cocoa display option left-command-key which can be used to disable the left command key in the guest. Default is on. - Added a call to hideCursor on left and right mouse clicks so if the cursor is visible after switching back to the guest a mouse click will hide the cursor again. - Also updated the command line docs to reference the show-cursor option which is also respected by the cocoa UI code. Carwyn Ellis (1): ui/cocoa: Add option to disable left command and hide cursor on click qapi/ui.json | 17 +++++++++++++++++ qemu-options.hx | 12 ++++++++++++ ui/cocoa.m | 33 +++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 8 deletions(-) -- 2.34.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/1] ui/cocoa: Add option to disable left command and hide cursor on click 2021-12-31 17:42 [PATCH 0/1] ui/cocoa: Add option to disable left command and hide cursor on click Carwyn Ellis @ 2021-12-31 17:42 ` Carwyn Ellis 2021-12-31 17:49 ` Alexander Orzechowski 2021-12-31 17:56 ` Alexander Orzechowski 0 siblings, 2 replies; 7+ messages in thread From: Carwyn Ellis @ 2021-12-31 17:42 UTC (permalink / raw) To: qemu-devel; +Cc: qemu-trivial, peter.maydell, Carwyn Ellis When switching between guest and host on a Mac using command-tab the command key is sent to the guest which can trigger functionality in the guest OS. Specifying left-command-key=off disables forwarding this key to the guest. Defaults to enabled. When switching between guest and host on a Mac with a fullscreen guest the host pointer will occasionally persist despite the ui code requesting that it be hidden. Added cursor hide calls on left and right mouse click to hide the cursor when the mouse is clicked. Also updated the cocoa display documentation to reference the new left-command-key option along with the existing show-cursor option. --- qapi/ui.json | 17 +++++++++++++++++ qemu-options.hx | 12 ++++++++++++ ui/cocoa.m | 33 +++++++++++++++++++++++++-------- 3 files changed, 54 insertions(+), 8 deletions(-) diff --git a/qapi/ui.json b/qapi/ui.json index 2b4371da37..764480e145 100644 --- a/qapi/ui.json +++ b/qapi/ui.json @@ -1107,6 +1107,22 @@ 'data' : { '*grab-on-hover' : 'bool', '*zoom-to-fit' : 'bool' } } +## +# @DisplayCocoa: +# +# Cocoa display options. +# +# @left-command-key: Enable/disable forwarding of left command key to +# guest. Allows command-tab window switching on the +# host without sending this key to the guest when +# "off". Defaults to "on" +# +# Since: 6.2.50 +# +## +{ 'struct' : 'DisplayCocoa', + 'data' : { '*left-command-key' : 'bool' } } + ## # @DisplayEGLHeadless: # @@ -1254,6 +1270,7 @@ 'discriminator' : 'type', 'data' : { 'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' }, + 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, 'egl-headless': { 'type': 'DisplayEGLHeadless', 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, diff --git a/qemu-options.hx b/qemu-options.hx index 7d47510947..5214457676 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -1869,6 +1869,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, #if defined(CONFIG_DBUS_DISPLAY) "-display dbus[,addr=<dbusaddr>]\n" " [,gl=on|core|es|off][,rendernode=<file>]\n" +#endif +#if defined(CONFIG_COCOA) + "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n" #endif "-display none\n" " select display backend type\n" @@ -1956,6 +1959,15 @@ SRST ``charset=CP850`` for IBM CP850 encoding. The default is ``CP437``. + ``cocoa`` + Display video output in a Cocoa window. Mac only. This interface + provides drop-down menus and other UI elements to configure and + control the VM during runtime. Valid parameters are: + + ``show-cursor=on|off`` : Force showing the mouse cursor + + ``left-command-key=on|off`` : Disable forwarding left command key to host + ``egl-headless[,rendernode=<file>]`` Offload all OpenGL operations to a local DRI device. For any graphical display, this display needs to be paired with either diff --git a/ui/cocoa.m b/ui/cocoa.m index 69745c483b..10e492538a 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -95,6 +95,8 @@ static DisplayChangeListener dcl = { }; static int last_buttons; static int cursor_hide = 1; +static bool cursor_visible = 1; +static int left_command_key_enabled = 1; static int gArgc; static char **gArgv; @@ -411,18 +413,18 @@ QemuCocoaView *cocoaView; - (void) hideCursor { - if (!cursor_hide) { - return; + if (cursor_hide && cursor_visible) { + cursor_visible = 0; + [NSCursor hide]; } - [NSCursor hide]; } - (void) unhideCursor { - if (!cursor_hide) { - return; + if (cursor_hide && !cursor_visible) { + cursor_visible = 1; + [NSCursor unhide]; } - [NSCursor unhide]; } - (void) drawRect:(NSRect) rect @@ -831,10 +833,14 @@ QemuCocoaView *cocoaView; } break; - /* Don't pass command key changes to guest unless mouse is grabbed */ + /* + Don't pass command key changes to guest unless mouse is grabbed + or the key is explicitly disabled using the left-command-key option + */ case kVK_Command: if (isMouseGrabbed && - !!(modifiers & NSEventModifierFlagCommand)) { + !!(modifiers & NSEventModifierFlagCommand) && + left_command_key_enabled) { [self toggleKey:Q_KEY_CODE_META_L]; } break; @@ -923,10 +929,16 @@ QemuCocoaView *cocoaView; case NSEventTypeLeftMouseDown: buttons |= MOUSE_EVENT_LBUTTON; mouse_event = true; + if (isFullscreen) { + [self hideCursor]; + } break; case NSEventTypeRightMouseDown: buttons |= MOUSE_EVENT_RBUTTON; mouse_event = true; + if (isFullscreen) { + [self hideCursor]; + } break; case NSEventTypeOtherMouseDown: buttons |= MOUSE_EVENT_MBUTTON; @@ -2050,10 +2062,15 @@ 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; } + if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { + left_command_key_enabled = 0; + } + // register vga output callbacks register_displaychangelistener(&dcl); -- 2.34.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] ui/cocoa: Add option to disable left command and hide cursor on click 2021-12-31 17:42 ` [PATCH 1/1] " Carwyn Ellis @ 2021-12-31 17:49 ` Alexander Orzechowski 2021-12-31 17:52 ` Carwyn Ellis 2021-12-31 17:56 ` Alexander Orzechowski 1 sibling, 1 reply; 7+ messages in thread From: Alexander Orzechowski @ 2021-12-31 17:49 UTC (permalink / raw) To: Carwyn Ellis; +Cc: qemu trivial, QEMU On 12/31/21 12:42, Carwyn Ellis wrote: > When switching between guest and host on a Mac using command-tab the > command key is sent to the guest which can trigger functionality in the > guest OS. Specifying left-command-key=off disables forwarding this key > to the guest. Defaults to enabled. > > When switching between guest and host on a Mac with a fullscreen guest > the host pointer will occasionally persist despite the ui code > requesting that it be hidden. Added cursor hide calls on left and right > mouse click to hide the cursor when the mouse is clicked. > > Also updated the cocoa display documentation to reference the new > left-command-key option along with the existing show-cursor option. > --- > qapi/ui.json | 17 +++++++++++++++++ > qemu-options.hx | 12 ++++++++++++ > ui/cocoa.m | 33 +++++++++++++++++++++++++-------- > 3 files changed, 54 insertions(+), 8 deletions(-) > > diff --git a/qapi/ui.json b/qapi/ui.json > index 2b4371da37..764480e145 100644 > --- a/qapi/ui.json > +++ b/qapi/ui.json > @@ -1107,6 +1107,22 @@ > 'data' : { '*grab-on-hover' : 'bool', > '*zoom-to-fit' : 'bool' } } > > +## > +# @DisplayCocoa: > +# > +# Cocoa display options. > +# > +# @left-command-key: Enable/disable forwarding of left command key to > +# guest. Allows command-tab window switching on the > +# host without sending this key to the guest when > +# "off". Defaults to "on" > +# > +# Since: 6.2.50 > +# > +## > +{ 'struct' : 'DisplayCocoa', > + 'data' : { '*left-command-key' : 'bool' } } > + > ## > # @DisplayEGLHeadless: > # > @@ -1254,6 +1270,7 @@ > 'discriminator' : 'type', > 'data' : { > 'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' }, > + 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, > 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, > 'egl-headless': { 'type': 'DisplayEGLHeadless', > 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, > diff --git a/qemu-options.hx b/qemu-options.hx > index 7d47510947..5214457676 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1869,6 +1869,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, > #if defined(CONFIG_DBUS_DISPLAY) > "-display dbus[,addr=<dbusaddr>]\n" > " [,gl=on|core|es|off][,rendernode=<file>]\n" > +#endif > +#if defined(CONFIG_COCOA) > + "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n" > #endif > "-display none\n" > " select display backend type\n" > @@ -1956,6 +1959,15 @@ SRST > ``charset=CP850`` for IBM CP850 encoding. The default is > ``CP437``. > > + ``cocoa`` > + Display video output in a Cocoa window. Mac only. This interface > + provides drop-down menus and other UI elements to configure and > + control the VM during runtime. Valid parameters are: > + > + ``show-cursor=on|off`` : Force showing the mouse cursor > + > + ``left-command-key=on|off`` : Disable forwarding left command key to host > + > ``egl-headless[,rendernode=<file>]`` > Offload all OpenGL operations to a local DRI device. For any > graphical display, this display needs to be paired with either > diff --git a/ui/cocoa.m b/ui/cocoa.m > index 69745c483b..10e492538a 100644 > --- a/ui/cocoa.m > +++ b/ui/cocoa.m > @@ -95,6 +95,8 @@ static DisplayChangeListener dcl = { > }; > static int last_buttons; > static int cursor_hide = 1; > +static bool cursor_visible = 1; > +static int left_command_key_enabled = 1; > > static int gArgc; > static char **gArgv; > @@ -411,18 +413,18 @@ QemuCocoaView *cocoaView; > > - (void) hideCursor > { > - if (!cursor_hide) { > - return; > + if (cursor_hide && cursor_visible) { > + cursor_visible = 0; > + [NSCursor hide]; > } > - [NSCursor hide]; > } > > - (void) unhideCursor > { > - if (!cursor_hide) { > - return; > + if (cursor_hide && !cursor_visible) { > + cursor_visible = 1; > + [NSCursor unhide]; > } > - [NSCursor unhide]; > } > > - (void) drawRect:(NSRect) rect > @@ -831,10 +833,14 @@ QemuCocoaView *cocoaView; > } > break; > > - /* Don't pass command key changes to guest unless mouse is grabbed */ > + /* > + Don't pass command key changes to guest unless mouse is grabbed > + or the key is explicitly disabled using the left-command-key option > + */ > case kVK_Command: > if (isMouseGrabbed && > - !!(modifiers & NSEventModifierFlagCommand)) { > + !!(modifiers & NSEventModifierFlagCommand) && > + left_command_key_enabled) { > [self toggleKey:Q_KEY_CODE_META_L]; > } > break; > @@ -923,10 +929,16 @@ QemuCocoaView *cocoaView; > case NSEventTypeLeftMouseDown: > buttons |= MOUSE_EVENT_LBUTTON; > mouse_event = true; > + if (isFullscreen) { > + [self hideCursor]; > + } > break; > case NSEventTypeRightMouseDown: > buttons |= MOUSE_EVENT_RBUTTON; > mouse_event = true; > + if (isFullscreen) { > + [self hideCursor]; > + } > break; > case NSEventTypeOtherMouseDown: > buttons |= MOUSE_EVENT_MBUTTON; > @@ -2050,10 +2062,15 @@ 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; > } > > + if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { > + left_command_key_enabled = 0; > + } > + > // register vga output callbacks > register_displaychangelistener(&dcl); > All the fullscreen stuff could be put into its own patch. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] ui/cocoa: Add option to disable left command and hide cursor on click 2021-12-31 17:49 ` Alexander Orzechowski @ 2021-12-31 17:52 ` Carwyn Ellis 0 siblings, 0 replies; 7+ messages in thread From: Carwyn Ellis @ 2021-12-31 17:52 UTC (permalink / raw) To: Alexander Orzechowski; +Cc: qemu trivial, QEMU Ok cool, I’ll separate this out into 2 patches for the fullscreen and left-command changes respectively. Will aim to get this out at some point tomorrow. Cheers Carwyn > On 31 Dec 2021, at 17:49, Alexander Orzechowski <orzechowski.alexander@gmail.com> wrote: > > > On 12/31/21 12:42, Carwyn Ellis wrote: >> When switching between guest and host on a Mac using command-tab the >> command key is sent to the guest which can trigger functionality in the >> guest OS. Specifying left-command-key=off disables forwarding this key >> to the guest. Defaults to enabled. >> >> When switching between guest and host on a Mac with a fullscreen guest >> the host pointer will occasionally persist despite the ui code >> requesting that it be hidden. Added cursor hide calls on left and right >> mouse click to hide the cursor when the mouse is clicked. >> >> Also updated the cocoa display documentation to reference the new >> left-command-key option along with the existing show-cursor option. >> --- >> qapi/ui.json | 17 +++++++++++++++++ >> qemu-options.hx | 12 ++++++++++++ >> ui/cocoa.m | 33 +++++++++++++++++++++++++-------- >> 3 files changed, 54 insertions(+), 8 deletions(-) >> >> diff --git a/qapi/ui.json b/qapi/ui.json >> index 2b4371da37..764480e145 100644 >> --- a/qapi/ui.json >> +++ b/qapi/ui.json >> @@ -1107,6 +1107,22 @@ >> 'data' : { '*grab-on-hover' : 'bool', >> '*zoom-to-fit' : 'bool' } } >> +## >> +# @DisplayCocoa: >> +# >> +# Cocoa display options. >> +# >> +# @left-command-key: Enable/disable forwarding of left command key to >> +# guest. Allows command-tab window switching on the >> +# host without sending this key to the guest when >> +# "off". Defaults to "on" >> +# >> +# Since: 6.2.50 >> +# >> +## >> +{ 'struct' : 'DisplayCocoa', >> + 'data' : { '*left-command-key' : 'bool' } } >> + >> ## >> # @DisplayEGLHeadless: >> # >> @@ -1254,6 +1270,7 @@ >> 'discriminator' : 'type', >> 'data' : { >> 'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' }, >> + 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, >> 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, >> 'egl-headless': { 'type': 'DisplayEGLHeadless', >> 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, >> diff --git a/qemu-options.hx b/qemu-options.hx >> index 7d47510947..5214457676 100644 >> --- a/qemu-options.hx >> +++ b/qemu-options.hx >> @@ -1869,6 +1869,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, >> #if defined(CONFIG_DBUS_DISPLAY) >> "-display dbus[,addr=<dbusaddr>]\n" >> " [,gl=on|core|es|off][,rendernode=<file>]\n" >> +#endif >> +#if defined(CONFIG_COCOA) >> + "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n" >> #endif >> "-display none\n" >> " select display backend type\n" >> @@ -1956,6 +1959,15 @@ SRST >> ``charset=CP850`` for IBM CP850 encoding. The default is >> ``CP437``. >> + ``cocoa`` >> + Display video output in a Cocoa window. Mac only. This interface >> + provides drop-down menus and other UI elements to configure and >> + control the VM during runtime. Valid parameters are: >> + >> + ``show-cursor=on|off`` : Force showing the mouse cursor >> + >> + ``left-command-key=on|off`` : Disable forwarding left command key to host >> + >> ``egl-headless[,rendernode=<file>]`` >> Offload all OpenGL operations to a local DRI device. For any >> graphical display, this display needs to be paired with either >> diff --git a/ui/cocoa.m b/ui/cocoa.m >> index 69745c483b..10e492538a 100644 >> --- a/ui/cocoa.m >> +++ b/ui/cocoa.m >> @@ -95,6 +95,8 @@ static DisplayChangeListener dcl = { >> }; >> static int last_buttons; >> static int cursor_hide = 1; >> +static bool cursor_visible = 1; >> +static int left_command_key_enabled = 1; >> static int gArgc; >> static char **gArgv; >> @@ -411,18 +413,18 @@ QemuCocoaView *cocoaView; >> - (void) hideCursor >> { >> - if (!cursor_hide) { >> - return; >> + if (cursor_hide && cursor_visible) { >> + cursor_visible = 0; >> + [NSCursor hide]; >> } >> - [NSCursor hide]; >> } >> - (void) unhideCursor >> { >> - if (!cursor_hide) { >> - return; >> + if (cursor_hide && !cursor_visible) { >> + cursor_visible = 1; >> + [NSCursor unhide]; >> } >> - [NSCursor unhide]; >> } >> - (void) drawRect:(NSRect) rect >> @@ -831,10 +833,14 @@ QemuCocoaView *cocoaView; >> } >> break; >> - /* Don't pass command key changes to guest unless mouse is grabbed */ >> + /* >> + Don't pass command key changes to guest unless mouse is grabbed >> + or the key is explicitly disabled using the left-command-key option >> + */ >> case kVK_Command: >> if (isMouseGrabbed && >> - !!(modifiers & NSEventModifierFlagCommand)) { >> + !!(modifiers & NSEventModifierFlagCommand) && >> + left_command_key_enabled) { >> [self toggleKey:Q_KEY_CODE_META_L]; >> } >> break; >> @@ -923,10 +929,16 @@ QemuCocoaView *cocoaView; >> case NSEventTypeLeftMouseDown: >> buttons |= MOUSE_EVENT_LBUTTON; >> mouse_event = true; >> + if (isFullscreen) { >> + [self hideCursor]; >> + } >> break; >> case NSEventTypeRightMouseDown: >> buttons |= MOUSE_EVENT_RBUTTON; >> mouse_event = true; >> + if (isFullscreen) { >> + [self hideCursor]; >> + } >> break; >> case NSEventTypeOtherMouseDown: >> buttons |= MOUSE_EVENT_MBUTTON; >> @@ -2050,10 +2062,15 @@ 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; >> } >> + if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { >> + left_command_key_enabled = 0; >> + } >> + >> // register vga output callbacks >> register_displaychangelistener(&dcl); >> > All the fullscreen stuff could be put into its own patch. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] ui/cocoa: Add option to disable left command and hide cursor on click 2021-12-31 17:42 ` [PATCH 1/1] " Carwyn Ellis 2021-12-31 17:49 ` Alexander Orzechowski @ 2021-12-31 17:56 ` Alexander Orzechowski 2021-12-31 17:57 ` Carwyn Ellis 1 sibling, 1 reply; 7+ messages in thread From: Alexander Orzechowski @ 2021-12-31 17:56 UTC (permalink / raw) To: Carwyn Ellis; +Cc: qemu trivial, QEMU On 12/31/21 12:42, Carwyn Ellis wrote: > When switching between guest and host on a Mac using command-tab the > command key is sent to the guest which can trigger functionality in the > guest OS. Specifying left-command-key=off disables forwarding this key > to the guest. Defaults to enabled. > > When switching between guest and host on a Mac with a fullscreen guest > the host pointer will occasionally persist despite the ui code > requesting that it be hidden. Added cursor hide calls on left and right > mouse click to hide the cursor when the mouse is clicked. > > Also updated the cocoa display documentation to reference the new > left-command-key option along with the existing show-cursor option. > --- > qapi/ui.json | 17 +++++++++++++++++ > qemu-options.hx | 12 ++++++++++++ > ui/cocoa.m | 33 +++++++++++++++++++++++++-------- > 3 files changed, 54 insertions(+), 8 deletions(-) > > diff --git a/qapi/ui.json b/qapi/ui.json > index 2b4371da37..764480e145 100644 > --- a/qapi/ui.json > +++ b/qapi/ui.json > @@ -1107,6 +1107,22 @@ > 'data' : { '*grab-on-hover' : 'bool', > '*zoom-to-fit' : 'bool' } } > > +## > +# @DisplayCocoa: > +# > +# Cocoa display options. > +# > +# @left-command-key: Enable/disable forwarding of left command key to > +# guest. Allows command-tab window switching on the > +# host without sending this key to the guest when > +# "off". Defaults to "on" > +# > +# Since: 6.2.50 > +# > +## > +{ 'struct' : 'DisplayCocoa', > + 'data' : { '*left-command-key' : 'bool' } } > + > ## > # @DisplayEGLHeadless: > # > @@ -1254,6 +1270,7 @@ > 'discriminator' : 'type', > 'data' : { > 'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' }, > + 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, > 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, > 'egl-headless': { 'type': 'DisplayEGLHeadless', > 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, > diff --git a/qemu-options.hx b/qemu-options.hx > index 7d47510947..5214457676 100644 > --- a/qemu-options.hx > +++ b/qemu-options.hx > @@ -1869,6 +1869,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, > #if defined(CONFIG_DBUS_DISPLAY) > "-display dbus[,addr=<dbusaddr>]\n" > " [,gl=on|core|es|off][,rendernode=<file>]\n" > +#endif > +#if defined(CONFIG_COCOA) > + "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n" > #endif > "-display none\n" > " select display backend type\n" > @@ -1956,6 +1959,15 @@ SRST > ``charset=CP850`` for IBM CP850 encoding. The default is > ``CP437``. > > + ``cocoa`` > + Display video output in a Cocoa window. Mac only. This interface > + provides drop-down menus and other UI elements to configure and > + control the VM during runtime. Valid parameters are: > + > + ``show-cursor=on|off`` : Force showing the mouse cursor > + > + ``left-command-key=on|off`` : Disable forwarding left command key to host > + > ``egl-headless[,rendernode=<file>]`` > Offload all OpenGL operations to a local DRI device. For any > graphical display, this display needs to be paired with either > diff --git a/ui/cocoa.m b/ui/cocoa.m > index 69745c483b..10e492538a 100644 > --- a/ui/cocoa.m > +++ b/ui/cocoa.m > @@ -95,6 +95,8 @@ static DisplayChangeListener dcl = { > }; > static int last_buttons; > static int cursor_hide = 1; > +static bool cursor_visible = 1; > +static int left_command_key_enabled = 1; > > static int gArgc; > static char **gArgv; > @@ -411,18 +413,18 @@ QemuCocoaView *cocoaView; > > - (void) hideCursor > { > - if (!cursor_hide) { > - return; > + if (cursor_hide && cursor_visible) { > + cursor_visible = 0; > + [NSCursor hide]; > } > - [NSCursor hide]; > } > > - (void) unhideCursor > { > - if (!cursor_hide) { > - return; > + if (cursor_hide && !cursor_visible) { > + cursor_visible = 1; > + [NSCursor unhide]; > } > - [NSCursor unhide]; > } > > - (void) drawRect:(NSRect) rect > @@ -831,10 +833,14 @@ QemuCocoaView *cocoaView; > } > break; > > - /* Don't pass command key changes to guest unless mouse is grabbed */ > + /* > + Don't pass command key changes to guest unless mouse is grabbed > + or the key is explicitly disabled using the left-command-key option > + */ > case kVK_Command: > if (isMouseGrabbed && > - !!(modifiers & NSEventModifierFlagCommand)) { > + !!(modifiers & NSEventModifierFlagCommand) && > + left_command_key_enabled) { > [self toggleKey:Q_KEY_CODE_META_L]; > } > break; > @@ -923,10 +929,16 @@ QemuCocoaView *cocoaView; > case NSEventTypeLeftMouseDown: > buttons |= MOUSE_EVENT_LBUTTON; > mouse_event = true; > + if (isFullscreen) { > + [self hideCursor]; > + } > break; > case NSEventTypeRightMouseDown: > buttons |= MOUSE_EVENT_RBUTTON; > mouse_event = true; > + if (isFullscreen) { > + [self hideCursor]; > + } > break; > case NSEventTypeOtherMouseDown: > buttons |= MOUSE_EVENT_MBUTTON; > @@ -2050,10 +2062,15 @@ 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; > } > > + if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { > + left_command_key_enabled = 0; > + } > + > // register vga output callbacks > register_displaychangelistener(&dcl); > You also forgot about the sign off. git commit with a -s switch will append the appropriate sign off message. All patches need to be signed off so we know you are okay with them going upstream. ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/1] ui/cocoa: Add option to disable left command and hide cursor on click 2021-12-31 17:56 ` Alexander Orzechowski @ 2021-12-31 17:57 ` Carwyn Ellis 0 siblings, 0 replies; 7+ messages in thread From: Carwyn Ellis @ 2021-12-31 17:57 UTC (permalink / raw) To: Alexander Orzechowski; +Cc: qemu trivial, QEMU > On 31 Dec 2021, at 17:56, Alexander Orzechowski <orzechowski.alexander@gmail.com> wrote: > > > On 12/31/21 12:42, Carwyn Ellis wrote: >> When switching between guest and host on a Mac using command-tab the >> command key is sent to the guest which can trigger functionality in the >> guest OS. Specifying left-command-key=off disables forwarding this key >> to the guest. Defaults to enabled. >> >> When switching between guest and host on a Mac with a fullscreen guest >> the host pointer will occasionally persist despite the ui code >> requesting that it be hidden. Added cursor hide calls on left and right >> mouse click to hide the cursor when the mouse is clicked. >> >> Also updated the cocoa display documentation to reference the new >> left-command-key option along with the existing show-cursor option. >> --- >> qapi/ui.json | 17 +++++++++++++++++ >> qemu-options.hx | 12 ++++++++++++ >> ui/cocoa.m | 33 +++++++++++++++++++++++++-------- >> 3 files changed, 54 insertions(+), 8 deletions(-) >> >> diff --git a/qapi/ui.json b/qapi/ui.json >> index 2b4371da37..764480e145 100644 >> --- a/qapi/ui.json >> +++ b/qapi/ui.json >> @@ -1107,6 +1107,22 @@ >> 'data' : { '*grab-on-hover' : 'bool', >> '*zoom-to-fit' : 'bool' } } >> +## >> +# @DisplayCocoa: >> +# >> +# Cocoa display options. >> +# >> +# @left-command-key: Enable/disable forwarding of left command key to >> +# guest. Allows command-tab window switching on the >> +# host without sending this key to the guest when >> +# "off". Defaults to "on" >> +# >> +# Since: 6.2.50 >> +# >> +## >> +{ 'struct' : 'DisplayCocoa', >> + 'data' : { '*left-command-key' : 'bool' } } >> + >> ## >> # @DisplayEGLHeadless: >> # >> @@ -1254,6 +1270,7 @@ >> 'discriminator' : 'type', >> 'data' : { >> 'gtk': { 'type': 'DisplayGTK', 'if': 'CONFIG_GTK' }, >> + 'cocoa': { 'type': 'DisplayCocoa', 'if': 'CONFIG_COCOA' }, >> 'curses': { 'type': 'DisplayCurses', 'if': 'CONFIG_CURSES' }, >> 'egl-headless': { 'type': 'DisplayEGLHeadless', >> 'if': { 'all': ['CONFIG_OPENGL', 'CONFIG_GBM'] } }, >> diff --git a/qemu-options.hx b/qemu-options.hx >> index 7d47510947..5214457676 100644 >> --- a/qemu-options.hx >> +++ b/qemu-options.hx >> @@ -1869,6 +1869,9 @@ DEF("display", HAS_ARG, QEMU_OPTION_display, >> #if defined(CONFIG_DBUS_DISPLAY) >> "-display dbus[,addr=<dbusaddr>]\n" >> " [,gl=on|core|es|off][,rendernode=<file>]\n" >> +#endif >> +#if defined(CONFIG_COCOA) >> + "-display cocoa[,show-cursor=on|off][,left-command-key=on|off]\n" >> #endif >> "-display none\n" >> " select display backend type\n" >> @@ -1956,6 +1959,15 @@ SRST >> ``charset=CP850`` for IBM CP850 encoding. The default is >> ``CP437``. >> + ``cocoa`` >> + Display video output in a Cocoa window. Mac only. This interface >> + provides drop-down menus and other UI elements to configure and >> + control the VM during runtime. Valid parameters are: >> + >> + ``show-cursor=on|off`` : Force showing the mouse cursor >> + >> + ``left-command-key=on|off`` : Disable forwarding left command key to host >> + >> ``egl-headless[,rendernode=<file>]`` >> Offload all OpenGL operations to a local DRI device. For any >> graphical display, this display needs to be paired with either >> diff --git a/ui/cocoa.m b/ui/cocoa.m >> index 69745c483b..10e492538a 100644 >> --- a/ui/cocoa.m >> +++ b/ui/cocoa.m >> @@ -95,6 +95,8 @@ static DisplayChangeListener dcl = { >> }; >> static int last_buttons; >> static int cursor_hide = 1; >> +static bool cursor_visible = 1; >> +static int left_command_key_enabled = 1; >> static int gArgc; >> static char **gArgv; >> @@ -411,18 +413,18 @@ QemuCocoaView *cocoaView; >> - (void) hideCursor >> { >> - if (!cursor_hide) { >> - return; >> + if (cursor_hide && cursor_visible) { >> + cursor_visible = 0; >> + [NSCursor hide]; >> } >> - [NSCursor hide]; >> } >> - (void) unhideCursor >> { >> - if (!cursor_hide) { >> - return; >> + if (cursor_hide && !cursor_visible) { >> + cursor_visible = 1; >> + [NSCursor unhide]; >> } >> - [NSCursor unhide]; >> } >> - (void) drawRect:(NSRect) rect >> @@ -831,10 +833,14 @@ QemuCocoaView *cocoaView; >> } >> break; >> - /* Don't pass command key changes to guest unless mouse is grabbed */ >> + /* >> + Don't pass command key changes to guest unless mouse is grabbed >> + or the key is explicitly disabled using the left-command-key option >> + */ >> case kVK_Command: >> if (isMouseGrabbed && >> - !!(modifiers & NSEventModifierFlagCommand)) { >> + !!(modifiers & NSEventModifierFlagCommand) && >> + left_command_key_enabled) { >> [self toggleKey:Q_KEY_CODE_META_L]; >> } >> break; >> @@ -923,10 +929,16 @@ QemuCocoaView *cocoaView; >> case NSEventTypeLeftMouseDown: >> buttons |= MOUSE_EVENT_LBUTTON; >> mouse_event = true; >> + if (isFullscreen) { >> + [self hideCursor]; >> + } >> break; >> case NSEventTypeRightMouseDown: >> buttons |= MOUSE_EVENT_RBUTTON; >> mouse_event = true; >> + if (isFullscreen) { >> + [self hideCursor]; >> + } >> break; >> case NSEventTypeOtherMouseDown: >> buttons |= MOUSE_EVENT_MBUTTON; >> @@ -2050,10 +2062,15 @@ 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; >> } >> + if (opts->u.cocoa.has_left_command_key && !opts->u.cocoa.left_command_key) { >> + left_command_key_enabled = 0; >> + } >> + >> // register vga output callbacks >> register_displaychangelistener(&dcl); >> > > You also forgot about the sign off. git commit with a -s switch will append the appropriate sign off message. > > All patches need to be signed off so we know you are okay with them going upstream. > Good point! Will make sure that’s in on the next set of patches. ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 0/1] ui/cocoa: Add option to disable left command and hide cursor on click @ 2021-12-31 11:30 Carwyn Ellis 0 siblings, 0 replies; 7+ messages in thread From: Carwyn Ellis @ 2021-12-31 11:30 UTC (permalink / raw) To: qemu-devel; +Cc: qemu-trivial, peter.maydell, Carwyn Ellis Having made the switch to an M1 Mac I needed to switch from VMware back to QEMU in order to run some intel guests. This patch addresses a couple of niggles with the cocoa UI, namely: - Using command-tab to switch between the guest OS and MacOS sends the command keypress to the guest which can be annoying e.g. on a windows guest this may trigger the start menu - Switching between the guest and MacOS sometimes leaves the MacOS mouse cursor visible with no way to hide it without switching windows again To address these issues I've made the following changes - Added a new cocoa display option left-command-key which can be used to disable the left command key in the guest. Default is on. - Added a call to hideCursor on left and right mouse clicks so if the cursor is visible after switching back to the guest a mouse click will hide the cursor again. - Also updated the command line docs to reference the show-cursor option which is also respected by the cocoa UI code. Carwyn Ellis (1): ui/cocoa: Add option to disable left command and hide cursor on click qapi/ui.json | 17 +++++++++++++++++ qemu-options.hx | 12 ++++++++++++ ui/cocoa.m | 16 ++++++++++++++-- 3 files changed, 43 insertions(+), 2 deletions(-) -- 2.34.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2021-12-31 17:58 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2021-12-31 17:42 [PATCH 0/1] ui/cocoa: Add option to disable left command and hide cursor on click Carwyn Ellis 2021-12-31 17:42 ` [PATCH 1/1] " Carwyn Ellis 2021-12-31 17:49 ` Alexander Orzechowski 2021-12-31 17:52 ` Carwyn Ellis 2021-12-31 17:56 ` Alexander Orzechowski 2021-12-31 17:57 ` Carwyn Ellis -- strict thread matches above, loose matches on Subject: below -- 2021-12-31 11:30 [PATCH 0/1] " Carwyn Ellis
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).