@ -13,14 +13,14 @@
# include "backend/libinput.h"
# include "backend/libinput.h"
# include "util/signal.h"
# include "util/signal.h"
static struct wlr_tablet_ tool_impl tool _impl;
static struct wlr_tablet_ impl tablet _impl;
static bool tablet_ tool_ is_libinput( struct wlr_tablet _tool * tool ) {
static bool tablet_ is_libinput( struct wlr_tablet * tablet ) {
return t ool- > impl = = & tool _impl;
return t ablet- > impl = = & tablet _impl;
}
}
struct wlr_libinput_tablet_tool {
struct wlr_libinput_tablet_tool {
struct wlr_tablet_tool _tool wlr_tool ;
struct wlr_tablet_tool wlr_tool ;
struct libinput_tablet_tool * libinput_tool ;
struct libinput_tablet_tool * libinput_tool ;
@ -38,7 +38,7 @@ struct tablet_tool_list_elem {
} ;
} ;
struct wlr_libinput_tablet {
struct wlr_libinput_tablet {
struct wlr_tablet _tool wlr_tool ;
struct wlr_tablet wlr_tablet ;
struct wl_list tools ; // tablet_tool_list_elem::link
struct wl_list tools ; // tablet_tool_list_elem::link
} ;
} ;
@ -51,10 +51,10 @@ static void destroy_tool_tool(struct wlr_libinput_tablet_tool *tool) {
}
}
static void destroy_tablet _tool( struct wlr_tablet_tool * tool ) {
static void destroy_tablet ( struct wlr_tablet * wlr_tablet ) {
assert ( tablet_ tool_is_libinput( tool ) ) ;
assert ( tablet_ is_libinput( wlr_tablet ) ) ;
struct wlr_libinput_tablet * tablet =
struct wlr_libinput_tablet * tablet =
wl_container_of ( tool, tablet , wlr_tool ) ;
wl_container_of ( wlr_tablet, tablet , wlr_tablet ) ;
struct tablet_tool_list_elem * pos ;
struct tablet_tool_list_elem * pos ;
struct tablet_tool_list_elem * tmp ;
struct tablet_tool_list_elem * tmp ;
@ -71,29 +71,29 @@ static void destroy_tablet_tool(struct wlr_tablet_tool *tool) {
free ( tablet ) ;
free ( tablet ) ;
}
}
static struct wlr_tablet_ tool_impl tool _impl = {
static struct wlr_tablet_ impl tablet _impl = {
. destroy = destroy_tablet _tool ,
. destroy = destroy_tablet ,
} ;
} ;
struct wlr_tablet _tool * create_libinput_tablet _tool (
struct wlr_tablet * create_libinput_tablet (
struct libinput_device * libinput_dev ) {
struct libinput_device * libinput_dev ) {
assert ( libinput_dev ) ;
assert ( libinput_dev ) ;
struct wlr_libinput_tablet * libinput_tablet _tool =
struct wlr_libinput_tablet * libinput_tablet =
calloc ( 1 , sizeof ( struct wlr_libinput_tablet ) ) ;
calloc ( 1 , sizeof ( struct wlr_libinput_tablet ) ) ;
if ( ! libinput_tablet _tool ) {
if ( ! libinput_tablet ) {
wlr_log ( WLR_ERROR , " Unable to allocate wlr_tablet_tool " ) ;
wlr_log ( WLR_ERROR , " Unable to allocate wlr_tablet_tool " ) ;
return NULL ;
return NULL ;
}
}
struct wlr_tablet _tool * wlr_tablet_tool = & libinput_tablet_tool - > wlr_tool ;
struct wlr_tablet * wlr_tablet = & libinput_tablet - > wlr_tablet ;
wlr_list_init ( & wlr_tablet _tool - > paths ) ;
wlr_list_init ( & wlr_tablet - > paths ) ;
struct udev_device * udev = libinput_device_get_udev_device ( libinput_dev ) ;
struct udev_device * udev = libinput_device_get_udev_device ( libinput_dev ) ;
wlr_list_push ( & wlr_tablet _tool - > paths , strdup ( udev_device_get_syspath ( udev ) ) ) ;
wlr_list_push ( & wlr_tablet - > paths , strdup ( udev_device_get_syspath ( udev ) ) ) ;
wlr_tablet _tool - > name = strdup ( libinput_device_get_name ( libinput_dev ) ) ;
wlr_tablet - > name = strdup ( libinput_device_get_name ( libinput_dev ) ) ;
wl_list_init ( & libinput_tablet _tool - > tools ) ;
wl_list_init ( & libinput_tablet - > tools ) ;
wlr_tablet_ tool_init( wlr_tablet_tool , & tool _impl) ;
wlr_tablet_ init( wlr_tablet , & tablet _impl) ;
return wlr_tablet _tool ;
return wlr_tablet ;
}
}
static enum wlr_tablet_tool_type wlr_type_from_libinput_type (
static enum wlr_tablet_tool_type wlr_type_from_libinput_type (
@ -154,11 +154,11 @@ static struct wlr_libinput_tablet_tool *get_wlr_tablet_tool(
}
}
static void ensure_tool_reference ( struct wlr_libinput_tablet_tool * tool ,
static void ensure_tool_reference ( struct wlr_libinput_tablet_tool * tool ,
struct wlr_tablet_tool * wlr_dev ) {
struct wlr_tablet * wlr_dev ) {
assert ( tablet_tool_is_libinput ( wlr_dev ) ) ;
assert ( tablet_is_libinput ( wlr_dev ) ) ;
struct tablet_tool_list_elem * pos ;
struct wlr_libinput_tablet * tablet = wl_container_of ( wlr_dev , tablet , wlr_tablet ) ;
struct wlr_libinput_tablet * tablet = wl_container_of ( wlr_dev , tablet , wlr_tool ) ;
struct tablet_tool_list_elem * pos ;
wl_list_for_each ( pos , & tablet - > tools , link ) {
wl_list_for_each ( pos , & tablet - > tools , link ) {
if ( pos - > tool = = tool ) { // We already have a ref
if ( pos - > tool = = tool ) { // We already have a ref
// XXX: We *could* optimize the tool to the front of
// XXX: We *could* optimize the tool to the front of
@ -173,7 +173,8 @@ static void ensure_tool_reference(struct wlr_libinput_tablet_tool *tool,
struct tablet_tool_list_elem * new =
struct tablet_tool_list_elem * new =
calloc ( 1 , sizeof ( struct tablet_tool_list_elem ) ) ;
calloc ( 1 , sizeof ( struct tablet_tool_list_elem ) ) ;
if ( ! new ) { // TODO: Should we at least log?
if ( ! new ) {
wlr_log ( WLR_ERROR , " Failed to allocate memory for tracking tablet tool " ) ;
return ;
return ;
}
}
@ -195,7 +196,7 @@ void handle_tablet_tool_axis(struct libinput_event *event,
struct wlr_event_tablet_tool_axis wlr_event = { 0 } ;
struct wlr_event_tablet_tool_axis wlr_event = { 0 } ;
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet _tool ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet ) ;
wlr_event . device = wlr_dev ;
wlr_event . device = wlr_dev ;
wlr_event . tool = & tool - > wlr_tool ;
wlr_event . tool = & tool - > wlr_tool ;
@ -239,7 +240,7 @@ void handle_tablet_tool_axis(struct libinput_event *event,
wlr_event . updated_axes | = WLR_TABLET_TOOL_AXIS_WHEEL ;
wlr_event . updated_axes | = WLR_TABLET_TOOL_AXIS_WHEEL ;
wlr_event . wheel_delta = libinput_event_tablet_tool_get_wheel_delta ( tevent ) ;
wlr_event . wheel_delta = libinput_event_tablet_tool_get_wheel_delta ( tevent ) ;
}
}
wlr_signal_emit_safe ( & wlr_dev - > tablet _tool - > events . axis , & wlr_event ) ;
wlr_signal_emit_safe ( & wlr_dev - > tablet - > events . axis , & wlr_event ) ;
}
}
void handle_tablet_tool_proximity ( struct libinput_event * event ,
void handle_tablet_tool_proximity ( struct libinput_event * event ,
@ -255,7 +256,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
struct wlr_event_tablet_tool_proximity wlr_event = { 0 } ;
struct wlr_event_tablet_tool_proximity wlr_event = { 0 } ;
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet _tool ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet ) ;
wlr_event . tool = & tool - > wlr_tool ;
wlr_event . tool = & tool - > wlr_tool ;
wlr_event . device = wlr_dev ;
wlr_event . device = wlr_dev ;
@ -269,7 +270,7 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
wlr_event . state = WLR_TABLET_TOOL_PROXIMITY_IN ;
wlr_event . state = WLR_TABLET_TOOL_PROXIMITY_IN ;
break ;
break ;
}
}
wlr_signal_emit_safe ( & wlr_dev - > tablet _tool - > events . proximity , & wlr_event ) ;
wlr_signal_emit_safe ( & wlr_dev - > tablet - > events . proximity , & wlr_event ) ;
if ( libinput_event_tablet_tool_get_proximity_state ( tevent ) = = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN ) {
if ( libinput_event_tablet_tool_get_proximity_state ( tevent ) = = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_IN ) {
handle_tablet_tool_axis ( event , libinput_dev ) ;
handle_tablet_tool_axis ( event , libinput_dev ) ;
@ -281,9 +282,9 @@ void handle_tablet_tool_proximity(struct libinput_event *event,
libinput_event_tablet_tool_get_proximity_state ( tevent ) = = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT ) {
libinput_event_tablet_tool_get_proximity_state ( tevent ) = = LIBINPUT_TABLET_TOOL_PROXIMITY_STATE_OUT ) {
// The tool isn't unique, it can't be on multiple tablets
// The tool isn't unique, it can't be on multiple tablets
assert ( tool - > pad_refs = = 1 ) ;
assert ( tool - > pad_refs = = 1 ) ;
assert ( tablet_ tool_ is_libinput( wlr_dev - > tablet _tool ) ) ;
assert ( tablet_ is_libinput( wlr_dev - > tablet ) ) ;
struct wlr_libinput_tablet * tablet =
struct wlr_libinput_tablet * tablet =
wl_container_of ( wlr_dev - > tablet _tool, tablet , wlr_tool ) ;
wl_container_of ( wlr_dev - > tablet , tablet , wlr_tablet ) ;
struct tablet_tool_list_elem * pos ;
struct tablet_tool_list_elem * pos ;
struct tablet_tool_list_elem * tmp ;
struct tablet_tool_list_elem * tmp ;
@ -313,7 +314,7 @@ void handle_tablet_tool_tip(struct libinput_event *event,
struct wlr_event_tablet_tool_tip wlr_event = { 0 } ;
struct wlr_event_tablet_tool_tip wlr_event = { 0 } ;
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet _tool ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet ) ;
wlr_event . device = wlr_dev ;
wlr_event . device = wlr_dev ;
wlr_event . tool = & tool - > wlr_tool ;
wlr_event . tool = & tool - > wlr_tool ;
@ -327,7 +328,7 @@ void handle_tablet_tool_tip(struct libinput_event *event,
wlr_event . state = WLR_TABLET_TOOL_TIP_DOWN ;
wlr_event . state = WLR_TABLET_TOOL_TIP_DOWN ;
break ;
break ;
}
}
wlr_signal_emit_safe ( & wlr_dev - > tablet _tool - > events . tip , & wlr_event ) ;
wlr_signal_emit_safe ( & wlr_dev - > tablet - > events . tip , & wlr_event ) ;
}
}
void handle_tablet_tool_button ( struct libinput_event * event ,
void handle_tablet_tool_button ( struct libinput_event * event ,
@ -344,7 +345,7 @@ void handle_tablet_tool_button(struct libinput_event *event,
struct wlr_event_tablet_tool_button wlr_event = { 0 } ;
struct wlr_event_tablet_tool_button wlr_event = { 0 } ;
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
struct wlr_libinput_tablet_tool * tool = get_wlr_tablet_tool (
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
libinput_event_tablet_tool_get_tool ( tevent ) ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet _tool ) ;
ensure_tool_reference ( tool , wlr_dev - > tablet ) ;
wlr_event . device = wlr_dev ;
wlr_event . device = wlr_dev ;
wlr_event . tool = & tool - > wlr_tool ;
wlr_event . tool = & tool - > wlr_tool ;
@ -359,5 +360,5 @@ void handle_tablet_tool_button(struct libinput_event *event,
wlr_event . state = WLR_BUTTON_PRESSED ;
wlr_event . state = WLR_BUTTON_PRESSED ;
break ;
break ;
}
}
wlr_signal_emit_safe ( & wlr_dev - > tablet _tool - > events . button , & wlr_event ) ;
wlr_signal_emit_safe ( & wlr_dev - > tablet - > events . button , & wlr_event ) ;
}
}