summaryrefslogtreecommitdiff
path: root/shortcuts
diff options
authorMarco Trevisan (Treviño) <mail@3v1n0.net>2013-01-23 16:24:59 +0100
committerMarco Trevisan (Treviño) <mail@3v1n0.net>2013-01-23 16:24:59 +0100
commitb6e08c0093f83f188cbdce366db9e4e06a963353 (patch)
tree7fdb10510bbf87ecafd7be9e93181980467b3315 /shortcuts
parentd251f00d928bfafb4783106c35abe9e3464aef79 (diff)
ShortcutController: better handle model changes, use window matching layout size
(bzr r2919.3.64)
Diffstat (limited to 'shortcuts')
-rw-r--r--shortcuts/ShortcutController.cpp57
-rw-r--r--shortcuts/ShortcutController.h3
2 files changed, 41 insertions, 19 deletions
diff --git a/shortcuts/ShortcutController.cpp b/shortcuts/ShortcutController.cpp
index 2d4e9f26f..eb855df2e 100644
--- a/shortcuts/ShortcutController.cpp
+++ b/shortcuts/ShortcutController.cpp
@@ -65,15 +65,7 @@ Controller::Controller(BaseWindowRaiser::Ptr const& base_window_raiser,
SetOpacity(opacity);
});
- modeller->model_changed.connect([this] (Model::Ptr const& model) {
- if (!view_)
- return;
-
- if (visible_)
- model->Fill();
-
- view_->SetModel(model);
- });
+ modeller_->model_changed.connect(sigc::mem_fun(this, &Controller::OnModelUpdated));
}
Controller::~Controller()
@@ -89,6 +81,30 @@ void Controller::OnBackgroundUpdate(GVariant* data)
view_->background_color = bg_color_;
}
+void Controller::OnModelUpdated(Model::Ptr const& model)
+{
+ if (!view_)
+ return;
+
+ view_->SetModel(model);
+
+ if (Visible())
+ {
+ model->Fill();
+ auto uscreen = UScreen::GetDefault();
+ int monitor = uscreen->GetMonitorAtPosition(view_window_->GetX(), view_window_->GetX());
+ auto const& offset = GetOffsetPerMonitor(monitor);
+
+ if (offset.x < 0 || offset.y < 0)
+ {
+ Hide();
+ return;
+ }
+
+ view_window_->SetXY(offset.x, offset.y);
+ }
+}
+
bool Controller::Show()
{
if (enabled_ && modeller_->GetCurrentModel())
@@ -110,14 +126,17 @@ bool Controller::OnShowTimer()
modeller_->GetCurrentModel()->Fill();
EnsureView();
+ view_->ComputeContentSize();
+ view_window_->ComputeContentSize();
+
int monitor = UScreen::GetDefault()->GetMonitorWithMouse();
- auto const& geo = GetGeometryPerMonitor(monitor);
+ auto const& offset = GetOffsetPerMonitor(monitor);
- if (geo.IsNull())
+ if (offset.x < 0 || offset.y < 0)
return false;
base_window_raiser_->Raise(view_window_);
- view_window_->SetGeometry(geo);
+ view_window_->SetXY(offset.x, offset.y);
if (visible_)
{
@@ -137,7 +156,7 @@ bool Controller::OnShowTimer()
return false;
}
-nux::Geometry Controller::GetGeometryPerMonitor(int monitor)
+nux::Point Controller::GetOffsetPerMonitor(int monitor)
{
EnsureView();
@@ -147,14 +166,15 @@ nux::Geometry Controller::GetGeometryPerMonitor(int monitor)
if (adjustment_.x + view_geo.width > monitor_geo.width ||
adjustment_.y + view_geo.height > monitor_geo.height)
{
- return nux::Geometry();
+ // Invalid position
+ return nux::Point(std::numeric_limits<int>::min(), std::numeric_limits<int>::min());
}
- nux::Geometry geo(monitor_geo.x, monitor_geo.y, view_geo.width, view_geo.height);
- geo.x += adjustment_.x + (monitor_geo.width - view_geo.width - adjustment_.x) / 2;
- geo.y += adjustment_.y + (monitor_geo.height - view_geo.height - adjustment_.y) / 2;
+ nux::Point offset(adjustment_.x + monitor_geo.x, adjustment_.y + monitor_geo.y);
+ offset.x += (monitor_geo.width - view_geo.width - adjustment_.x) / 2;
+ offset.y += (monitor_geo.height - view_geo.height - adjustment_.y) / 2;
- return geo;
+ return offset;
}
void Controller::ConstructView()
@@ -173,6 +193,7 @@ void Controller::ConstructView()
view_window_ = new nux::BaseWindow("ShortcutHint");
view_window_->SetLayout(main_layout_);
view_window_->SetBackgroundColor(nux::color::Transparent);
+ view_window_->SetWindowSizeMatchLayout(true);
}
main_layout_->AddView(view_.GetPointer());
diff --git a/shortcuts/ShortcutController.h b/shortcuts/ShortcutController.h
index 0205d94d3..18ca21bd3 100644
--- a/shortcuts/ShortcutController.h
+++ b/shortcuts/ShortcutController.h
@@ -62,12 +62,13 @@ protected:
// Introspectable
std::string GetName() const;
void AddProperties(GVariantBuilder* builder);
- virtual nux::Geometry GetGeometryPerMonitor(int monitor);
+ virtual nux::Point GetOffsetPerMonitor(int monitor);
private:
void ConstructView();
void EnsureView();
void OnBackgroundUpdate(GVariant* data);
+ void OnModelUpdated(Model::Ptr const&);
bool OnShowTimer();
View::Ptr view_;