[Spice-commits] 2 commits - vdagent/desktop_layout.cpp vdagent/vdagent.cpp

Arnon Gilboa agilboa at kemper.freedesktop.org
Wed Apr 24 02:04:59 PDT 2013


 vdagent/desktop_layout.cpp |   35 ++++++++++++++++++++++++++---------
 vdagent/vdagent.cpp        |    4 +++-
 2 files changed, 29 insertions(+), 10 deletions(-)

New commits:
commit de672f8cf216c2e6f1797358e2a43b9b55d9b60a
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Tue Apr 23 17:08:02 2013 +0200

    Revert "Refresh monitor config only when needed"
    
    This reverts commit 67c1bcf49367d1726033b298a8ab016b4e22cf23.
    
    Also add a comment why the refresh is necessary there. The original
    issue, reentering call, doesn't seem reproducible...
    
    https://bugzilla.redhat.com/show_bug.cgi?id=912793

diff --git a/vdagent/vdagent.cpp b/vdagent/vdagent.cpp
index f254d55..dde967c 100644
--- a/vdagent/vdagent.cpp
+++ b/vdagent/vdagent.cpp
@@ -610,7 +610,6 @@ bool VDAgent::handle_mon_config(VDAgentMonitorsConfig* mon_config, uint32_t port
     VDAgentReply* reply;
     size_t display_count;
 
-    _desktop_layout->get_displays();
     display_count = _desktop_layout->get_display_count();
     for (uint32_t i = 0; i < display_count; i++) {
         DisplayMode* mode = _desktop_layout->get_display(i);
@@ -1368,6 +1367,9 @@ LRESULT CALLBACK VDAgent::wnd_proc(HWND hwnd, UINT message, WPARAM wparam, LPARA
     switch (message) {
     case WM_DISPLAYCHANGE:
         vd_printf("Display change");
+        // the desktop layout needs to be updated for the mouse
+        // position to be scaled correctly
+        a->_desktop_layout->get_displays();
         break;
     case WM_TIMER:
         a->send_input();
commit 8628ca2e09dab3cf5cb753e83cc0ed9e2dad21bc
Author: Marc-André Lureau <marcandre.lureau at gmail.com>
Date:   Mon Apr 22 23:08:30 2013 +0200

    Try harder to enable monitors
    
    0ba6e2936 was trying to fix CreateDC() failing when the monitor is
    disabled, unfortunately, enabling monitor with an arbitrary resolution
    may still fail (the previous resolution, or the current one).
    
    This patch address the issue by first trying the current resolution, and
    falling back to a well-known resolution. This causes a temporary client
    resolution change (bad), which is immediately adjusted to the arbitrary
    resolution.
    
    We may want to improve agent->driver communication of arbitrary
    resolution before the driver is loaded, perhaps using registry or via
    the spice server. Any of these solution will unfortunately take some more
    time which we are missing.
    
    https://bugzilla.redhat.com/show_bug.cgi?id=922394
    
    (seem to solve related bugs, like mouse offset, or flashing monitors)

diff --git a/vdagent/desktop_layout.cpp b/vdagent/desktop_layout.cpp
index bce9ac0..c474edb 100644
--- a/vdagent/desktop_layout.cpp
+++ b/vdagent/desktop_layout.cpp
@@ -253,19 +253,36 @@ bool DesktopLayout::init_dev_mode(LPCTSTR dev_name, DEVMODE* dev_mode, DisplayMo
         return true;
     }
 
-    // attach
-    EnumDisplaySettings(dev_name, ENUM_CURRENT_SETTINGS, dev_mode);
-    ret = ChangeDisplaySettingsEx(dev_name, dev_mode, NULL, CDS_UPDATEREGISTRY, NULL);
-    vd_printf("attach %d", ret);
-
-    // Update custom resolution
-    custom.xres = mode->_width;
-    custom.yres = mode->_height;
-    custom.bpp = mode->_depth;
     hdc = CreateDC(dev_name, NULL, NULL, NULL);
     if (!hdc) {
+        // for some reason, windows want those 3 flags to enable monitor
+        dev_mode->dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_POSITION;
+        dev_mode->dmPelsWidth = mode->_width;
+        dev_mode->dmPelsHeight = mode->_height;
+        ret = ChangeDisplaySettingsEx(dev_name, dev_mode, NULL, CDS_UPDATEREGISTRY, NULL);
+        if (ret == DISP_CHANGE_BADMODE) {
+            // custom resolution might not be set yet, use known resolution
+            // FIXME: this causes client temporary resize... a
+            // solution would involve passing custom resolution before
+            // driver initialization, perhaps through registry
+            dev_mode->dmPelsWidth = 640;
+            dev_mode->dmPelsHeight = 480;
+            ret = ChangeDisplaySettingsEx(dev_name, dev_mode, NULL, CDS_UPDATEREGISTRY, NULL);
+        }
+
+        vd_printf("attach %d", ret);
+        hdc = CreateDC(dev_name, NULL, NULL, NULL);
+    }
+
+    if (!hdc) {
         vd_printf("failed to create DC");
+        return false;
     } else {
+        // Update custom resolution
+        custom.xres = mode->_width;
+        custom.yres = mode->_height;
+        custom.bpp = mode->_depth;
+
         int err = ExtEscape(hdc, QXL_ESCAPE_SET_CUSTOM_DISPLAY,
                             sizeof(QXLEscapeSetCustomDisplay), (LPCSTR)&custom, 0, NULL);
         if (err <= 0) {


More information about the Spice-commits mailing list