Repository navigation
Closed
Milestone
Description
I'm one of the developers of REAPER. There is an issue where plug-is that use nih-plug and egui (which afaict uses baseview) do not set their NSViews as first responder on mouse click. On most other DAWs this is not an issue, as the NSView is often the only view in the NSWindow, however in REAPER it does present some issues.
I have written some suggested code that should fix for macOS, which compiles, but due to my unfamiliarity with the Cargo ecosystem I haven't been able to get it into the actual resulting binary.
diff --git a/src/macos/view.rs b/src/macos/view.rs
index 8b765b4..a970b33 100644
--- a/src/macos/view.rs
+++ b/src/macos/view.rs
@@ -54,12 +54,18 @@ macro_rules! add_simple_mouse_class_method {
/// Similar to [add_simple_mouse_class_method!], but this creates its own event object for the
/// press/release event and adds the active modifier keys to that event.
macro_rules! add_mouse_button_class_method {
- ($class:ident, $sel:ident, $event_ty:ident, $button:expr) => {
+ ($class:ident, $sel:ident, $event_ty:ident, $button:expr, $foc:expr) => {
#[allow(non_snake_case)]
extern "C" fn $sel(this: &Object, _: Sel, event: id){
let state = unsafe { WindowState::from_view(this) };
let modifiers = unsafe { NSEvent::modifierFlags(event) };
+ if $foc {
+ unsafe {
+ let window: id = msg_send![this, window];
+ let _: () = msg_send![window, makeFirstResponder: this];
+ }
+ }
state.trigger_event(Event::Mouse($event_ty {
button: $button,
@@ -211,12 +217,12 @@ unsafe fn create_view_class() -> &'static Class {
handle_notification as extern "C" fn(&Object, Sel, id),
);
- add_mouse_button_class_method!(class, mouseDown, ButtonPressed, MouseButton::Left);
- add_mouse_button_class_method!(class, mouseUp, ButtonReleased, MouseButton::Left);
- add_mouse_button_class_method!(class, rightMouseDown, ButtonPressed, MouseButton::Right);
- add_mouse_button_class_method!(class, rightMouseUp, ButtonReleased, MouseButton::Right);
- add_mouse_button_class_method!(class, otherMouseDown, ButtonPressed, MouseButton::Middle);
- add_mouse_button_class_method!(class, otherMouseUp, ButtonReleased, MouseButton::Middle);
+ add_mouse_button_class_method!(class, mouseDown, ButtonPressed, MouseButton::Left, true);
+ add_mouse_button_class_method!(class, mouseUp, ButtonReleased, MouseButton::Left, false);
+ add_mouse_button_class_method!(class, rightMouseDown, ButtonPressed, MouseButton::Right, true);
+ add_mouse_button_class_method!(class, rightMouseUp, ButtonReleased, MouseButton::Right, false);
+ add_mouse_button_class_method!(class, otherMouseDown, ButtonPressed, MouseButton::Middle, true);
+ add_mouse_button_class_method!(class, otherMouseUp, ButtonReleased, MouseButton::Middle, false);
add_simple_mouse_class_method!(class, mouseEntered, MouseEvent::CursorEntered);
add_simple_mouse_class_method!(class, mouseExited, MouseEvent::CursorLeft);
Thanks for looking at this!
Reacted by Matthias Kronlachner
Metadata
Metadata
Assignees
Labels
No labels
Activity
peastman commentedon Feb 11, 2025
I can confirm this change works, and it fixes the problem in #169. It would be great if we could get it into a release.
dathinaios commentedon Mar 18, 2025
I believe this is related to #152
Which has been resolved in: #170
But also requires the change in the respective GUI. Latest Vizia should be working (haven't tested but maybe @geom3trik can confirm) but nih_plug uses an old version as of now. I am still using the implementation/temp workaround from vizia/vizia#463 and it is working fine.
Finally, it should be noted that these changes do not resolve the input focus issue in all DAWs. Specifically the issue is still present on Ableton Live for Windows and I believe Studio One on Windows. Reaper and Bitwig are working fine in both OSs as far as I can tell.
peastman commentedon Mar 19, 2025
#170 doesn't fix it for me. My plugin uses NIH-Plug and egui. When I build all dependencies from source and use the most recent baseview code, keyboard input is still broken in Reaper. But if I add the patch above, it does work.
dathinaios commentedon Mar 19, 2025
The solution is two-fold. #170 provided the interface for focusing the window but it is the responsibility of the GUI (in your case egui) to call it when it is required. So you would need to make a change in egui to implement it. Don't get me wrong, if the workaround is working for you you might want to just go with it until all these things are properly resolved. I personally had to use modified versions of
baseview,viziaandnih-plugand I am getting a headache.. So if I had this solution I might have gone with it. But I don't think it is going to be added as is tobaseviewbecause it is triggered in every mouse click which is incorrect.By the way, are you on windows by any chance? Do you know if the above addition fixes keyboard input on Ableton Live?
peastman commentedon Mar 19, 2025
I'm on Mac.
Does the change need to be made in egui itself, or in egui-baseview, or in NIH-Plug? Can you describe what the required change is?
dathinaios commentedon Mar 19, 2025
Probably
egui-baseviewbut I don't know anything aboutegui. As to the required change it will be that a component wold request focus when necessary. With Vizia I have just added it on alt-click on the slider but Vizia's author has, I believe, used a better design for the final fix (which I haven't tried cause it is not synced with nih_plug yet).peastman commentedon Mar 19, 2025
Do you have a link to the changes in Vizia?
dathinaios commentedon Mar 19, 2025
I am using the workaround I mentioned above: #202 (comment)
Current Vizia version is doing something different. Not sure what.
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
fix(macos): override hitTest: so first click in non-key window reache…
dathinaios commentedon May 3, 2026
Has this been solved by b519246?
dathinaios commentedon May 3, 2026
Tested with the gain example ( BillyDM 's
nih_plugfork at https://github.com/BillyDM/nih-plug) and currentbaseviewmaster.Keyboard focus / mouse click focus seem to be working fine. If there are specific steps to reproduce just let me know and I am happy to test further.
prokopyl commentedon May 3, 2026
It does seem that b519246 fixed the issue indeed.
I have tested various plugins from BillyDM's fork of NIH-plug (with current
baseviewmaster), on macOS 26.2, as CLAP/VST3 in Reaper, Bitwig & theclack-host-cpalexample, and I couldn't find focus issues.I am going to close this issue for now. But if anyone still has the issue, feel free to comment here, and I will consider reopening this (or opening another issue if that ends up being more appropriate).