From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.bugs Subject: bug#4234: allow xterm to detect the background color Date: Sat, 22 Aug 2009 10:15:12 -0700 (PDT) Message-ID: <200908221715.n7MHFCVA002498@godzilla.ics.uci.edu> Reply-To: Dan Nicolaescu , 4234@emacsbugs.donarmstrong.com NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1250962094 13084 80.91.229.12 (22 Aug 2009 17:28:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 22 Aug 2009 17:28:14 +0000 (UTC) To: bug-gnu-emacs Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Aug 22 19:28:07 2009 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MeuNo-00042t-BI for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 19:28:05 +0200 Original-Received: from localhost ([127.0.0.1]:46617 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeuNn-0005AG-GF for geb-bug-gnu-emacs@m.gmane.org; Sat, 22 Aug 2009 13:28:03 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeuMn-0004sF-QQ for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:27:01 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeuMi-0004qG-FW for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:27:01 -0400 Original-Received: from [199.232.76.173] (port=48426 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeuMi-0004q9-8A for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:26:56 -0400 Original-Received: from rzlab.ucr.edu ([138.23.92.77]:43114) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MeuMh-0003JO-HG for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:26:55 -0400 Original-Received: from rzlab.ucr.edu (rzlab.ucr.edu [127.0.0.1]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7MHQpU3013488; Sat, 22 Aug 2009 10:26:53 -0700 Original-Received: (from debbugs@localhost) by rzlab.ucr.edu (8.14.3/8.14.3/Submit) id n7MHP6o0013121; Sat, 22 Aug 2009 10:25:06 -0700 Resent-Date: Sat, 22 Aug 2009 10:25:06 -0700 X-Loop: owner@emacsbugs.donarmstrong.com Resent-From: Dan Nicolaescu Resent-To: bug-submit-list@donarmstrong.com Resent-CC: Emacs Bugs 2Resent-Date: Sat, 22 Aug 2009 17:25:06 +0000 Resent-Message-ID: Resent-Sender: owner@emacsbugs.donarmstrong.com X-Emacs-PR-Message: report 4234 X-Emacs-PR-Package: emacs X-Emacs-PR-Keywords: Original-Received: via spool by submit@emacsbugs.donarmstrong.com id=B.125096142911836 (code B ref -1); Sat, 22 Aug 2009 17:25:06 +0000 Original-Received: (at submit) by emacsbugs.donarmstrong.com; 22 Aug 2009 17:17:09 +0000 X-Spam-Bayes: score:0.5 Bayes not run. spammytokens:Tokens not available. hammytokens:Tokens not available. Original-Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) by rzlab.ucr.edu (8.14.3/8.14.3/Debian-5) with ESMTP id n7MHH7fp011830 for ; Sat, 22 Aug 2009 10:17:08 -0700 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MeuDC-0007zP-Ss for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:17:06 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MeuD6-0007tX-S6 for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:17:06 -0400 Original-Received: from [199.232.76.173] (port=50985 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MeuD6-0007tP-P1 for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:17:00 -0400 Original-Received: from sallyv2.ics.uci.edu ([128.195.1.120]:60987) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MeuD6-0001Lv-At for bug-gnu-emacs@gnu.org; Sat, 22 Aug 2009 13:17:00 -0400 Original-Received: from godzilla.ics.uci.edu (godzilla.ics.uci.edu [128.195.10.101]) by sallyv2.ics.uci.edu (8.13.8+Sun/8.13.8) with ESMTP id n7MHFCff004350 for ; Sat, 22 Aug 2009 10:15:12 -0700 (PDT) Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n7MHFCVA002498; Sat, 22 Aug 2009 10:15:12 -0700 (PDT) Original-Lines: 80 X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: n7MHFCff004350 X-ICS-MailScanner: Found to be clean X-ICS-MailScanner-SpamCheck: not spam, SpamAssassin (score=-1.44, required 5, autolearn=disabled, ALL_TRUSTED -1.44) X-ICS-MailScanner-From: dann@godzilla.ics.uci.edu X-detected-operating-system: by monty-python.gnu.org: Solaris 10 (beta) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) Resent-Date: Sat, 22 Aug 2009 13:27:00 -0400 X-BeenThere: bug-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:30478 Archived-At: emacs/emacsclient -nw running in an xterm set the frame background mode to 'light. Not all users use the default white background, so they get the wrong face colors. Newer xterms can tell what the background color is (see http://permalink.gmane.org/gmane.emacs.devel/111270) This patch implements reads the background color from xterm (iff it supports the feature) and sets the background mode accordingly. --- xterm.el.~1.62.~ 2009-01-08 14:24:21.000000000 -0800 +++ xterm.el 2009-08-22 10:12:38.000000000 -0700 @@ -462,8 +462,6 @@ (set-keymap-parent input-decode-map map))) (xterm-register-default-colors) - ;; This recomputes all the default faces given the colors we've just set up. - (tty-set-up-initial-frame-faces) ;; Try to turn on the modifyOtherKeys feature on modern xterms. ;; When it is turned on many more key bindings work: things like @@ -472,7 +470,8 @@ ;; modifyOtherKeys. At this time only xterm does. (let ((coding-system-for-read 'binary) (chr nil) - (str nil)) + (str nil) + version) ;; Pending input can be mistakenly returned by the calls to ;; read-event below. Discard it. (discard-input) @@ -494,8 +493,23 @@ ;; NUMBER2 is the xterm version number, look for something ;; greater than 216, the version when modifyOtherKeys was ;; introduced. - (when (>= (string-to-number - (substring str (match-beginning 1) (match-end 1))) 216) + (setq version (string-to-number + (substring str (match-beginning 1) (match-end 1)))) + ;; xterm version 242 supports reporting the background + ;; color, maybe earlier versions do too... + (when (>= version 242) + (send-string-to-terminal "\e]11;?\e\\") + (when (equal (read-event nil nil 2) ?\e) + (when (equal (read-event nil nil 2) ?\]) + (setq str "") + (while (not (equal (setq chr (read-event nil nil 2)) ?\\)) + (setq str (concat str (string chr)))) + (when (string-match "11;rgb:\\([a-f0-9]+\\)/\\([a-f0-9]+\\)/\\([a-f0-9]+\\)" str) + (xterm-set-background-mode + (string-to-number (match-string 1 str) 16) + (string-to-number (match-string 2 str) 16) + (string-to-number (match-string 3 str) 16)))))) + (when (>= version 216) ;; Make sure that the modifyOtherKeys state is restored when ;; suspending, resuming and exiting. (add-hook 'suspend-hook 'xterm-turn-off-modify-other-keys) @@ -508,6 +522,9 @@ xterm-modify-other-keys-terminal-list) (xterm-turn-on-modify-other-keys)))))) + ;; This recomputes all the default faces given the colors we've just set up. + (tty-set-up-initial-frame-faces) + (run-hooks 'terminal-init-xterm-hook)) ;; Set up colors, for those versions of xterm that support it. @@ -649,5 +666,11 @@ versions of xterm." (delq terminal xterm-modify-other-keys-terminal-list)) (send-string-to-terminal "\e[>4m" terminal))) +(defun xterm-set-background-mode (redc greenc bluec) + ;; Use the heuristic in `frame-set-background-mode' to decide if a + ;; frame is dark. + (when (< (+ redc greenc bluec) (* .6 (+ 65535 65535 65535))) + (set-terminal-parameter nil 'background-mode 'dark))) + ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a ;;; xterm.el ends here