summaryrefslogtreecommitdiffstats
path: root/sway
diff options
context:
space:
mode:
authorLibravatar David Eklov <david.eklov@gmail.com>2016-07-06 00:28:14 -0500
committerLibravatar David Eklov <david.eklov@gmail.com>2016-07-14 17:18:01 -0500
commit5c4f52f9537ad0e8e1f251392fea986871ab73b0 (patch)
treeb4aeeb0ca1452824d7b8f55218dd5cebee2c5b2f /sway
parentDon't treat backgrounds as shell surfaces (diff)
downloadsway-5c4f52f9537ad0e8e1f251392fea986871ab73b0.tar.gz
sway-5c4f52f9537ad0e8e1f251392fea986871ab73b0.tar.zst
sway-5c4f52f9537ad0e8e1f251392fea986871ab73b0.zip
Set panels' geometries correctly and don't render them explicitly
Panels were explicitly rendered by calling wlc_surface_render in handle_output_pre_render. Calling wlc_surface_render does not set the surface's geometry (like wlc_view_set_geometry does). Sway did not call wlc_view_set_geometry for panels, so wlc defaulted their geometry to be at the origin. This is not correct for bars unless their location is top. Furthermore, for a surface to receive pointer events, its mask has to be set to visible. This causes wlc to render these surfaces, causing panels and backgrounds to be rendered twice. This commit makes panels and surfaces visible, sets the correct geometries and removes the code that explicitly rendered them.
Diffstat (limited to 'sway')
-rw-r--r--sway/handlers.c115
1 files changed, 75 insertions, 40 deletions
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