Skip to content

Commit

Permalink
Set modifiers on baseview mouse events
Browse files Browse the repository at this point in the history
Using the changes from RustAudio/baseview#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.
  • Loading branch information
robbert-vdh committed Mar 18, 2022
1 parent 4c60371 commit 88cbe3a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 6 deletions.
2 changes: 1 addition & 1 deletion baseview/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
33 changes: 28 additions & 5 deletions baseview/src/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 88cbe3a

Please sign in to comment.