diff options
author | Jean Guyomarc'h <jean@guyomarch.bzh> | 2016-10-02 14:22:53 +0200 |
---|---|---|
committer | Jean Guyomarc'h <jean@guyomarch.bzh> | 2016-10-30 16:46:29 +0100 |
commit | 1f8224cc9a10b1a0e448d5e83efc9012e83a3b7d (patch) | |
tree | 974bd1ffbeb4b0aaed0968cdcf5724949e6e2260 /src | |
parent | b5fa168e96c6f11b173a4330f5b79fb75bc0d3de (diff) |
ecore_cocoa: allow to override termination sequence
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/ecore_cocoa/Ecore_Cocoa.h | 22 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa.m | 7 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa_app.h | 3 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa_app.m | 25 |
4 files changed, 55 insertions, 2 deletions
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h index a1c1e22218..b187f81e61 100644 --- a/src/lib/ecore_cocoa/Ecore_Cocoa.h +++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h | |||
@@ -81,6 +81,17 @@ typedef struct _Ecore_Cocoa_Event_Window_Unfocused Ecore_Cocoa_Event_Window_Unfo | |||
81 | typedef struct _Ecore_Cocoa_Event_Window_Destroy Ecore_Cocoa_Event_Window_Destroy; | 81 | typedef struct _Ecore_Cocoa_Event_Window_Destroy Ecore_Cocoa_Event_Window_Destroy; |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * @typedef Ecore_Cocoa_Terminate_Cb | ||
85 | * Callback called when a delete request is sent to the application. | ||
86 | * Such function must return EINA_TRUE for the application to terminate, | ||
87 | * and EINA_FALSE to ignore application termination. | ||
88 | * It is typically called by a CMD+Q signal. | ||
89 | * @param sender The NSApplication instance to be terminated | ||
90 | * @since 1.19 | ||
91 | */ | ||
92 | typedef Eina_Bool (*Ecore_Cocoa_Terminate_Cb)(Ecore_Cocoa_Object *sender); | ||
93 | |||
94 | /** | ||
84 | * @typedef Ecore_Cocoa_Cursor | 95 | * @typedef Ecore_Cocoa_Cursor |
85 | * Values of the Cocoa cursors handled by Ecore_Cocoa | 96 | * Values of the Cocoa cursors handled by Ecore_Cocoa |
86 | * See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/index.html for images of each cursors. | 97 | * See https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSCursor_Class/index.html for images of each cursors. |
@@ -527,6 +538,17 @@ EAPI void ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win, | |||
527 | EAPI void ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win, Eina_Bool show); | 538 | EAPI void ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win, Eina_Bool show); |
528 | EINA_ARG_NONNULL(1); | 539 | EINA_ARG_NONNULL(1); |
529 | 540 | ||
541 | /** | ||
542 | * Overrides the default behaviour in response to an application delete | ||
543 | * request. When an application receives a delete request (i.e. CMD+Q) | ||
544 | * the termination callback will be called and its result will determine | ||
545 | * whether the application should terminate or not | ||
546 | * @param cb The custom termination callback to set | ||
547 | * @see Ecore_Cocoa_Terminate_Cb | ||
548 | * @since 1.19 | ||
549 | */ | ||
550 | EAPI void ecore_cocoa_terminate_cb_set(Ecore_Cocoa_Terminate_Cb cb) | ||
551 | EINA_ARG_NONNULL(1); | ||
530 | 552 | ||
531 | 553 | ||
532 | /* | 554 | /* |
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m index 1c9c20f358..05de6f4bc5 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa.m +++ b/src/lib/ecore_cocoa/ecore_cocoa.m | |||
@@ -387,3 +387,10 @@ ecore_cocoa_titlebar_height_get(void) | |||
387 | } | 387 | } |
388 | return height; | 388 | return height; |
389 | } | 389 | } |
390 | |||
391 | EAPI void | ||
392 | ecore_cocoa_terminate_cb_set(Ecore_Cocoa_Terminate_Cb cb) | ||
393 | { | ||
394 | EINA_SAFETY_ON_NULL_RETURN(cb); | ||
395 | [NSApp setTerminateCb: cb]; | ||
396 | } | ||
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_app.h b/src/lib/ecore_cocoa/ecore_cocoa_app.h index 0cc01615af..e6eac097fc 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_app.h +++ b/src/lib/ecore_cocoa/ecore_cocoa_app.h | |||
@@ -8,6 +8,7 @@ | |||
8 | { | 8 | { |
9 | Ecore_Timer *_timer; | 9 | Ecore_Timer *_timer; |
10 | NSDate *_expiration; | 10 | NSDate *_expiration; |
11 | Ecore_Cocoa_Terminate_Cb _terminate_cb; | ||
11 | } | 12 | } |
12 | 13 | ||
13 | - (NSDate *)eventExpirationDate; | 14 | - (NSDate *)eventExpirationDate; |
@@ -17,6 +18,8 @@ | |||
17 | - (void)sendEvent:(NSEvent *)anEvent; | 18 | - (void)sendEvent:(NSEvent *)anEvent; |
18 | - (id)init; | 19 | - (id)init; |
19 | - (void)internalUpdate; | 20 | - (void)internalUpdate; |
21 | - (void)setTerminateCb:(Ecore_Cocoa_Terminate_Cb)cb; | ||
22 | - (Ecore_Cocoa_Terminate_Cb)terminateCb; | ||
20 | 23 | ||
21 | - (void) pauseNSRunLoopMonitoring; | 24 | - (void) pauseNSRunLoopMonitoring; |
22 | - (void) resumeNSRunLoopMonitoring; | 25 | - (void) resumeNSRunLoopMonitoring; |
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_app.m b/src/lib/ecore_cocoa/ecore_cocoa_app.m index 04391f61ff..8df1be1830 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_app.m +++ b/src/lib/ecore_cocoa/ecore_cocoa_app.m | |||
@@ -112,6 +112,16 @@ _ecore_cocoa_run_loop_cb(void *data EINA_UNUSED) | |||
112 | ecore_timer_thaw(_timer); | 112 | ecore_timer_thaw(_timer); |
113 | } | 113 | } |
114 | 114 | ||
115 | - (void)setTerminateCb:(Ecore_Cocoa_Terminate_Cb)cb | ||
116 | { | ||
117 | _terminate_cb = cb; | ||
118 | } | ||
119 | |||
120 | - (Ecore_Cocoa_Terminate_Cb)terminateCb | ||
121 | { | ||
122 | return _terminate_cb; | ||
123 | } | ||
124 | |||
115 | @end | 125 | @end |
116 | 126 | ||
117 | 127 | ||
@@ -131,8 +141,19 @@ static Ecore_Cocoa_AppDelegate *_appDelegate = nil; | |||
131 | - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) EINA_UNUSED sender | 141 | - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *) EINA_UNUSED sender |
132 | { | 142 | { |
133 | // XXX This should be alterable (by Elm_Window policy) | 143 | // XXX This should be alterable (by Elm_Window policy) |
134 | return YES; | 144 | return NO; |
135 | } | 145 | } |
136 | 146 | ||
137 | @end | 147 | - (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender |
148 | { | ||
149 | NSApplicationTerminateReply status = NSTerminateNow; | ||
150 | const Ecore_Cocoa_Terminate_Cb cb = [(Ecore_Cocoa_Application *)sender terminateCb]; | ||
151 | if (cb) | ||
152 | { | ||
153 | const Eina_Bool ret = cb(sender); | ||
154 | if (!ret) status = NSTerminateCancel; | ||
155 | } | ||
156 | return status; | ||
157 | } | ||
138 | 158 | ||
159 | @end | ||