Merge lp:~3v1n0/unity/panel-p-style into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Thomi Richards
Approved revision: no longer in the source branch.
Merged at revision: 2236
Proposed branch: lp:~3v1n0/unity/panel-p-style
Merge into: lp:unity
Diff against target: 409 lines (+162/-78)
2 files modified
plugins/unityshell/src/PanelStyle.cpp (+137/-61)
plugins/unityshell/src/PanelStyle.h (+25/-17)
To merge this branch: bzr merge lp:~3v1n0/unity/panel-p-style
Reviewer Review Type Date Requested Status
Tim Penhey (community) Approve
Review via email: mp+100134@code.launchpad.net

Commit message

Panel style changes.

Description of the change

To post a comment you must log in.
Revision history for this message
Tim Penhey (thumper) wrote :

You can use the operator & on glib::String instead of AsOutParam.

I added that so the glib::String could be used more naturally with the glib functions.

Apart from that, this looks good.

review: Approve
Revision history for this message
Tim Penhey (thumper) wrote :

Thanks

review: Approve
Revision history for this message
Unity Merger (unity-merger) wrote :

No commit message specified.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/unityshell/src/PanelStyle.cpp'
2--- plugins/unityshell/src/PanelStyle.cpp 2012-03-21 12:31:11 +0000
3+++ plugins/unityshell/src/PanelStyle.cpp 2012-04-02 09:37:20 +0000
4@@ -15,12 +15,15 @@
5 *
6 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
7 * Neil Jagdish Patel <neil.patel@canonical.com>
8+ * Marco Trevisan <3v1n0@ubuntu.com>
9 */
10
11 #include "config.h"
12
13 #include <math.h>
14 #include <gtk/gtk.h>
15+#include <gconf/gconf-client.h>
16+#include <boost/algorithm/string/predicate.hpp>
17
18 #include <Nux/Nux.h>
19 #include <NuxGraphics/GraphicsEngine.h>
20@@ -40,7 +43,11 @@
21 {
22 Style* style_instance = nullptr;
23
24-nux::logging::Logger logger("unity.panel");
25+nux::logging::Logger logger("unity.panel.style");
26+
27+const std::string METACITY_SETTINGS_PATH("/apps/metacity/general/");
28+const std::string PANEL_TITLE_FONT_KEY("/apps/metacity/general/titlebar_font");
29+const std::string HIGH_CONTRAST_THEME_PREFIX("HighContrast");
30
31 nux::Color ColorFromGdkRGBA(GdkRGBA const& color)
32 {
33@@ -54,7 +61,7 @@
34
35 Style::Style()
36 : panel_height(24)
37- , _theme_name(NULL)
38+ , _style_context(gtk_style_context_new())
39 {
40 if (style_instance)
41 {
42@@ -65,8 +72,6 @@
43 style_instance = this;
44 }
45
46- _style_context = gtk_style_context_new();
47-
48 GtkWidgetPath* widget_path = gtk_widget_path_new();
49 gint pos = gtk_widget_path_append_type(widget_path, GTK_TYPE_WINDOW);
50 gtk_widget_path_iter_set_name(widget_path, pos, "UnityPanelWidget");
51@@ -77,23 +82,42 @@
52
53 gtk_widget_path_free(widget_path);
54
55- _gtk_theme_changed_id = g_signal_connect(gtk_settings_get_default(), "notify::gtk-theme-name",
56- G_CALLBACK(Style::OnGtkThemeChanged), this);
57+ GtkSettings* settings = gtk_settings_get_default();
58+
59+ _style_changed_signal.Connect(settings, "notify::gtk-theme-name",
60+ [&] (GtkSettings*, GParamSpec*) {
61+ Refresh();
62+ });
63+
64+ _font_changed_signal.Connect(settings, "notify::gtk-font-name",
65+ [&] (GtkSettings*, GParamSpec*) {
66+ changed.emit();
67+ });
68+
69+ _dpi_changed_signal.Connect(settings, "notify::gtk-xft-dpi",
70+ [&] (GtkSettings*, GParamSpec*) {
71+ changed.emit();
72+ });
73+
74+ GConfClient* client = gconf_client_get_default();
75+ gconf_client_add_dir(client, METACITY_SETTINGS_PATH.c_str(), GCONF_CLIENT_PRELOAD_NONE, nullptr);
76+ _gconf_notify_id = gconf_client_notify_add(client, PANEL_TITLE_FONT_KEY.c_str(),
77+ [] (GConfClient*,guint,GConfEntry*, gpointer data)
78+ {
79+ auto self = static_cast<Style*>(data);
80+ self->changed.emit();
81+ }, this, nullptr, nullptr);
82
83 Refresh();
84 }
85
86 Style::~Style()
87 {
88- if (_gtk_theme_changed_id)
89- g_signal_handler_disconnect(gtk_settings_get_default(),
90- _gtk_theme_changed_id);
91-
92- g_object_unref(_style_context);
93- g_free(_theme_name);
94-
95 if (style_instance == this)
96 style_instance = nullptr;
97+
98+ if (_gconf_notify_id)
99+ gconf_client_notify_remove(gconf_client_get_default(), _gconf_notify_id);
100 }
101
102 Style& Style::Instance()
103@@ -106,24 +130,33 @@
104 return *style_instance;
105 }
106
107-
108 void Style::Refresh()
109 {
110- GdkRGBA rgba_text;
111-
112- if (_theme_name)
113- g_free(_theme_name);
114-
115- _theme_name = NULL;
116- g_object_get(gtk_settings_get_default(), "gtk-theme-name", &_theme_name, NULL);
117+ GdkRGBA rgba_text_color;
118+ glib::String theme_name;
119+ bool updated = false;
120+
121+ GtkSettings* settings = gtk_settings_get_default();
122+ g_object_get(settings, "gtk-theme-name", &theme_name, nullptr);
123+
124+ if (_theme_name != theme_name.Str())
125+ {
126+ _theme_name = theme_name.Str();
127+ updated = true;
128+ }
129
130 gtk_style_context_invalidate(_style_context);
131-
132- gtk_style_context_get_color(_style_context, GTK_STATE_FLAG_NORMAL, &rgba_text);
133-
134- _text = ColorFromGdkRGBA(rgba_text);
135-
136- changed.emit();
137+ gtk_style_context_get_color(_style_context, GTK_STATE_FLAG_NORMAL, &rgba_text_color);
138+ nux::Color const& new_text_color = ColorFromGdkRGBA(rgba_text_color);
139+
140+ if (_text_color != new_text_color)
141+ {
142+ _text_color = new_text_color;
143+ updated = true;
144+ }
145+
146+ if (updated)
147+ changed.emit();
148 }
149
150 GtkStyleContext* Style::GetStyleContext()
151@@ -131,15 +164,6 @@
152 return _style_context;
153 }
154
155-void Style::OnGtkThemeChanged(GObject* gobject,
156- GParamSpec* pspec,
157- gpointer data)
158-{
159- Style* self = (Style*) data;
160-
161- self->Refresh();
162-}
163-
164 nux::NBitmapData* Style::GetBackground(int width, int height, float opacity)
165 {
166 nux::CairoGraphics context(CAIRO_FORMAT_ARGB32, width, height);
167@@ -158,8 +182,9 @@
168 nux::BaseTexture* Style::GetWindowButton(WindowButtonType type, WindowState state)
169 {
170 nux::BaseTexture* texture = NULL;
171- const char* names[] = { "close", "minimize", "unmaximize" };
172- const char* states[] = { "", "_focused_prelight", "_focused_pressed" };
173+ std::string names[] = { "close", "minimize", "unmaximize", "maximize" };
174+ std::string states[] = { "", "_focused_prelight", "_focused_pressed", "_unfocused",
175+ "_unfocused", "_unfocused_prelight", "_unfocused_pressed"};
176
177 std::ostringstream subpath;
178 subpath << "unity/" << names[static_cast<int>(type)]
179@@ -169,7 +194,7 @@
180 const char* home_dir = g_get_home_dir();
181 if (home_dir)
182 {
183- glib::String filename(g_build_filename(home_dir, ".themes", _theme_name, subpath.str().c_str(), NULL));
184+ glib::String filename(g_build_filename(home_dir, ".themes", _theme_name.c_str(), subpath.str().c_str(), NULL));
185
186 if (g_file_test(filename.Value(), G_FILE_TEST_EXISTS))
187 {
188@@ -191,7 +216,7 @@
189 if (!var)
190 var = "/usr";
191
192- glib::String filename(g_build_filename(var, "share", "themes", _theme_name, subpath.str().c_str(), NULL));
193+ glib::String filename(g_build_filename(var, "share", "themes", _theme_name.c_str(), subpath.str().c_str(), NULL));
194
195 if (g_file_test(filename.Value(), G_FILE_TEST_EXISTS))
196 {
197@@ -215,26 +240,48 @@
198 nux::BaseTexture* Style::GetFallbackWindowButton(WindowButtonType type,
199 WindowState state)
200 {
201- int width = 18, height = 18;
202+ int width = 17, height = 17;
203+ int canvas_w = 19, canvas_h = 19;
204+
205+ if (boost::starts_with(_theme_name, HIGH_CONTRAST_THEME_PREFIX))
206+ {
207+ width = 20, height = 20;
208+ canvas_w = 22, canvas_h = 22;
209+ }
210+
211 float w = width / 3.0f;
212 float h = height / 3.0f;
213- nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, 22, 22);
214- cairo_t* cr;
215- nux::Color main = _text;
216+ nux::CairoGraphics cairo_graphics(CAIRO_FORMAT_ARGB32, canvas_w, canvas_h);
217+ nux::Color main = (state != WindowState::UNFOCUSED) ? _text_color : nux::color::Gray;
218+ cairo_t* cr = cairo_graphics.GetContext();
219
220 if (type == WindowButtonType::CLOSE)
221 {
222- main = nux::Color(1.0f, 0.3f, 0.3f, 0.8f);
223- }
224-
225- if (state == WindowState::PRELIGHT)
226- main = main * 1.2f;
227- else if (state == WindowState::PRESSED)
228- main = main * 0.8f;
229- else if (state == WindowState::DISABLED)
230- main = main * 0.5f;
231-
232- cr = cairo_graphics.GetContext();
233+ double alpha = (state != WindowState::UNFOCUSED) ? 0.8f : 0.5;
234+ main = nux::Color(1.0f, 0.3f, 0.3f, alpha);
235+ }
236+
237+ switch (state)
238+ {
239+ case WindowState::PRELIGHT:
240+ main = main * 1.2f;
241+ break;
242+ case WindowState::UNFOCUSED_PRELIGHT:
243+ main = main * 0.9f;
244+ break;
245+ case WindowState::PRESSED:
246+ main = main * 0.8f;
247+ break;
248+ case WindowState::UNFOCUSED_PRESSED:
249+ main = main * 0.7f;
250+ break;
251+ case WindowState::DISABLED:
252+ main = main * 0.5f;
253+ break;
254+ default:
255+ break;
256+ }
257+
258 cairo_translate(cr, 0.5, 0.5);
259 cairo_set_line_width(cr, 1.5f);
260
261@@ -278,29 +325,58 @@
262 }
263
264 cairo_stroke(cr);
265-
266 cairo_destroy(cr);
267
268 return texture_from_cairo_graphics(cairo_graphics);
269 }
270
271-GdkPixbuf* Style::GetHomeButton()
272+glib::Object<GdkPixbuf> Style::GetHomeButton()
273 {
274- GdkPixbuf* pixbuf = NULL;
275+ glib::Object<GdkPixbuf> pixbuf;
276
277 pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
278 "start-here",
279- 24,
280+ panel_height,
281 (GtkIconLookupFlags)0,
282 NULL);
283- if (pixbuf == NULL)
284+ if (!pixbuf)
285 pixbuf = gtk_icon_theme_load_icon(gtk_icon_theme_get_default(),
286 "distributor-logo",
287- 24,
288+ panel_height,
289 (GtkIconLookupFlags)0,
290 NULL);
291 return pixbuf;
292 }
293
294+std::string Style::GetFontDescription(PanelItem item)
295+{
296+ switch (item)
297+ {
298+ case PanelItem::INDICATOR:
299+ case PanelItem::MENU:
300+ {
301+ glib::String font_name;
302+ g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, nullptr);
303+ return font_name.Str();
304+ }
305+ case PanelItem::TITLE:
306+ {
307+ GConfClient* client = gconf_client_get_default();
308+ glib::String font_name(gconf_client_get_string(client, PANEL_TITLE_FONT_KEY.c_str(), nullptr));
309+ return font_name.Str();
310+ }
311+ }
312+
313+ return "";
314+}
315+
316+int Style::GetTextDPI()
317+{
318+ int dpi = 0;
319+ g_object_get(gtk_settings_get_default(), "gtk-xft-dpi", &dpi, nullptr);
320+
321+ return dpi;
322+}
323+
324 } // namespace panel
325 } // namespace unity
326
327=== modified file 'plugins/unityshell/src/PanelStyle.h'
328--- plugins/unityshell/src/PanelStyle.h 2012-03-21 12:31:11 +0000
329+++ plugins/unityshell/src/PanelStyle.h 2012-04-02 09:37:20 +0000
330@@ -16,6 +16,7 @@
331 *
332 * Authored by: Mirco Müller <mirco.mueller@canonical.com>
333 * Neil Jagdish Patel <neil.patel@canonical.com>
334+ * Marco Trevisan <3v1n0@ubuntu.com>
335 */
336
337 #ifndef PANEL_STYLE_H
338@@ -25,6 +26,8 @@
339 #include <NuxCore/Property.h>
340
341 #include <gtk/gtk.h>
342+#include <UnityCore/GLibWrapper.h>
343+#include <UnityCore/GLibSignal.h>
344
345 namespace unity
346 {
347@@ -44,7 +47,17 @@
348 NORMAL,
349 PRELIGHT,
350 PRESSED,
351- DISABLED
352+ DISABLED,
353+ UNFOCUSED,
354+ UNFOCUSED_PRELIGHT,
355+ UNFOCUSED_PRESSED
356+};
357+
358+enum class PanelItem
359+{
360+ INDICATOR,
361+ MENU,
362+ TITLE
363 };
364
365 class Style
366@@ -56,32 +69,27 @@
367 static Style& Instance();
368
369 GtkStyleContext* GetStyleContext();
370-
371 nux::NBitmapData* GetBackground(int width, int height, float opacity);
372-
373 nux::BaseTexture* GetWindowButton(WindowButtonType type, WindowState state);
374 nux::BaseTexture* GetFallbackWindowButton(WindowButtonType type, WindowState state);
375+ glib::Object<GdkPixbuf> GetHomeButton();
376+ std::string GetFontDescription(PanelItem item);
377+ int GetTextDPI();
378
379- GdkPixbuf* GetHomeButton();
380+ nux::Property<int> panel_height;
381
382 sigc::signal<void> changed;
383
384- bool IsAmbianceOrRadiance();
385-
386- nux::Property<int> panel_height;
387-
388 private:
389 void Refresh();
390
391- static void OnGtkThemeChanged(GObject* gobject,
392- GParamSpec* pspec,
393- gpointer data);
394-private:
395- GtkStyleContext* _style_context;
396- char* _theme_name;
397- nux::Color _text;
398-
399- gulong _gtk_theme_changed_id;
400+ glib::Object<GtkStyleContext> _style_context;
401+ glib::Signal<void, GtkSettings*, GParamSpec*> _style_changed_signal;
402+ glib::Signal<void, GtkSettings*, GParamSpec*> _font_changed_signal;
403+ glib::Signal<void, GtkSettings*, GParamSpec*> _dpi_changed_signal;
404+ guint _gconf_notify_id;
405+ std::string _theme_name;
406+ nux::Color _text_color;
407 };
408
409 }