aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/render.c
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 15:16:12 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2018-03-29 22:11:08 -0400
commit0d0ab7c5ce148bce841fa0682d04bc7b6c21b902 (patch)
treebc3dcefa0e306ac00d81a0cabbd6a0404d7baff6 /swaybar/render.c
parentIterate over workspaces backwards (diff)
downloadsway-0d0ab7c5ce148bce841fa0682d04bc7b6c21b902.tar.gz
sway-0d0ab7c5ce148bce841fa0682d04bc7b6c21b902.tar.zst
sway-0d0ab7c5ce148bce841fa0682d04bc7b6c21b902.zip
Implement status line
Does not yet support i3bar json protocol
Diffstat (limited to 'swaybar/render.c')
-rw-r--r--swaybar/render.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/swaybar/render.c b/swaybar/render.c
index f797873c..ec1239a1 100644
--- a/swaybar/render.c
+++ b/swaybar/render.c
@@ -9,12 +9,59 @@
9#include "swaybar/bar.h" 9#include "swaybar/bar.h"
10#include "swaybar/config.h" 10#include "swaybar/config.h"
11#include "swaybar/render.h" 11#include "swaybar/render.h"
12#include "swaybar/status_line.h"
12#include "wlr-layer-shell-unstable-v1-client-protocol.h" 13#include "wlr-layer-shell-unstable-v1-client-protocol.h"
13 14
14static const int ws_horizontal_padding = 5; 15static const int ws_horizontal_padding = 5;
15static const double ws_vertical_padding = 1.5; 16static const double ws_vertical_padding = 1.5;
16static const double border_width = 1; 17static const double border_width = 1;
17 18
19static uint32_t render_status_line_text(cairo_t *cairo,
20 struct swaybar_config *config, struct status_line *status,
21 bool focused, uint32_t width, uint32_t height) {
22 if (!status->text) {
23 return 0;
24 }
25 //wlr_log(L_DEBUG, "focused %d", focused);
26 cairo_set_source_u32(cairo, focused ?
27 config->colors.focused_statusline : config->colors.statusline);
28 static const int margin = 3;
29 int text_width, text_height;
30 get_text_size(cairo, config->font, &text_width, &text_height,
31 1, config->pango_markup, "%s", status->text);
32 uint32_t ideal_height = text_height + ws_vertical_padding * 2;
33 if (height < ideal_height) {
34 height = ideal_height;
35 }
36 double text_y = height / 2.0 - text_height / 2.0;
37 cairo_move_to(cairo, width - text_width - margin, (int)floor(text_y));
38 pango_printf(cairo, config->font, 1, config->pango_markup,
39 "%s", status->text);
40 return ideal_height;
41}
42
43static uint32_t render_status_line_i3bar(cairo_t *cairo,
44 struct swaybar_config *config, struct status_line *status,
45 bool focused, uint32_t width, uint32_t height) {
46 // TODO
47 return 0;
48}
49
50static uint32_t render_status_line(cairo_t *cairo,
51 struct swaybar_config *config, struct status_line *status,
52 bool focused, uint32_t width, uint32_t height) {
53 switch (status->protocol) {
54 case PROTOCOL_TEXT:
55 return render_status_line_text(cairo,
56 config, status, focused, width, height);
57 case PROTOCOL_I3BAR:
58 return render_status_line_i3bar(cairo,
59 config, status, focused, width, height);
60 default:
61 return 0;
62 }
63}
64
18static uint32_t render_binding_mode_indicator(cairo_t *cairo, 65static uint32_t render_binding_mode_indicator(cairo_t *cairo,
19 struct swaybar_config *config, const char *mode, double x, 66 struct swaybar_config *config, const char *mode, double x,
20 uint32_t height) { 67 uint32_t height) {
@@ -148,6 +195,11 @@ static uint32_t render_to_cairo(cairo_t *cairo,
148 cairo, config, config->mode, x, output->height); 195 cairo, config, config->mode, x, output->height);
149 max_height = h > max_height ? h : max_height; 196 max_height = h > max_height ? h : max_height;
150 } 197 }
198 if (bar->status) {
199 uint32_t h = render_status_line(cairo, config, bar->status,
200 output->focused, output->width, output->height);
201 max_height = h > max_height ? h : max_height;
202 }
151 203
152 return max_height > output->height ? max_height : output->height; 204 return max_height > output->height ? max_height : output->height;
153} 205}
@@ -157,6 +209,10 @@ void render_frame(struct swaybar *bar,
157 cairo_surface_t *recorder = cairo_recording_surface_create( 209 cairo_surface_t *recorder = cairo_recording_surface_create(
158 CAIRO_CONTENT_COLOR_ALPHA, NULL); 210 CAIRO_CONTENT_COLOR_ALPHA, NULL);
159 cairo_t *cairo = cairo_create(recorder); 211 cairo_t *cairo = cairo_create(recorder);
212 cairo_save(cairo);
213 cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR);
214 cairo_paint(cairo);
215 cairo_restore(cairo);
160 uint32_t height = render_to_cairo(cairo, bar, output); 216 uint32_t height = render_to_cairo(cairo, bar, output);
161 if (bar->config->height >= 0 && height < (uint32_t)bar->config->height) { 217 if (bar->config->height >= 0 && height < (uint32_t)bar->config->height) {
162 height = bar->config->height; 218 height = bar->config->height;