@@ -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
9498impl 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 > ) {
0 commit comments