unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Wrong value of background-mode on dark XTerm
@ 2009-06-01 22:32 Juliusz Chroboczek
  2009-08-11  5:03 ` Dan Nicolaescu
  0 siblings, 1 reply; 2+ messages in thread
From: Juliusz Chroboczek @ 2009-06-01 22:32 UTC (permalink / raw)
  To: emacs-devel

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.

                                        Juliusz




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Wrong value of background-mode on dark XTerm
  2009-06-01 22:32 Wrong value of background-mode on dark XTerm Juliusz Chroboczek
@ 2009-08-11  5:03 ` Dan Nicolaescu
  0 siblings, 0 replies; 2+ messages in thread
From: Dan Nicolaescu @ 2009-08-11  5:03 UTC (permalink / raw)
  To: Juliusz Chroboczek; +Cc: emacs-devel

Juliusz Chroboczek <Juliusz.Chroboczek@pps.jussieu.fr> 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




^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-08-11  5:03 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-06-01 22:32 Wrong value of background-mode on dark XTerm Juliusz Chroboczek
2009-08-11  5:03 ` Dan Nicolaescu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).