diff --git a/baseview/Cargo.toml b/baseview/Cargo.toml index 78f00a0d5..4464c77ad 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 = { git = "https://github.com/femtovg/femtovg", rev = "87fe627794f3f793d8e3a338c838a2f8e8a8aa9d", default-features = false } diff --git a/baseview/src/application.rs b/baseview/src/application.rs index b860ec536..5572c5b7a 100644 --- a/baseview/src/application.rs +++ b/baseview/src/application.rs @@ -329,23 +329,31 @@ impl ApplicationRunner { match event { baseview::Event::Mouse(event) => match event { - baseview::MouseEvent::CursorMoved { position } => { + baseview::MouseEvent::CursorMoved { position, modifiers } => { + self.update_modifiers(modifiers); + let physical_posx = position.x * self.context.style.dpi_factor; let physical_posy = position.y * self.context.style.dpi_factor; let cursorx = (physical_posx) as f32; let cursory = (physical_posy) 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 { @@ -488,6 +496,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