diff options
| author | Marco Trevisan (TreviƱo) <mail@3v1n0.net> | 2017-10-04 18:50:26 +0000 |
|---|---|---|
| committer | Bileto Bot <ci-train-bot@canonical.com> | 2017-10-04 18:50:26 +0000 |
| commit | 244bdcbe0e34c50eca2689a90b788092d2fe00fe (patch) | |
| tree | 46e6273e670ef1c740a0e475073c8ee5b1ee2f8d | |
| parent | de253aa81d99d81ec240dd99c99cfe7bb307cdf1 (diff) | |
| parent | b9d26c4f2df57b119dfc8ceb25398bd9947451ff (diff) | |
UnitySettings: use the ubuntu-schemas path for scaling settings
Also remove unused parts of EMConverter (LP: #1721082) Approved by: Andrea Azzarone (bzr r4260)
| -rw-r--r-- | debian/control | 3 | ||||
| -rw-r--r-- | debian/unity.migrations | 1 | ||||
| -rw-r--r-- | tests/data/external.gschema.xml | 13 | ||||
| -rw-r--r-- | tests/test_em_converter.cpp | 26 | ||||
| -rw-r--r-- | tests/test_raw_pixel.cpp | 3 | ||||
| -rwxr-xr-x | tools/migration-scripts/02_unity_setup_text_scale_factor | 10 | ||||
| -rwxr-xr-x[-rw-r--r--] | tools/migration-scripts/04_unity_update_software_center_desktop_file | 13 | ||||
| -rwxr-xr-x | tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas | 66 | ||||
| -rw-r--r-- | unity-shared/EMConverter.cpp | 65 | ||||
| -rw-r--r-- | unity-shared/EMConverter.h | 17 | ||||
| -rw-r--r-- | unity-shared/UnitySettings.cpp | 62 |
11 files changed, 123 insertions, 156 deletions
diff --git a/debian/control b/debian/control index acca6839e..f61138fde 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Build-Depends: cmake, dh-python, google-mock (>= 1.6.0+svn437), gsettings-desktop-schemas-dev, - gsettings-ubuntu-schemas (>= 0.0.1+14.04.20140219), + gsettings-ubuntu-schemas (>= 0.0.7+17.10.20170922), intltool (>= 0.35.0), libappstream-glib-dev, libatk1.0-dev, @@ -73,6 +73,7 @@ Depends: ${shlibs:Depends}, compiz-core, compiz-core-abiversion-${coreabiversion}, libnux-abiversion-${nuxabiversion}, compiz-plugins-default, + gsettings-ubuntu-schemas (>= 0.0.7+17.10.20170922), libglib2.0-bin, nux-tools, python3-gi, diff --git a/debian/unity.migrations b/debian/unity.migrations index 58bd12d59..98ba87204 100644 --- a/debian/unity.migrations +++ b/debian/unity.migrations @@ -2,3 +2,4 @@ tools/migration-scripts/01_unity_change_dconf_path tools/migration-scripts/02_unity_setup_text_scale_factor tools/migration-scripts/03_unity_first_run_stamp_move tools/migration-scripts/04_unity_update_software_center_desktop_file +tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas \ No newline at end of file diff --git a/tests/data/external.gschema.xml b/tests/data/external.gschema.xml index 6d498e2a0..9b7c1a2d0 100644 --- a/tests/data/external.gschema.xml +++ b/tests/data/external.gschema.xml @@ -74,6 +74,19 @@ </key> </schema> + <schema path="/com/ubuntu/user-interface/desktop/" id="com.ubuntu.user-interface.desktop"> + <key type="u" name="scaling-factor"> + <default>0</default> + </key> + <key type="d" name="text-scaling-factor"> + <range min="0.5" max="3.0"/> + <default>1.0</default> + </key> + <key type="i" name="cursor-size"> + <default>24</default> + </key> + </schema> + <schema id="com.canonical.unity-greeter" path="/com/canonical/unity-greeter/"> <key type="s" name="logo"> <default>'/usr/share/unity-greeter/logo.png'</default> diff --git a/tests/test_em_converter.cpp b/tests/test_em_converter.cpp index 3936c08bc..44239263e 100644 --- a/tests/test_em_converter.cpp +++ b/tests/test_em_converter.cpp @@ -26,34 +26,19 @@ namespace unity { int const PIXEL_SIZE = 24; -int const FONT_SIZE = 13; double const DPI = 96.0; class TestEMConverter : public Test { public: TestEMConverter() - : em_converter(FONT_SIZE, DPI) + : em_converter(DPI) { } EMConverter em_converter; }; -TEST_F(TestEMConverter, TestCtor) -{ - EXPECT_EQ(FONT_SIZE, em_converter.GetFontSize()); - EXPECT_EQ(DPI, em_converter.GetDPI()); -} - -TEST_F(TestEMConverter, TestSetFontSize) -{ - int const font_size = 15; - - em_converter.SetFontSize(font_size); - EXPECT_EQ(font_size, em_converter.GetFontSize()); -} - TEST_F(TestEMConverter, TestSetDPI) { int const dpi = 120.0; @@ -79,10 +64,13 @@ TEST_F(TestEMConverter, TestDPIScale2) EXPECT_FLOAT_EQ(em_converter.DPIScale(), 2.0); } -TEST_F(TestEMConverter, TestPtToPx) +TEST_F(TestEMConverter, TestConvertPixelScaled) { - int pt = 12; - EXPECT_EQ(em_converter.PtToPx(pt), 16); + for (double scale : std::vector<double>({1.0, 1.25, 1.5, 1.75, 2})) + { + em_converter.SetDPI(DPI * scale); + EXPECT_EQ(std::round(PIXEL_SIZE * scale), em_converter.CP(PIXEL_SIZE)); + } } } // namespace unity diff --git a/tests/test_raw_pixel.cpp b/tests/test_raw_pixel.cpp index 140bf6010..c7cc9eef5 100644 --- a/tests/test_raw_pixel.cpp +++ b/tests/test_raw_pixel.cpp @@ -25,14 +25,13 @@ using namespace testing; namespace unity { -int const FONT_SIZE = 13; double const DPI = 96.0; class TestRawPixel : public Test { public: TestRawPixel() - : cv(std::make_shared<EMConverter>(FONT_SIZE, DPI)) + : cv(std::make_shared<EMConverter>(DPI)) , p_i(10_em) , p_f(10.0_em) { diff --git a/tools/migration-scripts/02_unity_setup_text_scale_factor b/tools/migration-scripts/02_unity_setup_text_scale_factor index b4d42557d..5f8201eab 100755 --- a/tools/migration-scripts/02_unity_setup_text_scale_factor +++ b/tools/migration-scripts/02_unity_setup_text_scale_factor @@ -1,6 +1,6 @@ #!/usr/bin/python3 # -*- coding: utf-8 -*- -# Copyright (C) 2014-2015 Canonical +# Copyright (C) 2014-2017 Canonical # # Authors: # Marco Trevisan <marco.trevisan@canonical.com> @@ -25,7 +25,6 @@ GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; UNITY_UI_SETTINGS = "com.canonical.Unity.Interface"; -UNITY_UI_SETTINGS_PATH = "/com/canonical/unity/interface/" UNITY_TEXT_SCALE_FACTOR = "text-scale-factor"; gnome_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(GNOME_UI_SETTINGS, recursive=False) @@ -35,8 +34,5 @@ if not gnome_ui_schema: text_scale_factor = Gio.Settings(settings_schema=gnome_ui_schema).get_double(GNOME_TEXT_SCALE_FACTOR) -# gsettings doesn't work directly, the key is somewhat reverted. Work one level under then: dconf! -# Gio.Settings(schema=UNITY_UI_SETTINGS).set_int(UNITY_TEXT_SCALE_FACTOR, text_scale_factor) -from subprocess import Popen, PIPE, STDOUT -p = Popen(("dconf load "+UNITY_UI_SETTINGS_PATH).split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) -p.communicate(input=bytes("[/]\n"+UNITY_TEXT_SCALE_FACTOR+"={}".format(text_scale_factor), 'utf-8')) +Gio.Settings.new(UNITY_UI_SETTINGS).set_double(UNITY_TEXT_SCALE_FACTOR, text_scale_factor) +Gio.Settings.sync() diff --git a/tools/migration-scripts/04_unity_update_software_center_desktop_file b/tools/migration-scripts/04_unity_update_software_center_desktop_file index 3521b68be..5d94e70cd 100644..100755 --- a/tools/migration-scripts/04_unity_update_software_center_desktop_file +++ b/tools/migration-scripts/04_unity_update_software_center_desktop_file @@ -21,16 +21,17 @@ from gi.repository import Gio UNITY_LAUNCHER_SETTINGS = "com.canonical.Unity.Launcher"; -UNITY_LAUNCHER_SETTINGS_PATH = "/com/canonical/unity/launcher/" UNITY_LAUNCER_FAVORITES = "favorites"; -favorites = Gio.Settings(schema=UNITY_LAUNCHER_SETTINGS).get_strv(UNITY_LAUNCER_FAVORITES) +launcher_settings = Gio.Settings.new(UNITY_LAUNCHER_SETTINGS) +favorites = launcher_settings.get_strv(UNITY_LAUNCER_FAVORITES) +replaced = False for i in range(len(favorites)): if 'ubuntu-software-center.desktop' in favorites[i]: favorites[i] = favorites[i].replace('ubuntu-software-center', 'org.gnome.Software') + replaced = True -# gsettings doesn't work directly, the key is somewhat reverted. Work one level under then: dconf! -from subprocess import Popen, PIPE, STDOUT -p = Popen(("dconf load "+UNITY_LAUNCHER_SETTINGS_PATH).split(), stdout=PIPE, stdin=PIPE, stderr=STDOUT) -p.communicate(input=bytes("[/]\n"+UNITY_LAUNCER_FAVORITES+"={}".format(favorites), 'utf-8')) +if replaced: + launcher_settings.set_strv(UNITY_LAUNCER_FAVORITES, favorites) + Gio.Settings.sync() diff --git a/tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas b/tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas new file mode 100755 index 000000000..bfb8ad122 --- /dev/null +++ b/tools/migration-scripts/05_unity_use_ubuntu_scaling_settings_schemas @@ -0,0 +1,66 @@ +#!/usr/bin/python3 +# -*- coding: utf-8 -*- +# Copyright (C) 2014-2017 Canonical +# +# Authors: +# Marco Trevisan <marco.trevisan@canonical.com> +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free Software +# Foundation; version 3. +# +# This program is distributed in the hope that it will be useful, but WITHOUTa +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +from gi.repository import Gio +import os,sys + +GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; +UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface.desktop"; +UNITY_UI_SETTINGS = "com.canonical.Unity.Interface"; + +KEYS_TO_TRANSLATE = { "text-scaling-factor": "text-scale-factor" } +KEYS_TO_MIGRATE = [ "cursor-size", "scaling-factor", "text-scaling-factor" ] + +gnome_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(GNOME_UI_SETTINGS, recursive=False) +if not gnome_ui_schema: + print("No gnome desktop interface schemas found, no migration needed") + sys.exit(0) + +ubuntu_ui_schema = Gio.SettingsSchemaSource.get_default().lookup(UBUNTU_UI_SETTINGS, recursive=False) +if not ubuntu_ui_schema: + print("No ubuntu desktop interface schemas found, no migration needed") + sys.exit(0) + +gnome_settings = Gio.Settings(settings_schema=gnome_ui_schema) +ubuntu_settings = Gio.Settings(settings_schema=ubuntu_ui_schema) + +for key in KEYS_TO_MIGRATE: + gnome_value = gnome_settings.get_value(key) + ubuntu_value = ubuntu_settings.get_value(key) + + # We reset the gnome values first + if gnome_settings.is_writable(key): + if key in KEYS_TO_TRANSLATE.keys(): + unity_value = Gio.Settings.new(UNITY_UI_SETTINGS).get_value(KEYS_TO_TRANSLATE[key]) + if unity_value != gnome_value: + gnome_settings.set_value(key, unity_value) + else: + gnome_settings.reset(key) + else: + print("Can't reset or migrate key '{} {}': in read only.".format(GNOME_UI_SETTINGS, key)) + + # Then we migrate the settings, so that u-s-d proxy won't interfere + if ubuntu_settings.is_writable(key): + if ubuntu_value != gnome_value: + ubuntu_settings.set_value(key, gnome_value) + else: + print("Can't migrate key '{} {}': in read only.".format(UBUNTU_UI_SETTINGS, key)) + +Gio.Settings.sync() diff --git a/unity-shared/EMConverter.cpp b/unity-shared/EMConverter.cpp index 6a65ab38f..9616a057f 100644 --- a/unity-shared/EMConverter.cpp +++ b/unity-shared/EMConverter.cpp @@ -23,86 +23,31 @@ namespace unity { -double const BASE_DPI = 96.0; -double const DEFAULT_PPE = 10.0; -double const PIXELS_PER_INCH = 72.0; - -EMConverter::EMConverter(int font_size, double dpi) - : pixels_per_em_(DEFAULT_PPE) - , base_pixels_per_em_(DEFAULT_PPE) - , dpi_(dpi) - , font_size_(font_size) -{ - UpdatePixelsPerEM(); - UpdateBasePixelsPerEM(); -} - -double EMConverter::PtToPx(int pt) -{ - return pt * dpi_ / PIXELS_PER_INCH; -} - -void EMConverter::UpdatePixelsPerEM() +namespace { - pixels_per_em_ = font_size_ * dpi_ / PIXELS_PER_INCH; - - if (pixels_per_em_ == 0) - pixels_per_em_ = DEFAULT_PPE; +const double BASE_DPI = 96.0; } -void EMConverter::UpdateBasePixelsPerEM() -{ - base_pixels_per_em_ = font_size_ * BASE_DPI / PIXELS_PER_INCH; - - if (base_pixels_per_em_ == 0) - base_pixels_per_em_ = DEFAULT_PPE; -} - -bool EMConverter::SetFontSize(int font_size) -{ - if (font_size != font_size_) - { - font_size_ = font_size; - UpdatePixelsPerEM(); - UpdateBasePixelsPerEM(); - return true; - } - - return false; -} +EMConverter::EMConverter(double dpi) + : dpi_(dpi) +{} bool EMConverter::SetDPI(double dpi) { if (dpi != dpi_) { dpi_ = dpi; - UpdatePixelsPerEM(); return true; } return false; } -int EMConverter::GetFontSize() const -{ - return font_size_; -} - double EMConverter::GetDPI() const { return dpi_; } -double EMConverter::EMToPixels(double em) const -{ - return (em * pixels_per_em_); -} - -double EMConverter::PixelsToBaseEM(int pixels) const -{ - return (pixels / base_pixels_per_em_); -} - double EMConverter::CP(int pixels) const { return std::round(pixels * DPIScale()); diff --git a/unity-shared/EMConverter.h b/unity-shared/EMConverter.h index 4847d6274..374ed43c2 100644 --- a/unity-shared/EMConverter.h +++ b/unity-shared/EMConverter.h @@ -30,31 +30,16 @@ class EMConverter public: typedef std::shared_ptr<EMConverter> Ptr; - EMConverter(int font_size = 0, double dpi = 96.0); + EMConverter(double dpi = 96.0); - bool SetFontSize(int font_size); bool SetDPI(double dpi); - - int GetFontSize() const; double GetDPI() const; double CP(int pixels) const; double DPIScale() const; - double PtToPx(int pt); - private: - void UpdatePixelsPerEM(); - void UpdateBasePixelsPerEM(); - - double EMToPixels(double em) const; - double PixelsToBaseEM(int pixels) const; - - double pixels_per_em_; - double base_pixels_per_em_; - double dpi_; - int font_size_; }; } // namespace unity diff --git a/unity-shared/UnitySettings.cpp b/unity-shared/UnitySettings.cpp index cf3f557d9..96b014b8f 100644 --- a/unity-shared/UnitySettings.cpp +++ b/unity-shared/UnitySettings.cpp @@ -62,13 +62,12 @@ const std::string COMPIZ_SETTINGS = "org.compiz"; const std::string COMPIZ_PROFILE = "current-profile"; const std::string UBUNTU_UI_SETTINGS = "com.ubuntu.user-interface"; +const std::string UBUNTU_DESKTOP_UI_SETTINGS = "com.ubuntu.user-interface.desktop"; const std::string SCALE_FACTOR = "scale-factor"; -const std::string GNOME_UI_SETTINGS = "org.gnome.desktop.interface"; -const std::string GNOME_FONT_NAME = "font-name"; -const std::string GNOME_CURSOR_SIZE = "cursor-size"; -const std::string GNOME_SCALE_FACTOR = "scaling-factor"; -const std::string GNOME_TEXT_SCALE_FACTOR = "text-scaling-factor"; +const std::string DESKTOP_CURSOR_SIZE = "cursor-size"; +const std::string DESKTOP_SCALE_FACTOR = "scaling-factor"; +const std::string DESKTOP_TEXT_SCALE_FACTOR = "text-scaling-factor"; const std::string REMOTE_CONTENT_SETTINGS = "com.canonical.Unity.Lenses"; const std::string REMOTE_CONTENT_KEY = "remote-content-search"; @@ -84,7 +83,7 @@ const std::string CCS_PROFILE_LOWGFX = CCS_PROFILE_DEFAULT + "-lowgfx"; const int DEFAULT_LAUNCHER_SIZE = 64; const int MINIMUM_DESKTOP_HEIGHT = 800; -const int GNOME_SETTINGS_CHANGED_WAIT_SECONDS = 1; +const int DESKTOP_SETTINGS_CHANGED_WAIT_SECONDS = 1; const double DEFAULT_DPI = 96.0f; const double DPI_SCALING_LIMIT = 140.0f; const int DPI_SCALING_STEP = 8; @@ -105,7 +104,7 @@ public: , gestures_settings_(g_settings_new(GESTURES_SETTINGS.c_str())) , ui_settings_(g_settings_new(UI_SETTINGS.c_str())) , ubuntu_ui_settings_(g_settings_new(UBUNTU_UI_SETTINGS.c_str())) - , gnome_ui_settings_(g_settings_new(GNOME_UI_SETTINGS.c_str())) + , desktop_ui_settings_(g_settings_new(UBUNTU_DESKTOP_UI_SETTINGS.c_str())) , remote_content_settings_(g_settings_new(REMOTE_CONTENT_SETTINGS.c_str())) , launcher_sizes_(monitors::MAX, DEFAULT_LAUNCHER_SIZE) , cached_launcher_position_(LauncherPosition::LEFT) @@ -174,13 +173,8 @@ public: UpdateDPI(); }); - signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_FONT_NAME, [this] (GSettings*, const gchar* t) { - UpdateFontSize(); - UpdateDPI(); - }); - - signals_.Add<void, GSettings*, const gchar*>(gnome_ui_settings_, "changed::" + GNOME_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { - double new_scale_factor = g_settings_get_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str()); + signals_.Add<void, GSettings*, const gchar*>(desktop_ui_settings_, "changed::" + DESKTOP_TEXT_SCALE_FACTOR, [this] (GSettings*, const gchar* t) { + double new_scale_factor = g_settings_get_double(desktop_ui_settings_, DESKTOP_TEXT_SCALE_FACTOR.c_str()); g_settings_set_double(ui_settings_, TEXT_SCALE_FACTOR.c_str(), new_scale_factor); }); @@ -203,7 +197,6 @@ public: UpdateGesturesSetting(); UpdateTextScaleFactor(); UpdateCursorScaleFactor(); - UpdateFontSize(); UpdateDPI(); CacheFormFactor(); @@ -365,27 +358,6 @@ public: return g_settings_get_boolean(usettings_, PAM_CHECK_ACCOUNT_TYPE.c_str()); } - int GetFontSize() const - { - gint font_size; - PangoFontDescription* desc; - - glib::String font_name(g_settings_get_string(gnome_ui_settings_, GNOME_FONT_NAME.c_str())); - desc = pango_font_description_from_string(font_name); - font_size = pango_font_description_get_size(desc); - pango_font_description_free(desc); - - return font_size / 1024; - } - - void UpdateFontSize() - { - int font_size = GetFontSize(); - - for (auto const& em : em_converters_) - em->SetFontSize(font_size); - } - void UpdateTextScaleFactor() { parent_->font_scaling = g_settings_get_double(ui_settings_, TEXT_SCALE_FACTOR.c_str()); @@ -505,18 +477,18 @@ public: void UpdateAppsScaling(double scale) { - signals_.Block(gnome_ui_settings_); + signals_.Block(desktop_ui_settings_); unsigned integer_scaling = std::max<unsigned>(1, std::lround(scale)); double point_scaling = scale / static_cast<double>(integer_scaling); double text_scale_factor = parent_->font_scaling() * point_scaling; - glib::Variant default_cursor_size(g_settings_get_default_value(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str()), glib::StealRef()); + glib::Variant default_cursor_size(g_settings_get_default_value(desktop_ui_settings_, DESKTOP_CURSOR_SIZE.c_str()), glib::StealRef()); int cursor_size = std::round(default_cursor_size.GetInt32() * point_scaling * cursor_scale_); - g_settings_set_int(gnome_ui_settings_, GNOME_CURSOR_SIZE.c_str(), cursor_size); - g_settings_set_uint(gnome_ui_settings_, GNOME_SCALE_FACTOR.c_str(), integer_scaling); - g_settings_set_double(gnome_ui_settings_, GNOME_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); + g_settings_set_int(desktop_ui_settings_, DESKTOP_CURSOR_SIZE.c_str(), cursor_size); + g_settings_set_uint(desktop_ui_settings_, DESKTOP_SCALE_FACTOR.c_str(), integer_scaling); + g_settings_set_double(desktop_ui_settings_, DESKTOP_TEXT_SCALE_FACTOR.c_str(), text_scale_factor); - changing_gnome_settings_timeout_.reset(new glib::TimeoutSeconds(GNOME_SETTINGS_CHANGED_WAIT_SECONDS, [this] { - signals_.Unblock(gnome_ui_settings_); + changing_desktop_settings_timeout_.reset(new glib::TimeoutSeconds(DESKTOP_SETTINGS_CHANGED_WAIT_SECONDS, [this] { + signals_.Unblock(desktop_ui_settings_); return false; }, glib::Source::Priority::LOW)); } @@ -546,9 +518,9 @@ public: glib::Object<GSettings> gestures_settings_; glib::Object<GSettings> ui_settings_; glib::Object<GSettings> ubuntu_ui_settings_; - glib::Object<GSettings> gnome_ui_settings_; + glib::Object<GSettings> desktop_ui_settings_; glib::Object<GSettings> remote_content_settings_; - glib::Source::UniquePtr changing_gnome_settings_timeout_; + glib::Source::UniquePtr changing_desktop_settings_timeout_; glib::SignalManager signals_; std::vector<EMConverter::Ptr> em_converters_; std::vector<int> launcher_sizes_; |
