diff --git a/include/types/wlr_xdg_shell.h b/include/types/wlr_xdg_shell.h index 9a34c49c..e3688a94 100644 --- a/include/types/wlr_xdg_shell.h +++ b/include/types/wlr_xdg_shell.h @@ -36,11 +36,11 @@ struct wlr_xdg_popup_grab *get_xdg_shell_popup_grab_from_seat( void create_xdg_toplevel(struct wlr_xdg_surface *xdg_surface, uint32_t id); -void handle_xdg_surface_toplevel_committed(struct wlr_xdg_surface *surface); -void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface_configure *configure); -void handle_xdg_toplevel_ack_configure(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface_configure *configure); -void destroy_xdg_toplevel(struct wlr_xdg_surface *surface); +void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel); +struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure( + struct wlr_xdg_toplevel *toplevel); +void handle_xdg_toplevel_ack_configure(struct wlr_xdg_toplevel *toplevel, + struct wlr_xdg_toplevel_configure *configure); +void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel); #endif diff --git a/include/wlr/types/wlr_xdg_shell.h b/include/wlr/types/wlr_xdg_shell.h index 8d1a6fce..e16d3218 100644 --- a/include/wlr/types/wlr_xdg_shell.h +++ b/include/wlr/types/wlr_xdg_shell.h @@ -258,7 +258,7 @@ struct wlr_xdg_toplevel_show_window_menu_event { struct wlr_xdg_shell *wlr_xdg_shell_create(struct wl_display *display); -/** Returns the wlr_xdg_surface from an xdg_surface resource. +/** Get the corresponding wlr_xdg_surface from a resource. * * Aborts if the resource doesn't have the correct type. Returns NULL if the * resource is inert. @@ -267,7 +267,13 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_resource( struct wl_resource *resource); struct wlr_xdg_surface *wlr_xdg_surface_from_popup_resource( struct wl_resource *resource); -struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource( + +/** Get the corresponding wlr_xdg_toplevel from a resource. + * + * Aborts if the resource doesn't have the correct type. Returns NULL if the + * resource is inert. + */ +struct wlr_xdg_toplevel *wlr_xdg_toplevel_from_resource( struct wl_resource *resource); /** @@ -280,55 +286,55 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface); * Request that this toplevel surface be the given size. Returns the associated * configure serial. */ -uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_toplevel *toplevel, uint32_t width, uint32_t height); /** - * Request that this toplevel surface show itself in an activated or deactivated + * Request that this toplevel show itself in an activated or deactivated * state. Returns the associated configure serial. */ -uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_toplevel *toplevel, bool activated); /** - * Request that this toplevel surface consider itself maximized or not + * Request that this toplevel consider itself maximized or not * maximized. Returns the associated configure serial. */ -uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_toplevel *toplevel, bool maximized); /** - * Request that this toplevel surface consider itself fullscreen or not + * Request that this toplevel consider itself fullscreen or not * fullscreen. Returns the associated configure serial. */ -uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_toplevel *toplevel, bool fullscreen); /** - * Request that this toplevel surface consider itself to be resizing or not + * Request that this toplevel consider itself to be resizing or not * resizing. Returns the associated configure serial. */ -uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_toplevel *toplevel, bool resizing); /** - * Request that this toplevel surface consider itself in a tiled layout and some + * Request that this toplevel consider itself in a tiled layout and some * edges are adjacent to another part of the tiling grid. `tiled_edges` is a * bitfield of `enum wlr_edges`. Returns the associated configure serial. */ -uint32_t wlr_xdg_toplevel_set_tiled(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_tiled(struct wlr_xdg_toplevel *toplevel, uint32_t tiled_edges); /** * Request that this xdg toplevel closes. */ -void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface); +void wlr_xdg_toplevel_send_close(struct wlr_xdg_toplevel *toplevel); /** * Sets the parent of this toplevel. Parent can be NULL. */ -void wlr_xdg_toplevel_set_parent(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface *parent); +void wlr_xdg_toplevel_set_parent(struct wlr_xdg_toplevel *toplevel, + struct wlr_xdg_toplevel *parent); /** * Request that this xdg popup closes. diff --git a/tinywl/tinywl.c b/tinywl/tinywl.c index 6f628836..a4fcc262 100644 --- a/tinywl/tinywl.c +++ b/tinywl/tinywl.c @@ -78,7 +78,7 @@ struct tinywl_output { struct tinywl_view { struct wl_list link; struct tinywl_server *server; - struct wlr_xdg_surface *xdg_surface; + struct wlr_xdg_toplevel *xdg_toplevel; struct wlr_scene_node *scene_node; struct wl_listener map; struct wl_listener unmap; @@ -117,7 +117,8 @@ static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) { */ struct wlr_xdg_surface *previous = wlr_xdg_surface_from_wlr_surface( seat->keyboard_state.focused_surface); - wlr_xdg_toplevel_set_activated(previous, false); + assert(previous->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); + wlr_xdg_toplevel_set_activated(previous->toplevel, false); } struct wlr_keyboard *keyboard = wlr_seat_get_keyboard(seat); /* Move the view to the front */ @@ -125,13 +126,13 @@ static void focus_view(struct tinywl_view *view, struct wlr_surface *surface) { wl_list_remove(&view->link); wl_list_insert(&server->views, &view->link); /* Activate the new surface */ - wlr_xdg_toplevel_set_activated(view->xdg_surface, true); + wlr_xdg_toplevel_set_activated(view->xdg_toplevel, true); /* * Tell the seat to have the keyboard enter this surface. wlroots will keep * track of this and automatically send key events to the appropriate * clients without additional work on your part. */ - wlr_seat_keyboard_notify_enter(seat, view->xdg_surface->surface, + wlr_seat_keyboard_notify_enter(seat, view->xdg_toplevel->base->surface, keyboard->keycodes, keyboard->num_keycodes, &keyboard->modifiers); } @@ -172,7 +173,7 @@ static bool handle_keybinding(struct tinywl_server *server, xkb_keysym_t sym) { } struct tinywl_view *next_view = wl_container_of( server->views.prev, next_view, link); - focus_view(next_view, next_view->xdg_surface->surface); + focus_view(next_view, next_view->xdg_toplevel->base->surface); break; default: return false; @@ -381,14 +382,14 @@ static void process_cursor_resize(struct tinywl_server *server, uint32_t time) { } struct wlr_box geo_box; - wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); + wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box); view->x = new_left - geo_box.x; view->y = new_top - geo_box.y; wlr_scene_node_set_position(view->scene_node, view->x, view->y); int new_width = new_right - new_left; int new_height = new_bottom - new_top; - wlr_xdg_toplevel_set_size(view->xdg_surface, new_width, new_height); + wlr_xdg_toplevel_set_size(view->xdg_toplevel, new_width, new_height); } static void process_cursor_motion(struct tinywl_server *server, uint32_t time) { @@ -581,7 +582,7 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) { wl_list_insert(&view->server->views, &view->link); - focus_view(view, view->xdg_surface->surface); + focus_view(view, view->xdg_toplevel->base->surface); } static void xdg_toplevel_unmap(struct wl_listener *listener, void *data) { @@ -612,7 +613,7 @@ static void begin_interactive(struct tinywl_view *view, struct tinywl_server *server = view->server; struct wlr_surface *focused_surface = server->seat->pointer_state.focused_surface; - if (view->xdg_surface->surface != + if (view->xdg_toplevel->base->surface != wlr_surface_get_root_surface(focused_surface)) { /* Deny move/resize requests from unfocused clients. */ return; @@ -625,7 +626,7 @@ static void begin_interactive(struct tinywl_view *view, server->grab_y = server->cursor->y - view->y; } else { struct wlr_box geo_box; - wlr_xdg_surface_get_geometry(view->xdg_surface, &geo_box); + wlr_xdg_surface_get_geometry(view->xdg_toplevel->base, &geo_box); double border_x = (view->x + geo_box.x) + ((edges & WLR_EDGE_RIGHT) ? geo_box.width : 0); @@ -691,9 +692,9 @@ static void server_new_xdg_surface(struct wl_listener *listener, void *data) { struct tinywl_view *view = calloc(1, sizeof(struct tinywl_view)); view->server = server; - view->xdg_surface = xdg_surface; + view->xdg_toplevel = xdg_surface->toplevel; view->scene_node = wlr_scene_xdg_surface_create( - &view->server->scene->node, view->xdg_surface); + &view->server->scene->node, view->xdg_toplevel->base); view->scene_node->data = view; xdg_surface->data = view->scene_node; diff --git a/types/wlr_xdg_decoration_v1.c b/types/wlr_xdg_decoration_v1.c index b6dd003e..d0f969f4 100644 --- a/types/wlr_xdg_decoration_v1.c +++ b/types/wlr_xdg_decoration_v1.c @@ -173,11 +173,10 @@ static void decoration_manager_handle_get_toplevel_decoration( uint32_t id, struct wl_resource *toplevel_resource) { struct wlr_xdg_decoration_manager_v1 *manager = decoration_manager_from_resource(manager_resource); - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(toplevel_resource); - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(toplevel_resource); - if (wlr_surface_has_buffer(surface->surface)) { + if (wlr_surface_has_buffer(toplevel->base->surface)) { wl_resource_post_error(manager_resource, ZXDG_TOPLEVEL_DECORATION_V1_ERROR_UNCONFIGURED_BUFFER, "xdg_toplevel_decoration must not have a buffer at creation"); @@ -191,7 +190,7 @@ static void decoration_manager_handle_get_toplevel_decoration( return; } decoration->manager = manager; - decoration->surface = surface; + decoration->surface = toplevel->base; uint32_t version = wl_resource_get_version(manager_resource); decoration->resource = wl_resource_create(client, @@ -212,24 +211,26 @@ static void decoration_manager_handle_get_toplevel_decoration( wl_signal_init(&decoration->events.destroy); wl_signal_init(&decoration->events.request_mode); - wl_signal_add(&surface->events.destroy, &decoration->surface_destroy); + wl_signal_add(&toplevel->base->events.destroy, + &decoration->surface_destroy); decoration->surface_destroy.notify = toplevel_decoration_handle_surface_destroy; - wl_signal_add(&surface->events.configure, &decoration->surface_configure); + wl_signal_add(&toplevel->base->events.configure, + &decoration->surface_configure); decoration->surface_configure.notify = toplevel_decoration_handle_surface_configure; - wl_signal_add(&surface->events.ack_configure, + wl_signal_add(&toplevel->base->events.ack_configure, &decoration->surface_ack_configure); decoration->surface_ack_configure.notify = toplevel_decoration_handle_surface_ack_configure; - wl_signal_add(&surface->surface->events.commit, + wl_signal_add(&toplevel->base->surface->events.commit, &decoration->surface_commit); decoration->surface_commit.notify = toplevel_decoration_handle_surface_commit; wl_list_insert(&manager->decorations, &decoration->link); - if (surface->added) { + if (toplevel->base->added) { decoration->added = true; wlr_signal_emit_safe(&manager->events.new_toplevel_decoration, decoration); diff --git a/types/wlr_xdg_foreign_v1.c b/types/wlr_xdg_foreign_v1.c index bb747517..c07959aa 100644 --- a/types/wlr_xdg_foreign_v1.c +++ b/types/wlr_xdg_foreign_v1.c @@ -103,7 +103,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client, struct wlr_xdg_surface *surface_child = wlr_xdg_surface_from_wlr_surface(wlr_surface_child); - wlr_xdg_toplevel_set_parent(surface_child, surface); + wlr_xdg_toplevel_set_parent(surface_child->toplevel, surface->toplevel); wl_signal_add(&surface_child->events.unmap, &child->xdg_surface_unmap); wl_signal_add(&surface_child->toplevel->events.set_parent, @@ -153,7 +153,7 @@ static void destroy_imported(struct wlr_xdg_imported_v1 *imported) { wlr_xdg_surface_from_wlr_surface(child->surface); if (xdg_child != NULL) { - wlr_xdg_toplevel_set_parent(xdg_child, NULL); + wlr_xdg_toplevel_set_parent(xdg_child->toplevel, NULL); } } diff --git a/types/wlr_xdg_foreign_v2.c b/types/wlr_xdg_foreign_v2.c index 7f7bff06..abd99735 100644 --- a/types/wlr_xdg_foreign_v2.c +++ b/types/wlr_xdg_foreign_v2.c @@ -109,7 +109,7 @@ static void xdg_imported_handle_set_parent_of(struct wl_client *client, struct wlr_xdg_surface *surface_child = wlr_xdg_surface_from_wlr_surface(wlr_surface_child); - wlr_xdg_toplevel_set_parent(surface_child, surface); + wlr_xdg_toplevel_set_parent(surface_child->toplevel, surface->toplevel); wl_signal_add(&surface_child->events.unmap, &child->xdg_surface_unmap); wl_signal_add(&surface_child->toplevel->events.set_parent, @@ -159,7 +159,7 @@ static void destroy_imported(struct wlr_xdg_imported_v2 *imported) { wlr_xdg_surface_from_wlr_surface(child->surface); if (xdg_child != NULL) { - wlr_xdg_toplevel_set_parent(xdg_child, NULL); + wlr_xdg_toplevel_set_parent(xdg_child->toplevel, NULL); } } diff --git a/types/xdg_shell/wlr_xdg_surface.c b/types/xdg_shell/wlr_xdg_surface.c index 62251d53..3315456d 100644 --- a/types/xdg_shell/wlr_xdg_surface.c +++ b/types/xdg_shell/wlr_xdg_surface.c @@ -130,7 +130,8 @@ static void xdg_surface_handle_ack_configure(struct wl_client *client, assert(0 && "not reached"); break; case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - handle_xdg_toplevel_ack_configure(surface, configure); + handle_xdg_toplevel_ack_configure(surface->toplevel, + configure->toplevel_configure); break; case WLR_XDG_SURFACE_ROLE_POPUP: break; @@ -164,7 +165,8 @@ static void surface_send_configure(void *user_data) { assert(0 && "not reached"); break; case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - send_xdg_toplevel_configure(surface, configure); + configure->toplevel_configure = + send_xdg_toplevel_configure(surface->toplevel); break; case WLR_XDG_SURFACE_ROLE_POPUP: xdg_popup_send_configure(surface->popup->resource, @@ -319,7 +321,7 @@ void xdg_surface_role_commit(struct wlr_surface *wlr_surface) { // inert toplevel or popup return; case WLR_XDG_SURFACE_ROLE_TOPLEVEL: - handle_xdg_surface_toplevel_committed(surface); + handle_xdg_toplevel_committed(surface->toplevel); break; case WLR_XDG_SURFACE_ROLE_POPUP: handle_xdg_surface_popup_committed(surface); @@ -493,12 +495,6 @@ void wlr_xdg_surface_ping(struct wlr_xdg_surface *surface) { surface->client->ping_serial); } -void wlr_xdg_toplevel_send_close(struct wlr_xdg_surface *surface) { - assert(surface->toplevel); - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - xdg_toplevel_send_close(surface->toplevel->resource); -} - void wlr_xdg_popup_destroy(struct wlr_xdg_surface *surface) { if (surface == NULL) { return; diff --git a/types/xdg_shell/wlr_xdg_toplevel.c b/types/xdg_shell/wlr_xdg_toplevel.c index 47a324d2..d88e6659 100644 --- a/types/xdg_shell/wlr_xdg_toplevel.c +++ b/types/xdg_shell/wlr_xdg_toplevel.c @@ -8,38 +8,32 @@ #include "util/signal.h" void handle_xdg_toplevel_ack_configure( - struct wlr_xdg_surface *surface, - struct wlr_xdg_surface_configure *configure) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - - struct wlr_xdg_toplevel_configure *acked = configure->toplevel_configure; - assert(acked != NULL); - - surface->toplevel->pending.maximized = acked->maximized; - surface->toplevel->pending.fullscreen = acked->fullscreen; - surface->toplevel->pending.resizing = acked->resizing; - surface->toplevel->pending.activated = acked->activated; - surface->toplevel->pending.tiled = acked->tiled; - - surface->toplevel->pending.width = acked->width; - surface->toplevel->pending.height = acked->height; + struct wlr_xdg_toplevel *toplevel, + struct wlr_xdg_toplevel_configure *configure) { + toplevel->pending.maximized = configure->maximized; + toplevel->pending.fullscreen = configure->fullscreen; + toplevel->pending.resizing = configure->resizing; + toplevel->pending.activated = configure->activated; + toplevel->pending.tiled = configure->tiled; + + toplevel->pending.width = configure->width; + toplevel->pending.height = configure->height; } -void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface_configure *configure) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - - configure->toplevel_configure = malloc(sizeof(*configure->toplevel_configure)); - if (configure->toplevel_configure == NULL) { +struct wlr_xdg_toplevel_configure *send_xdg_toplevel_configure( + struct wlr_xdg_toplevel *toplevel) { + struct wlr_xdg_toplevel_configure *configure = + calloc(1, sizeof(*configure)); + if (configure == NULL) { wlr_log(WLR_ERROR, "Allocation failed"); - wl_resource_post_no_memory(surface->toplevel->resource); - return; + wl_resource_post_no_memory(toplevel->resource); + return NULL; } - *configure->toplevel_configure = surface->toplevel->scheduled; + *configure = toplevel->scheduled; struct wl_array states; wl_array_init(&states); - if (surface->toplevel->scheduled.maximized) { + if (configure->maximized) { uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(WLR_ERROR, "Could not allocate state for maximized xdg_toplevel"); @@ -47,7 +41,7 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } *s = XDG_TOPLEVEL_STATE_MAXIMIZED; } - if (surface->toplevel->scheduled.fullscreen) { + if (configure->fullscreen) { uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(WLR_ERROR, "Could not allocate state for fullscreen xdg_toplevel"); @@ -55,7 +49,7 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } *s = XDG_TOPLEVEL_STATE_FULLSCREEN; } - if (surface->toplevel->scheduled.resizing) { + if (configure->resizing) { uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(WLR_ERROR, "Could not allocate state for resizing xdg_toplevel"); @@ -63,7 +57,7 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } *s = XDG_TOPLEVEL_STATE_RESIZING; } - if (surface->toplevel->scheduled.activated) { + if (configure->activated) { uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); if (!s) { wlr_log(WLR_ERROR, "Could not allocate state for activated xdg_toplevel"); @@ -71,8 +65,8 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } *s = XDG_TOPLEVEL_STATE_ACTIVATED; } - if (surface->toplevel->scheduled.tiled) { - if (wl_resource_get_version(surface->resource) >= + if (configure->tiled) { + if (wl_resource_get_version(toplevel->resource) >= XDG_TOPLEVEL_STATE_TILED_LEFT_SINCE_VERSION) { const struct { enum wlr_edges edge; @@ -85,8 +79,7 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, }; for (size_t i = 0; i < sizeof(tiled)/sizeof(tiled[0]); ++i) { - if ((surface->toplevel->scheduled.tiled & - tiled[i].edge) == 0) { + if ((configure->tiled & tiled[i].edge) == 0) { continue; } @@ -98,7 +91,7 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } *s = tiled[i].state; } - } else if (!surface->toplevel->scheduled.maximized) { + } else if (!configure->maximized) { // This version doesn't support tiling, best we can do is make the // toplevel maximized uint32_t *s = wl_array_add(&states, sizeof(uint32_t)); @@ -111,36 +104,35 @@ void send_xdg_toplevel_configure(struct wlr_xdg_surface *surface, } } - uint32_t width = surface->toplevel->scheduled.width; - uint32_t height = surface->toplevel->scheduled.height; - xdg_toplevel_send_configure(surface->toplevel->resource, width, height, - &states); + uint32_t width = configure->width; + uint32_t height = configure->height; + xdg_toplevel_send_configure(toplevel->resource, width, height, &states); wl_array_release(&states); - return; + return configure; error_out: wl_array_release(&states); - wl_resource_post_no_memory(surface->toplevel->resource); + free(configure); + wl_resource_post_no_memory(toplevel->resource); + return NULL; } -void handle_xdg_surface_toplevel_committed(struct wlr_xdg_surface *surface) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - - if (!surface->toplevel->added) { +void handle_xdg_toplevel_committed(struct wlr_xdg_toplevel *toplevel) { + if (!toplevel->added) { // on the first commit, send a configure request to tell the client it // is added - wlr_xdg_surface_schedule_configure(surface); - surface->toplevel->added = true; + wlr_xdg_surface_schedule_configure(toplevel->base); + toplevel->added = true; return; } - surface->toplevel->current = surface->toplevel->pending; + toplevel->current = toplevel->pending; } static const struct xdg_toplevel_interface xdg_toplevel_implementation; -struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource( +struct wlr_xdg_toplevel *wlr_xdg_toplevel_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &xdg_toplevel_interface, &xdg_toplevel_implementation)); @@ -150,46 +142,45 @@ struct wlr_xdg_surface *wlr_xdg_surface_from_toplevel_resource( static void handle_parent_unmap(struct wl_listener *listener, void *data) { struct wlr_xdg_toplevel *toplevel = wl_container_of(listener, toplevel, parent_unmap); - wlr_xdg_toplevel_set_parent(toplevel->base, - toplevel->parent->toplevel->parent); + wlr_xdg_toplevel_set_parent(toplevel, + toplevel->parent->toplevel->parent->toplevel); } -void wlr_xdg_toplevel_set_parent(struct wlr_xdg_surface *surface, - struct wlr_xdg_surface *parent) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - assert(!parent || parent->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - - if (surface->toplevel->parent) { - wl_list_remove(&surface->toplevel->parent_unmap.link); +void wlr_xdg_toplevel_set_parent(struct wlr_xdg_toplevel *toplevel, + struct wlr_xdg_toplevel *parent) { + if (toplevel->parent) { + wl_list_remove(&toplevel->parent_unmap.link); } - surface->toplevel->parent = parent; - if (surface->toplevel->parent) { - surface->toplevel->parent_unmap.notify = handle_parent_unmap; - wl_signal_add(&surface->toplevel->parent->events.unmap, - &surface->toplevel->parent_unmap); + if (parent) { + toplevel->parent = parent->base; + toplevel->parent_unmap.notify = handle_parent_unmap; + wl_signal_add(&toplevel->parent->events.unmap, + &toplevel->parent_unmap); + } else { + toplevel->parent = NULL; } - wlr_signal_emit_safe(&surface->toplevel->events.set_parent, surface); + wlr_signal_emit_safe(&toplevel->events.set_parent, NULL); } static void xdg_toplevel_handle_set_parent(struct wl_client *client, struct wl_resource *resource, struct wl_resource *parent_resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - struct wlr_xdg_surface *parent = NULL; + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + struct wlr_xdg_toplevel *parent = NULL; if (parent_resource != NULL) { - parent = wlr_xdg_surface_from_toplevel_resource(parent_resource); + parent = wlr_xdg_toplevel_from_resource(parent_resource); } - wlr_xdg_toplevel_set_parent(surface, parent); + wlr_xdg_toplevel_set_parent(toplevel, parent); } static void xdg_toplevel_handle_set_title(struct wl_client *client, struct wl_resource *resource, const char *title) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); char *tmp; tmp = strdup(title); @@ -197,15 +188,15 @@ static void xdg_toplevel_handle_set_title(struct wl_client *client, return; } - free(surface->toplevel->title); - surface->toplevel->title = tmp; - wlr_signal_emit_safe(&surface->toplevel->events.set_title, surface); + free(toplevel->title); + toplevel->title = tmp; + wlr_signal_emit_safe(&toplevel->events.set_title, NULL); } static void xdg_toplevel_handle_set_app_id(struct wl_client *client, struct wl_resource *resource, const char *app_id) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); char *tmp; tmp = strdup(app_id); @@ -213,21 +204,21 @@ static void xdg_toplevel_handle_set_app_id(struct wl_client *client, return; } - free(surface->toplevel->app_id); - surface->toplevel->app_id = tmp; - wlr_signal_emit_safe(&surface->toplevel->events.set_app_id, surface); + free(toplevel->app_id); + toplevel->app_id = tmp; + wlr_signal_emit_safe(&toplevel->events.set_app_id, NULL); } static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, int32_t x, int32_t y) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); - if (!surface->configured) { - wl_resource_post_error(surface->toplevel->resource, + if (!toplevel->base->configured) { + wl_resource_post_error(toplevel->base->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -239,26 +230,26 @@ static void xdg_toplevel_handle_show_window_menu(struct wl_client *client, } struct wlr_xdg_toplevel_show_window_menu_event event = { - .surface = surface, + .surface = toplevel->base, .seat = seat, .serial = serial, .x = x, .y = y, }; - wlr_signal_emit_safe(&surface->toplevel->events.request_show_window_menu, &event); + wlr_signal_emit_safe(&toplevel->events.request_show_window_menu, &event); } static void xdg_toplevel_handle_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); - if (!surface->configured) { - wl_resource_post_error(surface->toplevel->resource, + if (!toplevel->base->configured) { + wl_resource_post_error(toplevel->base->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -270,24 +261,24 @@ static void xdg_toplevel_handle_move(struct wl_client *client, } struct wlr_xdg_toplevel_move_event event = { - .surface = surface, + .surface = toplevel->base, .seat = seat, .serial = serial, }; - wlr_signal_emit_safe(&surface->toplevel->events.request_move, &event); + wlr_signal_emit_safe(&toplevel->events.request_move, &event); } static void xdg_toplevel_handle_resize(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial, uint32_t edges) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); struct wlr_seat_client *seat = wlr_seat_client_from_resource(seat_resource); - if (!surface->configured) { - wl_resource_post_error(surface->toplevel->resource, + if (!toplevel->base->configured) { + wl_resource_post_error(toplevel->base->resource, XDG_SURFACE_ERROR_NOT_CONSTRUCTED, "surface has not been configured yet"); return; @@ -299,47 +290,47 @@ static void xdg_toplevel_handle_resize(struct wl_client *client, } struct wlr_xdg_toplevel_resize_event event = { - .surface = surface, + .surface = toplevel->base, .seat = seat, .serial = serial, .edges = edges, }; - wlr_signal_emit_safe(&surface->toplevel->events.request_resize, &event); + wlr_signal_emit_safe(&toplevel->events.request_resize, &event); } static void xdg_toplevel_handle_set_max_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - surface->toplevel->pending.max_width = width; - surface->toplevel->pending.max_height = height; + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + toplevel->pending.max_width = width; + toplevel->pending.max_height = height; } static void xdg_toplevel_handle_set_min_size(struct wl_client *client, struct wl_resource *resource, int32_t width, int32_t height) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - surface->toplevel->pending.min_width = width; - surface->toplevel->pending.min_height = height; + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + toplevel->pending.min_width = width; + toplevel->pending.min_height = height; } static void xdg_toplevel_handle_set_maximized(struct wl_client *client, struct wl_resource *resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - surface->toplevel->requested.maximized = true; - wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); - wlr_xdg_surface_schedule_configure(surface); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + toplevel->requested.maximized = true; + wlr_signal_emit_safe(&toplevel->events.request_maximize, NULL); + wlr_xdg_surface_schedule_configure(toplevel->base); } static void xdg_toplevel_handle_unset_maximized(struct wl_client *client, struct wl_resource *resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - surface->toplevel->requested.maximized = false; - wlr_signal_emit_safe(&surface->toplevel->events.request_maximize, surface); - wlr_xdg_surface_schedule_configure(surface); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + toplevel->requested.maximized = false; + wlr_signal_emit_safe(&toplevel->events.request_maximize, NULL); + wlr_xdg_surface_schedule_configure(toplevel->base); } static void handle_fullscreen_output_destroy(struct wl_listener *listener, @@ -350,9 +341,9 @@ static void handle_fullscreen_output_destroy(struct wl_listener *listener, wl_list_remove(&req->fullscreen_output_destroy.link); } -static void store_fullscreen_requested(struct wlr_xdg_surface *surface, +static void store_fullscreen_requested(struct wlr_xdg_toplevel *toplevel, bool fullscreen, struct wlr_output *output) { - struct wlr_xdg_toplevel_requested *req = &surface->toplevel->requested; + struct wlr_xdg_toplevel_requested *req = &toplevel->requested; req->fullscreen = fullscreen; if (req->fullscreen_output) { wl_list_remove(&req->fullscreen_output_destroy.link); @@ -368,49 +359,49 @@ static void store_fullscreen_requested(struct wlr_xdg_surface *surface, static void xdg_toplevel_handle_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); struct wlr_output *output = NULL; if (output_resource != NULL) { output = wlr_output_from_resource(output_resource); } - store_fullscreen_requested(surface, true, output); + store_fullscreen_requested(toplevel, true, output); struct wlr_xdg_toplevel_set_fullscreen_event event = { - .surface = surface, + .surface = toplevel->base, .fullscreen = true, .output = output, }; - wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); - wlr_xdg_surface_schedule_configure(surface); + wlr_signal_emit_safe(&toplevel->events.request_fullscreen, &event); + wlr_xdg_surface_schedule_configure(toplevel->base); } static void xdg_toplevel_handle_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); - store_fullscreen_requested(surface, false, NULL); + store_fullscreen_requested(toplevel, false, NULL); struct wlr_xdg_toplevel_set_fullscreen_event event = { - .surface = surface, + .surface = toplevel->base, .fullscreen = false, .output = NULL, }; - wlr_signal_emit_safe(&surface->toplevel->events.request_fullscreen, &event); - wlr_xdg_surface_schedule_configure(surface); + wlr_signal_emit_safe(&toplevel->events.request_fullscreen, &event); + wlr_xdg_surface_schedule_configure(toplevel->base); } static void xdg_toplevel_handle_set_minimized(struct wl_client *client, struct wl_resource *resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - surface->toplevel->requested.minimized = true; - wlr_signal_emit_safe(&surface->toplevel->events.request_minimize, surface); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + toplevel->requested.minimized = true; + wlr_signal_emit_safe(&toplevel->events.request_minimize, NULL); } static void xdg_toplevel_handle_destroy(struct wl_client *client, @@ -436,9 +427,9 @@ static const struct xdg_toplevel_interface xdg_toplevel_implementation = { }; static void xdg_toplevel_handle_resource_destroy(struct wl_resource *resource) { - struct wlr_xdg_surface *surface = - wlr_xdg_surface_from_toplevel_resource(resource); - destroy_xdg_toplevel(surface); + struct wlr_xdg_toplevel *toplevel = + wlr_xdg_toplevel_from_resource(resource); + destroy_xdg_toplevel(toplevel); } const struct wlr_surface_role xdg_toplevel_surface_role = { @@ -488,65 +479,56 @@ void create_xdg_toplevel(struct wlr_xdg_surface *xdg_surface, return; } wl_resource_set_implementation(xdg_surface->toplevel->resource, - &xdg_toplevel_implementation, xdg_surface, + &xdg_toplevel_implementation, xdg_surface->toplevel, xdg_toplevel_handle_resource_destroy); xdg_surface->role = WLR_XDG_SURFACE_ROLE_TOPLEVEL; } -void destroy_xdg_toplevel(struct wlr_xdg_surface *xdg_surface) { - if (xdg_surface == NULL) { +void destroy_xdg_toplevel(struct wlr_xdg_toplevel *toplevel) { + if (toplevel == NULL) { return; } - assert(xdg_surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - reset_xdg_surface(xdg_surface); + reset_xdg_surface(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_surface *surface, - uint32_t width, uint32_t height) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.width = width; - surface->toplevel->scheduled.height = height; +void wlr_xdg_toplevel_send_close(struct wlr_xdg_toplevel *toplevel) { + xdg_toplevel_send_close(toplevel->resource); +} - return wlr_xdg_surface_schedule_configure(surface); +uint32_t wlr_xdg_toplevel_set_size(struct wlr_xdg_toplevel *toplevel, + uint32_t width, uint32_t height) { + toplevel->scheduled.width = width; + toplevel->scheduled.height = height; + return wlr_xdg_surface_schedule_configure(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_activated(struct wlr_xdg_toplevel *toplevel, bool activated) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.activated = activated; - - return wlr_xdg_surface_schedule_configure(surface); + toplevel->scheduled.activated = activated; + return wlr_xdg_surface_schedule_configure(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_maximized(struct wlr_xdg_toplevel *toplevel, bool maximized) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.maximized = maximized; - - return wlr_xdg_surface_schedule_configure(surface); + toplevel->scheduled.maximized = maximized; + return wlr_xdg_surface_schedule_configure(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_fullscreen(struct wlr_xdg_toplevel *toplevel, bool fullscreen) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.fullscreen = fullscreen; - - return wlr_xdg_surface_schedule_configure(surface); + toplevel->scheduled.fullscreen = fullscreen; + return wlr_xdg_surface_schedule_configure(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_resizing(struct wlr_xdg_toplevel *toplevel, bool resizing) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.resizing = resizing; - - return wlr_xdg_surface_schedule_configure(surface); + toplevel->scheduled.resizing = resizing; + return wlr_xdg_surface_schedule_configure(toplevel->base); } -uint32_t wlr_xdg_toplevel_set_tiled(struct wlr_xdg_surface *surface, +uint32_t wlr_xdg_toplevel_set_tiled(struct wlr_xdg_toplevel *toplevel, uint32_t tiled) { - assert(surface->role == WLR_XDG_SURFACE_ROLE_TOPLEVEL); - surface->toplevel->scheduled.tiled = tiled; - - return wlr_xdg_surface_schedule_configure(surface); + toplevel->scheduled.tiled = tiled; + return wlr_xdg_surface_schedule_configure(toplevel->base); }