Merge lp:~unity-team/unity/fix-lp1351591-trusty into lp:unity/7.2

Proposed by Christopher Townsend
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 3833
Proposed branch: lp:~unity-team/unity/fix-lp1351591-trusty
Merge into: lp:unity/7.2
Diff against target: 128 lines (+52/-18)
2 files modified
services/panel-service.c (+44/-6)
unity-shared/UScreen.cpp (+8/-12)
To merge this branch: bzr merge lp:~unity-team/unity/fix-lp1351591-trusty
Reviewer Review Type Date Requested Status
Marco Trevisan (Treviño) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+264836@code.launchpad.net

Commit message

UScreen, PanelService: 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 for absolute coordinates, independently from the scaling factor.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Marco Trevisan (Treviño) (3v1n0) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'services/panel-service.c'
2--- services/panel-service.c 2015-03-11 18:11:24 +0000
3+++ services/panel-service.c 2015-07-15 14:25:58 +0000
4@@ -263,6 +263,15 @@
5 g_type_class_add_private (obj_class, sizeof (PanelServicePrivate));
6 }
7
8+static gboolean
9+is_point_in_rect (gint x, gint y, GdkRectangle* rect)
10+{
11+ g_return_val_if_fail (rect, FALSE);
12+
13+ return (x >= rect->x && x <= (rect->x + rect->width) &&
14+ y >= rect->y && y <= (rect->y + rect->height));
15+}
16+
17 IndicatorObjectEntry *
18 get_entry_at (PanelService *self, gint x, gint y)
19 {
20@@ -280,8 +289,7 @@
21 IndicatorObjectEntry *entry = k;
22 GdkRectangle *geo = v;
23
24- if (x >= geo->x && x <= (geo->x + geo->width) &&
25- y >= geo->y && y <= (geo->y + geo->height))
26+ if (is_point_in_rect (x, y, geo))
27 {
28 return entry;
29 }
30@@ -1621,11 +1629,41 @@
31 }
32
33 static int
34+get_monitor_at (gint x, gint y)
35+{
36+ gint i;
37+ gdouble scale;
38+ GdkScreen *screen = gdk_screen_get_default ();
39+ gint monitors = gdk_screen_get_n_monitors (screen);
40+
41+ for (i = 0; i < monitors; ++i)
42+ {
43+ GdkRectangle rect = { 0 };
44+ gdk_screen_get_monitor_geometry (screen, i, &rect);
45+ scale = gdk_screen_get_monitor_scale_factor (screen, i);
46+
47+ if (scale != 1.0)
48+ {
49+ rect.x *= scale;
50+ rect.y *= scale;
51+ rect.width *= scale;
52+ rect.height *= scale;
53+ }
54+
55+ if (is_point_in_rect (x, y, &rect))
56+ {
57+ return i;
58+ }
59+ }
60+
61+ return gdk_screen_get_monitor_at_point (screen, x, y);
62+}
63+
64+static int
65 get_monitor_scale_at (gint x, gint y)
66 {
67- GdkScreen *screen = gdk_screen_get_default ();
68- int monitor = gdk_screen_get_monitor_at_point (screen, x, y);
69- return gdk_screen_get_monitor_scale_factor (screen, monitor);
70+ gint monitor = get_monitor_at (x, y);
71+ return gdk_screen_get_monitor_scale_factor (gdk_screen_get_default (), monitor);
72 }
73
74 static void
75@@ -1639,7 +1677,7 @@
76 PanelServicePrivate *priv = self->priv;
77
78 GdkScreen *screen = gdk_screen_get_default ();
79- gint monitor = gdk_screen_get_monitor_at_point (screen, priv->last_x, priv->last_y);
80+ gint monitor = get_monitor_at (priv->last_x, priv->last_y);
81 gtk_menu_set_monitor (menu, monitor);
82
83 gint scale = gdk_screen_get_monitor_scale_factor (screen, monitor);
84
85=== modified file 'unity-shared/UScreen.cpp'
86--- unity-shared/UScreen.cpp 2015-03-12 00:57:05 +0000
87+++ unity-shared/UScreen.cpp 2015-07-15 14:25:58 +0000
88@@ -18,6 +18,8 @@
89
90 #include "UScreen.h"
91 #include <NuxCore/Logger.h>
92+#include <NuxCore/NuxCore.h>
93+#include <NuxGraphics/GraphicsDisplay.h>
94
95 namespace unity
96 {
97@@ -61,17 +63,8 @@
98
99 int UScreen::GetMonitorWithMouse() const
100 {
101- GdkDevice* device;
102- GdkDisplay *display;
103- int x;
104- int y;
105-
106- display = gdk_display_get_default();
107- device = gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(display));
108-
109- gdk_device_get_position(device, nullptr, &x, &y);
110-
111- return GetMonitorAtPosition(x, y);
112+ auto const& mouse = nux::GetGraphicsDisplay()->GetMouseScreenCoord();
113+ return GetMonitorAtPosition(mouse.x, mouse.y);
114 }
115
116 int UScreen::GetPrimaryMonitor() const
117@@ -170,7 +163,10 @@
118 gdk_screen_get_monitor_geometry(screen_, i, &rect);
119
120 float scale = gdk_screen_get_monitor_scale_factor(screen_, i);
121- nux::Geometry geo(rect.x*scale, rect.y*scale, rect.width*scale, rect.height*scale);
122+ nux::Geometry geo(rect.x, rect.y, rect.width, rect.height);
123+
124+ if (scale != 1.0)
125+ geo = geo * scale;
126
127 // Check for mirrored displays
128 if (geo == last_geo)

Subscribers

People subscribed via source and target branches

to status/vote changes: