~thalexander/unity/update-fsf-address

« back to all changes in this revision

Viewing changes to lockscreen/LockScreenShield.cpp

  • Committer: Marco Trevisan (Treviño)
  • Date: 2016-03-07 18:51:47 UTC
  • mfrom: (4080 unity)
  • mto: This revision was merged to the branch mainline in revision 4085.
  • Revision ID: mail@3v1n0.net-20160307185147-0p1m89up4tqfb6w1
Merge with trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include <Nux/VLayout.h>
23
23
#include <Nux/HLayout.h>
24
 
#include <Nux/PaintLayer.h>
25
24
 
26
 
#include "BackgroundSettings.h"
27
 
#include "CofView.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"
34
28
 
35
29
namespace unity
36
30
{
37
31
namespace lockscreen
38
32
{
39
 
namespace
40
 
{
41
 
const unsigned MAX_GRAB_WAIT = 100;
42
 
}
43
33
 
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)
52
 
  , cof_view_(nullptr)
53
41
{
54
 
  UpdateScale();
55
42
  is_primary ? ShowPrimaryView() : ShowSecondaryView();
56
 
 
57
43
  EnableInputWindow(true);
58
44
 
59
 
  unity::Settings::Instance().dpi_changed.connect(sigc::mem_fun(this, &Shield::UpdateScale));
60
 
  geometry_changed.connect([this] (nux::Area*, nux::Geometry&) { UpdateBackgroundTexture();});
61
 
 
62
45
  monitor.changed.connect([this] (int monitor) {
63
 
    UpdateScale();
64
 
 
65
46
    if (panel_view_)
66
47
      panel_view_->monitor = monitor;
67
 
 
68
 
    UpdateBackgroundTexture();
69
48
  });
70
49
 
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);
75
 
    QueueRelayout();
76
 
    QueueDraw();
77
 
  });
78
 
 
79
 
  scale.changed.connect([this] (double scale) {
80
 
    if (prompt_view_ && primary())
81
 
      prompt_view_->scale = scale;
82
 
 
83
 
    if (cof_view_)
84
 
      cof_view_->scale = scale;
85
 
 
86
 
    if (prompt_layout_)
87
 
      prompt_layout_->SetLeftAndRightPadding(2 * Settings::GRID_SIZE.CP(scale));
88
 
 
89
 
    background_layer_.reset();
90
 
    UpdateBackgroundTexture();
91
 
  });
92
 
 
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);
96
 
  });
97
 
}
98
 
 
99
 
void Shield::UpdateScale()
100
 
{
101
 
  scale = unity::Settings::Instance().em(monitor)->DPIScale();
102
 
}
103
 
 
104
 
void Shield::UpdateBackgroundTexture()
105
 
{
106
 
  auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
107
 
 
108
 
  if (!background_layer_ || monitor_geo != background_layer_->GetGeometry())
109
 
  {
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());
113
 
  }
114
 
}
115
 
 
116
 
void Shield::GrabScreen(bool cancel_on_failure)
117
 
{
118
 
  auto& wc = nux::GetWindowCompositor();
119
 
 
120
 
  if (wc.GrabPointerAdd(this) && wc.GrabKeyboardAdd(this))
121
 
  {
122
 
    regrab_conn_->disconnect();
123
 
    regrab_timeout_.reset();
124
 
    grabbed.emit();
125
 
  }
126
 
  else
127
 
  {
128
 
    auto const& retry_cb = sigc::bind(sigc::mem_fun(this, &Shield::GrabScreen), false);
129
 
    regrab_conn_ = WindowManager::Default().screen_ungrabbed.connect(retry_cb);
130
 
 
131
 
    if (cancel_on_failure)
132
 
    {
133
 
      regrab_timeout_.reset(new glib::Timeout(MAX_GRAB_WAIT, [this] {
134
 
        grab_failed.emit();
135
 
        return false;
136
 
      }));
137
 
    }
138
 
  }
139
 
}
140
 
 
141
 
bool Shield::HasGrab() const
142
 
{
143
 
  auto& wc = nux::GetWindowCompositor();
144
 
  return (wc.GetPointerGrabArea() == this && wc.GetKeyboardGrabArea() == this);
 
52
  });
145
53
}
146
54
 
147
55
void Shield::ShowPrimaryView()
181
89
  main_layout->AddSpace(0, 10);
182
90
}
183
91
 
184
 
void Shield::ShowSecondaryView()
185
 
{
186
 
  if (prompt_layout_)
187
 
    prompt_layout_->RemoveChildObject(prompt_view_.GetPointer());
188
 
 
189
 
  if (cof_layout_)
190
 
  {
191
 
    SetLayout(cof_layout_.GetPointer());
192
 
    return;
193
 
  }
194
 
 
195
 
  nux::Layout* main_layout = new nux::VLayout();
196
 
  cof_layout_ = main_layout;
197
 
  SetLayout(cof_layout_.GetPointer());
198
 
 
199
 
  // The circle of friends
200
 
  cof_view_ = new CofView();
201
 
  cof_view_->scale = scale();
202
 
  main_layout->AddView(cof_view_);
203
 
}
204
 
 
205
92
Panel* Shield::CreatePanel()
206
93
{
207
94
  if (!indicators_ || !session_manager_)
259
146
  return nullptr;
260
147
}
261
148
 
262
 
bool Shield::AcceptKeyNavFocus()
263
 
{
264
 
  return false;
265
 
}
266
 
 
267
 
nux::Area* Shield::FindAreaUnderMouse(nux::Point const& mouse, nux::NuxEventType event_type)
268
 
{
269
 
  nux::Area* area = BaseWindow::FindAreaUnderMouse(mouse, event_type);
270
 
 
271
 
  if (!area && primary)
272
 
    return this;
273
 
 
274
 
  return area;
275
 
}
276
 
 
277
149
bool Shield::IsIndicatorOpen() const
278
150
{
279
151
  return panel_view_ ? panel_view_->active() : false;