mirror of
https://github.com/swaywm/sway.git
synced 2024-11-22 07:51:28 +00:00
swaybar: fix tray item icon scaling, positioning
This commit is contained in:
parent
bb60381c75
commit
107d15fafd
|
@ -493,24 +493,36 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
|
||||||
cairo_destroy(cairo_icon);
|
cairo_destroy(cairo_icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
int padded_size = icon_size + 2*padding;
|
double descaled_padding = (double)padding / output->scale;
|
||||||
*x -= padded_size;
|
double descaled_icon_size = (double)icon_size / output->scale;
|
||||||
int y = floor((height - padded_size) / 2.0);
|
|
||||||
|
int size = descaled_icon_size + 2 * descaled_padding;
|
||||||
|
*x -= size;
|
||||||
|
int icon_y = floor((output->height - size) / 2.0);
|
||||||
|
|
||||||
cairo_operator_t op = cairo_get_operator(cairo);
|
cairo_operator_t op = cairo_get_operator(cairo);
|
||||||
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
|
cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
|
||||||
cairo_set_source_surface(cairo, icon, *x + padding, y + padding);
|
|
||||||
cairo_rectangle(cairo, *x, y, padded_size, padded_size);
|
cairo_matrix_t scale_matrix;
|
||||||
|
cairo_pattern_t *icon_pattern = cairo_pattern_create_for_surface(icon);
|
||||||
|
// TODO: check cairo_pattern_status for "ENOMEM"
|
||||||
|
cairo_matrix_init_scale(&scale_matrix, output->scale, output->scale);
|
||||||
|
cairo_matrix_translate(&scale_matrix, -(*x + descaled_padding), -(icon_y + descaled_padding));
|
||||||
|
cairo_pattern_set_matrix(icon_pattern, &scale_matrix);
|
||||||
|
cairo_set_source(cairo, icon_pattern);
|
||||||
|
cairo_rectangle(cairo, *x, icon_y, size, size);
|
||||||
cairo_fill(cairo);
|
cairo_fill(cairo);
|
||||||
|
|
||||||
cairo_set_operator(cairo, op);
|
cairo_set_operator(cairo, op);
|
||||||
|
|
||||||
|
cairo_pattern_destroy(icon_pattern);
|
||||||
cairo_surface_destroy(icon);
|
cairo_surface_destroy(icon);
|
||||||
|
|
||||||
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
|
||||||
hotspot->x = *x;
|
hotspot->x = *x;
|
||||||
hotspot->y = 0;
|
hotspot->y = 0;
|
||||||
hotspot->width = height;
|
hotspot->width = size;
|
||||||
hotspot->height = height;
|
hotspot->height = output->height;
|
||||||
hotspot->callback = icon_hotspot_callback;
|
hotspot->callback = icon_hotspot_callback;
|
||||||
hotspot->destroy = free;
|
hotspot->destroy = free;
|
||||||
hotspot->data = strdup(sni->watcher_id);
|
hotspot->data = strdup(sni->watcher_id);
|
||||||
|
|
Loading…
Reference in a new issue