Debian Codegraph @

arctica-greeter-check-hidpi

raw
1 #!/usr/bin/python3
2 # -*- coding: utf-8 -*-
3
4 # Copyright (C) 2017 Clement Lefebvre <[email protected]>
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Authors: Clement Lefebvre <[email protected]>
19
20 import gi
21 gi.require_version('Gdk', '3.0')
22 from gi.repository import Gdk
23 import sys
24 import syslog
25 import os
26
27 HIDPI_LIMIT = 192
28
29 def get_window_scale():
30 window_scale = 1
31 try:
32 display = Gdk.Display.get_default()
33 if display != None:
34 monitor = display.get_primary_monitor()
35 rect = monitor.get_geometry()
36 width_mm = monitor.get_width_mm()
37 height_mm = monitor.get_height_mm()
38 monitor_scale = monitor.get_scale_factor()
39
40 # Return 1 if the screen size isn't available (some TVs report their aspect ratio instead ... 16/9 or 16/10)
41 if ((width_mm == 160 and height_mm == 90) \
42 or (width_mm == 160 and height_mm == 100) \
43 or (width_mm == 16 and height_mm == 9) \
44 or (width_mm == 16 and height_mm == 10)):
45 return 1
46
47 if rect.height * monitor_scale < 1500:
48 return 1
49
50 if width_mm > 0 and height_mm > 0:
51 width_inch = width_mm / 25.4
52 height_inch = height_mm / 25.4
53 dpi_x = rect.width * monitor_scale / width_inch
54 dpi_y = rect.height * monitor_scale / height_inch
55 if dpi_x > HIDPI_LIMIT and dpi_y > HIDPI_LIMIT:
56 window_scale = 2
57
58 except Exception as detail:
59 syslog.syslog("Error while detecting hidpi mode: %s" % detail)
60
61 return window_scale
62
63 if __name__ == '__main__':
64 window_scale = get_window_scale();
65 print ("{script}: Window scale is {value}".format(script=os.path.basename(sys.argv[0]), value=window_scale), file=sys.stderr)
66 print (window_scale, file=sys.stdout)
67 sys.exit(0)