From kenneth@wangpedersen.com  Tue Oct 22 07:29:21 2013
Received: (at submit) by bugs.x2go.org; 22 Oct 2013 05:29:22 +0000
X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on
	ymir.das-netzwerkteam.de
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,URIBL_BLOCKED
	autolearn=ham version=3.3.2
X-Greylist: delayed 935 seconds by postgrey-1.34 at ymir; Tue, 22 Oct 2013 07:29:21 CEST
Received: from sender1.zohomail.com (sender1.zohomail.com [72.5.230.103])
	by ymir (Postfix) with ESMTP id 3974F5DB16
	for <submit@bugs.x2go.org>; Tue, 22 Oct 2013 07:29:21 +0200 (CEST)
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; 
  s=zoho; d=wangpedersen.com; 
  h=date:from:to:message-id:subject:mime-version:content-type:user-agent; 
  b=c9zlUIIIU3V3ldZpO4KweXw4L+NTOopZKYBVrDc5YjDJwVnoOOPLVgtiMCpdiMZfrr1BmYWimb3Z
    E6IWKIu3z0TIFt/X4J72d1OTj4NDB71qke/8HI6A6ggSFNyLwhMOpopn5i15YokD+FPxsYcfGA8e
    6BsQ9uZPhQoTPMRRpFc=  
Received: from mail.zoho.com by mx.zohomail.com
	with SMTP id 13824188241111001.6217835969067; Mon, 21 Oct 2013 22:13:44 -0700 (PDT)
Date: Mon, 21 Oct 2013 22:13:44 -0700
From: kenneth <kenneth@wangpedersen.com>
To:  <submit@bugs.x2go.org>
Message-ID: <1878608620.350326.1382418824063.JavaMail.sas1@[172.29.249.242]>
Subject: Incorrect detection of color depth on Windows
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Priority: Medium
User-Agent: Zoho Mail
X-Mailer: Zoho Mail

Package: python-x2go
Version: 0.4.0.8
Tags: patch

The following code is used when detecting color depth on Windows (in x2go/utils.py):

  return win32api.GetSystemMetrics(2)

The following constant actually has the numeric value 2: 
SM_CXVSCROLL - The width of a vertical scroll bar, in pixels. 
See e.g. http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85).aspx

At least on my system (Windows 7), this value is 17, causing python-x2go to incorrectly identify the display
as having 17 bits-per-pixel.

The attached patch fixes this issue by creating a screen display context and querying it for the color depth.

Regards,
Kenneth Pedersen

>From aba9e380f1a26299042a7f075217c9ad99505f73 Mon Sep 17 00:00:00 2001
From: Kenneth Pedersen <kenneth@wangpedersen.com>
Date: Mon, 21 Oct 2013 22:07:53 +0200
Subject: [PATCH] Detect color depth correctly on Windows

---
 x2go/utils.py | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/x2go/utils.py b/x2go/utils.py
index e8d80bc..8ecbf2c 100644
--- a/x2go/utils.py
+++ b/x2go/utils.py
@@ -48,6 +48,8 @@ if _X2GOCLIENT_OS != 'Windows':
 if _X2GOCLIENT_OS == 'Windows':
     import win32api
     import win32gui
+    import win32print
+    import win32con
 
 def is_in_nx3packmethods(method):
 
@@ -555,8 +557,10 @@ def local_color_depth():
             return 24
 
     else:
-        return win32api.GetSystemMetrics(2)
-
+        # This gets the color depth of the primary monitor. All monitors need not have the same color depth.
+        dc = win32gui.GetDC(None)
+        _depth = win32print.GetDeviceCaps(dc, win32con.BITSPIXEL) * win32print.GetDeviceCaps(dc, win32con.PLANES)
+        win32gui.ReleaseDC(None, dc)
 
 def is_color_depth_ok(depth_session, depth_local):
     """\
-- 
1.8.4.msysgit.0

