From ca43a27a216e8c2111820389c3c2a6ab3fd4f486 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 4 Jul 2016 16:53:03 -0500 Subject: [PATCH 1/4] Enable backgrounds and panels to be shell surfaces Prior to this commit all windows (e.g. shell surfaces) were handled the same way in handle_view_created. Since backgrounds and panels have to be treated differently, they could not be shell surfaces. This changes checks whether a client is a background or a panel in handle_view_created and exists to let them be dealt with elsewhere. --- include/extensions.h | 4 ++++ sway/extensions.c | 2 ++ sway/handlers.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/include/extensions.h b/include/extensions.h index 158a40a2a..90de343f7 100644 --- a/include/extensions.h +++ b/include/extensions.h @@ -11,6 +11,8 @@ struct background_config { wlc_resource surface; // we need the wl_resource of the surface in the destructor struct wl_resource *wl_surface_res; + // used to determine if client is a background + struct wl_client *client; }; struct panel_config { @@ -21,6 +23,8 @@ struct panel_config { // we need the wl_resource of the surface in the destructor struct wl_resource *wl_surface_res; enum desktop_shell_panel_position panel_position; + // used to determine if client is a panel + struct wl_client *client; }; struct desktop_shell_state { diff --git a/sway/extensions.c b/sway/extensions.c index 7bc9bbe4b..5996d9ebc 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -73,6 +73,7 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc } sway_log(L_DEBUG, "Setting surface %p as background for output %d", surface, (int)output); struct background_config *config = malloc(sizeof(struct background_config)); + config->client = client; config->output = output; config->surface = wlc_resource_from_wl_surface_resource(surface); config->wl_surface_res = surface; @@ -91,6 +92,7 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource, 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->client = client; config->surface = wlc_resource_from_wl_surface_resource(surface); config->wl_surface_res = surface; wl_resource_set_destructor(surface, panel_surface_destructor); diff --git a/sway/handlers.c b/sway/handlers.c index 53dbeb87e..b5cc68156 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -175,6 +175,30 @@ static void handle_output_focused(wlc_handle output, bool focus) { } } +static bool client_is_background(struct wl_client *client) +{ + int i; + for (i = 0; i < desktop_shell.backgrounds->length; i++) { + struct background_config *config = desktop_shell.backgrounds->items[i]; + if (config->client == client) { + return true; + } + } + return false; +} + +static bool client_is_panel(struct wl_client *client) +{ + int i; + for (i = 0; i < desktop_shell.panels->length; i++) { + struct panel_config *config = desktop_shell.panels->items[i]; + if (config->client == client) { + return true; + } + } + return false; +} + static bool handle_view_created(wlc_handle handle) { // if view is child of another view, the use that as focused container wlc_handle parent = wlc_view_get_parent(handle); @@ -185,6 +209,10 @@ static bool handle_view_created(wlc_handle handle) { struct wl_client *client = wlc_view_get_wl_client(handle); pid_t pid; + if (client_is_background(client) || client_is_panel(client)) { + return true; + } + // Get parent container, to add view in if (parent) { focused = swayc_by_handle(parent); From 942585a01238b57d50a7f7aaae71ebc2121c73d2 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 4 Jul 2016 17:01:37 -0500 Subject: [PATCH 2/4] Move code to make a window a shell surface into seperate function --- include/client/window.h | 1 + wayland/window.c | 11 ++++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/include/client/window.h b/include/client/window.h index eff9032df..e48ec4f38 100644 --- a/include/client/window.h +++ b/include/client/window.h @@ -42,5 +42,6 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t void window_teardown(struct window *state); int window_prerender(struct window *state); int window_render(struct window *state); +void window_make_shell(struct window *window); #endif diff --git a/wayland/window.c b/wayland/window.c index ba64cb60f..fbb26ba1e 100644 --- a/wayland/window.c +++ b/wayland/window.c @@ -59,6 +59,13 @@ static const struct wl_shell_surface_listener surface_listener = { .configure = shell_surface_configure }; +void window_make_shell(struct window *window) +{ + window->shell_surface = wl_shell_get_shell_surface(window->registry->shell, window->surface); + wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window); + wl_shell_surface_set_toplevel(window->shell_surface); +} + struct window *window_setup(struct registry *registry, uint32_t width, uint32_t height, bool shell_surface) { struct window *window = malloc(sizeof(struct window)); memset(window, 0, sizeof(struct window)); @@ -69,9 +76,7 @@ struct window *window_setup(struct registry *registry, uint32_t width, uint32_t window->surface = wl_compositor_create_surface(registry->compositor); if (shell_surface) { - window->shell_surface = wl_shell_get_shell_surface(registry->shell, window->surface); - wl_shell_surface_add_listener(window->shell_surface, &surface_listener, window); - wl_shell_surface_set_toplevel(window->shell_surface); + window_make_shell(window); } if (registry->pointer) { wl_pointer_add_listener(registry->pointer, &pointer_listener, window); From a11cdefa3c087e91e824d277cbb7cb1d297a2654 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 4 Jul 2016 17:03:55 -0500 Subject: [PATCH 3/4] swaybar: Make swaybar a shell surface --- swaybar/bar.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/swaybar/bar.c b/swaybar/bar.c index 957e5bdf3..32ee56a6e 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c @@ -80,13 +80,15 @@ void bar_setup(struct bar *bar, const char *socket_path, const char *bar_id) { struct output_state *output = bar_output->registry->outputs->items[bar_output->idx]; - bar_output->window = window_setup(bar_output->registry, output->width, 30, false); + bar_output->window = window_setup(bar_output->registry, output->width, 60, false); if (!bar_output->window) { sway_abort("Failed to create window."); } desktop_shell_set_panel(bar_output->registry->desktop_shell, output->output, bar_output->window->surface); desktop_shell_set_panel_position(bar_output->registry->desktop_shell, bar->config->position); + window_make_shell(bar_output->window); + /* set font */ bar_output->window->font = bar->config->font; From 093e84728beab3ad9aa3cf88c4da174ea0fe1712 Mon Sep 17 00:00:00 2001 From: David Eklov Date: Mon, 4 Jul 2016 17:04:16 -0500 Subject: [PATCH 4/4] swaybg: Make swaybg a shell surface --- swaybg/main.c | 1 + 1 file changed, 1 insertion(+) diff --git a/swaybg/main.c b/swaybg/main.c index fbd0d16be..90ef2aee1 100644 --- a/swaybg/main.c +++ b/swaybg/main.c @@ -54,6 +54,7 @@ int main(int argc, const char **argv) { sway_abort("Failed to create surfaces."); } desktop_shell_set_background(registry->desktop_shell, output->output, window->surface); + window_make_shell(window); list_add(surfaces, window); #ifdef WITH_GDK_PIXBUF