summaryrefslogtreecommitdiff
path: root/src/lib/ecore_cocoa
diff options
context:
space:
mode:
authorpierre lamot <pierre.lamot@openwide.fr>2015-02-18 14:11:00 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-12 07:43:59 +0100
commitc0aedc828a0156fcb563890921302302a67747b8 (patch)
tree654b16d1d233a6c8d4fb9e457a7e9dec8efcf6d3 /src/lib/ecore_cocoa
parentcf730014cfccf7f8c0fa86af2440ed7439c43101 (diff)
ecore_cocoa: move mouse event handling to NSWindow
Mouse events was broken after a resize of the window from the left or the bottom. As I understand, theses resize were changing the origin of Cocoa window independly from the origin of the EFL. This has been resolved by moving mouse envents handling to our NSWindow delegate. thus events are always in the right referential. @fix Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/ecore_cocoa')
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m148
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_window.m122
2 files changed, 126 insertions, 144 deletions
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
index 396e1bcbf8..60229b774d 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -125,153 +125,15 @@ ecore_cocoa_feed_events(void *anEvent)
125 case NSLeftMouseDragged: 125 case NSLeftMouseDragged:
126 case NSRightMouseDragged: 126 case NSRightMouseDragged:
127 case NSOtherMouseDragged: 127 case NSOtherMouseDragged:
128 {
129 if (_has_ecore_cocoa_window(event))
130 {
131 Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move));
132 if (!ev) return pass;
133
134 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
135 NSView *view = [window contentView];
136 NSPoint pt = [event locationInWindow];
137
138 ev->x = pt.x;
139 ev->y = [view frame].size.height - pt.y;
140 ev->root.x = ev->x;
141 ev->root.y = ev->y;
142 ev->timestamp = time;
143 ev->window = (Ecore_Window)window.ecore_window_data;
144 ev->event_window = ev->window;
145 ev->modifiers = 0; /* FIXME: keep modifier around. */
146
147 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
148 }
149 else
150 {
151 // We might want to handle cases such as events on the menubar.
152 // If so, let's do it here.
153 }
154 pass = EINA_TRUE;
155 break;
156 }
157 case NSLeftMouseDown: 128 case NSLeftMouseDown:
158 case NSRightMouseDown: 129 case NSRightMouseDown:
159 case NSOtherMouseDown: 130 case NSOtherMouseDown:
160 {
161 if (_has_ecore_cocoa_window(event))
162 {
163 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
164 NSView *view = [window contentView];
165 NSPoint pt = [event locationInWindow];
166
167 int w = [view frame].size.width;
168 int h = [view frame].size.height;
169 int x = pt.x;
170 int y = h - pt.y;
171
172 if (y <= 0 || x <= 0 || y > h || x > w)
173 {
174 pass = EINA_TRUE;
175 break;
176 }
177
178 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
179 if (!ev) return pass;
180
181 ev->x = pt.x;
182 ev->y = y;
183 ev->root.x = ev->x;
184 ev->root.y = ev->y;
185 ev->timestamp = time;
186 switch ([event buttonNumber])
187 {
188 case 0: ev->buttons = 1; break;
189 case 1: ev->buttons = 3; break;
190 case 2: ev->buttons = 2; break;
191 default: ev->buttons = 0; break;
192 }
193 ev->window = (Ecore_Window)window.ecore_window_data;
194 ev->event_window = ev->window;
195
196 if ([event clickCount] == 2)
197 ev->double_click = 1;
198 else
199 ev->double_click = 0;
200
201 if ([event clickCount] >= 3)
202 ev->triple_click = 1;
203 else
204 ev->triple_click = 0;
205
206 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
207 }
208 else
209 {
210 // We might want to handle cases such as events on the menubar.
211 // If so, let's do it here.
212 }
213 pass = EINA_TRUE;
214 break;
215 }
216 case NSLeftMouseUp: 131 case NSLeftMouseUp:
217 case NSRightMouseUp: 132 case NSRightMouseUp:
218 case NSOtherMouseUp: 133 case NSOtherMouseUp:
219 { 134 {
220 135 //mouse events are managed in EcoreCocoaWindow
221 if (_has_ecore_cocoa_window(event)) 136 return EINA_TRUE;
222 {
223 EcoreCocoaWindow *window = (EcoreCocoaWindow *)[event window];
224 NSView *view = [window contentView];
225 NSPoint pt = [event locationInWindow];
226
227 int w = [view frame].size.width;
228 int h = [view frame].size.height;
229 int x = pt.x;
230 int y = h - pt.y;
231
232 if (y <= 0 || x <= 0 || y > h || x > w)
233 {
234 pass = EINA_TRUE;
235 break;
236 }
237
238 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
239 if (!ev) return pass;
240
241 ev->x = pt.x;
242 ev->y = y;
243 ev->root.x = ev->x;
244 ev->root.y = ev->y;
245 ev->timestamp = time;
246 switch ([event buttonNumber])
247 {
248 case 0: ev->buttons = 1; break;
249 case 1: ev->buttons = 3; break;
250 case 2: ev->buttons = 2; break;
251 default: ev->buttons = 0; break;
252 }
253 ev->window = (Ecore_Window)window.ecore_window_data;
254 ev->event_window = ev->window;
255
256 if ([event clickCount] == 2)
257 ev->double_click = 1;
258 else
259 ev->double_click = 0;
260
261 if ([event clickCount] >= 3)
262 ev->triple_click = 1;
263 else
264 ev->triple_click = 0;
265
266 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
267 }
268 else
269 {
270 // We might want to handle cases such as events on the menubar.
271 // If so, let's do it here.
272 }
273 pass = EINA_TRUE;
274 break;
275 } 137 }
276 case NSKeyDown: 138 case NSKeyDown:
277 { 139 {
@@ -416,8 +278,8 @@ ecore_cocoa_feed_events(void *anEvent)
416 case NSAppKitDefined: 278 case NSAppKitDefined:
417 { 279 {
418 if ([event subtype] == NSApplicationActivatedEventType) 280 if ([event subtype] == NSApplicationActivatedEventType)
419 { 281 {
420 Ecore_Cocoa_Event_Window *ev; 282 Ecore_Cocoa_Event_Window *ev;
421 283
422 ev = malloc(sizeof(Ecore_Cocoa_Event_Window)); 284 ev = malloc(sizeof(Ecore_Cocoa_Event_Window));
423 if (!ev) 285 if (!ev)
@@ -429,7 +291,7 @@ ecore_cocoa_feed_events(void *anEvent)
429 ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, ev, NULL, NULL); 291 ecore_event_add(ECORE_COCOA_EVENT_GOT_FOCUS, ev, NULL, NULL);
430 } 292 }
431 else if ([event subtype] == NSApplicationDeactivatedEventType) 293 else if ([event subtype] == NSApplicationDeactivatedEventType)
432 { 294 {
433 Ecore_Cocoa_Event_Window *ev; 295 Ecore_Cocoa_Event_Window *ev;
434 296
435 ev = malloc(sizeof(Ecore_Cocoa_Event_Window)); 297 ev = malloc(sizeof(Ecore_Cocoa_Event_Window));
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m
index 76b90247db..0a7d290f9b 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_window.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m
@@ -6,6 +6,7 @@
6#include <Ecore_Cocoa.h> 6#include <Ecore_Cocoa.h>
7#include "ecore_cocoa_private.h" 7#include "ecore_cocoa_private.h"
8#import "ecore_cocoa_window.h" 8#import "ecore_cocoa_window.h"
9#include <Ecore_Input.h>
9 10
10@implementation EcoreCocoaWindow 11@implementation EcoreCocoaWindow
11 12
@@ -67,7 +68,6 @@
67 (([self isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get()); 68 (([self isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get());
68 event->wid = [notif object]; 69 event->wid = [notif object];
69 ecore_event_add(ECORE_COCOA_EVENT_RESIZE, event, NULL, NULL); 70 ecore_event_add(ECORE_COCOA_EVENT_RESIZE, event, NULL, NULL);
70 ecore_main_loop_iterate();
71} 71}
72 72
73- (void)windowDidBecomeKey:(NSNotification *)notification 73- (void)windowDidBecomeKey:(NSNotification *)notification
@@ -98,6 +98,126 @@
98 ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, e, NULL, NULL); 98 ecore_event_add(ECORE_COCOA_EVENT_LOST_FOCUS, e, NULL, NULL);
99} 99}
100 100
101- (void) mouseDown:(NSEvent*) event
102{
103 unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
104
105 NSView *view = [self contentView];
106 NSPoint event_location = [event locationInWindow];
107 NSPoint pt = [view convertPoint:event_location fromView:nil];
108
109 int w = [view frame].size.width;
110 int h = [view frame].size.height;
111 int x = pt.x;
112 int y = h - pt.y;
113
114 if (y <= 0 || x <= 0 || y > h || x > w)
115 return;
116
117 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
118 if (!ev) return;
119
120 ev->x = pt.x;
121 ev->y = y;
122 ev->root.x = ev->x;
123 ev->root.y = ev->y;
124 ev->timestamp = time;
125 switch ([event buttonNumber])
126 {
127 case 0: ev->buttons = 1; break;
128 case 1: ev->buttons = 3; break;
129 case 2: ev->buttons = 2; break;
130 default: ev->buttons = 0; break;
131 }
132 ev->window = (Ecore_Window)self.ecore_window_data;
133 ev->event_window = ev->window;
134
135 if ([event clickCount] == 2)
136 ev->double_click = 1;
137 else
138 ev->double_click = 0;
139
140 if ([event clickCount] >= 3)
141 ev->triple_click = 1;
142 else
143 ev->triple_click = 0;
144
145 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
146}
147
148- (void) mouseUp:(NSEvent*) event
149{
150 unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
151
152 NSView *view = [self contentView];
153 NSPoint event_location = [event locationInWindow];
154 NSPoint pt = [view convertPoint:event_location fromView:nil];
155
156 int w = [view frame].size.width;
157 int h = [view frame].size.height;
158 int x = pt.x;
159 int y = h - pt.y;
160
161 if (y <= 0 || x <= 0 || y > h || x > w)
162 return;
163
164 Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
165 if (!ev) return;
166
167 ev->x = pt.x;
168 ev->y = y;
169 ev->root.x = ev->x;
170 ev->root.y = ev->y;
171 ev->timestamp = time;
172 switch ([event buttonNumber])
173 {
174 case 0: ev->buttons = 1; break;
175 case 1: ev->buttons = 3; break;
176 case 2: ev->buttons = 2; break;
177 default: ev->buttons = 0; break;
178 }
179 ev->window = (Ecore_Window)self.ecore_window_data;
180 ev->event_window = ev->window;
181
182 if ([event clickCount] == 2)
183 ev->double_click = 1;
184 else
185 ev->double_click = 0;
186
187 if ([event clickCount] >= 3)
188 ev->triple_click = 1;
189 else
190 ev->triple_click = 0;
191
192 ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
193}
194
195- (void) mouseMoved:(NSEvent*) event
196{
197 Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move));
198 if (!ev) return;
199
200 NSView *view = [self contentView];
201 NSPoint event_location = [event locationInWindow];
202 NSPoint pt = [view convertPoint:event_location fromView:nil];
203
204 ev->x = pt.x;
205 ev->y = [view frame].size.height - pt.y;
206 ev->root.x = ev->x;
207 ev->root.y = ev->y;
208 ev->timestamp = time;
209 ev->window = (Ecore_Window)self.ecore_window_data;
210 ev->event_window = ev->window;
211 ev->modifiers = 0; /* FIXME: keep modifier around. */
212
213 ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
214}
215
216- (void) mouseDragged: (NSEvent*) event
217{
218 [self mouseMoved:event];
219}
220
101@end 221@end
102 222
103Ecore_Cocoa_Window * 223Ecore_Cocoa_Window *