Commit a91e1f6b authored by Dan Nicolaescu's avatar Dan Nicolaescu
Browse files

Get the background mode from the terminal for xterm, and set

faces accordingly.
* term/xterm.el (xterm-set-background-mode): New function.
(terminal-init-xterm): Use it in case xterm supports background
color queries.  Recompute faces after getting the background
color.
parent 5fa9d1ec
......@@ -339,6 +339,11 @@ That means, they change `default-directory' to the new users value,
and let commands run under that user permissions. It works even when
`default-directory' is already remote.
*** When running in a new enough xterm (newer than version 242), emacs
asks xterm what the background color is and it sets up faces
accordingly for a dark background if needed (the current default is to
consider the background light).
* New Modes and Packages in Emacs 23.2
......
2009-12-07 Dan Nicolaescu <dann@ics.uci.edu>
Get the background mode from the terminal for xterm, and set
faces accordingly.
* term/xterm.el (xterm-set-background-mode): New function.
(terminal-init-xterm): Use it in case xterm supports background
color queries. Recompute faces after getting the background
color.
2009-12-07 Ulrich Mueller <ulm@gentoo.org>
* emacs-lisp/bytecomp.el (byte-compile-insert-header): Put the version
......
......@@ -462,9 +462,7 @@
(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
;; C-. C-, etc.
......@@ -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)
......@@ -491,11 +490,26 @@
(while (not (equal (setq chr (read-event nil nil 2)) ?c))
(setq str (concat str (string chr))))
(when (string-match ">0;\\([0-9]+\\);0" str)
(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))))))
;; 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)
(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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment