@@ -10,30 +10,21 @@ use std::os::unix::io::AsRawFd;
1010ioctl_none ! ( rfkill_noinput, b'R' , 1 ) ;
1111
1212pub fn create_uinput_device ( ) -> Result < VirtualDevice , Box < dyn std:: error:: Error > > {
13- let mut keys = AttributeSet :: < Key > :: new ( ) ;
14- for key in get_all_keys ( ) {
15- keys. insert ( key) ;
16- }
13+ let keys: AttributeSet < Key > = get_all_keys ( ) . iter ( ) . copied ( ) . collect ( ) ;
1714
18- let mut relative_axes = AttributeSet :: < RelativeAxisType > :: new ( ) ;
19- for axis in get_all_relative_axes ( ) {
20- relative_axes. insert ( axis) ;
21- }
15+ let relative_axes: AttributeSet < RelativeAxisType > =
16+ get_all_relative_axes ( ) . iter ( ) . copied ( ) . collect ( ) ;
2217
2318 let device = VirtualDeviceBuilder :: new ( ) ?
2419 . name ( "swhkd virtual output" )
2520 . with_keys ( & keys) ?
2621 . with_relative_axes ( & relative_axes) ?
27- . build ( )
28- . unwrap ( ) ;
22+ . build ( ) ?;
2923 Ok ( device)
3024}
3125
3226pub fn create_uinput_switches_device ( ) -> Result < VirtualDevice , Box < dyn std:: error:: Error > > {
33- let mut switches = AttributeSet :: < SwitchType > :: new ( ) ;
34- for switch in get_all_switches ( ) {
35- switches. insert ( switch) ;
36- }
27+ let switches: AttributeSet < SwitchType > = get_all_switches ( ) . iter ( ) . copied ( ) . collect ( ) ;
3728
3829 // We have to disable rfkill-input to avoid blocking all radio devices. When
3930 // a new device (virtual or physical) with the SW_RFKILL_ALL capability bit
@@ -52,12 +43,11 @@ pub fn create_uinput_switches_device() -> Result<VirtualDevice, Box<dyn std::err
5243 let device = VirtualDeviceBuilder :: new ( ) ?
5344 . name ( "swhkd switches virtual output" )
5445 . with_switches ( & switches) ?
55- . build ( )
56- . unwrap ( ) ;
46+ . build ( ) ?;
5747 Ok ( device)
5848}
59- pub fn get_all_keys ( ) -> Vec < Key > {
60- vec ! [
49+ pub fn get_all_keys ( ) -> & ' static [ Key ] {
50+ & [
6151 evdev:: Key :: KEY_RESERVED ,
6252 evdev:: Key :: KEY_ESC ,
6353 evdev:: Key :: KEY_1 ,
@@ -609,8 +599,8 @@ pub fn get_all_keys() -> Vec<Key> {
609599 ]
610600}
611601
612- pub fn get_all_relative_axes ( ) -> Vec < RelativeAxisType > {
613- vec ! [
602+ pub fn get_all_relative_axes ( ) -> & ' static [ RelativeAxisType ] {
603+ & [
614604 RelativeAxisType :: REL_X ,
615605 RelativeAxisType :: REL_Y ,
616606 RelativeAxisType :: REL_Z ,
@@ -627,8 +617,8 @@ pub fn get_all_relative_axes() -> Vec<RelativeAxisType> {
627617 ]
628618}
629619
630- pub fn get_all_switches ( ) -> Vec < SwitchType > {
631- vec ! [
620+ pub fn get_all_switches ( ) -> & ' static [ SwitchType ] {
621+ & [
632622 SwitchType :: SW_LID ,
633623 SwitchType :: SW_TABLET_MODE ,
634624 SwitchType :: SW_HEADPHONE_INSERT ,
0 commit comments