@ -9,27 +9,64 @@
# include "wayland-server.h"
# include "relative-pointer-unstable-v1-protocol.h"
# define RELATIVE_POINTER_MANAGER_VERSION 1
static const struct zwp_relative_pointer_manager_v1_interface relative_pointer_manager_v1_impl ;
static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl ;
/**
* Callback functions
* helper functions
*/
static void relative_pointer_manager_v1_handle_resource_destroy ( struct wl_resource * resource ) {
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
struct wlr_relative_pointer_v1 * relative_pointer_from_resource ( struct wl_resource * resource ) {
assert ( wl_resource_instance_of ( resource , & zwp_relative_pointer_v1_interface ,
& relative_pointer_v1_impl ) ) ;
return wl_resource_get_user_data ( resource ) ;
}
static struct wlr_relative_pointer_manager_v1 * relative_pointer_manager_from_resource ( struct wl_resource * resource ) {
assert ( wl_resource_instance_of ( resource , & zwp_relative_pointer_manager_v1_interface ,
& relative_pointer_manager_v1_impl ) ) ;
return wl_resource_get_user_data ( resource ) ;
}
/**
* relative_pointer handler functions
*/
static void relative_pointer_v1_handle_resource_destroy ( struct wl_resource * resource ) {
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
struct wlr_relative_pointer_v1 * relative_pointer =
relative_pointer_from_resource ( resource ) ;
wlr_signal_emit_safe ( & relative_pointer - > events . destroy , relative_pointer ) ;
struct wlr_relative_pointer_v1 * relative_pointer = wl_resource_get_user_data ( resource ) ;
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
free ( relative_pointer ) ;
}
static void relative_pointer_v1_handle_destroy ( struct wl_client * client ,
struct wl_resource * resource ) {
struct wlr_relative_pointer_v1 * relative_pointer =
relative_pointer_from_resource ( resource ) ;
wlr_log ( WLR_DEBUG , " relative_pointer_v1 %p released by client %p " ,
relative_pointer , client ) ;
wl_resource_destroy ( resource ) ;
}
/**
* relative_pointer_manager handler functions
*/
static void relative_pointer_manager_v1_handle_resource_destroy ( struct wl_resource * resource ) {
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
}
static void relative_pointer_manager_v1_handle_destroy ( struct wl_client * client ,
struct wl_resource * resource ) {
wl_resource_destroy ( resource ) ;
@ -62,18 +99,18 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
relative_pointer - > client = client ;
relative_pointer - > resource = relative_pointer_resource ;
relative_pointer - > pointer = ( struct wl_pointer * ) pointer ;
relative_pointer - > pointer = pointer ;
wl_signal_init ( & relative_pointer - > events . destroy ) ;
wl_list_insert ( & seat_client - > relative_pointers ,
wl_list_insert ( & seat_client - > relative_pointers _v1 ,
wl_resource_get_link ( relative_pointer_resource ) ) ;
wl_resource_set_implementation ( relative_pointer_resource , & relative_pointer_v1_impl ,
relative_pointer , relative_pointer_v1_handle_resource_destroy ) ;
struct wlr_relative_pointer_manager_v1 * relative_pointer_manager =
wl_resource_get_user_data ( resource ) ;
relative_pointer_manager_from_resource ( resource ) ;
wlr_signal_emit_safe ( & relative_pointer_manager - > events . new_relative_pointer ,
relative_pointer ) ;
@ -82,17 +119,6 @@ static void relative_pointer_manager_v1_handle_get_relative_pointer(struct wl_cl
}
static void relative_pointer_v1_handle_destroy ( struct wl_client * client ,
struct wl_resource * resource ) {
struct wlr_relative_pointer_v1 * relative_pointer =
wl_resource_get_user_data ( resource ) ;
wlr_log ( WLR_DEBUG , " relative_pointer_v1 %p released by client %p " ,
relative_pointer , client ) ;
wl_resource_destroy ( resource ) ;
}
static void relative_pointer_manager_v1_bind ( struct wl_client * wl_client , void * data ,
uint32_t version , uint32_t id ) {
struct wlr_relative_pointer_manager_v1 * relative_pointer_manager = data ;
@ -114,6 +140,12 @@ static void relative_pointer_manager_v1_bind(struct wl_client *wl_client, void *
wl_client ) ;
}
static void handle_display_destroy ( struct wl_listener * listener , void * data ) {
struct wlr_relative_pointer_manager_v1 * relative_pointer_manager =
wl_container_of ( listener , relative_pointer_manager , display_destroy_listener ) ;
wlr_relative_pointer_manager_v1_destroy ( relative_pointer_manager ) ;
}
/**
* Implementations
@ -134,7 +166,7 @@ static const struct zwp_relative_pointer_v1_interface relative_pointer_v1_impl =
* Public functions
*/
struct wlr_relative_pointer_manager_v1 * wlr_relative_pointer_ v1_create( struct wl_display * display ) {
struct wlr_relative_pointer_manager_v1 * wlr_relative_pointer_ manager_ v1_create( struct wl_display * display ) {
struct wlr_relative_pointer_manager_v1 * relative_pointer_manager =
calloc ( 1 , sizeof ( struct wlr_relative_pointer_manager_v1 ) ) ;
@ -144,11 +176,8 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl
wl_list_init ( & relative_pointer_manager - > resources ) ;
wl_signal_init ( & relative_pointer_manager - > events . destroy ) ;
wl_signal_init ( & relative_pointer_manager - > events . new_relative_pointer ) ;
relative_pointer_manager - > global = wl_global_create ( display ,
& zwp_relative_pointer_manager_v1_interface , 1 ,
& zwp_relative_pointer_manager_v1_interface , RELATIVE_POINTER_MANAGER_VERSION ,
relative_pointer_manager , relative_pointer_manager_v1_bind ) ;
if ( relative_pointer_manager - > global = = NULL ) {
@ -156,18 +185,25 @@ struct wlr_relative_pointer_manager_v1 *wlr_relative_pointer_v1_create(struct wl
return NULL ;
}
wl_signal_init ( & relative_pointer_manager - > events . destroy ) ;
wl_signal_init ( & relative_pointer_manager - > events . new_relative_pointer ) ;
relative_pointer_manager - > display_destroy_listener . notify = handle_display_destroy ;
wl_display_add_destroy_listener ( display , & relative_pointer_manager - > display_destroy_listener ) ;
wlr_log ( WLR_DEBUG , " relative_pointer_v1 manager created " ) ;
return relative_pointer_manager ;
}
void wlr_relative_pointer_ v1_destroy( struct wlr_relative_pointer_manager_v1 * relative_pointer_manager ) {
void wlr_relative_pointer_ manager_ v1_destroy( struct wlr_relative_pointer_manager_v1 * relative_pointer_manager ) {
if ( relative_pointer_manager = = NULL ) {
return ;
}
wlr_signal_emit_safe ( & relative_pointer_manager - > events . destroy , relative_pointer_manager ) ;
wl_list_remove ( & relative_pointer_manager - > display_destroy_listener . link ) ;
struct wl_resource * resource ;
struct wl_resource * tmp_resource ;
@ -190,3 +226,8 @@ void wlr_relative_pointer_v1_send_relative_motion(struct wlr_relative_pointer_v1
wl_fixed_from_double ( dx ) , wl_fixed_from_double ( dy ) ,
wl_fixed_from_double ( dx_unaccel ) , wl_fixed_from_double ( dy_unaccel ) ) ;
}
struct wlr_relative_pointer_v1 * wlr_relative_pointer_v1_from_resource ( struct wl_resource * resource ) {
return relative_pointer_from_resource ( resource ) ;
}