@ -22,15 +22,6 @@ struct wlr_subsurface *wlr_subsurface_from_wlr_surface(
return ( struct wlr_subsurface * ) surface - > role_data ;
return ( struct wlr_subsurface * ) surface - > role_data ;
}
}
static const struct wl_subcompositor_interface subcompositor_impl ;
static struct wlr_subcompositor * subcompositor_from_resource (
struct wl_resource * resource ) {
assert ( wl_resource_instance_of ( resource , & wl_subcompositor_interface ,
& subcompositor_impl ) ) ;
return wl_resource_get_user_data ( resource ) ;
}
static void subcompositor_handle_destroy ( struct wl_client * client ,
static void subcompositor_handle_destroy ( struct wl_client * client ,
struct wl_resource * resource ) {
struct wl_resource * resource ) {
wl_resource_destroy ( resource ) ;
wl_resource_destroy ( resource ) ;
@ -40,8 +31,6 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
struct wl_resource * resource , uint32_t id ,
struct wl_resource * resource , uint32_t id ,
struct wl_resource * surface_resource ,
struct wl_resource * surface_resource ,
struct wl_resource * parent_resource ) {
struct wl_resource * parent_resource ) {
struct wlr_subcompositor * subcompositor =
subcompositor_from_resource ( resource ) ;
struct wlr_surface * surface = wlr_surface_from_resource ( surface_resource ) ;
struct wlr_surface * surface = wlr_surface_from_resource ( surface_resource ) ;
struct wlr_surface * parent = wlr_surface_from_resource ( parent_resource ) ;
struct wlr_surface * parent = wlr_surface_from_resource ( parent_resource ) ;
@ -78,7 +67,7 @@ static void subcompositor_handle_get_subsurface(struct wl_client *client,
}
}
wlr_subsurface_create ( surface , parent , wl_resource_get_version ( resource ) ,
wlr_subsurface_create ( surface , parent , wl_resource_get_version ( resource ) ,
id , & subcompositor - > subsurface_resources ) ;
id , NULL ) ;
}
}
static const struct wl_subcompositor_interface subcompositor_impl = {
static const struct wl_subcompositor_interface subcompositor_impl = {
@ -86,10 +75,6 @@ static const struct wl_subcompositor_interface subcompositor_impl = {
. get_subsurface = subcompositor_handle_get_subsurface ,
. get_subsurface = subcompositor_handle_get_subsurface ,
} ;
} ;
static void subcompositor_resource_destroy ( struct wl_resource * resource ) {
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
}
static void subcompositor_bind ( struct wl_client * client , void * data ,
static void subcompositor_bind ( struct wl_client * client , void * data ,
uint32_t version , uint32_t id ) {
uint32_t version , uint32_t id ) {
struct wlr_subcompositor * subcompositor = data ;
struct wlr_subcompositor * subcompositor = data ;
@ -100,33 +85,24 @@ static void subcompositor_bind(struct wl_client *client, void *data,
return ;
return ;
}
}
wl_resource_set_implementation ( resource , & subcompositor_impl ,
wl_resource_set_implementation ( resource , & subcompositor_impl ,
subcompositor , subcompositor_resource_destroy ) ;
subcompositor , NULL ) ;
wl_list_insert ( & subcompositor - > resources , wl_resource_get_link ( resource ) ) ;
}
}
static void subcompositor_init ( struct wlr_subcompositor * subcompositor ,
static bool subcompositor_init ( struct wlr_subcompositor * subcompositor ,
struct wl_display * display ) {
struct wl_display * display ) {
subcompositor - > global = wl_global_create ( display ,
subcompositor - > global = wl_global_create ( display ,
& wl_subcompositor_interface , SUBCOMPOSITOR_VERSION , subcompositor ,
& wl_subcompositor_interface , SUBCOMPOSITOR_VERSION , subcompositor ,
subcompositor_bind ) ;
subcompositor_bind ) ;
if ( subcompositor - > global = = NULL ) {
if ( subcompositor - > global = = NULL ) {
wlr_log_errno ( WLR_ERROR , " Could not allocate subcompositor global " ) ;
wlr_log_errno ( WLR_ERROR , " Could not allocate subcompositor global " ) ;
return ;
return false ;
}
}
wl_list_init ( & subcompositor - > resources ) ;
wl_list_init ( & subcompositor - > subsurface_resources ) ;
return true ;
}
}
static void subcompositor_finish ( struct wlr_subcompositor * subcompositor ) {
static void subcompositor_finish ( struct wlr_subcompositor * subcompositor ) {
wl_global_destroy ( subcompositor - > global ) ;
wl_global_destroy ( subcompositor - > global ) ;
struct wl_resource * resource , * tmp ;
wl_resource_for_each_safe ( resource , tmp ,
& subcompositor - > subsurface_resources ) {
wl_resource_destroy ( resource ) ;
}
wl_resource_for_each_safe ( resource , tmp , & subcompositor - > resources ) {
wl_resource_destroy ( resource ) ;
}
}
}
@ -144,8 +120,7 @@ static void compositor_create_surface(struct wl_client *client,
struct wlr_compositor * compositor = compositor_from_resource ( resource ) ;
struct wlr_compositor * compositor = compositor_from_resource ( resource ) ;
struct wlr_surface * surface = wlr_surface_create ( client ,
struct wlr_surface * surface = wlr_surface_create ( client ,
wl_resource_get_version ( resource ) , id , compositor - > renderer ,
wl_resource_get_version ( resource ) , id , compositor - > renderer , NULL ) ;
& compositor - > surface_resources ) ;
if ( surface = = NULL ) {
if ( surface = = NULL ) {
wl_client_post_no_memory ( client ) ;
wl_client_post_no_memory ( client ) ;
return ;
return ;
@ -156,9 +131,7 @@ static void compositor_create_surface(struct wl_client *client,
static void compositor_create_region ( struct wl_client * client ,
static void compositor_create_region ( struct wl_client * client ,
struct wl_resource * resource , uint32_t id ) {
struct wl_resource * resource , uint32_t id ) {
struct wlr_compositor * compositor = compositor_from_resource ( resource ) ;
wlr_region_create ( client , wl_resource_get_version ( resource ) , id , NULL ) ;
wlr_region_create ( client , 1 , id , & compositor - > region_resources ) ;
}
}
static const struct wl_compositor_interface compositor_impl = {
static const struct wl_compositor_interface compositor_impl = {
@ -166,14 +139,9 @@ static const struct wl_compositor_interface compositor_impl = {
. create_region = compositor_create_region ,
. create_region = compositor_create_region ,
} ;
} ;
static void compositor_resource_destroy ( struct wl_resource * resource ) {
wl_list_remove ( wl_resource_get_link ( resource ) ) ;
}
static void compositor_bind ( struct wl_client * wl_client , void * data ,
static void compositor_bind ( struct wl_client * wl_client , void * data ,
uint32_t version , uint32_t id ) {
uint32_t version , uint32_t id ) {
struct wlr_compositor * compositor = data ;
struct wlr_compositor * compositor = data ;
assert ( wl_client & & compositor ) ;
struct wl_resource * resource =
struct wl_resource * resource =
wl_resource_create ( wl_client , & wl_compositor_interface , version , id ) ;
wl_resource_create ( wl_client , & wl_compositor_interface , version , id ) ;
@ -181,38 +149,19 @@ static void compositor_bind(struct wl_client *wl_client, void *data,
wl_client_post_no_memory ( wl_client ) ;
wl_client_post_no_memory ( wl_client ) ;
return ;
return ;
}
}
wl_resource_set_implementation ( resource , & compositor_impl ,
wl_resource_set_implementation ( resource , & compositor_impl , compositor , NULL ) ;
compositor , compositor_resource_destroy ) ;
wl_list_insert ( & compositor - > resources , wl_resource_get_link ( resource ) ) ;
}
}
void wlr_compositor_destroy ( struct wlr_compositor * compositor ) {
static void handle_display_destroy ( struct wl_listener * listener , void * data ) {
if ( compositor = = NULL ) {
struct wlr_compositor * compositor =
return ;
wl_container_of ( listener , compositor , display_destroy ) ;
}
wlr_signal_emit_safe ( & compositor - > events . destroy , compositor ) ;
wlr_signal_emit_safe ( & compositor - > events . destroy , compositor ) ;
subcompositor_finish ( & compositor - > subcompositor ) ;
subcompositor_finish ( & compositor - > subcompositor ) ;
wl_list_remove ( & compositor - > display_destroy . link ) ;
wl_list_remove ( & compositor - > display_destroy . link ) ;
wl_global_destroy ( compositor - > global ) ;
wl_global_destroy ( compositor - > global ) ;
struct wl_resource * resource , * tmp ;
wl_resource_for_each_safe ( resource , tmp , & compositor - > surface_resources ) {
wl_resource_destroy ( resource ) ;
}
wl_resource_for_each_safe ( resource , tmp , & compositor - > region_resources ) {
wl_resource_destroy ( resource ) ;
}
wl_resource_for_each_safe ( resource , tmp , & compositor - > resources ) {
wl_resource_destroy ( resource ) ;
}
free ( compositor ) ;
free ( compositor ) ;
}
}
static void handle_display_destroy ( struct wl_listener * listener , void * data ) {
struct wlr_compositor * compositor =
wl_container_of ( listener , compositor , display_destroy ) ;
wlr_compositor_destroy ( compositor ) ;
}
struct wlr_compositor * wlr_compositor_create ( struct wl_display * display ,
struct wlr_compositor * wlr_compositor_create ( struct wl_display * display ,
struct wlr_renderer * renderer ) {
struct wlr_renderer * renderer ) {
struct wlr_compositor * compositor =
struct wlr_compositor * compositor =
@ -231,9 +180,6 @@ struct wlr_compositor *wlr_compositor_create(struct wl_display *display,
}
}
compositor - > renderer = renderer ;
compositor - > renderer = renderer ;
wl_list_init ( & compositor - > resources ) ;
wl_list_init ( & compositor - > surface_resources ) ;
wl_list_init ( & compositor - > region_resources ) ;
wl_signal_init ( & compositor - > events . new_surface ) ;
wl_signal_init ( & compositor - > events . new_surface ) ;
wl_signal_init ( & compositor - > events . destroy ) ;
wl_signal_init ( & compositor - > events . destroy ) ;