Merge lp:~brandontschaefer/unity/lp.1308288-fix into lp:unity

Proposed by Brandon Schaefer
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3811
Proposed branch: lp:~brandontschaefer/unity/lp.1308288-fix
Merge into: lp:unity
Prerequisite: lp:~brandontschaefer/unity/lp.1307738-fix
Diff against target: 213 lines (+88/-10)
3 files modified
po/POTFILES.in (+1/-0)
unity-shared/TextInput.cpp (+78/-9)
unity-shared/TextInput.h (+9/-1)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lp.1308288-fix
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+215988@code.launchpad.net

Commit message

Lockscreen warning icon needs a tooltip to say what the warning is about!

Description of the change

Lockscreen warning icon needs a tooltip to say what the warning is about!

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Cool, this is fine, and Yes the tooltip should stay above the text, not inside the layout.

The only thing here is that, imho you should initialize both the warning icon and the tooltip only if show_caps_lock is set to true, otherwise we shouldn't spend any time on building them.

204 + IconTexture* warning_;
205 + nux::ObjectPtr<nux::BaseTexture> warning_tooltip_;

Also please move these above the sig_manager_, as that one should be the first one to be destroyed.
Plus, do we really need to keep track of IconTexture* warning_;? You can just always pass it to the lambdas...

Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Yeah, unfortunately:
156 + nux::Geometry warning_geo = warning_->GetGeometry();

I need the warnings geo, which can change depending on if activated or not.

The problem about waiting to init both warning icon/tooltip is the icon it self needs to be placed in the layout before the spinner. If its not, then it'll get added on after the spinner (not sure if we can place it before?).

Im fine doing that with the tooltip though, on a show_caps_lock changed, if warning_tooltip_ == nullptr, then create it.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Ok, sounds fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'po/POTFILES.in'
2--- po/POTFILES.in 2014-04-02 12:31:33 +0000
3+++ po/POTFILES.in 2014-04-23 16:50:25 +0000
4@@ -48,5 +48,6 @@
5 unity-shared/DashStyle.cpp
6 unity-shared/PreviewStyle.cpp
7 unity-shared/SearchBar.cpp
8+unity-shared/TextInput.cpp
9 unity-shared/UScreen.cpp
10 gnome/50-unity-launchers.xml.in
11
12=== modified file 'unity-shared/TextInput.cpp'
13--- unity-shared/TextInput.cpp 2014-04-23 16:50:25 +0000
14+++ unity-shared/TextInput.cpp 2014-04-23 16:50:25 +0000
15@@ -38,10 +38,14 @@
16
17 const int HIGHLIGHT_HEIGHT = 24;
18
19+const RawPixel TOOLTIP_Y_OFFSET = 3_em;
20+const RawPixel TOOLTIP_OFFSET = 10_em;
21 const RawPixel DEFAULT_ICON_SIZE = 22_em;
22
23-std::string WARNING_ICON = "dialog-warning-symbolic";
24+// Caps is on 0x1, couldn't find any #define in /usr/include/X11
25+const int CAPS_STATE_ON = 0x1;
26
27+std::string WARNING_ICON = "dialog-warning-symbolic";
28 // Fonts
29 const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";
30 const int HINT_LABEL_FONT_SIZE = 11;
31@@ -88,6 +92,7 @@
32 , caps_lock_on(false)
33 , last_width_(-1)
34 , last_height_(-1)
35+ , mouse_over_warning_icon_(false)
36 {
37 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
38 layout_->SetLeftAndRightPadding(LEFT_INTERNAL_PADDING, TEXT_INPUT_RIGHT_BORDER);
39@@ -122,19 +127,22 @@
40 layered_layout_->SetActiveLayerN(1);
41 layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
42
43- auto* warning = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE));
44- warning->SetVisible(caps_lock_on());
45- layout_->AddView(warning, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
46- caps_lock_on.changed.connect([this, warning] (bool on) {
47+ warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE));
48+ warning_->SetVisible(caps_lock_on());
49+ layout_->AddView(warning_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
50+ caps_lock_on.changed.connect([this] (bool on) {
51 if (show_caps_lock)
52 {
53- warning->SetVisible(on);
54+ warning_->SetVisible(on);
55 QueueRelayout();
56 QueueDraw();
57 }
58 });
59
60 show_caps_lock.changed.connect([this] (bool changed) {
61+ if (!warning_tooltip_.IsValid())
62+ LoadWarningTooltip();
63+
64 CheckIfCapsLockOn();
65 });
66
67@@ -152,6 +160,16 @@
68 im_active.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_active));
69 im_preedit.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_preedit));
70 input_hint.changed.connect([this](std::string const& s) { OnInputHintChanged(); });
71+
72+ warning_->mouse_enter.connect([this] (int x, int y, int button, int key_flags) {
73+ mouse_over_warning_icon_ = true;
74+ QueueDraw();
75+ });
76+
77+ warning_->mouse_leave.connect([this] (int x, int y, int button, int key_flags) {
78+ mouse_over_warning_icon_ = false;
79+ QueueDraw();
80+ });
81 }
82
83 void TextInput::CheckIfCapsLockOn()
84@@ -160,8 +178,7 @@
85 unsigned int state = 0;
86 XkbGetIndicatorState(dpy, XkbUseCoreKbd, &state);
87
88- // Caps is on 0x1, couldn't find any #define in /usr/include/X11
89- if ((state & 0x1) == 1)
90+ if ((state & CAPS_STATE_ON) == 1)
91 caps_lock_on = true;
92 else
93 caps_lock_on = false;
94@@ -213,6 +230,44 @@
95 }
96 }
97
98+void TextInput::LoadWarningTooltip()
99+{
100+ glib::String font_name;
101+ g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL);
102+
103+ glib::Object<GtkStyleContext> style_context(gtk_style_context_new());
104+ std::shared_ptr<GtkWidgetPath> widget_path(gtk_widget_path_new(), gtk_widget_path_free);
105+ gtk_widget_path_append_type(widget_path.get(), GTK_TYPE_TOOLTIP);
106+
107+ gtk_style_context_set_path(style_context, widget_path.get());
108+ gtk_style_context_add_class(style_context, "tooltip");
109+
110+ glib::Object<PangoLayout> layout;
111+ glib::Object<PangoContext> context(gdk_pango_context_get_for_screen(gdk_screen_get_default()));
112+ layout = pango_layout_new(context);
113+
114+ std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);
115+ pango_context_set_font_description(context, desc.get());
116+ pango_context_set_language(context, gtk_get_default_language());
117+
118+ pango_layout_set_height(layout, -1); //avoid wrap lines
119+ pango_layout_set_text(layout, _("Caps lock is on"), -1);
120+
121+ nux::Size extents;
122+ pango_layout_get_pixel_size(layout, &extents.width, &extents.height);
123+ extents.width += TOOLTIP_OFFSET;
124+ extents.height += TOOLTIP_OFFSET;
125+
126+ nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, extents.width, extents.height);
127+ cairo_t* cr = cg.GetInternalContext();
128+
129+ gtk_render_background(style_context, cr, 0, 0, extents.width, extents.height);
130+ gtk_render_frame(style_context, cr, 0, 0, extents.width, extents.height);
131+ gtk_render_layout(style_context, cr, TOOLTIP_OFFSET/2, TOOLTIP_OFFSET/2, layout);
132+
133+ warning_tooltip_ = texture_ptr_from_cairo_graphics(cg);
134+}
135+
136 void TextInput::OnFontChanged(GtkSettings* settings, GParamSpec* pspec)
137 {
138 glib::String font_name;
139@@ -270,7 +325,6 @@
140 nux::GetPainter().PushLayer(GfxContext, highlight_layer_->GetGeometry(), highlight_layer_.get());
141 }
142
143-
144 if (!IsFullRedraw())
145 {
146 gPainter.PushLayer(GfxContext, bg_layer_->GetGeometry(), bg_layer_.get());
147@@ -282,6 +336,9 @@
148
149 layout_->ProcessDraw(GfxContext, force_draw);
150
151+ if (caps_lock_on && mouse_over_warning_icon_)
152+ PaintWarningTooltip(GfxContext);
153+
154 if (!IsFullRedraw())
155 {
156 gPainter.PopBackground();
157@@ -294,6 +351,18 @@
158 GfxContext.PopClippingRectangle();
159 }
160
161+void TextInput::PaintWarningTooltip(nux::GraphicsEngine& graphics_engine)
162+{
163+ nux::Geometry warning_geo = warning_->GetGeometry();
164+
165+ nux::Geometry tooltip_geo = {warning_geo.x - (warning_tooltip_->GetWidth() + TOOLTIP_OFFSET / 2),
166+ warning_geo.y - TOOLTIP_Y_OFFSET,
167+ warning_tooltip_->GetWidth(),
168+ warning_tooltip_->GetHeight()};
169+
170+ nux::GetPainter().PushDrawLayer(graphics_engine, tooltip_geo, CreateWarningLayer(warning_tooltip_.GetPointer()));
171+}
172+
173 void TextInput::UpdateBackground(bool force)
174 {
175 int RADIUS = 5;
176
177=== modified file 'unity-shared/TextInput.h'
178--- unity-shared/TextInput.h 2014-04-23 16:50:25 +0000
179+++ unity-shared/TextInput.h 2014-04-23 16:50:25 +0000
180@@ -87,9 +87,14 @@
181 bool AcceptKeyNavFocus();
182
183 bool ShouldBeHighlighted();
184+
185+ nux::Geometry GetWaringIconGeometry() const;
186 void CheckIfCapsLockOn();
187
188 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
189+ void LoadWarningTooltip();
190+
191+ void PaintWarningTooltip(nux::GraphicsEngine& graphics_engine);
192
193 protected:
194 void OnInputHintChanged();
195@@ -109,7 +114,6 @@
196 IMTextEntry* pango_entry_;
197
198 private:
199-
200 std::unique_ptr<nux::AbstractPaintLayer> bg_layer_;
201 std::unique_ptr<nux::AbstractPaintLayer> highlight_layer_;
202 nux::HLayout* layout_;
203@@ -119,6 +123,10 @@
204 nux::Property<bool> caps_lock_on;
205 int last_width_;
206 int last_height_;
207+ bool mouse_over_warning_icon_;
208+
209+ IconTexture* warning_;
210+ nux::ObjectPtr<nux::BaseTexture> warning_tooltip_;
211
212 glib::SignalManager sig_manager_;
213 };