Skip to content

Commit d6ce9e1

Browse files
henryksloanKeavon
authored andcommitted
Ignore mouse events without any button state changes (#343)
1 parent 18091dd commit d6ce9e1

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

editor/src/input/input_preprocessor.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ impl MessageHandler<InputPreprocessorMessage, ()> for InputPreprocessor {
5757
}
5858
InputPreprocessorMessage::MouseDown(state, modifier_keys) => {
5959
self.handle_modifier_keys(modifier_keys, responses);
60-
responses.push_back(self.translate_mouse_event(state, KeyPosition::Pressed));
60+
if let Some(message) = self.translate_mouse_event(state, KeyPosition::Pressed) {
61+
responses.push_back(message);
62+
}
6163
}
6264
InputPreprocessorMessage::MouseUp(state, modifier_keys) => {
6365
self.handle_modifier_keys(modifier_keys, responses);
64-
responses.push_back(self.translate_mouse_event(state, KeyPosition::Released));
66+
if let Some(message) = self.translate_mouse_event(state, KeyPosition::Released) {
67+
responses.push_back(message);
68+
}
6569
}
6670
InputPreprocessorMessage::KeyDown(key, modifier_keys) => {
6771
self.handle_modifier_keys(modifier_keys, responses);
@@ -92,23 +96,24 @@ impl MessageHandler<InputPreprocessorMessage, ()> for InputPreprocessor {
9296
}
9397

9498
impl InputPreprocessor {
95-
fn translate_mouse_event(&mut self, new_state: MouseState, position: KeyPosition) -> Message {
99+
fn translate_mouse_event(&mut self, new_state: MouseState, position: KeyPosition) -> Option<Message> {
96100
// Calculate the difference between the two key states (binary xor)
97101
let diff = self.mouse.mouse_keys ^ new_state.mouse_keys;
98102
self.mouse = new_state;
99103
let key = match diff {
100104
MouseKeys::LEFT => Key::Lmb,
101105
MouseKeys::RIGHT => Key::Rmb,
102106
MouseKeys::MIDDLE => Key::Mmb,
107+
MouseKeys::NONE => return None, // self.mouse.mouse_keys was invalid, e.g. when a drag began outside the client
103108
_ => {
104-
log::warn!("The number of buttons modified at the same time was not equal to 1. Modification: {:#010b}", diff);
109+
log::warn!("The number of buttons modified at the same time was greater than 1. Modification: {:#010b}", diff);
105110
Key::UnknownKey
106111
}
107112
};
108-
match position {
113+
Some(match position {
109114
KeyPosition::Pressed => InputMapperMessage::KeyDown(key).into(),
110115
KeyPosition::Released => InputMapperMessage::KeyUp(key).into(),
111-
}
116+
})
112117
}
113118

114119
fn handle_modifier_keys(&mut self, modifier_keys: ModifierKeys, responses: &mut VecDeque<Message>) {

editor/src/input/mouse.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ bitflags! {
5858
const LEFT = 0b0000_0001;
5959
const RIGHT = 0b0000_0010;
6060
const MIDDLE = 0b0000_0100;
61+
const NONE = 0b0000_0000;
6162
}
6263
}

0 commit comments

Comments
 (0)