diff mbox series

[v2,1/1] ui/cocoa: add zoom-to-fit display option

Message ID 20231027150942.72357-2-carwynellis@gmail.com (mailing list archive)
State New, archived
Headers show
Series ui/cocoa: add zoom-to-fit display option | expand

Commit Message

Carwyn Ellis Oct. 27, 2023, 3:09 p.m. UTC
From: Carwyn Ellis <carwynellis@gmail.com>

Provides a display option, zoom-to-fit, that enables scaling of the
display when full-screen mode is enabled.

Also ensures that the corresponding menu item is marked as enabled when
the option is set to on.

Signed-off-by: Carwyn Ellis <carwynellis@gmail.com>
---
 qapi/ui.json |  8 ++++++--
 ui/cocoa.m   | 35 ++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 17 deletions(-)

Comments

Akihiko Odaki Oct. 27, 2023, 3:24 p.m. UTC | #1
On 2023/10/28 0:09, carwynellis@gmail.com wrote:
> From: Carwyn Ellis <carwynellis@gmail.com>
> 
> Provides a display option, zoom-to-fit, that enables scaling of the
> display when full-screen mode is enabled.
> 
> Also ensures that the corresponding menu item is marked as enabled when
> the option is set to on.
> 
> Signed-off-by: Carwyn Ellis <carwynellis@gmail.com>
> ---
>   qapi/ui.json |  8 ++++++--
>   ui/cocoa.m   | 35 ++++++++++++++++++++---------------
>   2 files changed, 26 insertions(+), 17 deletions(-)
> 
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 006616aa77..fd12791ff9 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1409,13 +1409,17 @@
>   #     codes match their position on non-Mac keyboards and you can use
>   #     Meta/Super and Alt where you expect them.  (default: off)
>   #
> -# Since: 7.0
> +# @zoom-to-fit: Scale display to fit when full-screen enabled.
> +#     Defaults to "off".
> +#
> +# Since: 8.2

I don't think this new option will affect only when full-screen enabled, 
but probably it will affect also in a windowed mode. Perhaps you can 
just copy the description for DisplayGTK except the statement regarding 
virtio-gpu.

Also don't replace "Since: 7.0". It denotes the version that introduced 
the structure, not an individual member.

>   ##
>   { 'struct': 'DisplayCocoa',
>     'data': {
>         '*left-command-key': 'bool',
>         '*full-grab': 'bool',
> -      '*swap-opt-cmd': 'bool'
> +      '*swap-opt-cmd': 'bool',
> +      '*zoom-to-fit': 'bool'
>     } }
>   
>   ##
> diff --git a/ui/cocoa.m b/ui/cocoa.m
> index d95276013c..903adb85a1 100644
> --- a/ui/cocoa.m
> +++ b/ui/cocoa.m
> @@ -104,7 +104,7 @@ static void cocoa_switch(DisplayChangeListener *dcl,
>   static int left_command_key_enabled = 1;
>   static bool swap_opt_cmd;
>   
> -static bool stretch_video;
> +static bool stretch_video = false;

You don't need to assign false here. C initializes it as false by default.
Carwyn Ellis Oct. 27, 2023, 3:31 p.m. UTC | #2
> On 27 Oct 2023, at 16:24, Akihiko Odaki <akihiko.odaki@daynix.com> wrote:
> 
> On 2023/10/28 0:09, carwynellis@gmail.com wrote:
>> From: Carwyn Ellis <carwynellis@gmail.com>
>> Provides a display option, zoom-to-fit, that enables scaling of the
>> display when full-screen mode is enabled.
>> Also ensures that the corresponding menu item is marked as enabled when
>> the option is set to on.
>> Signed-off-by: Carwyn Ellis <carwynellis@gmail.com>
>> ---
>>  qapi/ui.json |  8 ++++++--
>>  ui/cocoa.m   | 35 ++++++++++++++++++++---------------
>>  2 files changed, 26 insertions(+), 17 deletions(-)
>> diff --git a/qapi/ui.json b/qapi/ui.json
>> index 006616aa77..fd12791ff9 100644
>> --- a/qapi/ui.json
>> +++ b/qapi/ui.json
>> @@ -1409,13 +1409,17 @@
>>  #     codes match their position on non-Mac keyboards and you can use
>>  #     Meta/Super and Alt where you expect them.  (default: off)
>>  #
>> -# Since: 7.0
>> +# @zoom-to-fit: Scale display to fit when full-screen enabled.
>> +#     Defaults to "off".
>> +#
>> +# Since: 8.2
> 
> I don't think this new option will affect only when full-screen enabled, but probably it will affect also in a windowed mode. Perhaps you can just copy the description for DisplayGTK except the statement regarding virtio-gpu.

Ok.

> 
> Also don't replace "Since: 7.0". It denotes the version that introduced the structure, not an individual member.

Ok, I’ll flip it back to 7.0.

> 
>>  ##
>>  { 'struct': 'DisplayCocoa',
>>    'data': {
>>        '*left-command-key': 'bool',
>>        '*full-grab': 'bool',
>> -      '*swap-opt-cmd': 'bool'
>> +      '*swap-opt-cmd': 'bool',
>> +      '*zoom-to-fit': 'bool'
>>    } }
>>    ##
>> diff --git a/ui/cocoa.m b/ui/cocoa.m
>> index d95276013c..903adb85a1 100644
>> --- a/ui/cocoa.m
>> +++ b/ui/cocoa.m
>> @@ -104,7 +104,7 @@ static void cocoa_switch(DisplayChangeListener *dcl,
>>  static int left_command_key_enabled = 1;
>>  static bool swap_opt_cmd;
>>  -static bool stretch_video;
>> +static bool stretch_video = false;
> 
> You don't need to assign false here. C initializes it as false by default.

Ahh of course.

Thanks again for getting back to me so quickly! :)
diff mbox series

Patch

diff --git a/qapi/ui.json b/qapi/ui.json
index 006616aa77..fd12791ff9 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1409,13 +1409,17 @@ 
 #     codes match their position on non-Mac keyboards and you can use
 #     Meta/Super and Alt where you expect them.  (default: off)
 #
-# Since: 7.0
+# @zoom-to-fit: Scale display to fit when full-screen enabled.
+#     Defaults to "off".
+#
+# Since: 8.2
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
       '*left-command-key': 'bool',
       '*full-grab': 'bool',
-      '*swap-opt-cmd': 'bool'
+      '*swap-opt-cmd': 'bool',
+      '*zoom-to-fit': 'bool'
   } }
 
 ##
diff --git a/ui/cocoa.m b/ui/cocoa.m
index d95276013c..903adb85a1 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -104,7 +104,7 @@  static void cocoa_switch(DisplayChangeListener *dcl,
 static int left_command_key_enabled = 1;
 static bool swap_opt_cmd;
 
-static bool stretch_video;
+static bool stretch_video = false;
 static NSTextField *pauseLabel;
 
 static bool allow_events;
@@ -1247,7 +1247,6 @@  - (id) init
         [normalWindow makeKeyAndOrderFront:self];
         [normalWindow center];
         [normalWindow setDelegate: self];
-        stretch_video = false;
 
         /* Used for displaying pause on the screen */
         pauseLabel = [NSTextField new];
@@ -1671,7 +1670,9 @@  static void create_initial_menus(void)
     // View menu
     menu = [[NSMenu alloc] initWithTitle:@"View"];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(doToggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
-    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease]];
+    menuItem = [[[NSMenuItem alloc] initWithTitle:@"Zoom To Fit" action:@selector(zoomToFit:) keyEquivalent:@""] autorelease];
+    [menuItem setState: stretch_video ? NSControlStateValueOn : NSControlStateValueOff];
+    [menu addItem: menuItem];
     menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
     [menuItem setSubmenu:menu];
     [[NSApp mainMenu] addItem:menuItem];
@@ -2041,18 +2042,6 @@  static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
 
     [QemuApplication sharedApplication];
 
-    create_initial_menus();
-
-    /*
-     * Create the menu entries which depend on QEMU state (for consoles
-     * and removable devices). These make calls back into QEMU functions,
-     * which is OK because at this point we know that the second thread
-     * holds the iothread lock and is synchronously waiting for us to
-     * finish.
-     */
-    add_console_menu_entries();
-    addRemovableDevicesMenuItems();
-
     // Create an Application controller
     QemuCocoaAppController *controller = [[QemuCocoaAppController alloc] init];
     [NSApp setDelegate:controller];
@@ -2077,6 +2066,22 @@  static void cocoa_display_init(DisplayState *ds, DisplayOptions *opts)
         left_command_key_enabled = 0;
     }
 
+    if (opts->u.cocoa.has_zoom_to_fit && opts->u.cocoa.zoom_to_fit) {
+        stretch_video = true;
+    }
+
+    create_initial_menus();
+    /*
+     * Create the menu entries which depend on QEMU state (for consoles
+     * and removable devices). These make calls back into QEMU functions,
+     * which is OK because at this point we know that the second thread
+     * holds the iothread lock and is synchronously waiting for us to
+     * finish.
+     */
+    add_console_menu_entries();
+    addRemovableDevicesMenuItems();
+
     // register vga output callbacks
     register_displaychangelistener(&dcl);
 
-- 
2.42.0