diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2013-01-21 17:06:36 +0100 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2013-01-21 17:06:36 +0100 |
| commit | 1078c59ac3fbb5714f9697fc8a84b774e57a4469 (patch) | |
| tree | b14d0e9df45ab84ca5c2c6d4f854dd40ee10ca20 /shortcuts | |
| parent | 41db8c704d0af7281f5ca65e3eb2916b999cbc38 (diff) | |
ShortcutController: compute the view position on screen
(bzr r2919.3.36)
Diffstat (limited to 'shortcuts')
| -rw-r--r-- | shortcuts/ShortcutController.cpp | 34 | ||||
| -rw-r--r-- | shortcuts/ShortcutController.h | 4 |
2 files changed, 32 insertions, 6 deletions
diff --git a/shortcuts/ShortcutController.cpp b/shortcuts/ShortcutController.cpp index ce770b265..1c2a1858f 100644 --- a/shortcuts/ShortcutController.cpp +++ b/shortcuts/ShortcutController.cpp @@ -19,6 +19,7 @@ #include "ShortcutController.h" #include "unity-shared/UBusMessages.h" +#include "unity-shared/UScreen.h" namespace na = nux::animation; @@ -101,8 +102,10 @@ bool Controller::OnShowTimer() base_window_raiser_->Raise(view_window_); - nux::Geometry geo; - if (!view_->GetBaseGeometry(geo)) + int monitor = UScreen::GetDefault()->GetMonitorWithMouse(); + auto const& geo = GetGeometryPerMonitor(monitor); + + if (geo.IsNull()) return false; view_window_->SetGeometry(geo); @@ -125,6 +128,27 @@ bool Controller::OnShowTimer() return false; } +nux::Geometry Controller::GetGeometryPerMonitor(int monitor) +{ + if (!view_) + ConstructView(); + + auto const& view_geo = view_->GetAbsoluteGeometry(); + auto const& monitor_geo = UScreen::GetDefault()->GetMonitorGeometry(monitor); + + if (adjustment_.x + view_geo.width > monitor_geo.width || + adjustment_.y + view_geo.height > monitor_geo.height) + { + return nux::Geometry(); + } + + 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; + + return geo; +} + void Controller::ConstructView() { view_ = View::Ptr(new View()); @@ -158,12 +182,10 @@ void Controller::EnsureView() void Controller::SetAdjustment(int x, int y) { - EnsureView(); - - view_->SetAdjustment(x, y); + adjustment_.x = x; + adjustment_.y = y; } - void Controller::Hide() { if (!visible_) diff --git a/shortcuts/ShortcutController.h b/shortcuts/ShortcutController.h index 1dd636542..7a2ddb2c7 100644 --- a/shortcuts/ShortcutController.h +++ b/shortcuts/ShortcutController.h @@ -63,6 +63,7 @@ protected: // Introspectable std::string GetName() const; void AddProperties(GVariantBuilder* builder); + virtual nux::Geometry GetGeometryPerMonitor(int monitor); private: void ConstructView(); @@ -77,6 +78,7 @@ private: nux::Geometry workarea_; nux::ObjectPtr<nux::BaseWindow> view_window_; nux::HLayout* main_layout_; + nux::Point adjustment_; bool visible_; bool enabled_; @@ -86,6 +88,8 @@ private: glib::Source::UniquePtr show_timer_; UBusManager ubus_manager_; + + friend class TestShortcutController; }; } |
