From 1321999aec92a1e66559874a1e16e9eda4d76851 Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Tue, 3 Nov 2020 12:09:31 +0100 Subject: [PATCH] VST3: macOS key forwarding --- gtk2_ardour/vst3_nsview_plugin_ui.h | 2 ++ gtk2_ardour/vst3_nsview_plugin_ui.mm | 19 +++++++++++++++++++ gtk2_ardour/vst3_plugin_ui.cc | 9 ++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/gtk2_ardour/vst3_nsview_plugin_ui.h b/gtk2_ardour/vst3_nsview_plugin_ui.h index dec8f5b52d..514496fac7 100644 --- a/gtk2_ardour/vst3_nsview_plugin_ui.h +++ b/gtk2_ardour/vst3_nsview_plugin_ui.h @@ -48,7 +48,9 @@ public: bool on_window_show(const std::string&); void on_window_hide (); + void forward_key_event (GdkEventKey*); void grab_focus(); + bool non_gtk_gui() const { return true; } private: void view_realized (); diff --git a/gtk2_ardour/vst3_nsview_plugin_ui.mm b/gtk2_ardour/vst3_nsview_plugin_ui.mm index 8498e5defa..6ce1a07a9b 100644 --- a/gtk2_ardour/vst3_nsview_plugin_ui.mm +++ b/gtk2_ardour/vst3_nsview_plugin_ui.mm @@ -219,6 +219,25 @@ VST3NSViewPluginUI::on_window_hide () hide_all (); } +void +VST3NSViewPluginUI::forward_key_event (GdkEventKey* ev) +{ + /* despite the VST3 spec mandating onKeyUp/Down, many + * plugins (notably JUCE) reply on platform callbacks. + */ + NSEvent* nsevent = gdk_quartz_event_get_nsevent ((GdkEvent*)ev); + if (!nsevent) { + return; + } + if ([nsevent type] == NSKeyDown) { + [[[_ns_view window] firstResponder] keyDown:nsevent]; + } else if ([nsevent type] == NSKeyUp) { + [[[_ns_view window] firstResponder] keyUp:nsevent]; + } else if ([nsevent type] == NSFlagsChanged) { + [[[_ns_view window] firstResponder] flagsChanged:nsevent]; + } +} + void VST3NSViewPluginUI::grab_focus () { diff --git a/gtk2_ardour/vst3_plugin_ui.cc b/gtk2_ardour/vst3_plugin_ui.cc index c0ece21086..db21de7d2e 100644 --- a/gtk2_ardour/vst3_plugin_ui.cc +++ b/gtk2_ardour/vst3_plugin_ui.cc @@ -90,7 +90,7 @@ VST3PluginUI::resizable () bool VST3PluginUI::non_gtk_gui() const { - // return true to enable forward_key_event + /* return true to enable forward_key_event */ return false; } @@ -134,11 +134,14 @@ VST3PluginUI::parameter_update () void VST3PluginUI::forward_key_event (GdkEventKey* ev) { -#if 0 + /* NB VST3NSViewPluginUI overrides this */ +#if 0 // -> non_gtk_gui () -> true + // TODO: map key-events IPlugView* view = _vst3->view (); switch (gdk_key->type) { case GDK_KEY_PRESS: - /* key: unicode code of key + /* onKeyDown (char16 key, int16 keyCode, int16 modifiers) + * key: unicode code of key * keyCode: virtual keycode for non ascii keys - see VirtualKeyCodes in keycodes.h * modifiers : any combination of modifiers - see KeyModifier in keycodes.h */