summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/extensions.h2
-rw-r--r--sway/handlers.c115
2 files changed, 77 insertions, 40 deletions
diff --git a/include/extensions.h b/include/extensions.h
index 2e2e4b07..d26e95c1 100644
--- a/include/extensions.h
+++ b/include/extensions.h
@@ -23,6 +23,8 @@ struct panel_config {
23 enum desktop_shell_panel_position panel_position; 23 enum desktop_shell_panel_position panel_position;
24 // used to determine if client is a panel 24 // used to determine if client is a panel
25 struct wl_client *client; 25 struct wl_client *client;
26 // wlc handle for this panel's surface, not set until panel is created
27 wlc_handle handle;
26}; 28};
27 29
28struct desktop_shell_state { 30struct desktop_shell_state {
diff --git a/sway/handlers.c b/sway/handlers.c
index c339fa5e..a7a87564 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -33,6 +33,66 @@
33// Event handled by sway and should not be sent to client 33// Event handled by sway and should not be sent to client
34#define EVENT_HANDLED true 34#define EVENT_HANDLED true
35 35
36static struct panel_config *if_panel_find_config(struct wl_client *client) {
37 int i;
38 for (i = 0; i < desktop_shell.panels->length; i++) {
39 struct panel_config *config = desktop_shell.panels->items[i];
40 if (config->client == client) {
41 return config;
42 }
43 }
44 return NULL;
45}
46
47static struct wlc_geometry compute_panel_geometry(struct panel_config *config) {
48 const struct wlc_size resolution = *wlc_output_get_resolution(config->output);
49 const struct wlc_geometry *old = wlc_view_get_geometry(config->handle);
50 struct wlc_geometry new;
51
52 switch (config->panel_position) {
53 case DESKTOP_SHELL_PANEL_POSITION_TOP:
54 new.origin.x = 0;
55 new.origin.y = 0;
56 new.size.w = resolution.w;
57 new.size.h = old->size.h;
58 break;
59 case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
60 new.origin.x = 0;
61 new.origin.y = resolution.h - old->size.h;
62 new.size.w = resolution.w;
63 new.size.h = old->size.h;
64 break;
65 case DESKTOP_SHELL_PANEL_POSITION_LEFT:
66 new.origin.x = 0;
67 new.origin.y = 0;
68 new.size.w = old->size.w;
69 new.size.h = resolution.h;
70 break;
71 case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
72 new.origin.x = resolution.w - old->size.w;
73 new.origin.y = 0;
74 new.size.w = old->size.w;
75 new.size.h = resolution.h;
76 break;
77 }
78
79 return new;
80}
81
82static void update_panel_geometry(struct panel_config *config) {
83 struct wlc_geometry geometry = compute_panel_geometry(config);
84 wlc_view_set_geometry(config->handle, 0, &geometry);
85}
86
87static void update_panel_geometries(wlc_handle output) {
88 for (int i = 0; i < desktop_shell.panels->length; i++) {
89 struct panel_config *config = desktop_shell.panels->items[i];
90 if (config->output == output) {
91 update_panel_geometry(config);
92 }
93 }
94}
95
36/* Handles */ 96/* Handles */
37 97
38static bool handle_input_created(struct libinput_device *device) { 98static bool handle_input_created(struct libinput_device *device) {
@@ -119,32 +179,6 @@ static void handle_output_pre_render(wlc_handle output) {
119 break; 179 break;
120 } 180 }
121 } 181 }
122
123 for (i = 0; i < desktop_shell.panels->length; ++i) {
124 struct panel_config *config = desktop_shell.panels->items[i];
125 if (config->output == output) {
126 struct wlc_size size = *wlc_surface_get_size(config->surface);
127 struct wlc_geometry geo = {
128 .size = size
129 };
130 switch (config->panel_position) {
131 case DESKTOP_SHELL_PANEL_POSITION_TOP:
132 geo.origin = (struct wlc_point){ 0, 0 };
133 break;
134 case DESKTOP_SHELL_PANEL_POSITION_BOTTOM:
135 geo.origin = (struct wlc_point){ 0, resolution.h - size.h };
136 break;
137 case DESKTOP_SHELL_PANEL_POSITION_LEFT:
138 geo.origin = (struct wlc_point){ 0, 0 };
139 break;
140 case DESKTOP_SHELL_PANEL_POSITION_RIGHT:
141 geo.origin = (struct wlc_point){ resolution.w - size.w, 0 };
142 break;
143 }
144 wlc_surface_render(config->surface, &geo);
145 break;
146 }
147 }
148} 182}
149 183
150static void handle_output_post_render(wlc_handle output) { 184static void handle_output_post_render(wlc_handle output) {
@@ -158,10 +192,16 @@ static void handle_view_pre_render(wlc_handle view) {
158 192
159static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) { 193static void handle_output_resolution_change(wlc_handle output, const struct wlc_size *from, const struct wlc_size *to) {
160 sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h); 194 sway_log(L_DEBUG, "Output %u resolution changed to %d x %d", (unsigned int)output, to->w, to->h);
195
161 swayc_t *c = swayc_by_handle(output); 196 swayc_t *c = swayc_by_handle(output);
162 if (!c) return; 197 if (!c) {
198 return;
199 }
163 c->width = to->w; 200 c->width = to->w;
164 c->height = to->h; 201 c->height = to->h;
202
203 update_panel_geometries(output);
204
165 arrange_windows(&root_container, -1, -1); 205 arrange_windows(&root_container, -1, -1);
166} 206}
167 207
@@ -176,17 +216,6 @@ static void handle_output_focused(wlc_handle output, bool focus) {
176 } 216 }
177} 217}
178 218
179static bool client_is_panel(struct wl_client *client) {
180 int i;
181 for (i = 0; i < desktop_shell.panels->length; i++) {
182 struct panel_config *config = desktop_shell.panels->items[i];
183 if (config->client == client) {
184 return true;
185 }
186 }
187 return false;
188}
189
190static void ws_cleanup() { 219static void ws_cleanup() {
191 swayc_t *op, *ws; 220 swayc_t *op, *ws;
192 int i = 0, j; 221 int i = 0, j;
@@ -217,8 +246,14 @@ static bool handle_view_created(wlc_handle handle) {
217 bool return_to_workspace = false; 246 bool return_to_workspace = false;
218 struct wl_client *client = wlc_view_get_wl_client(handle); 247 struct wl_client *client = wlc_view_get_wl_client(handle);
219 pid_t pid; 248 pid_t pid;
220 249 struct panel_config *panel_config = NULL;
221 if (client_is_panel(client)) { 250
251 panel_config = if_panel_find_config(client);
252 if (panel_config) {
253 panel_config->handle = handle;
254 update_panel_geometry(panel_config);
255 wlc_view_set_mask(handle, VISIBLE);
256 wlc_view_set_output(handle, panel_config->output);
222 return true; 257 return true;
223 } 258 }
224 259