Fixed known regressions from the wlr_scene migration

This commit is contained in:
Keith Bowes 2022-03-03 10:35:50 -05:00
parent 579a2d2084
commit ac01aefe32
4 changed files with 58 additions and 14 deletions

View file

@ -5,6 +5,7 @@
void init_xdg_shell(struct wb_server *server); void init_xdg_shell(struct wb_server *server);
void focus_view(struct wb_view *view, struct wlr_surface *surface); void focus_view(struct wb_view *view, struct wlr_surface *surface);
struct wlr_output *get_active_output(struct wb_view *view);
struct wb_view *get_view_at( struct wb_view *get_view_at(
struct wb_server *server, double lx, double ly, struct wb_server *server, double lx, double ly,
struct wlr_surface **surface, double *sx, double *sy); struct wlr_surface **surface, double *sx, double *sy);

View file

@ -56,6 +56,14 @@ static void arrange_surface (struct wb_output *output, struct wlr_box *full_area
struct wb_layer_surface *surface = desc->data; struct wb_layer_surface *surface = desc->data;
wlr_scene_layer_surface_v1_configure(surface->scene, wlr_scene_layer_surface_v1_configure(surface->scene,
full_area, usable_area); full_area, usable_area);
if (surface->scene->layer_surface->current.layer !=
ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
wlr_scene_node_raise_to_top(scene_node);
}
if (surface->scene->layer_surface == output->server->seat->focused_layer) {
seat_set_focus_layer(output->server->seat, surface->scene->layer_surface);
}
#endif #endif
} }
} }
@ -133,8 +141,22 @@ static void handle_surface_commit(struct wl_listener *listener, void *data) {
if (committed || layer_surface->mapped != surface->mapped) { if (committed || layer_surface->mapped != surface->mapped) {
surface->mapped = layer_surface->mapped; surface->mapped = layer_surface->mapped;
#if WLR_CHECK_VERSION(0, 17, 0)
arrange_layers(surface->output); arrange_layers(surface->output);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(layer_surface->surface, &now);
} }
#else
}
arrange_layers(surface->output);
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
wlr_surface_send_frame_done(layer_surface->surface, &now);
#endif
#endif #endif
} }
@ -163,14 +185,20 @@ static void handle_map(struct wl_listener *listener, void *data) {
} }
static void handle_unmap(struct wl_listener *listener, void *data) { static void handle_unmap(struct wl_listener *listener, void *data) {
#if WLR_CHECK_VERSION(0, 16, 0)
struct wb_layer_surface *surface = wl_container_of( struct wb_layer_surface *surface = wl_container_of(
listener, surface, unmap); listener, surface, unmap);
#if WLR_CHECK_VERSION(0, 16, 0)
struct wb_seat *seat = surface->server->seat; struct wb_seat *seat = surface->server->seat;
if (seat->focused_layer == surface->scene->layer_surface) { if (seat->focused_layer == surface->scene->layer_surface) {
seat_set_focus_layer(seat, seat->focused_layer); seat_set_focus_layer(seat, NULL);
} }
#endif #endif
struct wb_view *view = wl_container_of(surface->server->views.next, view, link);
if (view) {
focus_view(view, view->xdg_toplevel->base->surface);
}
} }
static void wb_layer_surface_destroy(struct wb_layer_surface *surface) { static void wb_layer_surface_destroy(struct wb_layer_surface *surface) {
@ -300,8 +328,11 @@ static void handle_new_popup(struct wl_listener *listener, void *data) {
void handle_layer_shell_surface(struct wl_listener *listener, void *data) { void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
struct wlr_layer_surface_v1 *layer_surface = data; struct wlr_layer_surface_v1 *layer_surface = data;
if (layer_surface->output == NULL) if (layer_surface->output == NULL) {
return; struct wb_server *server = wl_container_of(listener, server, new_layer_surface);
struct wb_view *view = wl_container_of(server->views.next, view, link);
layer_surface->output = get_active_output(view);
}
struct wb_output *output = layer_surface->output->data; struct wb_output *output = layer_surface->output->data;
if (!layer_surface->output) { if (!layer_surface->output) {

View file

@ -18,7 +18,6 @@ struct wb_layer_surface {
struct wl_listener map; struct wl_listener map;
struct wl_listener unmap; struct wl_listener unmap;
struct wl_listener surface_commit; struct wl_listener surface_commit;
struct wl_listener output_destroy;
struct wl_listener new_popup; struct wl_listener new_popup;
}; };

View file

@ -38,7 +38,7 @@ void focus_view(struct wb_view *view, struct wlr_surface *surface) {
/* Don't re-focus an already focused surface. */ /* Don't re-focus an already focused surface. */
return; return;
} }
if (prev_surface) { if (prev_surface && wlr_surface_is_xdg_surface(prev_surface)) {
/* /*
* Deactivate the previously focused surface. This lets the client know * Deactivate the previously focused surface. This lets the client know
* it no longer has focus and the client will repaint accordingly, e.g. * it no longer has focus and the client will repaint accordingly, e.g.
@ -70,15 +70,19 @@ void focus_view(struct wb_view *view, struct wlr_surface *surface) {
seat_focus_surface(server->seat, view->xdg_toplevel->base->surface); seat_focus_surface(server->seat, view->xdg_toplevel->base->surface);
} }
static struct wlr_box get_usable_area(struct wb_view *view) { struct wlr_output *get_active_output(struct wb_view *view) {
double closest_x, closest_y; double closest_x, closest_y;
struct wlr_output *output = NULL; struct wlr_output *output = NULL;
struct wlr_box usable_area = {0};
wlr_output_layout_closest_point(view->server->output_layout, output, wlr_output_layout_closest_point(view->server->output_layout, output,
view->current_position.x + view->current_position.width / 2, view->current_position.x + view->current_position.width / 2,
view->current_position.y + view->current_position.height / 2, view->current_position.y + view->current_position.height / 2,
&closest_x, &closest_y); &closest_x, &closest_y);
output = wlr_output_layout_output_at(view->server->output_layout, closest_x, closest_y); return wlr_output_layout_output_at(view->server->output_layout, closest_x, closest_y);
}
static struct wlr_box get_usable_area(struct wb_view *view) {
struct wlr_output *output = get_active_output(view);
struct wlr_box usable_area = {0};
wlr_output_effective_resolution(output, &usable_area.width, &usable_area.height); wlr_output_effective_resolution(output, &usable_area.width, &usable_area.height);
return usable_area; return usable_area;
} }
@ -108,12 +112,21 @@ static void xdg_toplevel_map(struct wl_listener *listener, void *data) {
view->current_position.y = 0; view->current_position.y = 0;
} }
/* A view no larger than a title bar shouldn't be sized or focused */
/* TODO: Get the title bar height from the theme */
if (view->current_position.height > 9 &&
view->current_position.height > 9 *
(usable_area.width / usable_area.height)) {
#if WLR_CHECK_VERSION(0, 16, 0) #if WLR_CHECK_VERSION(0, 16, 0)
wlr_xdg_toplevel_set_size(view->xdg_toplevel, view->current_position.width, view->current_position.height); wlr_xdg_toplevel_set_size(view->xdg_toplevel,
view->current_position.width, view->current_position.height);
#else #else
wlr_xdg_toplevel_set_size(view->xdg_surface, view->current_position.width, view->current_position.height); wlr_xdg_toplevel_set_size(view->xdg_surface,
view->current_position.width, view->current_position.height);
#endif #endif
focus_view(view, view->xdg_toplevel->base->surface); focus_view(view, view->xdg_toplevel->base->surface);
}
wlr_scene_node_set_position(view->scene_node, wlr_scene_node_set_position(view->scene_node,
view->current_position.x, view->current_position.y); view->current_position.x, view->current_position.y);
} }