From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Dan Nicolaescu Newsgroups: gmane.emacs.devel Subject: Re: Wrong value of background-mode on dark XTerm Date: Mon, 10 Aug 2009 22:03:59 -0700 (PDT) Message-ID: <200908110503.n7B53xHV002874@godzilla.ics.uci.edu> References: <7itz2zr3er.fsf@lanthane.pps.jussieu.fr> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1249967164 11986 80.91.229.12 (11 Aug 2009 05:06:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 11 Aug 2009 05:06:04 +0000 (UTC) Cc: emacs-devel@gnu.org To: Juliusz Chroboczek Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Aug 11 07:05:53 2009 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1MajYX-0001FG-FU for ged-emacs-devel@m.gmane.org; Tue, 11 Aug 2009 07:05:53 +0200 Original-Received: from localhost ([127.0.0.1]:56531 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MajYW-0005ni-4r for ged-emacs-devel@m.gmane.org; Tue, 11 Aug 2009 01:05:52 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MajYP-0005lx-5p for emacs-devel@gnu.org; Tue, 11 Aug 2009 01:05:45 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MajYJ-0005fx-8E for emacs-devel@gnu.org; Tue, 11 Aug 2009 01:05:43 -0400 Original-Received: from [199.232.76.173] (port=45388 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MajYI-0005fm-Sm for emacs-devel@gnu.org; Tue, 11 Aug 2009 01:05:39 -0400 Original-Received: from sallyv2.ics.uci.edu ([128.195.1.120]:46698) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA1:24) (Exim 4.60) (envelope-from ) id 1MajYH-0008H8-RU for emacs-devel@gnu.org; Tue, 11 Aug 2009 01:05:38 -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 n7B53x2O009198; Mon, 10 Aug 2009 22:03:59 -0700 (PDT) Original-Received: (from dann@localhost) by godzilla.ics.uci.edu (8.13.8+Sun/8.13.6/Submit) id n7B53xHV002874; Mon, 10 Aug 2009 22:03:59 -0700 (PDT) In-Reply-To: <7itz2zr3er.fsf@lanthane.pps.jussieu.fr> (Juliusz Chroboczek's message of "Tue, 02 Jun 2009 00:32:28 +0200") Original-Lines: 102 X-ICS-MailScanner-Information: Please contact the ISP for more information X-ICS-MailScanner-ID: n7B53x2O009198 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-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:114032 Archived-At: Juliusz Chroboczek writes: > Running 23.0.94.1 on an ``xterm -rv'' (reverse-video), I get > > (frame-parameter nil 'background-mode) > ==> light > > which oviously reads to almost illegible text in certain modes. > > With recent XTerm versions, the background colour can be retrieved with > the escape sequence ``Operating System Controls'' > > ESC ] 1 1 ; ? ESC \ > > which returns an escape sequence in the same format, but with the ``?'' > replaced with an RGB specification > > ESC ] 1 1 ; rgb:0000/0000/0000 ESC \ > > I have no idea what this escape sequence does to older XTerms, but the > XTerm version number can be retrieved with ``Send Device Attributes'' > > ESC [ > c > > which returns something like > > ESC [ > 0 ; 2 4 2 ; 0 c > > where the 242 is the XTerm patchlevel. Thanks for the suggestion. Please try this (very lightly tested) patch. Is 242 the earliest version that provides this feature? --- xterm.el.~1.62.~ 2009-01-08 14:24:21.000000000 -0800 +++ xterm.el 2009-08-10 22:00:07.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,21 @@ ;; 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)))) + (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)) + (string-to-number (match-string 2 str)) + (string-to-number (match-string 3 str))))))) + (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 +520,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 +664,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 (+ 255 255 255))) + (set-terminal-parameter nil 'background-mode 'dark))) + ;; arch-tag: 12e7ebdd-1e6c-4b25-b0f9-35ace25e855a ;;; xterm.el ends here