Merge lp:~3v1n0/unity/use-scaling-ubuntu-schemas-settings into lp:unity
- use-scaling-ubuntu-schemas-settings
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Andrea Azzarone |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4260 |
Proposed branch: | lp:~3v1n0/unity/use-scaling-ubuntu-schemas-settings |
Merge into: | lp:unity |
Diff against target: |
527 lines (+126/-159) 11 files modified
debian/control (+2/-1) debian/unity.migrations (+1/-0) tests/data/external.gschema.xml (+13/-0) tests/test_em_converter.cpp (+7/-19) tests/test_raw_pixel.cpp (+1/-2) tools/migration-scripts/02_unity_setup_text_scale_factor (+3/-7) tools/migration-scripts/04_unity_update_software_center_desktop_file (+7/-6) tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas (+66/-0) unity-shared/EMConverter.cpp (+8/-63) unity-shared/EMConverter.h (+1/-16) unity-shared/UnitySettings.cpp (+17/-45) |
To merge this branch: | bzr merge lp:~3v1n0/unity/use-scaling-ubuntu-schemas-settings |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Didier Roche-Tolomelli | Needs Fixing | ||
Andrea Azzarone (community) | Approve | ||
Review via email: mp+331667@code.launchpad.net |
Commit message
UnitySettings: use the ubuntu-schemas path for scaling settings
Also remove unused parts of EMConverter
Description of the change
Andrea Azzarone (azzar1) wrote : | # |
text-scaling is not correctly migrated doing an upgrade from Z to A using this ppa. But this improves the current behavior so +1 for me.
Didier Roche-Tolomelli (didrocks) wrote : | # |
The change looks good to me code-wise, there are 2 things on this and other merge proposals to do:
- please file a bug to explain why we are migrating those values. This is so that the release team understands the bug fix and reference it in each package impacted.
- on this one, we have a migration script for the scaling factor. However, we have another migration script to reset the scaling factor for GNOME. It means that if we run the ubuntu session before switching to the unity one, we need to ensure about the order (and having the migration script moving the key before the Ubuntu one). Another way is to move the reset from the other script to that one, after you migrated the settings. Mind doing that change?
Preview Diff
1 | === modified file 'debian/control' | |||
2 | --- debian/control 2017-09-01 09:48:41 +0000 | |||
3 | +++ debian/control 2017-10-04 18:50:31 +0000 | |||
4 | @@ -12,7 +12,7 @@ | |||
5 | 12 | dh-python, | 12 | dh-python, |
6 | 13 | google-mock (>= 1.6.0+svn437), | 13 | google-mock (>= 1.6.0+svn437), |
7 | 14 | gsettings-desktop-schemas-dev, | 14 | gsettings-desktop-schemas-dev, |
9 | 15 | gsettings-ubuntu-schemas (>= 0.0.1+14.04.20140219), | 15 | gsettings-ubuntu-schemas (>= 0.0.7+17.10.20170922), |
10 | 16 | intltool (>= 0.35.0), | 16 | intltool (>= 0.35.0), |
11 | 17 | libappstream-glib-dev, | 17 | libappstream-glib-dev, |
12 | 18 | libatk1.0-dev, | 18 | libatk1.0-dev, |
13 | @@ -73,6 +73,7 @@ | |||
14 | 73 | compiz-core, compiz-core-abiversion-${coreabiversion}, | 73 | compiz-core, compiz-core-abiversion-${coreabiversion}, |
15 | 74 | libnux-abiversion-${nuxabiversion}, | 74 | libnux-abiversion-${nuxabiversion}, |
16 | 75 | compiz-plugins-default, | 75 | compiz-plugins-default, |
17 | 76 | gsettings-ubuntu-schemas (>= 0.0.7+17.10.20170922), | ||
18 | 76 | libglib2.0-bin, | 77 | libglib2.0-bin, |
19 | 77 | nux-tools, | 78 | nux-tools, |
20 | 78 | python3-gi, | 79 | python3-gi, |
21 | 79 | 80 | ||
22 | === modified file 'debian/unity.migrations' | |||
23 | --- debian/unity.migrations 2016-02-22 20:34:21 +0000 | |||
24 | +++ debian/unity.migrations 2017-10-04 18:50:31 +0000 | |||
25 | @@ -2,3 +2,4 @@ | |||
26 | 2 | tools/migration-scripts/02_unity_setup_text_scale_factor | 2 | tools/migration-scripts/02_unity_setup_text_scale_factor |
27 | 3 | tools/migration-scripts/03_unity_first_run_stamp_move | 3 | tools/migration-scripts/03_unity_first_run_stamp_move |
28 | 4 | tools/migration-scripts/04_unity_update_software_center_desktop_file | 4 | tools/migration-scripts/04_unity_update_software_center_desktop_file |
29 | 5 | tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas | ||
30 | 5 | \ No newline at end of file | 6 | \ No newline at end of file |
31 | 6 | 7 | ||
32 | === modified file 'tests/data/external.gschema.xml' | |||
33 | --- tests/data/external.gschema.xml 2017-07-17 16:47:39 +0000 | |||
34 | +++ tests/data/external.gschema.xml 2017-10-04 18:50:31 +0000 | |||
35 | @@ -74,6 +74,19 @@ | |||
36 | 74 | </key> | 74 | </key> |
37 | 75 | </schema> | 75 | </schema> |
38 | 76 | 76 | ||
39 | 77 | <schema path="/com/ubuntu/user-interface/desktop/" id="com.ubuntu.user-interface.desktop"> | ||
40 | 78 | <key type="u" name="scaling-factor"> | ||
41 | 79 | <default>0</default> | ||
42 | 80 | </key> | ||
43 | 81 | <key type="d" name="text-scaling-factor"> | ||
44 | 82 | <range min="0.5" max="3.0"/> | ||
45 | 83 | <default>1.0</default> | ||
46 | 84 | </key> | ||
47 | 85 | <key type="i" name="cursor-size"> | ||
48 | 86 | <default>24</default> | ||
49 | 87 | </key> | ||
50 | 88 | </schema> | ||
51 | 89 | |||
52 | 77 | <schema id="com.canonical.unity-greeter" path="/com/canonical/unity-greeter/"> | 90 | <schema id="com.canonical.unity-greeter" path="/com/canonical/unity-greeter/"> |
53 | 78 | <key type="s" name="logo"> | 91 | <key type="s" name="logo"> |
54 | 79 | <default>'/usr/share/unity-greeter/logo.png'</default> | 92 | <default>'/usr/share/unity-greeter/logo.png'</default> |
55 | 80 | 93 | ||
56 | === modified file 'tests/test_em_converter.cpp' | |||
57 | --- tests/test_em_converter.cpp 2014-02-07 23:45:27 +0000 | |||
58 | +++ tests/test_em_converter.cpp 2017-10-04 18:50:31 +0000 | |||
59 | @@ -26,34 +26,19 @@ | |||
60 | 26 | { | 26 | { |
61 | 27 | 27 | ||
62 | 28 | int const PIXEL_SIZE = 24; | 28 | int const PIXEL_SIZE = 24; |
63 | 29 | int const FONT_SIZE = 13; | ||
64 | 30 | double const DPI = 96.0; | 29 | double const DPI = 96.0; |
65 | 31 | 30 | ||
66 | 32 | class TestEMConverter : public Test | 31 | class TestEMConverter : public Test |
67 | 33 | { | 32 | { |
68 | 34 | public: | 33 | public: |
69 | 35 | TestEMConverter() | 34 | TestEMConverter() |
71 | 36 | : em_converter(FONT_SIZE, DPI) | 35 | : em_converter(DPI) |
72 | 37 | { | 36 | { |
73 | 38 | } | 37 | } |
74 | 39 | 38 | ||
75 | 40 | EMConverter em_converter; | 39 | EMConverter em_converter; |
76 | 41 | }; | 40 | }; |
77 | 42 | 41 | ||
78 | 43 | TEST_F(TestEMConverter, TestCtor) | ||
79 | 44 | { | ||
80 | 45 | EXPECT_EQ(FONT_SIZE, em_converter.GetFontSize()); | ||
81 | 46 | EXPECT_EQ(DPI, em_converter.GetDPI()); | ||
82 | 47 | } | ||
83 | 48 | |||
84 | 49 | TEST_F(TestEMConverter, TestSetFontSize) | ||
85 | 50 | { | ||
86 | 51 | int const font_size = 15; | ||
87 | 52 | |||
88 | 53 | em_converter.SetFontSize(font_size); | ||
89 | 54 | EXPECT_EQ(font_size, em_converter.GetFontSize()); | ||
90 | 55 | } | ||
91 | 56 | |||
92 | 57 | TEST_F(TestEMConverter, TestSetDPI) | 42 | TEST_F(TestEMConverter, TestSetDPI) |
93 | 58 | { | 43 | { |
94 | 59 | int const dpi = 120.0; | 44 | int const dpi = 120.0; |
95 | @@ -79,10 +64,13 @@ | |||
96 | 79 | EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0); | 64 | EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0); |
97 | 80 | } | 65 | } |
98 | 81 | 66 | ||
100 | 82 | TEST_F(TestEMConverter, TestPtToPx) | 67 | TEST_F(TestEMConverter, TestConvertPixelScaled) |
101 | 83 | { | 68 | { |
104 | 84 | int pt = 12; | 69 | for (double scale : std::vector<double>({1.0, 1.25, 1.5, 1.75, 2})) |
105 | 85 | EXPECT_EQ(em_converter.PtToPx(pt), 16); | 70 | { |
106 | 71 | em_converter.SetDPI(DPI * scale); | ||
107 | 72 | EXPECT_EQ(std::round(PIXEL_SIZE * scale), em_converter.CP(PIXEL_SIZE)); | ||
108 | 73 | } | ||
109 | 86 | } | 74 | } |
110 | 87 | 75 | ||
111 | 88 | } // namespace unity | 76 | } // namespace unity |
112 | 89 | 77 | ||
113 | === modified file 'tests/test_raw_pixel.cpp' | |||
114 | --- tests/test_raw_pixel.cpp 2014-02-26 00:01:21 +0000 | |||
115 | +++ tests/test_raw_pixel.cpp 2017-10-04 18:50:31 +0000 | |||
116 | @@ -25,14 +25,13 @@ | |||
117 | 25 | namespace unity | 25 | namespace unity |
118 | 26 | { | 26 | { |
119 | 27 | 27 | ||
120 | 28 | int const FONT_SIZE = 13; | ||
121 | 29 | double const DPI = 96.0; | 28 | double const DPI = 96.0; |
122 | 30 | 29 | ||
123 | 31 | class TestRawPixel : public Test | 30 | class TestRawPixel : public Test |
124 | 32 | { | 31 | { |
125 | 33 | public: | 32 | public: |
126 | 34 | TestRawPixel() | 33 | TestRawPixel() |
128 | 35 | : cv(std::make_shared<EMConverter>(FONT_SIZE, DPI)) | 34 | : cv(std::make_shared<EMConverter>(DPI)) |
129 | 36 | , p_i(10_em) | 35 | , p_i(10_em) |
130 | 37 | , p_f(10.0_em) | 36 | , p_f(10.0_em) |
131 | 38 | { | 37 | { |
132 | 39 | 38 | ||
133 | === modified file 'tools/migration-scripts/02_unity_setup_text_scale_factor' | |||
134 | --- tools/migration-scripts/02_unity_setup_text_scale_factor 2016-02-22 20:34:21 +0000 | |||
135 | +++ tools/migration-scripts/02_unity_setup_text_scale_factor 2017-10-04 18:50:31 +0000 | |||
136 | @@ -1,6 +1,6 @@ | |||
137 | 1 | #!/usr/bin/python3 | 1 | #!/usr/bin/python3 |
138 | 2 | # -*- coding: utf-8 -*- | 2 | # -*- coding: utf-8 -*- |
140 | 3 | # Copyright (C) 2014-2015 Canonical | 3 | # Copyright (C) 2014-2017 Canonical |
141 | 4 | # | 4 | # |
142 | 5 | # Authors: | 5 | # Authors: |
143 | 6 | # Marco Trevisan <marco.trevisan@canonical.com> | 6 | # Marco Trevisan <marco.trevisan@canonical.com> |
144 | @@ -25,7 +25,6 @@ | |||
145 | 25 | GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; | 25 | GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; |
146 | 26 | 26 | ||
147 | 27 | UNITY_UI_SETTINGS = "com.canonical.Unity.Interface"; | 27 | UNITY_UI_SETTINGS = "com.canonical.Unity.Interface"; |
148 | 28 | UNITY_UI_SETTINGS_PATH = "/com/canonical/unity/interface/" | ||
149 | 29 | UNITY_TEXT_SCALE_FACTOR = "text-scale-factor"; | 28 | UNITY_TEXT_SCALE_FACTOR = "text-scale-factor"; |
150 | 30 | 29 | ||
151 | 31 | gnome_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(GNOME_UI_SETTINGS, recursive=False) | 30 | gnome_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(GNOME_UI_SETTINGS, recursive=False) |
152 | @@ -35,8 +34,5 @@ | |||
153 | 35 | 34 | ||
154 | 36 | text_scale_factor = Gio.Settings(settings_schema=gnome_ui_schema).get_double(GNOME_TEXT_SCALE_FACTOR) | 35 | text_scale_factor = Gio.Settings(settings_schema=gnome_ui_schema).get_double(GNOME_TEXT_SCALE_FACTOR) |
155 | 37 | 36 | ||
161 | 38 | # gsettings doesn't work directly, the key is somewhat reverted. Work one level under then: dconf! | 37 | Gio.Settings.new(UNITY_UI_SETTINGS).set_double(UNITY_TEXT_SCALE_FACTOR, text_scale_factor) |
162 | 39 | # Gio.Settings(schema=UNITY_UI_SETTINGS).set_int(UNITY_TEXT_SCALE_FACTOR, text_scale_factor) | 38 | Gio.Settings.sync() |
158 | 40 | from subprocess import Popen, PIPE, STDOUT | ||
159 | 41 | p = Popen(("dconf load "+UNITY_UI_SETTINGS_PATH).split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) | ||
160 | 42 | p.communicate(input=bytes("[/]\n"+UNITY_TEXT_SCALE_FACTOR+"={}".format(text_scale_factor), 'utf-8')) | ||
163 | 43 | 39 | ||
164 | === modified file 'tools/migration-scripts/04_unity_update_software_center_desktop_file' (properties changed: -x to +x) | |||
165 | --- tools/migration-scripts/04_unity_update_software_center_desktop_file 2016-02-22 20:50:18 +0000 | |||
166 | +++ tools/migration-scripts/04_unity_update_software_center_desktop_file 2017-10-04 18:50:31 +0000 | |||
167 | @@ -21,16 +21,17 @@ | |||
168 | 21 | from gi.repository import Gio | 21 | from gi.repository import Gio |
169 | 22 | 22 | ||
170 | 23 | UNITY_LAUNCHER_SETTINGS = "com.canonical.Unity.Launcher"; | 23 | UNITY_LAUNCHER_SETTINGS = "com.canonical.Unity.Launcher"; |
171 | 24 | UNITY_LAUNCHER_SETTINGS_PATH = "/com/canonical/unity/launcher/" | ||
172 | 25 | UNITY_LAUNCER_FAVORITES = "favorites"; | 24 | UNITY_LAUNCER_FAVORITES = "favorites"; |
173 | 26 | 25 | ||
175 | 27 | favorites = Gio.Settings(schema=UNITY_LAUNCHER_SETTINGS).get_strv(UNITY_LAUNCER_FAVORITES) | 26 | launcher_settings = Gio.Settings.new(UNITY_LAUNCHER_SETTINGS) |
176 | 27 | favorites = launcher_settings.get_strv(UNITY_LAUNCER_FAVORITES) | ||
177 | 28 | replaced = False | ||
178 | 28 | 29 | ||
179 | 29 | for i in range(len(favorites)): | 30 | for i in range(len(favorites)): |
180 | 30 | if 'ubuntu-software-center.desktop' in favorites[i]: | 31 | if 'ubuntu-software-center.desktop' in favorites[i]: |
181 | 31 | favorites[i] = favorites[i].replace('ubuntu-software-center', 'org.gnome.Software') | 32 | favorites[i] = favorites[i].replace('ubuntu-software-center', 'org.gnome.Software') |
182 | 33 | replaced = True | ||
183 | 32 | 34 | ||
188 | 33 | # gsettings doesn't work directly, the key is somewhat reverted. Work one level under then: dconf! | 35 | if replaced: |
189 | 34 | from subprocess import Popen, PIPE, STDOUT | 36 | launcher_settings.set_strv(UNITY_LAUNCER_FAVORITES, favorites) |
190 | 35 | p = Popen(("dconf load "+UNITY_LAUNCHER_SETTINGS_PATH).split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) | 37 | Gio.Settings.sync() |
187 | 36 | p.communicate(input=bytes("[/]\n"+UNITY_LAUNCER_FAVORITES+"={}".format(favorites), 'utf-8')) | ||
191 | 37 | 38 | ||
192 | === added file 'tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas' | |||
193 | --- tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas 1970-01-01 00:00:00 +0000 | |||
194 | +++ tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas 2017-10-04 18:50:31 +0000 | |||
195 | @@ -0,0 +1,66 @@ | |||
196 | 1 | #!/usr/bin/python3 | ||
197 | 2 | # -*- coding: utf-8 -*- | ||
198 | 3 | # Copyright (C) 2014-2017 Canonical | ||
199 | 4 | # | ||
200 | 5 | # Authors: | ||
201 | 6 | # Marco Trevisan <marco.trevisan@canonical.com> | ||
202 | 7 | # | ||
203 | 8 | # This program is free software; you can redistribute it and/or modify it under | ||
204 | 9 | # the terms of the GNU General Public License as published by the Free Software | ||
205 | 10 | # Foundation; version 3. | ||
206 | 11 | # | ||
207 | 12 | # This program is distributed in the hope that it will be useful, but WITHOUTa | ||
208 | 13 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
209 | 14 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
210 | 15 | # details. | ||
211 | 16 | # | ||
212 | 17 | # You should have received a copy of the GNU General Public License along with | ||
213 | 18 | # this program; if not, write to the Free Software Foundation, Inc., | ||
214 | 19 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
215 | 20 | |||
216 | 21 | from gi.repository import Gio | ||
217 | 22 | import os,sys | ||
218 | 23 | |||
219 | 24 | GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; | ||
220 | 25 | UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface.desktop"; | ||
221 | 26 | UNITY_UI_SETTINGS = "com.canonical.Unity.Interface"; | ||
222 | 27 | |||
223 | 28 | KEYS_TO_TRANSLATE = { "text-scaling-factor": "text-scale-factor" } | ||
224 | 29 | KEYS_TO_MIGRATE = [ "cursor-size", "scaling-factor", "text-scaling-factor" ] | ||
225 | 30 | |||
226 | 31 | gnome_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(GNOME_UI_SETTINGS, recursive=False) | ||
227 | 32 | if not gnome_ui_schema: | ||
228 | 33 | print("No gnome desktop interface schemas found, no migration needed") | ||
229 | 34 | sys.exit(0) | ||
230 | 35 | |||
231 | 36 | ubuntu_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(UBUNTU_UI_SETTINGS, recursive=False) | ||
232 | 37 | if not ubuntu_ui_schema: | ||
233 | 38 | print("No ubuntu desktop interface schemas found, no migration needed") | ||
234 | 39 | sys.exit(0) | ||
235 | 40 | |||
236 | 41 | gnome_settings = Gio.Settings(settings_schema=gnome_ui_schema) | ||
237 | 42 | ubuntu_settings = Gio.Settings(settings_schema=ubuntu_ui_schema) | ||
238 | 43 | |||
239 | 44 | for key in KEYS_TO_MIGRATE: | ||
240 | 45 | gnome_value = gnome_settings.get_value(key) | ||
241 | 46 | ubuntu_value = ubuntu_settings.get_value(key) | ||
242 | 47 | |||
243 | 48 | # We reset the gnome values first | ||
244 | 49 | if gnome_settings.is_writable(key): | ||
245 | 50 | if key in KEYS_TO_TRANSLATE.keys(): | ||
246 | 51 | unity_value = Gio.Settings.new(UNITY_UI_SETTINGS).get_value(KEYS_TO_TRANSLATE[key]) | ||
247 | 52 | if unity_value != gnome_value: | ||
248 | 53 | gnome_settings.set_value(key, unity_value) | ||
249 | 54 | else: | ||
250 | 55 | gnome_settings.reset(key) | ||
251 | 56 | else: | ||
252 | 57 | print("Can't reset or migrate key '{} {}': in read only.".format(GNOME_UI_SETTINGS, key)) | ||
253 | 58 | |||
254 | 59 | # Then we migrate the settings, so that u-s-d proxy won't interfere | ||
255 | 60 | if ubuntu_settings.is_writable(key): | ||
256 | 61 | if ubuntu_value != gnome_value: | ||
257 | 62 | ubuntu_settings.set_value(key, gnome_value) | ||
258 | 63 | else: | ||
259 | 64 | print("Can't migrate key '{} {}': in read only.".format(UBUNTU_UI_SETTINGS, key)) | ||
260 | 65 | |||
261 | 66 | Gio.Settings.sync() | ||
262 | 0 | 67 | ||
263 | === modified file 'unity-shared/EMConverter.cpp' | |||
264 | --- unity-shared/EMConverter.cpp 2014-05-08 03:19:39 +0000 | |||
265 | +++ unity-shared/EMConverter.cpp 2017-10-04 18:50:31 +0000 | |||
266 | @@ -23,86 +23,31 @@ | |||
267 | 23 | namespace unity | 23 | namespace unity |
268 | 24 | { | 24 | { |
269 | 25 | 25 | ||
317 | 26 | double const BASE_DPI = 96.0; | 26 | namespace |
318 | 27 | double const DEFAULT_PPE = 10.0; | 27 | { |
319 | 28 | double const PIXELS_PER_INCH = 72.0; | 28 | const double BASE_DPI = 96.0; |
320 | 29 | 29 | } | |
321 | 30 | EMConverter::EMConverter(int font_size, double dpi) | 30 | |
322 | 31 | : pixels_per_em_(DEFAULT_PPE) | 31 | EMConverter::EMConverter(double dpi) |
323 | 32 | , base_pixels_per_em_(DEFAULT_PPE) | 32 | : dpi_(dpi) |
324 | 33 | , dpi_(dpi) | 33 | {} |
278 | 34 | , font_size_(font_size) | ||
279 | 35 | { | ||
280 | 36 | UpdatePixelsPerEM(); | ||
281 | 37 | UpdateBasePixelsPerEM(); | ||
282 | 38 | } | ||
283 | 39 | |||
284 | 40 | double EMConverter::PtToPx(int pt) | ||
285 | 41 | { | ||
286 | 42 | return pt * dpi_ / PIXELS_PER_INCH; | ||
287 | 43 | } | ||
288 | 44 | |||
289 | 45 | void EMConverter::UpdatePixelsPerEM() | ||
290 | 46 | { | ||
291 | 47 | pixels_per_em_ = font_size_ * dpi_ / PIXELS_PER_INCH; | ||
292 | 48 | |||
293 | 49 | if (pixels_per_em_ == 0) | ||
294 | 50 | pixels_per_em_ = DEFAULT_PPE; | ||
295 | 51 | } | ||
296 | 52 | |||
297 | 53 | void EMConverter::UpdateBasePixelsPerEM() | ||
298 | 54 | { | ||
299 | 55 | base_pixels_per_em_ = font_size_ * BASE_DPI / PIXELS_PER_INCH; | ||
300 | 56 | |||
301 | 57 | if (base_pixels_per_em_ == 0) | ||
302 | 58 | base_pixels_per_em_ = DEFAULT_PPE; | ||
303 | 59 | } | ||
304 | 60 | |||
305 | 61 | bool EMConverter::SetFontSize(int font_size) | ||
306 | 62 | { | ||
307 | 63 | if (font_size != font_size_) | ||
308 | 64 | { | ||
309 | 65 | font_size_ = font_size; | ||
310 | 66 | UpdatePixelsPerEM(); | ||
311 | 67 | UpdateBasePixelsPerEM(); | ||
312 | 68 | return true; | ||
313 | 69 | } | ||
314 | 70 | |||
315 | 71 | return false; | ||
316 | 72 | } | ||
325 | 73 | 34 | ||
326 | 74 | bool EMConverter::SetDPI(double dpi) | 35 | bool EMConverter::SetDPI(double dpi) |
327 | 75 | { | 36 | { |
328 | 76 | if (dpi != dpi_) | 37 | if (dpi != dpi_) |
329 | 77 | { | 38 | { |
330 | 78 | dpi_ = dpi; | 39 | dpi_ = dpi; |
331 | 79 | UpdatePixelsPerEM(); | ||
332 | 80 | return true; | 40 | return true; |
333 | 81 | } | 41 | } |
334 | 82 | 42 | ||
335 | 83 | return false; | 43 | return false; |
336 | 84 | } | 44 | } |
337 | 85 | 45 | ||
338 | 86 | int EMConverter::GetFontSize() const | ||
339 | 87 | { | ||
340 | 88 | return font_size_; | ||
341 | 89 | } | ||
342 | 90 | |||
343 | 91 | double EMConverter::GetDPI() const | 46 | double EMConverter::GetDPI() const |
344 | 92 | { | 47 | { |
345 | 93 | return dpi_; | 48 | return dpi_; |
346 | 94 | } | 49 | } |
347 | 95 | 50 | ||
348 | 96 | double EMConverter::EMToPixels(double em) const | ||
349 | 97 | { | ||
350 | 98 | return (em * pixels_per_em_); | ||
351 | 99 | } | ||
352 | 100 | |||
353 | 101 | double EMConverter::PixelsToBaseEM(int pixels) const | ||
354 | 102 | { | ||
355 | 103 | return (pixels / base_pixels_per_em_); | ||
356 | 104 | } | ||
357 | 105 | |||
358 | 106 | double EMConverter::CP(int pixels) const | 51 | double EMConverter::CP(int pixels) const |
359 | 107 | { | 52 | { |
360 | 108 | return std::round(pixels * DPIScale()); | 53 | return std::round(pixels * DPIScale()); |
361 | 109 | 54 | ||
362 | === modified file 'unity-shared/EMConverter.h' | |||
363 | --- unity-shared/EMConverter.h 2014-02-27 04:54:19 +0000 | |||
364 | +++ unity-shared/EMConverter.h 2017-10-04 18:50:31 +0000 | |||
365 | @@ -30,31 +30,16 @@ | |||
366 | 30 | public: | 30 | public: |
367 | 31 | typedef std::shared_ptr<EMConverter> Ptr; | 31 | typedef std::shared_ptr<EMConverter> Ptr; |
368 | 32 | 32 | ||
370 | 33 | EMConverter(int font_size = 0, double dpi = 96.0); | 33 | EMConverter(double dpi = 96.0); |
371 | 34 | 34 | ||
372 | 35 | bool SetFontSize(int font_size); | ||
373 | 36 | bool SetDPI(double dpi); | 35 | bool SetDPI(double dpi); |
374 | 37 | |||
375 | 38 | int GetFontSize() const; | ||
376 | 39 | double GetDPI() const; | 36 | double GetDPI() const; |
377 | 40 | 37 | ||
378 | 41 | double CP(int pixels) const; | 38 | double CP(int pixels) const; |
379 | 42 | double DPIScale() const; | 39 | double DPIScale() const; |
380 | 43 | 40 | ||
381 | 44 | double PtToPx(int pt); | ||
382 | 45 | |||
383 | 46 | private: | 41 | private: |
384 | 47 | void UpdatePixelsPerEM(); | ||
385 | 48 | void UpdateBasePixelsPerEM(); | ||
386 | 49 | |||
387 | 50 | double EMToPixels(double em) const; | ||
388 | 51 | double PixelsToBaseEM(int pixels) const; | ||
389 | 52 | |||
390 | 53 | double pixels_per_em_; | ||
391 | 54 | double base_pixels_per_em_; | ||
392 | 55 | |||
393 | 56 | double dpi_; | 42 | double dpi_; |
394 | 57 | int font_size_; | ||
395 | 58 | }; | 43 | }; |
396 | 59 | 44 | ||
397 | 60 | } // namespace unity | 45 | } // namespace unity |
398 | 61 | 46 | ||
399 | === modified file 'unity-shared/UnitySettings.cpp' | |||
400 | --- unity-shared/UnitySettings.cpp 2017-07-17 10:33:25 +0000 | |||
401 | +++ unity-shared/UnitySettings.cpp 2017-10-04 18:50:31 +0000 | |||
402 | @@ -62,13 +62,12 @@ | |||
403 | 62 | const std::string COMPIZ_PROFILE = "current-profile"; | 62 | const std::string COMPIZ_PROFILE = "current-profile"; |
404 | 63 | 63 | ||
405 | 64 | const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface"; | 64 | const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface"; |
406 | 65 | const std::string UBUNTU_DESKTOP_UI_SETTINGS = "com.ubuntu.user-interface.desktop"; | ||
407 | 65 | const std::string SCALE_FACTOR = "scale-factor"; | 66 | const std::string SCALE_FACTOR = "scale-factor"; |
408 | 66 | 67 | ||
414 | 67 | const std::string GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; | 68 | const std::string DESKTOP_CURSOR_SIZE = "cursor-size"; |
415 | 68 | const std::string GNOME_FONT_NAME = "font-name"; | 69 | const std::string DESKTOP_SCALE_FACTOR = "scaling-factor"; |
416 | 69 | const std::string GNOME_CURSOR_SIZE = "cursor-size"; | 70 | const std::string DESKTOP_TEXT_SCALE_FACTOR = "text-scaling-factor"; |
412 | 70 | const std::string GNOME_SCALE_FACTOR = "scaling-factor"; | ||
413 | 71 | const std::string GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; | ||
417 | 72 | 71 | ||
418 | 73 | const std::string REMOTE_CONTENT_SETTINGS = "com.canonical.Unity.Lenses"; | 72 | const std::string REMOTE_CONTENT_SETTINGS = "com.canonical.Unity.Lenses"; |
419 | 74 | const std::string REMOTE_CONTENT_KEY = "remote-content-search"; | 73 | const std::string REMOTE_CONTENT_KEY = "remote-content-search"; |
420 | @@ -84,7 +83,7 @@ | |||
421 | 84 | 83 | ||
422 | 85 | const int DEFAULT_LAUNCHER_SIZE = 64; | 84 | const int DEFAULT_LAUNCHER_SIZE = 64; |
423 | 86 | const int MINIMUM_DESKTOP_HEIGHT = 800; | 85 | const int MINIMUM_DESKTOP_HEIGHT = 800; |
425 | 87 | const int GNOME_SETTINGS_CHANGED_WAIT_SECONDS = 1; | 86 | const int DESKTOP_SETTINGS_CHANGED_WAIT_SECONDS = 1; |
426 | 88 | const double DEFAULT_DPI = 96.0f; | 87 | const double DEFAULT_DPI = 96.0f; |
427 | 89 | const double DPI_SCALING_LIMIT = 140.0f; | 88 | const double DPI_SCALING_LIMIT = 140.0f; |
428 | 90 | const int DPI_SCALING_STEP = 8; | 89 | const int DPI_SCALING_STEP = 8; |
429 | @@ -105,7 +104,7 @@ | |||
430 | 105 | , gestures_settings_(g_settings_new(GESTURES_SETTINGS.c_str())) | 104 | , gestures_settings_(g_settings_new(GESTURES_SETTINGS.c_str())) |
431 | 106 | , ui_settings_(g_settings_new(UI_SETTINGS.c_str())) | 105 | , ui_settings_(g_settings_new(UI_SETTINGS.c_str())) |
432 | 107 | , ubuntu_ui_settings_(g_settings_new(UBUNTU_UI_SETTINGS.c_str())) | 106 | , ubuntu_ui_settings_(g_settings_new(UBUNTU_UI_SETTINGS.c_str())) |
434 | 108 | , gnome_ui_settings_(g_settings_new(GNOME_UI_SETTINGS.c_str())) | 107 | , desktop_ui_settings_(g_settings_new(UBUNTU_DESKTOP_UI_SETTINGS.c_str())) |
435 | 109 | , remote_content_settings_(g_settings_new(REMOTE_CONTENT_SETTINGS.c_str())) | 108 | , remote_content_settings_(g_settings_new(REMOTE_CONTENT_SETTINGS.c_str())) |
436 | 110 | , launcher_sizes_(monitors::MAX, DEFAULT_LAUNCHER_SIZE) | 109 | , launcher_sizes_(monitors::MAX, DEFAULT_LAUNCHER_SIZE) |
437 | 111 | , cached_launcher_position_(LauncherPosition::LEFT) | 110 | , cached_launcher_position_(LauncherPosition::LEFT) |
438 | @@ -174,13 +173,8 @@ | |||
439 | 174 | UpdateDPI(); | 173 | UpdateDPI(); |
440 | 175 | }); | 174 | }); |
441 | 176 | 175 | ||
449 | 177 | signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_FONT_NAME, [this] (GSettings*, const gchar* t) { | 176 | signals_.Add<void, GSettings*, const gchar*>(desktop_ui_settings_, "changed::" + DESKTOP_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { |
450 | 178 | UpdateFontSize(); | 177 | double new_scale_factor = g_settings_get_double(desktop_ui_settings_, DESKTOP_TEXT_SCALE_FACTOR.c_str()); |
444 | 179 | UpdateDPI(); | ||
445 | 180 | }); | ||
446 | 181 | |||
447 | 182 | signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { | ||
448 | 183 | double new_scale_factor = g_settings_get_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str()); | ||
451 | 184 | g_settings_set_double(ui_settings_, TEXT_SCALE_FACTOR.c_str(), new_scale_factor); | 178 | g_settings_set_double(ui_settings_, TEXT_SCALE_FACTOR.c_str(), new_scale_factor); |
452 | 185 | }); | 179 | }); |
453 | 186 | 180 | ||
454 | @@ -203,7 +197,6 @@ | |||
455 | 203 | UpdateGesturesSetting(); | 197 | UpdateGesturesSetting(); |
456 | 204 | UpdateTextScaleFactor(); | 198 | UpdateTextScaleFactor(); |
457 | 205 | UpdateCursorScaleFactor(); | 199 | UpdateCursorScaleFactor(); |
458 | 206 | UpdateFontSize(); | ||
459 | 207 | UpdateDPI(); | 200 | UpdateDPI(); |
460 | 208 | 201 | ||
461 | 209 | CacheFormFactor(); | 202 | CacheFormFactor(); |
462 | @@ -365,27 +358,6 @@ | |||
463 | 365 | return g_settings_get_boolean(usettings_, PAM_CHECK_ACCOUNT_TYPE.c_str()); | 358 | return g_settings_get_boolean(usettings_, PAM_CHECK_ACCOUNT_TYPE.c_str()); |
464 | 366 | } | 359 | } |
465 | 367 | 360 | ||
466 | 368 | int GetFontSize() const | ||
467 | 369 | { | ||
468 | 370 | gint font_size; | ||
469 | 371 | PangoFontDescription* desc; | ||
470 | 372 | |||
471 | 373 | glib::String font_name(g_settings_get_string(gnome_ui_settings_, GNOME_FONT_NAME.c_str())); | ||
472 | 374 | desc = pango_font_description_from_string(font_name); | ||
473 | 375 | font_size = pango_font_description_get_size(desc); | ||
474 | 376 | pango_font_description_free(desc); | ||
475 | 377 | |||
476 | 378 | return font_size / 1024; | ||
477 | 379 | } | ||
478 | 380 | |||
479 | 381 | void UpdateFontSize() | ||
480 | 382 | { | ||
481 | 383 | int font_size = GetFontSize(); | ||
482 | 384 | |||
483 | 385 | for (auto const& em : em_converters_) | ||
484 | 386 | em->SetFontSize(font_size); | ||
485 | 387 | } | ||
486 | 388 | |||
487 | 389 | void UpdateTextScaleFactor() | 361 | void UpdateTextScaleFactor() |
488 | 390 | { | 362 | { |
489 | 391 | parent_->font_scaling = g_settings_get_double(ui_settings_, TEXT_SCALE_FACTOR.c_str()); | 363 | parent_->font_scaling = g_settings_get_double(ui_settings_, TEXT_SCALE_FACTOR.c_str()); |
490 | @@ -505,18 +477,18 @@ | |||
491 | 505 | 477 | ||
492 | 506 | void UpdateAppsScaling(double scale) | 478 | void UpdateAppsScaling(double scale) |
493 | 507 | { | 479 | { |
495 | 508 | signals_.Block(gnome_ui_settings_); | 480 | signals_.Block(desktop_ui_settings_); |
496 | 509 | unsigned integer_scaling = std::max<unsigned>(1, std::lround(scale)); | 481 | unsigned integer_scaling = std::max<unsigned>(1, std::lround(scale)); |
497 | 510 | double point_scaling = scale / static_cast<double>(integer_scaling); | 482 | double point_scaling = scale / static_cast<double>(integer_scaling); |
498 | 511 | double text_scale_factor = parent_->font_scaling() * point_scaling; | 483 | double text_scale_factor = parent_->font_scaling() * point_scaling; |
500 | 512 | glib::Variant default_cursor_size(g_settings_get_default_value(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str()), glib::StealRef()); | 484 | glib::Variant default_cursor_size(g_settings_get_default_value(desktop_ui_settings_, DESKTOP_CURSOR_SIZE.c_str()), glib::StealRef()); |
501 | 513 | int cursor_size = std::round(default_cursor_size.GetInt32() * point_scaling * cursor_scale_); | 485 | int cursor_size = std::round(default_cursor_size.GetInt32() * point_scaling * cursor_scale_); |
505 | 514 | g_settings_set_int(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str(), cursor_size); | 486 | g_settings_set_int(desktop_ui_settings_, DESKTOP_CURSOR_SIZE.c_str(), cursor_size); |
506 | 515 | g_settings_set_uint(gnome_ui_settings_, GNOME_SCALE_FACTOR.c_str(), integer_scaling); | 487 | g_settings_set_uint(desktop_ui_settings_, DESKTOP_SCALE_FACTOR.c_str(), integer_scaling); |
507 | 516 | g_settings_set_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); | 488 | g_settings_set_double(desktop_ui_settings_, DESKTOP_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); |
508 | 517 | 489 | ||
511 | 518 | changing_gnome_settings_timeout_.reset(new glib::TimeoutSeconds(GNOME_SETTINGS_CHANGED_WAIT_SECONDS, [this] { | 490 | changing_desktop_settings_timeout_.reset(new glib::TimeoutSeconds(DESKTOP_SETTINGS_CHANGED_WAIT_SECONDS, [this] { |
512 | 519 | signals_.Unblock(gnome_ui_settings_); | 491 | signals_.Unblock(desktop_ui_settings_); |
513 | 520 | return false; | 492 | return false; |
514 | 521 | }, glib::Source::Priority::LOW)); | 493 | }, glib::Source::Priority::LOW)); |
515 | 522 | } | 494 | } |
516 | @@ -546,9 +518,9 @@ | |||
517 | 546 | glib::Object<GSettings> gestures_settings_; | 518 | glib::Object<GSettings> gestures_settings_; |
518 | 547 | glib::Object<GSettings> ui_settings_; | 519 | glib::Object<GSettings> ui_settings_; |
519 | 548 | glib::Object<GSettings> ubuntu_ui_settings_; | 520 | glib::Object<GSettings> ubuntu_ui_settings_; |
521 | 549 | glib::Object<GSettings> gnome_ui_settings_; | 521 | glib::Object<GSettings> desktop_ui_settings_; |
522 | 550 | glib::Object<GSettings> remote_content_settings_; | 522 | glib::Object<GSettings> remote_content_settings_; |
524 | 551 | glib::Source::UniquePtr changing_gnome_settings_timeout_; | 523 | glib::Source::UniquePtr changing_desktop_settings_timeout_; |
525 | 552 | glib::SignalManager signals_; | 524 | glib::SignalManager signals_; |
526 | 553 | std::vector<EMConverter::Ptr> em_converters_; | 525 | std::vector<EMConverter::Ptr> em_converters_; |
527 | 554 | std::vector<int> launcher_sizes_; | 526 | std::vector<int> launcher_sizes_; |
+1