summaryrefslogtreecommitdiff
path: root/unity-shared
diff options
authorAndrea Azzarone <azzaronea@gmail.com>2014-11-07 18:04:00 +0100
committerAndrea Azzarone <azzaronea@gmail.com>2014-11-07 18:04:00 +0100
commit3dea32678de4f55ff5024b665d6361292c9fe0b2 (patch)
tree07cbb25199a2ca1c16243217feb6f4ebfc8434e7 /unity-shared
parent349a6b9030a3643e578858e4c7cbbe0b94bc79d0 (diff)
Make sure GetScreenGeometry returns the correct value.
(bzr r3884.6.1)
Diffstat (limited to 'unity-shared')
-rw-r--r--unity-shared/UScreen.cpp34
1 files changed, 19 insertions, 15 deletions
diff --git a/unity-shared/UScreen.cpp b/unity-shared/UScreen.cpp
index 91407a0c7..7a3e6c6d9 100644
--- a/unity-shared/UScreen.cpp
+++ b/unity-shared/UScreen.cpp
@@ -73,21 +73,13 @@ int UScreen::GetPrimaryMonitor() const
int UScreen::GetMonitorAtPosition(int x, int y) const
{
- int monitors = gdk_screen_get_n_monitors(screen_);
+ int idx = 0;
- for (int i = 0; i < monitors; ++i)
+ for (auto const& monitor : monitors_)
{
- GdkRectangle rect = { 0 };
- gdk_screen_get_monitor_geometry(screen_, i, &rect);
-
- float scale = gdk_screen_get_monitor_scale_factor(screen_, i);
- nux::Geometry geo(rect.x, rect.y, rect.width, rect.height);
-
- if (scale != 1.0)
- geo = geo * scale;
-
- if (geo.IsPointInside(x, y))
- return i;
+ if (monitor.IsPointInside(x, y))
+ return idx;
+ ++idx;
}
return gdk_screen_get_monitor_at_point(screen_, x, y);
@@ -105,8 +97,20 @@ std::vector<nux::Geometry> const& UScreen::GetMonitors() const
nux::Geometry UScreen::GetScreenGeometry() const
{
- int width = gdk_screen_get_width(screen_);
- int height = gdk_screen_get_height(screen_);
+ if (monitors_.empty())
+ return nux::Geometry();
+
+ auto rightmost_geo = max_element(monitors_.begin(), monitors_.end(), [](nux::Geometry const& a, nux::Geometry const& b) {
+ return a.x + a.width < b.x + b.width;
+ });
+
+ auto lower_geo = max_element(monitors_.begin(), monitors_.end(), [](nux::Geometry const& a, nux::Geometry const& b) {
+ return a.y + a.height < b.y + b.height;
+ });
+
+ auto width = rightmost_geo->x + rightmost_geo->width;
+ auto height = lower_geo->y + lower_geo->height;
+
return nux::Geometry(0, 0, width, height);
}