diff options
author | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-03-16 12:37:45 +0100 |
---|---|---|
committer | Mike Gabriel <mike.gabriel@das-netzwerkteam.de> | 2018-03-16 12:41:32 +0100 |
commit | 7ddfa06d6248ca18e33781ec8ba20163fc4c2ad5 (patch) | |
tree | e4821a58b641fb5471ba2e3279d94cb0b54a9a72 | |
parent | 48db8cad986b0af83edb90c9fa00f58fc45b5900 (diff) | |
download | arctica-greeter-7ddfa06d6248ca18e33781ec8ba20163fc4c2ad5.tar.gz arctica-greeter-7ddfa06d6248ca18e33781ec8ba20163fc4c2ad5.tar.bz2 arctica-greeter-7ddfa06d6248ca18e33781ec8ba20163fc4c2ad5.zip |
Port HiDPI support from slick-greeter.
Inspired by these slick-greeter commits:
commit ffd43c4d425e70bc003b490dcddb8fbae1fffea7
Author: Clement Lefebvre <clement.lefebvre@linuxmint.com>
Date: Sat Apr 8 14:13:23 2017 +0100
HiDPI: Allow to force HiDPI support ON or OFF
commit 809f1b30a321ae12fdd3ba154791f9ead291acc7
Author: Clement Lefebvre <clement.lefebvre@linuxmint.com>
Date: Fri Apr 7 23:04:50 2017 +0100
HiDPI: Take the screen size in consideration
HiDPI shouldn't be activated on large screens where the dpi is OK.
commit 851fca4e5508471d6f388edcd0327c3fc5b2b12f
Author: Clement Lefebvre <clement.lefebvre@linuxmint.com>
Date: Fri Apr 7 18:43:42 2017 +0100
Add HiDPI support
Only support 1x and 2x scale ratios for now.
Also add a setting so the user can disable HiDPI support.
-rw-r--r-- | Makefile.am | 1 | ||||
-rwxr-xr-x | arctica-greeter-check-hidpi | 67 | ||||
-rw-r--r-- | data/org.ArcticaProject.arctica-greeter.gschema.xml | 9 | ||||
-rw-r--r-- | debian/arctica-greeter.install | 1 | ||||
-rw-r--r-- | src/arctica-greeter.vala | 31 | ||||
-rw-r--r-- | src/settings.vala | 1 |
6 files changed, 107 insertions, 3 deletions
diff --git a/Makefile.am b/Makefile.am index 7ba4009..730cceb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ sbin_SCRIPTS = arctica-greeter-guest-account-script pkglibexec_SCRIPTS = lightdm-arctica-greeter-session \ arctica-greeter-guest-session-auto.sh \ arctica-greeter-guest-session-setup.sh \ + arctica-greeter-check-hidpi \ arctica-greeter-set-keyboard-layout EXTRA_DIST = \ diff --git a/arctica-greeter-check-hidpi b/arctica-greeter-check-hidpi new file mode 100755 index 0000000..68f0baf --- /dev/null +++ b/arctica-greeter-check-hidpi @@ -0,0 +1,67 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- + +# Copyright (C) 2017 Clement Lefebvre <clement.lefebvre@linuxmint.com> +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 3 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +# Authors: Clement Lefebvre <clement.lefebvre@linuxmint.com> + +import gi +gi.require_version('Gdk', '3.0') +from gi.repository import Gdk +import sys +import os + +HIDPI_LIMIT = 192 + +def get_window_scale(): + window_scale = 1 + try: + display = Gdk.Display.get_default() + screen = display.get_default_screen() + primary = screen.get_primary_monitor() + + rect = screen.get_monitor_geometry(primary) + width_mm = screen.get_monitor_width_mm(primary) + height_mm = screen.get_monitor_height_mm(primary) + monitor_scale = screen.get_monitor_scale_factor(primary) + + # Return 1 if the screen size isn't available (some TVs report their aspect ratio instead ... 16/9 or 16/10) + if ((width_mm == 160 and height_mm == 90) \ + or (width_mm == 160 and height_mm == 100) \ + or (width_mm == 16 and height_mm == 9) \ + or (width_mm == 16 and height_mm == 10)): + return 1 + + if rect.height < 1500: + return 1 + + if width_mm > 0 and height_mm > 0: + witdh_inch = width_mm / 25.4 + height_inch = height_mm / 25.4 + dpi_x = rect.width * monitor_scale / witdh_inch + dpi_y = rect.height * monitor_scale / height_inch + if dpi_x > HIDPI_LIMIT and dpi_y > HIDPI_LIMIT: + window_scale = 2 + + except Exception as detail: + syslog.syslog("Error while detecting hidpi mode: %s" % detail) + + return window_scale + +if __name__ == '__main__': + window_scale = get_window_scale(); + print ("{script}: Window scale is {value}".format(script=os.path.basename(sys.argv[0]), value=window_scale), file=sys.stderr) + print (window_scale, file=sys.stdout) + sys.exit(0) diff --git a/data/org.ArcticaProject.arctica-greeter.gschema.xml b/data/org.ArcticaProject.arctica-greeter.gschema.xml index 7e8adc8..95ab139 100644 --- a/data/org.ArcticaProject.arctica-greeter.gschema.xml +++ b/data/org.ArcticaProject.arctica-greeter.gschema.xml @@ -106,6 +106,15 @@ <default>300</default> <summary>Number of seconds of inactivity before blanking the screen. Set to 0 to never timeout.</summary> </key> + <key name="enable-hidpi" type="s"> + <choices> + <choice value='on'/> + <choice value='off'/> + <choice value='auto'/> + </choices> + <default>'auto'</default> + <summary>Whether to enable HiDPI support</summary> + </key> <key name="remote-service-fqdn" type="s"> <default>'service.arctica-project.org'</default> <summary>Default FQDN for host offering Remote Logon Service</summary> diff --git a/debian/arctica-greeter.install b/debian/arctica-greeter.install index a6be53b..6a5bb10 100644 --- a/debian/arctica-greeter.install +++ b/debian/arctica-greeter.install @@ -10,5 +10,6 @@ usr/share/man/ usr/share/sounds/ usr/share/xgreeters/ usr/lib/*/arctica-greeter/lightdm-arctica-greeter-session +usr/lib/*/arctica-greeter/arctica-greeter-check-hidpi usr/lib/*/arctica-greeter/arctica-greeter-set-keyboard-layout var/lib/polkit-1/localauthority/10-vendor.d/arctica-greeter.pkla diff --git a/src/arctica-greeter.vala b/src/arctica-greeter.vala index adeb480..74be36a 100644 --- a/src/arctica-greeter.vala +++ b/src/arctica-greeter.vala @@ -606,6 +606,22 @@ public class ArcticaGreeter } } + private static void check_hidpi () + { + try { + string output; + Process.spawn_command_line_sync(Path.build_filename (Config.PKGLIBEXECDIR, "arctica-greeter-check-hidpi"), out output, null, null); + output = output.strip(); + if (output == "2") { + debug ("Activating HiDPI (2x scale ratio)"); + GLib.Environment.set_variable ("GDK_SCALE", "2", true); + } + } + catch (Error e){ + warning ("Error while setting HiDPI support: %s", e.message); + } + } + public static int main (string[] args) { /* Protect memory from being paged to disk, as we deal with passwords */ @@ -629,6 +645,18 @@ public class ArcticaGreeter */ GLib.Environment.set_variable ("GDK_CORE_DEVICE_EVENTS", "1", true); + log_timer = new Timer (); + Log.set_default_handler (log_cb); + + var hidpi = AGSettings.get_string (AGSettings.KEY_ENABLE_HIDPI); + debug ("HiDPI support: %s", hidpi); + if (hidpi == "auto") { + check_hidpi (); + } + else if (hidpi == "on") { + GLib.Environment.set_variable ("GDK_SCALE", "2", true); + } + bool do_show_version = false; bool do_test_mode = false; OptionEntry versionOption = { "version", 'v', 0, OptionArg.NONE, ref do_show_version, @@ -710,9 +738,6 @@ public class ArcticaGreeter Gtk.init (ref args); Ido.init (); - log_timer = new Timer (); - Log.set_default_handler (log_cb); - debug ("Starting arctica-greeter %s UID=%d LANG=%s", Config.VERSION, (int) Posix.getuid (), Environment.get_variable ("LANG")); /* Set the cursor to not be the crap default */ diff --git a/src/settings.vala b/src/settings.vala index e55b0c2..441035b 100644 --- a/src/settings.vala +++ b/src/settings.vala @@ -47,6 +47,7 @@ public class AGSettings public const string KEY_REMOTE_SERVICE_FQDN = "remote-service-fqdn"; public const string KEY_TOGGLEBOX_FONT_FGCOLOR = "togglebox-font-fgcolor"; public const string KEY_TOGGLEBOX_BUTTON_BGCOLOR = "togglebox-button-bgcolor"; + public const string KEY_ENABLE_HIDPI = "enable-hidpi"; public static bool get_boolean (string key) { |