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
=== modified file 'po/POTFILES.in'
--- po/POTFILES.in 2014-04-02 12:31:33 +0000
+++ po/POTFILES.in 2014-04-23 16:50:25 +0000
@@ -48,5 +48,6 @@
48unity-shared/DashStyle.cpp48unity-shared/DashStyle.cpp
49unity-shared/PreviewStyle.cpp49unity-shared/PreviewStyle.cpp
50unity-shared/SearchBar.cpp50unity-shared/SearchBar.cpp
51unity-shared/TextInput.cpp
51unity-shared/UScreen.cpp52unity-shared/UScreen.cpp
52gnome/50-unity-launchers.xml.in53gnome/50-unity-launchers.xml.in
5354
=== modified file 'unity-shared/TextInput.cpp'
--- unity-shared/TextInput.cpp 2014-04-23 16:50:25 +0000
+++ unity-shared/TextInput.cpp 2014-04-23 16:50:25 +0000
@@ -38,10 +38,14 @@
3838
39const int HIGHLIGHT_HEIGHT = 24;39const int HIGHLIGHT_HEIGHT = 24;
4040
41const RawPixel TOOLTIP_Y_OFFSET = 3_em;
42const RawPixel TOOLTIP_OFFSET = 10_em;
41const RawPixel DEFAULT_ICON_SIZE = 22_em;43const RawPixel DEFAULT_ICON_SIZE = 22_em;
4244
43std::string WARNING_ICON = "dialog-warning-symbolic";45// Caps is on 0x1, couldn't find any #define in /usr/include/X11
46const int CAPS_STATE_ON = 0x1;
4447
48std::string WARNING_ICON = "dialog-warning-symbolic";
45// Fonts49// Fonts
46const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";50const std::string HINT_LABEL_DEFAULT_FONT_NAME = "Ubuntu";
47const int HINT_LABEL_FONT_SIZE = 11;51const int HINT_LABEL_FONT_SIZE = 11;
@@ -88,6 +92,7 @@
88 , caps_lock_on(false)92 , caps_lock_on(false)
89 , last_width_(-1)93 , last_width_(-1)
90 , last_height_(-1)94 , last_height_(-1)
95 , mouse_over_warning_icon_(false)
91{96{
92 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);97 layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
93 layout_->SetLeftAndRightPadding(LEFT_INTERNAL_PADDING, TEXT_INPUT_RIGHT_BORDER);98 layout_->SetLeftAndRightPadding(LEFT_INTERNAL_PADDING, TEXT_INPUT_RIGHT_BORDER);
@@ -122,19 +127,22 @@
122 layered_layout_->SetActiveLayerN(1);127 layered_layout_->SetActiveLayerN(1);
123 layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);128 layout_->AddView(layered_layout_, 1, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FIX);
124129
125 auto* warning = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE));130 warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE));
126 warning->SetVisible(caps_lock_on());131 warning_->SetVisible(caps_lock_on());
127 layout_->AddView(warning, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);132 layout_->AddView(warning_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
128 caps_lock_on.changed.connect([this, warning] (bool on) {133 caps_lock_on.changed.connect([this] (bool on) {
129 if (show_caps_lock)134 if (show_caps_lock)
130 {135 {
131 warning->SetVisible(on);136 warning_->SetVisible(on);
132 QueueRelayout();137 QueueRelayout();
133 QueueDraw();138 QueueDraw();
134 }139 }
135 });140 });
136141
137 show_caps_lock.changed.connect([this] (bool changed) {142 show_caps_lock.changed.connect([this] (bool changed) {
143 if (!warning_tooltip_.IsValid())
144 LoadWarningTooltip();
145
138 CheckIfCapsLockOn();146 CheckIfCapsLockOn();
139 });147 });
140148
@@ -152,6 +160,16 @@
152 im_active.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_active));160 im_active.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_active));
153 im_preedit.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_preedit));161 im_preedit.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_im_preedit));
154 input_hint.changed.connect([this](std::string const& s) { OnInputHintChanged(); });162 input_hint.changed.connect([this](std::string const& s) { OnInputHintChanged(); });
163
164 warning_->mouse_enter.connect([this] (int x, int y, int button, int key_flags) {
165 mouse_over_warning_icon_ = true;
166 QueueDraw();
167 });
168
169 warning_->mouse_leave.connect([this] (int x, int y, int button, int key_flags) {
170 mouse_over_warning_icon_ = false;
171 QueueDraw();
172 });
155}173}
156174
157void TextInput::CheckIfCapsLockOn()175void TextInput::CheckIfCapsLockOn()
@@ -160,8 +178,7 @@
160 unsigned int state = 0;178 unsigned int state = 0;
161 XkbGetIndicatorState(dpy, XkbUseCoreKbd, &state);179 XkbGetIndicatorState(dpy, XkbUseCoreKbd, &state);
162180
163 // Caps is on 0x1, couldn't find any #define in /usr/include/X11181 if ((state & CAPS_STATE_ON) == 1)
164 if ((state & 0x1) == 1)
165 caps_lock_on = true;182 caps_lock_on = true;
166 else183 else
167 caps_lock_on = false;184 caps_lock_on = false;
@@ -213,6 +230,44 @@
213 }230 }
214}231}
215232
233void TextInput::LoadWarningTooltip()
234{
235 glib::String font_name;
236 g_object_get(gtk_settings_get_default(), "gtk-font-name", &font_name, NULL);
237
238 glib::Object<GtkStyleContext> style_context(gtk_style_context_new());
239 std::shared_ptr<GtkWidgetPath> widget_path(gtk_widget_path_new(), gtk_widget_path_free);
240 gtk_widget_path_append_type(widget_path.get(), GTK_TYPE_TOOLTIP);
241
242 gtk_style_context_set_path(style_context, widget_path.get());
243 gtk_style_context_add_class(style_context, "tooltip");
244
245 glib::Object<PangoLayout> layout;
246 glib::Object<PangoContext> context(gdk_pango_context_get_for_screen(gdk_screen_get_default()));
247 layout = pango_layout_new(context);
248
249 std::shared_ptr<PangoFontDescription> desc(pango_font_description_from_string(font_name), pango_font_description_free);
250 pango_context_set_font_description(context, desc.get());
251 pango_context_set_language(context, gtk_get_default_language());
252
253 pango_layout_set_height(layout, -1); //avoid wrap lines
254 pango_layout_set_text(layout, _("Caps lock is on"), -1);
255
256 nux::Size extents;
257 pango_layout_get_pixel_size(layout, &extents.width, &extents.height);
258 extents.width += TOOLTIP_OFFSET;
259 extents.height += TOOLTIP_OFFSET;
260
261 nux::CairoGraphics cg(CAIRO_FORMAT_ARGB32, extents.width, extents.height);
262 cairo_t* cr = cg.GetInternalContext();
263
264 gtk_render_background(style_context, cr, 0, 0, extents.width, extents.height);
265 gtk_render_frame(style_context, cr, 0, 0, extents.width, extents.height);
266 gtk_render_layout(style_context, cr, TOOLTIP_OFFSET/2, TOOLTIP_OFFSET/2, layout);
267
268 warning_tooltip_ = texture_ptr_from_cairo_graphics(cg);
269}
270
216void TextInput::OnFontChanged(GtkSettings* settings, GParamSpec* pspec)271void TextInput::OnFontChanged(GtkSettings* settings, GParamSpec* pspec)
217{272{
218 glib::String font_name;273 glib::String font_name;
@@ -270,7 +325,6 @@
270 nux::GetPainter().PushLayer(GfxContext, highlight_layer_->GetGeometry(), highlight_layer_.get());325 nux::GetPainter().PushLayer(GfxContext, highlight_layer_->GetGeometry(), highlight_layer_.get());
271 }326 }
272327
273
274 if (!IsFullRedraw())328 if (!IsFullRedraw())
275 {329 {
276 gPainter.PushLayer(GfxContext, bg_layer_->GetGeometry(), bg_layer_.get());330 gPainter.PushLayer(GfxContext, bg_layer_->GetGeometry(), bg_layer_.get());
@@ -282,6 +336,9 @@
282336
283 layout_->ProcessDraw(GfxContext, force_draw);337 layout_->ProcessDraw(GfxContext, force_draw);
284338
339 if (caps_lock_on && mouse_over_warning_icon_)
340 PaintWarningTooltip(GfxContext);
341
285 if (!IsFullRedraw())342 if (!IsFullRedraw())
286 {343 {
287 gPainter.PopBackground();344 gPainter.PopBackground();
@@ -294,6 +351,18 @@
294 GfxContext.PopClippingRectangle();351 GfxContext.PopClippingRectangle();
295}352}
296353
354void TextInput::PaintWarningTooltip(nux::GraphicsEngine& graphics_engine)
355{
356 nux::Geometry warning_geo = warning_->GetGeometry();
357
358 nux::Geometry tooltip_geo = {warning_geo.x - (warning_tooltip_->GetWidth() + TOOLTIP_OFFSET / 2),
359 warning_geo.y - TOOLTIP_Y_OFFSET,
360 warning_tooltip_->GetWidth(),
361 warning_tooltip_->GetHeight()};
362
363 nux::GetPainter().PushDrawLayer(graphics_engine, tooltip_geo, CreateWarningLayer(warning_tooltip_.GetPointer()));
364}
365
297void TextInput::UpdateBackground(bool force)366void TextInput::UpdateBackground(bool force)
298{367{
299 int RADIUS = 5;368 int RADIUS = 5;
300369
=== modified file 'unity-shared/TextInput.h'
--- unity-shared/TextInput.h 2014-04-23 16:50:25 +0000
+++ unity-shared/TextInput.h 2014-04-23 16:50:25 +0000
@@ -87,9 +87,14 @@
87 bool AcceptKeyNavFocus();87 bool AcceptKeyNavFocus();
8888
89 bool ShouldBeHighlighted();89 bool ShouldBeHighlighted();
90
91 nux::Geometry GetWaringIconGeometry() const;
90 void CheckIfCapsLockOn();92 void CheckIfCapsLockOn();
9193
92 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);94 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
95 void LoadWarningTooltip();
96
97 void PaintWarningTooltip(nux::GraphicsEngine& graphics_engine);
9398
94protected:99protected:
95 void OnInputHintChanged();100 void OnInputHintChanged();
@@ -109,7 +114,6 @@
109 IMTextEntry* pango_entry_;114 IMTextEntry* pango_entry_;
110115
111private:116private:
112
113 std::unique_ptr<nux::AbstractPaintLayer> bg_layer_;117 std::unique_ptr<nux::AbstractPaintLayer> bg_layer_;
114 std::unique_ptr<nux::AbstractPaintLayer> highlight_layer_;118 std::unique_ptr<nux::AbstractPaintLayer> highlight_layer_;
115 nux::HLayout* layout_;119 nux::HLayout* layout_;
@@ -119,6 +123,10 @@
119 nux::Property<bool> caps_lock_on;123 nux::Property<bool> caps_lock_on;
120 int last_width_;124 int last_width_;
121 int last_height_;125 int last_height_;
126 bool mouse_over_warning_icon_;
127
128 IconTexture* warning_;
129 nux::ObjectPtr<nux::BaseTexture> warning_tooltip_;
122130
123 glib::SignalManager sig_manager_;131 glib::SignalManager sig_manager_;
124};132};