summaryrefslogtreecommitdiffstats
path: root/src/cocoa_in_gtk2.mm
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2015-02-22 15:43:41 +0000
committerDavid Robillard <d@drobilla.net>2015-02-22 15:43:41 +0000
commit37efb28df8049cb291746db272fd83fb3cf079ec (patch)
tree687161c4a2d175de084167fab1bb3712d97248d8 /src/cocoa_in_gtk2.mm
parent56ebb4e326314495f242a7615ebf7715d0927c2e (diff)
downloadsuil-37efb28df8049cb291746db272fd83fb3cf079ec.tar.gz
suil-37efb28df8049cb291746db272fd83fb3cf079ec.tar.bz2
suil-37efb28df8049cb291746db272fd83fb3cf079ec.zip
Fix keyboard events on OSX (patch from Robin Gareus).
git-svn-id: http://svn.drobilla.net/lad/trunk/suil@5601 a436a847-0d15-0410-975c-d299462d15a1
Diffstat (limited to 'src/cocoa_in_gtk2.mm')
-rw-r--r--src/cocoa_in_gtk2.mm61
1 files changed, 41 insertions, 20 deletions
diff --git a/src/cocoa_in_gtk2.mm b/src/cocoa_in_gtk2.mm
index 2ab0f66..09ca883 100644
--- a/src/cocoa_in_gtk2.mm
+++ b/src/cocoa_in_gtk2.mm
@@ -137,8 +137,7 @@ suil_cocoa_size_allocate(GtkWidget* widget, GtkAllocation* allocation)
gtk_widget_get_parent(widget), widget, 0, 0, &xx, &yy);
NSView* view = (NSView*)self->instance->ui_widget;
- [view setFrame:NSMakeRect(xx, yy,
- self->alo_width, self->alo_height)];
+ [view setFrame:NSMakeRect(xx, yy, self->alo_width, self->alo_height)];
}
static void
@@ -157,8 +156,7 @@ suil_cocoa_map(GtkWidget* widget)
NSView* view = (NSView*)self->instance->ui_widget;
[view setHidden:NO];
- [view setFrame:NSMakeRect(xx, yy,
- self->alo_width, self->alo_height)];
+ [view setFrame:NSMakeRect(xx, yy, self->alo_width, self->alo_height)];
}
static void
@@ -172,6 +170,32 @@ suil_cocoa_unmap(GtkWidget* widget)
}
static gboolean
+suil_cocoa_key_press(GtkWidget* widget, GdkEventKey* event)
+{
+ SuilCocoaWrapper* const self = SUIL_COCOA_WRAPPER(widget);
+ if (!self->instance || !self->wrapper || !self->wrapper->impl) {
+ return FALSE;
+ }
+ NSEvent* nsevent = gdk_quartz_event_get_nsevent((GdkEvent*)event);
+ NSView* view = (NSView*)self->instance->ui_widget;
+ [view keyDown:nsevent];
+ return TRUE;
+}
+
+static gboolean
+suil_cocoa_key_release(GtkWidget* widget, GdkEventKey* event)
+{
+ SuilCocoaWrapper* const self = SUIL_COCOA_WRAPPER(widget);
+ if (!self->instance || !self->wrapper || !self->wrapper->impl) {
+ return FALSE;
+ }
+ NSEvent* nsevent = gdk_quartz_event_get_nsevent((GdkEvent*)event);
+ NSView* view = (NSView*)self->instance->ui_widget;
+ [view keyUp:nsevent];
+ return TRUE;
+}
+
+static gboolean
suil_cocoa_expose(GtkWidget* widget, GdkEventExpose* event)
{
SuilCocoaWrapper* const self = SUIL_COCOA_WRAPPER(widget);
@@ -191,12 +215,14 @@ suil_cocoa_wrapper_class_init(SuilCocoaWrapperClass* klass)
gobject_class->finalize = suil_cocoa_wrapper_finalize;
- widget_class->realize = suil_cocoa_realize;
- widget_class->expose_event = suil_cocoa_expose;
- widget_class->size_request = suil_cocoa_size_request;
- widget_class->size_allocate = suil_cocoa_size_allocate;
- widget_class->map = suil_cocoa_map;
- widget_class->unmap = suil_cocoa_unmap;
+ widget_class->realize = suil_cocoa_realize;
+ widget_class->expose_event = suil_cocoa_expose;
+ widget_class->size_request = suil_cocoa_size_request;
+ widget_class->size_allocate = suil_cocoa_size_allocate;
+ widget_class->map = suil_cocoa_map;
+ widget_class->unmap = suil_cocoa_unmap;
+ widget_class->key_press_event = suil_cocoa_key_press;
+ widget_class->key_release_event = suil_cocoa_key_release;
}
static void
@@ -222,7 +248,7 @@ wrapper_resize(LV2UI_Feature_Handle handle, int width, int height)
wrap->req_width = width;
wrap->req_height = height;
wrap->custom_size = true;
- gtk_widget_queue_resize (GTK_WIDGET (handle));
+ gtk_widget_queue_resize(GTK_WIDGET(handle));
return 0;
}
@@ -248,12 +274,6 @@ event_filter(GdkXEvent* xevent, GdkEvent* event, gpointer data)
NSView* view = (NSView*)wrap->instance->ui_widget;
if (view && nsevent) {
switch([nsevent type]) {
- case NSKeyDown:
- [view keyDown:nsevent];
- return GDK_FILTER_REMOVE;
- case NSKeyUp:
- [view keyUp:nsevent];
- return GDK_FILTER_REMOVE;
case NSFlagsChanged:
[view flagsChanged:nsevent];
return GDK_FILTER_REMOVE;
@@ -311,7 +331,8 @@ wrapper_wrap(SuilWrapper* wrapper, SuilInstance* instance)
}
if (idle_iface) {
wrap->idle_iface = idle_iface;
- wrap->idle_id = g_timeout_add (wrap->idle_ms, suil_cocoa_wrapper_idle, wrap);
+ wrap->idle_id = g_timeout_add(
+ wrap->idle_ms, suil_cocoa_wrapper_idle, wrap);
}
#endif
return 0;
@@ -388,9 +409,9 @@ suil_wrapper_new(SuilHost* host,
LV2_Options_Option* options = NULL;
for (LV2_Feature** f = *features; *f && (!map || !options); ++f) {
if (!strcmp((*f)->URI, LV2_OPTIONS__options)) {
- options = (LV2_Options_Option *)(*f)->data;
+ options = (LV2_Options_Option*)(*f)->data;
} else if (!strcmp((*f)->URI, LV2_URID__map)) {
- map = (LV2_URID_Map *)(*f)->data;
+ map = (LV2_URID_Map*)(*f)->data;
}
}