Skip to content

Linux + iPhone Continuity / iMessage / SMS

feat(gtk): dynamic font scaling

Zack Bartel728c03c9263d
diff --git a/README.md b/README.md
index d4f9062..85dfa8c 100644
--- a/README.md
+++ b/README.md
@@ -476,6 +476,7 @@ Keyboard shortcuts in the desktop app:
| Ctrl+N | New message |
| Ctrl+F | Search conversations |
| Ctrl+, | Settings |
+| Ctrl++ / Ctrl+- / Ctrl+0 | Larger text, smaller text, reset |
| Escape | Close Settings, leave search |
| Ctrl+W | Close window |
| Ctrl+Q | Quit |
diff --git a/src/gtk/main.cpp b/src/gtk/main.cpp
index 6c271b7..3898622 100644
--- a/src/gtk/main.cpp
+++ b/src/gtk/main.cpp
@@ -10,6 +10,8 @@
#include "tray.hpp"
#include "ui_util.hpp"
+#include <algorithm>
+#include <cmath>
#include <csignal>
#include <filesystem>
#include <glib-unix.h>
@@ -167,11 +169,36 @@ namespace {
gtk_stack_set_visible_child_name(GTK_STACK(g_stack), name);
}
+ // Text zoom scales gtk-xft-dpi, which every pt/em/% font size
+ void apply_text_zoom(double zoom) {
+ zoom = std::clamp(std::round(zoom * 10) / 10, 0.5, 2.0);
+ prefs()["text_zoom"] = zoom;
+
+ static bool overridden = false;
+ GtkSettings* settings = gtk_settings_get_default();
+ if (!settings || (zoom == 1.0 && !overridden))
+ return;
+ overridden = true;
+ gtk_settings_reset_property(settings, "gtk-xft-dpi");
+ int dpi = 0;
+ g_object_get(settings, "gtk-xft-dpi", &dpi, nullptr);
+ if (dpi <= 0)
+ dpi = 96 * 1024;
+ g_object_set(settings, "gtk-xft-dpi", static_cast<int>(dpi * zoom), nullptr);
+ }
+
+ void step_text_zoom(double delta) {
+ apply_text_zoom(prefs().value("text_zoom", 1.0) + delta);
+ prefs_save();
+ }
+
void install_actions(GtkApplication* app, GtkWidget* window) {
struct Accel {
const char* name;
const char* key;
void (*run)();
+ const char* alt_key = nullptr;
+ const char* alt_key2 = nullptr;
};
static const Accel accels[] = {
{"new-message",
@@ -205,6 +232,15 @@ namespace {
if (GtkWidget* w = main_window())
gtk_window_close(GTK_WINDOW(w));
}},
+ {"zoom-in", "<Control>plus", [] { step_text_zoom(0.1); }, "<Control>equal", "<Control>KP_Add"},
+ {"zoom-out", "<Control>minus", [] { step_text_zoom(-0.1); }, "<Control>KP_Subtract"},
+ {"zoom-reset",
+ "<Control>0",
+ [] {
+ apply_text_zoom(1.0);
+ prefs_save();
+ },
+ "<Control>KP_0"},
};
for (const Accel& accel : accels) {
@@ -218,7 +254,7 @@ namespace {
g_object_unref(action);
const std::string detailed = std::string("win.") + accel.name;
- const char* keys[] = {accel.key, nullptr};
+ const char* keys[] = {accel.key, accel.alt_key, accel.alt_key2, nullptr};
gtk_application_set_accels_for_action(app, detailed.c_str(), keys);
}
}
@@ -232,6 +268,7 @@ namespace {
tether::Crypto::instance().init();
install_style();
follow_system_color_scheme();
+ apply_text_zoom(prefs().value("text_zoom", 1.0));
GtkWidget* window = gtk_application_window_new(app);
gtk_window_set_title(GTK_WINDOW(window), _("Tether"));
diff --git a/src/gtk/ui_util.cpp b/src/gtk/ui_util.cpp
index 5adb3e4..f8d3639 100644
--- a/src/gtk/ui_util.cpp
+++ b/src/gtk/ui_util.cpp
@@ -40,8 +40,8 @@ namespace tether::ui {
.tether-nav-item:checked { background-color: alpha(@theme_selected_bg_color, 0.20); color: @theme_fg_color; font-weight: bold; }
.tether-app headerbar { min-height: 42px; box-shadow: none; border-bottom: 1px solid alpha(@theme_fg_color, 0.08); }
.tether-page-header { padding: 22px 24px; border-bottom: 1px solid alpha(@theme_fg_color, 0.08); }
-.tether-page-title { font-size: 22px; font-weight: bold; }
-.tether-hero-title { font-size: 23px; font-weight: bold; }
+.tether-page-title { font-size: 16.5pt; font-weight: bold; }
+.tether-hero-title { font-size: 17.25pt; font-weight: bold; }
.tether-hero-icon { color: @theme_selected_bg_color; background-color: alpha(@theme_selected_bg_color, 0.10); border-radius: 20px; padding: 18px; }
.tether-card { background-color: mix(@theme_bg_color, @theme_fg_color, 0.045); border: 1px solid alpha(@theme_fg_color, 0.09); border-radius: 16px; padding: 22px; }
.tether-detail { margin: 24px; }
@@ -50,7 +50,7 @@ namespace tether::ui {
.tether-app .tether-list row { padding: 0; margin: 3px 0; border-radius: 12px; border: 1px solid transparent; }
.tether-app .tether-list row:hover { background-color: alpha(@theme_fg_color, 0.055); }
.tether-app .tether-list row:selected { background-color: alpha(@theme_selected_bg_color, 0.14); border-color: alpha(@theme_selected_bg_color, 0.28); color: @theme_fg_color; }
-.tether-avatar { min-width: 36px; min-height: 36px; border-radius: 24px; background-color: alpha(@theme_selected_bg_color, 0.15); color: @theme_fg_color; font-size: 16px; font-weight: bold; }
+.tether-avatar { min-width: 36px; min-height: 36px; border-radius: 24px; background-color: alpha(@theme_selected_bg_color, 0.15); color: @theme_fg_color; font-size: 12pt; font-weight: bold; }
.tether-app .tether-feed { padding: 12px 24px 24px; }
.tether-app .tether-feed row { background-color: mix(@theme_bg_color, @theme_fg_color, 0.035); border: 1px solid alpha(@theme_fg_color, 0.09); border-radius: 14px; margin: 0 0 10px; padding: 8px; }
.tether-app entry { border-radius: 10px; min-height: 34px; box-shadow: none; }
@@ -147,7 +147,7 @@ namespace tether::ui {
box-shadow: 0 4px 16px alpha(black, 0.3), 0 0 0 1px alpha(@theme_fg_color, 0.12);
}
.tether-picker { padding: 20px 24px; }
-.tether-picker-title { font-size: 17px; font-weight: bold; }
+.tether-picker-title { font-size: 12.75pt; font-weight: bold; }
.tether-picker-tile {
min-width: 128px;
min-height: 128px;