Merge lp:~3v1n0/unity/lockscreen-num-lock-warning into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Andrea Azzarone
Approved revision: no longer in the source branch.
Merged at revision: 4044
Proposed branch: lp:~3v1n0/unity/lockscreen-num-lock-warning
Merge into: lp:unity
Diff against target: 167 lines (+45/-31)
3 files modified
lockscreen/UserPromptView.cpp (+1/-1)
unity-shared/TextInput.cpp (+39/-24)
unity-shared/TextInput.h (+5/-6)
To merge this branch: bzr merge lp:~3v1n0/unity/lockscreen-num-lock-warning
Reviewer Review Type Date Requested Status
Andrea Azzarone (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+276859@code.launchpad.net

Commit message

TextInput: show warning also when num lock is enabled

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andrea Azzarone (azzar1) wrote :

OnLockStateChanged and CheckLocks are poorly named IMHO. CheckLockWarnings?

Revision history for this message
Andrea Azzarone (azzar1) wrote :

Nevermind my fault, they look good.

Revision history for this message
Andrea Azzarone (azzar1) wrote :

+1

review: Approve
Revision history for this message
Johan Boule (johan-boule) wrote :

Some people see this new feature as a bug :|
See bug #1526322

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lockscreen/UserPromptView.cpp'
--- lockscreen/UserPromptView.cpp 2015-09-08 02:19:56 +0000
+++ lockscreen/UserPromptView.cpp 2015-11-06 13:51:19 +0000
@@ -317,7 +317,7 @@
317 text_input->scale = scale();317 text_input->scale = scale();
318 text_input->input_hint = SanitizeMessage(message);318 text_input->input_hint = SanitizeMessage(message);
319 text_input->hint_font_size = PROMPT_FONT_SIZE;319 text_input->hint_font_size = PROMPT_FONT_SIZE;
320 text_input->show_caps_lock = true;320 text_input->show_lock_warnings = true;
321 text_input->show_activator = true;321 text_input->show_activator = true;
322 text_entry->SetPasswordMode(!visible);322 text_entry->SetPasswordMode(!visible);
323 text_entry->SetPasswordChar("•");323 text_entry->SetPasswordChar("•");
324324
=== modified file 'unity-shared/TextInput.cpp'
--- unity-shared/TextInput.cpp 2014-09-04 22:11:03 +0000
+++ unity-shared/TextInput.cpp 2015-11-06 13:51:19 +0000
@@ -92,10 +92,11 @@
92 , hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)92 , hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)
93 , hint_font_size(HINT_LABEL_FONT_SIZE)93 , hint_font_size(HINT_LABEL_FONT_SIZE)
94 , show_activator(false)94 , show_activator(false)
95 , show_caps_lock(false)95 , show_lock_warnings(false)
96 , scale(1.0)96 , scale(1.0)
97 , bg_layer_(new nux::ColorLayer(nux::Color(0xff595853), true))97 , bg_layer_(new nux::ColorLayer(nux::Color(0xff595853), true))
98 , caps_lock_on(false)98 , caps_lock_on(false)
99 , num_lock_on(false)
99 , last_width_(-1)100 , last_width_(-1)
100 , last_height_(-1)101 , last_height_(-1)
101{102{
@@ -135,18 +136,12 @@
135136
136 // Caps lock warning137 // Caps lock warning
137 warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));138 warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));
138 warning_->SetVisible(caps_lock_on());139 warning_->SetVisible(caps_lock_on() || num_lock_on());
139 layout_->AddView(warning_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);140 layout_->AddView(warning_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
140 caps_lock_on.changed.connect([this] (bool on) {141 num_lock_on.changed.connect(sigc::mem_fun(this, &TextInput::OnLockStateChanged));
141 if (show_caps_lock)142 caps_lock_on.changed.connect(sigc::mem_fun(this, &TextInput::OnLockStateChanged));
142 {
143 warning_->SetVisible(on);
144 QueueRelayout();
145 QueueDraw();
146 }
147 });
148143
149 show_caps_lock.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::CheckIfCapsLockOn)));144 show_lock_warnings.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::CheckLocks)));
150 scale.changed.connect(sigc::mem_fun(this, &TextInput::UpdateScale));145 scale.changed.connect(sigc::mem_fun(this, &TextInput::UpdateScale));
151 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));146 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));
152147
@@ -169,16 +164,9 @@
169 spinner_->scale = scale();164 spinner_->scale = scale();
170 layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);165 layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
171166
167 OnFontChanged();
172 sig_manager_.Add<void, GtkSettings*>(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::mem_fun(this, &TextInput::OnFontChanged)));168 sig_manager_.Add<void, GtkSettings*>(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::mem_fun(this, &TextInput::OnFontChanged)));
173 OnFontChanged();169 sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) { CheckLocks(); });
174
175 sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) {
176 CheckIfCapsLockOn();
177 });
178
179 sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) {
180 CheckIfCapsLockOn();
181 });
182170
183 input_string.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_input_string));171 input_string.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_input_string));
184 input_string.SetSetterFunction(sigc::mem_fun(this, &TextInput::set_input_string));172 input_string.SetSetterFunction(sigc::mem_fun(this, &TextInput::set_input_string));
@@ -228,10 +216,25 @@
228 QueueDraw();216 QueueDraw();
229}217}
230218
231void TextInput::CheckIfCapsLockOn()219void TextInput::CheckLocks()
232{220{
233 GdkKeymap* keymap = gdk_keymap_get_default();221 GdkKeymap* keymap = gdk_keymap_get_default();
234 caps_lock_on = gdk_keymap_get_caps_lock_state(keymap) == FALSE ? false : true;222 caps_lock_on = gdk_keymap_get_caps_lock_state(keymap) ? true : false;
223 num_lock_on = gdk_keymap_get_num_lock_state(keymap) ? true : false;
224}
225
226void TextInput::OnLockStateChanged(bool)
227{
228 if (!show_lock_warnings)
229 {
230 warning_->SetVisible(false);
231 return;
232 }
233
234 warning_->SetVisible(caps_lock_on() || num_lock_on());
235 warning_tooltip_.Release();
236 QueueRelayout();
237 QueueDraw();
235}238}
236239
237void TextInput::SetSpinnerVisible(bool visible)240void TextInput::SetSpinnerVisible(bool visible)
@@ -308,7 +311,19 @@
308 pango_cairo_context_set_resolution(context, 96.0 * Settings::Instance().font_scaling());311 pango_cairo_context_set_resolution(context, 96.0 * Settings::Instance().font_scaling());
309312
310 pango_layout_set_height(layout, -1); //avoid wrap lines313 pango_layout_set_height(layout, -1); //avoid wrap lines
311 pango_layout_set_text(layout, _("Caps lock is on"), -1);314
315 if (caps_lock_on() && num_lock_on())
316 {
317 pango_layout_set_text(layout, _("Caps lock and Num lock are on"), -1);
318 }
319 else if (caps_lock_on())
320 {
321 pango_layout_set_text(layout, _("Caps lock is on"), -1);
322 }
323 else if (num_lock_on())
324 {
325 pango_layout_set_text(layout, _("Num lock is on"), -1);
326 }
312327
313 nux::Size extents;328 nux::Size extents;
314 pango_layout_get_pixel_size(layout, &extents.width, &extents.height);329 pango_layout_get_pixel_size(layout, &extents.width, &extents.height);
@@ -395,7 +410,7 @@
395410
396 layout_->ProcessDraw(GfxContext, force_draw);411 layout_->ProcessDraw(GfxContext, force_draw);
397412
398 if (caps_lock_on && warning_->IsMouseInside() && !tooltip_timeout_)413 if (warning_->IsVisible() && warning_->IsMouseInside() && !tooltip_timeout_)
399 PaintWarningTooltip(GfxContext);414 PaintWarningTooltip(GfxContext);
400415
401 if (!IsFullRedraw())416 if (!IsFullRedraw())
402417
=== modified file 'unity-shared/TextInput.h'
--- unity-shared/TextInput.h 2014-08-27 22:08:58 +0000
+++ unity-shared/TextInput.h 2015-11-06 13:51:19 +0000
@@ -64,7 +64,7 @@
64 nux::ROProperty<bool> im_active;64 nux::ROProperty<bool> im_active;
65 nux::ROProperty<bool> im_preedit;65 nux::ROProperty<bool> im_preedit;
66 nux::Property<bool> show_activator;66 nux::Property<bool> show_activator;
67 nux::Property<bool> show_caps_lock;67 nux::Property<bool> show_lock_warnings;
68 nux::Property<double> scale;68 nux::Property<double> scale;
6969
70private:70private:
@@ -77,14 +77,12 @@
77 void UpdateSize();77 void UpdateSize();
7878
79 std::string GetName() const;79 std::string GetName() const;
80
81 void AddProperties(debug::IntrospectionData&);80 void AddProperties(debug::IntrospectionData&);
81
82 bool AcceptKeyNavFocus();82 bool AcceptKeyNavFocus();
83
84 bool ShouldBeHighlighted();83 bool ShouldBeHighlighted();
8584 void CheckLocks();
86 nux::Geometry GetWaringIconGeometry() const;85 void OnLockStateChanged(bool);
87 void CheckIfCapsLockOn();
8886
89 nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(int icon_size);87 nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(int icon_size);
90 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);88 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
@@ -117,6 +115,7 @@
117 SearchBarSpinner* spinner_;115 SearchBarSpinner* spinner_;
118116
119 nux::Property<bool> caps_lock_on;117 nux::Property<bool> caps_lock_on;
118 nux::Property<bool> num_lock_on;
120 int last_width_;119 int last_width_;
121 int last_height_;120 int last_height_;
122121