2
* Copyright (C) 2011 Canonical Ltd
4
* This program is free software: you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 3 as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
* Authored by: Andrea Azzarone <azzaronea@gmail.com>
19
#include "ShortcutController.h"
21
#include "UBusMessages.h"
22
#include "ubus-server.h"
23
#include "WindowManager.h"
31
const unsigned int SUPER_TAP_DURATION = 650;
32
} // anonymouse namespace;
34
Controller::Controller(std::list<AbstractHint*>& hints)
38
, fade_in_animator_(new Animator(100))
39
, fade_out_animator_(new Animator(100))
42
bg_color_ = nux::Color(0.0, 0.0, 0.0, 0.5);
44
UBusServer *ubus = ubus_server_get_default();
45
bg_update_handle_ = ubus_server_register_interest(ubus, UBUS_BACKGROUND_COLOR_CHANGED,
46
(UBusCallback)&Controller::OnBackgroundUpdate,
49
model_.reset(new Model(hints));
54
fade_in_animator_->animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeInUpdated));
55
fade_in_animator_->animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeInEnded));
56
fade_out_animator_->animation_updated.connect(sigc::mem_fun(this, &Controller::OnFadeOutUpdated));
57
fade_out_animator_->animation_ended.connect(sigc::mem_fun(this, &Controller::OnFadeOutEnded));
60
Controller::~Controller()
62
ubus_server_unregister_interest(ubus_server_get_default(), bg_update_handle_);
64
if (fade_in_animator_)
65
delete fade_in_animator_;
67
if (fade_out_animator_)
68
delete fade_out_animator_;
71
view_window_->UnReference();
77
void Controller::OnFadeInUpdated(double opacity)
79
view_window_->SetOpacity(opacity);
82
void Controller::OnFadeInEnded()
84
view_window_->SetOpacity(1.0);
87
void Controller::OnFadeOutUpdated(double progress)
89
double opacity = CLAMP(1.0f - progress, 0.0f, 1.0f);
90
view_window_->SetOpacity(opacity);
93
void Controller::OnFadeOutEnded()
95
view_window_->SetOpacity(0.0);
99
void Controller::OnBackgroundUpdate(GVariant* data, Controller* self)
101
gdouble red, green, blue, alpha;
102
g_variant_get(data, "(dddd)", &red, &green, &blue, &alpha);
103
self->bg_color_ = nux::Color(red, green, blue, alpha);
106
self->view_->background_color = self->bg_color_;
109
void Controller::Show()
112
g_source_remove (show_timer_);
113
show_timer_ = g_timeout_add(SUPER_TAP_DURATION, &Controller::OnShowTimer, this);
119
gboolean Controller::OnShowTimer(gpointer data)
121
Controller* self = static_cast<Controller*>(data);
123
ubus_server_send_message(ubus_server_get_default(),
124
UBUS_PLACE_VIEW_CLOSE_REQUEST,
129
self->view_->SetupBackground(true);
130
self->fade_out_animator_->Stop();
131
self->fade_in_animator_->Start(self->view_window_->GetOpacity());
134
self->show_timer_ = 0;
138
void Controller::ConstructView()
140
view_ = View::Ptr(new View());
141
view_->SetModel(model_);
142
view_->background_color = bg_color_;
146
main_layout_ = new nux::HLayout(NUX_TRACKER_LOCATION);
147
main_layout_->SetVerticalExternalMargin(0);
148
main_layout_->SetHorizontalExternalMargin(0);
150
view_window_ = new nux::BaseWindow("ShortcutHint");
151
view_window_->SinkReference();
152
view_window_->SetLayout(main_layout_);
153
view_window_->SetBackgroundColor(nux::Color(0x00000000));
156
main_layout_->AddView(view_.GetPointer(), 1);
158
view_->SetupBackground(false);
159
view_window_->SetOpacity(0.0);
160
view_window_->ShowWindow(true);
163
void Controller::SetWorkspace(nux::Geometry const& geo)
166
view_window_->SetGeometry(workarea_);
169
void Controller::Hide()
178
view_->SetupBackground(false);
179
fade_in_animator_->Stop();
180
fade_out_animator_->Start(1.0 - view_window_->GetOpacity());
184
g_source_remove(show_timer_);
188
bool Controller::Visible()
193
} // namespace shortcut