From 88cbe3aa9e6561bbda80126c485104d603f3df92 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Thu, 17 Mar 2022 18:16:23 +0100 Subject: [PATCH] Set modifiers on baseview mouse events Using the changes from https://github.com/RustAudio/baseview/pull/117. Until baseview implements proper keyboard focus handling this helps when dragging a knob or slider outside of the window. Otherwise the modifier state may get stuck on an incorrect value. --- baseview/Cargo.toml | 2 +- baseview/src/application.rs | 33 ++++++++++++++++++++++++++++----- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/baseview/Cargo.toml b/baseview/Cargo.toml index 72e6e6a17..e00fecce8 100644 --- a/baseview/Cargo.toml +++ b/baseview/Cargo.toml @@ -10,7 +10,7 @@ description = "Baseview backend for vizia" [dependencies] vizia_core = { path = "../core" } -baseview = { git = "https://github.com/RustAudio/baseview.git", rev = "b3712638bacb3fdf2883cb5aa3f6caed0e91ac8c", features = ["opengl"] } +baseview = { git = "https://github.com/robbert-vdh/baseview.git", branch = "feature/mouse-event-modifiers", features = ["opengl"] } keyboard-types = { version = "0.6.2", default-features = false } raw-window-handle = "0.4" femtovg = {version = "0.3.0", default-features = false} diff --git a/baseview/src/application.rs b/baseview/src/application.rs index af95e8ed5..2e53a8cdf 100644 --- a/baseview/src/application.rs +++ b/baseview/src/application.rs @@ -288,21 +288,29 @@ impl ApplicationRunner { match event { baseview::Event::Mouse(event) => match event { - baseview::MouseEvent::CursorMoved { position } => { + baseview::MouseEvent::CursorMoved { position, modifiers } => { + self.update_modifiers(modifiers); + let cursorx = (position.x) as f32; let cursory = (position.y) as f32; self.context.dispatch_system_event(WindowEvent::MouseMove(cursorx, cursory)); } - baseview::MouseEvent::ButtonPressed(button) => { + baseview::MouseEvent::ButtonPressed { button, modifiers } => { + self.update_modifiers(modifiers); + let b = translate_mouse_button(button); self.context.dispatch_system_event(WindowEvent::MouseDown(b)); } - baseview::MouseEvent::ButtonReleased(button) => { + baseview::MouseEvent::ButtonReleased { button, modifiers } => { + self.update_modifiers(modifiers); + let b = translate_mouse_button(button); self.context.dispatch_system_event(WindowEvent::MouseUp(b)); } - baseview::MouseEvent::WheelScrolled(scroll_delta) => { - let (lines_x, lines_y) = match scroll_delta { + baseview::MouseEvent::WheelScrolled { delta, modifiers } => { + self.update_modifiers(modifiers); + + let (lines_x, lines_y) = match delta { baseview::ScrollDelta::Lines { x, y } => (x, y), baseview::ScrollDelta::Pixels { x, y } => ( if x < 0.0 { @@ -446,6 +454,21 @@ impl ApplicationRunner { (idle_callback)(&mut self.context); } } + + fn update_modifiers(&mut self, modifiers: keyboard_types::Modifiers) { + self.context + .modifiers + .set(Modifiers::SHIFT, modifiers.contains(keyboard_types::Modifiers::SHIFT)); + self.context + .modifiers + .set(Modifiers::CTRL, modifiers.contains(keyboard_types::Modifiers::CONTROL)); + self.context + .modifiers + .set(Modifiers::LOGO, modifiers.contains(keyboard_types::Modifiers::META)); + self.context + .modifiers + .set(Modifiers::ALT, modifiers.contains(keyboard_types::Modifiers::ALT)); + } } /// Returns true if the provided event should cause an [`Application`] to