summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Guyomarc'h <jean.guyomarch@openwide.fr>2015-10-08 11:58:46 +0200
committerNicolas Aguirre <aguirre.nicolas@gmail.com>2015-11-10 08:32:49 +0100
commit4c3134c97f2972b8a791a41d70f571505bb71e9a (patch)
treecb5663a3bd6313d105960eec641309db703b482e
parent0bec83d667cb3671effe3d5d3d992545139f09b8 (diff)
ecore_cocoa: add support for system cursors
- Ecore_Cocoa_Cursor enum which references system cursors; - API to show/hide cursor: ecore_cocoa_window_cursor_show(); - API to set system cursor: ecore_cocoa_window_cursor_set(); - Ecore_Evas interface to get Ecore_Cocoa_Window from Ecore_Evas.
-rw-r--r--src/Makefile_Ecore_Cocoa.am1
-rw-r--r--src/Makefile_Ecore_Evas.am1
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa.h5
-rw-r--r--src/lib/ecore_cocoa/Ecore_Cocoa_Cursor.h32
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa.m3
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_private.h4
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_window.m53
-rw-r--r--src/lib/ecore_evas/Ecore_Evas.h2
-rw-r--r--src/lib/ecore_evas/ecore_evas.c10
-rw-r--r--src/lib/ecore_evas/ecore_evas_cocoa.h14
-rw-r--r--src/modules/ecore_evas/engines/cocoa/ecore_evas_cocoa.c56
11 files changed, 172 insertions, 9 deletions
diff --git a/src/Makefile_Ecore_Cocoa.am b/src/Makefile_Ecore_Cocoa.am
index 3321b258fb..a158767380 100644
--- a/src/Makefile_Ecore_Cocoa.am
+++ b/src/Makefile_Ecore_Cocoa.am
@@ -7,6 +7,7 @@ lib_LTLIBRARIES += lib/ecore_cocoa/libecore_cocoa.la
7installed_ecorecocoamainheadersdir = $(includedir)/ecore-cocoa-@VMAJ@ 7installed_ecorecocoamainheadersdir = $(includedir)/ecore-cocoa-@VMAJ@
8dist_installed_ecorecocoamainheaders_DATA = \ 8dist_installed_ecorecocoamainheaders_DATA = \
9lib/ecore_cocoa/Ecore_Cocoa.h \ 9lib/ecore_cocoa/Ecore_Cocoa.h \
10lib/ecore_cocoa/Ecore_Cocoa_Cursor.h \
10lib/ecore_cocoa/Ecore_Cocoa_Keys.h 11lib/ecore_cocoa/Ecore_Cocoa_Keys.h
11 12
12lib_ecore_cocoa_libecore_cocoa_la_SOURCES = \ 13lib_ecore_cocoa_libecore_cocoa_la_SOURCES = \
diff --git a/src/Makefile_Ecore_Evas.am b/src/Makefile_Ecore_Evas.am
index f8da5e18fa..ed497a6645 100644
--- a/src/Makefile_Ecore_Evas.am
+++ b/src/Makefile_Ecore_Evas.am
@@ -20,6 +20,7 @@ lib/ecore_evas/ecore_evas_private.h \
20lib/ecore_evas/ecore_evas_extn.h \ 20lib/ecore_evas/ecore_evas_extn.h \
21lib/ecore_evas/ecore_evas_extn.c \ 21lib/ecore_evas/ecore_evas_extn.c \
22lib/ecore_evas/ecore_evas_wayland.h \ 22lib/ecore_evas/ecore_evas_wayland.h \
23lib/ecore_evas/ecore_evas_cocoa.h \
23lib/ecore_evas/ecore_evas_win32.h \ 24lib/ecore_evas/ecore_evas_win32.h \
24lib/ecore_evas/ecore_evas_x11.h \ 25lib/ecore_evas/ecore_evas_x11.h \
25lib/ecore_evas/ecore_evas_util.c 26lib/ecore_evas/ecore_evas_util.c
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa.h b/src/lib/ecore_cocoa/Ecore_Cocoa.h
index 78d15ced48..4341389ce2 100644
--- a/src/lib/ecore_cocoa/Ecore_Cocoa.h
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa.h
@@ -26,6 +26,7 @@
26#endif 26#endif
27 27
28#include <Eina.h> 28#include <Eina.h>
29#include "Ecore_Cocoa_Cursor.h"
29 30
30#ifdef __cplusplus 31#ifdef __cplusplus
31extern "C" { 32extern "C" {
@@ -165,6 +166,10 @@ EAPI int ecore_cocoa_titlebar_height_get(void);
165 166
166EAPI Ecore_Cocoa_Window_Id ecore_cocoa_window_get_window_id(Ecore_Cocoa_Window *window); 167EAPI Ecore_Cocoa_Window_Id ecore_cocoa_window_get_window_id(Ecore_Cocoa_Window *window);
167 168
169
170EAPI void ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win, Ecore_Cocoa_Cursor c);
171EAPI void ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win, Eina_Bool show);
172
168#ifdef __cplusplus 173#ifdef __cplusplus
169} 174}
170#endif 175#endif
diff --git a/src/lib/ecore_cocoa/Ecore_Cocoa_Cursor.h b/src/lib/ecore_cocoa/Ecore_Cocoa_Cursor.h
new file mode 100644
index 0000000000..6bca47f6aa
--- /dev/null
+++ b/src/lib/ecore_cocoa/Ecore_Cocoa_Cursor.h
@@ -0,0 +1,32 @@
1#ifndef __ECORE_COCOA_CURSOR_H__
2#define __ECORE_COCOA_CURSOR_H__
3
4typedef enum
5{
6 ECORE_COCOA_CURSOR_ARROW = 0,
7 ECORE_COCOA_CURSOR_CONTEXTUAL_MENU,
8 ECORE_COCOA_CURSOR_CLOSED_HAND,
9 ECORE_COCOA_CURSOR_CROSSHAIR,
10 ECORE_COCOA_CURSOR_DISAPPEARING_ITEM,
11 ECORE_COCOA_CURSOR_DRAG_COPY,
12 ECORE_COCOA_CURSOR_DRAG_LINK,
13 ECORE_COCOA_CURSOR_IBEAM,
14 ECORE_COCOA_CURSOR_OPEN_HAND,
15 ECORE_COCOA_CURSOR_OPERATION_NOT_ALLOWED,
16 ECORE_COCOA_CURSOR_POINTING_HAND,
17 ECORE_COCOA_CURSOR_RESIZE_DOWN,
18 ECORE_COCOA_CURSOR_RESIZE_LEFT,
19 ECORE_COCOA_CURSOR_RESIZE_LEFT_RIGHT,
20 ECORE_COCOA_CURSOR_RESIZE_RIGHT,
21 ECORE_COCOA_CURSOR_RESIZE_UP,
22 ECORE_COCOA_CURSOR_RESIZE_UP_DOWN,
23 ECORE_COCOA_CURSOR_IBEAM_VERTICAL,
24
25 __ECORE_COCOA_CURSOR_LAST, /* Sentinel */
26
27 ECORE_COCOA_CURSOR_DEFAULT = ECORE_COCOA_CURSOR_ARROW
28
29} Ecore_Cocoa_Cursor;
30
31#endif /* ! __ECORE_COCOA_CURSOR_H__ */
32
diff --git a/src/lib/ecore_cocoa/ecore_cocoa.m b/src/lib/ecore_cocoa/ecore_cocoa.m
index d4e85804b2..1227f2a2a9 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa.m
@@ -61,6 +61,9 @@ ecore_cocoa_init(void)
61 /* Start events monitoring */ 61 /* Start events monitoring */
62 [NSApp run]; 62 [NSApp run];
63 63
64 if (!_ecore_cocoa_window_init())
65 return --_ecore_cocoa_init_count;
66
64 return _ecore_cocoa_init_count; 67 return _ecore_cocoa_init_count;
65} 68}
66 69
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_private.h b/src/lib/ecore_cocoa/ecore_cocoa_private.h
index ffe48ab074..9952278cea 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_private.h
+++ b/src/lib/ecore_cocoa/ecore_cocoa_private.h
@@ -62,4 +62,8 @@ struct _Ecore_Cocoa_Window
62}; 62};
63 63
64 64
65/* Internal init */
66Eina_Bool _ecore_cocoa_window_init(void);
67
68
65#endif 69#endif
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_window.m b/src/lib/ecore_cocoa/ecore_cocoa_window.m
index 53137a0a84..de905c53ee 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_window.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_window.m
@@ -6,9 +6,13 @@
6 6
7#include <Ecore.h> 7#include <Ecore.h>
8#include <Ecore_Cocoa.h> 8#include <Ecore_Cocoa.h>
9#include <Ecore_Cocoa_Cursor.h>
9#import "ecore_cocoa_window.h" 10#import "ecore_cocoa_window.h"
10#include "ecore_cocoa_private.h" 11#include "ecore_cocoa_private.h"
11 12
13static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
14
15
12@implementation EcoreCocoaWindow 16@implementation EcoreCocoaWindow
13 17
14@synthesize ecore_window_data; 18@synthesize ecore_window_data;
@@ -501,3 +505,52 @@ Ecore_Cocoa_Window_Id ecore_cocoa_window_get_window_id(Ecore_Cocoa_Window *windo
501 505
502 return window->window; 506 return window->window;
503} 507}
508
509EAPI void
510ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win,
511 Ecore_Cocoa_Cursor c)
512{
513 EINA_SAFETY_ON_NULL_RETURN(win);
514 EINA_SAFETY_ON_FALSE_RETURN((c >= 0) && (c <= __ECORE_COCOA_CURSOR_LAST));
515
516 NSCursor *cursor = _cursors[c];
517
518 DBG("Setting cursor %i (%s)", c, [[cursor description] UTF8String]);
519 [cursor set];
520}
521
522EAPI void
523ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win,
524 Eina_Bool show)
525{
526 EINA_SAFETY_ON_NULL_RETURN(win);
527
528 if (show) [NSCursor unhide];
529 else [NSCursor hide];
530}
531
532Eina_Bool
533_ecore_cocoa_window_init(void)
534{
535 _cursors[ECORE_COCOA_CURSOR_ARROW] = [NSCursor arrowCursor];
536 _cursors[ECORE_COCOA_CURSOR_CONTEXTUAL_MENU] = [NSCursor contextualMenuCursor];
537 _cursors[ECORE_COCOA_CURSOR_CLOSED_HAND] = [NSCursor closedHandCursor];
538 _cursors[ECORE_COCOA_CURSOR_CROSSHAIR] = [NSCursor crosshairCursor];
539 _cursors[ECORE_COCOA_CURSOR_DISAPPEARING_ITEM] = [NSCursor disappearingItemCursor];
540 _cursors[ECORE_COCOA_CURSOR_DRAG_COPY] = [NSCursor dragCopyCursor];
541 _cursors[ECORE_COCOA_CURSOR_DRAG_LINK] = [NSCursor dragLinkCursor];
542 _cursors[ECORE_COCOA_CURSOR_IBEAM] = [NSCursor IBeamCursor];
543 _cursors[ECORE_COCOA_CURSOR_OPEN_HAND] = [NSCursor openHandCursor];
544 _cursors[ECORE_COCOA_CURSOR_OPERATION_NOT_ALLOWED] = [NSCursor operationNotAllowedCursor];
545 _cursors[ECORE_COCOA_CURSOR_POINTING_HAND] = [NSCursor pointingHandCursor];
546 _cursors[ECORE_COCOA_CURSOR_RESIZE_DOWN] = [NSCursor resizeDownCursor];
547 _cursors[ECORE_COCOA_CURSOR_RESIZE_LEFT] = [NSCursor resizeLeftCursor];
548 _cursors[ECORE_COCOA_CURSOR_RESIZE_LEFT_RIGHT] = [NSCursor resizeLeftRightCursor];
549 _cursors[ECORE_COCOA_CURSOR_RESIZE_RIGHT] = [NSCursor resizeRightCursor];
550 _cursors[ECORE_COCOA_CURSOR_RESIZE_UP] = [NSCursor resizeUpCursor];
551 _cursors[ECORE_COCOA_CURSOR_RESIZE_UP_DOWN] = [NSCursor resizeUpDownCursor];
552 _cursors[ECORE_COCOA_CURSOR_IBEAM_VERTICAL] = [NSCursor IBeamCursorForVerticalLayout];
553
554 return EINA_TRUE;
555}
556
diff --git a/src/lib/ecore_evas/Ecore_Evas.h b/src/lib/ecore_evas/Ecore_Evas.h
index 1a035ab1fa..1aef27be7d 100644
--- a/src/lib/ecore_evas/Ecore_Evas.h
+++ b/src/lib/ecore_evas/Ecore_Evas.h
@@ -1317,6 +1317,8 @@ EAPI void ecore_evas_wayland_pointer_set(Ecore_Evas *ee, int hot_x, i
1317EAPI void ecore_evas_wayland_type_set(Ecore_Evas *ee, int type); 1317EAPI void ecore_evas_wayland_type_set(Ecore_Evas *ee, int type);
1318EAPI Ecore_Wl_Window *ecore_evas_wayland_window_get(const Ecore_Evas *ee); 1318EAPI Ecore_Wl_Window *ecore_evas_wayland_window_get(const Ecore_Evas *ee);
1319 1319
1320EAPI Ecore_Cocoa_Window *ecore_evas_cocoa_window_get(const Ecore_Evas *ee);
1321
1320EAPI Ecore_Evas *ecore_evas_drm_new(const char *device, unsigned int parent, int x, int y, int w, int h); 1322EAPI Ecore_Evas *ecore_evas_drm_new(const char *device, unsigned int parent, int x, int y, int w, int h);
1321EAPI Ecore_Evas *ecore_evas_gl_drm_new(const char *device, unsigned int parent, int x, int y, int w, int h); /** @since 1.12 */ 1323EAPI Ecore_Evas *ecore_evas_gl_drm_new(const char *device, unsigned int parent, int x, int y, int w, int h); /** @since 1.12 */
1322 1324
diff --git a/src/lib/ecore_evas/ecore_evas.c b/src/lib/ecore_evas/ecore_evas.c
index d702cccbad..f0a784ac7b 100644
--- a/src/lib/ecore_evas/ecore_evas.c
+++ b/src/lib/ecore_evas/ecore_evas.c
@@ -30,6 +30,7 @@
30#include "ecore_evas_private.h" 30#include "ecore_evas_private.h"
31#include "ecore_evas_x11.h" 31#include "ecore_evas_x11.h"
32#include "ecore_evas_wayland.h" 32#include "ecore_evas_wayland.h"
33#include "ecore_evas_cocoa.h"
33#include "ecore_evas_extn.h" 34#include "ecore_evas_extn.h"
34#include "ecore_evas_win32.h" 35#include "ecore_evas_win32.h"
35 36
@@ -3983,6 +3984,15 @@ ecore_evas_wayland_window_get(const Ecore_Evas *ee)
3983 return iface->window_get(ee); 3984 return iface->window_get(ee);
3984} 3985}
3985 3986
3987EAPI Ecore_Cocoa_Window *
3988ecore_evas_cocoa_window_get(const Ecore_Evas *ee)
3989{
3990 Ecore_Evas_Interface_Cocoa *iface;
3991 iface = (Ecore_Evas_Interface_Cocoa *)_ecore_evas_interface_get(ee, "opengl_cocoa");
3992 EINA_SAFETY_ON_NULL_RETURN_VAL(iface, NULL);
3993 return iface->window_get(ee);
3994}
3995
3986EAPI Ecore_Evas * 3996EAPI Ecore_Evas *
3987ecore_evas_drm_new(const char *disp_name, unsigned int parent, 3997ecore_evas_drm_new(const char *disp_name, unsigned int parent,
3988 int x, int y, int w, int h) 3998 int x, int y, int w, int h)
diff --git a/src/lib/ecore_evas/ecore_evas_cocoa.h b/src/lib/ecore_evas/ecore_evas_cocoa.h
new file mode 100644
index 0000000000..edc8e051f3
--- /dev/null
+++ b/src/lib/ecore_evas/ecore_evas_cocoa.h
@@ -0,0 +1,14 @@
1#ifndef __ECORE_EVAS_COCOA_H__
2#define __ECORE_EVAS_COCOA_H__
3
4typedef struct _Ecore_Evas_Interface_Cocoa Ecore_Evas_Interface_Cocoa;
5
6struct _Ecore_Evas_Interface_Cocoa
7{
8 Ecore_Evas_Interface base;
9
10 Ecore_Cocoa_Window *(*window_get)(const Ecore_Evas *ee);
11};
12
13#endif /* ! __ECORE_EVAS_COCOA_H__ */
14
diff --git a/src/modules/ecore_evas/engines/cocoa/ecore_evas_cocoa.c b/src/modules/ecore_evas/engines/cocoa/ecore_evas_cocoa.c
index fc0241f6f2..574604a8ae 100644
--- a/src/modules/ecore_evas/engines/cocoa/ecore_evas_cocoa.c
+++ b/src/modules/ecore_evas/engines/cocoa/ecore_evas_cocoa.c
@@ -12,6 +12,7 @@
12 12
13#include "Ecore_Evas.h" 13#include "Ecore_Evas.h"
14#include "ecore_evas_private.h" 14#include "ecore_evas_private.h"
15#include "ecore_evas_cocoa.h"
15 16
16#ifdef EAPI 17#ifdef EAPI
17# undef EAPI 18# undef EAPI
@@ -44,6 +45,9 @@ static Eina_List *ecore_evases = NULL;
44static Ecore_Event_Handler *ecore_evas_event_handlers[5] = { 0 }; 45static Ecore_Event_Handler *ecore_evas_event_handlers[5] = { 0 };
45static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL; 46static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL;
46 47
48static const char *_iface_name = "opengl_cocoa";
49static const int _iface_version = 1;
50
47static int 51static int
48_render_updates_process(Ecore_Evas *ee, Eina_List *updates) 52_render_updates_process(Ecore_Evas *ee, Eina_List *updates)
49{ 53{
@@ -528,16 +532,19 @@ static void
528_ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y) 532_ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int hot_x, int hot_y)
529{ 533{
530 int x, y; 534 int x, y;
535 Evas_Object *old;
536 Ecore_Cocoa_Window *win = (Ecore_Cocoa_Window *)(ee->prop.window);
531 DBG(""); 537 DBG("");
532 if (ee->prop.cursor.object) evas_object_del(ee->prop.cursor.object);
533 538
539 old = ee->prop.cursor.object;
534 if (obj == NULL) 540 if (obj == NULL)
535 { 541 {
536 ee->prop.cursor.object = NULL; 542 ee->prop.cursor.object = NULL;
537 ee->prop.cursor.layer = 0; 543 ee->prop.cursor.layer = 0;
538 ee->prop.cursor.hot.x = 0; 544 ee->prop.cursor.hot.x = 0;
539 ee->prop.cursor.hot.y = 0; 545 ee->prop.cursor.hot.y = 0;
540 return; 546 ecore_cocoa_window_cursor_show(win, EINA_TRUE);
547 goto end;
541 } 548 }
542 549
543 ee->prop.cursor.object = obj; 550 ee->prop.cursor.object = obj;
@@ -546,17 +553,27 @@ _ecore_evas_object_cursor_set(Ecore_Evas *ee, Evas_Object *obj, int layer, int h
546 ee->prop.cursor.hot.y = hot_y; 553 ee->prop.cursor.hot.y = hot_y;
547 554
548 evas_pointer_output_xy_get(ee->evas, &x, &y); 555 evas_pointer_output_xy_get(ee->evas, &x, &y);
549 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer); 556 if (obj != old)
557 {
558 ecore_cocoa_window_cursor_show(win, EINA_FALSE);
559 evas_object_layer_set(ee->prop.cursor.object, ee->prop.cursor.layer);
560 evas_object_pass_events_set(ee->prop.cursor.object, 1);
561 if (evas_pointer_inside_get(ee->evas))
562 evas_object_show(ee->prop.cursor.object);
563 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL,
564 _ecore_evas_object_cursor_del, ee);
565 }
550 evas_object_move(ee->prop.cursor.object, 566 evas_object_move(ee->prop.cursor.object,
551 x - ee->prop.cursor.hot.x, 567 x - ee->prop.cursor.hot.x,
552 y - ee->prop.cursor.hot.y); 568 y - ee->prop.cursor.hot.y);
553 569
554 evas_object_pass_events_set(ee->prop.cursor.object, 1); 570end:
555 571 if ((old) && (obj != old))
556 if (evas_pointer_inside_get(ee->evas)) 572 {
557 evas_object_show(ee->prop.cursor.object); 573 evas_object_event_callback_del_full(old, EVAS_CALLBACK_DEL,
558 574 _ecore_evas_object_cursor_del, ee);
559 evas_object_event_callback_add(obj, EVAS_CALLBACK_DEL, _ecore_evas_object_cursor_del, ee); 575 evas_object_del(old);
576 }
560} 577}
561 578
562static void 579static void
@@ -688,10 +705,19 @@ static Ecore_Evas_Engine_Func _ecore_cocoa_engine_func =
688 NULL // msg_send 705 NULL // msg_send
689 }; 706 };
690 707
708static Ecore_Cocoa_Window *
709_ecore_evas_cocoa_window_get(const Ecore_Evas *ee)
710{
711 /* See affectation of ee->prop.window in ecore_evas_cocoa_new_internal */
712 return (Ecore_Cocoa_Window *)(ee->prop.window);
713}
714
715
691EAPI Ecore_Evas * 716EAPI Ecore_Evas *
692ecore_evas_cocoa_new_internal(Ecore_Cocoa_Window *parent EINA_UNUSED, int x, int y, int w, int h) 717ecore_evas_cocoa_new_internal(Ecore_Cocoa_Window *parent EINA_UNUSED, int x, int y, int w, int h)
693{ 718{
694 Ecore_Evas *ee; 719 Ecore_Evas *ee;
720 Ecore_Evas_Interface_Cocoa *iface;
695 721
696 if (!ecore_cocoa_init()) 722 if (!ecore_cocoa_init())
697 return NULL; 723 return NULL;
@@ -755,6 +781,18 @@ ecore_evas_cocoa_new_internal(Ecore_Cocoa_Window *parent EINA_UNUSED, int x, int
755 return NULL; 781 return NULL;
756 } 782 }
757 783
784 /* Interface setup */
785 iface = calloc(1, sizeof(*iface));
786 if (EINA_UNLIKELY(!iface))
787 {
788 _ecore_evas_cocoa_shutdown();
789 free(ee);
790 return NULL;
791 }
792 iface->base.name = _iface_name;
793 iface->base.version = _iface_version;
794 iface->window_get = _ecore_evas_cocoa_window_get;
795 ee->engine.ifaces = eina_list_append(ee->engine.ifaces, iface);
758 796
759 ee->engine.func->fn_render = _ecore_evas_cocoa_render; 797 ee->engine.func->fn_render = _ecore_evas_cocoa_render;
760 _ecore_evas_register(ee); 798 _ecore_evas_register(ee);