diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-12-20 12:05:32 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-12-20 12:05:32 -0500 |
commit | 3082245243689e978186d6a6ba69972b050fb288 (patch) | |
tree | 364472d861aac5192e964a4984e1e63752e16c90 | |
parent | Merge pull request #378 from mikkeloscar/bar-pixel-perfect (diff) | |
parent | extensions: Track panels by wl_resource, position per panel. (diff) | |
download | sway-3082245243689e978186d6a6ba69972b050fb288.tar.gz sway-3082245243689e978186d6a6ba69972b050fb288.tar.zst sway-3082245243689e978186d6a6ba69972b050fb288.zip |
Merge pull request #373 from sce/per_panel_config
Per panel config
-rw-r--r-- | include/extensions.h | 10 | ||||
-rw-r--r-- | sway/extensions.c | 33 | ||||
-rw-r--r-- | sway/handlers.c | 2 | ||||
-rw-r--r-- | sway/layout.c | 4 |
4 files changed, 34 insertions, 15 deletions
diff --git a/include/extensions.h b/include/extensions.h index 311ead1d..164688ee 100644 --- a/include/extensions.h +++ b/include/extensions.h | |||
@@ -9,13 +9,18 @@ | |||
9 | struct background_config { | 9 | struct background_config { |
10 | wlc_handle output; | 10 | wlc_handle output; |
11 | wlc_resource surface; | 11 | wlc_resource surface; |
12 | struct wl_resource *resource; | 12 | // we need the wl_resource of the surface in the destructor |
13 | struct wl_resource *wl_surface_res; | ||
13 | }; | 14 | }; |
14 | 15 | ||
15 | struct panel_config { | 16 | struct panel_config { |
17 | // wayland resource used in callbacks, is used to track this panel | ||
18 | struct wl_resource *wl_resource; | ||
16 | wlc_handle output; | 19 | wlc_handle output; |
17 | wlc_resource surface; | 20 | wlc_resource surface; |
18 | struct wl_resource *resource; | 21 | // we need the wl_resource of the surface in the destructor |
22 | struct wl_resource *wl_surface_res; | ||
23 | enum desktop_shell_panel_position panel_position; | ||
19 | }; | 24 | }; |
20 | 25 | ||
21 | struct desktop_shell_state { | 26 | struct desktop_shell_state { |
@@ -23,7 +28,6 @@ struct desktop_shell_state { | |||
23 | list_t *panels; | 28 | list_t *panels; |
24 | list_t *lock_surfaces; | 29 | list_t *lock_surfaces; |
25 | bool is_locked; | 30 | bool is_locked; |
26 | enum desktop_shell_panel_position panel_position; | ||
27 | struct wlc_size panel_size; | 31 | struct wlc_size panel_size; |
28 | }; | 32 | }; |
29 | 33 | ||
diff --git a/sway/extensions.c b/sway/extensions.c index 5e09bdbb..00a72a80 100644 --- a/sway/extensions.c +++ b/sway/extensions.c | |||
@@ -9,12 +9,27 @@ | |||
9 | 9 | ||
10 | struct desktop_shell_state desktop_shell; | 10 | struct desktop_shell_state desktop_shell; |
11 | 11 | ||
12 | static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { | ||
13 | for (int i = 0; i < desktop_shell.panels->length; i++) { | ||
14 | struct panel_config *conf = desktop_shell.panels->items[i]; | ||
15 | if (conf->wl_resource == resource) { | ||
16 | sway_log(L_DEBUG, "Found existing panel config for resource %p", resource); | ||
17 | return conf; | ||
18 | } | ||
19 | } | ||
20 | sway_log(L_DEBUG, "Creating panel config for resource %p", resource); | ||
21 | struct panel_config *config = calloc(1, sizeof(struct panel_config)); | ||
22 | list_add(desktop_shell.panels, config); | ||
23 | config->wl_resource = resource; | ||
24 | return config; | ||
25 | } | ||
26 | |||
12 | void background_surface_destructor(struct wl_resource *resource) { | 27 | void background_surface_destructor(struct wl_resource *resource) { |
13 | sway_log(L_DEBUG, "Background surface killed"); | 28 | sway_log(L_DEBUG, "Background surface killed"); |
14 | int i; | 29 | int i; |
15 | for (i = 0; i < desktop_shell.backgrounds->length; ++i) { | 30 | for (i = 0; i < desktop_shell.backgrounds->length; ++i) { |
16 | struct background_config *config = desktop_shell.backgrounds->items[i]; | 31 | struct background_config *config = desktop_shell.backgrounds->items[i]; |
17 | if (config->resource == resource) { | 32 | if (config->wl_surface_res == resource) { |
18 | list_del(desktop_shell.backgrounds, i); | 33 | list_del(desktop_shell.backgrounds, i); |
19 | break; | 34 | break; |
20 | } | 35 | } |
@@ -26,7 +41,7 @@ void panel_surface_destructor(struct wl_resource *resource) { | |||
26 | int i; | 41 | int i; |
27 | for (i = 0; i < desktop_shell.panels->length; ++i) { | 42 | for (i = 0; i < desktop_shell.panels->length; ++i) { |
28 | struct panel_config *config = desktop_shell.panels->items[i]; | 43 | struct panel_config *config = desktop_shell.panels->items[i]; |
29 | if (config->resource == resource) { | 44 | if (config->wl_surface_res == resource) { |
30 | list_del(desktop_shell.panels, i); | 45 | list_del(desktop_shell.panels, i); |
31 | arrange_windows(&root_container, -1, -1); | 46 | arrange_windows(&root_container, -1, -1); |
32 | break; | 47 | break; |
@@ -58,7 +73,7 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc | |||
58 | struct background_config *config = malloc(sizeof(struct background_config)); | 73 | struct background_config *config = malloc(sizeof(struct background_config)); |
59 | config->output = output; | 74 | config->output = output; |
60 | config->surface = wlc_resource_from_wl_surface_resource(surface); | 75 | config->surface = wlc_resource_from_wl_surface_resource(surface); |
61 | config->resource = surface; | 76 | config->wl_surface_res = surface; |
62 | list_add(desktop_shell.backgrounds, config); | 77 | list_add(desktop_shell.backgrounds, config); |
63 | wl_resource_set_destructor(surface, background_surface_destructor); | 78 | wl_resource_set_destructor(surface, background_surface_destructor); |
64 | } | 79 | } |
@@ -69,12 +84,11 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource, | |||
69 | if (!output) { | 84 | if (!output) { |
70 | return; | 85 | return; |
71 | } | 86 | } |
72 | sway_log(L_DEBUG, "Setting surface %p as panel for output %d", surface, (int)output); | 87 | sway_log(L_DEBUG, "Setting surface %p as panel for output %d (wl_resource: %p)", surface, (int)output, resource); |
73 | struct panel_config *config = malloc(sizeof(struct panel_config)); | 88 | struct panel_config *config = find_or_create_panel_config(resource); |
74 | config->output = output; | 89 | config->output = output; |
75 | config->surface = wlc_resource_from_wl_surface_resource(surface); | 90 | config->surface = wlc_resource_from_wl_surface_resource(surface); |
76 | config->resource = surface; | 91 | config->wl_surface_res = surface; |
77 | list_add(desktop_shell.panels, config); | ||
78 | wl_resource_set_destructor(surface, panel_surface_destructor); | 92 | wl_resource_set_destructor(surface, panel_surface_destructor); |
79 | desktop_shell.panel_size = *wlc_surface_get_size(config->surface); | 93 | desktop_shell.panel_size = *wlc_surface_get_size(config->surface); |
80 | arrange_windows(&root_container, -1, -1); | 94 | arrange_windows(&root_container, -1, -1); |
@@ -121,7 +135,9 @@ static void desktop_ready(struct wl_client *client, struct wl_resource *resource | |||
121 | } | 135 | } |
122 | 136 | ||
123 | static void set_panel_position(struct wl_client *client, struct wl_resource *resource, uint32_t position) { | 137 | static void set_panel_position(struct wl_client *client, struct wl_resource *resource, uint32_t position) { |
124 | desktop_shell.panel_position = position; | 138 | struct panel_config *config = find_or_create_panel_config(resource); |
139 | sway_log(L_DEBUG, "Panel position for wl_resource %p changed %d => %d", resource, config->panel_position, position); | ||
140 | config->panel_position = position; | ||
125 | arrange_windows(&root_container, -1, -1); | 141 | arrange_windows(&root_container, -1, -1); |
126 | } | 142 | } |
127 | 143 | ||
@@ -174,7 +190,6 @@ void register_extensions(void) { | |||
174 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); | 190 | wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); |
175 | desktop_shell.backgrounds = create_list(); | 191 | desktop_shell.backgrounds = create_list(); |
176 | desktop_shell.panels = create_list(); | 192 | desktop_shell.panels = create_list(); |
177 | desktop_shell.panel_position = DESKTOP_SHELL_PANEL_POSITION_BOTTOM; | ||
178 | desktop_shell.lock_surfaces = create_list(); | 193 | desktop_shell.lock_surfaces = create_list(); |
179 | desktop_shell.is_locked = false; | 194 | desktop_shell.is_locked = false; |
180 | wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); | 195 | wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); |
diff --git a/sway/handlers.c b/sway/handlers.c index 3161c677..751e894c 100644 --- a/sway/handlers.c +++ b/sway/handlers.c | |||
@@ -90,7 +90,7 @@ static void handle_output_pre_render(wlc_handle output) { | |||
90 | struct wlc_geometry geo = { | 90 | struct wlc_geometry geo = { |
91 | .size = size | 91 | .size = size |
92 | }; | 92 | }; |
93 | switch (desktop_shell.panel_position) { | 93 | switch (config->panel_position) { |
94 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | 94 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
95 | geo.origin = (struct wlc_point){ 0, 0 }; | 95 | geo.origin = (struct wlc_point){ 0, 0 }; |
96 | break; | 96 | break; |
diff --git a/sway/layout.c b/sway/layout.c index 5b7dc486..6d82921c 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) { | |||
455 | struct panel_config *config = desktop_shell.panels->items[i]; | 455 | struct panel_config *config = desktop_shell.panels->items[i]; |
456 | if (config->output == output->handle) { | 456 | if (config->output == output->handle) { |
457 | struct wlc_size size = *wlc_surface_get_size(config->surface); | 457 | struct wlc_size size = *wlc_surface_get_size(config->surface); |
458 | sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, desktop_shell.panel_position); | 458 | sway_log(L_DEBUG, "-> Found panel for this workspace: %ux%u, position: %u", size.w, size.h, config->panel_position); |
459 | switch (desktop_shell.panel_position) { | 459 | switch (config->panel_position) { |
460 | case DESKTOP_SHELL_PANEL_POSITION_TOP: | 460 | case DESKTOP_SHELL_PANEL_POSITION_TOP: |
461 | y += size.h; height -= size.h; | 461 | y += size.h; height -= size.h; |
462 | break; | 462 | break; |