@ -26,20 +26,20 @@ static void xdg_imported_handle_destroy(struct wl_client *client,
wl_resource_destroy ( resource ) ;
wl_resource_destroy ( resource ) ;
}
}
static struct wlr_xdg_toplevel * verify_is _toplevel( struct wl_resource * resource ,
static struct wlr_xdg_toplevel * get _toplevel( struct wl_resource * resource ,
struct wlr_surface * surface ) {
struct wlr_surface * surface ) {
// Note: xdg_surface and xdg_toplevel are never inert, so if this fails,
// the surface isn't a toplevel
struct wlr_xdg_toplevel * toplevel = wlr_xdg_toplevel_try_from_wlr_surface ( surface ) ;
if ( toplevel = = NULL ) {
// Note: the error codes are the same for zxdg_exporter_v2 and
// Note: the error codes are the same for zxdg_exporter_v2 and
// zxdg_importer_v2
// zxdg_importer_v2
wl_resource_post_error ( resource , ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE ,
struct wlr_xdg_surface * xdg_surface = wlr_xdg_surface_try_from_wlr_surface ( surface ) ;
if ( xdg_surface = = NULL | | xdg_surface - > role ! = WLR_XDG_SURFACE_ROLE_TOPLEVEL ) {
wl_resource_post_error ( resource ,
ZXDG_EXPORTER_V2_ERROR_INVALID_SURFACE ,
" surface must be an xdg_toplevel " ) ;
" surface must be an xdg_toplevel " ) ;
return NULL ;
return NULL ;
}
}
return xdg_surface- > toplevel;
return toplevel;
}
}
static void destroy_imported_child ( struct wlr_xdg_imported_child_v2 * child ) {
static void destroy_imported_child ( struct wlr_xdg_imported_child_v2 * child ) {
@ -56,7 +56,7 @@ static void handle_child_xdg_toplevel_destroy(
destroy_imported_child ( child ) ;
destroy_imported_child ( child ) ;
}
}
static void handle_ xdg_toplevel_set_parent(
static void handle_ child_ xdg_toplevel_set_parent(
struct wl_listener * listener , void * data ) {
struct wl_listener * listener , void * data ) {
struct wlr_xdg_imported_child_v2 * child =
struct wlr_xdg_imported_child_v2 * child =
wl_container_of ( listener , child , xdg_toplevel_set_parent ) ;
wl_container_of ( listener , child , xdg_toplevel_set_parent ) ;
@ -64,32 +64,29 @@ static void handle_xdg_toplevel_set_parent(
}
}
static void xdg_imported_handle_set_parent_of ( struct wl_client * client ,
static void xdg_imported_handle_set_parent_of ( struct wl_client * client ,
struct wl_resource * resource ,
struct wl_resource * resource , struct wl_resource * child_resource ) {
struct wl_resource * child_resource ) {
struct wlr_xdg_imported_v2 * imported =
struct wlr_xdg_imported_v2 * imported =
xdg_imported_from_resource ( resource ) ;
xdg_imported_from_resource ( resource ) ;
if ( imported = = NULL ) {
if ( imported = = NULL ) {
return ;
return ;
}
}
struct wlr_surface * wlr_surface = imported - > exported - > surface ;
struct wlr_surface * wlr_surface_child =
wlr_surface_from_resource ( child_resource ) ;
struct wlr_xdg_surface * surface = wlr_xdg_surface_try_from_wlr_surface ( wlr_surface ) ;
struct wlr_xdg_toplevel * toplevel = imported - > exported - > toplevel ;
struct wlr_xdg_toplevel * child_toplevel =
struct wlr_surface * child_surface = wlr_surface_from_resource ( child_resource ) ;
verify_is_toplevel ( resource , wlr_surface_child ) ;
struct wlr_xdg_toplevel * child_toplevel = get_toplevel ( resource , child_surface ) ;
if ( ! child_toplevel ) {
if ( ! child_toplevel ) {
return ;
return ;
}
}
if ( ! surfac e- > surface - > mapped ) {
if ( ! toplevel- > ba se- > surface - > mapped ) {
wlr_xdg_toplevel_set_parent ( child_toplevel , NULL ) ;
wlr_xdg_toplevel_set_parent ( child_toplevel , NULL ) ;
return ;
return ;
}
}
struct wlr_xdg_imported_child_v2 * child ;
struct wlr_xdg_imported_child_v2 * child ;
wl_list_for_each ( child , & imported - > children , link ) {
wl_list_for_each ( child , & imported - > children , link ) {
if ( child - > surface = = wlr_surface_child ) {
if ( child - > toplevel = = child_toplevel ) {
return ;
return ;
}
}
}
}
@ -99,19 +96,18 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client,
wl_client_post_no_memory ( client ) ;
wl_client_post_no_memory ( client ) ;
return ;
return ;
}
}
child - > surface = wlr_surface_child ;
child - > toplevel = child_toplevel ;
child - > xdg_toplevel_destroy . notify = handle_child_xdg_toplevel_destroy ;
child - > xdg_toplevel_destroy . notify = handle_child_xdg_toplevel_destroy ;
child - > xdg_toplevel_set_parent . notify = handle_ xdg_toplevel_set_parent;
child - > xdg_toplevel_set_parent . notify = handle_ child_ xdg_toplevel_set_parent;
if ( ! wlr_xdg_toplevel_set_parent ( child_toplevel , surface- > toplevel) ) {
if ( ! wlr_xdg_toplevel_set_parent ( child_toplevel , toplevel) ) {
wl_resource_post_error ( surface- > toplevel- > resource ,
wl_resource_post_error ( toplevel- > resource ,
XDG_TOPLEVEL_ERROR_INVALID_PARENT ,
XDG_TOPLEVEL_ERROR_INVALID_PARENT ,
" a toplevel cannot be a parent of itself or its ancestor " ) ;
" a toplevel cannot be a parent of itself or its ancestor " ) ;
free ( child ) ;
free ( child ) ;
return ;
return ;
}
}
wlr_xdg_toplevel_set_parent ( child_toplevel , surface - > toplevel ) ;
wl_signal_add ( & child_toplevel - > events . destroy , & child - > xdg_toplevel_destroy ) ;
wl_signal_add ( & child_toplevel - > events . destroy , & child - > xdg_toplevel_destroy ) ;
wl_signal_add ( & child_toplevel - > events . set_parent , & child - > xdg_toplevel_set_parent ) ;
wl_signal_add ( & child_toplevel - > events . set_parent , & child - > xdg_toplevel_set_parent ) ;
@ -155,10 +151,7 @@ static void destroy_imported(struct wlr_xdg_imported_v2 *imported) {
imported - > exported = NULL ;
imported - > exported = NULL ;
struct wlr_xdg_imported_child_v2 * child , * child_tmp ;
struct wlr_xdg_imported_child_v2 * child , * child_tmp ;
wl_list_for_each_safe ( child , child_tmp , & imported - > children , link ) {
wl_list_for_each_safe ( child , child_tmp , & imported - > children , link ) {
struct wlr_xdg_surface * xdg_child =
wlr_xdg_toplevel_set_parent ( child - > toplevel , NULL ) ;
wlr_xdg_surface_try_from_wlr_surface ( child - > surface ) ;
assert ( xdg_child ! = NULL ) ;
wlr_xdg_toplevel_set_parent ( xdg_child - > toplevel , NULL ) ;
}
}
wl_list_remove ( & imported - > exported_destroyed . link ) ;
wl_list_remove ( & imported - > exported_destroyed . link ) ;
@ -197,15 +190,12 @@ static void handle_xdg_toplevel_destroy(struct wl_listener *listener, void *data
}
}
static void xdg_exporter_handle_export ( struct wl_client * wl_client ,
static void xdg_exporter_handle_export ( struct wl_client * wl_client ,
struct wl_resource * client_resource ,
struct wl_resource * client_resource , uint32_t id , struct wl_resource * surface_resource ) {
uint32_t id ,
struct wl_resource * surface_resource ) {
struct wlr_xdg_foreign_v2 * foreign =
struct wlr_xdg_foreign_v2 * foreign =
xdg_foreign_from_exporter_resource ( client_resource ) ;
xdg_foreign_from_exporter_resource ( client_resource ) ;
struct wlr_surface * surface = wlr_surface_from_resource ( surface_resource ) ;
struct wlr_surface * surface = wlr_surface_from_resource ( surface_resource ) ;
struct wlr_xdg_toplevel * xdg_toplevel =
struct wlr_xdg_toplevel * xdg_toplevel = get_toplevel ( client_resource , surface ) ;
verify_is_toplevel ( client_resource , surface ) ;
if ( ! xdg_toplevel ) {
if ( ! xdg_toplevel ) {
return ;
return ;
}
}
@ -222,7 +212,7 @@ static void xdg_exporter_handle_export(struct wl_client *wl_client,
return ;
return ;
}
}
exported - > base . surface = surface ;
exported - > base . toplevel = xdg_toplevel ;
exported - > resource = wl_resource_create ( wl_client , & zxdg_exported_v2_interface ,
exported - > resource = wl_resource_create ( wl_client , & zxdg_exported_v2_interface ,
wl_resource_get_version ( client_resource ) , id ) ;
wl_resource_get_version ( client_resource ) , id ) ;
if ( exported - > resource = = NULL ) {
if ( exported - > resource = = NULL ) {
@ -294,9 +284,7 @@ static void xdg_imported_handle_exported_destroy(struct wl_listener *listener,
}
}
static void xdg_importer_handle_import ( struct wl_client * wl_client ,
static void xdg_importer_handle_import ( struct wl_client * wl_client ,
struct wl_resource * client_resource ,
struct wl_resource * client_resource , uint32_t id , const char * handle ) {
uint32_t id ,
const char * handle ) {
struct wlr_xdg_foreign_v2 * foreign =
struct wlr_xdg_foreign_v2 * foreign =
xdg_foreign_from_importer_resource ( client_resource ) ;
xdg_foreign_from_importer_resource ( client_resource ) ;