diff mbox

[v5] ui/cocoa.m: Adds console items to the View menu

Message ID 30C61AFC-7A08-4F94-A7B1-0DAAA58DC017@gmail.com
State New
Headers show

Commit Message

Programmingkid May 11, 2015, 3:18 p.m. UTC
Adds any console that is available to the current emulator as a menu item under the View menu.

Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

---
Removed the initConsoleVariables() function.
Removed global variables.
Rewrote how console menu items are added.

 ui/cocoa.m |   50 ++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 42 insertions(+), 8 deletions(-)

Comments

Peter Maydell May 16, 2015, 9:45 p.m. UTC | #1
On 11 May 2015 at 16:18, Programmingkid <programmingkidx@gmail.com> wrote:
> Adds any console that is available to the current emulator as a menu item under the View menu.
>
> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>

Thanks; I think this version looks pretty good. A minor
improvement:

> +static void create_view_menu()
> +{
> +    NSMenu * menu;
> +    NSMenuItem * menuItem;
> +    int index = 0;
> +
> +    menu = [[NSMenu alloc] initWithTitle:@"View"];
> +    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
> +    [menu addItem:[NSMenuItem separatorItem]]; //Separator
> +
> +    // Give each console its own menu item in the View menu
> +    while(qemu_console_lookup_by_index(index) != NULL) {
> +        menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
> +                                               action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
> +        [menuItem setTag: index];
> +        [menu addItem: menuItem];
> +        index++;
> +    }
> +
> +    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
> +    [menuItem setSubmenu:menu];
> +    [[NSApp mainMenu] insertItem: menuItem atIndex: 1]; // insert View menu after Application menu
> +}

Rather than creating the whole menu here, and then having to
use awkward hard-coded indexes to decide where to put it in
the menubar, I think it would be nicer to leave the creation
of the menu (and its fixed entries) where it is and just do
the addition of new items here. You can get the View menu with:

    menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];

and then just [menu addItem ... ] the new items to it.

I also had to tweak the patch a bit to get it to apply on top
of the fullscreen patches, so I went ahead and made that
change, and applied the resulting patch to my cocoa.next
branch in
https://git.linaro.org/people/peter.maydell/qemu-arm.git

Let me know if you'd rather do something else.

thanks
-- PMM
Programmingkid May 17, 2015, 8:09 p.m. UTC | #2
On May 16, 2015, at 5:45 PM, Peter Maydell wrote:

> On 11 May 2015 at 16:18, Programmingkid <programmingkidx@gmail.com> wrote:
>> Adds any console that is available to the current emulator as a menu item under the View menu.
>> 
>> Signed-off-by: John Arbuckle <programmingkidx@gmail.com>
> 
> Thanks; I think this version looks pretty good. A minor
> improvement:
> 
>> +static void create_view_menu()
>> +{
>> +    NSMenu * menu;
>> +    NSMenuItem * menuItem;
>> +    int index = 0;
>> +
>> +    menu = [[NSMenu alloc] initWithTitle:@"View"];
>> +    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
>> +    [menu addItem:[NSMenuItem separatorItem]]; //Separator
>> +
>> +    // Give each console its own menu item in the View menu
>> +    while(qemu_console_lookup_by_index(index) != NULL) {
>> +        menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
>> +                                               action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
>> +        [menuItem setTag: index];
>> +        [menu addItem: menuItem];
>> +        index++;
>> +    }
>> +
>> +    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
>> +    [menuItem setSubmenu:menu];
>> +    [[NSApp mainMenu] insertItem: menuItem atIndex: 1]; // insert View menu after Application menu
>> +}
> 
> Rather than creating the whole menu here, and then having to
> use awkward hard-coded indexes to decide where to put it in
> the menubar, I think it would be nicer to leave the creation
> of the menu (and its fixed entries) where it is and just do
> the addition of new items here. You can get the View menu with:
> 
>    menu = [[[NSApp mainMenu] itemWithTitle:@"View"] submenu];
> 
> and then just [menu addItem ... ] the new items to it.
> 
> I also had to tweak the patch a bit to get it to apply on top
> of the fullscreen patches, so I went ahead and made that
> change, and applied the resulting patch to my cocoa.next
> branch in
> https://git.linaro.org/people/peter.maydell/qemu-arm.git
> 
> Let me know if you'd rather do something else.
> 
> thanks
> -- PMM

What you did looks good. 

You know how there's a "Zoom To Fit" menu item. What if we added a mutually exclusive menu item called "Resize To Fit"? This menu item would instead adjust the host screen's resolution to match that of the guest screen's resolution. It can be implemented in its own patch if you like the idea.
Peter Maydell May 17, 2015, 9:37 p.m. UTC | #3
On 17 May 2015 at 21:09, Programmingkid <programmingkidx@gmail.com> wrote:
> You know how there's a "Zoom To Fit" menu item. What if we added a
> mutually exclusive menu item called "Resize To Fit"? This menu item
> would instead adjust the host screen's resolution to match that of the
> guest screen's resolution. It can be implemented in its own patch if
> you like the idea.

Do any other VM/emulator type programs for OSX do that? It sounds
rather odd -- wouldn't we run into the same "changing resolution
makes OSX move all your other windows around" problems we had with
an earlier version of the fullscreen patches?

-- PMM
Programmingkid May 17, 2015, 9:55 p.m. UTC | #4
On May 17, 2015, at 5:37 PM, Peter Maydell wrote:

> On 17 May 2015 at 21:09, Programmingkid <programmingkidx@gmail.com> wrote:
>> You know how there's a "Zoom To Fit" menu item. What if we added a
>> mutually exclusive menu item called "Resize To Fit"? This menu item
>> would instead adjust the host screen's resolution to match that of the
>> guest screen's resolution. It can be implemented in its own patch if
>> you like the idea.
> 
> Do any other VM/emulator type programs for OSX do that?
Connectix Virtual PC 3.

> It sounds
> rather odd -- wouldn't we run into the same "changing resolution
> makes OSX move all your other windows around" problems we had with
> an earlier version of the fullscreen patches?
It would cause those problems, but shouldn't the user decide what is and
isn't acceptable? Some users might like the convenience of having QEMU do
all the work to make the screen look good.

I think SDL solved this problem some how. I was using a fullscreen program that used
SDL and it managed to change the resolution without messing up all the windows. So
I think there is a way to solve this problem. Maybe someone out there might be willing 
to share...
Peter Maydell May 17, 2015, 10 p.m. UTC | #5
On 17 May 2015 at 22:55, Programmingkid <programmingkidx@gmail.com> wrote:
> I think SDL solved this problem some how. I was using a fullscreen program that used
> SDL and it managed to change the resolution without messing up all the windows. So
> I think there is a way to solve this problem. Maybe someone out there might be willing
> to share...

Parallels also manages to let the guest work in non-standard resolutions
without messing up the main screen resolution/window placement, so
yeah, it ought to be possible. I have no idea how, though.

-- PMM
diff mbox

Patch

diff --git a/ui/cocoa.m b/ui/cocoa.m
index d37c29b..b4b7adb 100644
--- a/ui/cocoa.m
+++ b/ui/cocoa.m
@@ -801,6 +801,7 @@  QemuCocoaView *cocoaView;
 - (void)toggleFullScreen:(id)sender;
 - (void)showQEMUDoc:(id)sender;
 - (void)showQEMUTec:(id)sender;
+- (void)displayConsole:(id)sender;
 @end
 
 @implementation QemuCocoaAppController
@@ -943,8 +944,14 @@  QemuCocoaView *cocoaView;
     [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
         [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
 }
-@end
 
+/* Displays the console on the screen */
+- (void)displayConsole:(id)sender
+{
+    console_select([sender tag]);
+}
+
+@end
 
 
 int main (int argc, const char * argv[]) {
@@ -1003,13 +1010,6 @@  int main (int argc, const char * argv[]) {
     [[NSApp mainMenu] addItem:menuItem];
     [NSApp performSelector:@selector(setAppleMenu:) withObject:menu]; // Workaround (this method is private since 10.4+)
 
-    // View menu
-    menu = [[NSMenu alloc] initWithTitle:@"View"];
-    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
-    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
-    [menuItem setSubmenu:menu];
-    [[NSApp mainMenu] addItem:menuItem];
-
     // Window menu
     menu = [[NSMenu alloc] initWithTitle:@"Window"];
     [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Minimize" action:@selector(performMiniaturize:) keyEquivalent:@"m"] autorelease]]; // Miniaturize
@@ -1116,6 +1116,37 @@  static const DisplayChangeListenerOps dcl_ops = {
     .dpy_refresh = cocoa_refresh,
 };
 
+// Returns a name for a given console
+static NSString * getConsoleName(QemuConsole * console)
+{
+    return [NSString stringWithFormat: @"%s", qemu_console_get_label(console)];
+}
+
+// Creates the view menu
+static void create_view_menu()
+{
+    NSMenu * menu;
+    NSMenuItem * menuItem;
+    int index = 0;
+
+    menu = [[NSMenu alloc] initWithTitle:@"View"];
+    [menu addItem: [[[NSMenuItem alloc] initWithTitle:@"Enter Fullscreen" action:@selector(toggleFullScreen:) keyEquivalent:@"f"] autorelease]]; // Fullscreen
+    [menu addItem:[NSMenuItem separatorItem]]; //Separator
+
+    // Give each console its own menu item in the View menu
+    while(qemu_console_lookup_by_index(index) != NULL) {
+        menuItem = [[[NSMenuItem alloc] initWithTitle: getConsoleName(qemu_console_lookup_by_index(index))
+                                               action: @selector(displayConsole:) keyEquivalent: @""] autorelease];
+        [menuItem setTag: index];
+        [menu addItem: menuItem];
+        index++;
+    }
+
+    menuItem = [[[NSMenuItem alloc] initWithTitle:@"View" action:nil keyEquivalent:@""] autorelease];
+    [menuItem setSubmenu:menu];
+    [[NSApp mainMenu] insertItem: menuItem atIndex: 1]; // insert View menu after Application menu
+}
+
 void cocoa_display_init(DisplayState *ds, int full_screen)
 {
     COCOA_DEBUG("qemu_cocoa: cocoa_display_init\n");
@@ -1128,4 +1159,7 @@  void cocoa_display_init(DisplayState *ds, int full_screen)
 
     // register cleanup function
     atexit(cocoa_cleanup);
+
+    // QEMU needs to be running first before we can create the view menu
+    create_view_menu();
 }