From e45fd9b6c5dfb858c6f86277351bc216574d8200 Mon Sep 17 00:00:00 2001 From: "S. Christoffer Eliesen" Date: Sun, 20 Dec 2015 12:49:11 +0100 Subject: [PATCH] extensions: Track panels by wl_resource, position per panel. Track each panel separately via its wl_resource. `set_panel_position` might be called before `set_panel`, so reuse panel config. Place the position in panel_config so that each panel has its own position. --- include/extensions.h | 4 +++- sway/extensions.c | 25 ++++++++++++++++++++----- sway/handlers.c | 2 +- sway/layout.c | 4 ++-- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/include/extensions.h b/include/extensions.h index 67c7d5fe5..164688eef 100644 --- a/include/extensions.h +++ b/include/extensions.h @@ -14,10 +14,13 @@ struct background_config { }; struct panel_config { + // wayland resource used in callbacks, is used to track this panel + struct wl_resource *wl_resource; wlc_handle output; wlc_resource surface; // we need the wl_resource of the surface in the destructor struct wl_resource *wl_surface_res; + enum desktop_shell_panel_position panel_position; }; struct desktop_shell_state { @@ -25,7 +28,6 @@ struct desktop_shell_state { list_t *panels; list_t *lock_surfaces; bool is_locked; - enum desktop_shell_panel_position panel_position; struct wlc_size panel_size; }; diff --git a/sway/extensions.c b/sway/extensions.c index d37eadddb..00a72a804 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -9,6 +9,21 @@ struct desktop_shell_state desktop_shell; +static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { + for (int i = 0; i < desktop_shell.panels->length; i++) { + struct panel_config *conf = desktop_shell.panels->items[i]; + if (conf->wl_resource == resource) { + sway_log(L_DEBUG, "Found existing panel config for resource %p", resource); + return conf; + } + } + sway_log(L_DEBUG, "Creating panel config for resource %p", resource); + struct panel_config *config = calloc(1, sizeof(struct panel_config)); + list_add(desktop_shell.panels, config); + config->wl_resource = resource; + return config; +} + void background_surface_destructor(struct wl_resource *resource) { sway_log(L_DEBUG, "Background surface killed"); int i; @@ -69,12 +84,11 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource, if (!output) { return; } - sway_log(L_DEBUG, "Setting surface %p as panel for output %d", surface, (int)output); - struct panel_config *config = malloc(sizeof(struct panel_config)); + sway_log(L_DEBUG, "Setting surface %p as panel for output %d (wl_resource: %p)", surface, (int)output, resource); + struct panel_config *config = find_or_create_panel_config(resource); config->output = output; config->surface = wlc_resource_from_wl_surface_resource(surface); config->wl_surface_res = surface; - list_add(desktop_shell.panels, config); wl_resource_set_destructor(surface, panel_surface_destructor); desktop_shell.panel_size = *wlc_surface_get_size(config->surface); arrange_windows(&root_container, -1, -1); @@ -121,7 +135,9 @@ static void desktop_ready(struct wl_client *client, struct wl_resource *resource } static void set_panel_position(struct wl_client *client, struct wl_resource *resource, uint32_t position) { - desktop_shell.panel_position = position; + struct panel_config *config = find_or_create_panel_config(resource); + sway_log(L_DEBUG, "Panel position for wl_resource %p changed %d => %d", resource, config->panel_position, position); + config->panel_position = position; arrange_windows(&root_container, -1, -1); } @@ -174,7 +190,6 @@ void register_extensions(void) { wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); desktop_shell.backgrounds = create_list(); desktop_shell.panels = create_list(); - desktop_shell.panel_position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; desktop_shell.lock_surfaces = create_list(); desktop_shell.is_locked = false; wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); diff --git a/sway/handlers.c b/sway/handlers.c index 3161c6771..751e894c3 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -90,7 +90,7 @@ static void handle_output_pre_render(wlc_handle output) { struct wlc_geometry geo = { .size = size }; - switch (desktop_shell.panel_position) { + switch (config->panel_position) { case DESKTOP_SHELL_PANEL_POSITION_TOP: geo.origin = (struct wlc_point){ 0, 0 }; break; diff --git a/sway/layout.c b/sway/layout.c index 5b7dc4863..6d82921c2 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -455,8 +455,8 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { struct panel_config *config = desktop_shell.panels->items[i]; if (config->output == output->handle) { struct wlc_size size = *wlc_surface_get_size(config->surface); - sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, desktop_shell.panel_position); - switch (desktop_shell.panel_position) { + sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position); + switch (config->panel_position) { case DESKTOP_SHELL_PANEL_POSITION_TOP: y += size.h; height -= size.h; break;