aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/tray/item.c
diff options
context:
space:
mode:
Diffstat (limited to 'swaybar/tray/item.c')
-rw-r--r--swaybar/tray/item.c53
1 files changed, 40 insertions, 13 deletions
diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c
index a5660f62..d5fe50b1 100644
--- a/swaybar/tray/item.c
+++ b/swaybar/tray/item.c
@@ -7,13 +7,13 @@
7#include <string.h> 7#include <string.h>
8#include "swaybar/bar.h" 8#include "swaybar/bar.h"
9#include "swaybar/config.h" 9#include "swaybar/config.h"
10#include "swaybar/image.h"
10#include "swaybar/input.h" 11#include "swaybar/input.h"
11#include "swaybar/tray/host.h" 12#include "swaybar/tray/host.h"
12#include "swaybar/tray/icon.h" 13#include "swaybar/tray/icon.h"
13#include "swaybar/tray/item.h" 14#include "swaybar/tray/item.h"
14#include "swaybar/tray/tray.h" 15#include "swaybar/tray/tray.h"
15#include "background-image.h" 16#include "cairo_util.h"
16#include "cairo.h"
17#include "list.h" 17#include "list.h"
18#include "log.h" 18#include "log.h"
19#include "wlr-layer-shell-unstable-v1-client-protocol.h" 19#include "wlr-layer-shell-unstable-v1-client-protocol.h"
@@ -118,8 +118,13 @@ static int get_property_callback(sd_bus_message *msg, void *data,
118 118
119 int ret; 119 int ret;
120 if (sd_bus_message_is_method_error(msg, NULL)) { 120 if (sd_bus_message_is_method_error(msg, NULL)) {
121 sway_log(SWAY_ERROR, "%s %s: %s", sni->watcher_id, prop, 121 const sd_bus_error *err = sd_bus_message_get_error(msg);
122 sd_bus_message_get_error(msg)->message); 122 sway_log_importance_t log_lv = SWAY_ERROR;
123 if ((!strcmp(prop, "IconThemePath")) &&
124 (!strcmp(err->name, SD_BUS_ERROR_UNKNOWN_PROPERTY))) {
125 log_lv = SWAY_DEBUG;
126 }
127 sway_log(log_lv, "%s %s: %s", sni->watcher_id, prop, err->message);
123 ret = sd_bus_message_get_errno(msg); 128 ret = sd_bus_message_get_errno(msg);
124 goto cleanup; 129 goto cleanup;
125 } 130 }
@@ -380,13 +385,18 @@ static int cmp_sni_id(const void *item, const void *cmp_to) {
380 385
381static enum hotspot_event_handling icon_hotspot_callback( 386static enum hotspot_event_handling icon_hotspot_callback(
382 struct swaybar_output *output, struct swaybar_hotspot *hotspot, 387 struct swaybar_output *output, struct swaybar_hotspot *hotspot,
383 double x, double y, uint32_t button, void *data) { 388 double x, double y, uint32_t button, bool released, void *data) {
384 sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data); 389 sway_log(SWAY_DEBUG, "Clicked on %s", (char *)data);
385 390
386 struct swaybar_tray *tray = output->bar->tray; 391 struct swaybar_tray *tray = output->bar->tray;
387 int idx = list_seq_find(tray->items, cmp_sni_id, data); 392 int idx = list_seq_find(tray->items, cmp_sni_id, data);
388 393
389 if (idx != -1) { 394 if (idx != -1) {
395 if (released) {
396 // Since we handle the pressed event, also handle the released event
397 // to block it from falling through to a binding in the bar
398 return HOTSPOT_IGNORE;
399 }
390 struct swaybar_sni *sni = tray->items->items[idx]; 400 struct swaybar_sni *sni = tray->items->items[idx];
391 // guess global position since wayland doesn't expose it 401 // guess global position since wayland doesn't expose it
392 struct swaybar_config *config = tray->bar->config; 402 struct swaybar_config *config = tray->bar->config;
@@ -421,7 +431,7 @@ static void reload_sni(struct swaybar_sni *sni, char *icon_theme,
421 list_free(icon_search_paths); 431 list_free(icon_search_paths);
422 if (icon_path) { 432 if (icon_path) {
423 cairo_surface_destroy(sni->icon); 433 cairo_surface_destroy(sni->icon);
424 sni->icon = load_background_image(icon_path); 434 sni->icon = load_image(icon_path);
425 free(icon_path); 435 free(icon_path);
426 return; 436 return;
427 } 437 }
@@ -461,6 +471,11 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
461 sni->target_size = target_size; 471 sni->target_size = target_size;
462 } 472 }
463 473
474 // Passive
475 if (sni->status && sni->status[0] == 'P') {
476 return 0;
477 }
478
464 int icon_size; 479 int icon_size;
465 cairo_surface_t *icon; 480 cairo_surface_t *icon;
466 if (sni->icon) { 481 if (sni->icon) {
@@ -488,24 +503,36 @@ uint32_t render_sni(cairo_t *cairo, struct swaybar_output *output, double *x,
488 cairo_destroy(cairo_icon); 503 cairo_destroy(cairo_icon);
489 } 504 }
490 505
491 int padded_size = icon_size + 2*padding; 506 double descaled_padding = (double)padding / output->scale;
492 *x -= padded_size; 507 double descaled_icon_size = (double)icon_size / output->scale;
493 int y = floor((height - padded_size) / 2.0); 508
509 int size = descaled_icon_size + 2 * descaled_padding;
510 *x -= size;
511 int icon_y = floor((output->height - size) / 2.0);
494 512
495 cairo_operator_t op = cairo_get_operator(cairo); 513 cairo_operator_t op = cairo_get_operator(cairo);
496 cairo_set_operator(cairo, CAIRO_OPERATOR_OVER); 514 cairo_set_operator(cairo, CAIRO_OPERATOR_OVER);
497 cairo_set_source_surface(cairo, icon, *x + padding, y + padding); 515
498 cairo_rectangle(cairo, *x, y, padded_size, padded_size); 516 cairo_matrix_t scale_matrix;
517 cairo_pattern_t *icon_pattern = cairo_pattern_create_for_surface(icon);
518 // TODO: check cairo_pattern_status for "ENOMEM"
519 cairo_matrix_init_scale(&scale_matrix, output->scale, output->scale);
520 cairo_matrix_translate(&scale_matrix, -(*x + descaled_padding), -(icon_y + descaled_padding));
521 cairo_pattern_set_matrix(icon_pattern, &scale_matrix);
522 cairo_set_source(cairo, icon_pattern);
523 cairo_rectangle(cairo, *x, icon_y, size, size);
499 cairo_fill(cairo); 524 cairo_fill(cairo);
525
500 cairo_set_operator(cairo, op); 526 cairo_set_operator(cairo, op);
501 527
528 cairo_pattern_destroy(icon_pattern);
502 cairo_surface_destroy(icon); 529 cairo_surface_destroy(icon);
503 530
504 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot)); 531 struct swaybar_hotspot *hotspot = calloc(1, sizeof(struct swaybar_hotspot));
505 hotspot->x = *x; 532 hotspot->x = *x;
506 hotspot->y = 0; 533 hotspot->y = 0;
507 hotspot->width = height; 534 hotspot->width = size;
508 hotspot->height = height; 535 hotspot->height = output->height;
509 hotspot->callback = icon_hotspot_callback; 536 hotspot->callback = icon_hotspot_callback;
510 hotspot->destroy = free; 537 hotspot->destroy = free;
511 hotspot->data = strdup(sni->watcher_id); 538 hotspot->data = strdup(sni->watcher_id);