diff options
| author | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-08-05 23:22:40 +0200 |
|---|---|---|
| committer | Marco Trevisan (Treviño) <mail@3v1n0.net> | 2014-08-05 23:22:40 +0200 |
| commit | b0b57195b624d2c3326e9b591bf2f695143a38a3 (patch) | |
| tree | 3f084295e3e08c0be832594a2a17c1c66cdda9f7 /unity-shared | |
| parent | 0ab956e7d678e588455a5e3cdbd1dc7524c600c6 (diff) | |
UScreen: get monitor at position, ignoring pre-multipled Gdk scale factor
Get monitor position based on absolute coordinates, ignoring the pre-multipled scaling factor that Gdk applies to all the monitor sizes. In this way we get the proper monitor index, independently from the scaling factor. (bzr r3844.5.2)
Diffstat (limited to 'unity-shared')
| -rw-r--r-- | unity-shared/UScreen.cpp | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/unity-shared/UScreen.cpp b/unity-shared/UScreen.cpp index 97be8dd32..91407a0c7 100644 --- a/unity-shared/UScreen.cpp +++ b/unity-shared/UScreen.cpp @@ -18,6 +18,8 @@ #include "UScreen.h" #include <NuxCore/Logger.h> +#include <NuxCore/NuxCore.h> +#include <NuxGraphics/GraphicsDisplay.h> namespace unity { @@ -60,17 +62,8 @@ UScreen* UScreen::GetDefault() int UScreen::GetMonitorWithMouse() const { - GdkDevice* device; - GdkDisplay *display; - int x; - int y; - - display = gdk_display_get_default(); - device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(display)); - - gdk_device_get_position(device, nullptr, &x, &y); - - return GetMonitorAtPosition(x, y); + auto const& mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord(); + return GetMonitorAtPosition(mouse.x, mouse.y); } int UScreen::GetPrimaryMonitor() const @@ -80,6 +73,23 @@ int UScreen::GetPrimaryMonitor() const int UScreen::GetMonitorAtPosition(int x, int y) const { + int monitors = gdk_screen_get_n_monitors(screen_); + + for (int i = 0; i < monitors; ++i) + { + 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; + } + return gdk_screen_get_monitor_at_point(screen_, x, y); } @@ -151,7 +161,10 @@ void UScreen::Refresh() gdk_screen_get_monitor_geometry(screen_, i, &rect); float scale = gdk_screen_get_monitor_scale_factor(screen_, i); - nux::Geometry geo(rect.x*scale, rect.y*scale, rect.width*scale, rect.height*scale); + nux::Geometry geo(rect.x, rect.y, rect.width, rect.height); + + if (scale != 1.0) + geo = geo * scale; // Check for mirrored displays if (geo == last_geo) |
