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
1=== modified file 'lockscreen/UserPromptView.cpp'
2--- lockscreen/UserPromptView.cpp 2015-09-08 02:19:56 +0000
3+++ lockscreen/UserPromptView.cpp 2015-11-06 13:51:19 +0000
4@@ -317,7 +317,7 @@
5 text_input->scale = scale();
6 text_input->input_hint = SanitizeMessage(message);
7 text_input->hint_font_size = PROMPT_FONT_SIZE;
8- text_input->show_caps_lock = true;
9+ text_input->show_lock_warnings = true;
10 text_input->show_activator = true;
11 text_entry->SetPasswordMode(!visible);
12 text_entry->SetPasswordChar("•");
13
14=== modified file 'unity-shared/TextInput.cpp'
15--- unity-shared/TextInput.cpp 2014-09-04 22:11:03 +0000
16+++ unity-shared/TextInput.cpp 2015-11-06 13:51:19 +0000
17@@ -92,10 +92,11 @@
18 , hint_font_name(HINT_LABEL_DEFAULT_FONT_NAME)
19 , hint_font_size(HINT_LABEL_FONT_SIZE)
20 , show_activator(false)
21- , show_caps_lock(false)
22+ , show_lock_warnings(false)
23 , scale(1.0)
24 , bg_layer_(new nux::ColorLayer(nux::Color(0xff595853), true))
25 , caps_lock_on(false)
26+ , num_lock_on(false)
27 , last_width_(-1)
28 , last_height_(-1)
29 {
30@@ -135,18 +136,12 @@
31
32 // Caps lock warning
33 warning_ = new IconTexture(LoadWarningIcon(DEFAULT_ICON_SIZE.CP(scale)));
34- warning_->SetVisible(caps_lock_on());
35+ warning_->SetVisible(caps_lock_on() || num_lock_on());
36 layout_->AddView(warning_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
37- caps_lock_on.changed.connect([this] (bool on) {
38- if (show_caps_lock)
39- {
40- warning_->SetVisible(on);
41- QueueRelayout();
42- QueueDraw();
43- }
44- });
45+ num_lock_on.changed.connect(sigc::mem_fun(this, &TextInput::OnLockStateChanged));
46+ caps_lock_on.changed.connect(sigc::mem_fun(this, &TextInput::OnLockStateChanged));
47
48- show_caps_lock.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::CheckIfCapsLockOn)));
49+ show_lock_warnings.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::CheckLocks)));
50 scale.changed.connect(sigc::mem_fun(this, &TextInput::UpdateScale));
51 Settings::Instance().font_scaling.changed.connect(sigc::hide(sigc::mem_fun(this, &TextInput::UpdateSize)));
52
53@@ -169,16 +164,9 @@
54 spinner_->scale = scale();
55 layout_->AddView(spinner_, 0, nux::MINOR_POSITION_CENTER, nux::MINOR_SIZE_FULL);
56
57+ OnFontChanged();
58 sig_manager_.Add<void, GtkSettings*>(gtk_settings_get_default(), "notify::gtk-font-name", sigc::hide(sigc::mem_fun(this, &TextInput::OnFontChanged)));
59- OnFontChanged();
60-
61- sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) {
62- CheckIfCapsLockOn();
63- });
64-
65- sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) {
66- CheckIfCapsLockOn();
67- });
68+ sig_manager_.Add<void, GdkKeymap*>(gdk_keymap_get_default(), "state-changed", [this](GdkKeymap*) { CheckLocks(); });
69
70 input_string.SetGetterFunction(sigc::mem_fun(this, &TextInput::get_input_string));
71 input_string.SetSetterFunction(sigc::mem_fun(this, &TextInput::set_input_string));
72@@ -228,10 +216,25 @@
73 QueueDraw();
74 }
75
76-void TextInput::CheckIfCapsLockOn()
77+void TextInput::CheckLocks()
78 {
79 GdkKeymap* keymap = gdk_keymap_get_default();
80- caps_lock_on = gdk_keymap_get_caps_lock_state(keymap) == FALSE ? false : true;
81+ caps_lock_on = gdk_keymap_get_caps_lock_state(keymap) ? true : false;
82+ num_lock_on = gdk_keymap_get_num_lock_state(keymap) ? true : false;
83+}
84+
85+void TextInput::OnLockStateChanged(bool)
86+{
87+ if (!show_lock_warnings)
88+ {
89+ warning_->SetVisible(false);
90+ return;
91+ }
92+
93+ warning_->SetVisible(caps_lock_on() || num_lock_on());
94+ warning_tooltip_.Release();
95+ QueueRelayout();
96+ QueueDraw();
97 }
98
99 void TextInput::SetSpinnerVisible(bool visible)
100@@ -308,7 +311,19 @@
101 pango_cairo_context_set_resolution(context, 96.0 * Settings::Instance().font_scaling());
102
103 pango_layout_set_height(layout, -1); //avoid wrap lines
104- pango_layout_set_text(layout, _("Caps lock is on"), -1);
105+
106+ if (caps_lock_on() && num_lock_on())
107+ {
108+ pango_layout_set_text(layout, _("Caps lock and Num lock are on"), -1);
109+ }
110+ else if (caps_lock_on())
111+ {
112+ pango_layout_set_text(layout, _("Caps lock is on"), -1);
113+ }
114+ else if (num_lock_on())
115+ {
116+ pango_layout_set_text(layout, _("Num lock is on"), -1);
117+ }
118
119 nux::Size extents;
120 pango_layout_get_pixel_size(layout, &extents.width, &extents.height);
121@@ -395,7 +410,7 @@
122
123 layout_->ProcessDraw(GfxContext, force_draw);
124
125- if (caps_lock_on && warning_->IsMouseInside() && !tooltip_timeout_)
126+ if (warning_->IsVisible() && warning_->IsMouseInside() && !tooltip_timeout_)
127 PaintWarningTooltip(GfxContext);
128
129 if (!IsFullRedraw())
130
131=== modified file 'unity-shared/TextInput.h'
132--- unity-shared/TextInput.h 2014-08-27 22:08:58 +0000
133+++ unity-shared/TextInput.h 2015-11-06 13:51:19 +0000
134@@ -64,7 +64,7 @@
135 nux::ROProperty<bool> im_active;
136 nux::ROProperty<bool> im_preedit;
137 nux::Property<bool> show_activator;
138- nux::Property<bool> show_caps_lock;
139+ nux::Property<bool> show_lock_warnings;
140 nux::Property<double> scale;
141
142 private:
143@@ -77,14 +77,12 @@
144 void UpdateSize();
145
146 std::string GetName() const;
147-
148 void AddProperties(debug::IntrospectionData&);
149+
150 bool AcceptKeyNavFocus();
151-
152 bool ShouldBeHighlighted();
153-
154- nux::Geometry GetWaringIconGeometry() const;
155- void CheckIfCapsLockOn();
156+ void CheckLocks();
157+ void OnLockStateChanged(bool);
158
159 nux::ObjectPtr<nux::BaseTexture> LoadActivatorIcon(int icon_size);
160 nux::ObjectPtr<nux::BaseTexture> LoadWarningIcon(int icon_size);
161@@ -117,6 +115,7 @@
162 SearchBarSpinner* spinner_;
163
164 nux::Property<bool> caps_lock_on;
165+ nux::Property<bool> num_lock_on;
166 int last_width_;
167 int last_height_;
168