Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use cairo_scale instead of * scale #392

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions icon.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,9 @@ struct mako_icon *create_icon(struct mako_notification *notif) {
#endif

void draw_icon(cairo_t *cairo, struct mako_icon *icon,
double xpos, double ypos, double scale) {
double xpos, double ypos) {
cairo_save(cairo);
cairo_scale(cairo, scale*icon->scale, scale*icon->scale);
cairo_scale(cairo, icon->scale, icon->scale);
cairo_set_source_surface(cairo, icon->image, xpos/icon->scale, ypos/icon->scale);
cairo_paint(cairo);
cairo_restore(cairo);
Expand Down
2 changes: 1 addition & 1 deletion include/icon.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ struct mako_image_data {
struct mako_icon *create_icon(struct mako_notification *notif);
void destroy_icon(struct mako_icon *icon);
void draw_icon(cairo_t *cairo, struct mako_icon *icon,
double xpos, double ypos, double scale);
double xpos, double ypos);

#endif
2 changes: 1 addition & 1 deletion include/render.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
struct mako_state;
struct mako_surface;

int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale);
int render(struct mako_surface *surface, struct pool_buffer *buffer);

#endif
54 changes: 21 additions & 33 deletions render.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,17 @@ static void set_source_u32(cairo_t *cairo, uint32_t color) {
(color >> (0*8) & 0xFF) / 255.0);
}

static void set_layout_size(PangoLayout *layout, int width, int height,
int scale) {
pango_layout_set_width(layout, width * scale * PANGO_SCALE);
pango_layout_set_height(layout, height * scale * PANGO_SCALE);
}

static void move_to(cairo_t *cairo, double x, double y, int scale) {
cairo_move_to(cairo, x * scale, y * scale);
static void set_layout_size(PangoLayout *layout, int width, int height) {
pango_layout_set_width(layout, width * PANGO_SCALE);
pango_layout_set_height(layout, height * PANGO_SCALE);
}

static void set_rounded_rectangle(cairo_t *cairo, double x, double y, double width, double height,
int scale, int radius) {
int radius) {
if (width == 0 || height == 0) {
return;
}
x *= scale;
y *= scale;
width *= scale;
height *= scale;
radius *= scale;

double degrees = M_PI / 180.0;

cairo_new_sub_path(cairo);
Expand Down Expand Up @@ -91,7 +82,7 @@ static void set_font_options(cairo_t *cairo, struct mako_surface *surface) {
}

static int render_notification(cairo_t *cairo, struct mako_state *state, struct mako_surface *surface,
struct mako_style *style, const char *text, struct mako_icon *icon, int offset_y, int scale,
struct mako_style *style, const char *text, struct mako_icon *icon, int offset_y,
struct mako_hotspot *hotspot, int progress) {
int border_size = 2 * style->border_size;
int padding_height = style->padding.top + style->padding.bottom;
Expand Down Expand Up @@ -142,7 +133,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
set_font_options(cairo, surface);

PangoLayout *layout = pango_cairo_create_layout(cairo);
set_layout_size(layout, text_layout_width, text_layout_height, scale);
set_layout_size(layout, text_layout_width, text_layout_height);
pango_layout_set_alignment(layout, style->text_alignment);
pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR);
pango_layout_set_ellipsize(layout, PANGO_ELLIPSIZE_END);
Expand All @@ -164,12 +155,10 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
pango_layout_set_text(layout, text, -1);
}

if (attrs == NULL) {
attrs = pango_attr_list_new();
if (attrs != NULL) {
pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs);
}
pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs);

int buffer_text_height = 0;
int buffer_text_width = 0;
Expand All @@ -179,8 +168,8 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
if (pango_layout_get_character_count(layout) > 0) {
pango_layout_get_pixel_size(layout, &buffer_text_width, &buffer_text_height);
}
int text_height = buffer_text_height / scale;
int text_width = buffer_text_width / scale;
int text_height = buffer_text_height;
int text_width = buffer_text_width;

if (text_height > text_layout_height) {
text_height = text_layout_height;
Expand Down Expand Up @@ -210,7 +199,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
offset_y + style->border_size / 2.0,
notif_background_width,
notif_height - style->border_size,
scale, radius);
radius);

// Render background, keeping the path.
set_source_u32(cairo, style->colors.background);
Expand Down Expand Up @@ -241,7 +230,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
offset_y + style->border_size,
progress_width,
notif_height - style->border_size,
scale, 0);
0);
cairo_fill(cairo);
cairo_restore(cairo);

Expand All @@ -253,7 +242,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
cairo_append_path(cairo, border_path);
set_source_u32(cairo, style->colors.border);
cairo_set_operator(cairo, CAIRO_OPERATOR_SOURCE);
cairo_set_line_width(cairo, style->border_size * scale);
cairo_set_line_width(cairo, style->border_size);
cairo_stroke(cairo);
cairo_restore(cairo);

Expand Down Expand Up @@ -288,7 +277,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
ypos = offset_y + text_y + text_height + style->margin.bottom;
break;
}
draw_icon(cairo, icon, xpos, ypos, scale);
draw_icon(cairo, icon, xpos, ypos);
}

if (icon_vertical) {
Expand All @@ -299,10 +288,9 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct

// Render text
set_source_u32(cairo, style->colors.text);
move_to(cairo,
cairo_move_to(cairo,
offset_x + style->border_size + text_x,
offset_y + style->border_size + text_y,
scale);
offset_y + style->border_size + text_y);
pango_cairo_update_layout(cairo, layout);
pango_cairo_show_layout(cairo, layout);

Expand All @@ -319,7 +307,7 @@ static int render_notification(cairo_t *cairo, struct mako_state *state, struct
return notif_height;
}

int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale) {
int render(struct mako_surface *surface, struct pool_buffer *buffer) {
struct mako_state *state = surface->state;
cairo_t *cairo = buffer->cairo;

Expand Down Expand Up @@ -395,7 +383,7 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)

struct mako_icon *icon = (style->icons) ? notif->icon : NULL;
int notif_height = render_notification(
cairo, state, surface, style, text, icon, total_height, scale,
cairo, state, surface, style, text, icon, total_height,
&notif->hotspot, notif->progress);
free(text);

Expand Down Expand Up @@ -442,7 +430,7 @@ int render(struct mako_surface *surface, struct pool_buffer *buffer, int scale)
format_text(style->format, text, format_hidden_text, &data);

int hidden_height = render_notification(
cairo, state, surface, style, text, NULL, total_height, scale, NULL, 0);
cairo, state, surface, style, text, NULL, total_height, NULL, 0);
free(text);
destroy_notification(hidden_notif);

Expand Down
8 changes: 7 additions & 1 deletion wayland.c
Original file line number Diff line number Diff line change
Expand Up @@ -575,8 +575,14 @@ static void send_frame(struct mako_surface *surface) {
return;
}

cairo_t *cairo = surface->current_buffer->cairo;

cairo_identity_matrix(cairo);
cairo_scale(cairo, scale, scale);

struct mako_output *output = get_configured_output(surface);
int height = render(surface, surface->current_buffer, scale);

int height = render(surface, surface->current_buffer);

// There are two cases where we want to tear down the surface: zero
// notifications (height = 0) or moving between outputs.
Expand Down