diff options
author | Dan Nicolaescu <dann@ics.uci.edu> | 2009-12-07 06:30:30 +0000 |
---|---|---|
committer | Dan Nicolaescu <dann@ics.uci.edu> | 2009-12-07 06:30:30 +0000 |
commit | a91e1f6bf8c2c1a721d660dbb49bede3adde0a38 (patch) | |
tree | 4e53846dd31c4b8161a35be07dcf79ae19bd900f | |
parent | 5fa9d1ecf496e0c20ee0f263c64c97c40b9cab35 (diff) | |
download | emacs-a91e1f6bf8c2c1a721d660dbb49bede3adde0a38.tar.gz |
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.
-rw-r--r-- | etc/NEWS | 5 | ||||
-rw-r--r-- | lisp/ChangeLog | 9 | ||||
-rw-r--r-- | lisp/term/xterm.el | 35 |
3 files changed, 43 insertions, 6 deletions
@@ -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 diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 2d2d938639a..1630f37ba4d 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,12 @@ +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 diff --git a/lisp/term/xterm.el b/lisp/term/xterm.el index 0fcccc3508d..bef43776dae 100644 --- a/lisp/term/xterm.el +++ b/lisp/term/xterm.el @@ -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 |