diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-07-17 11:55:05 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-07-17 11:55:05 -0400 |
commit | 6d971af5c3ceae870c424325ca06fc635703bb29 (patch) | |
tree | 886e321930a4ee95f5cb7f0136138712f5ee1c57 | |
parent | c8917395c0cc5ff9fbec3a504c1855d9012d17ed (diff) |
Turn swaybg into a shell surface
-rw-r--r-- | include/extensions.h | 2 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/extensions.c | 1 | ||||
-rw-r--r-- | sway/handlers.c | 53 | ||||
-rw-r--r-- | swaybg/main.c | 1 |
5 files changed, 43 insertions, 15 deletions
diff --git a/include/extensions.h b/include/extensions.h index d26e95c1..f6b0c00e 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; + struct wl_client *client; + wlc_handle handle; }; struct panel_config { diff --git a/sway/config.c b/sway/config.c index 766d2b23..9c957e2d 100644 --- a/sway/config.c +++ b/sway/config.c @@ -904,7 +904,6 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { } if (oc && oc->background) { - if (output->bg_pid != 0) { terminate_swaybg(output->bg_pid); } diff --git a/sway/extensions.c b/sway/extensions.c index ab425fa7..1fe15ac5 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; diff --git a/sway/handlers.c b/sway/handlers.c index 1b96be0a..72cb8057 100644 --- a/sway/handlers.c +++ b/sway/handlers.c @@ -44,6 +44,17 @@ static struct panel_config *if_panel_find_config(struct wl_client *client) { return NULL; } +static struct background_config *if_background_find_config(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 config; + } + } + return NULL; +} + static struct wlc_geometry compute_panel_geometry(struct panel_config *config) { const struct wlc_size resolution = *wlc_output_get_resolution(config->output); const struct wlc_geometry *old = wlc_view_get_geometry(config->handle); @@ -93,6 +104,21 @@ static void update_panel_geometries(wlc_handle output) { } } +static void update_background_geometry(struct background_config *config) { + struct wlc_geometry geometry = { 0 }; + geometry.size = *wlc_output_get_resolution(config->output); + wlc_view_set_geometry(config->handle, 0, &geometry); +} + +static void update_background_geometries(wlc_handle output) { + for (int i = 0; i < desktop_shell.backgrounds->length; i++) { + struct background_config *config = desktop_shell.backgrounds->items[i]; + if (config->output == output) { + update_background_geometry(config); + } + } +} + /* Handles */ static bool handle_input_created(struct libinput_device *device) { @@ -168,19 +194,6 @@ static void handle_output_destroyed(wlc_handle output) { } } -static void handle_output_pre_render(wlc_handle output) { - struct wlc_size resolution = *wlc_output_get_resolution(output); - - int i; - for (i = 0; i < desktop_shell.backgrounds->length; ++i) { - struct background_config *config = desktop_shell.backgrounds->items[i]; - if (config->output == output) { - wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, resolution }); - break; - } - } -} - static void handle_output_post_render(wlc_handle output) { ipc_get_pixels(output); arrange_windows(swayc_by_handle(output), -1, -1); @@ -201,6 +214,7 @@ static void handle_output_resolution_change(wlc_handle output, const struct wlc_ c->height = to->h; update_panel_geometries(output); + update_background_geometries(output); arrange_windows(&root_container, -1, -1); } @@ -247,6 +261,7 @@ static bool handle_view_created(wlc_handle handle) { struct wl_client *client = wlc_view_get_wl_client(handle); pid_t pid; struct panel_config *panel_config = NULL; + struct background_config *background_config = NULL; panel_config = if_panel_find_config(client); if (panel_config) { @@ -254,6 +269,17 @@ static bool handle_view_created(wlc_handle handle) { update_panel_geometry(panel_config); wlc_view_set_mask(handle, VISIBLE); wlc_view_set_output(handle, panel_config->output); + wlc_view_bring_to_front(handle); + return true; + } + + background_config = if_background_find_config(client); + if (background_config) { + background_config->handle = handle; + update_background_geometry(background_config); + wlc_view_set_mask(handle, VISIBLE); + wlc_view_set_output(handle, background_config->output); + wlc_view_send_to_back(handle); return true; } @@ -883,7 +909,6 @@ void register_wlc_handlers() { wlc_set_output_destroyed_cb(handle_output_destroyed); wlc_set_output_resolution_cb(handle_output_resolution_change); wlc_set_output_focus_cb(handle_output_focused); - wlc_set_output_render_pre_cb(handle_output_pre_render); wlc_set_output_render_post_cb(handle_output_post_render); wlc_set_view_created_cb(handle_view_created); wlc_set_view_destroyed_cb(handle_view_destroyed); diff --git a/swaybg/main.c b/swaybg/main.c index fbd0d16b..4e0cc4b3 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 |