From 5820299278eee0db4a77c5eeba4eb7308a7ca666 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Sat, 3 Oct 2020 15:59:39 -0500 Subject: [PATCH] swaybar: add SNI Title, Category, Id support --- include/swaybar/tray/item.h | 3 +++ swaybar/tray/item.c | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/include/swaybar/tray/item.h b/include/swaybar/tray/item.h index a7a7ab2a..df4f9a87 100644 --- a/include/swaybar/tray/item.h +++ b/include/swaybar/tray/item.h @@ -52,6 +52,9 @@ struct swaybar_sni { bool item_is_menu; char *menu; struct swaybar_sni_tool_tip *tool_tip; + char *title; + char *category; + char *id; char *icon_theme_path; // non-standard KDE property struct wl_list slots; // swaybar_sni_slot::link diff --git a/swaybar/tray/item.c b/swaybar/tray/item.c index 7faa14a8..a91054c4 100644 --- a/swaybar/tray/item.c +++ b/swaybar/tray/item.c @@ -306,6 +306,29 @@ static int handle_new_status(sd_bus_message *msg, void *data, sd_bus_error *erro return ret; } +static int handle_new_title(sd_bus_message *msg, void *data, sd_bus_error *error) { + // NOTE(nms): unsure if sni_check_msg_sender is valid (I assume this is to check if title property is sent with the + // NewTitle message) + struct swaybar_sni *sni = data; + int ret = sni_check_msg_sender(sni, msg, "title"); + if (ret == 1) { + char *title; + int r = sd_bus_message_read(msg, "s", &title); + if (r < 0) { + sway_log(SWAY_ERROR, "%s new title error: %s", sni->watcher_id, strerror(-ret)); + ret = r; + } else { + free(sni->title); + sni->title = strdup(title); + sway_log(SWAY_DEBUG, "%s has new title = '%s'", sni->watcher_id, title); + set_sni_dirty(sni); + } + } else { + sni_get_property_async(sni, "Title", "s", &sni->title); + } + return ret; +} + static void sni_match_signal_async(struct swaybar_sni *sni, char *signal, sd_bus_message_handler_t callback) { struct swaybar_sni_slot *slot = calloc(1, sizeof(struct swaybar_sni_slot)); @@ -340,8 +363,7 @@ struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray) { sni_get_property_async(sni, "IconThemePath", "s", &sni->icon_theme_path); } - // Ignored: Category, Id, Title, WindowId, OverlayIconName, - // OverlayIconPixmap, AttentionMovieName + // Ignored: WindowId, OverlayIconName, OverlayIconPixmap, AttentionMovieName sni_get_property_async(sni, "Status", "s", &sni->status); sni_get_property_async(sni, "IconName", "s", &sni->icon_name); sni_get_property_async(sni, "IconPixmap", NULL, &sni->icon_pixmap); @@ -349,11 +371,15 @@ struct swaybar_sni *create_sni(char *id, struct swaybar_tray *tray) { sni_get_property_async(sni, "AttentionIconPixmap", NULL, &sni->attention_icon_pixmap); sni_get_property_async(sni, "ItemIsMenu", "b", &sni->item_is_menu); sni_get_property_async(sni, "Menu", "o", &sni->menu); + sni_get_property_async(sni, "Title", "s", &sni->title); sni_get_property_async(sni, "ToolTip", NULL, &sni->tool_tip); + sni_get_property_async(sni, "Category", "s", &sni->category); + sni_get_property_async(sni, "Id", "s", &sni->id); sni_match_signal_async(sni, "NewIcon", handle_new_icon); sni_match_signal_async(sni, "NewAttentionIcon", handle_new_attention_icon); sni_match_signal_async(sni, "NewStatus", handle_new_status); + sni_match_signal_async(sni, "NewTitle", handle_new_title); //sni_match_signal_async(sni, "NewToolTip", handle_new_tool_tip); return sni; @@ -374,7 +400,10 @@ void destroy_sni(struct swaybar_sni *sni) { free(sni->attention_icon_name); list_free_items_and_destroy(sni->attention_icon_pixmap); free(sni->menu); + free(sni->title); free(sni->tool_tip); + free(sni->category); + free(sni->id); free(sni->icon_theme_path); struct swaybar_sni_slot *slot, *slot_tmp;