From 0e8634a227f12f36bfbda39f9f5718534f1147b3 Mon Sep 17 00:00:00 2001 From: scorpion-26 Date: Sun, 3 Dec 2023 22:48:31 +0100 Subject: [PATCH] Implement ability to disable certain SNI icons Implements https://github.com/scorpion-26/gBar/issues/69 (nice) --- data/config | 4 ++++ src/Config.cpp | 1 + src/Config.h | 1 + src/SNI.cpp | 14 ++++++++++++++ 4 files changed, 20 insertions(+) diff --git a/data/config b/data/config index 7c4b959..df3e4d2 100644 --- a/data/config +++ b/data/config @@ -165,7 +165,9 @@ EnableSNI: true # SNIIconSize sets the icon size for a SNI icon. # SNIPaddingTop Can be used to push the Icon down. Negative values are allowed # SNIIconName overrides what icon from an icon theme to display. +# SNIDisabled prevents an icon from being registered. # For all SNI properties: The first parameter is a filter of the tooltip(The text that pops up, when the icon is hovered) of the icon. +# The wildcard filter '*' does not work for SNIIconName and SNIDisabled # Scale everything down to 25 pixels ('*' as filter means everything) #SNIIconSize: *, 25 @@ -175,6 +177,8 @@ EnableSNI: true #SNIPaddingTop: Discord, 5 # Override the default icon given to gBar by discord to an icon theme supplied one (Example is from papirus theme) #SNIIconName: Discord, discord-tray +# Prevents steam from displaying. Note: Steam doesn't have a tooltip, which means the object path is filtered instead. +#SNIDisabled: steam, true # These set the range for the network widget. The widget changes colors at six intervals: # - Below Min...Bytes ("under") diff --git a/src/Config.cpp b/src/Config.cpp index 33001c0..d448e31 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -299,6 +299,7 @@ void Config::Load() AddConfigVar("SNIIconSize", config.sniIconSizes, lineView, foundProperty); AddConfigVar("SNIPaddingTop", config.sniPaddingTop, lineView, foundProperty); AddConfigVar("SNIIconName", config.sniIconNames, lineView, foundProperty); + AddConfigVar("SNIDisabled", config.sniDisabled, lineView, foundProperty); // Modern map syntax AddConfigVar("WorkspaceSymbol", config.workspaceSymbols, lineView, foundProperty); // Legacy syntax diff --git a/src/Config.h b/src/Config.h index 95aa92b..06d7240 100644 --- a/src/Config.h +++ b/src/Config.h @@ -85,6 +85,7 @@ public: std::unordered_map sniIconSizes; std::unordered_map sniPaddingTop; std::unordered_map sniIconNames; + std::unordered_map sniDisabled; // Only affects outputs (i.e.: speakers, not microphones). This remaps the range of the volume; In percent double audioMinVolume = 0.f; // Map the minimum volume to this value diff --git a/src/SNI.cpp b/src/SNI.cpp index 8725aa1..1525177 100644 --- a/src/SNI.cpp +++ b/src/SNI.cpp @@ -166,8 +166,22 @@ namespace SNI } bool wasExplicitOverride = false; + for (auto& [filter, disabled] : Config::Get().sniDisabled) + { + if (ItemMatchesFilter(item, filter, wasExplicitOverride)) + { + if (disabled) + { + LOG("SNI: Disabling item due to config"); + // We're done here. + return item; + } + } + } + // First try icon theme querying std::string iconName; + wasExplicitOverride = false; for (auto& [filter, name] : Config::Get().sniIconNames) { if (ItemMatchesFilter(item, filter, wasExplicitOverride))