[X2Go-Dev] Bug#330: Incorrect detection of color depth on Windows

kenneth kenneth at wangpedersen.com
Tue Oct 22 07:13:44 CEST 2013


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 at 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



More information about the x2go-dev mailing list