8888 IT_JOYSTICK ,
8989 IT_TABLET ,
9090 IT_ACCELEROMETER ,
91+ IT_SWITCH ,
9192};
9293
9394/* Flag which in indicates a device should be skipped because it's
@@ -253,6 +254,9 @@ set_input_device_type(struct udev_device *ud, int input_type)
253254 case IT_ACCELEROMETER :
254255 udev_list_insert (ul , "ID_INPUT_ACCELEROMETER" , "1" );
255256 break ;
257+ case IT_SWITCH :
258+ udev_list_insert (ul , "ID_INPUT_SWITCH" , "1" );
259+ break ;
256260 }
257261 return (0 );
258262}
@@ -316,10 +320,11 @@ create_evdev_handler(struct udev_device *ud)
316320 size_t len ;
317321 bool opened = false;
318322 bool has_keys , has_buttons , has_lmr ;
319- bool has_rel_axes , has_abs_axes , has_mt ;
323+ bool has_rel_axes , has_abs_axes , has_mt , has_switches ;
320324 unsigned long key_bits [NLONGS (KEY_CNT )];
321325 unsigned long rel_bits [NLONGS (REL_CNT )];
322326 unsigned long abs_bits [NLONGS (ABS_CNT )];
327+ unsigned long sw_bits [NLONGS (SW_CNT )];
323328 unsigned long prp_bits [NLONGS (INPUT_PROP_CNT )];
324329 struct input_id id ;
325330
@@ -357,6 +362,11 @@ create_evdev_handler(struct udev_device *ud)
357362 if (sysctlbyname (mib , abs_bits , & len , NULL , 0 ) < 0 )
358363 goto use_ioctl ;
359364
365+ snprintf (mib , sizeof (mib ), "kern.evdev.input.%s.sw_bits" , unit );
366+ len = sizeof (sw_bits );
367+ if (sysctlbyname (mib , sw_bits , & len , NULL , 0 ) < 0 )
368+ goto use_ioctl ;
369+
360370 snprintf (mib , sizeof (mib ), "kern.evdev.input.%s.props" , unit );
361371 len = sizeof (prp_bits );
362372 if (sysctlbyname (mib , prp_bits , & len , NULL , 0 ) < 0 )
@@ -381,6 +391,7 @@ create_evdev_handler(struct udev_device *ud)
381391 ioctl (fd , EVIOCGBIT (EV_REL , sizeof (rel_bits )), rel_bits ) < 0 ||
382392 ioctl (fd , EVIOCGBIT (EV_ABS , sizeof (abs_bits )), abs_bits ) < 0 ||
383393 ioctl (fd , EVIOCGBIT (EV_KEY , sizeof (key_bits )), key_bits ) < 0 ||
394+ ioctl (fd , EVIOCGBIT (EV_SW , sizeof (sw_bits )), sw_bits ) < 0 ||
384395 ioctl (fd , EVIOCGPROP (sizeof (prp_bits )), prp_bits ) < 0 ) {
385396 ERR ("could not query evdev" );
386397 goto bail_out ;
@@ -393,6 +404,7 @@ create_evdev_handler(struct udev_device *ud)
393404 has_lmr = bit_find (key_bits , BTN_LEFT , BTN_MIDDLE + 1 );
394405 has_rel_axes = bit_find (rel_bits , 0 , REL_CNT );
395406 has_abs_axes = bit_find (abs_bits , 0 , ABS_CNT );
407+ has_switches = bit_find (sw_bits , 0 , SW_CNT );
396408 has_mt = bit_find (abs_bits , ABS_MT_SLOT , ABS_CNT );
397409
398410 if (has_abs_axes ) {
@@ -443,6 +455,8 @@ create_evdev_handler(struct udev_device *ud)
443455 input_type = IT_KEYBOARD ;
444456 else if (bit_is_set (prp_bits , INPUT_PROP_POINTER ) || has_rel_axes || has_abs_axes || has_buttons )
445457 input_type = IT_MOUSE ;
458+ else if (has_switches )
459+ input_type = IT_SWITCH ;
446460
447461 if (input_type == IT_NONE )
448462 goto bail_out ;
0 commit comments