diff --git a/include/wayland.h b/include/wayland.h index bd7d7a87..c21568a4 100644 --- a/include/wayland.h +++ b/include/wayland.h @@ -2,6 +2,7 @@ #define _MAKO_WAYLAND_H #include +#include struct mako_state; @@ -21,6 +22,7 @@ struct mako_output { struct wl_list link; // mako_state::outputs char *name; + enum wl_output_subpixel subpixel; int32_t scale; }; diff --git a/render.c b/render.c index 9da10e72..e84a7f97 100644 --- a/render.c +++ b/render.c @@ -37,11 +37,43 @@ static void set_rectangle(cairo_t *cairo, int x, int y, int width, int height, cairo_rectangle(cairo, x * scale, y * scale, width * scale, height * scale); } +static cairo_subpixel_order_t get_cairo_subpixel_order( + enum wl_output_subpixel subpixel) { + switch (subpixel) { + case WL_OUTPUT_SUBPIXEL_UNKNOWN: + case WL_OUTPUT_SUBPIXEL_NONE: + return CAIRO_SUBPIXEL_ORDER_DEFAULT; + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_RGB: + return CAIRO_SUBPIXEL_ORDER_RGB; + case WL_OUTPUT_SUBPIXEL_HORIZONTAL_BGR: + return CAIRO_SUBPIXEL_ORDER_BGR; + case WL_OUTPUT_SUBPIXEL_VERTICAL_RGB: + return CAIRO_SUBPIXEL_ORDER_VRGB; + case WL_OUTPUT_SUBPIXEL_VERTICAL_BGR: + return CAIRO_SUBPIXEL_ORDER_VBGR; + } +} + +static void set_font_options(cairo_t *cairo, struct mako_state *state) { + if (state->surface_output == NULL) { + return; + } + + cairo_font_options_t *fo = cairo_font_options_create(); + cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_SUBPIXEL); + cairo_font_options_set_subpixel_order(fo, + get_cairo_subpixel_order(state->surface_output->subpixel)); + cairo_set_font_options(cairo, fo); + cairo_font_options_destroy(fo); +} + static int render_notification(cairo_t *cairo, struct mako_state *state, struct mako_style *style, const char *text, int offset_y, int scale) { int border_size = 2 * style->border_size; int padding_size = 2 * style->padding; + set_font_options(cairo, state); + PangoLayout *layout = pango_cairo_create_layout(cairo); set_layout_size(layout, state->width - border_size - padding_size, diff --git a/wayland.c b/wayland.c index 160e8823..41ef0534 100644 --- a/wayland.c +++ b/wayland.c @@ -40,6 +40,14 @@ static void get_xdg_output(struct mako_output *output) { output); } +static void output_handle_geometry(void *data, struct wl_output *wl_output, + int32_t x, int32_t y, int32_t phy_width, int32_t phy_height, + int32_t subpixel, const char *make, const char *model, + int32_t transform) { + struct mako_output *output = data; + output->subpixel = subpixel; +} + static void output_handle_scale(void *data, struct wl_output *wl_output, int32_t factor) { struct mako_output *output = data; @@ -47,7 +55,7 @@ static void output_handle_scale(void *data, struct wl_output *wl_output, } static const struct wl_output_listener output_listener = { - .geometry = noop, + .geometry = output_handle_geometry, .mode = noop, .done = noop, .scale = output_handle_scale,