~unity-team/unity/trusty-1328677

« back to all changes in this revision

Viewing changes to lockscreen/UserPromptView.cpp

  • Committer: CI bot
  • Author(s): Chris Townsend, Andrea Azzarone, Alfred Neumayer, Brandon Schaefer, Marco Trevisan (Treviño)
  • Date: 2014-07-14 14:30:31 UTC
  • mfrom: (3797.1.35 unity.trusty-7.2.2)
  • Revision ID: ps-jenkins@lists.canonical.com-20140714143031-f5ky7acxlp761352
Prepare for upstream micro-release 7.2.2 that includes fixes for the following bugs:
Bug #607796: Launcher, Window management - Dragging and holding a selection over an entry in the Launcher should spread out windows belonging to that application
Bug #727902: Launcher icon highlighting should not switch off as soon the cursor moves after the app spread appears.
Bug #741869: Unity/compiz intercepts Super and Alt keypresses from grabbed windows like VMs.
Bug #754580: Cannot move tabs between multiple Firefox or Chromium windows while using Unity unless windows are both unmaximized, unminimized, and visible.
Bug #839728: Launcher - dragging a item on top of a launcher tile that is a valid drop receptacle in the Launcher should cause that launcher tile to glow
Bug #924840: Keyboard shortcuts overlay text too long
Bug #1281058: [UIFe] The system shutdowns when multiple accounts are open
Bug #1283775: Launcher: icon pips are not always updated properly
Bug #1304882: [Regression] Launcher doesn't reappear fully after hiding from DND
Bug #1305586: Lock screen is unusable when some windows have a keyboard/mouse grab
Bug #1307738: Lockscreen caps lock icon drawn under text entry, should be a white icon.
Bug #1308288: Lockscreen warning icon has no tooltip
Bug #1308323: Shutdown/reboot/login/logout dialogs not scaled after toggling UI scale Edit
Bug #1308911: Clipboard contents are accessible within lockscreen
Bug #1309739: Unity launcher icon edge illumination is offset
Bug #1310200: Indicators disappear at the panel (clementine, dropbox, skype etc)
Bug #1313280: Fullscreen window set to "Always on Top" in single-monitor will hide the lockscreen
Bug #1316005: Panel shadow appears over full screen applications w/ locally integrated menus enabled
Bug #1317348: Switcher (Alt-Tab) does not respect monitor-defined scaling factor
Bug #1317356: Shortcut hint does not respect monitor scaling factor
Bug #1317869: Keyboard shortcuts overlay does not show up when workspaces are enabled at 1366x768
Bug #1320438: Unity launcher auto hide fails on screen unlock using "Super+L"
Bug #1321043: [regression] lock screen bypass with touchpad Fixes: 607796, 727902, 741869, 754580, 839728, 924840, 1281058, 1283775, 1304882, 1305586, 1307738, 1308288, 1308323, 1308911, 1309739, 1310200, 1313280, 1316005, 1317348, 1317356, 1317869, 1320438, 1321043
Approved by: Marco Trevisan (Treviño)

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <boost/algorithm/string/trim.hpp>
23
23
#include <Nux/VLayout.h>
24
 
#include <X11/XKBlib.h>
25
24
 
26
25
#include "LockScreenSettings.h"
27
26
#include "unity-shared/CairoTexture.h"
28
27
#include "unity-shared/DashStyle.h"
29
 
#include "unity-shared/PreviewStyle.h"
30
28
#include "unity-shared/TextInput.h"
31
29
#include "unity-shared/StaticCairoText.h"
32
30
#include "unity-shared/RawPixel.h"
40
38
const RawPixel PADDING              = 10_em;
41
39
const RawPixel LAYOUT_MARGIN        = 10_em;
42
40
const RawPixel MSG_LAYOUT_MARGIN    = 15_em;
43
 
const RawPixel PROMPT_LAYOUT_MARGIN = 5_em;
 
41
const RawPixel PROMPT_LAYOUT_MARGIN =  5_em;
44
42
 
45
 
const int PROMPT_FONT_SIZE     = 13;
 
43
const int PROMPT_FONT_SIZE = 13;
46
44
 
47
45
nux::AbstractPaintLayer* CrateBackgroundLayer(int width, int height)
48
46
{
78
76
                                rop));
79
77
}
80
78
 
81
 
nux::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
 
 
103
79
std::string SanitizeMessage(std::string const& message)
104
80
{
105
81
  std::string msg = boost::algorithm::trim_copy(message);
124
100
UserPromptView::UserPromptView(session::Manager::Ptr const& session_manager)
125
101
  : nux::View(NUX_TRACKER_LOCATION)
126
102
  , session_manager_(session_manager)
127
 
  , caps_lock_on_(false)
128
103
{
129
104
  user_authenticator_.echo_on_requested.connect([this](std::string const& message, PromiseAuthCodePtr const& promise){
130
105
    AddPrompt(message, /* visible */ true, promise);
146
121
    ResetLayout();
147
122
  });
148
123
 
149
 
  dash::previews::Style& preview_style = dash::previews::Style::Instance();
150
 
 
151
 
  warning_ = preview_style.GetWarningIcon();
152
124
  ResetLayout();
153
125
 
154
126
  user_authenticator_.AuthenticateStart(session_manager_->UserName(),
155
127
                                        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
 
 
164
 
void 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;
175
128
}
176
129
 
177
130
bool UserPromptView::InspectKeyEvent(unsigned int eventType, unsigned int key_sym, const char* character)
179
132
  if ((eventType == nux::NUX_KEYDOWN) && (key_sym == NUX_VK_ESCAPE))
180
133
  {
181
134
    if (!focus_queue_.empty())
182
 
      focus_queue_.front()->SetText("");
 
135
      focus_queue_.front()->text_entry()->SetText("");
183
136
 
184
137
    return true;
185
138
  }
260
213
    nux::GetPainter().PushLayer(graphics_engine, geo, bg_layer_.get());
261
214
  }
262
215
 
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
 
 
272
216
  if (GetLayout())
273
217
    GetLayout()->ProcessDraw(graphics_engine, force_draw);
274
218
 
278
222
  graphics_engine.PopClippingRectangle();
279
223
}
280
224
 
281
 
void 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
 
 
289
 
int UserPromptView::GetWarningIconOffset()
290
 
{
291
 
  return warning_->GetWidth() + spin_icon_width_;
292
 
}
293
 
 
294
225
nux::View* UserPromptView::focus_view()
295
226
{
296
227
  if (focus_queue_.empty())
297
228
    return nullptr;
298
229
 
299
230
  for (auto* view : focus_queue_)
300
 
    if (view->HasKeyboardFocus())
 
231
    if (view->text_entry()->HasKeyboardFocus())
301
232
      return view;
302
233
 
303
 
  return focus_queue_.front();
304
 
}
305
 
 
306
 
void UserPromptView::ToggleCapsLockBool()
307
 
{
308
 
  caps_lock_on_ = !caps_lock_on_;
309
 
  QueueDraw();
310
 
}
311
 
 
312
 
void 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
 
  }
 
234
  return focus_queue_.front()->text_entry();
324
235
}
325
236
 
326
237
void UserPromptView::AddPrompt(std::string const& message, bool visible, PromiseAuthCodePtr const& promise)
330
241
 
331
242
  text_input->input_hint = SanitizeMessage(message);
332
243
  text_input->hint_font_size = PROMPT_FONT_SIZE;
 
244
  text_input->show_caps_lock = true;
333
245
  text_entry->SetPasswordMode(!visible);
334
246
  text_entry->SetPasswordChar("•");
335
247
  text_entry->SetToggleCursorVisibilityOnKeyFocus(true);
336
 
 
337
 
  text_entry->key_up.connect(sigc::mem_fun(this, &UserPromptView::RecvKeyUp));
 
248
  text_entry->clipboard_enabled = false;
338
249
 
339
250
  text_input->SetMinimumHeight(Settings::GRID_SIZE);
340
251
  text_input->SetMaximumHeight(Settings::GRID_SIZE);
341
252
  prompt_layout_->AddView(text_input, 1);
342
 
  focus_queue_.push_back(text_entry);
343
 
 
344
 
  CheckIfCapsLockOn();
 
253
  focus_queue_.push_back(text_input);
345
254
 
346
255
  // Don't remove it, it helps with a11y.
347
256
  if (focus_queue_.size() == 1)