Merge lp:~brandontschaefer/unity/lockscreen-caps-lock-detector 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: 3775
Proposed branch: lp:~brandontschaefer/unity/lockscreen-caps-lock-detector
Merge into: lp:unity
Diff against target: 353 lines (+128/-18)
9 files modified
lockscreen/LockScreenAbstractShield.h (+1/-0)
lockscreen/LockScreenController.cpp (+1/-0)
lockscreen/LockScreenShield.cpp (+6/-0)
lockscreen/LockScreenShield.h (+3/-2)
lockscreen/UserPromptView.cpp (+100/-4)
lockscreen/UserPromptView.h (+14/-1)
tests/test_lockscreen_controller.cpp (+1/-0)
unity-shared/CompizUtils.cpp (+2/-10)
unity-shared/CompizUtils.h (+0/-1)
To merge this branch: bzr merge lp:~brandontschaefer/unity/lockscreen-caps-lock-detector
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Marco Trevisan (Treviño) Approve
Review via email: mp+213707@code.launchpad.net

Commit message

When we detect caps lock, or caps lock is pressed, render a warning icon to show its on.

Description of the change

When we detect caps lock, or caps lock is pressed, render a warning icon to show its on.

To post a comment you must log in.
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

Cool, looks good to me!

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'lockscreen/LockScreenAbstractShield.h'
--- lockscreen/LockScreenAbstractShield.h 2014-03-24 21:36:55 +0000
+++ lockscreen/LockScreenAbstractShield.h 2014-04-09 17:10:19 +0000
@@ -47,6 +47,7 @@
4747
48 using MockableBaseWindow::RemoveLayout;48 using MockableBaseWindow::RemoveLayout;
49 virtual bool IsIndicatorOpen() const = 0;49 virtual bool IsIndicatorOpen() const = 0;
50 virtual void CheckCapsLockPrompt() = 0;
5051
51 sigc::signal<void, int, int> grab_motion;52 sigc::signal<void, int, int> grab_motion;
5253
5354
=== modified file 'lockscreen/LockScreenController.cpp'
--- lockscreen/LockScreenController.cpp 2014-03-24 21:36:55 +0000
+++ lockscreen/LockScreenController.cpp 2014-04-09 17:10:19 +0000
@@ -101,6 +101,7 @@
101101
102 primary_shield_->primary = false;102 primary_shield_->primary = false;
103 primary_shield_ = shield;103 primary_shield_ = shield;
104 primary_shield_->CheckCapsLockPrompt();
104 shield->primary = true;105 shield->primary = true;
105 auto move_cb = sigc::mem_fun(this, &Controller::OnPrimaryShieldMotion);106 auto move_cb = sigc::mem_fun(this, &Controller::OnPrimaryShieldMotion);
106 motion_connection_ = shield->grab_motion.connect(move_cb);107 motion_connection_ = shield->grab_motion.connect(move_cb);
107108
=== modified file 'lockscreen/LockScreenShield.cpp'
--- lockscreen/LockScreenShield.cpp 2014-03-07 19:35:46 +0000
+++ lockscreen/LockScreenShield.cpp 2014-04-09 17:10:19 +0000
@@ -86,6 +86,12 @@
86 }86 }
87}87}
8888
89void Shield::CheckCapsLockPrompt()
90{
91 if (prompt_view_)
92 prompt_view_->CheckIfCapsLockOn();
93}
94
89void Shield::ShowPrimaryView()95void Shield::ShowPrimaryView()
90{96{
91 GrabPointer();97 GrabPointer();
9298
=== modified file 'lockscreen/LockScreenShield.h'
--- lockscreen/LockScreenShield.h 2014-03-07 19:17:35 +0000
+++ lockscreen/LockScreenShield.h 2014-04-09 17:10:19 +0000
@@ -38,7 +38,8 @@
38public:38public:
39 Shield(session::Manager::Ptr const&, indicator::Indicators::Ptr const&, int monitor, bool is_primary);39 Shield(session::Manager::Ptr const&, indicator::Indicators::Ptr const&, int monitor, bool is_primary);
4040
41 bool IsIndicatorOpen() const;41 bool IsIndicatorOpen() const override;
42 void CheckCapsLockPrompt() override;
4243
43protected:44protected:
44 bool AcceptKeyNavFocus() override;45 bool AcceptKeyNavFocus() override;
@@ -64,4 +65,4 @@
64}65}
65}66}
6667
67#endif
68\ No newline at end of file68\ No newline at end of file
69#endif
6970
=== modified file 'lockscreen/UserPromptView.cpp'
--- lockscreen/UserPromptView.cpp 2014-03-26 18:52:13 +0000
+++ lockscreen/UserPromptView.cpp 2014-04-09 17:10:19 +0000
@@ -21,9 +21,12 @@
2121
22#include <boost/algorithm/string/trim.hpp>22#include <boost/algorithm/string/trim.hpp>
23#include <Nux/VLayout.h>23#include <Nux/VLayout.h>
24#include <X11/XKBlib.h>
2425
25#include "LockScreenSettings.h"26#include "LockScreenSettings.h"
26#include "unity-shared/CairoTexture.h"27#include "unity-shared/CairoTexture.h"
28#include "unity-shared/DashStyle.h"
29#include "unity-shared/PreviewStyle.h"
27#include "unity-shared/TextInput.h"30#include "unity-shared/TextInput.h"
28#include "unity-shared/StaticCairoText.h"31#include "unity-shared/StaticCairoText.h"
29#include "unity-shared/RawPixel.h"32#include "unity-shared/RawPixel.h"
@@ -34,11 +37,12 @@
34{37{
35namespace38namespace
36{39{
37const RawPixel PADDING = 10_em;40const RawPixel PADDING = 10_em;
38const RawPixel LAYOUT_MARGIN = 10_em;41const RawPixel LAYOUT_MARGIN = 10_em;
39const RawPixel MSG_LAYOUT_MARGIN = 15_em;42const RawPixel MSG_LAYOUT_MARGIN = 15_em;
40const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;43const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
41const int PROMPT_FONT_SIZE = 13;44
45const int PROMPT_FONT_SIZE = 13;
4246
43nux::AbstractPaintLayer* CrateBackgroundLayer(int width, int height)47nux::AbstractPaintLayer* CrateBackgroundLayer(int width, int height)
44{48{
@@ -74,6 +78,28 @@
74 rop));78 rop));
75}79}
7680
81nux::AbstractPaintLayer* CreateWarningLayer(nux::BaseTexture* texture)
82{
83 // Create the texture layer
84 nux::TexCoordXForm texxform;
85
86 texxform.SetTexCoordType(nux::TexCoordXForm::OFFSET_COORD);
87 texxform.SetWrap(nux::TEXWRAP_REPEAT, nux::TEXWRAP_REPEAT);
88 texxform.min_filter = nux::TEXFILTER_LINEAR;
89 texxform.mag_filter = nux::TEXFILTER_LINEAR;
90
91 nux::ROPConfig rop;
92 rop.Blend = true;
93 rop.SrcBlend = GL_ONE;
94 rop.DstBlend = GL_ONE_MINUS_SRC_ALPHA;
95
96 return (new nux::TextureLayer(texture->GetDeviceTexture(),
97 texxform,
98 nux::color::White,
99 true,
100 rop));
101}
102
77std::string SanitizeMessage(std::string const& message)103std::string SanitizeMessage(std::string const& message)
78{104{
79 std::string msg = boost::algorithm::trim_copy(message);105 std::string msg = boost::algorithm::trim_copy(message);
@@ -98,6 +124,7 @@
98UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)124UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)
99 : nux::View(NUX_TRACKER_LOCATION)125 : nux::View(NUX_TRACKER_LOCATION)
100 , session_manager_(session_manager)126 , session_manager_(session_manager)
127 , caps_lock_on_(false)
101{128{
102 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){129 user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
103 AddPrompt(message, /* visible */ true, promise);130 AddPrompt(message, /* visible */ true, promise);
@@ -119,10 +146,32 @@
119 ResetLayout();146 ResetLayout();
120 });147 });
121148
149 dash::previews::Style& preview_style = dash::previews::Style::Instance();
150
151 warning_ = preview_style.GetWarningIcon();
122 ResetLayout();152 ResetLayout();
123153
124 user_authenticator_.AuthenticateStart(session_manager_->UserName(),154 user_authenticator_.AuthenticateStart(session_manager_->UserName(),
125 sigc::mem_fun(this, &UserPromptView::AuthenticationCb));155 sigc::mem_fun(this, &UserPromptView::AuthenticationCb));
156
157 // When we get to HiDPI changes here, we will need to update this width
158 dash::Style& style = dash::Style::Instance();
159 spin_icon_width_ = style.GetSearchSpinIcon()->GetWidth();
160
161 CheckIfCapsLockOn();
162}
163
164void UserPromptView::CheckIfCapsLockOn()
165{
166 Display *dpy = nux::GetGraphicsDisplay()->GetX11Display();
167 unsigned int state = 0;
168 XkbGetIndicatorState(dpy, XkbUseCoreKbd, &state);
169
170 // Caps is on 0x1, couldn't find any #define in /usr/include/X11
171 if ((state & 0x1) == 1)
172 caps_lock_on_ = true;
173 else
174 caps_lock_on_ = false;
126}175}
127176
128bool UserPromptView::InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character)177bool UserPromptView::InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character)
@@ -211,6 +260,15 @@
211 nux::GetPainter().PushLayer(graphics_engine, geo, bg_layer_.get());260 nux::GetPainter().PushLayer(graphics_engine, geo, bg_layer_.get());
212 }261 }
213262
263 if (caps_lock_on_)
264 {
265 for (auto const& text_entry : focus_queue_)
266 PaintWarningIcon(graphics_engine, text_entry->GetGeometry());
267
268 if (focus_queue_.empty())
269 PaintWarningIcon(graphics_engine, cached_focused_geo_);
270 }
271
214 if (GetLayout())272 if (GetLayout())
215 GetLayout()->ProcessDraw(graphics_engine, force_draw);273 GetLayout()->ProcessDraw(graphics_engine, force_draw);
216274
@@ -220,6 +278,19 @@
220 graphics_engine.PopClippingRectangle();278 graphics_engine.PopClippingRectangle();
221}279}
222280
281void UserPromptView::PaintWarningIcon(nux::GraphicsEngine& graphics_engine, nux::Geometry const& geo)
282{
283 nux::Geometry warning_geo = {geo.x + geo.width - GetWarningIconOffset(),
284 geo.y, warning_->GetWidth(), warning_->GetHeight()};
285
286 nux::GetPainter().PushLayer(graphics_engine, warning_geo, CreateWarningLayer(warning_));
287}
288
289int UserPromptView::GetWarningIconOffset()
290{
291 return warning_->GetWidth() + spin_icon_width_;
292}
293
223nux::View* UserPromptView::focus_view()294nux::View* UserPromptView::focus_view()
224{295{
225 if (focus_queue_.empty())296 if (focus_queue_.empty())
@@ -232,6 +303,26 @@
232 return focus_queue_.front();303 return focus_queue_.front();
233}304}
234305
306void UserPromptView::ToggleCapsLockBool()
307{
308 caps_lock_on_ = !caps_lock_on_;
309 QueueDraw();
310}
311
312void UserPromptView::RecvKeyUp(unsigned keysym,
313 unsigned long keycode,
314 unsigned long state)
315{
316 if (!caps_lock_on_ && keysym == NUX_VK_CAPITAL)
317 {
318 ToggleCapsLockBool();
319 }
320 else if (caps_lock_on_ && keysym == NUX_VK_CAPITAL)
321 {
322 ToggleCapsLockBool();
323 }
324}
325
235void UserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise)326void UserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise)
236{327{
237 auto* text_input = new unity::TextInput();328 auto* text_input = new unity::TextInput();
@@ -243,11 +334,15 @@
243 text_entry->SetPasswordChar("•");334 text_entry->SetPasswordChar("•");
244 text_entry->SetToggleCursorVisibilityOnKeyFocus(true);335 text_entry->SetToggleCursorVisibilityOnKeyFocus(true);
245336
337 text_entry->key_up.connect(sigc::mem_fun(this, &UserPromptView::RecvKeyUp));
338
246 text_input->SetMinimumHeight(Settings::GRID_SIZE);339 text_input->SetMinimumHeight(Settings::GRID_SIZE);
247 text_input->SetMaximumHeight(Settings::GRID_SIZE);340 text_input->SetMaximumHeight(Settings::GRID_SIZE);
248 prompt_layout_->AddView(text_input, 1);341 prompt_layout_->AddView(text_input, 1);
249 focus_queue_.push_back(text_entry);342 focus_queue_.push_back(text_entry);
250343
344 CheckIfCapsLockOn();
345
251 // Don't remove it, it helps with a11y.346 // Don't remove it, it helps with a11y.
252 if (focus_queue_.size() == 1)347 if (focus_queue_.size() == 1)
253 nux::GetWindowCompositor().SetKeyFocusArea(text_entry);348 nux::GetWindowCompositor().SetKeyFocusArea(text_entry);
@@ -261,6 +356,7 @@
261356
262 focus_queue_.pop_front();357 focus_queue_.pop_front();
263 auto* text_entry = text_input->text_entry();358 auto* text_entry = text_input->text_entry();
359 cached_focused_geo_ = text_entry->GetGeometry();
264 text_entry->SetInputEventSensitivity(false);360 text_entry->SetInputEventSensitivity(false);
265 QueueRelayout();361 QueueRelayout();
266 QueueDraw();362 QueueDraw();
267363
=== modified file 'lockscreen/UserPromptView.h'
--- lockscreen/UserPromptView.h 2014-03-25 18:39:24 +0000
+++ lockscreen/UserPromptView.h 2014-04-09 17:10:19 +0000
@@ -29,7 +29,6 @@
2929
30#include "UserAuthenticatorPam.h"30#include "UserAuthenticatorPam.h"
31#include "unity-shared/IMTextEntry.h"31#include "unity-shared/IMTextEntry.h"
32#include "unity-shared/SearchBarSpinner.h"
3332
34namespace nux33namespace nux
35{34{
@@ -57,6 +56,8 @@
57 void AddMessage(std::string const& message, nux::Color const& color);56 void AddMessage(std::string const& message, nux::Color const& color);
58 void AuthenticationCb(bool authenticated);57 void AuthenticationCb(bool authenticated);
5958
59 void CheckIfCapsLockOn();
60
60protected:61protected:
61 void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) override;62 void Draw(nux::GraphicsEngine& graphics_engine, bool force_draw) override;
62 void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) override;63 void DrawContent(nux::GraphicsEngine& graphics_engine, bool force_draw) override;
@@ -65,6 +66,12 @@
65 void ResetLayout();66 void ResetLayout();
6667
67 bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);68 bool InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character);
69 void RecvKeyUp(unsigned int, unsigned long, unsigned long);
70
71 void PaintWarningIcon(nux::GraphicsEngine& graphics_engine, nux::Geometry const& geo);
72 void ToggleCapsLockBool();
73
74 int GetWarningIconOffset();
6875
69 session::Manager::Ptr session_manager_;76 session::Manager::Ptr session_manager_;
70 UserAuthenticatorPam user_authenticator_;77 UserAuthenticatorPam user_authenticator_;
@@ -75,6 +82,12 @@
75 StaticCairoText* error_;82 StaticCairoText* error_;
76 StaticCairoText* invalid_login_;83 StaticCairoText* invalid_login_;
77 std::deque<IMTextEntry*> focus_queue_;84 std::deque<IMTextEntry*> focus_queue_;
85
86 nux::BaseTexture* warning_;
87 nux::Geometry cached_focused_geo_;
88
89 bool caps_lock_on_;
90 int spin_icon_width_;
78};91};
7992
80}93}
8194
=== modified file 'tests/test_lockscreen_controller.cpp'
--- tests/test_lockscreen_controller.cpp 2014-03-21 23:08:47 +0000
+++ tests/test_lockscreen_controller.cpp 2014-04-09 17:10:19 +0000
@@ -68,6 +68,7 @@
68 {}68 {}
6969
70 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());70 MOCK_CONST_METHOD0(IsIndicatorOpen, bool());
71 MOCK_METHOD0(CheckCapsLockPrompt, void());
71};72};
7273
73struct ShieldFactoryMock : ShieldFactoryInterface74struct ShieldFactoryMock : ShieldFactoryInterface
7475
=== modified file 'unity-shared/CompizUtils.cpp'
--- unity-shared/CompizUtils.cpp 2014-03-29 02:10:18 +0000
+++ unity-shared/CompizUtils.cpp 2014-04-09 17:10:19 +0000
@@ -180,8 +180,8 @@
180 if (win->region().numRects() != 1) // Non rectangular windows180 if (win->region().numRects() != 1) // Non rectangular windows
181 return false;181 return false;
182182
183 if (win->alpha())183 if (win->overrideRedirect() && win->alpha())
184 return WindowHasMotifDecorations(win);184 return false;
185185
186 return true;186 return true;
187}187}
@@ -194,14 +194,6 @@
194 if (!IsWindowShadowDecorable(win))194 if (!IsWindowShadowDecorable(win))
195 return false;195 return false;
196196
197 return WindowHasMotifDecorations(win);
198}
199
200bool WindowHasMotifDecorations(CompWindow* win)
201{
202 if (!win)
203 return false;
204
205 if (win->overrideRedirect())197 if (win->overrideRedirect())
206 return false;198 return false;
207199
208200
=== modified file 'unity-shared/CompizUtils.h'
--- unity-shared/CompizUtils.h 2014-03-29 02:10:18 +0000
+++ unity-shared/CompizUtils.h 2014-04-09 17:10:19 +0000
@@ -113,7 +113,6 @@
113113
114bool IsWindowShadowDecorable(CompWindow*);114bool IsWindowShadowDecorable(CompWindow*);
115bool IsWindowFullyDecorable(CompWindow*);115bool IsWindowFullyDecorable(CompWindow*);
116bool WindowHasMotifDecorations(CompWindow*);
117116
118} // compiz_utils namespace117} // compiz_utils namespace
119} // unity namespace118} // unity namespace