diff options
-rw-r--r-- | include/extensions.h | 13 | ||||
-rw-r--r-- | sway/extensions.c | 19 | ||||
-rw-r--r-- | sway/handlers.c | 19 |
3 files changed, 47 insertions, 4 deletions
diff --git a/include/extensions.h b/include/extensions.h index e122c59a..3e2d1cde 100644 --- a/include/extensions.h +++ b/include/extensions.h | |||
@@ -1,6 +1,19 @@ | |||
1 | #ifndef _SWAY_EXTENSIONS_H | 1 | #ifndef _SWAY_EXTENSIONS_H |
2 | #define _SWAY_EXTENSIONS_H | 2 | #define _SWAY_EXTENSIONS_H |
3 | 3 | ||
4 | #include "list.h" | ||
5 | |||
6 | struct background_config { | ||
7 | wlc_handle output; | ||
8 | wlc_handle surface; | ||
9 | }; | ||
10 | |||
11 | struct desktop_shell_state { | ||
12 | list_t *backgrounds; | ||
13 | }; | ||
14 | |||
15 | extern struct desktop_shell_state desktop_shell; | ||
16 | |||
4 | void register_extensions(void); | 17 | void register_extensions(void); |
5 | 18 | ||
6 | #endif | 19 | #endif |
diff --git a/sway/extensions.c b/sway/extensions.c index a37ceaa8..5ef8a0ff 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -2,14 +2,26 @@ | |||
2 | #include <wlc/wlc-wayland.h> | 2 | #include <wlc/wlc-wayland.h> |
3 | #include "wayland-desktop-shell-server-protocol.h" | 3 | #include "wayland-desktop-shell-server-protocol.h" |
4 | #include "log.h" | 4 | #include "log.h" |
5 | #include "extensions.h" | ||
6 | |||
7 | struct desktop_shell_state desktop_shell; | ||
5 | 8 | ||
6 | static void set_background(struct wl_client *client, struct wl_resource *resource, | 9 | static void set_background(struct wl_client *client, struct wl_resource *resource, |
7 | struct wl_resource *output, struct wl_resource *surface) { | 10 | struct wl_resource *_output, struct wl_resource *_surface) { |
8 | sway_log(L_DEBUG, "Surface requesting background for output"); | 11 | wlc_handle output = wlc_handle_from_wl_output_resource(_output); |
12 | wlc_handle surface = wlc_handle_from_wl_surface_resource(_surface); | ||
13 | sway_log(L_DEBUG, "Setting surface %d as background for output %d", (int)surface, (int)output); | ||
14 | if (!output || !surface) { | ||
15 | return; | ||
16 | } | ||
17 | struct background_config *config = malloc(sizeof(struct background_config)); | ||
18 | config->output = output; | ||
19 | config->surface = surface; | ||
20 | list_add(desktop_shell.backgrounds, config); | ||
9 | } | 21 | } |
10 | 22 | ||
11 | static struct desktop_shell_interface desktop_shell_implementation = { | 23 | static struct desktop_shell_interface desktop_shell_implementation = { |
12 | .set_background = set_background, | 24 | .set_background = set_background |
13 | }; | 25 | }; |
14 | 26 | ||
15 | static void desktop_shell_bind(struct wl_client *client, void *data, | 27 | static void desktop_shell_bind(struct wl_client *client, void *data, |
@@ -29,4 +41,5 @@ static void desktop_shell_bind(struct wl_client *client, void *data, | |||
29 | 41 | ||
30 | void register_extensions(void) { | 42 | void register_extensions(void) { |
31 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 1, NULL, desktop_shell_bind); | 43 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 1, NULL, desktop_shell_bind); |
44 | desktop_shell.backgrounds = create_list(); | ||
32 | } | 45 | } |
diff --git a/sway/handlers.c b/sway/handlers.c index 3f3c1bdd..9e98cffe 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -3,6 +3,7 @@ | |||
3 | #include <stdbool.h> | 3 | #include <stdbool.h> |
4 | #include <math.h> | 4 | #include <math.h> |
5 | #include <wlc/wlc.h> | 5 | #include <wlc/wlc.h> |
6 | #include <wlc/wlc-wayland.h> | ||
6 | #include <ctype.h> | 7 | #include <ctype.h> |
7 | 8 | ||
8 | #include "handlers.h" | 9 | #include "handlers.h" |
@@ -17,6 +18,7 @@ | |||
17 | #include "focus.h" | 18 | #include "focus.h" |
18 | #include "input_state.h" | 19 | #include "input_state.h" |
19 | #include "resize.h" | 20 | #include "resize.h" |
21 | #include "extensions.h" | ||
20 | 22 | ||
21 | // Event should be sent to client | 23 | // Event should be sent to client |
22 | #define EVENT_PASSTHROUGH false | 24 | #define EVENT_PASSTHROUGH false |
@@ -63,6 +65,18 @@ static void handle_output_destroyed(wlc_handle output) { | |||
63 | } | 65 | } |
64 | } | 66 | } |
65 | 67 | ||
68 | static void handle_output_pre_render(wlc_handle output) { | ||
69 | int i; | ||
70 | for (i = 0; i < desktop_shell.backgrounds->length; ++i) { | ||
71 | struct background_config *config = desktop_shell.backgrounds->items[i]; | ||
72 | if (config->output == output) { | ||
73 | sway_log(L_DEBUG, "Rendering background surface %d", (int)config->surface); | ||
74 | wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, *wlc_output_get_resolution(output) }); | ||
75 | break; | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | |||
66 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { | 80 | static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { |
67 | sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); | 81 | sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); |
68 | swayc_t *c = swayc_by_handle(output); | 82 | swayc_t *c = swayc_by_handle(output); |
@@ -463,7 +477,10 @@ struct wlc_interface interface = { | |||
463 | .created = handle_output_created, | 477 | .created = handle_output_created, |
464 | .destroyed = handle_output_destroyed, | 478 | .destroyed = handle_output_destroyed, |
465 | .resolution = handle_output_resolution_change, | 479 | .resolution = handle_output_resolution_change, |
466 | .focus = handle_output_focused | 480 | .focus = handle_output_focused, |
481 | .render = { | ||
482 | .pre = handle_output_pre_render | ||
483 | } | ||
467 | }, | 484 | }, |
468 | .view = { | 485 | .view = { |
469 | .created = handle_view_created, | 486 | .created = handle_view_created, |