From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#10397: [PATCH] Under Remote Desktop, NUMCOLORS is unreliable; workaround Date: Fri, 30 Dec 2011 10:51:40 +0200 Message-ID: <8362gyv3vn.fsf@gnu.org> References: <69c9ec930ef1d48655624d437aa66d0fce275d3e.1325166766.git.dancol@dancol.org> <4EFC9416.6090005@dancol.org> <4EFC987D.2020901@dancol.org> <4EFCF0BF.1020907@dancol.org> <4EFD2D75.3030603@dancol.org> Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1325235198 8234 80.91.229.12 (30 Dec 2011 08:53:18 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 30 Dec 2011 08:53:18 +0000 (UTC) Cc: lekktu@gmail.com, 10397@debbugs.gnu.org To: Daniel Colascione Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Dec 30 09:53:14 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RgYDB-0006Wt-Nb for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2011 09:53:13 +0100 Original-Received: from localhost ([::1]:40525 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgYDA-0000yc-Uw for geb-bug-gnu-emacs@m.gmane.org; Fri, 30 Dec 2011 03:53:12 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:57440) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgYD7-0000yL-9J for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2011 03:53:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RgYD5-0000Lq-Vw for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2011 03:53:09 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:58274) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RgYD5-0000Lm-T5 for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2011 03:53:07 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1RgYFu-0004Ss-4O for bug-gnu-emacs@gnu.org; Fri, 30 Dec 2011 03:56:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 30 Dec 2011 08:56:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10397 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 10397-submit@debbugs.gnu.org id=B10397.132523533417126 (code B ref 10397); Fri, 30 Dec 2011 08:56:02 +0000 Original-Received: (at 10397) by debbugs.gnu.org; 30 Dec 2011 08:55:34 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgYFS-0004SA-Mb for submit@debbugs.gnu.org; Fri, 30 Dec 2011 03:55:34 -0500 Original-Received: from mtaout20.012.net.il ([80.179.55.166]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1RgYFQ-0004S1-18 for 10397@debbugs.gnu.org; Fri, 30 Dec 2011 03:55:33 -0500 Original-Received: from conversion-daemon.a-mtaout20.012.net.il by a-mtaout20.012.net.il (HyperSendmail v2007.08) id <0LX000400DRTOO00@a-mtaout20.012.net.il> for 10397@debbugs.gnu.org; Fri, 30 Dec 2011 10:51:40 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.126.18.76]) by a-mtaout20.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LX0003VJDY2H1J0@a-mtaout20.012.net.il>; Fri, 30 Dec 2011 10:51:40 +0200 (IST) In-reply-to: <4EFD2D75.3030603@dancol.org> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Fri, 30 Dec 2011 03:56:02 -0500 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:55300 Archived-At: > Date: Thu, 29 Dec 2011 19:18:13 -0800 > From: Daniel Colascione > Cc: 10397@debbugs.gnu.org > > > Hmm. Shouldn't in fact GetDeviceCaps (hdc, NUMCOLORS) always be <= 256? > > > > According to http://msdn.microsoft.com/en-us/library/dd144877(v=vs.85).aspx > > > > NUMCOLORS > > Number of entries in the device's color table, if the device has a > > color depth of no more than 8 bits per pixel. For devices with greater > > color depths, 1 is returned. > > > > (It says "1", but it's a typo for "-1".) > > Good catch. What about this (untested) code? > > hdc = GetDC (dpyinfo->root_window); > if (dpyinfo->has_palette) > cap = GetDeviceCaps (hdc, SIZEPALETTE); > 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; There's a comment near the end of the GetDeviceCaps documentation saying this: NUMCOLORS doesn't always return one with more than 256 colors The documentation for NUMCOLORS is wrong, devices that support more than 256 colors often return -1 and some virtual machines can return the number of Windows reserved colors (i.e. 20), even in high color mode. Combine the NUMCOLORS return value with BITSPIXEL and PLANES to reliably detect indexed color. So how about using `1 << (n_planes * n_cbits)' (which we compute when NUMCOLORS call returns -1) unconditionally? IOW, why do we need to call GetDeviceCaps(..., NUMCOLORS) here in the first place?