From 52fe2688ea1068d5cd0801ead4fc078c3a37dea1 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Tue, 27 Mar 2018 17:18:16 -0400 Subject: [PATCH] Address @emersion's feedback --- include/rootston/layers.h | 1 + include/wlr/types/wlr_layer_shell.h | 14 +------ rootston/desktop.c | 6 --- rootston/layer_shell.c | 19 +++++---- types/wlr_layer_shell.c | 60 ++++++++++------------------- 5 files changed, 35 insertions(+), 65 deletions(-) diff --git a/include/rootston/layers.h b/include/rootston/layers.h index cc285fe7..35f5399e 100644 --- a/include/rootston/layers.h +++ b/include/rootston/layers.h @@ -16,6 +16,7 @@ struct roots_layer_surface { struct wl_listener surface_commit; struct wl_listener output_destroy; struct wl_listener output_mode; + struct wl_listener output_transform; bool configured; struct wlr_box geo; diff --git a/include/wlr/types/wlr_layer_shell.h b/include/wlr/types/wlr_layer_shell.h index c24b391e..e8da8e0f 100644 --- a/include/wlr/types/wlr_layer_shell.h +++ b/include/wlr/types/wlr_layer_shell.h @@ -21,7 +21,7 @@ */ struct wlr_layer_shell { struct wl_global *wl_global; - struct wl_list clients; + struct wl_list client_resources; // wl_resource struct wl_listener display_destroy; @@ -32,15 +32,6 @@ struct wlr_layer_shell { void *data; }; -struct wlr_layer_client { - struct wlr_layer_shell *shell; - struct wl_resource *resource; - struct wl_client *client; - struct wl_list surfaces; - - struct wl_list link; // wlr_layer_shell::clients -}; - struct wlr_layer_surface_state { uint32_t anchor; int32_t exclusive_zone; @@ -61,9 +52,8 @@ struct wlr_layer_surface_configure { struct wlr_layer_surface { struct wlr_surface *surface; struct wlr_output *output; - struct wlr_layer_client *client; struct wl_resource *resource; - struct wl_list link; // wlr_layer_client:surfaces + struct wlr_layer_shell *shell; const char *namespace; enum zwlr_layer_shell_v1_layer layer; diff --git a/rootston/desktop.c b/rootston/desktop.c index a0659250..9ea392f6 100644 --- a/rootston/desktop.c +++ b/rootston/desktop.c @@ -209,12 +209,6 @@ void view_arrange_maximized(struct roots_view *view) { usable_area.x += output_box->x; usable_area.y += output_box->y; - wlr_log(L_DEBUG, "output area: %dx%d@%d,%d", - output_box->width, output_box->height, - output_box->x, output_box->y); - wlr_log(L_DEBUG, "usable area: %dx%d@%d,%d", - usable_area.width, usable_area.height, - usable_area.x, usable_area.y); view_move_resize(view, usable_area.x, usable_area.y, usable_area.width, usable_area.height); view_rotate(view, 0); diff --git a/rootston/layer_shell.c b/rootston/layer_shell.c index 5efdf3c9..809ddbf3 100644 --- a/rootston/layer_shell.c +++ b/rootston/layer_shell.c @@ -82,14 +82,8 @@ static void arrange_layer(struct wlr_output *output, struct wl_list *list, wl_list_for_each(roots_surface, list, link) { struct wlr_layer_surface *layer = roots_surface->layer_surface; struct wlr_layer_surface_state *state = &layer->current; - if (exclusive) { - if (state->exclusive_zone <= 0) { - continue; - } - } else { - if (state->exclusive_zone > 0) { - continue; - } + if (exclusive != (state->exclusive_zone >0)) { + continue; } struct wlr_box bounds; if (state->exclusive_zone == -1) { @@ -212,6 +206,10 @@ static void handle_output_mode(struct wl_listener *listener, void *data) { arrange_layers((struct wlr_output *)data); } +static void handle_output_transform(struct wl_listener *listener, void *data) { + arrange_layers((struct wlr_output *)data); +} + static void handle_surface_commit(struct wl_listener *listener, void *data) { struct roots_layer_surface *layer = wl_container_of(listener, layer, surface_commit); @@ -254,6 +252,7 @@ static void handle_destroy(struct wl_listener *listener, void *data) { } wl_list_remove(&layer->output_destroy.link); wl_list_remove(&layer->output_mode.link); + wl_list_remove(&layer->output_transform.link); arrange_layers(layer->layer_surface->output); free(layer); } @@ -304,6 +303,10 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { wl_signal_add(&layer_surface->output->events.mode, &roots_surface->output_mode); + roots_surface->output_transform.notify = handle_output_transform; + wl_signal_add(&layer_surface->output->events.transform, + &roots_surface->output_transform); + roots_surface->destroy.notify = handle_destroy; wl_signal_add(&layer_surface->events.destroy, &roots_surface->destroy); roots_surface->map.notify = handle_map; diff --git a/types/wlr_layer_shell.c b/types/wlr_layer_shell.c index 761d2413..532309a3 100644 --- a/types/wlr_layer_shell.c +++ b/types/wlr_layer_shell.c @@ -18,7 +18,7 @@ static void resource_handle_destroy(struct wl_client *client, static const struct zwlr_layer_shell_v1_interface layer_shell_implementation; static const struct zwlr_layer_surface_v1_interface layer_surface_implementation; -static struct wlr_layer_client *layer_client_from_resource( +static struct wlr_layer_shell *layer_shell_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, &zwlr_layer_shell_v1_interface, &layer_shell_implementation)); @@ -58,7 +58,7 @@ static void layer_surface_handle_ack_configure(struct wl_client *client, } } if (!found) { - wl_resource_post_error(surface->client->resource, + wl_resource_post_error(resource, ZWLR_LAYER_SURFACE_V1_ERROR_INVALID_SURFACE_STATE, "wrong configure serial: %u", serial); return; @@ -156,7 +156,6 @@ static void layer_surface_destroy(struct wlr_layer_surface *surface) { layer_surface_unmap(surface); wlr_signal_emit_safe(&surface->events.destroy, surface); wl_resource_set_user_data(surface->resource, NULL); - wl_list_remove(&surface->link); wl_list_remove(&surface->surface_destroy_listener.link); wlr_surface_set_role_committed(surface->surface, NULL, NULL); free(surface); @@ -195,11 +194,11 @@ void wlr_layer_surface_configure(struct wlr_layer_surface *surface, surface->server_pending.actual_height = height; if (wlr_layer_surface_state_changed(surface)) { struct wl_display *display = - wl_client_get_display(surface->client->client); + wl_client_get_display(wl_resource_get_client(surface->resource)); struct wlr_layer_surface_configure *configure = calloc(1, sizeof(struct wlr_layer_surface_configure)); if (configure == NULL) { - wl_client_post_no_memory(surface->client->client); + wl_client_post_no_memory(wl_resource_get_client(surface->resource)); return; } surface->configure_next_serial = wl_display_next_serial(display); @@ -248,7 +247,7 @@ static void handle_wlr_surface_committed(struct wlr_surface *wlr_surface, if (!surface->added) { surface->added = true; - wlr_signal_emit_safe(&surface->client->shell->events.new_surface, + wlr_signal_emit_safe(&surface->shell->events.new_surface, surface); } if (surface->configured && wlr_surface_has_buffer(surface->surface) && @@ -274,8 +273,8 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, struct wl_resource *surface_resource, struct wl_resource *output_resource, uint32_t layer, const char *namespace) { - struct wlr_layer_client *client = - layer_client_from_resource(client_resource); + struct wlr_layer_shell *shell = + layer_shell_from_resource(client_resource); struct wlr_layer_surface *surface = calloc(1, sizeof(struct wlr_layer_surface)); @@ -284,7 +283,7 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, return; } - surface->client = client; + surface->shell = shell; surface->surface = wlr_surface_from_resource(surface_resource); surface->output = wlr_output_from_resource(output_resource); surface->resource = wl_resource_create(wl_client, @@ -322,23 +321,14 @@ static void layer_shell_handle_get_layer_surface(struct wl_client *wl_client, surface, surface->resource); wl_resource_set_implementation(surface->resource, &layer_surface_implementation, surface, layer_surface_resource_destroy); - wl_list_insert(&client->surfaces, &surface->link); } static const struct zwlr_layer_shell_v1_interface layer_shell_implementation = { .get_layer_surface = layer_shell_handle_get_layer_surface, }; -static void wlr_layer_client_destroy(struct wl_resource *resource) { - struct wlr_layer_client *client = layer_client_from_resource(resource); - - struct wlr_layer_surface *surface, *tmp = NULL; - wl_list_for_each_safe(surface, tmp, &client->surfaces, link) { - layer_surface_destroy(surface); - } - - wl_list_remove(&client->link); - free(client); +static void client_handle_destroy(struct wl_resource *resource) { + wl_list_remove(wl_resource_get_link(resource)); } static void layer_shell_bind(struct wl_client *wl_client, void *data, @@ -346,28 +336,16 @@ static void layer_shell_bind(struct wl_client *wl_client, void *data, struct wlr_layer_shell *layer_shell = data; assert(wl_client && layer_shell); - struct wlr_layer_client *client = - calloc(1, sizeof(struct wlr_layer_client)); - if (client == NULL) { - wl_client_post_no_memory(wl_client); - return; - } - - wl_list_init(&client->surfaces); - - client->resource = wl_resource_create( + struct wl_resource *resource = wl_resource_create( wl_client, &zwlr_layer_shell_v1_interface, version, id); - if (client->resource == NULL) { - free(client); + if (resource == NULL) { wl_client_post_no_memory(wl_client); return; } - client->client = wl_client; - client->shell = layer_shell; - - wl_resource_set_implementation(client->resource, - &layer_shell_implementation, client, wlr_layer_client_destroy); - wl_list_insert(&layer_shell->clients, &client->link); + wl_resource_set_implementation(resource, + &layer_shell_implementation, layer_shell, client_handle_destroy); + wl_list_insert(&layer_shell->client_resources, + wl_resource_get_link(resource)); } static void handle_display_destroy(struct wl_listener *listener, void *data) { @@ -383,7 +361,7 @@ struct wlr_layer_shell *wlr_layer_shell_create(struct wl_display *display) { return NULL; } - wl_list_init(&layer_shell->clients); + wl_list_init(&layer_shell->client_resources); struct wl_global *wl_global = wl_global_create(display, &zwlr_layer_shell_v1_interface, 1, layer_shell, layer_shell_bind); @@ -405,6 +383,10 @@ void wlr_layer_shell_destroy(struct wlr_layer_shell *layer_shell) { if (!layer_shell) { return; } + struct wl_resource *client, *tmp; + wl_resource_for_each_safe(client, tmp, &layer_shell->client_resources) { + wl_resource_destroy(client); + } wl_list_remove(&layer_shell->display_destroy.link); wl_global_destroy(layer_shell->wl_global); free(layer_shell);