From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Daniel Colascione Newsgroups: gmane.emacs.devel Subject: [PATCH 1/9] Under Remote Desktop, NUMCOLORS is unreliable; workaround Date: Tue, 07 Aug 2012 01:19:27 -0700 Message-ID: <139f6550dc3f2f06eaea8a9a23bcf30333a41bcb.1344326992.git.dancol@dancol.org> References: NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1344327582 790 80.91.229.3 (7 Aug 2012 08:19:42 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 7 Aug 2012 08:19:42 +0000 (UTC) To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 07 10:19:42 2012 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Syf0v-000329-R0 for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 10:19:41 +0200 Original-Received: from localhost ([::1]:49849 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0u-0000gt-Oc for ged-emacs-devel@m.gmane.org; Tue, 07 Aug 2012 04:19:40 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:57357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0p-0000f7-5I for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:39 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Syf0n-0007jr-RY for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:35 -0400 Original-Received: from dancol.org ([96.126.100.184]:37128) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Syf0n-0007iX-LI for emacs-devel@gnu.org; Tue, 07 Aug 2012 04:19:33 -0400 Original-Received: from dancol by dancol.org with local (Exim 4.72) (envelope-from ) id 1Syf0h-0006pq-4M for emacs-devel@gnu.org; Tue, 07 Aug 2012 01:19:27 -0700 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 96.126.100.184 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:152236 Archived-At: Under remote desktop, Windows returns the wrong number of colors from GetDeviceCaps (hdc, NUMCOLORS). I hit this bug myself, and MSDN comments seem to indicate that others hit it as well. The workaround seems harmless: on non-palettized displays, calculating the number of display colors based on display bitness should produce good results. --- src/w32fns.c | 9 ++++++++- 1 files changed, 8 insertions(+), 1 deletions(-) diff --git a/src/w32fns.c b/src/w32fns.c index b82d4bc..7fc5cf5 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -4513,8 +4513,15 @@ If omitted or nil, that stands for the selected frame's display. */) hdc = GetDC (dpyinfo->root_window); if (dpyinfo->has_palette) cap = GetDeviceCaps (hdc, SIZEPALETTE); - else + else if (dpyinfo->n_cbits <= 8) + /* According to the MSDN, GetDeviceCaps (NUMCOLORS) is valid only + for devices with at most eight bits per pixel. It's supposed + to return -1 for other displays, but because it actually + returns other, incorrect values under some conditions (e.g., + remote desktop), only use it when we know it's valid. */ cap = GetDeviceCaps (hdc, NUMCOLORS); + else + cap = -1; /* We force 24+ bit depths to 24-bit, both to prevent an overflow and because probably is more meaningful on Windows anyway */ -- 1.7.2.5