Merge lp:~3v1n0/unity/theme-settings into lp:unity
- theme-settings
- Merge into trunk
Status: | Merged |
---|---|
Approved by: | Marco Trevisan (Treviño) |
Approved revision: | no longer in the source branch. |
Merged at revision: | 4082 |
Proposed branch: | lp:~3v1n0/unity/theme-settings |
Merge into: | lp:unity |
Diff against target: |
2261 lines (+633/-426) 40 files modified
UnityCore/DesktopUtilities.cpp (+8/-3) UnityCore/DesktopUtilities.h (+1/-0) dash/FilterBasicButton.cpp (+1/-0) dash/ResultRendererTile.cpp (+2/-4) decorations/DecorationsForceQuitDialog.cpp (+3/-3) decorations/DecorationsMenuDropdown.cpp (+2/-0) decorations/DecorationsMenuEntry.cpp (+8/-4) launcher/BFBLauncherIcon.cpp (+8/-2) launcher/BFBLauncherIcon.h (+1/-0) launcher/ExpoLauncherIcon.h (+2/-0) launcher/LauncherIcon.cpp (+4/-49) launcher/LauncherIcon.h (+0/-9) launcher/QuicklistMenuItem.cpp (+3/-5) launcher/SimpleLauncherIcon.cpp (+2/-5) launcher/SimpleLauncherIcon.h (+0/-3) panel/PanelIndicatorEntryView.cpp (+6/-9) panel/PanelIndicatorEntryView.h (+0/-2) resources/dash-widgets.json (+51/-26) unity-shared/CMakeLists.txt (+1/-0) unity-shared/DashStyle.cpp (+94/-72) unity-shared/DashStyle.h (+10/-3) unity-shared/DecorationStyle.cpp (+22/-72) unity-shared/DecorationStyle.h (+3/-3) unity-shared/FontSettings.cpp (+39/-51) unity-shared/FontSettings.h (+6/-6) unity-shared/GtkUtils.h (+73/-0) unity-shared/IconLoader.cpp (+8/-10) unity-shared/IconRenderer.cpp (+5/-5) unity-shared/JSONParser.h (+2/-2) unity-shared/PanelStyle.cpp (+1/-1) unity-shared/PlacesOverlayVScrollBar.cpp (+16/-16) unity-shared/PlacesVScrollBar.cpp (+15/-17) unity-shared/PlacesVScrollBar.h (+1/-1) unity-shared/SearchBar.cpp (+10/-16) unity-shared/SearchBar.h (+1/-1) unity-shared/StaticCairoText.cpp (+9/-11) unity-shared/TextInput.cpp (+8/-14) unity-shared/TextInput.h (+1/-1) unity-shared/ThemeSettings.cpp (+145/-0) unity-shared/ThemeSettings.h (+61/-0) |
To merge this branch: | bzr merge lp:~3v1n0/unity/theme-settings |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Approve | |
Andrea Azzarone (community) | Approve | ||
Review via email: mp+286343@code.launchpad.net |
Commit message
ThemeSettings: add small class for reading gtk settings for theming
Implemented through a new GtkUtils class which includes some functions
and classes to handle Gtk elements.
The ThemeSettings utility class allows to read settings and being notified when
these changes. All in a single place. It also includes some methods
As bonus, some improvements to the dash theming (dash-widgets.json is now
themable and supports new scrollbars as well), and BFB icon can be overridden
as well.
More infos at: https:/
Description of the change
PS Jenkins bot (ps-jenkins) wrote : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:4099
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Andrea Azzarone (azzar1) wrote : | # |
Please see the comment about the virtual dtor. The rest looks good to me.
Andrea Azzarone (azzar1) : | # |
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:4101
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
FAILED: Continuous integration, rev:4102
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:4103
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild:
http://
Preview Diff
1 | === modified file 'UnityCore/DesktopUtilities.cpp' |
2 | --- UnityCore/DesktopUtilities.cpp 2015-11-25 23:40:26 +0000 |
3 | +++ UnityCore/DesktopUtilities.cpp 2016-02-25 15:59:57 +0000 |
4 | @@ -35,6 +35,11 @@ |
5 | DECLARE_LOGGER(logger, "unity.desktop.utilities"); |
6 | } |
7 | |
8 | +std::string DesktopUtilities::GetUserHomeDirectory() |
9 | +{ |
10 | + return glib::gchar_to_string(g_get_home_dir()); |
11 | +} |
12 | + |
13 | std::string DesktopUtilities::GetUserDataDirectory() |
14 | { |
15 | const char* user_dir = g_get_user_data_dir(); |
16 | @@ -43,12 +48,12 @@ |
17 | return user_dir; |
18 | |
19 | // This shouldn't ever happen, but let's manually fallback to the default |
20 | - const char* home = g_get_home_dir(); |
21 | + auto home = GetUserHomeDirectory(); |
22 | |
23 | - if (home) |
24 | + if (!home.empty()) |
25 | { |
26 | const char* subdir = G_DIR_SEPARATOR_S ".local" G_DIR_SEPARATOR_S "share"; |
27 | - return std::string(home).append(subdir); |
28 | + return home.append(subdir); |
29 | } |
30 | |
31 | return ""; |
32 | |
33 | === modified file 'UnityCore/DesktopUtilities.h' |
34 | --- UnityCore/DesktopUtilities.h 2015-11-25 23:40:26 +0000 |
35 | +++ UnityCore/DesktopUtilities.h 2016-02-25 15:59:57 +0000 |
36 | @@ -29,6 +29,7 @@ |
37 | class DesktopUtilities |
38 | { |
39 | public: |
40 | + static std::string GetUserHomeDirectory(); |
41 | static std::string GetUserDataDirectory(); |
42 | static std::string GetUserCacheDirectory(); |
43 | static std::string GetUserRuntimeDirectory(); |
44 | |
45 | === modified file 'dash/FilterBasicButton.cpp' |
46 | --- dash/FilterBasicButton.cpp 2015-05-08 04:24:43 +0000 |
47 | +++ dash/FilterBasicButton.cpp 2016-02-25 15:59:57 +0000 |
48 | @@ -72,6 +72,7 @@ |
49 | |
50 | scale.changed.connect(sigc::mem_fun(this, &FilterBasicButton::UpdateScale)); |
51 | Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &FilterBasicButton::InitTheme))); |
52 | + Style::Instance().changed.connect(sigc::mem_fun(this, &FilterBasicButton::InitTheme)); |
53 | } |
54 | |
55 | void FilterBasicButton::InitTheme() |
56 | |
57 | === modified file 'dash/ResultRendererTile.cpp' |
58 | --- dash/ResultRendererTile.cpp 2015-10-03 01:08:12 +0000 |
59 | +++ dash/ResultRendererTile.cpp 2016-02-25 15:59:57 +0000 |
60 | @@ -32,6 +32,7 @@ |
61 | #include "unity-shared/DashStyle.h" |
62 | #include "unity-shared/TextureCache.h" |
63 | #include "unity-shared/UnitySettings.h" |
64 | +#include "unity-shared/ThemeSettings.h" |
65 | |
66 | namespace unity |
67 | { |
68 | @@ -465,13 +466,10 @@ |
69 | PangoFontDescription* desc = NULL; |
70 | PangoContext* pango_context = NULL; |
71 | GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
72 | - glib::String font; |
73 | - |
74 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font, NULL); |
75 | |
76 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
77 | layout = pango_cairo_create_layout(cr); |
78 | - desc = pango_font_description_from_string(font.Value()); |
79 | + desc = pango_font_description_from_string(theme::Settings::Get()->font().c_str()); |
80 | pango_font_description_set_size (desc, FONT_SIZE * FONT_MULTIPLIER); |
81 | |
82 | pango_layout_set_font_description(layout, desc); |
83 | |
84 | === modified file 'decorations/DecorationsForceQuitDialog.cpp' |
85 | --- decorations/DecorationsForceQuitDialog.cpp 2015-07-01 01:24:59 +0000 |
86 | +++ decorations/DecorationsForceQuitDialog.cpp 2016-02-25 15:59:57 +0000 |
87 | @@ -385,7 +385,7 @@ |
88 | gtk_widget_set_can_focus(self, FALSE); |
89 | gtk_widget_set_halign(self, GTK_ALIGN_START); |
90 | |
91 | - auto const& file = decoration::Style::Get()->ThemedFilePath(CLOSE_BUTTON_INACTIVE_FILE, {PKGDATADIR"/"}); |
92 | + auto const& file = decoration::Style::Get()->ThemedFilePath(CLOSE_BUTTON_INACTIVE_FILE, {PKGDATADIR}); |
93 | auto* img = gtk_image_new_from_file(file.c_str()); |
94 | gtk_container_add(GTK_CONTAINER(self), img); |
95 | CLOSE_BUTTON(self)->priv->img = GTK_IMAGE(img); |
96 | @@ -419,13 +419,13 @@ |
97 | |
98 | auto new_flags = gtk_widget_get_state_flags(self); |
99 | auto const& deco_style = decoration::Style::Get(); |
100 | - auto file = deco_style->ThemedFilePath(CLOSE_BUTTON_INACTIVE_FILE, {PKGDATADIR"/"}); |
101 | + auto file = deco_style->ThemedFilePath(CLOSE_BUTTON_INACTIVE_FILE, {PKGDATADIR}); |
102 | |
103 | if (((new_flags & GTK_STATE_FLAG_PRELIGHT) && !gtk_widget_get_can_focus(self)) || |
104 | (new_flags & GTK_STATE_FLAG_FOCUSED)) |
105 | { |
106 | auto const& basename = (new_flags & GTK_STATE_FLAG_ACTIVE) ? CLOSE_BUTTON_ACTIVE_FILE : CLOSE_BUTTON_FOCUSED_FILE; |
107 | - file = deco_style->ThemedFilePath(basename, {PKGDATADIR"/"}); |
108 | + file = deco_style->ThemedFilePath(basename, {PKGDATADIR}); |
109 | } |
110 | |
111 | gtk_image_set_from_file(img, file.c_str()); |
112 | |
113 | === modified file 'decorations/DecorationsMenuDropdown.cpp' |
114 | --- decorations/DecorationsMenuDropdown.cpp 2015-02-02 12:30:49 +0000 |
115 | +++ decorations/DecorationsMenuDropdown.cpp 2016-02-25 15:59:57 +0000 |
116 | @@ -19,6 +19,7 @@ |
117 | |
118 | #include "DecorationsMenuDropdown.h" |
119 | #include "DecorationStyle.h" |
120 | +#include "unity-shared/ThemeSettings.h" |
121 | |
122 | namespace unity |
123 | { |
124 | @@ -39,6 +40,7 @@ |
125 | natural_.width = ICON_SIZE; |
126 | natural_.height = ICON_SIZE; |
127 | entry_->set_image(1, ICON_NAME, true, true); |
128 | + theme::Settings::Get()->icons_changed.connect(sigc::mem_fun(this, &MenuDropdown::RenderTexture)); |
129 | } |
130 | |
131 | void MenuDropdown::ShowMenu(unsigned button) |
132 | |
133 | === modified file 'decorations/DecorationsMenuEntry.cpp' |
134 | --- decorations/DecorationsMenuEntry.cpp 2015-02-03 12:32:06 +0000 |
135 | +++ decorations/DecorationsMenuEntry.cpp 2016-02-25 15:59:57 +0000 |
136 | @@ -40,11 +40,15 @@ |
137 | , show_menu_enabled_(true) |
138 | { |
139 | entry_->updated.connect(sigc::mem_fun(this, &MenuEntry::EntryUpdated)); |
140 | - horizontal_padding.changed.connect(sigc::hide(sigc::mem_fun(this, &MenuEntry::RenderTexture))); |
141 | - vertical_padding.changed.connect(sigc::hide(sigc::mem_fun(this, &MenuEntry::RenderTexture))); |
142 | - scale.changed.connect(sigc::hide(sigc::mem_fun(this, &MenuEntry::RenderTexture))); |
143 | - focused.changed.connect(sigc::hide(sigc::mem_fun(this, &MenuEntry::RenderTexture))); |
144 | in_dropdown.changed.connect([this] (bool in) { visible = entry_->visible() && !in; }); |
145 | + |
146 | + auto render_texture_cb = sigc::hide(sigc::mem_fun(this, &MenuEntry::RenderTexture)); |
147 | + horizontal_padding.changed.connect(render_texture_cb); |
148 | + vertical_padding.changed.connect(render_texture_cb); |
149 | + scale.changed.connect(render_texture_cb); |
150 | + focused.changed.connect(render_texture_cb); |
151 | + Style::Get()->font.changed.connect(render_texture_cb); |
152 | + |
153 | EntryUpdated(); |
154 | } |
155 | |
156 | |
157 | === modified file 'launcher/BFBLauncherIcon.cpp' |
158 | --- launcher/BFBLauncherIcon.cpp 2015-05-22 13:20:22 +0000 |
159 | +++ launcher/BFBLauncherIcon.cpp 2016-02-25 15:59:57 +0000 |
160 | @@ -21,6 +21,7 @@ |
161 | #include "config.h" |
162 | #include <glib/gi18n-lib.h> |
163 | #include "unity-shared/UBusMessages.h" |
164 | +#include "unity-shared/ThemeSettings.h" |
165 | #include "unity-shared/UnitySettings.h" |
166 | |
167 | #include "BFBLauncherIcon.h" |
168 | @@ -35,15 +36,15 @@ |
169 | , reader_(dash::GSettingsScopesReader::GetDefault()) |
170 | , launcher_hide_mode_(hide_mode) |
171 | { |
172 | - icon_name = PKGDATADIR"/launcher_bfb.png"; |
173 | position = Position::BEGIN; |
174 | SetQuirk(Quirk::VISIBLE, true); |
175 | SkipQuirkAnimation(Quirk::VISIBLE); |
176 | - |
177 | background_color_ = nux::color::White; |
178 | |
179 | + UpdateIcon(); |
180 | UpdateDefaultSearchText(); |
181 | |
182 | + theme::Settings::Get()->theme.changed.connect(sigc::hide(sigc::mem_fun(this, &BFBLauncherIcon::UpdateIcon))); |
183 | Settings::Instance().remote_content.changed.connect(sigc::hide(sigc::mem_fun(this, &BFBLauncherIcon::UpdateDefaultSearchText))); |
184 | |
185 | mouse_enter.connect([this](int m) { ubus_manager_.SendMessage(UBUS_DASH_ABOUT_TO_SHOW, NULL); }); |
186 | @@ -51,6 +52,11 @@ |
187 | ubus_manager_.RegisterInterest(UBUS_OVERLAY_HIDDEN, sigc::bind(sigc::mem_fun(this, &BFBLauncherIcon::OnOverlayShown), false)); |
188 | } |
189 | |
190 | +void BFBLauncherIcon::UpdateIcon() |
191 | +{ |
192 | + icon_name = theme::Settings::Get()->ThemedFilePath("launcher_bfb", {PKGDATADIR}); |
193 | +} |
194 | + |
195 | void BFBLauncherIcon::SetHideMode(LauncherHideMode hide_mode) |
196 | { |
197 | launcher_hide_mode_ = hide_mode; |
198 | |
199 | === modified file 'launcher/BFBLauncherIcon.h' |
200 | --- launcher/BFBLauncherIcon.h 2015-04-23 14:57:38 +0000 |
201 | +++ launcher/BFBLauncherIcon.h 2016-02-25 15:59:57 +0000 |
202 | @@ -53,6 +53,7 @@ |
203 | void OnOverlayShown(GVariant *data, bool visible); |
204 | void OnMenuitemActivated(DbusmenuMenuitem* item, int time, std::string const& scope_id); |
205 | void UpdateDefaultSearchText(); |
206 | + void UpdateIcon(); |
207 | |
208 | nux::Color background_color_; |
209 | dash::GSettingsScopesReader::Ptr reader_; |
210 | |
211 | === modified file 'launcher/ExpoLauncherIcon.h' |
212 | --- launcher/ExpoLauncherIcon.h 2015-11-20 11:35:08 +0000 |
213 | +++ launcher/ExpoLauncherIcon.h 2016-02-25 15:59:57 +0000 |
214 | @@ -20,6 +20,8 @@ |
215 | #ifndef EXPO_LAUNCHER_ICON_H |
216 | #define EXPO_LAUNCHER_ICON_H |
217 | |
218 | +#include <UnityCore/GLibSignal.h> |
219 | + |
220 | #include "SimpleLauncherIcon.h" |
221 | |
222 | namespace unity |
223 | |
224 | === modified file 'launcher/LauncherIcon.cpp' |
225 | --- launcher/LauncherIcon.cpp 2016-02-19 12:36:57 +0000 |
226 | +++ launcher/LauncherIcon.cpp 2016-02-25 15:59:57 +0000 |
227 | @@ -26,6 +26,7 @@ |
228 | #include "LauncherIcon.h" |
229 | #include "unity-shared/AnimationUtils.h" |
230 | #include "unity-shared/CairoTexture.h" |
231 | +#include "unity-shared/ThemeSettings.h" |
232 | #include "unity-shared/UnitySettings.h" |
233 | #include "unity-shared/UScreen.h" |
234 | |
235 | @@ -52,8 +53,6 @@ |
236 | const int IGNORE_REPEAT_SHORTCUT_DURATION = 250; |
237 | |
238 | const std::string DEFAULT_ICON = "application-default-icon"; |
239 | -const std::string MONO_TEST_ICON = "gnome-home"; |
240 | -const std::string UNITY_THEME_NAME = "unity-icon-theme"; |
241 | |
242 | const std::string CENTER_STABILIZE_TIMEOUT = "center-stabilize-timeout"; |
243 | const std::string PRESENT_TIMEOUT = "present-timeout"; |
244 | @@ -65,9 +64,6 @@ |
245 | |
246 | NUX_IMPLEMENT_OBJECT_TYPE(LauncherIcon); |
247 | |
248 | -int LauncherIcon::_current_theme_is_mono = -1; |
249 | -glib::Object<GtkIconTheme> LauncherIcon::_unity_theme; |
250 | - |
251 | LauncherIcon::LauncherIcon(IconType type) |
252 | : _icon_type(type) |
253 | , _sticky(false) |
254 | @@ -325,46 +321,6 @@ |
255 | glow = nux::Color(nux::color::RedGreenBlue(hsv)); |
256 | } |
257 | |
258 | -/* |
259 | - * FIXME, all this code (and below), should be put in a facility for IconLoader |
260 | - * to share between launcher and places the same Icon loading logic and not look |
261 | - * having etoomanyimplementationofsamethings. |
262 | - */ |
263 | -/* static */ |
264 | -bool LauncherIcon::IsMonoDefaultTheme() |
265 | -{ |
266 | - if (_current_theme_is_mono != -1) |
267 | - return (bool)_current_theme_is_mono; |
268 | - |
269 | - GtkIconTheme* default_theme; |
270 | - glib::Object<GtkIconInfo> info; |
271 | - default_theme = gtk_icon_theme_get_default(); |
272 | - |
273 | - _current_theme_is_mono = (int)false; |
274 | - info = gtk_icon_theme_lookup_icon(default_theme, MONO_TEST_ICON.c_str(), icon_size(), GTK_ICON_LOOKUP_FORCE_SIZE); |
275 | - |
276 | - if (!info) |
277 | - return (bool)_current_theme_is_mono; |
278 | - |
279 | - // yeah, it's evil, but it's blessed upstream |
280 | - if (g_strrstr(gtk_icon_info_get_filename(info), "ubuntu-mono") != NULL) |
281 | - _current_theme_is_mono = (int)true; |
282 | - |
283 | - return (bool)_current_theme_is_mono; |
284 | -} |
285 | - |
286 | -GtkIconTheme* LauncherIcon::GetUnityTheme() |
287 | -{ |
288 | - // The theme object is invalid as soon as you add a new icon to change the theme. |
289 | - // invalidate the cache then and rebuild the theme the first time after a icon theme update. |
290 | - if (!_unity_theme.IsType(GTK_TYPE_ICON_THEME)) |
291 | - { |
292 | - _unity_theme = gtk_icon_theme_new(); |
293 | - gtk_icon_theme_set_custom_theme(_unity_theme, UNITY_THEME_NAME.c_str()); |
294 | - } |
295 | - return _unity_theme; |
296 | -} |
297 | - |
298 | BaseTexturePtr LauncherIcon::TextureFromPixbuf(GdkPixbuf* pixbuf, int size, bool update_glow_colors) |
299 | { |
300 | g_return_val_if_fail(GDK_IS_PIXBUF(pixbuf), BaseTexturePtr()); |
301 | @@ -391,7 +347,7 @@ |
302 | result = TextureFromSpecificGtkTheme(default_theme, icon_name, size, update_glow_colors); |
303 | |
304 | if (!result) |
305 | - result = TextureFromSpecificGtkTheme(GetUnityTheme(), icon_name, size, update_glow_colors); |
306 | + result = TextureFromSpecificGtkTheme(theme::Settings::Get()->UnityIconTheme(), icon_name, size, update_glow_colors); |
307 | |
308 | if (!result) |
309 | result = TextureFromSpecificGtkTheme(default_theme, icon_name, size, update_glow_colors, true); |
310 | @@ -1068,9 +1024,8 @@ |
311 | glib::Object<PangoContext> pango_ctx(gdk_pango_context_get()); |
312 | glib::Object<PangoLayout> layout(pango_layout_new(pango_ctx)); |
313 | |
314 | - glib::String font_name; |
315 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, nullptr); |
316 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); |
317 | + auto const& font = theme::Settings::Get()->font(); |
318 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); |
319 | int font_size = pango_units_from_double(Settings::Instance().font_scaling() * COUNT_FONT_SIZE); |
320 | pango_font_description_set_absolute_size(desc.get(), font_size); |
321 | pango_layout_set_font_description(layout, desc.get()); |
322 | |
323 | === modified file 'launcher/LauncherIcon.h' |
324 | --- launcher/LauncherIcon.h 2016-02-19 12:36:57 +0000 |
325 | +++ launcher/LauncherIcon.h 2016-02-25 15:59:57 +0000 |
326 | @@ -277,10 +277,6 @@ |
327 | |
328 | BaseTexturePtr TextureFromPath(std::string const& name, int size, bool update_glow_colors = true); |
329 | |
330 | - static bool IsMonoDefaultTheme(); |
331 | - |
332 | - GtkIconTheme* GetUnityTheme(); |
333 | - |
334 | void OnRemoteEmblemChanged(LauncherEntryRemote* remote); |
335 | |
336 | void OnRemoteCountChanged(LauncherEntryRemote* remote); |
337 | @@ -309,9 +305,6 @@ |
338 | return *_quirk_animations[monitor][unsigned(quirk)]; |
339 | } |
340 | |
341 | - // This looks like a case for boost::logical::tribool |
342 | - static int _current_theme_is_mono; |
343 | - |
344 | private: |
345 | IconType _icon_type; |
346 | |
347 | @@ -357,8 +350,6 @@ |
348 | connection::Manager _remote_connections; |
349 | glib::Object<DbusmenuClient> _remote_menus; |
350 | |
351 | - static glib::Object<GtkIconTheme> _unity_theme; |
352 | - |
353 | protected: |
354 | glib::SourceManager _source_manager; |
355 | }; |
356 | |
357 | === modified file 'launcher/QuicklistMenuItem.cpp' |
358 | --- launcher/QuicklistMenuItem.cpp 2014-04-09 13:04:13 +0000 |
359 | +++ launcher/QuicklistMenuItem.cpp 2016-02-25 15:59:57 +0000 |
360 | @@ -20,6 +20,7 @@ |
361 | */ |
362 | |
363 | #include <gtk/gtk.h> |
364 | +#include "unity-shared/ThemeSettings.h" |
365 | #include "unity-shared/UBusWrapper.h" |
366 | #include "unity-shared/UBusMessages.h" |
367 | #include "unity-shared/UnitySettings.h" |
368 | @@ -291,10 +292,7 @@ |
369 | return; |
370 | |
371 | GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
372 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
373 | - |
374 | - glib::String font_name; |
375 | - g_object_get(settings, "gtk-font-name", &font_name, nullptr); |
376 | + auto const& font = theme::Settings::Get()->font(); |
377 | |
378 | cairo_t* cr = cairo.GetInternalContext(); |
379 | cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE); |
380 | @@ -302,7 +300,7 @@ |
381 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
382 | |
383 | glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); |
384 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); |
385 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); |
386 | pango_layout_set_font_description(layout, desc.get()); |
387 | pango_layout_set_height(layout, -1); |
388 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
389 | |
390 | === modified file 'launcher/SimpleLauncherIcon.cpp' |
391 | --- launcher/SimpleLauncherIcon.cpp 2016-02-19 12:11:52 +0000 |
392 | +++ launcher/SimpleLauncherIcon.cpp 2016-02-25 15:59:57 +0000 |
393 | @@ -22,6 +22,7 @@ |
394 | |
395 | #include "SimpleLauncherIcon.h" |
396 | |
397 | +#include "unity-shared/ThemeSettings.h" |
398 | #include "unity-shared/UBusWrapper.h" |
399 | #include "unity-shared/UBusMessages.h" |
400 | |
401 | @@ -36,11 +37,7 @@ |
402 | , icon_name("", sigc::mem_fun(this, &SimpleLauncherIcon::SetIconName)) |
403 | , icon_pixbuf(glib::Object<GdkPixbuf>(), sigc::mem_fun(this, &SimpleLauncherIcon::SetIconPixbuf)) |
404 | { |
405 | - auto* theme = gtk_icon_theme_get_default(); |
406 | - theme_changed_signal_.Connect(theme, "changed", [this] (GtkIconTheme *) { |
407 | - _current_theme_is_mono = -1; |
408 | - ReloadIcon(); |
409 | - }); |
410 | + theme::Settings::Get()->icons_changed.connect(sigc::mem_fun(this, &SimpleLauncherIcon::ReloadIcon)); |
411 | } |
412 | |
413 | void SimpleLauncherIcon::ActivateLauncherIcon(ActionArg arg) |
414 | |
415 | === modified file 'launcher/SimpleLauncherIcon.h' |
416 | --- launcher/SimpleLauncherIcon.h 2016-02-19 12:11:52 +0000 |
417 | +++ launcher/SimpleLauncherIcon.h 2016-02-25 15:59:57 +0000 |
418 | @@ -20,7 +20,6 @@ |
419 | #ifndef UNITYSHELL_SIMPLELAUNCHERICON_H |
420 | #define UNITYSHELL_SIMPLELAUNCHERICON_H |
421 | |
422 | -#include <UnityCore/GLibSignal.h> |
423 | #include "LauncherIcon.h" |
424 | |
425 | namespace unity |
426 | @@ -54,11 +53,9 @@ |
427 | |
428 | private: |
429 | std::unordered_map<int, BaseTexturePtr> texture_map_; |
430 | - glib::Signal<void, GtkIconTheme*> theme_changed_signal_; |
431 | }; |
432 | |
433 | } |
434 | } |
435 | |
436 | #endif // SIMPLELAUNCHERICON_H |
437 | - |
438 | |
439 | === modified file 'panel/PanelIndicatorEntryView.cpp' |
440 | --- panel/PanelIndicatorEntryView.cpp 2015-12-18 00:00:23 +0000 |
441 | +++ panel/PanelIndicatorEntryView.cpp 2016-02-25 15:59:57 +0000 |
442 | @@ -32,6 +32,7 @@ |
443 | #include "unity-shared/PanelStyle.h" |
444 | #include "unity-shared/RawPixel.h" |
445 | #include "unity-shared/WindowManager.h" |
446 | +#include "unity-shared/ThemeSettings.h" |
447 | #include "unity-shared/UnitySettings.h" |
448 | |
449 | namespace unity |
450 | @@ -72,16 +73,12 @@ |
451 | InputArea::mouse_wheel.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::OnMouseWheel)); |
452 | } |
453 | |
454 | + auto refresh_cb = sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh); |
455 | + panel::Style::Instance().changed.connect(refresh_cb); |
456 | + unity::Settings::Instance().dpi_changed.connect(refresh_cb); |
457 | + |
458 | if (type_ != MENU) |
459 | - { |
460 | - icon_theme_changed_.Connect(gtk_icon_theme_get_default(), "changed", [this] (GtkIconTheme*) { |
461 | - if (proxy_->image_type() && proxy_->image_visible()) |
462 | - Refresh(); |
463 | - }); |
464 | - } |
465 | - |
466 | - panel::Style::Instance().changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); |
467 | - unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &PanelIndicatorEntryView::Refresh)); |
468 | + theme::Settings::Get()->icons_changed.connect(refresh_cb); |
469 | |
470 | Refresh(); |
471 | } |
472 | |
473 | === modified file 'panel/PanelIndicatorEntryView.h' |
474 | --- panel/PanelIndicatorEntryView.h 2015-02-04 09:46:19 +0000 |
475 | +++ panel/PanelIndicatorEntryView.h 2016-02-25 15:59:57 +0000 |
476 | @@ -28,7 +28,6 @@ |
477 | |
478 | #include <UnityCore/IndicatorEntry.h> |
479 | #include <UnityCore/GLibWrapper.h> |
480 | -#include <UnityCore/GLibSignal.h> |
481 | |
482 | #include <gtk/gtk.h> |
483 | |
484 | @@ -119,7 +118,6 @@ |
485 | IndicatorEntryType type_; |
486 | nux::ObjectPtr<nux::BaseTexture> entry_texture_; |
487 | nux::Geometry cached_geo_; |
488 | - glib::Signal<void, GtkIconTheme*> icon_theme_changed_; |
489 | int monitor_; |
490 | double opacity_; |
491 | bool draw_active_; |
492 | |
493 | === modified file 'resources/dash-widgets.json' |
494 | --- resources/dash-widgets.json 2012-03-14 06:24:18 +0000 |
495 | +++ resources/dash-widgets.json 2016-02-25 15:59:57 +0000 |
496 | @@ -9,53 +9,62 @@ |
497 | "bag" : ["/usr/share/icons/unity/bag.svg", "32px", "32px"], |
498 | "next" : ["/usr/share/icons/unity/next.svg", "32px", "32px"], |
499 | "prev" : ["/usr/share/icons/unity/prev.svg", "32px", "32px"], |
500 | - "play" : ["/usr/share/icons/unity/play.svg", "32px", "32px"]}, |
501 | + "play" : ["/usr/share/icons/unity/play.svg", "32px", "32px"] |
502 | + }, |
503 | |
504 | "regular-text" : { |
505 | "text-color" : "#ffffff", |
506 | - "text-opacity" : 1.0, |
507 | + "text-opacity" : 1.0, |
508 | "text-size" : 13.0, |
509 | "text-mode" : "normal", |
510 | - "text-weight" : "regular"}, |
511 | + "text-weight" : "regular" |
512 | + }, |
513 | |
514 | "comments": { |
515 | - "states" : ["ACTIVE", "NORMAL","PRELIGHT","SELECTED","INSENSITIVE"]}, |
516 | + "states" : ["ACTIVE", "NORMAL","PRELIGHT","SELECTED","INSENSITIVE"] |
517 | + }, |
518 | |
519 | "button-icon": { |
520 | "color" : ["#ffffff", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"], |
521 | "opacity" : [ 1.0, 1.0, 1.0, 0.8, 0.8], |
522 | "overlay-opacity": [ 0.30, 0.48, 0.48, 0.45, 0.45], |
523 | "overlay-mode" : [ "normal","multiply", "multiply", "normal", "normal"], |
524 | - "blur-size" : [ 5, 0, 0, 0, 0]}, |
525 | + "blur-size" : [ 5, 0, 0, 0, 0] |
526 | + }, |
527 | |
528 | "icon-only" : { |
529 | "color" : "#123456", |
530 | "opacity" : 1.0, |
531 | "overlay-opacity": 0.2, |
532 | "overlay-mode" : "normal", |
533 | - "blur-size" : 6}, |
534 | + "blur-size" : 6 |
535 | + }, |
536 | |
537 | "lens-nav-bar" : { |
538 | "icon-height" : 20, |
539 | - "icon-gap" : 40}, |
540 | + "icon-gap" : 40 |
541 | + }, |
542 | |
543 | "button-label": { |
544 | "border-opacity" : [ 0.8, 0.13, 0.13, 0.13, 0.13], |
545 | "border-color" : ["#ffffff", "#FFFFFF", "#FFFFFF", "#FFFFFF", "#FFFFFF"], |
546 | "border-size" : [ 2.0, 1.0, 1.0, 0.5, 0.5], |
547 | + "border-radius" : 4.0, |
548 | "text-size" : 1.0, |
549 | "text-color" : ["#ffffff", "#ffffff", "#ffffff", "#ffffff", "#ffffff"], |
550 | - "text-opacity" : [ 1.0, 1.0, 1.0, 1.0, 1.0], |
551 | + "text-opacity" : [ 1.0, 1.0, 1.0, 1.0, 1.0], |
552 | "fill-color" : ["#FFFFFF", "#000000", "#000000", "#000000", "#000000"], |
553 | "fill-opacity" : [ 0.13, 0.0, 0.0, 0.0, 0.0], |
554 | "overlay-opacity": [ 0.1, 0.1, 0.1, 0.0, 0.0], |
555 | "overlay-mode" : [ "normal", "normal", "normal", "normal", "normal"], |
556 | - "blur-size" : [ 1, 1, 1, 0, 0]}, |
557 | + "blur-size" : [ 1, 1, 1, 0, 0] |
558 | + }, |
559 | |
560 | "track-view" : { |
561 | "line-gap" : 26.0, |
562 | "heading-list-gap" : 30, |
563 | - "left-padding" : 20}, |
564 | + "left-padding" : 20 |
565 | + }, |
566 | |
567 | "row-caption" : { |
568 | "main-text-color" : "#ffffff", |
569 | @@ -68,7 +77,8 @@ |
570 | "sub-text-weight" : "regular", |
571 | "icon-main-gap" : 10, |
572 | "main-sub-gap" : 15, |
573 | - "sub-arrow-gap" : 10}, |
574 | + "sub-arrow-gap" : 10 |
575 | + }, |
576 | |
577 | "preview-heading-small" : { |
578 | "main-title-size" : 23.0, |
579 | @@ -82,7 +92,8 @@ |
580 | "sub-title-mode" : "normal", |
581 | "sub-title-weight" : "regular", |
582 | "main-sub-gap" : 15, |
583 | - "padding" : 10}, |
584 | + "padding" : 10 |
585 | + }, |
586 | |
587 | "preview-heading" : { |
588 | "main-title-size" : 30.0, |
589 | @@ -96,16 +107,28 @@ |
590 | "sub-title-mode" : "normal", |
591 | "sub-title-weight" : "regular", |
592 | "main-sub-gap" : 15, |
593 | - "padding" : 10}, |
594 | - |
595 | - "scrollbar" : { |
596 | - "color" : "#ffffff", |
597 | - "opacity" : 1.0, |
598 | - "overlay-opacity": 0.30, |
599 | - "overlay-mode" : "normal", |
600 | - "blur-size" : 5, |
601 | + "padding" : 10 |
602 | + }, |
603 | + |
604 | + "scrollbar" : { |
605 | + "color" : "#fff", |
606 | + "opacity" : 1.0, |
607 | + "size" : 8, |
608 | + "buttons-size" : 0, |
609 | + "corner-radius" : 3 |
610 | + }, |
611 | + |
612 | + "scrollbar-overlay": { |
613 | + "color" : "#fff", |
614 | + "opacity" : 1.0, |
615 | "size" : 3, |
616 | - "corner-radius" : 1.5}, |
617 | + "corner-radius" : 1.5 |
618 | + }, |
619 | + |
620 | + "scrollbar-track": { |
621 | + "color" : "#fff", |
622 | + "opacity" : 0.4 |
623 | + }, |
624 | |
625 | "filter-pane" : { |
626 | "width" : 330, |
627 | @@ -116,15 +139,17 @@ |
628 | "title-style" : "bold", |
629 | "title-arrow-gap" : 10, |
630 | "button-height" : 30, |
631 | - "border-size" : 1}, |
632 | + "border-size" : 1 |
633 | + }, |
634 | |
635 | "separator" : { |
636 | "size" : 1.0, |
637 | "color" : "#ffffff", |
638 | - "opacity" : 0.15, |
639 | + "opacity" : 0.15, |
640 | "overlay-opacity": 0.47, |
641 | "overlay-mode" : "normal", |
642 | - "blur-size" : 6}, |
643 | + "blur-size" : 6 |
644 | + }, |
645 | |
646 | "filter-caption" : { |
647 | "text-size" : 17, |
648 | @@ -132,6 +157,6 @@ |
649 | "text-opacity" : 1.0, |
650 | "text-mode" : "normal", |
651 | "text-weight" : "bold", |
652 | - "text-arrow-gap" : 10} |
653 | - |
654 | + "text-arrow-gap" : 10 |
655 | + } |
656 | } |
657 | |
658 | === modified file 'unity-shared/CMakeLists.txt' |
659 | --- unity-shared/CMakeLists.txt 2016-02-19 12:11:52 +0000 |
660 | +++ unity-shared/CMakeLists.txt 2016-02-25 15:59:57 +0000 |
661 | @@ -62,6 +62,7 @@ |
662 | TextureCache.cpp |
663 | TextInput.cpp |
664 | TextureThumbnailProvider.cpp |
665 | + ThemeSettings.cpp |
666 | ThumbnailGenerator.cpp |
667 | Timer.cpp |
668 | UBusServer.cpp |
669 | |
670 | === modified file 'unity-shared/DashStyle.cpp' |
671 | --- unity-shared/DashStyle.cpp 2016-02-09 01:26:22 +0000 |
672 | +++ unity-shared/DashStyle.cpp 2016-02-25 15:59:57 +0000 |
673 | @@ -34,15 +34,13 @@ |
674 | #include <NuxCore/Logger.h> |
675 | #include <NuxGraphics/ImageSurface.h> |
676 | #include <NuxGraphics/CairoGraphics.h> |
677 | - |
678 | #include <Nux/PaintLayer.h> |
679 | - |
680 | -#include <UnityCore/GLibSignal.h> |
681 | #include <UnityCore/GLibWrapper.h> |
682 | |
683 | #include "CairoTexture.h" |
684 | #include "JSONParser.h" |
685 | #include "TextureCache.h" |
686 | +#include "ThemeSettings.h" |
687 | #include "UnitySettings.h" |
688 | #include "config.h" |
689 | |
690 | @@ -59,9 +57,6 @@ |
691 | |
692 | const int STATES = 5; |
693 | |
694 | -const double BUTTON_CORNER_RADIUS = 7.0; |
695 | - |
696 | - |
697 | // These cairo overrides may also be reused somewhere... |
698 | void cairo_set_source_rgba(cairo_t* cr, nux::Color const& color) |
699 | { |
700 | @@ -123,6 +118,7 @@ |
701 | |
702 | void Blur(cairo_t* cr, int size); |
703 | |
704 | + void LoadStyleFile(); |
705 | void SetDefaultValues(); |
706 | |
707 | void GetTextExtents(int& width, |
708 | @@ -173,7 +169,6 @@ |
709 | |
710 | void Refresh(); |
711 | void UpdateFormFactor(FormFactor); |
712 | - void OnFontChanged(GtkSettings* object, GParamSpec* pspec); |
713 | |
714 | BaseTexturePtr LoadScaledTexture(std::string const& name, double scale) |
715 | { |
716 | @@ -189,6 +184,7 @@ |
717 | |
718 | std::vector<nux::Color> button_label_border_color_; |
719 | std::vector<double> button_label_border_size_; |
720 | + double button_label_border_radius_; |
721 | double button_label_text_size_; |
722 | |
723 | std::vector<nux::Color> button_label_text_color_; |
724 | @@ -209,14 +205,14 @@ |
725 | BlendMode separator_overlay_mode_; |
726 | int separator_blur_size_; |
727 | |
728 | + int scrollbar_size_; |
729 | + int scrollbar_overlay_size_; |
730 | + int scrollbar_buttons_size_; |
731 | nux::Color scrollbar_color_; |
732 | - double scrollbar_overlay_opacity_; |
733 | - BlendMode scrollbar_overlay_mode_; |
734 | - int scrollbar_blur_size_; |
735 | - int scrollbar_size_; |
736 | + nux::Color scrollbar_overlay_color_; |
737 | + nux::Color scrollbar_track_color_; |
738 | double scrollbar_corner_radius_; |
739 | - |
740 | - glib::SignalManager signal_manager_; |
741 | + double scrollbar_overlay_corner_radius_; |
742 | |
743 | nux::Color text_color_; |
744 | |
745 | @@ -265,13 +261,14 @@ |
746 | , star_selected_texture_("/star_selected.png") |
747 | , star_highlight_texture_("/star_highlight.png") |
748 | { |
749 | - signal_manager_.Add(new glib::Signal<void, GtkSettings*, GParamSpec*> |
750 | - (gtk_settings_get_default(), |
751 | - "notify::gtk-font-name", |
752 | - sigc::mem_fun(this, &Impl::OnFontChanged))); |
753 | + auto refresh_cb = sigc::hide(sigc::mem_fun(this, &Impl::Refresh)); |
754 | + |
755 | + auto theme_settings = theme::Settings::Get(); |
756 | + theme_settings->font.changed.connect(refresh_cb); |
757 | + theme_settings->theme.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::LoadStyleFile))); |
758 | |
759 | auto& settings = Settings::Instance(); |
760 | - settings.font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::Refresh))); |
761 | + settings.font_scaling.changed.connect(refresh_cb); |
762 | settings.form_factor.changed.connect(sigc::mem_fun(this, &Impl::UpdateFormFactor)); |
763 | |
764 | Refresh(); |
765 | @@ -291,17 +288,28 @@ |
766 | CAIRO_HINT_METRICS_ON); |
767 | } |
768 | |
769 | + LoadStyleFile(); |
770 | +} |
771 | + |
772 | +void Style::Impl::LoadStyleFile() |
773 | +{ |
774 | json::Parser parser; |
775 | + |
776 | // Since the parser skips values if they are not found, make sure everything |
777 | // is initialised. |
778 | SetDefaultValues(); |
779 | - if (!parser.Open(DASH_WIDGETS_FILE)) |
780 | + |
781 | + if (!parser.Open(theme::Settings::Get()->ThemedFilePath("dash-widgets", {UNITYDATADIR"/themes"}, {"json"}))) |
782 | + { |
783 | + LOG_ERROR(logger) << "Impossible to find a dash-widgets.json in theme paths"; |
784 | return; |
785 | + } |
786 | |
787 | // button-label |
788 | parser.ReadColors("button-label", "border-color", "border-opacity", |
789 | button_label_border_color_); |
790 | parser.ReadDoubles("button-label", "border-size", button_label_border_size_); |
791 | + parser.ReadDouble("button-label", "border-radius", button_label_border_radius_); |
792 | parser.ReadDouble("button-label", "text-size", button_label_text_size_); |
793 | parser.ReadColors("button-label", "text-color", "text-opacity", |
794 | button_label_text_color_); |
795 | @@ -342,13 +350,16 @@ |
796 | parser.ReadInt("separator", "blur-size", separator_blur_size_); |
797 | |
798 | // scrollbar |
799 | + parser.ReadInt("scrollbar", "size", scrollbar_size_); |
800 | + parser.ReadInt("scrollbar-overlay", "size", scrollbar_overlay_size_); |
801 | + parser.ReadInt("scrollbar", "buttons-size", scrollbar_buttons_size_); |
802 | parser.ReadColor("scrollbar", "color", "opacity", scrollbar_color_); |
803 | - parser.ReadDouble("scrollbar", "overlay-opacity", scrollbar_overlay_opacity_); |
804 | - parser.ReadMappedString("scrollbar", "overlay-mode", blend_mode_map, |
805 | - scrollbar_overlay_mode_); |
806 | - parser.ReadInt("scrollbar", "blur-size", scrollbar_blur_size_); |
807 | - parser.ReadInt("scrollbar", "size", scrollbar_size_); |
808 | + parser.ReadColor("scrollbar-overlay", "color", "opacity", scrollbar_overlay_color_); |
809 | + parser.ReadColor("scrollbar-track", "color", "opacity", scrollbar_track_color_); |
810 | parser.ReadDouble("scrollbar", "corner-radius", scrollbar_corner_radius_); |
811 | + parser.ReadDouble("scrollbar-overlay", "corner-radius", scrollbar_overlay_corner_radius_); |
812 | + |
813 | + owner_->changed.emit(); |
814 | } |
815 | |
816 | Style::Impl::~Impl() |
817 | @@ -360,14 +371,12 @@ |
818 | void Style::Impl::Refresh() |
819 | { |
820 | const char* const SAMPLE_MAX_TEXT = "Chromium Web Browser"; |
821 | - GtkSettings* settings = ::gtk_settings_get_default(); |
822 | |
823 | nux::CairoGraphics util_cg(CAIRO_FORMAT_ARGB32, 1, 1); |
824 | cairo_t* cr = util_cg.GetInternalContext(); |
825 | |
826 | - glib::String font_description; |
827 | - ::g_object_get(settings, "gtk-font-name", &font_description, nullptr); |
828 | - PangoFontDescription* desc = ::pango_font_description_from_string(font_description); |
829 | + auto const& font = theme::Settings::Get()->font(); |
830 | + PangoFontDescription* desc = ::pango_font_description_from_string(font.c_str()); |
831 | ::pango_font_description_set_weight(desc, PANGO_WEIGHT_NORMAL); |
832 | ::pango_font_description_set_size(desc, 9 * PANGO_SCALE); |
833 | |
834 | @@ -392,11 +401,6 @@ |
835 | pango_font_description_free(desc); |
836 | } |
837 | |
838 | -void Style::Impl::OnFontChanged(GtkSettings* object, GParamSpec* pspec) |
839 | -{ |
840 | - Refresh(); |
841 | -} |
842 | - |
843 | void Style::Impl::UpdateFormFactor(FormFactor form_factor) |
844 | { |
845 | owner_->always_maximised = (form_factor == FormFactor::NETBOOK || form_factor == FormFactor::TV); |
846 | @@ -700,6 +704,7 @@ |
847 | //button_label_border_size_[nux::NUX_STATE_SELECTED] = 0.5; |
848 | //button_label_border_size_[nux::NUX_STATE_INSENSITIVE] = 0.5; |
849 | |
850 | + button_label_border_radius_ = 4.0; |
851 | button_label_text_size_ = 1.0; |
852 | |
853 | button_label_text_color_[nux::VISUAL_STATE_NORMAL] = nux::color::White; |
854 | @@ -746,12 +751,14 @@ |
855 | separator_blur_size_ = 6; |
856 | |
857 | // scrollbar |
858 | - scrollbar_color_ = nux::color::White; |
859 | - scrollbar_overlay_opacity_ = 0.3; |
860 | - scrollbar_overlay_mode_ = BlendMode::NORMAL; |
861 | - scrollbar_blur_size_ = 5; |
862 | - scrollbar_size_ = 3; |
863 | - scrollbar_corner_radius_ = 1.5; |
864 | + scrollbar_size_ = 8; |
865 | + scrollbar_overlay_size_ = 3; |
866 | + scrollbar_buttons_size_ = 0; |
867 | + scrollbar_color_ = nux::color::White; |
868 | + scrollbar_overlay_color_ = nux::color::White; |
869 | + scrollbar_track_color_ = nux::color::White * 0.4; |
870 | + scrollbar_corner_radius_ = 3; |
871 | + scrollbar_overlay_corner_radius_ = 1.5; |
872 | } |
873 | |
874 | void Style::Impl::ArrowPath(cairo_t* cr, Arrow arrow) |
875 | @@ -1356,9 +1363,7 @@ |
876 | PangoFontDescription* desc = NULL; |
877 | PangoContext* pangoCtx = NULL; |
878 | PangoRectangle inkRect = {0, 0, 0, 0}; |
879 | - char* fontName = NULL; |
880 | GdkScreen* screen = gdk_screen_get_default(); // is not ref'ed |
881 | - GtkSettings* settings = gtk_settings_get_default();// is not ref'ed |
882 | |
883 | surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
884 | cr = cairo_create(surface); |
885 | @@ -1366,16 +1371,9 @@ |
886 | cairo_set_font_options(cr, default_font_options_); |
887 | else |
888 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
889 | + |
890 | layout = pango_cairo_create_layout(cr); |
891 | - |
892 | - g_object_get(settings, "gtk-font-name", &fontName, NULL); |
893 | - if (!fontName) |
894 | - desc = pango_font_description_from_string("Sans 10"); |
895 | - else |
896 | - { |
897 | - desc = pango_font_description_from_string(fontName); |
898 | - g_free(fontName); |
899 | - } |
900 | + desc = pango_font_description_from_string(theme::Settings::Get()->font().c_str()); |
901 | |
902 | pango_layout_set_font_description(layout, desc); |
903 | pango_layout_set_wrap(layout, PANGO_WRAP_WORD_CHAR); |
904 | @@ -1423,9 +1421,7 @@ |
905 | PangoFontDescription* desc = NULL; |
906 | PangoContext* pangoCtx = NULL; |
907 | GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
908 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
909 | gchar* fontName = NULL; |
910 | - //double horizMargin = 10.0; |
911 | |
912 | get_actual_cairo_size(cr, &w, &h); |
913 | w -= 2 * horizMargin; |
914 | @@ -1434,13 +1430,9 @@ |
915 | cairo_set_font_options(cr, default_font_options_); |
916 | else |
917 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
918 | + |
919 | layout = pango_cairo_create_layout(cr); |
920 | - |
921 | - g_object_get(settings, "gtk-font-name", &fontName, NULL); |
922 | - if (!fontName) |
923 | - desc = pango_font_description_from_string("Ubuntu 10"); |
924 | - else |
925 | - desc = pango_font_description_from_string(fontName); |
926 | + desc = pango_font_description_from_string(theme::Settings::Get()->font().c_str()); |
927 | |
928 | if (text_size > 0) |
929 | { |
930 | @@ -1638,7 +1630,7 @@ |
931 | 1.0, |
932 | (double) (garnish) + 1.0, |
933 | (double) (garnish) + 1.0, |
934 | - BUTTON_CORNER_RADIUS, |
935 | + pimpl->button_label_border_radius_, |
936 | w - (double) (2 * garnish) - 2.0, |
937 | h - (double) (2 * garnish) - 2.0); |
938 | else |
939 | @@ -1646,7 +1638,7 @@ |
940 | 1.0, |
941 | (double) (garnish) + 0.5, |
942 | (double) (garnish) + 0.5, |
943 | - BUTTON_CORNER_RADIUS, |
944 | + pimpl->button_label_border_radius_, |
945 | w - (double) (2 * garnish) - 1.0, |
946 | h - (double) (2 * garnish) - 1.0); |
947 | |
948 | @@ -1739,7 +1731,7 @@ |
949 | cairo_move_to(cr, _align(x + width, odd), y); |
950 | if (curve_bottom) |
951 | { |
952 | - double radius = BUTTON_CORNER_RADIUS; |
953 | + double radius = pimpl->button_label_border_radius_; |
954 | LOG_DEBUG(logger) << "curve: " << _align(x + width, odd) << " - " << _align(y + height - radius, odd); |
955 | // line to bottom-right corner |
956 | cairo_line_to(cr, _align(x + width, odd), _align(y + height - radius, odd)); |
957 | @@ -1844,7 +1836,7 @@ |
958 | 1.0, |
959 | (double) 0.5, |
960 | (double) 0.5, |
961 | - BUTTON_CORNER_RADIUS, |
962 | + pimpl->button_label_border_radius_, |
963 | w - 1.0, |
964 | h - 1.0); |
965 | |
966 | @@ -1893,7 +1885,7 @@ |
967 | 1.0, |
968 | x, |
969 | y, |
970 | - BUTTON_CORNER_RADIUS, |
971 | + pimpl->button_label_border_radius_, |
972 | w, |
973 | h, |
974 | segment); |
975 | @@ -1916,7 +1908,7 @@ |
976 | 1.0, |
977 | x, |
978 | y + line_width/2, |
979 | - BUTTON_CORNER_RADIUS, |
980 | + pimpl->button_label_border_radius_, |
981 | w, |
982 | h - line_width, |
983 | segment, |
984 | @@ -2189,11 +2181,6 @@ |
985 | return pimpl->separator_blur_size_; |
986 | } |
987 | |
988 | -RawPixel Style::GetScrollbarGarnishSize() const |
989 | -{ |
990 | - return pimpl->scrollbar_blur_size_; |
991 | -} |
992 | - |
993 | nux::Color const& Style::GetTextColor() const |
994 | { |
995 | return pimpl->text_color_; |
996 | @@ -2406,9 +2393,44 @@ |
997 | return 10; |
998 | } |
999 | |
1000 | -RawPixel Style::GetScrollbarWidth() const |
1001 | -{ |
1002 | - return 3; |
1003 | +RawPixel Style::GetOverlayScrollbarSize() const |
1004 | +{ |
1005 | + return pimpl->scrollbar_overlay_size_; |
1006 | +} |
1007 | + |
1008 | +RawPixel Style::GetScrollbarSize() const |
1009 | +{ |
1010 | + return pimpl->scrollbar_size_; |
1011 | +} |
1012 | + |
1013 | +RawPixel Style::GetScrollbarButtonsSize() const |
1014 | +{ |
1015 | + return pimpl->scrollbar_buttons_size_; |
1016 | +} |
1017 | + |
1018 | +RawPixel Style::GetOverlayScrollbarCornerRadius() const |
1019 | +{ |
1020 | + return pimpl->scrollbar_overlay_corner_radius_; |
1021 | +} |
1022 | + |
1023 | +RawPixel Style::GetScrollbarCornerRadius() const |
1024 | +{ |
1025 | + return pimpl->scrollbar_corner_radius_; |
1026 | +} |
1027 | + |
1028 | +nux::Color Style::GetOverlayScrollbarColor() const |
1029 | +{ |
1030 | + return pimpl->scrollbar_overlay_color_; |
1031 | +} |
1032 | + |
1033 | +nux::Color Style::GetScrollbarColor() const |
1034 | +{ |
1035 | + return pimpl->scrollbar_color_; |
1036 | +} |
1037 | + |
1038 | +nux::Color Style::GetScrollbarTrackColor() const |
1039 | +{ |
1040 | + return pimpl->scrollbar_track_color_; |
1041 | } |
1042 | |
1043 | RawPixel Style::GetCategoryIconSize() const |
1044 | |
1045 | === modified file 'unity-shared/DashStyle.h' |
1046 | --- unity-shared/DashStyle.h 2014-07-10 19:30:17 +0000 |
1047 | +++ unity-shared/DashStyle.h 2016-02-25 15:59:57 +0000 |
1048 | @@ -140,8 +140,6 @@ |
1049 | |
1050 | RawPixel GetSeparatorGarnishSize() const; |
1051 | |
1052 | - RawPixel GetScrollbarGarnishSize() const; |
1053 | - |
1054 | void Blur(cairo_t* cr, int size); |
1055 | |
1056 | void RoundedRect(cairo_t* cr, |
1057 | @@ -237,7 +235,16 @@ |
1058 | RawPixel GetSpaceBetweenScopeAndFilters() const; |
1059 | |
1060 | // Scrollbars |
1061 | - RawPixel GetScrollbarWidth() const; |
1062 | + RawPixel GetOverlayScrollbarSize() const; |
1063 | + RawPixel GetScrollbarSize() const; |
1064 | + RawPixel GetScrollbarButtonsSize() const; |
1065 | + |
1066 | + RawPixel GetOverlayScrollbarCornerRadius() const; |
1067 | + RawPixel GetScrollbarCornerRadius() const; |
1068 | + |
1069 | + nux::Color GetOverlayScrollbarColor() const; |
1070 | + nux::Color GetScrollbarColor() const; |
1071 | + nux::Color GetScrollbarTrackColor() const; |
1072 | |
1073 | // Places Group |
1074 | RawPixel GetCategoryIconSize() const; |
1075 | |
1076 | === modified file 'unity-shared/DecorationStyle.cpp' |
1077 | --- unity-shared/DecorationStyle.cpp 2014-12-19 13:03:44 +0000 |
1078 | +++ unity-shared/DecorationStyle.cpp 2016-02-25 15:59:57 +0000 |
1079 | @@ -19,12 +19,16 @@ |
1080 | |
1081 | #include "config.h" |
1082 | #include "DecorationStyle.h" |
1083 | -#include <gtk/gtk.h> |
1084 | + |
1085 | +#include <math.h> |
1086 | #include <NuxCore/Colors.h> |
1087 | #include <NuxCore/Logger.h> |
1088 | +#include <UnityCore/ConnectionManager.h> |
1089 | #include <UnityCore/GLibWrapper.h> |
1090 | #include <UnityCore/GLibSignal.h> |
1091 | -#include <math.h> |
1092 | + |
1093 | +#include "GtkUtils.h" |
1094 | +#include "ThemeSettings.h" |
1095 | |
1096 | namespace unity |
1097 | { |
1098 | @@ -53,7 +57,6 @@ |
1099 | const int DEFAULT_GLOW_SIZE = 10; |
1100 | const nux::Color DEFAULT_GLOW_COLOR(221, 72, 20); |
1101 | |
1102 | -const std::array<std::string, 2> THEMED_FILE_EXTENSIONS = { "svg", "png" }; |
1103 | const std::array<std::string, size_t(WindowButtonType::Size)> WBUTTON_NAMES = { "close", "minimize", "unmaximize", "maximize" }; |
1104 | const std::array<std::string, size_t(WidgetState::Size)> WBUTTON_STATES = {"", "_focused_prelight", "_focused_pressed", "_unfocused", |
1105 | "_unfocused", "_unfocused_prelight", "_unfocused_pressed" }; |
1106 | @@ -157,8 +160,9 @@ |
1107 | gtk_widget_path_append_type(widget_path.get(), unity_decoration_get_type()); |
1108 | gtk_style_context_set_path(ctx_, widget_path.get()); |
1109 | |
1110 | - parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str(); |
1111 | - parent_->font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str(); |
1112 | + auto theme_settings = theme::Settings::Get(); |
1113 | + parent_->theme.SetGetterFunction([theme_settings] { return theme_settings->theme(); }); |
1114 | + parent_->font.SetGetterFunction([theme_settings] { return theme_settings->font(); }); |
1115 | parent_->font_scale = 1.0; |
1116 | SetTitleFont(); |
1117 | |
1118 | @@ -166,29 +170,26 @@ |
1119 | UpdateMenuItemPangoContext(parent_->font); |
1120 | UpdateThemedValues(); |
1121 | |
1122 | - GtkSettings* settings = gtk_settings_get_default(); |
1123 | - signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-theme-name", [this] (GtkSettings*, GParamSpec*) { |
1124 | + connections_.Add(theme_settings->theme.changed.connect([this] (std::string const& theme) { |
1125 | #if !GTK_CHECK_VERSION(3, 11, 0) |
1126 | gtk_style_context_invalidate(ctx_); |
1127 | #endif |
1128 | UpdateThemedValues(); |
1129 | - parent_->theme = glib::String(GetSettingValue<gchar*>("gtk-theme-name")).Str(); |
1130 | - LOG_INFO(logger) << "gtk-theme-name changed to " << parent_->theme(); |
1131 | - }); |
1132 | + parent_->theme.EmitChanged(theme); |
1133 | + LOG_INFO(logger) << "unity theme changed to " << parent_->theme(); |
1134 | + })); |
1135 | |
1136 | - signals_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-font-name", [this] (GtkSettings*, GParamSpec*) { |
1137 | - auto const& font = glib::String(GetSettingValue<gchar*>("gtk-font-name")).Str(); |
1138 | + connections_.Add(theme_settings->font.changed.connect([this] (std::string const& font) { |
1139 | UpdateMenuItemPangoContext(font); |
1140 | - parent_->font = font; |
1141 | + parent_->font.EmitChanged(font); |
1142 | |
1143 | if (g_settings_get_boolean(settings_, USE_SYSTEM_FONT_KEY.c_str())) |
1144 | { |
1145 | UpdateTitlePangoContext(parent_->font()); |
1146 | parent_->title_font = parent_->font(); |
1147 | } |
1148 | - |
1149 | - LOG_INFO(logger) << "gtk-font-name changed to " << parent_->font(); |
1150 | - }); |
1151 | + LOG_INFO(logger) << "unity font changed to " << parent_->font(); |
1152 | + })); |
1153 | |
1154 | parent_->font_scale.changed.connect([this] (bool scale) { |
1155 | UpdateTitlePangoContext(parent_->title_font); |
1156 | @@ -297,14 +298,6 @@ |
1157 | return value; |
1158 | } |
1159 | |
1160 | - template <typename TYPE> |
1161 | - inline TYPE GetSettingValue(std::string const& name) |
1162 | - { |
1163 | - TYPE value; |
1164 | - g_object_get(gtk_settings_get_default(), name.c_str(), &value, nullptr); |
1165 | - return value; |
1166 | - } |
1167 | - |
1168 | WMAction WMActionFromString(std::string const& action) const |
1169 | { |
1170 | if (action == "toggle-shade") |
1171 | @@ -391,54 +384,10 @@ |
1172 | gtk_style_context_restore(ctx_); |
1173 | } |
1174 | |
1175 | - std::string ThemedFilePath(std::string const& base_filename, std::vector<std::string> const& extra_folders = {}) const |
1176 | - { |
1177 | - auto const& theme = parent_->theme(); |
1178 | - const char* home_dir = g_get_home_dir(); |
1179 | - const char* gtk_prefix = g_getenv("GTK_DATA_PREFIX"); |
1180 | - if (!gtk_prefix) |
1181 | - gtk_prefix = GTK_PREFIX; |
1182 | - |
1183 | - for (auto const& extension : THEMED_FILE_EXTENSIONS) |
1184 | - { |
1185 | - auto filename = base_filename + '.' + extension; |
1186 | - glib::String subpath(g_build_filename(theme.c_str(), "unity", filename.c_str(), nullptr)); |
1187 | - |
1188 | - // Look in home directory |
1189 | - if (home_dir) |
1190 | - { |
1191 | - glib::String local_file(g_build_filename(home_dir, ".local", "share", "themes", subpath.Value(), nullptr)); |
1192 | - |
1193 | - if (g_file_test(local_file, G_FILE_TEST_EXISTS)) |
1194 | - return local_file.Str(); |
1195 | - |
1196 | - glib::String home_file(g_build_filename(home_dir, ".themes", subpath.Value(), nullptr)); |
1197 | - |
1198 | - if (g_file_test(home_file, G_FILE_TEST_EXISTS)) |
1199 | - return home_file.Str(); |
1200 | - } |
1201 | - |
1202 | - glib::String path(g_build_filename(gtk_prefix, "share", "themes", subpath.Value(), nullptr)); |
1203 | - |
1204 | - if (g_file_test(path, G_FILE_TEST_EXISTS)) |
1205 | - return path.Str(); |
1206 | - |
1207 | - for (auto const& folder : extra_folders) |
1208 | - { |
1209 | - glib::String path(g_build_filename(folder.c_str(), filename.c_str(), nullptr)); |
1210 | - |
1211 | - if (g_file_test(path, G_FILE_TEST_EXISTS)) |
1212 | - return path.Str(); |
1213 | - } |
1214 | - } |
1215 | - |
1216 | - return std::string(); |
1217 | - } |
1218 | - |
1219 | std::string WindowButtonFile(WindowButtonType type, WidgetState state) const |
1220 | { |
1221 | auto base_filename = WBUTTON_NAMES[unsigned(type)] + WBUTTON_STATES[unsigned(state)]; |
1222 | - auto const& file_path = ThemedFilePath(base_filename); |
1223 | + auto const& file_path = parent_->ThemedFilePath(base_filename); |
1224 | |
1225 | if (!file_path.empty()) |
1226 | return file_path; |
1227 | @@ -677,6 +626,7 @@ |
1228 | glib::Object<GSettings> usettings_; |
1229 | glib::Object<PangoContext> title_pango_ctx_; |
1230 | glib::Object<PangoContext> menu_item_pango_ctx_; |
1231 | + connection::Manager connections_; |
1232 | decoration::Border border_; |
1233 | decoration::Border input_edges_; |
1234 | decoration::Border radius_; |
1235 | @@ -751,7 +701,7 @@ |
1236 | |
1237 | std::string Style::ThemedFilePath(std::string const& basename, std::vector<std::string> const& extra_folders) const |
1238 | { |
1239 | - return impl_->ThemedFilePath(basename, extra_folders); |
1240 | + return theme::Settings::Get()->ThemedFilePath(basename, extra_folders); |
1241 | } |
1242 | |
1243 | std::string Style::WindowButtonFile(WindowButtonType type, WidgetState state) const |
1244 | @@ -832,12 +782,12 @@ |
1245 | |
1246 | int Style::DoubleClickMaxDistance() const |
1247 | { |
1248 | - return impl_->GetSettingValue<int>("gtk-double-click-distance"); |
1249 | + return gtk::GetSettingValue<int>("gtk-double-click-distance"); |
1250 | } |
1251 | |
1252 | int Style::DoubleClickMaxTimeDelta() const |
1253 | { |
1254 | - return impl_->GetSettingValue<int>("gtk-double-click-time"); |
1255 | + return gtk::GetSettingValue<int>("gtk-double-click-time"); |
1256 | } |
1257 | |
1258 | nux::Size Style::TitleNaturalSize(std::string const& text) |
1259 | |
1260 | === modified file 'unity-shared/DecorationStyle.h' |
1261 | --- unity-shared/DecorationStyle.h 2015-07-31 13:47:59 +0000 |
1262 | +++ unity-shared/DecorationStyle.h 2016-02-25 15:59:57 +0000 |
1263 | @@ -115,10 +115,10 @@ |
1264 | typedef std::shared_ptr<Style> Ptr; |
1265 | |
1266 | static Style::Ptr const& Get(); |
1267 | - virtual ~Style(); |
1268 | + ~Style(); |
1269 | |
1270 | - nux::Property<std::string> theme; |
1271 | - nux::Property<std::string> font; |
1272 | + nux::ROProperty<std::string> theme; |
1273 | + nux::ROProperty<std::string> font; |
1274 | nux::Property<std::string> title_font; |
1275 | nux::Property<unsigned> grab_wait; |
1276 | nux::Property<double> font_scale; |
1277 | |
1278 | === modified file 'unity-shared/FontSettings.cpp' |
1279 | --- unity-shared/FontSettings.cpp 2014-03-20 21:46:44 +0000 |
1280 | +++ unity-shared/FontSettings.cpp 2016-02-25 15:59:57 +0000 |
1281 | @@ -17,71 +17,59 @@ |
1282 | */ |
1283 | |
1284 | #include "FontSettings.h" |
1285 | - |
1286 | #include <cairo/cairo.h> |
1287 | |
1288 | -#include <UnityCore/GLibWrapper.h> |
1289 | -#include <sigc++/sigc++.h> |
1290 | - |
1291 | namespace unity |
1292 | { |
1293 | |
1294 | FontSettings::FontSettings() |
1295 | + : hintstyle_("gtk-xft-hintstyle") |
1296 | + , rgba_("gtk-xft-rgba") |
1297 | + , antialias_("gtk-xft-antialias") |
1298 | { |
1299 | - GtkSettings* settings = gtk_settings_get_default(); |
1300 | - |
1301 | - sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-hintstyle", sigc::mem_fun(this, &FontSettings::Refresh)); |
1302 | - sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-rgba", sigc::mem_fun(this, &FontSettings::Refresh)); |
1303 | - sig_man_.Add<void, GtkSettings*, GParamSpec*>(settings, "notify::gtk-xft-antialias", sigc::mem_fun(this, &FontSettings::Refresh)); |
1304 | + auto refresh_cb = sigc::hide(sigc::mem_fun(this, &FontSettings::Refresh)); |
1305 | + hintstyle_.changed.connect(refresh_cb); |
1306 | + rgba_.changed.connect(refresh_cb); |
1307 | + antialias_.changed.connect(refresh_cb); |
1308 | |
1309 | Refresh(); |
1310 | } |
1311 | |
1312 | -void FontSettings::Refresh(GtkSettings* unused0, GParamSpec* unused1) |
1313 | +void FontSettings::Refresh() |
1314 | { |
1315 | - GtkSettings* settings = gtk_settings_get_default(); |
1316 | cairo_font_options_t* font_options = cairo_font_options_create(); |
1317 | |
1318 | - { |
1319 | - cairo_subpixel_order_t order = CAIRO_SUBPIXEL_ORDER_DEFAULT; |
1320 | - glib::String value; |
1321 | - g_object_get(settings, "gtk-xft-rgba", &value, NULL); |
1322 | - gint antialias; |
1323 | - g_object_get(settings, "gtk-xft-antialias", &antialias, NULL); |
1324 | - |
1325 | - if (value.Str() == "rgb") |
1326 | - order = CAIRO_SUBPIXEL_ORDER_RGB; |
1327 | - else if (value.Str() == "bgr") |
1328 | - order = CAIRO_SUBPIXEL_ORDER_BGR; |
1329 | - else if (value.Str() == "vrgb") |
1330 | - order = CAIRO_SUBPIXEL_ORDER_VRGB; |
1331 | - else if (value.Str() == "vbgr") |
1332 | - order = CAIRO_SUBPIXEL_ORDER_VBGR; |
1333 | - |
1334 | - cairo_font_options_set_subpixel_order(font_options, order); |
1335 | - cairo_font_options_set_antialias(font_options, |
1336 | - value.Str() == "none" ? (antialias ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE) |
1337 | - : CAIRO_ANTIALIAS_SUBPIXEL); |
1338 | - |
1339 | - } |
1340 | - |
1341 | - { |
1342 | - cairo_hint_style_t style = CAIRO_HINT_STYLE_DEFAULT; |
1343 | - glib::String value; |
1344 | - g_object_get(settings, "gtk-xft-hintstyle", &value, NULL); |
1345 | - |
1346 | - if (value.Str() == "hintnone") |
1347 | - style = CAIRO_HINT_STYLE_NONE; |
1348 | - else if (value.Str() == "hintslight") |
1349 | - style = CAIRO_HINT_STYLE_SLIGHT; |
1350 | - else if (value.Str() == "hintmedium") |
1351 | - style = CAIRO_HINT_STYLE_MEDIUM; |
1352 | - else if (value.Str() == "hintfull") |
1353 | - style = CAIRO_HINT_STYLE_FULL; |
1354 | - |
1355 | - cairo_font_options_set_hint_style(font_options, style); |
1356 | - } |
1357 | - |
1358 | + auto const& rgba = rgba_(); |
1359 | + cairo_subpixel_order_t order = CAIRO_SUBPIXEL_ORDER_DEFAULT; |
1360 | + |
1361 | + if (rgba == "rgb") |
1362 | + order = CAIRO_SUBPIXEL_ORDER_RGB; |
1363 | + else if (rgba == "bgr") |
1364 | + order = CAIRO_SUBPIXEL_ORDER_BGR; |
1365 | + else if (rgba == "vrgb") |
1366 | + order = CAIRO_SUBPIXEL_ORDER_VRGB; |
1367 | + else if (rgba == "vbgr") |
1368 | + order = CAIRO_SUBPIXEL_ORDER_VBGR; |
1369 | + |
1370 | + cairo_font_options_set_subpixel_order(font_options, order); |
1371 | + cairo_font_options_set_antialias(font_options, |
1372 | + rgba == "none" ? (antialias_() ? CAIRO_ANTIALIAS_GRAY : CAIRO_ANTIALIAS_NONE) |
1373 | + : CAIRO_ANTIALIAS_SUBPIXEL); |
1374 | + |
1375 | + auto const& hintstyle = hintstyle_(); |
1376 | + cairo_hint_style_t style = CAIRO_HINT_STYLE_DEFAULT; |
1377 | + |
1378 | + if (hintstyle == "hintnone") |
1379 | + style = CAIRO_HINT_STYLE_NONE; |
1380 | + else if (hintstyle == "hintslight") |
1381 | + style = CAIRO_HINT_STYLE_SLIGHT; |
1382 | + else if (hintstyle == "hintmedium") |
1383 | + style = CAIRO_HINT_STYLE_MEDIUM; |
1384 | + else if (hintstyle == "hintfull") |
1385 | + style = CAIRO_HINT_STYLE_FULL; |
1386 | + |
1387 | + cairo_font_options_set_hint_style(font_options, style); |
1388 | + |
1389 | // FIXME: Where do we read this value from? |
1390 | cairo_font_options_set_hint_metrics(font_options, CAIRO_HINT_METRICS_ON); |
1391 | |
1392 | |
1393 | === modified file 'unity-shared/FontSettings.h' |
1394 | --- unity-shared/FontSettings.h 2014-03-20 21:46:44 +0000 |
1395 | +++ unity-shared/FontSettings.h 2016-02-25 15:59:57 +0000 |
1396 | @@ -19,23 +19,23 @@ |
1397 | #ifndef UNITY_FONT_SETTINGS_H_ |
1398 | #define UNITY_FONT_SETTINGS_H_ |
1399 | |
1400 | -#include <gtk/gtk.h> |
1401 | - |
1402 | -#include <UnityCore/GLibSignal.h> |
1403 | +#include "GtkUtils.h" |
1404 | |
1405 | namespace unity |
1406 | { |
1407 | |
1408 | -class FontSettings |
1409 | +class FontSettings : public sigc::trackable |
1410 | { |
1411 | public: |
1412 | FontSettings(); |
1413 | |
1414 | private: |
1415 | - void Refresh(GtkSettings* unused0=nullptr, GParamSpec* unused1=nullptr); |
1416 | + void Refresh(); |
1417 | |
1418 | private: |
1419 | - glib::SignalManager sig_man_; |
1420 | + gtk::Setting<std::string> hintstyle_; |
1421 | + gtk::Setting<std::string> rgba_; |
1422 | + gtk::Setting<int> antialias_; |
1423 | }; |
1424 | |
1425 | } |
1426 | |
1427 | === added file 'unity-shared/GtkUtils.h' |
1428 | --- unity-shared/GtkUtils.h 1970-01-01 00:00:00 +0000 |
1429 | +++ unity-shared/GtkUtils.h 2016-02-25 15:59:57 +0000 |
1430 | @@ -0,0 +1,73 @@ |
1431 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
1432 | +/* |
1433 | + * Copyright (C) 2016 Canonical Ltd |
1434 | + * |
1435 | + * This program is free software: you can redistribute it and/or modify |
1436 | + * it under the terms of the GNU General Public License version 3 as |
1437 | + * published by the Free Software Foundation. |
1438 | + * |
1439 | + * This program is distributed in the hope that it will be useful, |
1440 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
1441 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
1442 | + * GNU General Public License for more details. |
1443 | + * |
1444 | + * You should have received a copy of the GNU General Public License |
1445 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
1446 | + * |
1447 | + * Authored by: Marco Trevisan <marco.trevisan@canonical.com> |
1448 | + */ |
1449 | + |
1450 | +#ifndef UNITY_GTK_UTILS |
1451 | +#define UNITY_GTK_UTILS |
1452 | + |
1453 | +#include <gtk/gtk.h> |
1454 | +#include <sigc++/sigc++.h> |
1455 | + |
1456 | +#include <UnityCore/GLibWrapper.h> |
1457 | +#include <UnityCore/GLibSignal.h> |
1458 | + |
1459 | +namespace unity |
1460 | +{ |
1461 | +namespace gtk |
1462 | +{ |
1463 | + |
1464 | +template <typename TYPE> |
1465 | +inline TYPE GetSettingValue(std::string const& name) |
1466 | +{ |
1467 | + TYPE value; |
1468 | + g_object_get(gtk_settings_get_default(), name.c_str(), &value, nullptr); |
1469 | + return value; |
1470 | +} |
1471 | + |
1472 | +template <> |
1473 | +inline std::string GetSettingValue(std::string const& name) |
1474 | +{ |
1475 | + return glib::String(gtk::GetSettingValue<gchar*>(name)).Str(); |
1476 | +} |
1477 | + |
1478 | +template <typename TYPE> |
1479 | +class Setting |
1480 | +{ |
1481 | +public: |
1482 | + Setting(std::string const& name) |
1483 | + : name_(name) |
1484 | + { |
1485 | + connection_.Connect(gtk_settings_get_default(), "notify::"+name_, [this] (GtkSettings*, GParamSpec*) { |
1486 | + changed.emit(GetSettingValue<TYPE>(name_)); |
1487 | + }); |
1488 | + } |
1489 | + |
1490 | + TYPE Value() const { return GetSettingValue<TYPE>(name_); } |
1491 | + TYPE operator()() const { return Value(); } |
1492 | + |
1493 | + sigc::signal<void, TYPE const&> changed; |
1494 | + |
1495 | +private: |
1496 | + std::string name_; |
1497 | + glib::Signal<void, GtkSettings*, GParamSpec*> connection_; |
1498 | +}; |
1499 | + |
1500 | +} // theme namespace |
1501 | +} // gtk namespace |
1502 | + |
1503 | +#endif // UNITY_GTK_UTILS |
1504 | |
1505 | === modified file 'unity-shared/IconLoader.cpp' |
1506 | --- unity-shared/IconLoader.cpp 2015-10-05 16:52:24 +0000 |
1507 | +++ unity-shared/IconLoader.cpp 2016-02-25 15:59:57 +0000 |
1508 | @@ -30,11 +30,12 @@ |
1509 | #include <Nux/Nux.h> |
1510 | #include <NuxCore/Logger.h> |
1511 | #include <NuxGraphics/CairoGraphics.h> |
1512 | +#include <UnityCore/ConnectionManager.h> |
1513 | #include <UnityCore/GLibSource.h> |
1514 | -#include <UnityCore/GLibSignal.h> |
1515 | #include <UnityCore/GLibWrapper.h> |
1516 | |
1517 | #include "unity-shared/Timer.h" |
1518 | +#include "unity-shared/ThemeSettings.h" |
1519 | #include "unity-shared/UnitySettings.h" |
1520 | |
1521 | namespace unity |
1522 | @@ -313,12 +314,11 @@ |
1523 | glib::Object<PangoLayout> layout; |
1524 | PangoContext* pango_context = NULL; |
1525 | GdkScreen* screen = gdk_screen_get_default(); // not ref'ed |
1526 | - glib::String font; |
1527 | + auto const& font = theme::Settings::Get()->font(); |
1528 | |
1529 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font, NULL); |
1530 | cairo_set_font_options(cr, gdk_screen_get_font_options(screen)); |
1531 | layout = pango_cairo_create_layout(cr); |
1532 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font), pango_font_description_free); |
1533 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); |
1534 | pango_font_description_set_weight(desc.get(), PANGO_WEIGHT_BOLD); |
1535 | int font_size = FONT_SIZE; |
1536 | pango_font_description_set_size (desc.get(), font_size * PANGO_SCALE); |
1537 | @@ -817,7 +817,7 @@ |
1538 | Handle handle_counter_; |
1539 | glib::Source::UniquePtr idle_; |
1540 | glib::Source::UniquePtr coalesce_timeout_; |
1541 | - glib::Signal<void, GtkIconTheme*> theme_changed_signal_; |
1542 | + connection::Wrapper theme_changed_; |
1543 | }; |
1544 | |
1545 | |
1546 | @@ -827,7 +827,7 @@ |
1547 | , theme_(::gtk_icon_theme_get_default()) |
1548 | , handle_counter_(0) |
1549 | { |
1550 | - theme_changed_signal_.Connect(theme_, "changed", [this] (GtkIconTheme*) { |
1551 | + theme_changed_ = theme::Settings::Get()->icons_changed.connect([this] { |
1552 | /* Since the theme has been changed we can clear the cache, however we |
1553 | * could include two improvements here: |
1554 | * 1) clear only the themed icons in cache |
1555 | @@ -914,14 +914,12 @@ |
1556 | { |
1557 | // FIXME: what about CJK? |
1558 | const char* const SAMPLE_MAX_TEXT = "Chromium Web Browser"; |
1559 | - GtkSettings* settings = gtk_settings_get_default(); |
1560 | |
1561 | nux::CairoGraphics util_cg(CAIRO_FORMAT_ARGB32, 1, 1); |
1562 | cairo_t* cr = util_cg.GetInternalContext(); |
1563 | |
1564 | - glib::String font; |
1565 | - g_object_get(settings, "gtk-font-name", &font, nullptr); |
1566 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font), pango_font_description_free); |
1567 | + auto const& font = theme::Settings::Get()->font(); |
1568 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); |
1569 | pango_font_description_set_weight(desc.get(), PANGO_WEIGHT_BOLD); |
1570 | pango_font_description_set_size(desc.get(), FONT_SIZE * PANGO_SCALE); |
1571 | |
1572 | |
1573 | === modified file 'unity-shared/IconRenderer.cpp' |
1574 | --- unity-shared/IconRenderer.cpp 2014-09-04 22:11:33 +0000 |
1575 | +++ unity-shared/IconRenderer.cpp 2016-02-25 15:59:57 +0000 |
1576 | @@ -29,7 +29,7 @@ |
1577 | #include <UnityCore/ConnectionManager.h> |
1578 | #include <NuxGraphics/CairoGraphics.h> |
1579 | #include "unity-shared/CairoTexture.h" |
1580 | -#include "unity-shared/DecorationStyle.h" |
1581 | +#include "unity-shared/ThemeSettings.h" |
1582 | #include "unity-shared/TextureCache.h" |
1583 | #include "unity-shared/UnitySettings.h" |
1584 | #include "unity-shared/WindowManager.h" |
1585 | @@ -250,7 +250,7 @@ |
1586 | LocalTextures(IconRenderer* parent) |
1587 | : parent_(parent) |
1588 | { |
1589 | - connections_.Add(decoration::Style::Get()->theme.changed.connect([this] (std::string const&) { |
1590 | + connections_.Add(theme::Settings::Get()->theme.changed.connect([this] (std::string const&) { |
1591 | auto& cache = TextureCache::GetDefault(); |
1592 | |
1593 | for (auto const& tex_data : texture_files_) |
1594 | @@ -294,7 +294,7 @@ |
1595 | auto texture_loader = [] (std::string const& basename, int w, int h) |
1596 | { |
1597 | int size = std::max(w, h); |
1598 | - auto const& file = decoration::Style::Get()->ThemedFilePath(basename, {PKGDATADIR"/"}); |
1599 | + auto const& file = theme::Settings::Get()->ThemedFilePath(basename, {PKGDATADIR}); |
1600 | return nux::CreateTexture2DFromFile(file.c_str(), (size <= 0 ? -1 : size), true); |
1601 | }; |
1602 | |
1603 | @@ -827,8 +827,8 @@ |
1604 | cairo_fill(cr); |
1605 | |
1606 | glib::Object<PangoLayout> layout(pango_cairo_create_layout(cr)); |
1607 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); |
1608 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), |
1609 | + auto const& font = theme::Settings::Get()->font(); |
1610 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), |
1611 | pango_font_description_free); |
1612 | const double text_ratio = 0.75; |
1613 | int text_size = pango_units_from_double(label_size * text_ratio * Settings::Instance().font_scaling()); |
1614 | |
1615 | === modified file 'unity-shared/JSONParser.h' |
1616 | --- unity-shared/JSONParser.h 2012-05-06 23:48:38 +0000 |
1617 | +++ unity-shared/JSONParser.h 2016-02-25 15:59:57 +0000 |
1618 | @@ -103,7 +103,7 @@ |
1619 | values.size()); |
1620 | for (std::size_t i = 0; i < size; ++i) |
1621 | { |
1622 | - std::string key(json_array_get_string_element(array, i)); |
1623 | + auto key = glib::gchar_to_string(json_array_get_string_element(array, i)); |
1624 | boost::to_lower(key); |
1625 | auto it = mapping.find(key); |
1626 | if (it != mapping.end()) |
1627 | @@ -121,7 +121,7 @@ |
1628 | if (!object) |
1629 | return; |
1630 | |
1631 | - std::string key(json_object_get_string_member(object, member_name.c_str())); |
1632 | + auto key = glib::gchar_to_string(json_object_get_string_member(object, member_name.c_str())); |
1633 | boost::to_lower(key); |
1634 | auto it = mapping.find(key); |
1635 | if (it != mapping.end()) |
1636 | |
1637 | === modified file 'unity-shared/PanelStyle.cpp' |
1638 | --- unity-shared/PanelStyle.cpp 2014-06-13 15:22:15 +0000 |
1639 | +++ unity-shared/PanelStyle.cpp 2016-02-25 15:59:57 +0000 |
1640 | @@ -272,7 +272,7 @@ |
1641 | static const std::array<std::string, 4> states = { "", "_prelight", "_pressed", "_disabled" }; |
1642 | |
1643 | auto base_filename = names[unsigned(type)] + states[unsigned(state)]; |
1644 | - auto const& file = decoration::Style::Get()->ThemedFilePath(base_filename, {PKGDATADIR"/"}); |
1645 | + auto const& file = decoration::Style::Get()->ThemedFilePath(base_filename, {PKGDATADIR}); |
1646 | |
1647 | if (file.empty()) |
1648 | return BaseTexturePtr(); |
1649 | |
1650 | === modified file 'unity-shared/PlacesOverlayVScrollBar.cpp' |
1651 | --- unity-shared/PlacesOverlayVScrollBar.cpp 2015-11-06 18:05:38 +0000 |
1652 | +++ unity-shared/PlacesOverlayVScrollBar.cpp 2016-02-25 15:59:57 +0000 |
1653 | @@ -21,8 +21,8 @@ |
1654 | #include <Nux/Nux.h> |
1655 | |
1656 | #include "AnimationUtils.h" |
1657 | +#include "DashStyle.h" |
1658 | #include "PlacesOverlayVScrollBar.h" |
1659 | -#include "RawPixel.h" |
1660 | |
1661 | namespace unity |
1662 | { |
1663 | @@ -33,10 +33,6 @@ |
1664 | const RawPixel PROXIMITY = 7_em; |
1665 | const int PAGE_SCROLL_ANIMATION = 200; |
1666 | const int CLICK_SCROLL_ANIMATION = 80; |
1667 | - |
1668 | -const RawPixel BUTTONS_HEIGHT = 0_em; |
1669 | -const RawPixel DEFAULT_WIDTH = 3_em; |
1670 | -const RawPixel ACTIVE_WIDTH = 8_em; |
1671 | } |
1672 | |
1673 | struct PlacesOverlayVScrollBar::ProximityArea : public nux::InputAreaProximity, public sigc::trackable |
1674 | @@ -62,6 +58,7 @@ |
1675 | }); |
1676 | |
1677 | auto update_sb_cb = sigc::mem_fun(this, &PlacesOverlayVScrollBar::UpdateScrollbarSize); |
1678 | + Style::Instance().changed.connect(update_sb_cb); |
1679 | |
1680 | auto update_sb_proximity_cb = sigc::hide(update_sb_cb); |
1681 | area_prox_->mouse_near.connect(update_sb_proximity_cb); |
1682 | @@ -94,22 +91,26 @@ |
1683 | void PlacesOverlayVScrollBar::UpdateScrollbarSize() |
1684 | { |
1685 | bool is_hovering = false; |
1686 | - SetMinimumWidth(ACTIVE_WIDTH.CP(scale)); |
1687 | - SetMaximumWidth(ACTIVE_WIDTH.CP(scale)); |
1688 | - |
1689 | - _scroll_up_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
1690 | - _scroll_up_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
1691 | - _scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
1692 | - _scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
1693 | - |
1694 | - int slider_width = DEFAULT_WIDTH.CP(scale); |
1695 | + auto& style = Style::Instance(); |
1696 | + |
1697 | + int active_width = style.GetScrollbarSize().CP(scale); |
1698 | + SetMinimumWidth(active_width); |
1699 | + SetMaximumWidth(active_width); |
1700 | + |
1701 | + int buttons_height = style.GetScrollbarButtonsSize().CP(scale); |
1702 | + _scroll_up_button->SetMaximumHeight(buttons_height); |
1703 | + _scroll_up_button->SetMinimumHeight(buttons_height); |
1704 | + _scroll_down_button->SetMaximumHeight(buttons_height); |
1705 | + _scroll_down_button->SetMinimumHeight(buttons_height); |
1706 | + |
1707 | + int slider_width = style.GetOverlayScrollbarSize().CP(scale); |
1708 | |
1709 | if (_track->IsMouseInside() || _track->IsMouseOwner() || |
1710 | _slider->IsMouseInside() || _slider->IsMouseOwner() || |
1711 | area_prox_->IsMouseNear()) |
1712 | { |
1713 | is_hovering = true; |
1714 | - slider_width = ACTIVE_WIDTH.CP(scale); |
1715 | + slider_width = active_width; |
1716 | } |
1717 | |
1718 | hovering = is_hovering; |
1719 | @@ -152,4 +153,3 @@ |
1720 | |
1721 | } // namespace dash |
1722 | } // namespace unity |
1723 | - |
1724 | |
1725 | === modified file 'unity-shared/PlacesVScrollBar.cpp' |
1726 | --- unity-shared/PlacesVScrollBar.cpp 2015-11-06 18:05:38 +0000 |
1727 | +++ unity-shared/PlacesVScrollBar.cpp 2016-02-25 15:59:57 +0000 |
1728 | @@ -23,39 +23,30 @@ |
1729 | |
1730 | #include "PlacesVScrollBar.h" |
1731 | #include "unity-shared/CairoTexture.h" |
1732 | -#include "unity-shared/RawPixel.h" |
1733 | +#include "unity-shared/DashStyle.h" |
1734 | #include "unity-shared/GraphicsUtils.h" |
1735 | |
1736 | namespace unity |
1737 | { |
1738 | namespace dash |
1739 | { |
1740 | -namespace |
1741 | -{ |
1742 | -const RawPixel BUTTONS_HEIGHT = 0_em; |
1743 | -const RawPixel WIDTH = 3_em; |
1744 | -} |
1745 | |
1746 | PlacesVScrollBar::PlacesVScrollBar(NUX_FILE_LINE_DECL) |
1747 | : nux::VScrollBar(NUX_FILE_LINE_PARAM) |
1748 | , scale(1.0) |
1749 | , hovering(false) |
1750 | { |
1751 | - UpdateSize(); |
1752 | + Style::Instance().changed.connect(sigc::mem_fun(this, &PlacesVScrollBar::OnStyleChanged)); |
1753 | scale.changed.connect([this] (double scale) { |
1754 | - UpdateSize(); |
1755 | QueueRelayout(); |
1756 | QueueDraw(); |
1757 | }); |
1758 | } |
1759 | |
1760 | -void PlacesVScrollBar::UpdateSize() |
1761 | +void PlacesVScrollBar::OnStyleChanged() |
1762 | { |
1763 | - _scroll_up_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
1764 | - _scroll_up_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
1765 | - |
1766 | - _scroll_down_button->SetMaximumHeight(BUTTONS_HEIGHT.CP(scale)); |
1767 | - _scroll_down_button->SetMinimumHeight(BUTTONS_HEIGHT.CP(scale)); |
1768 | + slider_texture_.Release(); |
1769 | + QueueDraw(); |
1770 | } |
1771 | |
1772 | void PlacesVScrollBar::Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) |
1773 | @@ -95,7 +86,10 @@ |
1774 | nux::GetPainter().PushDrawLayer(graphics_engine, base, &layer); |
1775 | |
1776 | if (hovering) |
1777 | - graphics_engine.QRP_Color(base.x, base.y, base.width, base.height, nux::color::White * 0.4); |
1778 | + { |
1779 | + auto const& track_color = Style::Instance().GetScrollbarTrackColor(); |
1780 | + graphics_engine.QRP_Color(base.x, base.y, base.width, base.height, track_color * track_color.alpha); |
1781 | + } |
1782 | |
1783 | UpdateTexture(slider_geo); |
1784 | graphics_engine.QRP_1Tex(base.x + base.width - slider_geo.width, |
1785 | @@ -122,6 +116,7 @@ |
1786 | if (slider_texture_ && slider_texture_->GetWidth() == width && slider_texture_->GetHeight() == height) |
1787 | return; |
1788 | |
1789 | + auto& style = Style::Instance(); |
1790 | double unscaled_width = static_cast<double>(width) / scale(); |
1791 | double unscaled_height = static_cast<double>(height) / scale(); |
1792 | |
1793 | @@ -132,9 +127,12 @@ |
1794 | cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR); |
1795 | cairo_paint(cr); |
1796 | |
1797 | + auto const& color = hovering ? style.GetScrollbarColor() : style.GetOverlayScrollbarColor(); |
1798 | + double radius = hovering ? style.GetScrollbarCornerRadius() : style.GetOverlayScrollbarCornerRadius(); |
1799 | + |
1800 | cairo_set_operator(cr, CAIRO_OPERATOR_OVER); |
1801 | - cairo_set_source_rgba(cr, 1.0f, 1.0f, 1.0f, 1.0f); |
1802 | - cg.DrawRoundedRectangle(cr, 1.0f, 0, 0, unscaled_width / 2.0, unscaled_width, unscaled_height - 2.0); |
1803 | + cairo_set_source_rgba(cr, color.red, color.green, color.blue, color.alpha); |
1804 | + cg.DrawRoundedRectangle(cr, 1.0f, 0, 0, radius, unscaled_width, unscaled_height - 2.0); |
1805 | cairo_fill(cr); |
1806 | |
1807 | slider_texture_ = texture_ptr_from_cairo_graphics(cg); |
1808 | |
1809 | === modified file 'unity-shared/PlacesVScrollBar.h' |
1810 | --- unity-shared/PlacesVScrollBar.h 2015-11-06 18:05:38 +0000 |
1811 | +++ unity-shared/PlacesVScrollBar.h 2016-02-25 15:59:57 +0000 |
1812 | @@ -40,8 +40,8 @@ |
1813 | void DrawContent(nux::GraphicsEngine& gfxContext, bool forceDraw); |
1814 | |
1815 | private: |
1816 | - void UpdateSize(); |
1817 | void UpdateTexture(nux::Geometry const&); |
1818 | + void OnStyleChanged(); |
1819 | |
1820 | private: |
1821 | nux::ObjectPtr<nux::BaseTexture> slider_texture_; |
1822 | |
1823 | === modified file 'unity-shared/SearchBar.cpp' |
1824 | --- unity-shared/SearchBar.cpp 2015-06-27 04:44:51 +0000 |
1825 | +++ unity-shared/SearchBar.cpp 2016-02-25 15:59:57 +0000 |
1826 | @@ -38,6 +38,7 @@ |
1827 | #include "RawPixel.h" |
1828 | #include "SearchBarSpinner.h" |
1829 | #include "StaticCairoText.h" |
1830 | +#include "ThemeSettings.h" |
1831 | #include "UnitySettings.h" |
1832 | |
1833 | namespace unity |
1834 | @@ -226,8 +227,8 @@ |
1835 | expand_icon_->mouse_click.connect(mouse_expand); |
1836 | } |
1837 | |
1838 | - sig_manager_.Add<void, GtkSettings*>(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::mem_fun(this, &SearchBar::OnFontChanged))); |
1839 | - OnFontChanged(); |
1840 | + UpdateFont(); |
1841 | + theme::Settings::Get()->font.changed.connect(sigc::hide(sigc::mem_fun(this, &SearchBar::UpdateFont))); |
1842 | |
1843 | search_hint.changed.connect([this](std::string const& s) { OnSearchHintChanged(); }); |
1844 | search_string.SetGetterFunction([this] { return pango_entry_->GetText(); }); |
1845 | @@ -320,30 +321,23 @@ |
1846 | UpdateSearchBarSize(); |
1847 | } |
1848 | |
1849 | -void SearchBar::OnFontChanged() |
1850 | +void SearchBar::UpdateFont() |
1851 | { |
1852 | - glib::String font_name; |
1853 | - PangoFontDescription* desc; |
1854 | - std::ostringstream font_desc; |
1855 | - |
1856 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); |
1857 | - |
1858 | - desc = pango_font_description_from_string(font_name.Value()); |
1859 | + auto* desc = pango_font_description_from_string(theme::Settings::Get()->font().c_str()); |
1860 | + |
1861 | if (desc) |
1862 | { |
1863 | pango_entry_->SetFontFamily(pango_font_description_get_family(desc)); |
1864 | pango_entry_->SetFontSize(PANGO_ENTRY_FONT_SIZE.CP(scale * Settings::Instance().font_scaling())); |
1865 | pango_entry_->SetFontOptions(gdk_screen_get_font_options(gdk_screen_get_default())); |
1866 | |
1867 | - font_desc << pango_font_description_get_family(desc) << " " << HINT_LABEL_FONT_STYLE << " " << HINT_LABEL_FONT_SIZE; |
1868 | - hint_->SetFont(font_desc.str().c_str()); |
1869 | + auto font_desc = glib::gchar_to_string(pango_font_description_get_family(desc)) + " " + HINT_LABEL_FONT_STYLE + " " + HINT_LABEL_FONT_SIZE; |
1870 | + hint_->SetFont(font_desc.c_str()); |
1871 | |
1872 | if (show_filter_hint_) |
1873 | { |
1874 | - font_desc.str(""); |
1875 | - font_desc.clear(); |
1876 | - font_desc << pango_font_description_get_family(desc) << " " << SHOW_FILTERS_LABEL_FONT_STYLE << " " << SHOW_FILTERS_LABEL_FONT_SIZE; |
1877 | - show_filters_->SetFont(font_desc.str().c_str()); |
1878 | + font_desc = glib::gchar_to_string(pango_font_description_get_family(desc)) + " " + SHOW_FILTERS_LABEL_FONT_STYLE + " " + SHOW_FILTERS_LABEL_FONT_SIZE; |
1879 | + show_filters_->SetFont(font_desc.c_str()); |
1880 | } |
1881 | |
1882 | pango_font_description_free(desc); |
1883 | |
1884 | === modified file 'unity-shared/SearchBar.h' |
1885 | --- unity-shared/SearchBar.h 2015-06-27 04:44:51 +0000 |
1886 | +++ unity-shared/SearchBar.h 2016-02-25 15:59:57 +0000 |
1887 | @@ -73,7 +73,7 @@ |
1888 | sigc::signal<void, std::string const&> live_search_reached; |
1889 | |
1890 | private: |
1891 | - void OnFontChanged(); |
1892 | + void UpdateFont(); |
1893 | void OnSearchHintChanged(); |
1894 | |
1895 | void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); |
1896 | |
1897 | === modified file 'unity-shared/StaticCairoText.cpp' |
1898 | --- unity-shared/StaticCairoText.cpp 2015-02-13 17:19:08 +0000 |
1899 | +++ unity-shared/StaticCairoText.cpp 2016-02-25 15:59:57 +0000 |
1900 | @@ -33,9 +33,10 @@ |
1901 | #include <pango/pangocairo.h> |
1902 | |
1903 | #include <UnityCore/GLibWrapper.h> |
1904 | -#include <UnityCore/GLibSignal.h> |
1905 | +#include <UnityCore/ConnectionManager.h> |
1906 | |
1907 | #include "CairoTexture.h" |
1908 | +#include "ThemeSettings.h" |
1909 | #include "UnitySettings.h" |
1910 | |
1911 | using namespace nux; |
1912 | @@ -106,7 +107,7 @@ |
1913 | float line_spacing_; |
1914 | double scale_; |
1915 | |
1916 | - glib::Signal<void, GtkSettings*, GParamSpec*> font_changed_; |
1917 | + connection::Wrapper font_changed_conn_; |
1918 | }; |
1919 | |
1920 | StaticCairoText::Impl::Impl(StaticCairoText* parent, std::string const& text) |
1921 | @@ -127,8 +128,9 @@ |
1922 | , line_spacing_(0.5) |
1923 | , scale_(1.0f) |
1924 | { |
1925 | - font_changed_.Connect(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged)))); |
1926 | - Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged))); |
1927 | + auto font_changed_cb = sigc::hide(sigc::mem_fun(this, &Impl::OnFontChanged)); |
1928 | + font_changed_conn_ = theme::Settings::Get()->font.changed.connect(font_changed_cb); |
1929 | + Settings::Instance().font_scaling.changed.connect(font_changed_cb); |
1930 | } |
1931 | |
1932 | PangoEllipsizeMode StaticCairoText::Impl::GetPangoEllipsizeMode() const |
1933 | @@ -410,6 +412,7 @@ |
1934 | { |
1935 | if (pimpl->font_ != font) |
1936 | { |
1937 | + font.empty() ? pimpl->font_changed_conn_->unblock() : pimpl->font_changed_conn_->block(); |
1938 | pimpl->font_ = font; |
1939 | pimpl->need_new_extent_cache_ = true; |
1940 | Size s = GetTextExtents(); |
1941 | @@ -552,12 +555,7 @@ |
1942 | std::string StaticCairoText::Impl::GetEffectiveFont() const |
1943 | { |
1944 | if (font_.empty()) |
1945 | - { |
1946 | - GtkSettings* settings = gtk_settings_get_default(); // not ref'ed |
1947 | - glib::String font_name; |
1948 | - g_object_get(settings, "gtk-font-name", &font_name, NULL); |
1949 | - return font_name.Str(); |
1950 | - } |
1951 | + return theme::Settings::Get()->font(); |
1952 | |
1953 | return font_; |
1954 | } |
1955 | @@ -577,7 +575,7 @@ |
1956 | } |
1957 | |
1958 | Size result; |
1959 | - std::string font = GetEffectiveFont(); |
1960 | + std::string const& font = GetEffectiveFont(); |
1961 | nux::Size layout_size(-1, lines_ < 0 ? lines_ : std::numeric_limits<int>::min()); |
1962 | |
1963 | surface = cairo_image_surface_create(CAIRO_FORMAT_A1, 1, 1); |
1964 | |
1965 | === modified file 'unity-shared/TextInput.cpp' |
1966 | --- unity-shared/TextInput.cpp 2016-01-15 01:41:04 +0000 |
1967 | +++ unity-shared/TextInput.cpp 2016-02-25 15:59:57 +0000 |
1968 | @@ -36,6 +36,7 @@ |
1969 | #include "PreviewStyle.h" |
1970 | #include "RawPixel.h" |
1971 | #include "TextureCache.h" |
1972 | +#include "ThemeSettings.h" |
1973 | #include "UnitySettings.h" |
1974 | |
1975 | namespace unity |
1976 | @@ -141,7 +142,7 @@ |
1977 | layered_layout_->SetActiveLayerN(1); |
1978 | layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX); |
1979 | |
1980 | - UpdateSize(); |
1981 | + UpdateFont(); |
1982 | |
1983 | // Caps lock warning |
1984 | warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale))); |
1985 | @@ -181,8 +182,7 @@ |
1986 | spinner_->scale = scale(); |
1987 | layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL); |
1988 | |
1989 | - OnFontChanged(); |
1990 | - sig_manager_.Add<void, GtkSettings*>(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::mem_fun(this, &TextInput::OnFontChanged))); |
1991 | + theme::Settings::Get()->font.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateFont))); |
1992 | sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) { CheckLocks(); }); |
1993 | |
1994 | input_string.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_input_string)); |
1995 | @@ -320,9 +320,6 @@ |
1996 | |
1997 | void TextInput::LoadWarningTooltip() |
1998 | { |
1999 | - glib::String font_name; |
2000 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); |
2001 | - |
2002 | glib::Object<GtkStyleContext> style_context(gtk_style_context_new()); |
2003 | std::shared_ptr<GtkWidgetPath> widget_path(gtk_widget_path_new(), gtk_widget_path_free); |
2004 | gtk_widget_path_append_type(widget_path.get(), GTK_TYPE_TOOLTIP); |
2005 | @@ -333,7 +330,8 @@ |
2006 | glib::Object<PangoContext> context(gdk_pango_context_get()); |
2007 | glib::Object<PangoLayout> layout(pango_layout_new(context)); |
2008 | |
2009 | - std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free); |
2010 | + auto const& font = theme::Settings::Get()->font(); |
2011 | + std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font.c_str()), pango_font_description_free); |
2012 | pango_context_set_font_description(context, desc.get()); |
2013 | pango_context_set_language(context, gtk_get_default_language()); |
2014 | pango_cairo_context_set_resolution(context, 96.0 * Settings::Instance().font_scaling()); |
2015 | @@ -369,14 +367,10 @@ |
2016 | warning_tooltip_ = texture_ptr_from_cairo_graphics(cg); |
2017 | } |
2018 | |
2019 | -void TextInput::OnFontChanged() |
2020 | +void TextInput::UpdateFont() |
2021 | { |
2022 | - glib::String font_name; |
2023 | - PangoFontDescription* desc; |
2024 | - |
2025 | - g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL); |
2026 | - |
2027 | - desc = pango_font_description_from_string(font_name.Value()); |
2028 | + auto* desc = pango_font_description_from_string(theme::Settings::Get()->font().c_str()); |
2029 | + |
2030 | if (desc) |
2031 | { |
2032 | pango_entry_->SetFontFamily(pango_font_description_get_family(desc)); |
2033 | |
2034 | === modified file 'unity-shared/TextInput.h' |
2035 | --- unity-shared/TextInput.h 2016-01-15 01:41:04 +0000 |
2036 | +++ unity-shared/TextInput.h 2016-02-25 15:59:57 +0000 |
2037 | @@ -75,7 +75,7 @@ |
2038 | nux::Property<double> scale; |
2039 | |
2040 | private: |
2041 | - void OnFontChanged(); |
2042 | + void UpdateFont(); |
2043 | void UpdateHintFont(); |
2044 | void UpdateHintColor(); |
2045 | void Draw(nux::GraphicsEngine& GfxContext, bool force_draw); |
2046 | |
2047 | === added file 'unity-shared/ThemeSettings.cpp' |
2048 | --- unity-shared/ThemeSettings.cpp 1970-01-01 00:00:00 +0000 |
2049 | +++ unity-shared/ThemeSettings.cpp 2016-02-25 15:59:57 +0000 |
2050 | @@ -0,0 +1,145 @@ |
2051 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
2052 | +/* |
2053 | + * Copyright (C) 2016 Canonical Ltd |
2054 | + * |
2055 | + * This program is free software: you can redistribute it and/or modify |
2056 | + * it under the terms of the GNU General Public License version 3 as |
2057 | + * published by the Free Software Foundation. |
2058 | + * |
2059 | + * This program is distributed in the hope that it will be useful, |
2060 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2061 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2062 | + * GNU General Public License for more details. |
2063 | + * |
2064 | + * You should have received a copy of the GNU General Public License |
2065 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2066 | + * |
2067 | + * Authored by: Marco Trevisan <marco.trevisan@canonical.com> |
2068 | + */ |
2069 | + |
2070 | +#include "config.h" |
2071 | +#include "ThemeSettings.h" |
2072 | + |
2073 | +#include <NuxCore/Logger.h> |
2074 | +#include <UnityCore/DesktopUtilities.h> |
2075 | +#include <UnityCore/ConnectionManager.h> |
2076 | +#include "FontSettings.h" |
2077 | + |
2078 | +namespace unity |
2079 | +{ |
2080 | +namespace theme |
2081 | +{ |
2082 | +namespace |
2083 | +{ |
2084 | +DECLARE_LOGGER(logger, "unity.theme.settings"); |
2085 | + |
2086 | +const std::array<std::string, 2> THEMED_FILE_EXTENSIONS = { "svg", "png" }; |
2087 | +const std::string UNITY_THEME_NAME = "unity-icon-theme"; |
2088 | +} |
2089 | + |
2090 | +struct Settings::Impl |
2091 | +{ |
2092 | + Impl(Settings* parent) |
2093 | + : parent_(parent) |
2094 | + , theme_setting_("gtk-theme-name") |
2095 | + , font_setting_("gtk-font-name") |
2096 | + { |
2097 | + parent_->theme = theme_setting_(); |
2098 | + parent_->font = font_setting_(); |
2099 | + |
2100 | + connections_.Add(theme_setting_.changed.connect([this] (std::string const& theme) { |
2101 | + parent_->theme = theme; |
2102 | + LOG_INFO(logger) << "gtk-theme-name changed to " << parent_->theme(); |
2103 | + })); |
2104 | + |
2105 | + connections_.Add(font_setting_.changed.connect([this] (std::string const& font) { |
2106 | + parent_->font = font; |
2107 | + LOG_INFO(logger) << "gtk-font-name changed to " << parent_->font(); |
2108 | + })); |
2109 | + |
2110 | + unity_icon_theme_ = gtk_icon_theme_new(); |
2111 | + gtk_icon_theme_set_custom_theme(unity_icon_theme_, UNITY_THEME_NAME.c_str()); |
2112 | + |
2113 | + icon_theme_changed_.Connect(gtk_icon_theme_get_default(), "changed", [this] (GtkIconTheme*) { |
2114 | + LOG_INFO(logger) << "gtk default icon theme changed"; |
2115 | + parent_->icons_changed.emit(); |
2116 | + }); |
2117 | + } |
2118 | + |
2119 | + std::string ThemedFilePath(std::string const& base_filename, std::vector<std::string> const& extra_folders, std::vector<std::string> extensions) const |
2120 | + { |
2121 | + auto const& theme = parent_->theme(); |
2122 | + auto const& home_dir = DesktopUtilities::GetUserHomeDirectory(); |
2123 | + auto const& data_dir = DesktopUtilities::GetUserDataDirectory(); |
2124 | + const char* gtk_prefix = g_getenv("GTK_DATA_PREFIX"); |
2125 | + |
2126 | + if (!gtk_prefix || gtk_prefix[0] == '\0') |
2127 | + gtk_prefix = GTK_PREFIX; |
2128 | + |
2129 | + extensions.insert(end(extensions), begin(THEMED_FILE_EXTENSIONS), end(THEMED_FILE_EXTENSIONS)); |
2130 | + |
2131 | + for (auto const& extension : extensions) |
2132 | + { |
2133 | + auto filename = base_filename + '.' + extension; |
2134 | + glib::String subpath(g_build_filename(theme.c_str(), "unity", filename.c_str(), nullptr)); |
2135 | + glib::String local_file(g_build_filename(data_dir.c_str(), "themes", subpath.Value(), nullptr)); |
2136 | + |
2137 | + if (g_file_test(local_file, G_FILE_TEST_EXISTS)) |
2138 | + return local_file.Str(); |
2139 | + |
2140 | + glib::String home_file(g_build_filename(home_dir.c_str(), ".themes", subpath.Value(), nullptr)); |
2141 | + |
2142 | + if (g_file_test(home_file, G_FILE_TEST_EXISTS)) |
2143 | + return home_file.Str(); |
2144 | + |
2145 | + glib::String theme_file(g_build_filename(gtk_prefix, "share", "themes", subpath.Value(), nullptr)); |
2146 | + |
2147 | + if (g_file_test(theme_file, G_FILE_TEST_EXISTS)) |
2148 | + return theme_file.Str(); |
2149 | + |
2150 | + for (auto const& folder : extra_folders) |
2151 | + { |
2152 | + glib::String path(g_build_filename(folder.c_str(), filename.c_str(), nullptr)); |
2153 | + |
2154 | + if (g_file_test(path, G_FILE_TEST_EXISTS)) |
2155 | + return path.Str(); |
2156 | + } |
2157 | + } |
2158 | + |
2159 | + return std::string(); |
2160 | + } |
2161 | + |
2162 | + Settings* parent_; |
2163 | + FontSettings font_settings_; |
2164 | + gtk::Setting<std::string> theme_setting_; |
2165 | + gtk::Setting<std::string> font_setting_; |
2166 | + glib::Signal<void, GtkIconTheme*> icon_theme_changed_; |
2167 | + glib::Object<GtkIconTheme> unity_icon_theme_; |
2168 | + connection::Manager connections_; |
2169 | +}; |
2170 | + |
2171 | +Settings::Ptr const& Settings::Get() |
2172 | +{ |
2173 | + static Settings::Ptr theme(new Settings()); |
2174 | + return theme; |
2175 | +} |
2176 | + |
2177 | +Settings::Settings() |
2178 | + : impl_(new Impl(this)) |
2179 | +{} |
2180 | + |
2181 | +Settings::~Settings() |
2182 | +{} |
2183 | + |
2184 | +std::string Settings::ThemedFilePath(std::string const& basename, std::vector<std::string> const& extra_folders, std::vector<std::string> const& extra_extensions) const |
2185 | +{ |
2186 | + return impl_->ThemedFilePath(basename, extra_folders, extra_extensions); |
2187 | +} |
2188 | + |
2189 | +GtkIconTheme* Settings::UnityIconTheme() const |
2190 | +{ |
2191 | + return impl_->unity_icon_theme_; |
2192 | +} |
2193 | + |
2194 | +} // theme namespace |
2195 | +} // unity namespace |
2196 | |
2197 | === added file 'unity-shared/ThemeSettings.h' |
2198 | --- unity-shared/ThemeSettings.h 1970-01-01 00:00:00 +0000 |
2199 | +++ unity-shared/ThemeSettings.h 2016-02-25 15:59:57 +0000 |
2200 | @@ -0,0 +1,61 @@ |
2201 | +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- |
2202 | +/* |
2203 | + * Copyright (C) 2016 Canonical Ltd |
2204 | + * |
2205 | + * This program is free software: you can redistribute it and/or modify |
2206 | + * it under the terms of the GNU General Public License version 3 as |
2207 | + * published by the Free Software Foundation. |
2208 | + * |
2209 | + * This program is distributed in the hope that it will be useful, |
2210 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2211 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2212 | + * GNU General Public License for more details. |
2213 | + * |
2214 | + * You should have received a copy of the GNU General Public License |
2215 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
2216 | + * |
2217 | + * Authored by: Marco Trevisan <marco.trevisan@canonical.com> |
2218 | + */ |
2219 | + |
2220 | +#ifndef UNITY_THEME_SETTINGS |
2221 | +#define UNITY_THEME_SETTINGS |
2222 | + |
2223 | +#include <memory> |
2224 | +#include <NuxCore/Property.h> |
2225 | + |
2226 | +struct _GtkIconTheme; |
2227 | + |
2228 | +namespace unity |
2229 | +{ |
2230 | +namespace theme |
2231 | +{ |
2232 | + |
2233 | +class Settings |
2234 | +{ |
2235 | +public: |
2236 | + typedef std::shared_ptr<Settings> Ptr; |
2237 | + |
2238 | + static Settings::Ptr const& Get(); |
2239 | + ~Settings(); |
2240 | + |
2241 | + nux::Property<std::string> theme; |
2242 | + nux::Property<std::string> font; |
2243 | + |
2244 | + std::string ThemedFilePath(std::string const& basename, std::vector<std::string> const& extra_folders = {}, std::vector<std::string> const& extra_extensions = {}) const; |
2245 | + _GtkIconTheme* UnityIconTheme() const; |
2246 | + |
2247 | + sigc::signal<void> icons_changed; |
2248 | + |
2249 | +private: |
2250 | + Settings(); |
2251 | + Settings(Settings const&) = delete; |
2252 | + Settings& operator=(Settings const&) = delete; |
2253 | + |
2254 | + struct Impl; |
2255 | + std::unique_ptr<Impl> impl_; |
2256 | +}; |
2257 | + |
2258 | +} // theme namespace |
2259 | +} // unity namespace |
2260 | + |
2261 | +#endif // UNITY_THEME_SETTINGS |
PASSED: Continuous integration, rev:4098 jenkins. qa.ubuntu. com/job/ unity-ci/ 1407/ jenkins. qa.ubuntu. com/job/ unity-xenial- amd64-ci/ 57 jenkins. qa.ubuntu. com/job/ unity-xenial- armhf-ci/ 57 jenkins. qa.ubuntu. com/job/ unity-xenial- i386-ci/ 57
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/unity- ci/1407/ rebuild
http://