~brandontschaefer/unity/bump-to-new-nux-abi

« back to all changes in this revision

Viewing changes to lockscreen/LockScreenController.cpp

  • Committer: Andrea Azzarone
  • Date: 2013-12-28 17:34:36 UTC
  • mto: (3566.5.438 unity)
  • mto: This revision was merged to the branch mainline in revision 3703.
  • Revision ID: azzaronea@gmail.com-20131228173436-jqschonskxaj5xx3
Initial commit for the unity lockscreen. UserAuthenticator added with tests too.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
 
2
/*
 
3
* Copyright (C) 2013 Canonical Ltd
 
4
*
 
5
* This program is free software: you can redistribute it and/or modify
 
6
* it under the terms of the GNU General Public License version 3 as
 
7
* published by the Free Software Foundation.
 
8
*
 
9
* This program is distributed in the hope that it will be useful,
 
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
* GNU General Public License for more details.
 
13
*
 
14
* You should have received a copy of the GNU General Public License
 
15
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
16
*
 
17
* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
 
18
*/
 
19
 
 
20
#include "LockScreenController.h"
 
21
#include "unity-shared/UScreen.h"
 
22
 
 
23
namespace unity
 
24
{
 
25
namespace lockscreen
 
26
{
 
27
 
 
28
Controller::Controller(session::Manager::Ptr const& manager)
 
29
  : manager_(manager)
 
30
  , locked_(false) // FIXME unity can start in lock state!
 
31
{
 
32
  auto* uscreen = UScreen::GetDefault();
 
33
  EnsureShields(uscreen->GetMonitorWithMouse(), uscreen->GetMonitors());
 
34
 
 
35
  uscreen->changed.connect(sigc::mem_fun(this, &Controller::OnUScreenChanged));
 
36
  manager_->lock_requested.connect(sigc::mem_fun(this, &Controller::OnLockRequested));
 
37
  manager_->unlock_requested.connect(sigc::mem_fun(this, &Controller::OnUnlockRequested));
 
38
}
 
39
 
 
40
void Controller::OnUScreenChanged(int primary, std::vector<nux::Geometry> const& monitors)
 
41
{
 
42
  auto* uscreen = UScreen::GetDefault();
 
43
  EnsureShields(uscreen->GetMonitorWithMouse(), monitors);
 
44
}
 
45
 
 
46
void Controller::EnsureShields(int monitor_with_mouse, std::vector<nux::Geometry> const& monitors)
 
47
{
 
48
  int num_monitors = monitors.size();
 
49
  int num_shields = num_monitors;
 
50
  int shields_size = shields_.size();
 
51
  int last_shield = 0;
 
52
 
 
53
  for (int i = 0; i < num_shields; ++i, ++last_shield)
 
54
  {
 
55
    if (i >= shields_size)
 
56
    {
 
57
      shields_.push_back(CreateShield(i == monitor_with_mouse));
 
58
    }
 
59
    else if (!shields_.at(i))
 
60
    {
 
61
      shields_[i] = CreateShield(i == monitor_with_mouse);
 
62
    }
 
63
 
 
64
    shields_[i]->SetGeometry(monitors.at(i));
 
65
  }
 
66
 
 
67
  for (int i = last_shield; i < shields_size; ++i)
 
68
  {
 
69
  }
 
70
 
 
71
  shields_.resize(num_shields);
 
72
}
 
73
 
 
74
nux::ObjectPtr<Shield> Controller::CreateShield(bool is_monitor_with_mouse)
 
75
{
 
76
  nux::ObjectPtr<Shield> shield(new Shield(is_monitor_with_mouse));
 
77
  return shield;
 
78
}
 
79
 
 
80
void Controller::OnLockRequested()
 
81
{
 
82
  if (locked_)
 
83
    return;
 
84
 
 
85
  std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {
 
86
    shield->SetOpacity(1.0f);
 
87
    shield->ShowWindow(true);
 
88
  });
 
89
 
 
90
  locked_ = true;
 
91
}
 
92
 
 
93
void Controller::OnUnlockRequested()
 
94
{
 
95
  if (!locked_)
 
96
    return;
 
97
 
 
98
  std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {
 
99
    shield->SetOpacity(0.0f);
 
100
    shield->ShowWindow(false);
 
101
  });
 
102
 
 
103
  locked_ = false;
 
104
}
 
105
 
 
106
 
 
107
 
 
108
}
 
109
}
 
 
b'\\ No newline at end of file'