22
22
#include <Nux/VLayout.h>
23
23
#include <Nux/HLayout.h>
24
#include <Nux/PaintLayer.h>
26
#include "BackgroundSettings.h"
28
25
#include "LockScreenPanel.h"
29
26
#include "LockScreenSettings.h"
30
#include "UserPromptView.h"
31
#include "unity-shared/UScreen.h"
32
#include "unity-shared/UnitySettings.h"
33
#include "unity-shared/WindowManager.h"
27
#include "LockScreenAbstractPromptView.h"
37
31
namespace lockscreen
41
const unsigned MAX_GRAB_WAIT = 100;
44
34
Shield::Shield(session::Manager::Ptr const& session_manager,
45
35
indicator::Indicators::Ptr const& indicators,
46
36
Accelerators::Ptr const& accelerators,
47
nux::ObjectPtr<UserPromptView> const& prompt_view,
37
nux::ObjectPtr<AbstractUserPromptView> const& prompt_view,
48
38
int monitor_num, bool is_primary)
49
: AbstractShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary)
50
, bg_settings_(std::make_shared<BackgroundSettings>())
39
: BaseShield(session_manager, indicators, accelerators, prompt_view, monitor_num, is_primary)
51
40
, panel_view_(nullptr)
55
42
is_primary ? ShowPrimaryView() : ShowSecondaryView();
57
43
EnableInputWindow(true);
59
unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &Shield::UpdateScale));
60
geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();});
62
45
monitor.changed.connect([this] (int monitor) {
66
47
panel_view_->monitor = monitor;
68
UpdateBackgroundTexture();
71
50
primary.changed.connect([this] (bool is_primary) {
72
regrab_conn_->disconnect();
73
is_primary ? ShowPrimaryView() : ShowSecondaryView();
74
51
if (panel_view_) panel_view_->SetInputEventSensitivity(is_primary);
79
scale.changed.connect([this] (double scale) {
80
if (prompt_view_ && primary())
81
prompt_view_->scale = scale;
84
cof_view_->scale = scale;
87
prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale));
89
background_layer_.reset();
90
UpdateBackgroundTexture();
93
mouse_move.connect([this] (int x, int y, int, int, unsigned long, unsigned long) {
94
auto const& abs_geo = GetAbsoluteGeometry();
95
grab_motion.emit(abs_geo.x + x, abs_geo.y + y);
99
void Shield::UpdateScale()
101
scale = unity::Settings::Instance().em(monitor)->DPIScale();
104
void Shield::UpdateBackgroundTexture()
106
auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
108
if (!background_layer_ || monitor_geo != background_layer_->GetGeometry())
110
auto background_texture = bg_settings_->GetBackgroundTexture(monitor);
111
background_layer_.reset(new nux::TextureLayer(background_texture->GetDeviceTexture(), nux::TexCoordXForm(), nux::color::White, true));
112
SetBackgroundLayer(background_layer_.get());
116
void Shield::GrabScreen(bool cancel_on_failure)
118
auto& wc = nux::GetWindowCompositor();
120
if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this))
122
regrab_conn_->disconnect();
123
regrab_timeout_.reset();
128
auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &Shield::GrabScreen), false);
129
regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb);
131
if (cancel_on_failure)
133
regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] {
141
bool Shield::HasGrab() const
143
auto& wc = nux::GetWindowCompositor();
144
return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this);
147
55
void Shield::ShowPrimaryView()
181
89
main_layout->AddSpace(0, 10);
184
void Shield::ShowSecondaryView()
187
prompt_layout_->RemoveChildObject(prompt_view_.GetPointer());
191
SetLayout(cof_layout_.GetPointer());
195
nux::Layout* main_layout = new nux::VLayout();
196
cof_layout_ = main_layout;
197
SetLayout(cof_layout_.GetPointer());
199
// The circle of friends
200
cof_view_ = new CofView();
201
cof_view_->scale = scale();
202
main_layout->AddView(cof_view_);
205
92
Panel* Shield::CreatePanel()
207
94
if (!indicators_ || !session_manager_)