~brandontschaefer/unity/move-window-buttons-unity-shared

« back to all changes in this revision

Viewing changes to shortcuts/ShortcutController.cpp

  • Committer: Tarmac
  • Author(s): Marco Trevisan (Treviño)
  • Date: 2013-01-23 10:36:37 UTC
  • mfrom: (2919.3.60 shortcut-WS-dynamic)
  • Revision ID: tarmac-20130123103637-jm981x8jre95g5v6
ShortcutModeller: added a modeller that generates the shortcuts models for both compiz and standalone view.

Approved by Andrea Azzarone.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 */
19
19
 
20
20
#include "ShortcutController.h"
 
21
#include "ShortcutModel.h"
21
22
 
22
23
#include "unity-shared/UBusMessages.h"
23
24
#include "unity-shared/UScreen.h"
34
35
const unsigned int FADE_DURATION = 100;
35
36
}
36
37
 
37
 
Controller::Controller(std::list<AbstractHint::Ptr> const& hints,
38
 
                       BaseWindowRaiser::Ptr const& base_window_raiser)
39
 
  : model_(std::make_shared<Model>(hints))
 
38
Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,
 
39
                       AbstractModeller::Ptr const& modeller)
 
40
  : modeller_(modeller)
40
41
  , base_window_raiser_(base_window_raiser)
41
42
  , visible_(false)
42
43
  , enabled_(true)
43
44
  , bg_color_(0.0, 0.0, 0.0, 0.5)
44
45
  , fade_animator_(FADE_DURATION)
45
46
{
46
 
  model_->Fill();
47
 
 
48
47
  ubus_manager_.RegisterInterest(UBUS_BACKGROUND_COLOR_CHANGED,
49
48
                                 sigc::mem_fun(this, &Controller::OnBackgroundUpdate));
50
49
 
65
64
  fade_animator_.updated.connect([this] (double opacity) {
66
65
    SetOpacity(opacity);
67
66
  });
 
67
 
 
68
  modeller->model_changed.connect([this] (Model::Ptr const& model) {
 
69
    if (!view_)
 
70
      return;
 
71
 
 
72
    if (visible_)
 
73
      model->Fill();
 
74
 
 
75
    view_->SetModel(model);
 
76
  });
68
77
}
69
78
 
70
79
Controller::~Controller()
82
91
 
83
92
bool Controller::Show()
84
93
{
85
 
  if (enabled_)
 
94
  if (enabled_ && modeller_->GetCurrentModel())
86
95
  {
87
 
    EnsureView();
88
 
 
89
96
    show_timer_.reset(new glib::Timeout(SUPER_TAP_DURATION, sigc::mem_fun(this, &Controller::OnShowTimer)));
90
 
    model_->Fill();
91
97
    visible_ = true;
92
98
 
93
99
    return true;
98
104
 
99
105
bool Controller::OnShowTimer()
100
106
{
101
 
  if (!enabled_)
 
107
  if (!enabled_ || !modeller_->GetCurrentModel())
102
108
    return false;
103
109
 
104
 
  base_window_raiser_->Raise(view_window_);
 
110
  modeller_->GetCurrentModel()->Fill();
 
111
  EnsureView();
105
112
 
106
113
  int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
107
114
  auto const& geo = GetGeometryPerMonitor(monitor);
109
116
  if (geo.IsNull())
110
117
    return false;
111
118
 
 
119
  base_window_raiser_->Raise(view_window_);
112
120
  view_window_->SetGeometry(geo);
113
121
 
114
122
  if (visible_)
131
139
 
132
140
nux::Geometry Controller::GetGeometryPerMonitor(int monitor)
133
141
{
134
 
  if (!view_)
135
 
    ConstructView();
 
142
  EnsureView();
136
143
 
137
144
  auto const& view_geo = view_->GetAbsoluteGeometry();
138
145
  auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor);
154
161
{
155
162
  view_ = View::Ptr(new View());
156
163
  AddChild(view_.GetPointer());
157
 
  view_->SetModel(model_);
 
164
  view_->SetModel(modeller_->GetCurrentModel());
158
165
  view_->background_color = bg_color_;
159
166
 
160
167
  if (!view_window_)
165
172
 
166
173
    view_window_ = new nux::BaseWindow("ShortcutHint");
167
174
    view_window_->SetLayout(main_layout_);
168
 
    view_window_->SetBackgroundColor(nux::Color(0x00000000));
 
175
    view_window_->SetBackgroundColor(nux::color::Transparent);
169
176
  }
170
177
 
171
178
  main_layout_->AddView(view_.GetPointer());