* (should) fix the compilation on Mac OS X (ecore_input)

* better check of Cocoa.h

Patch by Andrew Wiliams and myself.

As I had to modify the patch so that it compiles on linux, could
the Mac OS X users check if the compilation is fine ?

Next steps:
 * change the name 'quartz' to 'cocoa'
 * add in ecore_cocoa all the needed functions to be used in ecore_evas
   (windows management, cursors, events, etc...) so that ecore_evas_cocoa.c
   does not contain objective c code anymore



SVN revision: 39915
This commit is contained in:
Vincent Torri 2009-04-10 06:31:58 +00:00
parent 481bde4366
commit 2045310c43
5 changed files with 134 additions and 248 deletions

View File

@ -179,6 +179,7 @@ AC_ARG_ENABLE(simple-x11,
### Checks for programs ### Checks for programs
have_gnu_objc="no"
m4_ifdef([AC_PROG_OBJC], m4_ifdef([AC_PROG_OBJC],
[ [
AC_PROG_OBJC AC_PROG_OBJC
@ -188,6 +189,7 @@ m4_ifdef([AC_PROG_OBJC],
AC_CHECK_TOOL([OBJC], [gcc]) AC_CHECK_TOOL([OBJC], [gcc])
AC_SUBST([OBJC]) AC_SUBST([OBJC])
AC_SUBST([OBJCFLAGS]) AC_SUBST([OBJCFLAGS])
have_gnu_objc="yes"
]) ])
AC_PROG_CXX AC_PROG_CXX
AC_PROG_CC AC_PROG_CC
@ -593,19 +595,21 @@ AC_CHECK_HEADER([linux/fb.h],
# Quartz header files (ecore_quartz) # Quartz header files (ecore_quartz)
quartz_cflags=""; quartz_ldflags="";
quartz_libs="";
have_quartz="no" have_quartz="no"
AC_CHECK_HEADER([Cocoa/Cocoa.h],
[
have_quartz="yes"
quartz_cflags="-framework Cocoa";
quartz_libs="-framework Cocoa"
],
[have_quartz="no"])
AC_SUBST(quartz_cflags) if test "x${have_gnu_objc}" = "xyes" ; then
AC_SUBST(quartz_libs) AC_LANG_PUSH([Objective C])
AC_CHECK_HEADER([Cocoa/Cocoa.h],
[
have_quartz="yes"
quartz_ldflags="-framework Cocoa"
],
[have_quartz="no"])
AC_LANG_POP([Objective C])
fi
AC_SUBST(quartz_ldflags)
### Checks for types ### Checks for types
AC_CHECK_SIZEOF(int, 4) AC_CHECK_SIZEOF(int, 4)

View File

@ -43,7 +43,7 @@ ECORE_SDL_LIBADD =
endif endif
if BUILD_ECORE_QUARTZ if BUILD_ECORE_QUARTZ
ECORE_QUARTZ_INC = -I$(top_srcdir)/src/lib/ecore_quartz @quartz_cflags@ -xobjective-c ECORE_QUARTZ_INC = -I$(top_srcdir)/src/lib/ecore_quartz -xobjective-c
ECORE_QUARTZ_LIB = $(top_builddir)/src/lib/ecore_quartz/libecore_quartz.la ECORE_QUARTZ_LIB = $(top_builddir)/src/lib/ecore_quartz/libecore_quartz.la
else else
ECORE_QUARTZ_INC = ECORE_QUARTZ_INC =
@ -110,7 +110,7 @@ $(top_builddir)/src/lib/ecore/libecore.la \
$(top_builddir)/src/lib/ecore_input/libecore_input.la \ $(top_builddir)/src/lib/ecore_input/libecore_input.la \
@EVAS_LIBS@ @EVAS_LIBS@
libecore_evas_la_LDFLAGS = -no-undefined @lt_enable_auto_import@ -version-info @version_info@ libecore_evas_la_LDFLAGS = @quartz_ldflags@ -no-undefined @lt_enable_auto_import@ -version-info @version_info@
endif endif

View File

@ -11,6 +11,7 @@
#endif #endif
#include "Ecore.h" #include "Ecore.h"
#include "Ecore_Input.h"
#include "Ecore_Evas.h" #include "Ecore_Evas.h"
#include "ecore_private.h" #include "ecore_private.h"
@ -22,11 +23,11 @@
static int _ecore_evas_init_count = 0; static int _ecore_evas_init_count = 0;
static Ecore_Evas *ecore_evases = NULL; static Ecore_Evas *ecore_evases = NULL;
static Ecore_Event_Handler *ecore_evas_event_handlers[10] = { static Ecore_Event_Handler *ecore_evas_event_handlers[4] = {
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL NULL, NULL, NULL, NULL
}; };
static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL; static Ecore_Idle_Enterer *ecore_evas_idle_enterer = NULL;
static Ecore_Idler *ecore_evas_event = NULL; static Ecore_Poller *ecore_evas_event = NULL;
static const char *ecore_evas_quartz_default = "EFL Quartz"; static const char *ecore_evas_quartz_default = "EFL Quartz";
@ -85,144 +86,6 @@ _ecore_evas_quartz_match(void)
return ecore_evases; return ecore_evases;
} }
static int
_ecore_evas_quartz_event_key_down(void *data __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_Quartz_Event_Key_Down *e;
Ecore_Evas *ee;
e = event;
ee = _ecore_evas_quartz_match();
if (!ee) return 1;
// pass on event
evas_event_feed_key_down(ee->evas, e->keyname, NULL, e->keycompose, NULL, e->time, NULL);
return 0; // dont pass it on
}
static int
_ecore_evas_quartz_event_key_up(void *data __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_Quartz_Event_Key_Up *e;
Ecore_Evas *ee;
e = event;
ee = _ecore_evas_quartz_match();
if (!ee) return 1;
// pass on event
evas_event_feed_key_up(ee->evas, e->keyname, NULL, e->keycompose, NULL, e->time, NULL);
return 0;
}
static int
_ecore_evas_quartz_event_mouse_move(void *data __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_Quartz_Event_Mouse_Move *e;
Ecore_Evas *ee;
e = event;
ee = _ecore_evas_quartz_match();
if (!ee) return 1; // pass on event
NSWindow * win = ((NSWindow*) (e->window));
// Also notify on entering or leaving the window
NSPoint mouseLoc = [win convertBaseToScreen:NSMakePoint(e->x, e->y)];
if(NSPointInRect(mouseLoc, [win frame]))
{
evas_event_feed_mouse_in(ee, 0, NULL);
int w, h;
evas_output_size_get(ee->evas, &w, &h);
e->y = h - e->y;
if (e->y >= 0) // Don't register movement in titlebar!
_ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
}
else
{
evas_event_feed_mouse_out(ee, 0, NULL);
}
return 0;
}
static int
_ecore_evas_quartz_event_button_down(void *data __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_Quartz_Event_Mouse_Button_Down *e;
Ecore_Evas *ee;
Evas_Button_Flags flags;
e = event;
ee = _ecore_evas_quartz_match();
flags = EVAS_BUTTON_NONE;
if (!ee) return 1;
int w, h;
evas_output_size_get(ee->evas, &w, &h);
e->y = h - e->y;
// pass on event
_ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
if (e->y >= 0) // Don't register clicks in titlebar!
evas_event_feed_mouse_down(ee->evas, e->button, flags, e->time, NULL);
return 0;
}
static int
_ecore_evas_quartz_event_button_up(void *data __UNUSED__, int type __UNUSED__, void *event)
{
Ecore_Quartz_Event_Mouse_Button_Up *e;
Ecore_Evas *ee;
Evas_Button_Flags flags;
e = event;
ee = _ecore_evas_quartz_match();
flags = EVAS_BUTTON_NONE;
if (!ee) return 1;
int w, h;
evas_output_size_get(ee->evas, &w, &h);
e->y = h - e->y;
// pass on event
_ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
if (e->double_click) flags |= EVAS_BUTTON_DOUBLE_CLICK;
if (e->triple_click) flags |= EVAS_BUTTON_TRIPLE_CLICK;
if (e->y >= 0) // Don't register clicks in titlebar!
evas_event_feed_mouse_up(ee->evas, e->button, flags, e->time, NULL);
return 0;
}
static int
_ecore_evas_quartz_event_mouse_wheel(void *data __UNUSED__, int type __UNUSED__, void *event)
{
/*Ecore_Quartz_Event_Mouse_Wheel *e;
Ecore_Evas *ee;
e = event;
ee = _ecore_evas_quartz_match();
if (!ee) return 1; // pass on event
_ecore_evas_mouse_move_process(ee, e->x, e->y, e->time);
evas_event_feed_mouse_wheel(ee->evas, e->direction, e->wheel, e->time, NULL);
return 0;*/
}
static int static int
_ecore_evas_quartz_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event) _ecore_evas_quartz_event_got_focus(void *data __UNUSED__, int type __UNUSED__, void *event)
{ {
@ -315,18 +178,13 @@ _ecore_evas_quartz_init(int w, int h)
if (_ecore_evas_init_count > 1) return _ecore_evas_init_count; if (_ecore_evas_init_count > 1) return _ecore_evas_init_count;
ecore_evas_idle_enterer = ecore_idle_enterer_add(_ecore_evas_idle_enter, NULL); ecore_evas_idle_enterer = ecore_idle_enterer_add(_ecore_evas_idle_enter, NULL);
ecore_evas_event = ecore_timer_add(0.008, _ecore_evas_quartz_event, NULL); ecore_evas_event = ecore_poller_add(ECORE_POLLER_CORE, 1, ecore_evas_event, NULL);
ecore_poller_poll_interval_set(ECORE_POLLER_CORE, 0.006);
ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_KEY_DOWN, _ecore_evas_quartz_event_key_down, NULL); ecore_evas_event_handlers[0] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_GOT_FOCUS, _ecore_evas_quartz_event_got_focus, NULL);
ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_KEY_UP, _ecore_evas_quartz_event_key_up, NULL); ecore_evas_event_handlers[1] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_LOST_FOCUS, _ecore_evas_quartz_event_lost_focus, NULL);
ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_MOUSE_BUTTON_DOWN, _ecore_evas_quartz_event_button_down, NULL); ecore_evas_event_handlers[2] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_RESIZE, _ecore_evas_quartz_event_video_resize, NULL);
ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_MOUSE_BUTTON_UP, _ecore_evas_quartz_event_button_up, NULL); ecore_evas_event_handlers[3] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_EXPOSE, _ecore_evas_quartz_event_video_expose, NULL);
ecore_evas_event_handlers[4] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_MOUSE_MOVE, _ecore_evas_quartz_event_mouse_move, NULL);
ecore_evas_event_handlers[5] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_MOUSE_WHEEL, _ecore_evas_quartz_event_mouse_wheel, NULL);
ecore_evas_event_handlers[6] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_GOT_FOCUS, _ecore_evas_quartz_event_got_focus, NULL);
ecore_evas_event_handlers[7] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_LOST_FOCUS, _ecore_evas_quartz_event_lost_focus, NULL);
ecore_evas_event_handlers[8] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_RESIZE, _ecore_evas_quartz_event_video_resize, NULL);
ecore_evas_event_handlers[9] = ecore_event_handler_add(ECORE_QUARTZ_EVENT_EXPOSE, _ecore_evas_quartz_event_video_expose, NULL);
return _ecore_evas_init_count; return _ecore_evas_init_count;
} }
@ -343,10 +201,10 @@ _ecore_evas_quartz_shutdown(void)
for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++) for (i = 0; i < sizeof (ecore_evas_event_handlers) / sizeof (Ecore_Event_Handler*); i++)
ecore_event_handler_del(ecore_evas_event_handlers[i]); ecore_event_handler_del(ecore_evas_event_handlers[i]);
ecore_event_evas_shutdown();
ecore_idle_enterer_del(ecore_evas_idle_enterer); ecore_idle_enterer_del(ecore_evas_idle_enterer);
ecore_evas_idle_enterer = NULL; ecore_evas_idle_enterer = NULL;
ecore_timer_del(ecore_evas_event); ecore_poller_del(ecore_evas_event);
ecore_evas_event = NULL; ecore_evas_event = NULL;
} }
if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0; if (_ecore_evas_init_count < 0) _ecore_evas_init_count = 0;
@ -357,6 +215,7 @@ static void
_ecore_evas_quartz_free(Ecore_Evas *ee) _ecore_evas_quartz_free(Ecore_Evas *ee)
{ {
ecore_evases = _ecore_list2_remove(ecore_evases, ee); ecore_evases = _ecore_list2_remove(ecore_evases, ee);
ecore_event_window_unregister(0);
_ecore_evas_quartz_shutdown(); _ecore_evas_quartz_shutdown();
ecore_quartz_shutdown(); ecore_quartz_shutdown();
} }
@ -478,7 +337,6 @@ static const Ecore_Evas_Engine_Func _ecore_quartz_engine_func =
NULL, NULL,
NULL, NULL,
NULL, NULL,
NULL,
NULL NULL
}; };
#endif #endif
@ -500,16 +358,21 @@ ecore_evas_quartz_new(const char* name, int w, int h)
if (!ecore_quartz_init(name)) return NULL; if (!ecore_quartz_init(name)) return NULL;
ee = calloc(1, sizeof(Ecore_Evas)); ee = calloc(1, sizeof(Ecore_Evas));
if (!ee) return NULL; if (!ee)
goto shutdown_ecore_quartz;
ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS); ECORE_MAGIC_SET(ee, ECORE_MAGIC_EVAS);
_ecore_evas_quartz_init(w, h); _ecore_evas_quartz_init(w, h);
ecore_event_window_register(0, ee, ee->evas, _ecore_evas_mouse_move_process);
ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_quartz_engine_func; ee->engine.func = (Ecore_Evas_Engine_Func *)&_ecore_quartz_engine_func;
ee->driver = "quartz"; ee->driver = "quartz";
if (name) ee->name = strdup(name); if (name) ee->name = strdup(name);
if (!ee->name)
goto free_ee;
if (w < 1) w = 1; if (w < 1) w = 1;
if (h < 1) h = 1; if (h < 1) h = 1;
@ -529,6 +392,8 @@ ecore_evas_quartz_new(const char* name, int w, int h)
// init evas here // init evas here
ee->evas = evas_new(); ee->evas = evas_new();
if (!ee->evas)
goto free_name;
evas_data_attach_set(ee->evas, ee); evas_data_attach_set(ee->evas, ee);
evas_output_method_set(ee->evas, rmethod); evas_output_method_set(ee->evas, rmethod);
@ -545,6 +410,7 @@ ecore_evas_quartz_new(const char* name, int w, int h)
// Create our main window, and embed an EvasView in it // Create our main window, and embed an EvasView in it
main_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,w,h) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) backing:NSBackingStoreBuffered defer:NO screen:nil]; main_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0,0,w,h) styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask) backing:NSBackingStoreBuffered defer:NO screen:nil];
/* FIXME: manage the case where main_window is NULL witht a goto free_evas; */
[main_window makeKeyAndOrderFront:NSApp]; [main_window makeKeyAndOrderFront:NSApp];
[main_window setTitle:[NSString stringWithUTF8String:name]]; [main_window setTitle:[NSString stringWithUTF8String:name]];
[main_window makeMainWindow]; [main_window makeMainWindow];
@ -561,26 +427,30 @@ ecore_evas_quartz_new(const char* name, int w, int h)
evas_output_viewport_set(ee->evas, 0, 0, w, h); evas_output_viewport_set(ee->evas, 0, 0, w, h);
einfo = (Evas_Engine_Info_Quartz*) evas_engine_info_get(ee->evas); einfo = (Evas_Engine_Info_Quartz*) evas_engine_info_get(ee->evas);
if (einfo) if (!einfo)
{ goto free_window;
einfo->info.context = [[evas_view context] retain];
evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
}
evas_key_modifier_add(ee->evas, "Shift"); einfo->info.context = [[evas_view context] retain];
evas_key_modifier_add(ee->evas, "Control"); evas_engine_info_set(ee->evas, (Evas_Engine_Info *)einfo);
evas_key_modifier_add(ee->evas, "Alt");
evas_key_modifier_add(ee->evas, "Meta");
evas_key_modifier_add(ee->evas, "Hyper");
evas_key_modifier_add(ee->evas, "Super");
evas_key_lock_add(ee->evas, "Caps_Lock");
evas_key_lock_add(ee->evas, "Num_Lock");
evas_key_lock_add(ee->evas, "Scroll_Lock");
evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL); evas_event_feed_mouse_in(ee->evas, (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff), NULL);
ecore_evases = _ecore_list2_prepend(ecore_evases, ee); ecore_evases = _ecore_list2_prepend(ecore_evases, ee);
return ee; return ee;
free_window:
/* FIXME: free window here */
free_evas:
free(ee->evas);
free_name:
free(ee->name);
free_ee:
_ecore_evas_quartz_shutdown();
free(ee);
shutdown_ecore_quartz:
ecore_quartz_shutdown();
return NULL;
#else #else
fprintf(stderr, "OUTCH !\n"); fprintf(stderr, "OUTCH !\n");
return NULL; return NULL;

View File

@ -2,8 +2,10 @@ MAINTAINERCLEANFILES = Makefile.in
AM_CPPFLAGS = \ AM_CPPFLAGS = \
-I$(top_srcdir)/src/lib/ecore \ -I$(top_srcdir)/src/lib/ecore \
-I$(top_srcdir)/src/lib/ecore_input \
-I$(top_builddir)/src/lib/ecore \ -I$(top_builddir)/src/lib/ecore \
@quartz_cflags@ \ -I$(top_builddir)/src/lib/ecore_input \
@EVAS_CFLAGS@ \
@EINA_CFLAGS@ @EINA_CFLAGS@
if BUILD_ECORE_QUARTZ if BUILD_ECORE_QUARTZ
@ -17,9 +19,10 @@ ecore_quartz.m
libecore_quartz_la_LIBADD = \ libecore_quartz_la_LIBADD = \
$(top_builddir)/src/lib/ecore/libecore.la \ $(top_builddir)/src/lib/ecore/libecore.la \
@quartz_libs@ \ $(top_builddir)/src/lib/ecore_input/libecore_input.la \
@EVAS_LIBS@ \
@EINA_LIBS@ @EINA_LIBS@
libecore_quartz_la_LDFLAGS = -version-info @version_info@ libecore_quartz_la_LDFLAGS = @quartz_ldflags@ -version-info @version_info@
endif endif

View File

@ -4,18 +4,15 @@
#include <Cocoa/Cocoa.h> #include <Cocoa/Cocoa.h>
#include <Eina.h>
#include <ecore_private.h>
#include <Ecore.h>
#include <Ecore_Input.h>
#include "Ecore_Quartz.h" #include "Ecore_Quartz.h"
#include "ecore_private.h"
#include "Ecore.h"
#include "Ecore_Data.h"
#include "Ecore_Quartz_Keys.h" #include "Ecore_Quartz_Keys.h"
EAPI int ECORE_QUARTZ_EVENT_KEY_DOWN = 0;
EAPI int ECORE_QUARTZ_EVENT_KEY_UP = 0;
EAPI int ECORE_QUARTZ_EVENT_MOUSE_BUTTON_DOWN = 0;
EAPI int ECORE_QUARTZ_EVENT_MOUSE_BUTTON_UP = 0;
EAPI int ECORE_QUARTZ_EVENT_MOUSE_MOVE = 0;
EAPI int ECORE_QUARTZ_EVENT_MOUSE_WHEEL = 0;
EAPI int ECORE_QUARTZ_EVENT_GOT_FOCUS = 0; EAPI int ECORE_QUARTZ_EVENT_GOT_FOCUS = 0;
EAPI int ECORE_QUARTZ_EVENT_LOST_FOCUS = 0; EAPI int ECORE_QUARTZ_EVENT_LOST_FOCUS = 0;
EAPI int ECORE_QUARTZ_EVENT_RESIZE = 0; EAPI int ECORE_QUARTZ_EVENT_RESIZE = 0;
@ -28,20 +25,17 @@ static int old_flags;
EAPI int EAPI int
ecore_quartz_init(const char *name __UNUSED__) ecore_quartz_init(const char *name __UNUSED__)
{ {
if (!_ecore_quartz_init_count) if (!_ecore_quartz_init_count)
{ {
ECORE_QUARTZ_EVENT_KEY_DOWN = ecore_event_type_new(); ECORE_QUARTZ_EVENT_GOT_FOCUS = ecore_event_type_new();
ECORE_QUARTZ_EVENT_KEY_UP = ecore_event_type_new(); ECORE_QUARTZ_EVENT_LOST_FOCUS = ecore_event_type_new();
ECORE_QUARTZ_EVENT_MOUSE_BUTTON_DOWN = ecore_event_type_new(); ECORE_QUARTZ_EVENT_RESIZE = ecore_event_type_new();
ECORE_QUARTZ_EVENT_MOUSE_BUTTON_UP = ecore_event_type_new(); ECORE_QUARTZ_EVENT_EXPOSE = ecore_event_type_new();
ECORE_QUARTZ_EVENT_MOUSE_MOVE = ecore_event_type_new(); }
ECORE_QUARTZ_EVENT_MOUSE_WHEEL = ecore_event_type_new();
ECORE_QUARTZ_EVENT_GOT_FOCUS = ecore_event_type_new(); ecore_event_init();
ECORE_QUARTZ_EVENT_LOST_FOCUS = ecore_event_type_new();
ECORE_QUARTZ_EVENT_RESIZE = ecore_event_type_new(); return ++_ecore_quartz_init_count;
ECORE_QUARTZ_EVENT_EXPOSE = ecore_event_type_new();
}
return ++_ecore_quartz_init_count;
} }
/** /**
@ -53,8 +47,11 @@ ecore_quartz_init(const char *name __UNUSED__)
EAPI int EAPI int
ecore_quartz_shutdown(void) ecore_quartz_shutdown(void)
{ {
_ecore_quartz_init_count--; _ecore_quartz_init_count--;
return _ecore_quartz_init_count;
ecore_event_shutdown();
return _ecore_quartz_init_count;
} }
EAPI void EAPI void
@ -77,13 +74,17 @@ ecore_quartz_feed_events(void)
case NSRightMouseDragged: case NSRightMouseDragged:
case NSOtherMouseDragged: case NSOtherMouseDragged:
{ {
Ecore_Quartz_Event_Mouse_Move * ev = malloc(sizeof(Ecore_Quartz_Event_Mouse_Move)); Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move));
if (!ev) return;
ev->x = [event locationInWindow].x; ev->x = [event locationInWindow].x;
ev->y = [event locationInWindow].y; ev->y = [event locationInWindow].y;
ev->time = time; ev->root.x = ev->x;
ev->root.y = ev->y;
ev->timestamp = time;
ev->window = [event window]; ev->window = [event window];
ev->modifiers = 0; /* FIXME: keep modifier around. */
ecore_event_add(ECORE_QUARTZ_EVENT_MOUSE_MOVE, ev, NULL, NULL); ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
[NSApp sendEvent:event]; // pass along mouse events, for window manager [NSApp sendEvent:event]; // pass along mouse events, for window manager
break; break;
@ -92,10 +93,14 @@ ecore_quartz_feed_events(void)
case NSRightMouseDown: case NSRightMouseDown:
case NSOtherMouseDown: case NSOtherMouseDown:
{ {
Ecore_Quartz_Event_Mouse_Button_Down * ev = malloc(sizeof(Ecore_Quartz_Event_Mouse_Button_Down)); Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
if (!ev) return;
ev->x = [event locationInWindow].x; ev->x = [event locationInWindow].x;
ev->y = [event locationInWindow].y; ev->y = [event locationInWindow].y;
ev->button = [event buttonNumber] + 1; // Apple indexes buttons from 0 ev->root.x = ev->x;
ev->root.y = ev->y;
ev->timestamp = time;
ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0
if ([event clickCount] == 2) if ([event clickCount] == 2)
ev->double_click = 1; ev->double_click = 1;
@ -107,9 +112,7 @@ ecore_quartz_feed_events(void)
else else
ev->triple_click = 0; ev->triple_click = 0;
ev->time = time; ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
ecore_event_add(ECORE_QUARTZ_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
[NSApp sendEvent:event]; // pass along mouse events, for window manager [NSApp sendEvent:event]; // pass along mouse events, for window manager
break; break;
@ -118,10 +121,14 @@ ecore_quartz_feed_events(void)
case NSRightMouseUp: case NSRightMouseUp:
case NSOtherMouseUp: case NSOtherMouseUp:
{ {
Ecore_Quartz_Event_Mouse_Button_Up * ev = malloc(sizeof(Ecore_Quartz_Event_Mouse_Button_Up)); Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
if (!ev) return;
ev->x = [event locationInWindow].x; ev->x = [event locationInWindow].x;
ev->y = [event locationInWindow].y; ev->y = [event locationInWindow].y;
ev->button = [event buttonNumber] + 1; // Apple indexes buttons from 0 ev->root.x = ev->x;
ev->root.y = ev->y;
ev->timestamp = time;
ev->buttons = [event buttonNumber] + 1; // Apple indexes buttons from 0
if ([event clickCount] == 2) if ([event clickCount] == 2)
ev->double_click = 1; ev->double_click = 1;
@ -133,71 +140,73 @@ ecore_quartz_feed_events(void)
else else
ev->triple_click = 0; ev->triple_click = 0;
ev->time = time; ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
ecore_event_add(ECORE_QUARTZ_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
[NSApp sendEvent:event]; // pass along mouse events, for window manager [NSApp sendEvent:event]; // pass along mouse events, for window manager
break; break;
} }
case NSKeyDown: case NSKeyDown:
{ {
Ecore_Quartz_Event_Key_Down *ev; Ecore_Event_Key *ev;
unsigned int i; unsigned int i;
ev = malloc(sizeof (Ecore_Quartz_Event_Key_Down)); ev = calloc(1, sizeof (Ecore_Event_Key));
ev->time = time; if (!ev) return;
ev->timestamp = time;
for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_quartz_keys_s); ++i) for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_quartz_keys_s); ++i)
{ {
if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0]))
{ {
ev->keyname = keystable[i].name; ev->keyname = keystable[i].name;
ev->keycompose = keystable[i].compose; ev->string = keystable[i].compose;
ecore_event_add(ECORE_QUARTZ_EVENT_KEY_DOWN, ev, NULL, NULL); ecore_event_add(ECORE_EVENT_KEY_DOWN, ev, NULL, NULL);
return; return;
} }
} }
free(ev);
break; break;
} }
case NSKeyUp: case NSKeyUp:
{ {
Ecore_Quartz_Event_Key_Up *ev; Ecore_Event_Key *ev;
unsigned int i; unsigned int i;
ev = malloc(sizeof (Ecore_Quartz_Event_Key_Up)); ev = calloc(1, sizeof (Ecore_Quartz_Event_Key_Up));
ev->time = time; if (!ev) return;
ev->timestamp = time;
for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_quartz_keys_s); ++i) for (i = 0; i < sizeof (keystable) / sizeof (struct _ecore_quartz_keys_s); ++i)
{ {
if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0])) if (keystable[i].code == tolower([[event charactersIgnoringModifiers] characterAtIndex:0]))
{ {
ev->keyname = keystable[i].name; ev->keyname = keystable[i].name;
ev->keycompose = keystable[i].compose; ev->string = keystable[i].compose;
ecore_event_add(ECORE_QUARTZ_EVENT_KEY_UP, ev, NULL, NULL); ecore_event_add(ECORE_EVENT_KEY_UP, ev, NULL, NULL);
return; return;
} }
} }
free(ev);
break; break;
} }
case NSFlagsChanged: case NSFlagsChanged:
{ {
int flags = [event modifierFlags]; int flags = [event modifierFlags];
Ecore_Quartz_Event_Key_Down *evDown = NULL; Ecore_Event_Key *evDown = NULL;
Ecore_Quartz_Event_Key_Up *evUp = NULL; Ecore_Event_Key *evUp = NULL;
evDown = malloc(sizeof (Ecore_Quartz_Event_Key_Down)); evDown = calloc(1, sizeof (Ecore_Quartz_Event_Key_Down));
evDown->keyname = NULL; if (!evDown) return;
evUp = malloc(sizeof (Ecore_Quartz_Event_Key_Up)); evUp = calloc(1, sizeof (Ecore_Quartz_Event_Key_Up));
evUp->keyname = NULL; if (!evUp)
{
free(evDown);
return;
}
// Turn special key flags on // Turn special key flags on
if (flags & NSShiftKeyMask) if (flags & NSShiftKeyMask)
@ -213,8 +222,8 @@ ecore_quartz_feed_events(void)
if (evDown->keyname) if (evDown->keyname)
{ {
evDown->time = time; evDown->timestamp = time;
evDown->keycompose = ""; evDown->string = "";
ecore_event_add(ECORE_QUARTZ_EVENT_KEY_DOWN, evDown, NULL, NULL); ecore_event_add(ECORE_QUARTZ_EVENT_KEY_DOWN, evDown, NULL, NULL);
old_flags = flags; old_flags = flags;
break; break;
@ -236,8 +245,8 @@ ecore_quartz_feed_events(void)
if (evUp->keyname) if (evUp->keyname)
{ {
evUp->time = time; evUp->timestamp = time;
evUp->keycompose = ""; evUp->string = "";
ecore_event_add(ECORE_QUARTZ_EVENT_KEY_UP, evUp, NULL, NULL); ecore_event_add(ECORE_QUARTZ_EVENT_KEY_UP, evUp, NULL, NULL);
old_flags = flags; old_flags = flags;
break; break;