1919//! Conversion of platform keyboard event into cross-platform event.
2020
2121use cocoa:: appkit:: { NSEvent , NSEventModifierFlags , NSEventType } ;
22- use cocoa:: foundation:: NSString ;
2322use cocoa:: base:: id;
24- use keyboard_types:: { Code , KeyState , Key , KeyboardEvent , Modifiers } ;
23+ use cocoa:: foundation:: NSString ;
24+ use keyboard_types:: { Code , Key , KeyState , KeyboardEvent , Modifiers } ;
2525use objc:: { msg_send, sel, sel_impl} ;
2626
2727use crate :: keyboard:: code_to_location;
2828
29-
3029pub ( crate ) fn from_nsstring ( s : id ) -> String {
3130 unsafe {
3231 let slice = std:: slice:: from_raw_parts ( s. UTF8String ( ) as * const _ , s. len ( ) ) ;
@@ -245,15 +244,13 @@ fn code_to_key(code: Code) -> Option<Key> {
245244 } )
246245}
247246
248-
249247fn is_valid_key ( s : & str ) -> bool {
250248 match s. chars ( ) . next ( ) {
251249 None => false ,
252250 Some ( c) => c >= ' ' && c != '\x7f' && !( '\u{e000}' ..'\u{f900}' ) . contains ( & c) ,
253251 }
254252}
255253
256-
257254fn is_modifier_code ( code : Code ) -> bool {
258255 matches ! (
259256 code,
@@ -270,7 +267,6 @@ fn is_modifier_code(code: Code) -> bool {
270267 )
271268}
272269
273-
274270impl KeyboardState {
275271 pub ( crate ) fn new ( ) -> KeyboardState {
276272 let last_mods = NSEventModifierFlags :: empty ( ) ;
@@ -329,33 +325,21 @@ impl KeyboardState {
329325 }
330326 }
331327 } ;
332- let event = KeyboardEvent {
333- code,
334- key,
335- location,
336- modifiers,
337- state,
338- is_composing,
339- repeat,
340- } ;
328+ let event =
329+ KeyboardEvent { code, key, location, modifiers, state, is_composing, repeat } ;
341330 Some ( event)
342331 }
343332 }
344333}
345334
346-
347335const MODIFIER_MAP : & [ ( NSEventModifierFlags , Modifiers ) ] = & [
348336 ( NSEventModifierFlags :: NSShiftKeyMask , Modifiers :: SHIFT ) ,
349337 ( NSEventModifierFlags :: NSAlternateKeyMask , Modifiers :: ALT ) ,
350338 ( NSEventModifierFlags :: NSControlKeyMask , Modifiers :: CONTROL ) ,
351339 ( NSEventModifierFlags :: NSCommandKeyMask , Modifiers :: META ) ,
352- (
353- NSEventModifierFlags :: NSAlphaShiftKeyMask ,
354- Modifiers :: CAPS_LOCK ,
355- ) ,
340+ ( NSEventModifierFlags :: NSAlphaShiftKeyMask , Modifiers :: CAPS_LOCK ) ,
356341] ;
357342
358-
359343pub ( crate ) fn make_modifiers ( raw : NSEventModifierFlags ) -> Modifiers {
360344 let mut modifiers = Modifiers :: empty ( ) ;
361345 for & ( flags, mods) in MODIFIER_MAP {
@@ -364,4 +348,4 @@ pub(crate) fn make_modifiers(raw: NSEventModifierFlags) -> Modifiers {
364348 }
365349 }
366350 modifiers
367- }
351+ }
0 commit comments