@ -9,13 +9,13 @@
struct wlr_input_device * get_appropriate_device (
enum wlr_input_device_type desired_type ,
struct libinput_device * device ) {
list_t * devices = libinput_device_get_user_data ( device ) ;
if ( ! devices) {
struct libinput_device * libinput_ dev) {
list_t * wlr_ devices = libinput_device_get_user_data ( libinput_ dev) ;
if ( ! wlr_ devices) {
return NULL ;
}
for ( size_t i = 0 ; i < devices- > length ; + + i ) {
struct wlr_input_device * dev = devices- > items [ i ] ;
for ( size_t i = 0 ; i < wlr_ devices- > length ; + + i ) {
struct wlr_input_device * dev = wlr_ devices- > items [ i ] ;
if ( dev - > type = = desired_type ) {
return dev ;
}
@ -33,168 +33,168 @@ static struct wlr_input_device_impl input_device_impl = {
} ;
static struct wlr_input_device * allocate_device (
struct wlr_libinput_backend * backend , struct libinput_device * device ,
list_t * devices, enum wlr_input_device_type type ) {
int vendor = libinput_device_get_id_vendor ( device ) ;
int product = libinput_device_get_id_product ( device ) ;
const char * name = libinput_device_get_name ( device ) ;
struct wlr_libinput_backend * backend , struct libinput_device * libinput_ dev,
list_t * wlr_ devices, enum wlr_input_device_type type ) {
int vendor = libinput_device_get_id_vendor ( libinput_ dev) ;
int product = libinput_device_get_id_product ( libinput_ dev) ;
const char * name = libinput_device_get_name ( libinput_ dev) ;
struct wlr_input_device_state * devstate =
calloc ( 1 , sizeof ( struct wlr_input_device_state ) ) ;
devstate - > handle = device ;
libinput_device_ref ( device ) ;
struct wlr_input_device * wlr_dev ice = wlr_input_device_create (
devstate - > handle = libinput_ dev;
libinput_device_ref ( libinput_ dev) ;
struct wlr_input_device * wlr_dev = wlr_input_device_create (
type , & input_device_impl , devstate ,
name , vendor , product ) ;
list_add ( devices, wlr_dev ice ) ;
return wlr_dev ice ;
list_add ( wlr_ devices, wlr_dev ) ;
return wlr_dev ;
}
static void handle_device_added ( struct wlr_libinput_backend * backend ,
struct libinput_device * device ) {
assert ( backend & & device ) ;
struct libinput_device * libinput_ dev) {
assert ( backend & & libinput_ dev) ;
/*
* Note : the wlr API exposes only devices with a single capability , because
* that meshes better with how Wayland does things and is a bit simpler .
* However , libinput devices often have multiple capabilities - in such
* cases we have to create several devices .
*/
int vendor = libinput_device_get_id_vendor ( device ) ;
int product = libinput_device_get_id_product ( device ) ;
const char * name = libinput_device_get_name ( device ) ;
list_t * devices = list_create ( ) ;
int vendor = libinput_device_get_id_vendor ( libinput_ dev) ;
int product = libinput_device_get_id_product ( libinput_ dev) ;
const char * name = libinput_device_get_name ( libinput_ dev) ;
list_t * wlr_ devices = list_create ( ) ;
wlr_log ( L_DEBUG , " Added %s [%d:%d] " , name , vendor , product ) ;
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_KEYBOARD ) ) {
struct wlr_input_device * wlr_dev ice = allocate_device ( backend ,
device , devices, WLR_INPUT_DEVICE_KEYBOARD ) ;
wlr_dev ice - > keyboard = wlr_libinput_keyboard_create ( device ) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ice ) ;
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_POINTER ) ) {
struct wlr_input_device * wlr_dev ice = allocate_device ( backend ,
device , devices, WLR_INPUT_DEVICE_POINTER ) ;
wlr_dev ice - > pointer = wlr_libinput_pointer_create ( device ) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ice ) ;
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_TOUCH ) ) {
struct wlr_input_device * wlr_dev ice = allocate_device ( backend ,
device , devices, WLR_INPUT_DEVICE_TOUCH ) ;
wlr_dev ice - > touch = wlr_libinput_touch_create ( device ) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ice ) ;
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_TABLET_TOOL ) ) {
struct wlr_input_device * wlr_dev ice = allocate_device ( backend ,
device , devices, WLR_INPUT_DEVICE_TABLET_TOOL ) ;
wlr_dev ice - > tablet_tool = wlr_libinput_tablet_tool_create ( device ) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ice ) ;
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_TABLET_PAD ) ) {
struct wlr_input_device * wlr_dev ice = allocate_device ( backend ,
device , devices, WLR_INPUT_DEVICE_TABLET_PAD ) ;
wlr_dev ice - > tablet_pad = wlr_libinput_tablet_pad_create ( device ) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ice ) ;
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_GESTURE ) ) {
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_KEYBOARD ) ) {
struct wlr_input_device * wlr_dev = allocate_device ( backend ,
libinput_ dev, wlr_ devices, WLR_INPUT_DEVICE_KEYBOARD ) ;
wlr_dev - > keyboard = wlr_libinput_keyboard_create ( libinput_ dev) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ) ;
}
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_POINTER ) ) {
struct wlr_input_device * wlr_dev = allocate_device ( backend ,
libinput_ dev, wlr_ devices, WLR_INPUT_DEVICE_POINTER ) ;
wlr_dev - > pointer = wlr_libinput_pointer_create ( libinput_ dev) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ) ;
}
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_TOUCH ) ) {
struct wlr_input_device * wlr_dev = allocate_device ( backend ,
libinput_ dev, wlr_ devices, WLR_INPUT_DEVICE_TOUCH ) ;
wlr_dev - > touch = wlr_libinput_touch_create ( libinput_ dev) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ) ;
}
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_TABLET_TOOL ) ) {
struct wlr_input_device * wlr_dev = allocate_device ( backend ,
libinput_ dev, wlr_ devices, WLR_INPUT_DEVICE_TABLET_TOOL ) ;
wlr_dev - > tablet_tool = wlr_libinput_tablet_tool_create ( libinput_ dev) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ) ;
}
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_TABLET_PAD ) ) {
struct wlr_input_device * wlr_dev = allocate_device ( backend ,
libinput_ dev, wlr_ devices, WLR_INPUT_DEVICE_TABLET_PAD ) ;
wlr_dev - > tablet_pad = wlr_libinput_tablet_pad_create ( libinput_ dev) ;
wl_signal_emit ( & backend - > backend . events . input_add , wlr_dev ) ;
}
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_GESTURE ) ) {
// TODO
}
if ( libinput_device_has_capability ( device , LIBINPUT_DEVICE_CAP_SWITCH ) ) {
if ( libinput_device_has_capability ( libinput_ dev, LIBINPUT_DEVICE_CAP_SWITCH ) ) {
// TODO
}
if ( devices- > length > 0 ) {
libinput_device_set_user_data ( device , devices) ;
list_add ( backend - > devices, devices) ;
if ( wlr_ devices- > length > 0 ) {
libinput_device_set_user_data ( libinput_ dev, wlr_ devices) ;
list_add ( backend - > wlr_ device_list s, wlr_ devices) ;
} else {
list_free ( devices) ;
list_free ( wlr_ devices) ;
}
}
static void handle_device_removed ( struct wlr_libinput_backend * backend ,
struct libinput_device * device ) {
list_t * devices = libinput_device_get_user_data ( device ) ;
int vendor = libinput_device_get_id_vendor ( device ) ;
int product = libinput_device_get_id_product ( device ) ;
const char * name = libinput_device_get_name ( device ) ;
struct libinput_device * libinput_ dev) {
list_t * wlr_ devices = libinput_device_get_user_data ( libinput_ dev) ;
int vendor = libinput_device_get_id_vendor ( libinput_ dev) ;
int product = libinput_device_get_id_product ( libinput_ dev) ;
const char * name = libinput_device_get_name ( libinput_ dev) ;
wlr_log ( L_DEBUG , " Removing %s [%d:%d] " , name , vendor , product ) ;
if ( ! devices) {
if ( ! wlr_ devices) {
return ;
}
for ( size_t i = 0 ; i < devices- > length ; i + + ) {
struct wlr_input_device * wlr_dev ice = devices- > items [ i ] ;
wl_signal_emit ( & backend - > backend . events . input_remove , wlr_dev ice ) ;
wlr_input_device_destroy ( wlr_dev ice ) ;
for ( size_t i = 0 ; i < wlr_ devices- > length ; i + + ) {
struct wlr_input_device * wlr_dev = wlr_ devices- > items [ i ] ;
wl_signal_emit ( & backend - > backend . events . input_remove , wlr_dev ) ;
wlr_input_device_destroy ( wlr_dev ) ;
}
for ( size_t i = 0 ; i < backend - > devices- > length ; i + + ) {
if ( backend - > devices- > items [ i ] = = devices) {
list_del ( backend - > devices, i ) ;
for ( size_t i = 0 ; i < backend - > wlr_ device_list s- > length ; i + + ) {
if ( backend - > wlr_ device_list s- > items [ i ] = = wlr_ devices) {
list_del ( backend - > wlr_ device_list s, i ) ;
break ;
}
}
list_free ( devices) ;
list_free ( wlr_ devices) ;
}
void wlr_libinput_event ( struct wlr_libinput_backend * backend ,
struct libinput_event * event ) {
assert ( backend & & event ) ;
struct libinput_device * device = libinput_event_get_device ( event ) ;
struct libinput_device * libinput_ dev = libinput_event_get_device ( event ) ;
enum libinput_event_type event_type = libinput_event_get_type ( event ) ;
switch ( event_type ) {
case LIBINPUT_EVENT_DEVICE_ADDED :
handle_device_added ( backend , device ) ;
handle_device_added ( backend , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_DEVICE_REMOVED :
handle_device_removed ( backend , device ) ;
handle_device_removed ( backend , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_KEYBOARD_KEY :
handle_keyboard_key ( event , device ) ;
handle_keyboard_key ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_POINTER_MOTION :
handle_pointer_motion ( event , device ) ;
handle_pointer_motion ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_POINTER_MOTION_ABSOLUTE :
handle_pointer_motion_abs ( event , device ) ;
handle_pointer_motion_abs ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_POINTER_BUTTON :
handle_pointer_button ( event , device ) ;
handle_pointer_button ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_POINTER_AXIS :
handle_pointer_axis ( event , device ) ;
handle_pointer_axis ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TOUCH_DOWN :
handle_touch_down ( event , device ) ;
handle_touch_down ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TOUCH_UP :
handle_touch_up ( event , device ) ;
handle_touch_up ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TOUCH_MOTION :
handle_touch_motion ( event , device ) ;
handle_touch_motion ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TOUCH_CANCEL :
handle_touch_cancel ( event , device ) ;
handle_touch_cancel ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TOUCH_FRAME :
// no-op (at least for now)
break ;
case LIBINPUT_EVENT_TABLET_TOOL_AXIS :
handle_tablet_tool_axis ( event , device ) ;
handle_tablet_tool_axis ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_TOOL_PROXIMITY :
handle_tablet_tool_proximity ( event , device ) ;
handle_tablet_tool_proximity ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_TOOL_TIP :
handle_tablet_tool_tip ( event , device ) ;
handle_tablet_tool_tip ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_TOOL_BUTTON :
handle_tablet_tool_button ( event , device ) ;
handle_tablet_tool_button ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_PAD_BUTTON :
handle_tablet_pad_button ( event , device ) ;
handle_tablet_pad_button ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_PAD_RING :
handle_tablet_pad_ring ( event , device ) ;
handle_tablet_pad_ring ( event , libinput_ dev) ;
break ;
case LIBINPUT_EVENT_TABLET_PAD_STRIP :
handle_tablet_pad_strip ( event , device ) ;
handle_tablet_pad_strip ( event , libinput_ dev) ;
break ;
default :
wlr_log ( L_DEBUG , " Unknown libinput event %d " , event_type ) ;