diff options
author | Jean Guyomarc'h <jean.guyomarch@gmail.com> | 2014-07-23 16:56:16 +0200 |
---|---|---|
committer | Raoul Hecky <raoul.hecky@gmail.com> | 2014-07-23 16:56:16 +0200 |
commit | f8235ff5c155ff97488850e19c60e65b6712c3f2 (patch) | |
tree | 772354f12a321089da7356f425fef5746178916d /src/lib | |
parent | 572b7aa92f44a954751be5fdfb896a1db5a7898b (diff) |
ecore_cocoa: Lion fullscreen workaround + warning fixes
Summary: Warnings and deprecated code fixes. I started to implement the OSX-Lion fullscreen style.
Reviewers: cedric, naguirre, raster, raoulh
Subscribers: cedric
Differential Revision: https://phab.enlightenment.org/D1175
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa.m | 197 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa_private.h | 2 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa_window.h | 4 | ||||
-rw-r--r-- | src/lib/ecore_cocoa/ecore_cocoa_window.m | 84 |
4 files changed, 162 insertions, 125 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m index d2303e7fb9..2b1bf08946 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa.m +++ b/src/lib/ecore_cocoa/ecore_cocoa.m | |||
@@ -75,6 +75,20 @@ _ecore_cocoa_event_modifiers(unsigned int mod) | |||
75 | return modifiers; | 75 | return modifiers; |
76 | } | 76 | } |
77 | 77 | ||
78 | static inline Eina_Bool | ||
79 | _nsevent_window_is_type_of(NSEvent *event, Class class) | ||
80 | { | ||
81 | /* An NSPeriodic event has no window (undefined behaviour) */ | ||
82 | if ([event type] == NSPeriodic) return EINA_FALSE; | ||
83 | return [[[event window] class] isKindOfClass:class]; | ||
84 | } | ||
85 | |||
86 | static inline Eina_Bool | ||
87 | _has_ecore_cocoa_window(NSEvent *event) | ||
88 | { | ||
89 | return _nsevent_window_is_type_of(event, [EcoreCocoaWindow class]); | ||
90 | } | ||
91 | |||
78 | EAPI void | 92 | EAPI void |
79 | ecore_cocoa_feed_events(void) | 93 | ecore_cocoa_feed_events(void) |
80 | { | 94 | { |
@@ -96,24 +110,31 @@ ecore_cocoa_feed_events(void) | |||
96 | case NSRightMouseDragged: | 110 | case NSRightMouseDragged: |
97 | case NSOtherMouseDragged: | 111 | case NSOtherMouseDragged: |
98 | { | 112 | { |
99 | Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)); | 113 | if (_has_ecore_cocoa_window(event)) |
100 | if (!ev) return; | 114 | { |
101 | 115 | Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move)); | |
102 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; | 116 | if (!ev) return; |
103 | NSView *view = [window contentView]; | 117 | |
104 | NSPoint pt = [event locationInWindow]; | 118 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; |
105 | 119 | NSView *view = [window contentView]; | |
106 | ev->x = pt.x; | 120 | NSPoint pt = [event locationInWindow]; |
107 | ev->y = [view frame].size.height - pt.y; | 121 | |
108 | ev->root.x = ev->x; | 122 | ev->x = pt.x; |
109 | ev->root.y = ev->y; | 123 | ev->y = [view frame].size.height - pt.y; |
110 | ev->timestamp = time; | 124 | ev->root.x = ev->x; |
111 | ev->window = window.ecore_window_data; | 125 | ev->root.y = ev->y; |
112 | ev->event_window = ev->window; | 126 | ev->timestamp = time; |
113 | ev->modifiers = 0; /* FIXME: keep modifier around. */ | 127 | ev->window = window.ecore_window_data; |
114 | 128 | ev->event_window = ev->window; | |
115 | ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); | 129 | ev->modifiers = 0; /* FIXME: keep modifier around. */ |
116 | 130 | ||
131 | ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL); | ||
132 | } | ||
133 | else | ||
134 | { | ||
135 | // We might want to handle cases such as events on the menubar. | ||
136 | // If so, let's do it here. | ||
137 | } | ||
117 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | 138 | [NSApp sendEvent:event]; // pass along mouse events, for window manager |
118 | break; | 139 | break; |
119 | } | 140 | } |
@@ -121,40 +142,47 @@ ecore_cocoa_feed_events(void) | |||
121 | case NSRightMouseDown: | 142 | case NSRightMouseDown: |
122 | case NSOtherMouseDown: | 143 | case NSOtherMouseDown: |
123 | { | 144 | { |
124 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | 145 | if (_has_ecore_cocoa_window(event)) |
125 | if (!ev) return; | 146 | { |
126 | 147 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | |
127 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; | 148 | if (!ev) return; |
128 | NSView *view = [window contentView]; | 149 | |
129 | NSPoint pt = [event locationInWindow]; | 150 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; |
130 | 151 | NSView *view = [window contentView]; | |
131 | ev->x = pt.x; | 152 | NSPoint pt = [event locationInWindow]; |
132 | ev->y = [view frame].size.height - pt.y; | 153 | |
133 | ev->root.x = ev->x; | 154 | ev->x = pt.x; |
134 | ev->root.y = ev->y; | 155 | ev->y = [view frame].size.height - pt.y; |
135 | ev->timestamp = time; | 156 | ev->root.x = ev->x; |
136 | switch ([event buttonNumber]) | 157 | ev->root.y = ev->y; |
137 | { | 158 | ev->timestamp = time; |
138 | case 0: ev->buttons = 1; break; | 159 | switch ([event buttonNumber]) |
139 | case 1: ev->buttons = 3; break; | 160 | { |
140 | case 2: ev->buttons = 2; break; | 161 | case 0: ev->buttons = 1; break; |
141 | default: ev->buttons = 0; break; | 162 | case 1: ev->buttons = 3; break; |
142 | } | 163 | case 2: ev->buttons = 2; break; |
143 | ev->window = window.ecore_window_data; | 164 | default: ev->buttons = 0; break; |
144 | ev->event_window = ev->window; | 165 | } |
145 | 166 | ev->window = window.ecore_window_data; | |
146 | if ([event clickCount] == 2) | 167 | ev->event_window = ev->window; |
147 | ev->double_click = 1; | 168 | |
148 | else | 169 | if ([event clickCount] == 2) |
149 | ev->double_click = 0; | 170 | ev->double_click = 1; |
150 | 171 | else | |
151 | if ([event clickCount] >= 3) | 172 | ev->double_click = 0; |
152 | ev->triple_click = 1; | 173 | |
174 | if ([event clickCount] >= 3) | ||
175 | ev->triple_click = 1; | ||
176 | else | ||
177 | ev->triple_click = 0; | ||
178 | |||
179 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); | ||
180 | } | ||
153 | else | 181 | else |
154 | ev->triple_click = 0; | 182 | { |
155 | 183 | // We might want to handle cases such as events on the menubar. | |
156 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL); | 184 | // If so, let's do it here. |
157 | 185 | } | |
158 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | 186 | [NSApp sendEvent:event]; // pass along mouse events, for window manager |
159 | break; | 187 | break; |
160 | } | 188 | } |
@@ -165,37 +193,44 @@ ecore_cocoa_feed_events(void) | |||
165 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); | 193 | Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button)); |
166 | if (!ev) return; | 194 | if (!ev) return; |
167 | 195 | ||
168 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; | 196 | if (_has_ecore_cocoa_window(event)) |
169 | NSView *view = [window contentView]; | 197 | { |
170 | NSPoint pt = [event locationInWindow]; | 198 | EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window]; |
171 | 199 | NSView *view = [window contentView]; | |
172 | ev->x = pt.x; | 200 | NSPoint pt = [event locationInWindow]; |
173 | ev->y = [view frame].size.height - pt.y; | 201 | |
174 | ev->root.x = ev->x; | 202 | ev->x = pt.x; |
175 | ev->root.y = ev->y; | 203 | ev->y = [view frame].size.height - pt.y; |
176 | ev->timestamp = time; | 204 | ev->root.x = ev->x; |
177 | switch ([event buttonNumber]) | 205 | ev->root.y = ev->y; |
178 | { | 206 | ev->timestamp = time; |
179 | case 0: ev->buttons = 1; break; | 207 | switch ([event buttonNumber]) |
180 | case 1: ev->buttons = 3; break; | 208 | { |
181 | case 2: ev->buttons = 2; break; | 209 | case 0: ev->buttons = 1; break; |
182 | default: ev->buttons = 0; break; | 210 | case 1: ev->buttons = 3; break; |
183 | } | 211 | case 2: ev->buttons = 2; break; |
184 | ev->window = window.ecore_window_data; | 212 | default: ev->buttons = 0; break; |
185 | ev->event_window = ev->window; | 213 | } |
186 | 214 | ev->window = window.ecore_window_data; | |
187 | if ([event clickCount] == 2) | 215 | ev->event_window = ev->window; |
188 | ev->double_click = 1; | 216 | |
189 | else | 217 | if ([event clickCount] == 2) |
190 | ev->double_click = 0; | 218 | ev->double_click = 1; |
191 | 219 | else | |
192 | if ([event clickCount] >= 3) | 220 | ev->double_click = 0; |
193 | ev->triple_click = 1; | 221 | |
222 | if ([event clickCount] >= 3) | ||
223 | ev->triple_click = 1; | ||
224 | else | ||
225 | ev->triple_click = 0; | ||
226 | |||
227 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); | ||
228 | } | ||
194 | else | 229 | else |
195 | ev->triple_click = 0; | 230 | { |
196 | 231 | // We might want to handle cases such as events on the menubar. | |
197 | ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL); | 232 | // If so, let's do it here. |
198 | 233 | } | |
199 | [NSApp sendEvent:event]; // pass along mouse events, for window manager | 234 | [NSApp sendEvent:event]; // pass along mouse events, for window manager |
200 | break; | 235 | break; |
201 | } | 236 | } |
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_private.h b/src/lib/ecore_cocoa/ecore_cocoa_private.h index 7cd08be9d2..41310d43d5 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_private.h +++ b/src/lib/ecore_cocoa/ecore_cocoa_private.h | |||
@@ -3,7 +3,7 @@ | |||
3 | 3 | ||
4 | struct _Ecore_Cocoa_Window | 4 | struct _Ecore_Cocoa_Window |
5 | { | 5 | { |
6 | NSWindow *window; | 6 | EcoreCocoaWindow *window; |
7 | unsigned int borderless : 1; | 7 | unsigned int borderless : 1; |
8 | }; | 8 | }; |
9 | 9 | ||
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.h b/src/lib/ecore_cocoa/ecore_cocoa_window.h index 6778c70133..911c729ab8 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_window.h +++ b/src/lib/ecore_cocoa/ecore_cocoa_window.h | |||
@@ -11,4 +11,8 @@ | |||
11 | styleMask: (unsigned int) aStyle | 11 | styleMask: (unsigned int) aStyle |
12 | backing: (NSBackingStoreType) bufferingType | 12 | backing: (NSBackingStoreType) bufferingType |
13 | defer: (BOOL) flag; | 13 | defer: (BOOL) flag; |
14 | |||
15 | - (BOOL)isFullScreen; | ||
16 | |||
14 | @end | 17 | @end |
18 | |||
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m index 297a425e23..ab4a78ce13 100644 --- a/src/lib/ecore_cocoa/ecore_cocoa_window.m +++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m | |||
@@ -15,9 +15,9 @@ | |||
15 | backing: (NSBackingStoreType) bufferingType | 15 | backing: (NSBackingStoreType) bufferingType |
16 | defer: (BOOL) flag | 16 | defer: (BOOL) flag |
17 | { | 17 | { |
18 | if (![super initWithContentRect: contentRect | 18 | if (![super initWithContentRect: contentRect |
19 | styleMask: aStyle | 19 | styleMask: aStyle |
20 | backing: bufferingType | 20 | backing: bufferingType |
21 | defer: flag]) return nil; | 21 | defer: flag]) return nil; |
22 | 22 | ||
23 | [self setBackgroundColor: [NSColor whiteColor]]; | 23 | [self setBackgroundColor: [NSColor whiteColor]]; |
@@ -25,9 +25,16 @@ | |||
25 | [self setDelegate:self]; | 25 | [self setDelegate:self]; |
26 | [self setAcceptsMouseMovedEvents:YES]; | 26 | [self setAcceptsMouseMovedEvents:YES]; |
27 | 27 | ||
28 | [self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary]; | ||
29 | |||
28 | return self; | 30 | return self; |
29 | } | 31 | } |
30 | 32 | ||
33 | - (BOOL)isFullScreen | ||
34 | { | ||
35 | return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask); | ||
36 | } | ||
37 | |||
31 | - (BOOL)acceptsFirstResponder | 38 | - (BOOL)acceptsFirstResponder |
32 | { | 39 | { |
33 | return YES; | 40 | return YES; |
@@ -38,12 +45,12 @@ | |||
38 | return YES; | 45 | return YES; |
39 | } | 46 | } |
40 | 47 | ||
41 | - (void)windowWillClose:(NSNotification *)notification | 48 | - (void)windowWillClose:(NSNotification *) EINA_UNUSED notification |
42 | { | 49 | { |
43 | NSLog(@"window is going to be closed"); | 50 | NSLog(@"window is going to be closed"); |
44 | } | 51 | } |
45 | 52 | ||
46 | - (void)windowDidResize:(NSNotification *)notif | 53 | - (void)windowDidResize:(NSNotification *) EINA_UNUSED notif |
47 | { | 54 | { |
48 | Ecore_Cocoa_Event_Video_Resize *event; | 55 | Ecore_Cocoa_Event_Video_Resize *event; |
49 | NSSize size = self.frame.size; | 56 | NSSize size = self.frame.size; |
@@ -56,7 +63,9 @@ | |||
56 | return; | 63 | return; |
57 | } | 64 | } |
58 | event->w = size.width; | 65 | event->w = size.width; |
59 | event->h = size.height - ecore_cocoa_titlebar_height_get(); | 66 | event->h = size.height - |
67 | (([self isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get()); | ||
68 | printf("Is fullscreen: %i\n", [self isFullScreen]); | ||
60 | ecore_event_add(ECORE_COCOA_EVENT_RESIZE, event, NULL, NULL); | 69 | ecore_event_add(ECORE_COCOA_EVENT_RESIZE, event, NULL, NULL); |
61 | } | 70 | } |
62 | 71 | ||
@@ -66,17 +75,6 @@ | |||
66 | #include "Ecore_Cocoa.h" | 75 | #include "Ecore_Cocoa.h" |
67 | #include "ecore_cocoa_private.h" | 76 | #include "ecore_cocoa_private.h" |
68 | 77 | ||
69 | static float _title_bar_height(void) | ||
70 | { | ||
71 | NSRect frame = NSMakeRect (0, 0, 100, 100); | ||
72 | NSRect contentRect; | ||
73 | |||
74 | contentRect = [NSWindow contentRectForFrameRect: frame | ||
75 | styleMask: NSTitledWindowMask]; | ||
76 | |||
77 | return (frame.size.height - contentRect.size.height); | ||
78 | } | ||
79 | |||
80 | Ecore_Cocoa_Window * | 78 | Ecore_Cocoa_Window * |
81 | ecore_cocoa_window_new(int x, | 79 | ecore_cocoa_window_new(int x, |
82 | int y, | 80 | int y, |
@@ -85,27 +83,29 @@ ecore_cocoa_window_new(int x, | |||
85 | { | 83 | { |
86 | Ecore_Cocoa_Window *w; | 84 | Ecore_Cocoa_Window *w; |
87 | 85 | ||
88 | EcoreCocoaWindow *window = [[EcoreCocoaWindow alloc] | 86 | EcoreCocoaWindow *window = [[EcoreCocoaWindow alloc] initWithContentRect:NSMakeRect(x, y, width, height) |
89 | initWithContentRect:NSMakeRect(x, y, width, height) | 87 | styleMask:(NSTitledWindowMask | |
90 | styleMask:(NSTitledWindowMask | | 88 | NSClosableWindowMask | |
91 | NSClosableWindowMask | | 89 | NSResizableWindowMask | |
92 | NSResizableWindowMask | | 90 | NSMiniaturizableWindowMask) |
93 | NSMiniaturizableWindowMask) | 91 | backing:NSBackingStoreBuffered |
94 | backing:NSBackingStoreBuffered | 92 | defer:NO]; |
95 | defer:NO]; | ||
96 | 93 | ||
97 | if (!window) | 94 | if (!window) |
98 | return NULL; | 95 | return NULL; |
99 | 96 | ||
100 | //Set the process to be a foreground process, | 97 | //Set the process to be a foreground process, |
101 | //without that it prevents the window to become the key window and | 98 | //without that it prevents the window to become the key window and |
102 | //receive all mouse mouve events. | 99 | //receive all mouse mouve events. |
103 | ProcessSerialNumber psn; | 100 | [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; |
104 | GetCurrentProcess(&psn); | 101 | [NSApp activateIgnoringOtherApps:YES]; |
105 | TransformProcessType(&psn, kProcessTransformToForegroundApplication); | 102 | |
106 | SetFrontProcess(&psn); | ||
107 | 103 | ||
108 | w = calloc(1, sizeof(Ecore_Cocoa_Window)); | 104 | w = calloc(1, sizeof(Ecore_Cocoa_Window)); |
105 | if (w == NULL) | ||
106 | { | ||
107 | return NULL; | ||
108 | } | ||
109 | w->window = window; | 109 | w->window = window; |
110 | w->borderless = 0; | 110 | w->borderless = 0; |
111 | 111 | ||
@@ -150,9 +150,9 @@ ecore_cocoa_window_resize(Ecore_Cocoa_Window *window, | |||
150 | 150 | ||
151 | NSRect win_frame; | 151 | NSRect win_frame; |
152 | 152 | ||
153 | |||
154 | win_frame = [window->window frame]; | 153 | win_frame = [window->window frame]; |
155 | win_frame.size.height = height + _title_bar_height(); | 154 | win_frame.size.height = height + |
155 | (([window->window isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get()); | ||
156 | win_frame.size.width = width; | 156 | win_frame.size.width = width; |
157 | 157 | ||
158 | [window->window setFrame:win_frame display:YES]; | 158 | [window->window setFrame:win_frame display:YES]; |
@@ -165,16 +165,13 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window, | |||
165 | int width, | 165 | int width, |
166 | int height) | 166 | int height) |
167 | { | 167 | { |
168 | if (!window) | 168 | if (!window) return; |
169 | return; | ||
170 | 169 | ||
171 | NSRect win_frame; | 170 | NSRect win_frame; |
172 | 171 | ||
173 | if (!window) | ||
174 | return; | ||
175 | |||
176 | win_frame = [window->window frame]; | 172 | win_frame = [window->window frame]; |
177 | win_frame.size.height = height + _title_bar_height(); | 173 | win_frame.size.height = height + |
174 | (([window->window isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get()); | ||
178 | win_frame.size.width = width; | 175 | win_frame.size.width = width; |
179 | win_frame.origin.x = x; | 176 | win_frame.origin.x = x; |
180 | win_frame.origin.y = y; | 177 | win_frame.origin.y = y; |
@@ -232,15 +229,16 @@ ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window, | |||
232 | return; | 229 | return; |
233 | 230 | ||
234 | //[[window->window contentView] addSubview:view]; | 231 | //[[window->window contentView] addSubview:view]; |
232 | NSView *v = view; | ||
235 | [window->window setContentView:view]; | 233 | [window->window setContentView:view]; |
236 | 234 | ||
237 | NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[view frame] | 235 | NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[v frame] |
238 | options:NSTrackingMouseMoved | | 236 | options:NSTrackingMouseMoved | |
239 | NSTrackingActiveInActiveApp | | 237 | NSTrackingActiveInActiveApp | |
240 | NSTrackingInVisibleRect | 238 | NSTrackingInVisibleRect |
241 | owner:view | 239 | owner:v |
242 | userInfo:nil]; | 240 | userInfo:nil]; |
243 | [view addTrackingArea:area]; | 241 | [v addTrackingArea:area]; |
244 | 242 | ||
245 | [area release]; | 243 | [area release]; |
246 | } | 244 | } |