Skip to contentSkip to conversation

ui/cocoa: add zoom-to-fit display option

PATCH Superseded [email protected] 2 participants 4 messages Oct 27, 2023

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover ui/cocoa: add zoom-to-fit display option

From: Carwyn Ellis <[email protected]>

The intention here is to allow fullscreen scaling of the display to be enabled by setting the display option zoom-to-fit to on, allowing this to be set from the command line without having to interact with the ui menu.

Includes changes requested by Akihiko Odaki.

Carwyn Ellis (1):
ui/cocoa: add zoom-to-fit display option

 qapi/ui.json |  8 ++++++--
 ui/cocoa.m   | 35 ++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 17 deletions(-)
Signature · 1 line
2.42.0
#1 lore raw

PATCH v2 1/1 ui/cocoa: add zoom-to-fit display option

From: Carwyn Ellis <[email protected]>

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.

---
 qapi/ui.json |  8 ++++++--
 ui/cocoa.m   | 35 ++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 17 deletions(-)
qapi/ui.json +6 -2
index 006616aa77..fd12791ff9 100644
@@ -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'
   } }
 
 ##
ui/cocoa.m +19 -15
index d95276013c..903adb85a1 100644
@@ -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);
 
Signature · 1 line
2.42.0
#2 lore raw
Quoted 19 lines · On 2023/10/28 0:09, [email protected] wrote:

From: Carwyn Ellis <[email protected]>

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.

---
  qapi/ui.json |  8 ++++++--
  ui/cocoa.m   | 35 ++++++++++++++++++++---------------
  2 files changed, 26 insertions(+), 17 deletions(-)
qapi/ui.json +0 -0
index 006616aa77..fd12791ff9 100644

qapi/ui.json line 1415

Quoted 8 lines
qapi/ui.json +4 -1
@@ -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.

Quoted 16 lines
qapi/ui.json +2 -1
  ##
  { 'struct': 'DisplayCocoa',
    'data': {
        '*left-command-key': 'bool',
        '*full-grab': 'bool',
-      '*swap-opt-cmd': 'bool'
+      '*swap-opt-cmd': 'bool',
+      '*zoom-to-fit': 'bool'
    } }
 
  ##
ui/cocoa.m +0 -0
index d95276013c..903adb85a1 100644

ui/cocoa.m static void cocoa_switch(DisplayChangeListener *dcl, · line 107

Quoted 5 lines
ui/cocoa.m +1 -1
@@ -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.

#3 lore raw
Quoted 22 lines · Akihiko Odaki
Quoted 17 lines · On 2023/10/28 0:09, [email protected] wrote:

From: Carwyn Ellis <[email protected]>
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.

---
 qapi/ui.json |  8 ++++++--
 ui/cocoa.m   | 35 ++++++++++++++++++++---------------
 2 files changed, 26 insertions(+), 17 deletions(-)
qapi/ui.json +0 -0
index 006616aa77..fd12791ff9 100644
@@ -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)
Quoted 8 lines

qapi/ui.json line 1415

Quoted 6 lines
qapi/ui.json +4 -1
 #
-# 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.

Quoted 2 lines

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.

Quoted 14 lines
Quoted 14 lines
qapi/ui.json +2 -1
 ##
 { 'struct': 'DisplayCocoa',
   'data': {
       '*left-command-key': 'bool',
       '*full-grab': 'bool',
-      '*swap-opt-cmd': 'bool'
+      '*swap-opt-cmd': 'bool',
+      '*zoom-to-fit': 'bool'
   } }
   ##
ui/cocoa.m +0 -1
index d95276013c..903adb85a1 100644
--- a/ui/cocoa.m
Quoted 8 lines

ui/cocoa.m static void cocoa_switch(DisplayChangeListener *dcl, · line 107

Quoted 6 lines

+++ b/ui/cocoa.m

ui/cocoa.m +1 -0
@@ -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! :)