diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-09-22 13:56:51 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-22 13:56:51 -0500 |
commit | 082488a81c491faa71ddc2c87fe985ef28f5d69d (patch) | |
tree | ee7316a573d5feb5332bb5cef509bd37faf5bcf7 | |
parent | Merge pull request #2660 from RyanDwyer/fix-scratchpad-iteration (diff) | |
parent | swaybar, swaylock, & tree/container: Set cairo font options to render text an... (diff) | |
download | sway-082488a81c491faa71ddc2c87fe985ef28f5d69d.tar.gz sway-082488a81c491faa71ddc2c87fe985ef28f5d69d.tar.zst sway-082488a81c491faa71ddc2c87fe985ef28f5d69d.zip |
Merge pull request #2677 from ggreer/pretty-fonts
Render fonts slightly nicer
-rw-r--r-- | common/cairo.c | 16 | ||||
-rw-r--r-- | include/cairo.h | 2 | ||||
-rw-r--r-- | include/swaybar/bar.h | 1 | ||||
-rw-r--r-- | include/swaylock/swaylock.h | 1 | ||||
-rw-r--r-- | sway/tree/container.c | 8 | ||||
-rw-r--r-- | swaybar/bar.c | 8 | ||||
-rw-r--r-- | swaybar/render.c | 7 | ||||
-rw-r--r-- | swaylock/main.c | 8 | ||||
-rw-r--r-- | swaylock/render.c | 7 |
9 files changed, 53 insertions, 5 deletions
diff --git a/common/cairo.c b/common/cairo.c index c267c77c..e8231484 100644 --- a/common/cairo.c +++ b/common/cairo.c | |||
@@ -13,6 +13,22 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) { | |||
13 | (color >> (0*8) & 0xFF) / 255.0); | 13 | (color >> (0*8) & 0xFF) / 255.0); |
14 | } | 14 | } |
15 | 15 | ||
16 | cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel) { | ||
17 | switch (subpixel) { | ||
18 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: | ||
19 | return CAIRO_SUBPIXEL_ORDER_RGB; | ||
20 | case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: | ||
21 | return CAIRO_SUBPIXEL_ORDER_BGR; | ||
22 | case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: | ||
23 | return CAIRO_SUBPIXEL_ORDER_VRGB; | ||
24 | case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: | ||
25 | return CAIRO_SUBPIXEL_ORDER_VBGR; | ||
26 | default: | ||
27 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; | ||
28 | } | ||
29 | return CAIRO_SUBPIXEL_ORDER_DEFAULT; | ||
30 | } | ||
31 | |||
16 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, | 32 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, |
17 | int width, int height) { | 33 | int width, int height) { |
18 | int image_width = cairo_image_surface_get_width(image); | 34 | int image_width = cairo_image_surface_get_width(image); |
diff --git a/include/cairo.h b/include/cairo.h index 31672705..86530b60 100644 --- a/include/cairo.h +++ b/include/cairo.h | |||
@@ -2,8 +2,10 @@ | |||
2 | #define _SWAY_CAIRO_H | 2 | #define _SWAY_CAIRO_H |
3 | #include <stdint.h> | 3 | #include <stdint.h> |
4 | #include <cairo/cairo.h> | 4 | #include <cairo/cairo.h> |
5 | #include <wlr/types/wlr_output.h> | ||
5 | 6 | ||
6 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color); | 7 | void cairo_set_source_u32(cairo_t *cairo, uint32_t color); |
8 | cairo_subpixel_order_t to_cairo_subpixel_order(enum wl_output_subpixel subpixel); | ||
7 | 9 | ||
8 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, | 10 | cairo_surface_t *cairo_image_surface_scale(cairo_surface_t *image, |
9 | int width, int height); | 11 | int width, int height); |
diff --git a/include/swaybar/bar.h b/include/swaybar/bar.h index 4065fb8b..29e96159 100644 --- a/include/swaybar/bar.h +++ b/include/swaybar/bar.h | |||
@@ -81,6 +81,7 @@ struct swaybar_output { | |||
81 | 81 | ||
82 | uint32_t width, height; | 82 | uint32_t width, height; |
83 | int32_t scale; | 83 | int32_t scale; |
84 | enum wl_output_subpixel subpixel; | ||
84 | struct pool_buffer buffers[2]; | 85 | struct pool_buffer buffers[2]; |
85 | struct pool_buffer *current_buffer; | 86 | struct pool_buffer *current_buffer; |
86 | }; | 87 | }; |
diff --git a/include/swaylock/swaylock.h b/include/swaylock/swaylock.h index 950cfaaf..2f0cd34d 100644 --- a/include/swaylock/swaylock.h +++ b/include/swaylock/swaylock.h | |||
@@ -82,6 +82,7 @@ struct swaylock_surface { | |||
82 | bool frame_pending, dirty; | 82 | bool frame_pending, dirty; |
83 | uint32_t width, height; | 83 | uint32_t width, height; |
84 | int32_t scale; | 84 | int32_t scale; |
85 | enum wl_output_subpixel subpixel; | ||
85 | char *output_name; | 86 | char *output_name; |
86 | struct wl_list link; | 87 | struct wl_list link; |
87 | }; | 88 | }; |
diff --git a/sway/tree/container.c b/sway/tree/container.c index 47687744..8dc22410 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c | |||
@@ -465,11 +465,17 @@ static void update_title_texture(struct sway_container *con, | |||
465 | cairo_surface_t *surface = cairo_image_surface_create( | 465 | cairo_surface_t *surface = cairo_image_surface_create( |
466 | CAIRO_FORMAT_ARGB32, width, height); | 466 | CAIRO_FORMAT_ARGB32, width, height); |
467 | cairo_t *cairo = cairo_create(surface); | 467 | cairo_t *cairo = cairo_create(surface); |
468 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); | ||
469 | cairo_font_options_t *fo = cairo_font_options_create(); | ||
470 | cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); | ||
471 | cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); | ||
472 | cairo_font_options_set_subpixel_order(fo, to_cairo_subpixel_order(output->wlr_output->subpixel)); | ||
473 | cairo_set_font_options(cairo, fo); | ||
474 | cairo_font_options_destroy(fo); | ||
468 | cairo_set_source_rgba(cairo, class->background[0], class->background[1], | 475 | cairo_set_source_rgba(cairo, class->background[0], class->background[1], |
469 | class->background[2], class->background[3]); | 476 | class->background[2], class->background[3]); |
470 | cairo_paint(cairo); | 477 | cairo_paint(cairo); |
471 | PangoContext *pango = pango_cairo_create_context(cairo); | 478 | PangoContext *pango = pango_cairo_create_context(cairo); |
472 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); | ||
473 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], | 479 | cairo_set_source_rgba(cairo, class->text[0], class->text[1], |
474 | class->text[2], class->text[3]); | 480 | class->text[2], class->text[3]); |
475 | cairo_move_to(cairo, 0, 0); | 481 | cairo_move_to(cairo, 0, 0); |
diff --git a/swaybar/bar.c b/swaybar/bar.c index 69069f40..ab307fd4 100644 --- a/swaybar/bar.c +++ b/swaybar/bar.c | |||
@@ -319,10 +319,14 @@ static bool bar_uses_output(struct swaybar *bar, const char *name) { | |||
319 | return false; | 319 | return false; |
320 | } | 320 | } |
321 | 321 | ||
322 | static void output_geometry(void *data, struct wl_output *output, int32_t x, | 322 | static void output_geometry(void *data, struct wl_output *wl_output, int32_t x, |
323 | int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, | 323 | int32_t y, int32_t width_mm, int32_t height_mm, int32_t subpixel, |
324 | const char *make, const char *model, int32_t transform) { | 324 | const char *make, const char *model, int32_t transform) { |
325 | // Who cares | 325 | struct swaybar_output *output = data; |
326 | output->subpixel = subpixel; | ||
327 | if (output->surface) { | ||
328 | render_frame(output->bar, output); | ||
329 | } | ||
326 | } | 330 | } |
327 | 331 | ||
328 | static void output_mode(void *data, struct wl_output *output, uint32_t flags, | 332 | static void output_mode(void *data, struct wl_output *output, uint32_t flags, |
diff --git a/swaybar/render.c b/swaybar/render.c index 26db80cb..9413dc57 100644 --- a/swaybar/render.c +++ b/swaybar/render.c | |||
@@ -495,6 +495,13 @@ void render_frame(struct swaybar *bar, struct swaybar_output *output) { | |||
495 | cairo_surface_t *recorder = cairo_recording_surface_create( | 495 | cairo_surface_t *recorder = cairo_recording_surface_create( |
496 | CAIRO_CONTENT_COLOR_ALPHA, NULL); | 496 | CAIRO_CONTENT_COLOR_ALPHA, NULL); |
497 | cairo_t *cairo = cairo_create(recorder); | 497 | cairo_t *cairo = cairo_create(recorder); |
498 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); | ||
499 | cairo_font_options_t *fo = cairo_font_options_create(); | ||
500 | cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); | ||
501 | cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); | ||
502 | cairo_font_options_set_subpixel_order(fo, to_cairo_subpixel_order(output->subpixel)); | ||
503 | cairo_set_font_options(cairo, fo); | ||
504 | cairo_font_options_destroy(fo); | ||
498 | cairo_save(cairo); | 505 | cairo_save(cairo); |
499 | cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); | 506 | cairo_set_operator(cairo, CAIRO_OPERATOR_CLEAR); |
500 | cairo_paint(cairo); | 507 | cairo_paint(cairo); |
diff --git a/swaylock/main.c b/swaylock/main.c index 668a8742..c25c8eec 100644 --- a/swaylock/main.c +++ b/swaylock/main.c | |||
@@ -195,11 +195,15 @@ void damage_state(struct swaylock_state *state) { | |||
195 | } | 195 | } |
196 | } | 196 | } |
197 | 197 | ||
198 | static void handle_wl_output_geometry(void *data, struct wl_output *output, | 198 | static void handle_wl_output_geometry(void *data, struct wl_output *wl_output, |
199 | int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, | 199 | int32_t x, int32_t y, int32_t width_mm, int32_t height_mm, |
200 | int32_t subpixel, const char *make, const char *model, | 200 | int32_t subpixel, const char *make, const char *model, |
201 | int32_t transform) { | 201 | int32_t transform) { |
202 | // Who cares | 202 | struct swaylock_surface *surface = data; |
203 | surface->subpixel = subpixel; | ||
204 | if (surface->state->run_display) { | ||
205 | damage_surface(surface); | ||
206 | } | ||
203 | } | 207 | } |
204 | 208 | ||
205 | static void handle_wl_output_mode(void *data, struct wl_output *output, | 209 | static void handle_wl_output_mode(void *data, struct wl_output *output, |
diff --git a/swaylock/render.c b/swaylock/render.c index 66c55965..fa8832bd 100644 --- a/swaylock/render.c +++ b/swaylock/render.c | |||
@@ -39,6 +39,13 @@ void render_frame(struct swaylock_surface *surface) { | |||
39 | } | 39 | } |
40 | 40 | ||
41 | cairo_t *cairo = surface->current_buffer->cairo; | 41 | cairo_t *cairo = surface->current_buffer->cairo; |
42 | cairo_set_antialias(cairo, CAIRO_ANTIALIAS_BEST); | ||
43 | cairo_font_options_t *fo = cairo_font_options_create(); | ||
44 | cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); | ||
45 | cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); | ||
46 | cairo_font_options_set_subpixel_order(fo, to_cairo_subpixel_order(surface->subpixel)); | ||
47 | cairo_set_font_options(cairo, fo); | ||
48 | cairo_font_options_destroy(fo); | ||
42 | cairo_identity_matrix(cairo); | 49 | cairo_identity_matrix(cairo); |
43 | 50 | ||
44 | cairo_save(cairo); | 51 | cairo_save(cairo); |