Merge lp:~mterry/unity/watch-font-changes into lp:unity

Proposed by Michael Terry
Status: Merged
Approved by: Mirco Müller
Approved revision: no longer in the source branch.
Merged at revision: 750
Proposed branch: lp:~mterry/unity/watch-font-changes
Merge into: lp:unity
Diff against target: 91 lines (+26/-8)
3 files modified
src/StaticCairoText.cpp (+21/-8)
src/StaticCairoText.h (+4/-0)
src/Tooltip.cpp (+1/-0)
To merge this branch: bzr merge lp:~mterry/unity/watch-font-changes
Reviewer Review Type Date Requested Status
Mirco Müller (community) Approve
Review via email: mp+45564@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Mirco Müller (macslow) wrote :

Code is ok, compiles and works. Changing font (size, family, style) on the fly via gnome-appearance-properties does correctly cause tooltips and quicklists to update their text-display.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/StaticCairoText.cpp'
2--- src/StaticCairoText.cpp 2011-01-07 16:37:51 +0000
3+++ src/StaticCairoText.cpp 2011-01-07 21:10:12 +0000
4@@ -43,20 +43,19 @@
5
6 StaticCairoText::~StaticCairoText ()
7 {
8+ GtkSettings* settings = gtk_settings_get_default (); // not ref'ed
9+ g_signal_handlers_disconnect_by_func (settings,
10+ (void *) &StaticCairoText::OnFontChanged,
11+ this);
12 delete (_cairoGraphics);
13 delete (_texture2D);
14 }
15
16 void StaticCairoText::PreLayoutManagement ()
17 {
18- int textWidth = 0;
19- int textHeight = 0;
20- GtkSettings* settings = gtk_settings_get_default (); // not ref'ed
21- gchar* fontName = NULL;
22-
23- g_object_get (settings, "gtk-font-name", &fontName, NULL);
24- GetTextExtents (fontName, textWidth, textHeight);
25- g_free (fontName);
26+ int textWidth = 0;
27+ int textHeight = 0;
28+ GetTextExtents (textWidth, textHeight);
29
30 _pre_layout_width = GetBaseWidth ();
31 _pre_layout_height = GetBaseHeight ();
32@@ -65,6 +64,12 @@
33
34 if((_texture2D == 0) )
35 {
36+ GtkSettings* settings = gtk_settings_get_default (); // not ref'ed
37+ g_signal_connect (settings, "notify::gtk-font-name",
38+ (GCallback) &StaticCairoText::OnFontChanged, this);
39+ g_signal_connect (settings, "notify::gtk-xft-dpi",
40+ (GCallback) &StaticCairoText::OnFontChanged, this);
41+
42 UpdateTexture ();
43 }
44
45@@ -322,4 +327,12 @@
46 delete _cairoGraphics;
47 }
48
49+void StaticCairoText::OnFontChanged (GObject *gobject, GParamSpec *pspec,
50+ gpointer data)
51+{
52+ StaticCairoText *self = (StaticCairoText*) data;
53+ self->UpdateTexture ();
54+ self->sigFontChanged.emit (self);
55+}
56+
57 }
58
59=== modified file 'src/StaticCairoText.h'
60--- src/StaticCairoText.h 2010-12-13 20:10:14 +0000
61+++ src/StaticCairoText.h 2011-01-07 21:10:12 +0000
62@@ -71,6 +71,7 @@
63
64 sigc::signal<void, StaticCairoText*> sigTextChanged;
65 sigc::signal<void, StaticCairoText*> sigTextColorChanged;
66+ sigc::signal<void, StaticCairoText*> sigFontChanged;
67
68 private:
69 NString _text;
70@@ -91,6 +92,9 @@
71 Color color);
72
73 void UpdateTexture ();
74+
75+ static void OnFontChanged (GObject *gobject, GParamSpec *pspec,
76+ gpointer data);
77 };
78 }
79
80
81=== modified file 'src/Tooltip.cpp'
82--- src/Tooltip.cpp 2011-01-07 16:37:51 +0000
83+++ src/Tooltip.cpp 2011-01-07 21:10:12 +0000
84@@ -68,6 +68,7 @@
85
86 _tooltip_text = new nux::StaticCairoText (_labelText.GetTCharPtr (), NUX_TRACKER_LOCATION);
87 _tooltip_text->sigTextChanged.connect (sigc::mem_fun (this, &Tooltip::RecvCairoTextChanged));
88+ _tooltip_text->sigFontChanged.connect (sigc::mem_fun (this, &Tooltip::RecvCairoTextChanged));
89 _tooltip_text->Reference();
90
91 _vlayout->AddView(_tooltip_text, 1, eCenter, eFull);