diff --git a/data/launcher.desktop.in b/data/launcher.desktop.in index fc5df469..6d46ed6b 100644 --- a/data/launcher.desktop.in +++ b/data/launcher.desktop.in @@ -1,7 +1,7 @@ [Desktop Entry] Name=Dippi GenericName=Display information calculator -Comment=Calculate display info like DPI and aspect ratio +Comment=Calculate display info like DPI Categories=Calculator;Utility; Exec=com.github.cassidyjames.dippi Icon=com.github.cassidyjames.dippi diff --git a/data/metainfo.appdata.xml.in b/data/metainfo.appdata.xml.in index 4c169120..5ab3d99f 100644 --- a/data/metainfo.appdata.xml.in +++ b/data/metainfo.appdata.xml.in @@ -83,6 +83,18 @@ + + +

Lies! Deception!

+
    +
  • Better handle several common resolutions/aspect ratios
  • +
+
+ + Common aspect ratios are dumb + Unexpected ratio for 3440×1440 + +

Lighten up!

diff --git a/meson.build b/meson.build index e2e7240f..6b223222 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'com.github.cassidyjames.dippi', 'vala', 'c', - version: '4.1.0', + version: '4.1.1', meson_version: '>=1.3.2', ) diff --git a/src/App.vala b/src/App.vala index a978156e..97c20249 100644 --- a/src/App.vala +++ b/src/App.vala @@ -1,6 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2018–2023 Cassidy James Blaede + * SPDX-FileCopyrightText: 2018–2024 Cassidy James Blaede */ public class Dippi.App : Adw.Application { diff --git a/src/Config.vala.in b/src/Config.vala.in index 2ae91e29..5326cd56 100644 --- a/src/Config.vala.in +++ b/src/Config.vala.in @@ -1,2 +1,7 @@ +/* + * SPDX-License-Identifier: GPL-3.0-or-later + * SPDX-FileCopyrightText: 2018–2024 Cassidy James Blaede + */ + public const string APP_ID = @APP_ID@; public const string VERSION = @VERSION@; diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 2b837c3b..5fda1741 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -1,6 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2018–2023 Cassidy James Blaede + * SPDX-FileCopyrightText: 2018–2024 Cassidy James Blaede */ public class Dippi.MainWindow : Adw.ApplicationWindow { @@ -16,10 +16,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { private const int EXTERNAL_UNCLEAR_RANGE = 20; private const double INCHES_INFER_EXTERNAL = 18; - private const int DPI_INFER_HIDPI = 192; // According to GNOME - - private int aspect_width = DEFAULT_ASPECT_WIDTH; - private int aspect_height = DEFAULT_ASPECT_HEIGHT; + private const int DPI_INFER_HIDPI = 192; // According to GNOME and elementary private double inches = 0.0; private int width = 0; @@ -38,7 +35,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { private Gtk.Stack range_stack; private Utils.DisplayType display_type; - public MainWindow (Gtk.Application application) { + public MainWindow (Adw.Application application) { Object ( application: application, resizable: false @@ -98,6 +95,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { pixel_size = 128 }; + ///TRANSLATORS: Label for the entry for the diagonal size of the display, e.g. 27-inches var diag_label = new Gtk.Label (_("Diagonal size:")) { halign = Gtk.Align.END }; @@ -110,6 +108,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { var diag_entry_focus_controller = new Gtk.EventControllerFocus (); diag_entry.add_controller (diag_entry_focus_controller); + ///TRANSLATORS: Label for the entry for the pixel resolution of the display, e.g. 1920×1080 var res_label = new Gtk.Label (_("Resolution:")) { halign = Gtk.Align.END }; @@ -130,13 +129,14 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { var height_entry_focus_controller = new Gtk.EventControllerFocus (); height_entry.add_controller (height_entry_focus_controller); - var x_label = new Gtk.Label (_("×")); - var px_label = new Gtk.Label (_("px")); + var x_label = new Gtk.Label ("×"); + var px_label = new Gtk.Label ("px"); var inches_label = new Gtk.Label (_("inches")) { halign = Gtk.Align.START }; + ///TRANSLATORS: Used to label the selection for type of display (e.g. laptop or desktop) var type_label = new Gtk.Label (_("Type:")) { halign = Gtk.Align.END }; @@ -192,6 +192,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { link_button = new Gtk.LinkButton.with_label ( "https://cassidyjames.com/dippi/", + ///TRANSLATORS: label for the button to open a web page to share the results of the calculation _("Share results…") ) { halign = Gtk.Align.END, @@ -429,9 +430,7 @@ public class Dippi.MainWindow : Adw.ApplicationWindow { private void recalculate_aspect (int width, int height) { if (width > 0 && height > 0) { - aspect_width = width / Utils.greatest_common_divisor (width, height); - aspect_height = height / Utils.greatest_common_divisor (width, height); - aspect_result_label.label = (aspect_width).to_string () + _(":") + (aspect_height).to_string (); + aspect_result_label.label = Utils.common_ratio (width, height); } else { aspect_result_label.label = ""; } diff --git a/src/Utils.vala b/src/Utils.vala index 3c567005..74a5751b 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -1,6 +1,6 @@ /* * SPDX-License-Identifier: GPL-3.0-or-later - * SPDX-FileCopyrightText: 2018–2022 Cassidy James Blaede + * SPDX-FileCopyrightText: 2018–2024 Cassidy James Blaede */ namespace Dippi.Utils { @@ -11,9 +11,11 @@ namespace Dippi.Utils { public string to_string () { switch (this) { case INTERNAL: + ///TRANSLATORS: label for the button to select an internal/laptop display return _("Laptop"); case EXTERNAL: + ///TRANSLATORS: label for the button to select an external/desktop monitor return _("Desktop"); default: @@ -60,4 +62,94 @@ namespace Dippi.Utils { return greatest_common_divisor (a, b % a); } } + + public string common_ratio (int width, int height) { + // We don't need every possible resolution/aspect ratio handled here, but + // https://en.wikipedia.org/wiki/List_of_computer_display_standards + // is a decent place to check. For now, this is just case-by-case for + // common resolutions and aspect ratios we've seen in the wild. + // + // We can also use this to catch "backwards" ratios, e.g. portrait + // displays (like on a smartphone). + // + // In general, put the true (or approximately true) ratio first, then put + // any other aspect ratio (like one used in marketing) in parenthesis. + + int aspect_width = width / greatest_common_divisor (width, height); + int aspect_height = height / greatest_common_divisor (width, height); + + string aspect_string = "%i:%i".printf (aspect_width, aspect_height); + + switch (aspect_string) { + case "1:2": + case "2:1": + return "2:1 (18:9)"; + + case "2:3": + return "3:2"; + + case "3:4": + return "4:3"; + + // The funkiest + case "64:45": + case "45:64": + return "2:√2"; + + case "5:8": + case "8:5": + return "8:5 (16:10)"; + + // Some smartphones + case "18:37": + case "37:18": + return "37:18 (18.5:9)"; + + // Pretty much just iPhone absurdity + case "422:195": + case "195:422": + case "466:215": + case "215:466": + case "284:131": + case "131:284": + case "463:214": + case "214:463": + case "448:207": + case "207:448": + case "812:375": + case "375:812": + case "6:13": + case "13:6": + return "13:6 (19.5:9)"; + + case "84:187": + case "187:84": + case "101:45": + case "45:101": + return "20:9"; + + case "3:7": + case "7:3": + // e.g. 3440×1440 + case "43:18": + return "7:3 (21:9)"; + + // 1360×768 + case "48:85": + case "85:48": + // 1366×768 + case "384:683": + case "683:384": + // iPhone 6–8 + case "667:375": + case "375:667": + // iPhone 5 + case "71:40": + case "40:71": + return "16:9"; + + default: + return aspect_string; + } + } }