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: Marco Trevisan (Treviño) <marco@ubuntu.com>
20
#include "SessionController.h"
22
#include "unity-shared/UBusMessages.h"
23
#include "unity-shared/UScreen.h"
25
namespace na = nux::animation;
33
const unsigned int FADE_DURATION = 100;
36
Controller::Controller(session::Manager::Ptr const& manager)
38
, bg_color_(0.0, 0.0, 0.0, 0.5)
39
, fade_animator_(FADE_DURATION)
41
ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED,
42
sigc::mem_fun(this, &Controller::OnBackgroundUpdate));
44
ubus_manager_.SendMessage(UBUS_BACKGROUND_REQUEST_COLOUR_EMIT);
46
fade_animator_.updated.connect([this] (double opacity) {
50
view_window_->SetOpacity(opacity);
52
if (opacity == 0.0f && fade_animator_.GetFinishValue() == 0.0f)
57
void Controller::OnBackgroundUpdate(GVariant* data)
59
gdouble red, green, blue, alpha;
60
g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
61
bg_color_ = nux::Color(red, green, blue, alpha);
64
view_->background_color = bg_color_;
67
void Controller::Show()
71
view_->SetupBackground(true);
73
int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
74
auto const& offset = GetOffsetPerMonitor(monitor);
75
view_window_->SetXY(offset.x, offset.y);
76
view_window_->EnableInputWindow(true, view_window_->GetWindowName().c_str(), true, false);
77
view_window_->ShowWindow(true);
78
view_window_->PushToFront();
80
if (fade_animator_.CurrentState() == na::Animation::State::Running)
82
if (fade_animator_.GetFinishValue() == 0.0f)
83
fade_animator_.Reverse();
87
fade_animator_.SetStartValue(0.0f).SetFinishValue(1.0f).Start();
91
nux::Point Controller::GetOffsetPerMonitor(int monitor)
95
// view_window_->ComputeContentSize();
96
auto const& view_geo = view_->GetAbsoluteGeometry();
97
auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
99
//TODO get adjustment from windowmanager!
100
nux::Point offset(adjustment_.x + monitor_geo.x, adjustment_.y + monitor_geo.y);
101
offset.x += (monitor_geo.width - view_geo.width - adjustment_.x) / 2;
102
offset.y += (monitor_geo.height - view_geo.height - adjustment_.y) / 2;
107
void Controller::ConstructView()
109
view_ = View::Ptr(new View(manager_));
110
view_->SetupBackground(false);
111
view_->background_color = bg_color_;
112
AddChild(view_.GetPointer());
114
auto layout = new nux::HLayout(NUX_TRACKER_LOCATION);
115
layout->SetVerticalExternalMargin(0);
116
layout->SetHorizontalExternalMargin(0);
117
layout->AddView(view_.GetPointer());
119
view_window_ = new nux::BaseWindow("SessionManager");
120
view_window_->SetLayout(layout);
121
view_window_->SetBackgroundColor(nux::color::Transparent);
122
view_window_->SetWindowSizeMatchLayout(true);
123
view_window_->ShowWindow(false);
126
void Controller::EnsureView()
132
void Controller::Hide()
134
if (fade_animator_.CurrentState() == na::Animation::State::Running)
136
if (fade_animator_.GetFinishValue() == 1.0f)
137
fade_animator_.Reverse();
141
fade_animator_.SetStartValue(1.0f).SetFinishValue(0.0f).Start();
145
void Controller::CloseWindow()
147
view_window_->PushToBack();
148
view_window_->ShowWindow(false);
149
view_window_->EnableInputWindow(false);
150
view_->SetupBackground(false);
156
std::string Controller::GetName() const
158
return "ShutdownController";
161
void Controller::AddProperties(GVariantBuilder* builder)
163
unity::variant::BuilderWrapper(builder)
164
.add("visible", (view_window_ && view_window_->GetOpacity() == 1.0f));
167
} // namespace session