All of lore.kernel.org
 help / color / mirror / Atom feed
* [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
@ 2015-05-11 15:18 Programmingkid
  2015-05-16 21:45 ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Programmingkid @ 2015-05-11 15:18 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel

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(-)

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();
 }
-- 
1.7.5.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
  2015-05-11 15:18 [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu Programmingkid
@ 2015-05-16 21:45 ` Peter Maydell
  2015-05-17 20:09   ` Programmingkid
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2015-05-16 21:45 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel qemu-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
  2015-05-16 21:45 ` Peter Maydell
@ 2015-05-17 20:09   ` Programmingkid
  2015-05-17 21:37     ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Programmingkid @ 2015-05-17 20:09 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel


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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
  2015-05-17 20:09   ` Programmingkid
@ 2015-05-17 21:37     ` Peter Maydell
  2015-05-17 21:55       ` Programmingkid
  0 siblings, 1 reply; 6+ messages in thread
From: Peter Maydell @ 2015-05-17 21:37 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel qemu-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
  2015-05-17 21:37     ` Peter Maydell
@ 2015-05-17 21:55       ` Programmingkid
  2015-05-17 22:00         ` Peter Maydell
  0 siblings, 1 reply; 6+ messages in thread
From: Programmingkid @ 2015-05-17 21:55 UTC (permalink / raw)
  To: Peter Maydell; +Cc: qemu-devel qemu-devel


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...

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu
  2015-05-17 21:55       ` Programmingkid
@ 2015-05-17 22:00         ` Peter Maydell
  0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2015-05-17 22:00 UTC (permalink / raw)
  To: Programmingkid; +Cc: qemu-devel qemu-devel

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2015-05-17 22:01 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-11 15:18 [Qemu-devel] [patch v5] ui/cocoa.m: Adds console items to the View menu Programmingkid
2015-05-16 21:45 ` Peter Maydell
2015-05-17 20:09   ` Programmingkid
2015-05-17 21:37     ` Peter Maydell
2015-05-17 21:55       ` Programmingkid
2015-05-17 22:00         ` Peter Maydell

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.