diff options
author | 2016-07-14 18:57:37 -0400 | |
---|---|---|
committer | 2016-07-14 18:57:37 -0400 | |
commit | 6abbe04e7590f3bfba13351eb87ada70ac3d506e (patch) | |
tree | f7c64d6e9d082bd080960c42e21e54edf01839de /swaybar/render.c | |
parent | Merge pull request #726 from Hummer12007/hwc (diff) | |
parent | Send command to sway to change workspace when workspace button is clicked (diff) | |
download | sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.tar.gz sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.tar.zst sway-6abbe04e7590f3bfba13351eb87ada70ac3d506e.zip |
Merge pull request #743 from deklov/panel-as-shell-03
Set panels/backgrounds' geometries correctly and don't render them ex…
Diffstat (limited to 'swaybar/render.c')
-rw-r--r-- | swaybar/render.c | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/swaybar/render.c b/swaybar/render.c index 273bd4f0..cea36f52 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -172,7 +172,7 @@ static void render_block(struct window *window, struct config *config, struct st | |||
172 | 172 | ||
173 | } | 173 | } |
174 | 174 | ||
175 | static char *handle_workspace_number(bool strip_num, const char *ws_name) { | 175 | static const char *strip_workspace_name(bool strip_num, const char *ws_name) { |
176 | bool strip = false; | 176 | bool strip = false; |
177 | int i; | 177 | int i; |
178 | 178 | ||
@@ -190,18 +190,23 @@ static char *handle_workspace_number(bool strip_num, const char *ws_name) { | |||
190 | } | 190 | } |
191 | 191 | ||
192 | if (strip) { | 192 | if (strip) { |
193 | return strdup(ws_name + i); | 193 | return ws_name + i; |
194 | } | 194 | } |
195 | 195 | ||
196 | return strdup(ws_name); | 196 | return ws_name; |
197 | } | ||
198 | |||
199 | void workspace_button_size(struct window *window, const char *workspace_name, int *width, int *height) { | ||
200 | const char *stripped_name = strip_workspace_name(swaybar.config->strip_workspace_numbers, workspace_name); | ||
201 | |||
202 | get_text_size(window->cairo, window->font, width, height, false, "%s", stripped_name); | ||
203 | *width += 2 * ws_horizontal_padding; | ||
204 | *height += 2 * ws_vertical_padding; | ||
197 | } | 205 | } |
198 | 206 | ||
199 | static void render_workspace_button(struct window *window, struct config *config, struct workspace *ws, double *x) { | 207 | static void render_workspace_button(struct window *window, struct config *config, struct workspace *ws, double *x) { |
200 | // strip workspace numbers if required | 208 | const char *stripped_name = strip_workspace_name(config->strip_workspace_numbers, ws->name); |
201 | char *name = handle_workspace_number(config->strip_workspace_numbers, ws->name); | ||
202 | 209 | ||
203 | int width, height; | ||
204 | get_text_size(window->cairo, window->font, &width, &height, false, "%s", name); | ||
205 | struct box_colors box_colors; | 210 | struct box_colors box_colors; |
206 | if (ws->urgent) { | 211 | if (ws->urgent) { |
207 | box_colors = config->colors.urgent_workspace; | 212 | box_colors = config->colors.urgent_workspace; |
@@ -213,26 +218,25 @@ static void render_workspace_button(struct window *window, struct config *config | |||
213 | box_colors = config->colors.inactive_workspace; | 218 | box_colors = config->colors.inactive_workspace; |
214 | } | 219 | } |
215 | 220 | ||
221 | int width, height; | ||
222 | workspace_button_size(window, stripped_name, &width, &height); | ||
223 | |||
216 | // background | 224 | // background |
217 | cairo_set_source_u32(window->cairo, box_colors.background); | 225 | cairo_set_source_u32(window->cairo, box_colors.background); |
218 | cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1, | 226 | cairo_rectangle(window->cairo, *x, 1.5, width - 1, height); |
219 | height + ws_vertical_padding * 2); | ||
220 | cairo_fill(window->cairo); | 227 | cairo_fill(window->cairo); |
221 | 228 | ||
222 | // border | 229 | // border |
223 | cairo_set_source_u32(window->cairo, box_colors.border); | 230 | cairo_set_source_u32(window->cairo, box_colors.border); |
224 | cairo_rectangle(window->cairo, *x, 1.5, width + ws_horizontal_padding * 2 - 1, | 231 | cairo_rectangle(window->cairo, *x, 1.5, width - 1, height); |
225 | height + ws_vertical_padding * 2); | ||
226 | cairo_stroke(window->cairo); | 232 | cairo_stroke(window->cairo); |
227 | 233 | ||
228 | // text | 234 | // text |
229 | cairo_set_source_u32(window->cairo, box_colors.text); | 235 | cairo_set_source_u32(window->cairo, box_colors.text); |
230 | cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin); | 236 | cairo_move_to(window->cairo, (int)*x + ws_horizontal_padding, margin); |
231 | pango_printf(window->cairo, window->font, false, "%s", name); | 237 | pango_printf(window->cairo, window->font, false, "%s", stripped_name); |
232 | |||
233 | *x += width + ws_horizontal_padding * 2 + ws_spacing; | ||
234 | 238 | ||
235 | free(name); | 239 | *x += width + ws_spacing; |
236 | } | 240 | } |
237 | 241 | ||
238 | static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) { | 242 | static void render_binding_mode_indicator(struct window *window, struct config *config, double pos) { |