diff options
Diffstat (limited to 'swaybar/tray/item.c')
-rw-r--r-- | swaybar/tray/item.c | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index 19f4beac..ca6c03ad 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c | |||
@@ -1,4 +1,3 @@ | |||
1 | #define _POSIX_C_SOURCE 200809L | ||
2 | #include <arpa/inet.h> | 1 | #include <arpa/inet.h> |
3 | #include <cairo.h> | 2 | #include <cairo.h> |
4 | #include <limits.h> | 3 | #include <limits.h> |
@@ -7,12 +6,12 @@ | |||
7 | #include <string.h> | 6 | #include <string.h> |
8 | #include "swaybar/bar.h" | 7 | #include "swaybar/bar.h" |
9 | #include "swaybar/config.h" | 8 | #include "swaybar/config.h" |
9 | #include "swaybar/image.h" | ||
10 | #include "swaybar/input.h" | 10 | #include "swaybar/input.h" |
11 | #include "swaybar/tray/host.h" | 11 | #include "swaybar/tray/host.h" |
12 | #include "swaybar/tray/icon.h" | 12 | #include "swaybar/tray/icon.h" |
13 | #include "swaybar/tray/item.h" | 13 | #include "swaybar/tray/item.h" |
14 | #include "swaybar/tray/tray.h" | 14 | #include "swaybar/tray/tray.h" |
15 | #include "background-image.h" | ||
16 | #include "cairo_util.h" | 15 | #include "cairo_util.h" |
17 | #include "list.h" | 16 | #include "list.h" |
18 | #include "log.h" | 17 | #include "log.h" |
@@ -385,13 +384,18 @@ static int cmp_sni_id(const void *item, const void *cmp_to) { | |||
385 | 384 | ||
386 | static enum hotspot_event_handling icon_hotspot_callback( | 385 | static enum hotspot_event_handling icon_hotspot_callback( |
387 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, | 386 | struct swaybar_output *output, struct swaybar_hotspot *hotspot, |
388 | double x, double y, uint32_t button, void *data) { | 387 | double x, double y, uint32_t button, bool released, void *data) { |
389 | sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data); | 388 | sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data); |
390 | 389 | ||
391 | struct swaybar_tray *tray = output->bar->tray; | 390 | struct swaybar_tray *tray = output->bar->tray; |
392 | int idx = list_seq_find(tray->items, cmp_sni_id, data); | 391 | int idx = list_seq_find(tray->items, cmp_sni_id, data); |
393 | 392 | ||
394 | if (idx != -1) { | 393 | if (idx != -1) { |
394 | if (released) { | ||
395 | // Since we handle the pressed event, also handle the released event | ||
396 | // to block it from falling through to a binding in the bar | ||
397 | return HOTSPOT_IGNORE; | ||
398 | } | ||
395 | struct swaybar_sni *sni = tray->items->items[idx]; | 399 | struct swaybar_sni *sni = tray->items->items[idx]; |
396 | // guess global position since wayland doesn't expose it | 400 | // guess global position since wayland doesn't expose it |
397 | struct swaybar_config *config = tray->bar->config; | 401 | struct swaybar_config *config = tray->bar->config; |
@@ -426,7 +430,7 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme, | |||
426 | list_free(icon_search_paths); | 430 | list_free(icon_search_paths); |
427 | if (icon_path) { | 431 | if (icon_path) { |
428 | cairo_surface_destroy(sni->icon); | 432 | cairo_surface_destroy(sni->icon); |
429 | sni->icon = load_background_image(icon_path); | 433 | sni->icon = load_image(icon_path); |
430 | free(icon_path); | 434 | free(icon_path); |
431 | return; | 435 | return; |
432 | } | 436 | } |
@@ -466,6 +470,11 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, | |||
466 | sni->target_size = target_size; | 470 | sni->target_size = target_size; |
467 | } | 471 | } |
468 | 472 | ||
473 | // Passive | ||
474 | if (sni->status && sni->status[0] == 'P') { | ||
475 | return 0; | ||
476 | } | ||
477 | |||
469 | int icon_size; | 478 | int icon_size; |
470 | cairo_surface_t *icon; | 479 | cairo_surface_t *icon; |
471 | if (sni->icon) { | 480 | if (sni->icon) { |
@@ -493,24 +502,36 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x, | |||
493 | cairo_destroy(cairo_icon); | 502 | cairo_destroy(cairo_icon); |
494 | } | 503 | } |
495 | 504 | ||
496 | int padded_size = icon_size + 2*padding; | 505 | double descaled_padding = (double)padding / output->scale; |
497 | *x -= padded_size; | 506 | double descaled_icon_size = (double)icon_size / output->scale; |
498 | int y = floor((height - padded_size) / 2.0); | 507 | |
508 | int size = descaled_icon_size + 2 * descaled_padding; | ||
509 | *x -= size; | ||
510 | int icon_y = floor((output->height - size) / 2.0); | ||
499 | 511 | ||
500 | cairo_operator_t op = cairo_get_operator(cairo); | 512 | cairo_operator_t op = cairo_get_operator(cairo); |
501 | cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); | 513 | cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); |
502 | cairo_set_source_surface(cairo, icon, *x + padding, y + padding); | 514 | |
503 | cairo_rectangle(cairo, *x, y, padded_size, padded_size); | 515 | cairo_matrix_t scale_matrix; |
516 | cairo_pattern_t *icon_pattern = cairo_pattern_create_for_surface(icon); | ||
517 | // TODO: check cairo_pattern_status for "ENOMEM" | ||
518 | cairo_matrix_init_scale(&scale_matrix, output->scale, output->scale); | ||
519 | cairo_matrix_translate(&scale_matrix, -(*x + descaled_padding), -(icon_y + descaled_padding)); | ||
520 | cairo_pattern_set_matrix(icon_pattern, &scale_matrix); | ||
521 | cairo_set_source(cairo, icon_pattern); | ||
522 | cairo_rectangle(cairo, *x, icon_y, size, size); | ||
504 | cairo_fill(cairo); | 523 | cairo_fill(cairo); |
524 | |||
505 | cairo_set_operator(cairo, op); | 525 | cairo_set_operator(cairo, op); |
506 | 526 | ||
527 | cairo_pattern_destroy(icon_pattern); | ||
507 | cairo_surface_destroy(icon); | 528 | cairo_surface_destroy(icon); |
508 | 529 | ||
509 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); | 530 | struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); |
510 | hotspot->x = *x; | 531 | hotspot->x = *x; |
511 | hotspot->y = 0; | 532 | hotspot->y = 0; |
512 | hotspot->width = height; | 533 | hotspot->width = size; |
513 | hotspot->height = height; | 534 | hotspot->height = output->height; |
514 | hotspot->callback = icon_hotspot_callback; | 535 | hotspot->callback = icon_hotspot_callback; |
515 | hotspot->destroy = free; | 536 | hotspot->destroy = free; |
516 | hotspot->data = strdup(sni->watcher_id); | 537 | hotspot->data = strdup(sni->watcher_id); |