Skip to content

Commit

Permalink
Use output subpixel when rendering text
Browse files Browse the repository at this point in the history
Fixes #63
  • Loading branch information
emersion committed Sep 23, 2018
1 parent e228571 commit 365549b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
2 changes: 2 additions & 0 deletions include/wayland.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define _MAKO_WAYLAND_H

#include <stdbool.h>
#include <wayland-client-protocol.h>

struct mako_state;

Expand All @@ -21,6 +22,7 @@ struct mako_output {
struct wl_list link; // mako_state::outputs

char *name;
enum wl_output_subpixel subpixel;
int32_t scale;
};

Expand Down
32 changes: 32 additions & 0 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,22 @@ 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;
output->scale = factor;
}

static const struct wl_output_listener output_listener = {
.geometry = noop,
.geometry = output_handle_geometry,
.mode = noop,
.done = noop,
.scale = output_handle_scale,
Expand Down

0 comments on commit 365549b

Please sign in to comment.