summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArnon Gilboa <agilboa@redhat.com>2012-01-04 12:52:15 +0200
committerArnon Gilboa <agilboa@redhat.com>2012-02-05 11:52:58 +0200
commitb127e5fdae0c95115a5c1f2223593adf64dd5cf7 (patch)
tree6180eb30aeb3a1e55f27175a40f367881f55931d
parent56f7f3f1d5ef6f28f58f3a3ed17957d0ad88411e (diff)
vdagent: fix cursor position sync on multimon rhbz#757819
On any change of the display settings, driven by client message or guest user, normalize all display positions to non-negative coordinates, and update total width and height of the virtual desktop. The bug was due to wrong handling of (non-primary) displays positioned on negative coordinates. Primary monitor is always located (in windows) in (0,0). When a secondary monitor is positioned above/to the left of the primary, it will have negative coordinate. This can be the case when guest display settings are changed either manually on the guest, or due to a message (auto-conf VD_AGENT_MONITORS_CONFIG) from the client to the agent. In VDAgent::handle_mouse_event(), mouse event is generated by scaling the received (x,y, display_id) to normalized absolute coordinates (0..0xffff) on the entire virtual desktop which contains all the displays. Keeping negative display coordinates, as received from the client, was mistakenly handled and generated wrong (sometimes even negative) coordinates.
-rw-r--r--vdagent/desktop_layout.cpp52
-rw-r--r--vdagent/desktop_layout.h1
2 files changed, 34 insertions, 19 deletions
diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index 0eada52..0ba7248 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -44,10 +44,6 @@ void DesktopLayout::get_displays()
DEVMODE mode;
DWORD display_id;
DWORD dev_id = 0;
- LONG min_x = 0;
- LONG min_y = 0;
- LONG max_x = 0;
- LONG max_y = 0;
bool attached;
lock();
@@ -81,22 +77,10 @@ void DesktopLayout::get_displays()
attached = !!(dev_info.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP);
EnumDisplaySettings(dev_info.DeviceName, ENUM_CURRENT_SETTINGS, &mode);
_displays[display_id] = new DisplayMode(mode.dmPosition.x, mode.dmPosition.y,
- mode.dmPelsWidth, mode.dmPelsHeight,
- mode.dmBitsPerPel, attached);
- if (attached) {
- min_x = min(min_x, mode.dmPosition.x);
- min_y = min(min_y, mode.dmPosition.y);
- max_x = max(max_x, mode.dmPosition.x + (LONG)mode.dmPelsWidth);
- max_y = max(max_y, mode.dmPosition.y + (LONG)mode.dmPelsHeight);
- }
- }
- if (min_x || min_y) {
- for (Displays::iterator iter = _displays.begin(); iter != _displays.end(); iter++) {
- (*iter)->move_pos(-min_x, -min_y);
- }
+ mode.dmPelsWidth, mode.dmPelsHeight,
+ mode.dmBitsPerPel, attached);
}
- _total_width = max_x - min_x;
- _total_height = max_y - min_y;
+ normalize_displays_pos();
unlock();
}
@@ -147,10 +131,40 @@ void DesktopLayout::set_displays()
}
if (dev_sets) {
ChangeDisplaySettingsEx(NULL, NULL, NULL, 0, NULL);
+ normalize_displays_pos();
}
unlock();
}
+// Normalize all display positions to non-negative coordinates and update total width and height of
+// the virtual desktop. Caller is responsible to lock() & unlock().
+void DesktopLayout::normalize_displays_pos()
+{
+ Displays::iterator iter;
+ DisplayMode* mode;
+ LONG min_x = 0;
+ LONG min_y = 0;
+ LONG max_x = 0;
+ LONG max_y = 0;
+
+ for (iter = _displays.begin(); iter != _displays.end(); iter++) {
+ mode = *iter;
+ if (mode->_attached) {
+ min_x = min(min_x, mode->_pos_x);
+ min_y = min(min_y, mode->_pos_y);
+ max_x = max(max_x, mode->_pos_x + (LONG)mode->_width);
+ max_y = max(max_y, mode->_pos_y + (LONG)mode->_height);
+ }
+ }
+ if (min_x || min_y) {
+ for (iter = _displays.begin(); iter != _displays.end(); iter++) {
+ (*iter)->move_pos(-min_x, -min_y);
+ }
+ }
+ _total_width = max_x - min_x;
+ _total_height = max_y - min_y;
+}
+
bool DesktopLayout::consistent_displays()
{
DISPLAY_DEVICE dev_info;
diff --git a/vdagent/desktop_layout.h b/vdagent/desktop_layout.h
index caab84f..c43ff03 100644
--- a/vdagent/desktop_layout.h
+++ b/vdagent/desktop_layout.h
@@ -73,6 +73,7 @@ public:
private:
void clean_displays();
+ void normalize_displays_pos();
static bool consistent_displays();
static bool is_attached(LPCTSTR dev_name);
static bool get_qxl_device_id(WCHAR* device_key, DWORD* device_id);