diff options
author | 2015-11-29 12:03:13 -0500 | |
---|---|---|
committer | 2015-11-29 12:03:13 -0500 | |
commit | e59cffcea2a881f16de3716c6b24d93aceb8c79a (patch) | |
tree | a09447b6eb903573edb598c7b80ac7c3c492dee5 /sway | |
parent | Add swaybar basics (diff) | |
download | sway-e59cffcea2a881f16de3716c6b24d93aceb8c79a.tar.gz sway-e59cffcea2a881f16de3716c6b24d93aceb8c79a.tar.zst sway-e59cffcea2a881f16de3716c6b24d93aceb8c79a.zip |
Support desktop shell panels in compositor
Diffstat (limited to 'sway')
-rw-r--r-- | sway/extensions.c | 51 | ||||
-rw-r--r-- | sway/handlers.c | 34 | ||||
-rw-r--r-- | sway/layout.c | 22 |
3 files changed, 103 insertions, 4 deletions
diff --git a/sway/extensions.c b/sway/extensions.c index aa51b474..1f8e9a7c 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -2,6 +2,7 @@ | |||
2 | #include <wlc/wlc.h> | 2 | #include <wlc/wlc.h> |
3 | #include <wlc/wlc-wayland.h> | 3 | #include <wlc/wlc-wayland.h> |
4 | #include "wayland-desktop-shell-server-protocol.h" | 4 | #include "wayland-desktop-shell-server-protocol.h" |
5 | #include "layout.h" | ||
5 | #include "log.h" | 6 | #include "log.h" |
6 | #include "extensions.h" | 7 | #include "extensions.h" |
7 | 8 | ||
@@ -20,13 +21,55 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc | |||
20 | list_add(desktop_shell.backgrounds, config); | 21 | list_add(desktop_shell.backgrounds, config); |
21 | } | 22 | } |
22 | 23 | ||
24 | static void set_panel(struct wl_client *client, struct wl_resource *resource, | ||
25 | struct wl_resource *_output, struct wl_resource *surface) { | ||
26 | wlc_handle output = wlc_handle_from_wl_output_resource(_output); | ||
27 | if (!output) { | ||
28 | return; | ||
29 | } | ||
30 | sway_log(L_DEBUG, "Setting surface %p as panel for output %d", surface, (int)output); | ||
31 | struct panel_config *config = malloc(sizeof(struct panel_config)); | ||
32 | config->output = output; | ||
33 | config->surface = wlc_resource_from_wl_surface_resource(surface); | ||
34 | list_add(desktop_shell.panels, config); | ||
35 | desktop_shell.panel_size = *wlc_surface_get_size(config->surface); | ||
36 | arrange_windows(&root_container, -1, -1); | ||
37 | } | ||
38 | |||
39 | static void set_lock_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) { | ||
40 | sway_log(L_ERROR, "desktop_set_lock_surface is not currently supported"); | ||
41 | } | ||
42 | |||
43 | static void unlock(struct wl_client *client, struct wl_resource *resource) { | ||
44 | sway_log(L_ERROR, "desktop_unlock is not currently supported"); | ||
45 | } | ||
46 | |||
47 | static void set_grab_surface(struct wl_client *client, struct wl_resource *resource, struct wl_resource *surface) { | ||
48 | sway_log(L_ERROR, "desktop_set_grab_surface is not currently supported"); | ||
49 | } | ||
50 | |||
51 | static void desktop_ready(struct wl_client *client, struct wl_resource *resource) { | ||
52 | // nop | ||
53 | } | ||
54 | |||
55 | static void set_panel_position(struct wl_client *client, struct wl_resource *resource, uint32_t position) { | ||
56 | desktop_shell.panel_position = position; | ||
57 | arrange_windows(&root_container, -1, -1); | ||
58 | } | ||
59 | |||
23 | static struct desktop_shell_interface desktop_shell_implementation = { | 60 | static struct desktop_shell_interface desktop_shell_implementation = { |
24 | .set_background = set_background | 61 | .set_background = set_background, |
62 | .set_panel = set_panel, | ||
63 | .set_lock_surface = set_lock_surface, | ||
64 | .unlock = unlock, | ||
65 | .set_grab_surface = set_grab_surface, | ||
66 | .desktop_ready = desktop_ready, | ||
67 | .set_panel_position = set_panel_position | ||
25 | }; | 68 | }; |
26 | 69 | ||
27 | static void desktop_shell_bind(struct wl_client *client, void *data, | 70 | static void desktop_shell_bind(struct wl_client *client, void *data, |
28 | unsigned int version, unsigned int id) { | 71 | unsigned int version, unsigned int id) { |
29 | if (version > 1) { | 72 | if (version > 3) { |
30 | // Unsupported version | 73 | // Unsupported version |
31 | return; | 74 | return; |
32 | } | 75 | } |
@@ -40,6 +83,8 @@ static void desktop_shell_bind(struct wl_client *client, void *data, | |||
40 | } | 83 | } |
41 | 84 | ||
42 | void register_extensions(void) { | 85 | void register_extensions(void) { |
43 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 1, NULL, desktop_shell_bind); | 86 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); |
44 | desktop_shell.backgrounds = create_list(); | 87 | desktop_shell.backgrounds = create_list(); |
88 | desktop_shell.panels = create_list(); | ||
89 | desktop_shell.panel_position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
45 | } | 90 | } |
diff --git a/sway/handlers.c b/sway/handlers.c index 267a8f3a..2029ae84 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -72,11 +72,43 @@ static void handle_output_destroyed(wlc_handle output) { | |||
72 | } | 72 | } |
73 | 73 | ||
74 | static void handle_output_pre_render(wlc_handle output) { | 74 | static void handle_output_pre_render(wlc_handle output) { |
75 | struct wlc_size resolution = *wlc_output_get_resolution(output); | ||
76 | |||
75 | int i; | 77 | int i; |
76 | for (i = 0; i < desktop_shell.backgrounds->length; ++i) { | 78 | for (i = 0; i < desktop_shell.backgrounds->length; ++i) { |
77 | struct background_config *config = desktop_shell.backgrounds->items[i]; | 79 | struct background_config *config = desktop_shell.backgrounds->items[i]; |
78 | if (config->output == output) { | 80 | if (config->output == output) { |
79 | wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, *wlc_output_get_resolution(output) }); | 81 | wlc_surface_render(config->surface, &(struct wlc_geometry){ wlc_origin_zero, resolution }); |
82 | break; | ||
83 | } | ||
84 | } | ||
85 | |||
86 | for (i = 0; i < desktop_shell.panels->length; ++i) { | ||
87 | struct panel_config *config = desktop_shell.panels->items[i]; | ||
88 | if (config->output == output) { | ||
89 | struct wlc_size size = *wlc_surface_get_size(config->surface); | ||
90 | struct wlc_geometry geo = { | ||
91 | .size = size | ||
92 | }; | ||
93 | switch (desktop_shell.panel_position) { | ||
94 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | ||
95 | geo.origin = (struct wlc_origin){ 0, 0 }; | ||
96 | break; | ||
97 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: | ||
98 | geo.origin = (struct wlc_origin){ 0, resolution.h - size.h }; | ||
99 | break; | ||
100 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: | ||
101 | geo.origin = (struct wlc_origin){ 0, 0 }; | ||
102 | break; | ||
103 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: | ||
104 | geo.origin = (struct wlc_origin){ resolution.w - size.w, 0 }; | ||
105 | break; | ||
106 | } | ||
107 | wlc_surface_render(config->surface, &geo); | ||
108 | if (size.w != desktop_shell.panel_size.w || size.h != desktop_shell.panel_size.h) { | ||
109 | desktop_shell.panel_size = size; | ||
110 | arrange_windows(&root_container, -1, -1); | ||
111 | } | ||
80 | break; | 112 | break; |
81 | } | 113 | } |
82 | } | 114 | } |
diff --git a/sway/layout.c b/sway/layout.c index de186886..70980ec3 100644 --- a/sway/layout.c +++ b/sway/layout.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <stdbool.h> | 2 | #include <stdbool.h> |
3 | #include <wlc/wlc.h> | 3 | #include <wlc/wlc.h> |
4 | #include "extensions.h" | ||
4 | #include "layout.h" | 5 | #include "layout.h" |
5 | #include "log.h" | 6 | #include "log.h" |
6 | #include "list.h" | 7 | #include "list.h" |
@@ -426,6 +427,27 @@ static void arrange_windows_r(swayc_t *container, double width, double height) { | |||
426 | } | 427 | } |
427 | return; | 428 | return; |
428 | case C_OUTPUT: | 429 | case C_OUTPUT: |
430 | for (i = 0; i < desktop_shell.panels->length; ++i) { | ||
431 | struct panel_config *config = desktop_shell.panels->items[i]; | ||
432 | if (config->output == container->handle) { | ||
433 | struct wlc_size size = *wlc_surface_get_size(config->surface); | ||
434 | switch (desktop_shell.panel_position) { | ||
435 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | ||
436 | y += size.h; height -= size.h; | ||
437 | break; | ||
438 | case DESKTOP_SHELL_PANEL_POSITION_BOTTOM: | ||
439 | height -= size.h; | ||
440 | break; | ||
441 | case DESKTOP_SHELL_PANEL_POSITION_LEFT: | ||
442 | x += size.w; width -= size.w; | ||
443 | break; | ||
444 | case DESKTOP_SHELL_PANEL_POSITION_RIGHT: | ||
445 | width -= size.w; | ||
446 | break; | ||
447 | } | ||
448 | } | ||
449 | } | ||
450 | |||
429 | container->width = width; | 451 | container->width = width; |
430 | container->height = height; | 452 | container->height = height; |
431 | x = 0, y = 0; | 453 | x = 0, y = 0; |