Linux + iPhone Continuity / iMessage / SMS
feat(gtk): support symbolic icons
Zack Bartel950312ff8529
diff --git a/docs/man/man1/tether-gtk.1.in b/docs/man/man1/tether-gtk.1.inindex df5065a..362d28a 100644--- a/docs/man/man1/tether-gtk.1.in+++ b/docs/man/man1/tether-gtk.1.in@@ -35,6 +35,18 @@ is raised and switched instead of a second one being started.Open the messages tab on the conversation with this thread key, for example\fBtel:+15551234567\fR. This is what the \fBReply\fR button on a messagenotification uses.+.SH FILES+.TP+.I ~/.config/tether/gtk.json+Interface preferences.+.B close_to_tray+(boolean) keeps the application running in the tray when the window is closed.+.B tray_icon+selects the tray icon set:+.B symbolic+(default) is monochrome and recolored by the panel,+.B color+is the full-color application icon..SH SEE ALSO.BR tether (1),.BR tetherd (8)diff --git a/scripts/generate_icons.sh b/scripts/generate_icons.shindex 08f59bb..7761fd5 100755--- a/scripts/generate_icons.sh+++ b/scripts/generate_icons.sh@@ -129,12 +129,26 @@ EOFecho "Generating GTK icons..."GTK_ICON_DIR="src/gtk/icons"mkdir -p "$GTK_ICON_DIR"++# Clips to a rounded square so the icon sits with themed icons in docks and+# launchers instead of reading as a hard tile. Radius follows the GNOME HIG grid.+round_corners() {+ local file=$1 size=$2+ local radius+ radius=$(awk "BEGIN{printf \"%.0f\", $size*0.22}")+ convert "$file" \+ \( -size "${size}x${size}" xc:none \+ -draw "roundrectangle 0,0,$((size - 1)),$((size - 1)),$radius,$radius" \) \+ -alpha set -compose DstIn -composite "$file"+}+for size in 16 32 48 64 128 256 512 1024; domkdir -p "$GTK_ICON_DIR/${size}x${size}"convert "$SOURCE" -resize "${size}x${size}" "$GTK_ICON_DIR/${size}x${size}/tether.png"+ round_corners "$GTK_ICON_DIR/${size}x${size}/tether.png" "$size"# Tray icon for "nothing is connected". Colour is the only thing readable at# panel size, so the offline state is the same mark drained of it.- convert "$SOURCE" -resize "${size}x${size}" -colorspace Gray -brightness-contrast -10x-25 \+ convert "$GTK_ICON_DIR/${size}x${size}/tether.png" -modulate 100,0 -brightness-contrast -10x-25 \"$GTK_ICON_DIR/${size}x${size}/tether-offline.png"# Tray icon for unread messages. A dot, not a count: digits are illegible at# the 22px most panels render.@@ -144,6 +158,8 @@ for size in 16 32 48 64 128 256 512 1024; doconvert "$GTK_ICON_DIR/${size}x${size}/tether.png" \-fill "#e01b24" -stroke none -draw "circle $dot_x,$dot_y $dot_edge,$dot_y" \"$GTK_ICON_DIR/${size}x${size}/tether-unread.png"+ # The dot paints over the clipped corner, so clip again.+ round_corners "$GTK_ICON_DIR/${size}x${size}/tether-unread.png" "$size"doneecho "All icons generated successfully."diff --git a/src/gtk/CMakeLists.txt b/src/gtk/CMakeLists.txtindex 03bfcaa..f81032e 100644--- a/src/gtk/CMakeLists.txt+++ b/src/gtk/CMakeLists.txt@@ -34,3 +34,8 @@ foreach(SIZE 16 32 48 64 128 256 512 1024)icons/${SIZE}x${SIZE}/tether-unread.pngDESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/${SIZE}x${SIZE}/apps)endforeach()++install(FILES icons/symbolic/tether-symbolic.svg+ icons/symbolic/tether-offline-symbolic.svg+ icons/symbolic/tether-unread-symbolic.svg+ DESTINATION ${CMAKE_INSTALL_DATADIR}/icons/hicolor/symbolic/apps)diff --git a/src/gtk/icons/1024x1024/tether-offline.png b/src/gtk/icons/1024x1024/tether-offline.pngindex d070b4a..748ebd8 100644Binary files a/src/gtk/icons/1024x1024/tether-offline.png and b/src/gtk/icons/1024x1024/tether-offline.png differdiff --git a/src/gtk/icons/1024x1024/tether-unread.png b/src/gtk/icons/1024x1024/tether-unread.pngindex 5db949b..704a9d3 100644Binary files a/src/gtk/icons/1024x1024/tether-unread.png and b/src/gtk/icons/1024x1024/tether-unread.png differdiff --git a/src/gtk/icons/1024x1024/tether.png b/src/gtk/icons/1024x1024/tether.pngindex d655d0c..4a3ee24 100644Binary files a/src/gtk/icons/1024x1024/tether.png and b/src/gtk/icons/1024x1024/tether.png differdiff --git a/src/gtk/icons/128x128/tether-offline.png b/src/gtk/icons/128x128/tether-offline.pngindex 8c792a9..bb17af3 100644Binary files a/src/gtk/icons/128x128/tether-offline.png and b/src/gtk/icons/128x128/tether-offline.png differdiff --git a/src/gtk/icons/128x128/tether-unread.png b/src/gtk/icons/128x128/tether-unread.pngindex 7b1e462..9c4f408 100644Binary files a/src/gtk/icons/128x128/tether-unread.png and b/src/gtk/icons/128x128/tether-unread.png differdiff --git a/src/gtk/icons/128x128/tether.png b/src/gtk/icons/128x128/tether.pngindex eda0fd4..a245407 100644Binary files a/src/gtk/icons/128x128/tether.png and b/src/gtk/icons/128x128/tether.png differdiff --git a/src/gtk/icons/16x16/tether-offline.png b/src/gtk/icons/16x16/tether-offline.pngindex 1f23aab..b8ce035 100644Binary files a/src/gtk/icons/16x16/tether-offline.png and b/src/gtk/icons/16x16/tether-offline.png differdiff --git a/src/gtk/icons/16x16/tether-unread.png b/src/gtk/icons/16x16/tether-unread.pngindex 6e4bcf3..2e8ed52 100644Binary files a/src/gtk/icons/16x16/tether-unread.png and b/src/gtk/icons/16x16/tether-unread.png differdiff --git a/src/gtk/icons/16x16/tether.png b/src/gtk/icons/16x16/tether.pngindex 10662ca..e88cc47 100644Binary files a/src/gtk/icons/16x16/tether.png and b/src/gtk/icons/16x16/tether.png differdiff --git a/src/gtk/icons/256x256/tether-offline.png b/src/gtk/icons/256x256/tether-offline.pngindex eaabfe9..8e0101f 100644Binary files a/src/gtk/icons/256x256/tether-offline.png and b/src/gtk/icons/256x256/tether-offline.png differdiff --git a/src/gtk/icons/256x256/tether-unread.png b/src/gtk/icons/256x256/tether-unread.pngindex 5ba4fc0..b94fa1c 100644Binary files a/src/gtk/icons/256x256/tether-unread.png and b/src/gtk/icons/256x256/tether-unread.png differdiff --git a/src/gtk/icons/256x256/tether.png b/src/gtk/icons/256x256/tether.pngindex b36b5f8..87a1db9 100644Binary files a/src/gtk/icons/256x256/tether.png and b/src/gtk/icons/256x256/tether.png differdiff --git a/src/gtk/icons/32x32/tether-offline.png b/src/gtk/icons/32x32/tether-offline.pngindex beb6ef1..167930d 100644Binary files a/src/gtk/icons/32x32/tether-offline.png and b/src/gtk/icons/32x32/tether-offline.png differdiff --git a/src/gtk/icons/32x32/tether-unread.png b/src/gtk/icons/32x32/tether-unread.pngindex e6d2801..647d6b5 100644Binary files a/src/gtk/icons/32x32/tether-unread.png and b/src/gtk/icons/32x32/tether-unread.png differdiff --git a/src/gtk/icons/32x32/tether.png b/src/gtk/icons/32x32/tether.pngindex 77d313c..57f3ce3 100644Binary files a/src/gtk/icons/32x32/tether.png and b/src/gtk/icons/32x32/tether.png differdiff --git a/src/gtk/icons/48x48/tether-offline.png b/src/gtk/icons/48x48/tether-offline.pngindex a9759c8..138ca82 100644Binary files a/src/gtk/icons/48x48/tether-offline.png and b/src/gtk/icons/48x48/tether-offline.png differdiff --git a/src/gtk/icons/48x48/tether-unread.png b/src/gtk/icons/48x48/tether-unread.pngindex f5ac3d7..6dacb30 100644Binary files a/src/gtk/icons/48x48/tether-unread.png and b/src/gtk/icons/48x48/tether-unread.png differdiff --git a/src/gtk/icons/48x48/tether.png b/src/gtk/icons/48x48/tether.pngindex 74892c5..3f1e39e 100644Binary files a/src/gtk/icons/48x48/tether.png and b/src/gtk/icons/48x48/tether.png differdiff --git a/src/gtk/icons/512x512/tether-offline.png b/src/gtk/icons/512x512/tether-offline.pngindex cd4f971..2ab27bc 100644Binary files a/src/gtk/icons/512x512/tether-offline.png and b/src/gtk/icons/512x512/tether-offline.png differdiff --git a/src/gtk/icons/512x512/tether-unread.png b/src/gtk/icons/512x512/tether-unread.pngindex 502c13b..da63a83 100644Binary files a/src/gtk/icons/512x512/tether-unread.png and b/src/gtk/icons/512x512/tether-unread.png differdiff --git a/src/gtk/icons/512x512/tether.png b/src/gtk/icons/512x512/tether.pngindex dbae178..15eef15 100644Binary files a/src/gtk/icons/512x512/tether.png and b/src/gtk/icons/512x512/tether.png differdiff --git a/src/gtk/icons/64x64/tether-offline.png b/src/gtk/icons/64x64/tether-offline.pngindex 295d3b4..aeee6ae 100644Binary files a/src/gtk/icons/64x64/tether-offline.png and b/src/gtk/icons/64x64/tether-offline.png differdiff --git a/src/gtk/icons/64x64/tether-unread.png b/src/gtk/icons/64x64/tether-unread.pngindex d368637..dac5331 100644Binary files a/src/gtk/icons/64x64/tether-unread.png and b/src/gtk/icons/64x64/tether-unread.png differdiff --git a/src/gtk/icons/64x64/tether.png b/src/gtk/icons/64x64/tether.pngindex 99f031a..c72b78a 100644Binary files a/src/gtk/icons/64x64/tether.png and b/src/gtk/icons/64x64/tether.png differdiff --git a/src/gtk/icons/symbolic/tether-offline-symbolic.svg b/src/gtk/icons/symbolic/tether-offline-symbolic.svgnew file mode 100644index 0000000..7a7b1a6--- /dev/null+++ b/src/gtk/icons/symbolic/tether-offline-symbolic.svg@@ -0,0 +1,5 @@+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">+ <path fill="#bebebe" d="M1.5 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+ <path fill="#bebebe" d="M7.7 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+ <path fill="#bebebe" d="M1.5 13.4 13.4 1.5 14.5 2.6 2.6 14.5z"/>+</svg>diff --git a/src/gtk/icons/symbolic/tether-symbolic.svg b/src/gtk/icons/symbolic/tether-symbolic.svgnew file mode 100644index 0000000..25b380e--- /dev/null+++ b/src/gtk/icons/symbolic/tether-symbolic.svg@@ -0,0 +1,4 @@+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">+ <path fill="#bebebe" d="M1.5 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+ <path fill="#bebebe" d="M7.7 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+</svg>diff --git a/src/gtk/icons/symbolic/tether-unread-symbolic.svg b/src/gtk/icons/symbolic/tether-unread-symbolic.svgnew file mode 100644index 0000000..b72c5af--- /dev/null+++ b/src/gtk/icons/symbolic/tether-unread-symbolic.svg@@ -0,0 +1,7 @@+<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16">+ <g transform="translate(0.3 2.9) scale(0.8)">+ <path fill="#bebebe" d="M1.5 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+ <path fill="#bebebe" d="M7.7 8a3.4 3.4 0 1 1 6.8 0 3.4 3.4 0 1 1-6.8 0zm1.6 0a1.8 1.8 0 1 0 3.6 0 1.8 1.8 0 1 0-3.6 0z"/>+ </g>+ <circle fill="#bebebe" cx="12.6" cy="3.4" r="2.4"/>+</svg>diff --git a/src/gtk/tray.cpp b/src/gtk/tray.cppindex d313402..1ae9aad 100644--- a/src/gtk/tray.cpp+++ b/src/gtk/tray.cpp@@ -4,6 +4,7 @@#include <filesystem>#include <fstream>#include <gio/gio.h>+#include <gtk/gtk.h>#include <nlohmann/json.hpp>#include <tether/log.hpp>#include <unistd.h>@@ -68,6 +69,8 @@ namespace tether::ui {int g_unread = 0;std::string g_tooltip;bool g_close_to_tray = false;+ std::string g_icon_style = "symbolic";+ std::string g_icon_suffix;RouteState& state(Route route) { return g_state[route == Route::WiFi ? 0 : 1]; }const char* route_name(Route route) { return route == Route::WiFi ? "Wi-Fi" : "Bluetooth"; }@@ -87,7 +90,9 @@ namespace tether::ui {std::ifstream in(path);if (!in)return;- g_close_to_tray = nlohmann::json::parse(in).value("close_to_tray", false);+ const nlohmann::json prefs = nlohmann::json::parse(in);+ g_close_to_tray = prefs.value("close_to_tray", false);+ g_icon_style = prefs.value("tray_icon", std::string("symbolic"));} catch (const std::exception& e) {// unreadable file means defaults, not a dead tray.debug::log(WARN, "tray: ignoring {} ({})", path, e.what());@@ -102,12 +107,21 @@ namespace tether::ui {std::error_code ec;std::filesystem::create_directories(std::filesystem::path(path).parent_path(), ec);std::ofstream out(path);- out << nlohmann::json{{"close_to_tray", g_close_to_tray}}.dump(2) << "\n";+ out << nlohmann::json{{"close_to_tray", g_close_to_tray}, {"tray_icon", g_icon_style}}.dump(2) << "\n";} catch (const std::exception& e) {debug::log(ERR, "tray: could not write {} ({})", path, e.what());}}+ // Symbolic icons are drawn in the panel's foreground color, so the item matches the rest of+ // the tray. Falls back to the color set when the symbolic one is not installed.+ void resolve_icon_style() {+ if (g_icon_style == "color")+ return;+ if (gtk_icon_theme_has_icon(gtk_icon_theme_get_default(), "tether-symbolic"))+ g_icon_suffix = "-symbolic";+ }+void present_window() {if (GtkWidget* window = main_window())gtk_window_present(GTK_WINDOW(window));@@ -213,6 +227,8 @@ namespace tether::ui {return;load_prefs();+ resolve_icon_style();+ g_icon += g_icon_suffix;GError* error = nullptr;g_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, &error);@@ -267,7 +283,8 @@ namespace tether::ui {tooltip.pop_back();const bool any_up = g_state[0].ok || g_state[1].ok;- const std::string icon = !any_up ? "tether-offline" : (g_unread > 0 ? "tether-unread" : "tether");+ const std::string icon =+ std::string(!any_up ? "tether-offline" : (g_unread > 0 ? "tether-unread" : "tether")) + g_icon_suffix;if (icon != g_icon) {g_icon = icon;