[Spice-devel] [vdagent PATCH] Add monitors_config driver escape.

sstutsma at redhat.com sstutsma at redhat.com
Thu Jun 18 16:14:10 PDT 2015


From: Sandy Stutsman <sstutsma at redhat.com>

When a Windows guest uses the "Set Resolution" applet to change
resolutions and/or monitor positions, this escape sends the new monitor
configurations to the client via a new QXL driver escape.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1202419
---
Depends on spice-protocol patch for qxl_windows.h
---
 vdagent/desktop_layout.cpp | 30 ++++++++++++++++++++++++++++--
 vdagent/desktop_layout.h   |  2 +-
 vdagent/vdagent.cpp        |  4 +++-
 3 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index f71abd0..3a97194 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -142,8 +142,8 @@ void DesktopLayout::set_displays()
             vd_printf("display_id %lu out of range, #displays %zu" , display_id, _displays.size());
             break;
         }
-        if (!init_dev_mode(dev_info.DeviceName, &dev_mode, _displays.at(display_id),
-                           normal_x, normal_y, true)) {
+        DisplayMode * mode(_displays.at(display_id));
+        if (!init_dev_mode(dev_info.DeviceName, &dev_mode, mode, normal_x, normal_y, true)) {
             vd_printf("No suitable mode found for display %S", dev_info.DeviceName);
             break;
         }
@@ -152,6 +152,7 @@ void DesktopLayout::set_displays()
                                            CDS_UPDATEREGISTRY | CDS_NORESET, NULL);
         if (ret == DISP_CHANGE_SUCCESSFUL) {
             dev_sets++;
+            update_monitor_config(dev_info.DeviceName, mode);
         }
         if (!is_qxl) {
             display_id++;
@@ -355,3 +356,28 @@ bool DesktopLayout::init_dev_mode(LPCTSTR dev_name, DEVMODE* dev_mode, DisplayMo
     return true;
 }
 
+bool DesktopLayout::update_monitor_config(LPCTSTR dev_name, DisplayMode* mode)
+{
+    QXLEscapeMonitorConfig MonitorConfig;
+
+    if (!mode || !mode->get_attached())
+        return false;
+
+    HDC hdc = CreateDC(dev_name, NULL, NULL, NULL);
+
+    MonitorConfig.bpp = mode->_depth;
+    MonitorConfig.xpos = mode->_pos_x;
+    MonitorConfig.ypos = mode->_pos_y;
+    MonitorConfig.xres = mode->_width;
+    MonitorConfig.yres = mode->_height;
+
+    int err = ExtEscape(hdc, QXL_ESCAPE_MONITOR_CONFIG,
+        sizeof(QXLEscapeMonitorConfig), (LPCSTR) &MonitorConfig, 0, NULL);
+
+    if (err < 0){
+        vd_printf("can't update monitor config, may have an older driver");
+    }
+
+    DeleteDC(hdc);
+    return (err >= 0);
+}
diff --git a/vdagent/desktop_layout.h b/vdagent/desktop_layout.h
index 4f6a042..0e310e3 100644
--- a/vdagent/desktop_layout.h
+++ b/vdagent/desktop_layout.h
@@ -83,7 +83,7 @@ private:
     static bool get_qxl_device_id(WCHAR* device_key, DWORD* device_id);
     static bool init_dev_mode(LPCTSTR dev_name, DEVMODE* dev_mode, DisplayMode* mode,
                               LONG normal_x, LONG normal_y, bool set_pos);
-
+    static bool update_monitor_config(LPCTSTR dev_name, DisplayMode* mode);
 private:
     mutex_t _mutex;
     Displays _displays;
diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index efce981..22860f4 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -1447,8 +1447,10 @@ LRESULT CALLBACK VDAgent::wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARA
         vd_printf("Display change");
         // the desktop layout needs to be updated for the mouse
         // position to be scaled correctly
-        if (!a->_updating_display_config)
+        if (!a->_updating_display_config) {
             a->_desktop_layout->get_displays();
+            a->_desktop_layout->set_displays();
+        }
         break;
     case WM_TIMER:
         a->send_input();
-- 
1.9.5.msysgit.0



More information about the Spice-devel mailing list