diff mbox

[09/11] Cocoa: Shutdown when window is closed

Message ID 1260672941-9365-10-git-send-email-andreas.faerber@web.de
State New
Headers show

Commit Message

Andreas Färber Dec. 13, 2009, 2:55 a.m. UTC
The application is not very useful once the guest window is closed.
QEMU is not a document-based application; terminating it automatically
saves the user another action and resembles SDL behavior.

Signed-off-by: Andreas Färber <andreas.faerber@web.de>
Cc: Mike Kronenberg <mike.kronenberg@kronenberg.org>
Cc: Alexander Graf <alex@csgraf.de>
---
 cocoa.m |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

Comments

Juha.Riihimaki@nokia.com Dec. 14, 2009, 7:04 a.m. UTC | #1
On Dec 13, 2009, at 04:55, ext Andreas Färber wrote:

> The application is not very useful once the guest window is closed.
> QEMU is not a document-based application; terminating it automatically
> saves the user another action and resembles SDL behavior.
> 
> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
> Cc: Mike Kronenberg <mike.kronenberg@kronenberg.org>
> Cc: Alexander Graf <alex@csgraf.de>
> ---
> cocoa.m |    7 +++++++
> 1 files changed, 7 insertions(+), 0 deletions(-)
> 
> diff --git a/cocoa.m b/cocoa.m
> index 70c249b..09ed3cd 100644
> --- a/cocoa.m
> +++ b/cocoa.m
> @@ -712,6 +712,7 @@ static int cocoa_keycode_to_qemu(int keycode)
> - (void)toggleFullScreen:(id)sender;
> - (void)showQEMUDoc:(id)sender;
> - (void)showQEMUTec:(id)sender;
> +- (void)windowWillClose:(NSNotification *)notification;
> @end
> 
> @implementation QemuCocoaAppController
> @@ -737,6 +738,7 @@ static int cocoa_keycode_to_qemu(int keycode)
>             fprintf(stderr, "(cocoa) can't create window\n");
>             exit(1);
>         }
> +        [normalWindow setDelegate:self];
>         [normalWindow setAcceptsMouseMovedEvents:YES];
>         [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
>         [normalWindow setContentView:cocoaView];
> @@ -835,6 +837,11 @@ static int cocoa_keycode_to_qemu(int keycode)
>     [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
>         [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
> }
> +
> +- (void)windowWillClose:(NSNotification *)notification
> +{
> +	[NSApp terminate:self];
> +}
> @end
> 

Another way to achieve the same thing is to instead of the above changes just introduce a new method for the QemuCocoaAppController like:

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
{
    return YES;
}


Regards,
Juha
Andreas Färber Dec. 14, 2009, 9:44 p.m. UTC | #2
Hi,

Am 14.12.2009 um 08:04 schrieb <Juha.Riihimaki@nokia.com> <Juha.Riihimaki@nokia.com 
 >:

>
> On Dec 13, 2009, at 04:55, ext Andreas Färber wrote:
>
>> The application is not very useful once the guest window is closed.
>> QEMU is not a document-based application; terminating it  
>> automatically
>> saves the user another action and resembles SDL behavior.
>>
>> Signed-off-by: Andreas Färber <andreas.faerber@web.de>
>> Cc: Mike Kronenberg <mike.kronenberg@kronenberg.org>
>> Cc: Alexander Graf <alex@csgraf.de>
>> ---
>> cocoa.m |    7 +++++++
>> 1 files changed, 7 insertions(+), 0 deletions(-)
>>
>> diff --git a/cocoa.m b/cocoa.m
>> index 70c249b..09ed3cd 100644
>> --- a/cocoa.m
>> +++ b/cocoa.m

>> @@ -835,6 +837,11 @@ static int cocoa_keycode_to_qemu(int keycode)
>>    [[NSWorkspace sharedWorkspace] openFile:[NSString  
>> stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
>>        [[NSBundle mainBundle] resourcePath]] withApplication:@"Help  
>> Viewer"];
>> }
>> +
>> +- (void)windowWillClose:(NSNotification *)notification
>> +{
>> +	[NSApp terminate:self];
>> +}
>> @end
>>
>
> Another way to achieve the same thing is to instead of the above  
> changes just introduce a new method for the QemuCocoaAppController  
> like:
>
> - (BOOL)applicationShouldTerminateAfterLastWindowClosed: 
> (NSApplication *)theApplication
> {
>    return YES;
> }

That's ingenious. I had searched for something like this, but around  
NSWindow... thanks!

Any other comments? Would you like to add an SoB to the now four  
patches proposed by you?

Regards,

Andreas
diff mbox

Patch

diff --git a/cocoa.m b/cocoa.m
index 70c249b..09ed3cd 100644
--- a/cocoa.m
+++ b/cocoa.m
@@ -712,6 +712,7 @@  static int cocoa_keycode_to_qemu(int keycode)
 - (void)toggleFullScreen:(id)sender;
 - (void)showQEMUDoc:(id)sender;
 - (void)showQEMUTec:(id)sender;
+- (void)windowWillClose:(NSNotification *)notification;
 @end
 
 @implementation QemuCocoaAppController
@@ -737,6 +738,7 @@  static int cocoa_keycode_to_qemu(int keycode)
             fprintf(stderr, "(cocoa) can't create window\n");
             exit(1);
         }
+        [normalWindow setDelegate:self];
         [normalWindow setAcceptsMouseMovedEvents:YES];
         [normalWindow setTitle:[NSString stringWithFormat:@"QEMU"]];
         [normalWindow setContentView:cocoaView];
@@ -835,6 +837,11 @@  static int cocoa_keycode_to_qemu(int keycode)
     [[NSWorkspace sharedWorkspace] openFile:[NSString stringWithFormat:@"%@/../doc/qemu/qemu-tech.html",
         [[NSBundle mainBundle] resourcePath]] withApplication:@"Help Viewer"];
 }
+
+- (void)windowWillClose:(NSNotification *)notification
+{
+	[NSApp terminate:self];
+}
 @end