@@ -18,17 +18,17 @@ use objc2_foundation::{
1818 NSNotFound , NSObject , NSPoint , NSRange , NSRect , NSSize , NSString , NSUInteger ,
1919} ;
2020use winit_core:: event:: {
21- DeviceEvent , ElementState , Ime , KeyEvent , Modifiers , MouseButton , MouseScrollDelta ,
22- PointerKind , PointerSource , TouchPhase , WindowEvent ,
21+ DeviceEvent , ElementState , Ime , KeyEvent , Modifiers , MouseScrollDelta , PointerKind ,
22+ PointerSource , TouchPhase , WindowEvent ,
2323} ;
2424use winit_core:: keyboard:: { Key , KeyCode , KeyLocation , ModifiersState , NamedKey } ;
2525use winit_core:: window:: ImeCapabilities ;
2626
2727use super :: app_state:: AppState ;
2828use super :: cursor:: { default_cursor, invisible_cursor} ;
2929use super :: event:: {
30- code_to_key, code_to_location, create_key_event, event_mods, lalt_pressed , ralt_pressed ,
31- scancode_to_physicalkey,
30+ button_number_to_mouse_button , code_to_key, code_to_location, create_key_event, event_mods,
31+ lalt_pressed , ralt_pressed , scancode_to_physicalkey,
3232} ;
3333use super :: window:: window_id;
3434use crate :: OptionAsAlt ;
@@ -1041,7 +1041,7 @@ impl WinitView {
10411041
10421042 fn mouse_click ( & self , event : & NSEvent , button_state : ElementState ) {
10431043 let position = self . mouse_view_point ( event) . to_physical ( self . scale_factor ( ) ) ;
1044- let button = mouse_button ( event) ;
1044+ let button = button_number_to_mouse_button ( event. buttonNumber ( ) ) ;
10451045
10461046 self . update_modifiers ( event, false ) ;
10471047
@@ -1088,23 +1088,6 @@ impl WinitView {
10881088 }
10891089}
10901090
1091- /// Get the mouse button from the NSEvent.
1092- fn mouse_button ( event : & NSEvent ) -> MouseButton {
1093- // The buttonNumber property only makes sense for the mouse events:
1094- // NSLeftMouse.../NSRightMouse.../NSOtherMouse...
1095- // For the other events, it's always set to 0.
1096- // MacOS only defines the left, right and middle buttons, 3..=31 are left as generic buttons,
1097- // but 3 and 4 are very commonly used as Back and Forward by hardware vendors and applications.
1098- match event. buttonNumber ( ) {
1099- 0 => MouseButton :: Left ,
1100- 1 => MouseButton :: Right ,
1101- 2 => MouseButton :: Middle ,
1102- 3 => MouseButton :: Back ,
1103- 4 => MouseButton :: Forward ,
1104- n => MouseButton :: Other ( n as u16 ) ,
1105- }
1106- }
1107-
11081091// NOTE: to get option as alt working we need to rewrite events
11091092// we're getting from the operating system, which makes it
11101093// impossible to provide such events as extra in `KeyEvent`.
0 commit comments