1
// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
3
* Copyright (C) 2013 Canonical Ltd
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.
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.
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/>.
17
* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com>
20
#include "LockScreenController.h"
21
#include "unity-shared/UScreen.h"
28
Controller::Controller(session::Manager::Ptr const& manager)
30
, locked_(false) // FIXME unity can start in lock state!
32
auto* uscreen = UScreen::GetDefault();
33
EnsureShields(uscreen->GetMonitorWithMouse(), uscreen->GetMonitors());
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));
40
void Controller::OnUScreenChanged(int primary, std::vector<nux::Geometry> const& monitors)
42
auto* uscreen = UScreen::GetDefault();
43
EnsureShields(uscreen->GetMonitorWithMouse(), monitors);
46
void Controller::EnsureShields(int monitor_with_mouse, std::vector<nux::Geometry> const& monitors)
48
int num_monitors = monitors.size();
49
int num_shields = num_monitors;
50
int shields_size = shields_.size();
53
for (int i = 0; i < num_shields; ++i, ++last_shield)
55
if (i >= shields_size)
57
shields_.push_back(CreateShield(i == monitor_with_mouse));
59
else if (!shields_.at(i))
61
shields_[i] = CreateShield(i == monitor_with_mouse);
64
shields_[i]->SetGeometry(monitors.at(i));
67
for (int i = last_shield; i < shields_size; ++i)
71
shields_.resize(num_shields);
74
nux::ObjectPtr<Shield> Controller::CreateShield(bool is_monitor_with_mouse)
76
nux::ObjectPtr<Shield> shield(new Shield(is_monitor_with_mouse));
80
void Controller::OnLockRequested()
85
std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {
86
shield->SetOpacity(1.0f);
87
shield->ShowWindow(true);
93
void Controller::OnUnlockRequested()
98
std::for_each(shields_.begin(), shields_.end(), [](nux::ObjectPtr<Shield> const& shield) {
99
shield->SetOpacity(0.0f);
100
shield->ShowWindow(false);
b'\\ No newline at end of file'